Locating Object Files at a Specific Memory Section in PSoC® Creator™- GCC Compiler Linker Script File - KBA91336 | Cypress Semiconductor
Support & Community
Locating Object Files at a Specific Memory Section in PSoC® Creator™- GCC Compiler Linker Script File - KBA91336
In my PSoC 4/ PSoC 5LP project, I would like to locate all the functions in a source file to a particular section defined in the gcc linker script file. Can I implement this using only the object file of the respective source file instead of adding additional code in the source file? If so, can I do the same for source files generated by PSoC Creator as well as user-defined source files?
It is possible to locate all of the functions in a user object file into a particular section defined in the gcc linker script file, but not for source files that are generated by PSoC Creator. Both cases are discussed below.
Note that the following content applies to the gcc compiler for PSoC 4 and PSoC 5LP.
Case 1: Object Files Belonging to User-Defined Source Files:
If you have created your own source file (“.c” and “.h”), and you want to place all functions in that file in a specific memory section (say “.data” or SRAM), do the following:
Create a custom linker script file.
Copy the linker script file generated by PSoC Creator:
Project Folder\Generated_Source\PSoC5\cm3gcc.ld (for PSoC 5LP project) or
Project Folder\Generated_Source\PSoC4\cm0gcc.ld (for PSoC 4 project)
to the project's .cydsn folder, renaming it according to your choice, for example cm3GCC_custom.ld (PSoC 5LP) or cm0GCC_custom.ld (PSoC 4).
In the project's Build Settings, under Linker option, set the Custom Linker Script section to the custom file name, as Figure 1 shows.
Figure 1. Setting a Custom Linker Script File
- Copy the linker script file generated by PSoC Creator:
In the .data section of the newly created custom linker script, add the full path of the object file “.text” section references. For example:
This places all functions in “myfile.o” object file in the “.data” section (SRAM).
Exclude the myfile.o file from the Flash section to prevent a multiple definitions error. In the .text section, replace the line:
*(.text .text.* .gnu.linkonce.t.*)
*(EXCLUDE_FILE(.\CortexM3\ARM_GCC_473\Debug\myfile.o) .text EXCLUDE_FILE(.\CortexM3\ARM_GCC_473\Debug\myfile.o) .text.* .gnu.linkonce.t.*)
Case 2: Object Files Belonging to Source Files Generated by PSoC Creator:
It is not possible to relocate the object file of any source file generated by PSoC Creator (for example, "CyFlash.o" generated for “CyFlash.c”), by modifying the .ld file. This is because PSoC Creator includes the object file in the project’s library (“.a”) file.
In this case, the only way to place all the functions in that source file is to include "__attribute__" syntax in each function prototype statement (not the actual function definition statement). To know more about relocating a function to a different section, see section 6 in the following knowledge base article: http://www.cypress.com/?id=4&rID=57109.
To learn more about customizing linker script files, see application note AN89610, PSoC 4 and PSoC 5LP ARM Cortex Code Optimization.