Strictly necessary cookies are on by default and cannot be turned off. Functional, Performance and Tracking/targeting/sharing cookies can be turned on below based on your preferences (this banner will remain available for you to accept cookies). You may change your cookie settings by deleting cookies from your browser. Then this banner will appear again. You can learn more details about cookies HERE.
Strictly necessary (always on)
Functional, Performance and Tracking/targeting/sharing (default off)
Firmware engineers are always looking for ways to write more efficient code. Often this means executing functions as fast as possible. One way to improve the execution time of your code when developing for PSoC5 is to place your code into RAM.
Placing code in RAM using GCC
Gcc supports the use of the __attribute__ keyword which allows you to apply special attributes to your code. There are many attributes you can apply; the one we are interested in is section .
The section attribute places code in a specific memory section as defined in the cm3gcc.ld file. RAM is defined as the .data section. So, for example, if you wanted to place a function in RAM the code for the function prototype would look like this:
A great use of this feature is to place interrupt handlers in RAM for faster execution time. If you define your own ISRs you can do this by placing __attribute__ ((section .data ))) after the ISR prototype like a normal function declaration.
If you are using the Cypress generated ISR code you can add a declaration statement to the section of code at the top of the .c file which is provided for the user to include modules and declare variables.
When you place code into the .data section you will get the following warning:
Warning: ignoring changed section attributes for .data
This is because the .data section does not, by default, expect to have code attributes associated with it. In this case you can ignore the warning, because you intend to add attributes to the .data section. Even though the warning indicates that the linker is ignoring your attribute, it will still place your code in RAM. You can verify this in the map file by checking which section your code has been placed in.
To clear this warning you would need to modify the cm3gcc.ld file. The best approach would be to add a custom section located in RAM for you code. However, since this is Creator generated source code, changes you make to this file will be overwritten when generating the project APIs.
RAM vs Flash execution
The following table provides some sample data taken to show the code execution speed from flash vs RAM. There is about a 30 % improvement in execution time when executing out of RAM vs flash. This data was taken by toggling a pin in an ISR with a varying amount of code, measured in bytes. The Cortex M3 was running at 24 MHz. There was no difference in the time it took to get into the interrupt.