Gcc ignoring pragma statements to place code into ITCM memory.

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Gcc ignoring pragma statements to place code into ITCM memory.

44 Views
RNJ
Contributor I

Hello!

Using Matlab R2025b, Simulink and MBDT for S32K3 version 1.7.1 here.

To optimize the performance of a motor controller application we are developing we want to place some parts of the code into the ITCM memory and later on, DTCM memory for data.

As for now, for testing the workflow, I am trying to get a function placed into ITCM memory. I managed to get Simulink/ embedded coder to place the correct pragma statements in to the c code like:

#pragma GCC section text ".itcm_text"
static void  Motor_Drive_Subsystem(void)
{
..........
}
#pragma GCC section text ""

However, when compiling the application gcc ignore these pragma statements and places the code in the standard .text segment. This can be concluded with The objdump command:

arm-none-eabi-objdump -h Motor_Control.o      (beeing the .o file generated from the c-file containing the Motor_Drive_Subsystem function)

There are no .itcm_text in the list just .text.xxxx segments (among the other non text segments).

When compiling I use the standard switches for gcc set by the MBDT environment:

arm-none-eabi-gcc -O2 -c -std=c99 -fshort-enums -funsigned-char -fstack-usage -ffunction-sections -fdata-sections -g -pedantic -Wall -Wextra -fmessage-length=0 -funsigned-bitfields -fno-common -Wunused -Wstrict-prototypes -Wsign-compare -Werror=implicit-function-declaration -mcpu=cortex-m7 -mthumb -mlittle-endian -mfloat-abi=hard -mfpu=fpv5-sp-d16 -DD_CACHE_ENABLE -DI_CACHE_ENABLE -specs=nano.specs -specs=nosys.specs --sysroot="C:\MATLAB_Add-Ons\Toolboxes\NXP_MBDToolbox_S32K3\tools\build_tools\gcc_v10.2\gcc-10.2-arm32-eabi\arm-none-eabi\newlib" -DSTEP_GPT_TIMER -DSTEP_GPT_CHANNEL=GptConf_GptChannelConfiguration_StepTimer -DSTEP_GPT_CHANNEL_FREQ=40000000 -DSTEP_GPT_CHANNEL_VALUE_MAX=4294967295 -DAUTOSAR_OS_NOT_USED -D__MW_TARGET_USE_HARDWARE_RESOURCES_H__ -DGCC -DS32K3XX -DS32K396 -DCPU_S32K396 -DENABLE_FPU -DMPU_ENABLE -DMBDT_INIT -DCLASSIC_INTERFACE=0 -DALLOCATIONFCN=0 -DTERMFCN=0 -DONESTEPFCN=1 -DMAT_FILE=0 -DMULTI_INSTANCE_CODE=0 -DINTEGER_CODE=0 -DMT=0  -DTID01EQ=0 -DSTACK_SIZE=64 -DRT -DMODEL=Motor_Control -DNUMST=1 -DNCSTATES=0 -DHAVESTDIO -DMODEL_HAS_DYNAMICALLY_LOADED_SFCNS=0 -IC: .....

By modifying the generated c code file and manually compiling it I can conclude the following:

Removing the “static” declaration of the function does not help. However, removing “static” and using the alternative way for this by adding an attribute statement on the function:

static void  __attribute__((section(".itcm_text")))Motor_Drive_Subsystem(void);

will create a .itcm_text segment in the .o file.

 

I am not sure if I am doing something wrong here or if it is a tool problem.

Can someone guide me on how to get this working?

Of course, we want the tool chain to handle this and do not want to manually modify the c code after code generation.

As far as I can see it looks like the startup_cm7.s and linker_flash_s32k396.ld files are prepared for handling the ITCM and DTCM memories.

I found this post in the forum, not sure if it is relevant for this: https://community.nxp.com/t5/S32-Design-Studio/No-GCC-11-4-item-in-new-project-wizard-dialog-on-S32D...

The MBDT gcc seems to be build 1728 where as the fixed one in the post is build 1803.

 

Thanks in advance!

0 Kudos
Reply
1 Reply

14 Views
SorinIBancila
NXP Employee
NXP Employee

Hello,

Please check the following page on MathWorks website how to set up a custom storage class.: Control Data and Function Placement in Memory by Inserting Pragmas.
The part that you need to use is "Override Default Memory Placement for Subsystem Functions and Data".

SorinIBancila_0-1786627722302.png

After you created you custom storage class, you must configure the model to load it: 

0. Create and configure the custom storage class:

SorinIBancila_5-1786628332348.png

 


1. Enter Code Perspective

 

SorinIBancila_1-1786628013296.png

 

2. Open Embedded Coder DIctionary (Model)

SorinIBancila_2-1786628097732.png

 

3. Load the custom class you previously created.

SorinIBancila_3-1786628212316.png


4. Inside the model, create a new Subsystem and set it to atomic.

SorinIBancila_6-1786628433580.png


5.  Inside the Code Generation, set the Memory section for execution functions: "MemSection_ITCM" as set in the custom class.

SorinIBancila_7-1786628826071.png


6.  arm-none-eabi-objdump properly repots that ITCM_ToggleDIO.o is loaded into the .itcm_text memory section

SorinIBancila_8-1786631977524.png

arm-none-eabi-nm -n s32k3xx_dio_s32ct.elf also says that ITCM_ToggleDIO is found at  0x0 address.

SorinIBancila_9-1786632086079.png


If the .elf is flashed from the S32DS and a breakpoint is used inside the s32k3xx_dio_s32c_ITCM_ToggleDIO function., in the disassembly view we can see that the instructions are stored starting at 0x0 address.

SorinIBancila_0-1786632484317.png

 



Best regards,
Sorin Bancila



0 Kudos
Reply