cancel
Showing results for 
Search instead for 
Did you mean: 

Modify the link file to locate the stack/heap into DTCM area

ABITT.1
Associate III

Hello,

Someone have a document that give explications/informations on how modify the link file ?

I must optimize ma code performance and I would realocate the stack/heap, the time critical functions, into the TCM area.

I know the way to locate variables into specific area ("attribute" put after variable declaration). But I don't find the way to do that for all the content of one source file (to put functions into specific code section and and variables into specific data section)

Thanks a lot for your time

1 ACCEPTED SOLUTION

Accepted Solutions
KnarfB
Principal III

Assuming gcc toolchain.

For the critical functions you may

  1. hide the attribute definiton in a user-defined macro for each function, or
  2. use objcopy for mass-renaming the section names in the .o file in a post-processing step to compilation, or
  3. fiddle with the .ld file which allows specifying .o file names, see example in https://ftp.gnu.org/old-gnu/Manuals/ld-2.9.1/html_chapter/ld_toc.html#TOC19

2.+ 3. may interfer with automagically generated make- and other files depending on your IDE

The initial stack pointer is the value of symbol _estack defined in the .ld file which can be easily redefined as you like. Things get more complicated when using a RTOS with task-specifiy stacks (typically allocated on the heap).

For the main heap, check the implementation of _sbrk. In STM generated code, this is in sysmem.c and uses two linker script defined symbols for heap beginning and end. Those values can also be changed to your needs. Putting the main heap into DTCM may be too much for that valuable ressource, use with care.

View solution in original post

2 REPLIES 2
KnarfB
Principal III

Assuming gcc toolchain.

For the critical functions you may

  1. hide the attribute definiton in a user-defined macro for each function, or
  2. use objcopy for mass-renaming the section names in the .o file in a post-processing step to compilation, or
  3. fiddle with the .ld file which allows specifying .o file names, see example in https://ftp.gnu.org/old-gnu/Manuals/ld-2.9.1/html_chapter/ld_toc.html#TOC19

2.+ 3. may interfer with automagically generated make- and other files depending on your IDE

The initial stack pointer is the value of symbol _estack defined in the .ld file which can be easily redefined as you like. Things get more complicated when using a RTOS with task-specifiy stacks (typically allocated on the heap).

For the main heap, check the implementation of _sbrk. In STM generated code, this is in sysmem.c and uses two linker script defined symbols for heap beginning and end. Those values can also be changed to your needs. Putting the main heap into DTCM may be too much for that valuable ressource, use with care.

ABITT.1
Associate III

Hello KnarfB

I already use the 1. solution, it's useful for locate specific function.

The manual on gcc to modify the ld file will help me a lot in the syntax undertanding of the linker file.

For the stack, I finally fond the solution that you explain.

Many thanks for your time