Author: AH_96 Version: **
How do I place the Program counter functions at a required address with a large application code when compiling with Arm® GCC?
This document assumes that you have referred to the following application notes: AN89056 - PSoC® 4 - IEC 60730 Class B and IEC 61508 SIL Safety Software Library and AN89610 - PSoC® 4 and PSoC 5LP Arm® Cortex® Code Optimization.
The IEC 60730 standard, which is described in AN89056 and AN89610, requires a few functions to have absolute address with some pattern in its bits (that is, its lower bits must be 0b0101, like 0x15555, or 0xaaaa). But sometimes the code size is larger than this and might cause an overlap. In this case, the user must write custom linker script with functions placed manually.
The following steps shows how to create a custom linker script with the functions placed at the correct address:
1. Steps to generate custom linker script:
2. Once the custom linker script is ready, generate the symbols using the nm program. The GNU nm program lists the symbols from the object files. For GCC bundled with PSoC Creator, the default location is C:\Program Files (x86)\Cypress\PSoC Creator\<PSoC Creator Version>\PSoC Creator\import\gnu\arm\<arm version installed>\bin\arm-none-eabi-nm.exe. This is the path to the nm program
3. Follow these steps to generate the list of code section symbols:
4. Open the <ProjectName>.defsym.code file in any advanced text editor like notepad++ that allows multi-line editing and allows usage of extended symbols like “\r” and “\n” in the replace dialog.
5. Move the text pointer to a position before the first character in file. Start multi-line editing of all lines in the file by pressing Page Down or Arrow Down buttons multiple times while holding Alt+Shift (in notepad++).
6. When the text pointer goes to the last nonempty line of the file, release the Alt+Shift buttons.
7. Press Delete button until you meet the first character of symbol names in the first column of the editor, as shown in the following screenshot.
8. Write “KEEP(*(*” in multi-line editing mode, so all selected lines have “KEEP(*(*” at the beginning of them.
9. Put “))” at the end of every non-empty line in the file, by following these steps:
10. Locate the line with symbol cyfitter_cfg.
11. Remove lines that are above this line (lines from the beginning of the file up to this line, excluding this line).
12. Find the lines with a symbol name that needs to be placed in a particular address – in case of ClassB tests, the symbol name is SelfTest_PCAAAA and SelfTest_PC5555. Move these to the last line of the file.
13. Copy all the contents of this file to the custom linker script file created in step 1. This needs to be placed after the line with text . = MAX(., 0x100); in the .text region of linker script.
14. Clean and build the project.
15. Repeat step 3 to generate the new symbol list file <ProjectName>.defsym.code.
16. In the generated <ProjectName>.defsym.code file, find the symbol with the highest address lower than 0xAAAA.
In this case, func12 has an address of A1E4. Hence the SelfTest_PCAAAA function must be placed before this function.
17. Open the custom linker script and insert . = MAX(., 0xAAAA); before line containing symbol mentioned in step 16.
18. Remove the line KEEP(*(*SelfTest_PCAAAA)) text and insert it after the line mentioned in step 17.
19. Clean and build the project.
20. Repeat step 3 to generate the new symbol list file <ProjectName>.defsym.code.
21. Find the symbol with highest address lower than 0x15555.
22. Open the custom linker script and insert . = MAX(., 0x15555); before line containing symbol mentioned in step 21.
23. Remove the line KEEP(*(*SelfTest_PC5555)) text and insert it after the line mentioned in step 22.
24. Clean and build the project and make sure SelfTest_PCAAAA and SelfTest_PC5555 are located at the appropriate address.