This thread has been locked.
If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.
How to edit the linker.cmd file to add new sections in TCM and how to add the application code into these TCM sections for faster code execution?
Sometimes machine critical applications require faster execution times with very low latency code. In such cases, the piece of code can be configured to be executed in TCM as it is present close to the CPU. TCM takes single R5 cycle per access if the core is accessing its own TCM. For more information regarding TCM please refer to TRM. Each R5 core contains 64 KB TCM memory divided as below:
TCMA - 32KB
TCMB - 32KB
1. Modifying the linker.cmd file:
Code and data memory can be separately added to the TCM. As a general principle, the code and data should be put into different TCM partitions (TCMA and TCMB) to further increase the performance. To create section in TCM edit the linker.cmd as below:
.NewTCMSection1 : {} palign(8) > R5F_TCMA .NewTCMSection2 : {} palign(8) > R5F_TCMB
Example:
Here the controlfunction section contains code and is present in TCM_A. Similarly, the data part of application is present in the controldata section which is present in TCM_B.
2. Further Additions to the linker.cmd file for the code part:
The stack used by the code in TCM should also be put in the TCM. For example the IRQ or SVC stacks for ISRs should be in TCM too. The below picture shows how to add the IRQ, SVC, and FIQ stacks.
Note: If your application consumes less TCM space, other sections of the linker.cmd file can also be placed in TCM depending on the requirement as shown below:
3. Modifying the Code:
Now the sections of code required in the TCM:
static inline __attribute__((__section__(".controlfnc"),always_inline)) void Function_API (uint32 function_param) {} __attribute__((__section__(".controlfnc"))) int Function_API (uint32 function_param) { return 0;}
For Global Variables:
uint32_t GlobalVariable __attribute__((__section__(".controldata")));
Any ISR that executes very often consuming most of the CPU time can be put into TCM. Any functions used by the ISRs like math functions etc. should also be put into the TCM. The local variables inside the ISR or internal functions can be made as global variables and added to the TCM.
4. Memory Exception:
The TCMA and TCMB are each 32KB, hence if any excess memory is added beyond 32KB, the compiler raises below exception:
"error #10099-D: program will not fit into available memory, or the section contains a call site that requires a trampoline that can't be generated for this section."
Then the user has to re-adjust which piece of code is required to be present and which can be avoided. It is usually recommended to place High priority ISRs with Sensing and Control Loop related applications inside the TCM.
5. Map File & TCM sections:
To verify if this section of code is successfully placed in the TCM, please refer the following steps:
1. Compile and Build the code. It is strongly recommended to use Release Mode Configurations with Optimizations enabled.
2. TCMA in R5_0_0 (1st core) is present from address 0x0000 to 0x07FFF.
3. TCMB in R5_0_0 (1st core) is present from address 0x80000 to 0x807FFF.
4. Search your respective TCM section name in the .map file to find their respective memory locations inside the TCM. This information should be present in the SECTION ALLOCATION MAP title of the map file, for example:
5. Check for the Memory Configuration Title in the .map file to see the memory usage of TCM and OCRAM as shown below:
The following linker script can be used as reference for using the 64KB TCM:
The following are the configurations to use AM263 TCM for 128KB in Lockstep Mode:
1. Initially set AM263 in lockstep mode. The below steps are to set AM263 in Lockstep mode using CCS - GELs.
The below steps are to set AM263 in Lockstep mode using SBL.
2. Now Set the TCM size as 128KB as shown below in your linker file:
3. Now Set the TCMA size as 64KB and TCMB size as 64KB in your MPU configurations in syscfg as shown below:
TCMA:
TCMB:
This should configure your application to use 128 KB TCM. TO verify the lockstep mode of your core you can use this API -
Status = SOC_rcmIsR5FInLockStepMode(CSL_ARM_R5_CLUSTER_GROUP_ID_0);
I have tested the same at my end and here is a picture of Memory Allocation Tab: