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)
Question: How do I place code at an absolute location in PSoC flash?
We can do this using the ‘#pragma’ directive in PSoC Designer. Suppose we need to define a relocatable code area called ‘my_code_area’ in the memory locations 0x3800 to 0x3FFF. The following steps are to be followed to do this:
1. Declare a custom area in the PSoC flash memory which will contain the user-written code using the ‘#pragma’ directive in the main.c file of your PSoC Designer project. You can insert the code you wish in this area as follows:
#pragma text:my_code_area // Place following code in custom area in flash // add your code here
#pragma text:text // Place following code in default area
‘my_code_area’ can be any user-defined name.
2. A file called custom.lkp can be created in the root folder of the project, which can contain Linker commands. A typical use for employing the custom.lkp capability would be to define a custom relocatable code area. The code was placed in the custom area in the previous step. Now, add the following line to the custom.lkp file which will place the custom area in the address range 0x3800 to 0x3FFF.
2.Using assembly language:
This can also be done using the ‘AREA’ assembler directive. ‘AREA’ defines where code or data is placed in RAM or flash by the Linker. You have to follow the steps given below:
1. Declare a custom area in PSoC flash memory which will contain the user-written code using the ‘AREA’ assembler directive in the main.asm file of you PSoC Designer project. You can insert your code in this area as follows:
_my_code_area_start: */insert your code here
(Please refer to the Assembly Language Compiler Guide for more details)
The PSoC flash contains the following seven areas:
(Please refer C Language Compiler User Guide for more details about these sections of flash)
These are not absolute areas, i.e., the space they occupy differ from project to project. For instance, if you add a user module to your project in PSoC Designer, the space occupied by the UserModules will increase and this will be compensated for by other sections of flash. If we define these areas rigidly, we lose this flexibility which is undesirable. So in the custom.lkp file, we only have to define the custom area we want to use to insert the code as shown above with ‘my_code_area’.