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.

TMS570LS3137: Setting Stack value in HalcoGen vs sys_link.cmd

Part Number: TMS570LS3137
Other Parts Discussed in Thread: HALCOGEN, CODECOMPOSER,

Info:

HalcoGen: 04.07.01
CodeComposer: 8.1.0.00011 
MicroController: TMS570LS3137
Compiler: TI v18.1.2.LTS
Reference Link: This 

Hello,

I have been tasked with figuring out our stack usage, and came across the link above which helped a great deal. When trying to figure out how much we were using vs allocated I noticed a discrepancy.

In the sys_link.cmd we have:
STACK        (RW)   : origin=0x08000000 length=0x00003000
(Overall Stack 0x3000)

but when I looked at _coreInitStackPointer_ in sys_core.asm I noticed

userSp .word 0x08000000+0x00001000
svcSp .word 0x08000000+0x00001000+0x00000100
fiqSp .word 0x08000000+0x00001000+0x00000100+0x00000100
irqSp .word 0x08000000+0x00001000+0x00000100+0x00000100+0x00000100
abortSp .word 0x08000000+0x00001000+0x00000100+0x00000100+0x00000100+0x00000100
undefSp .word 0x08000000+0x00001000+0x00000100+0x00000100+0x00000100+0x00000100+0x00000100

(Overall stack 0x1500 and user stack 0x1000)

When I went to HalcogGen to try and have the Overall Stack match what we put in the sys_link.cmd file, HalcoGen would not let me change the first Stack length for the Stack Base Address section. I can change the length for the other Stack Base/Stack Length Sections.

I searched through SPNU499c.pdf and the SPNU151R.pdf file for info and didn't really find anything except in SPNU151R.pdf section 6.7.6 which states:

The FIQ, supervisor, abort, IRQ, and undefined modes have separate stacks that are not automatically
set up by the C/C++ run-time environment. If you have interrupt routines in one of these modes, you
must set up the software stack for that mode. However, ARM Cortex-M processors have two stacks,
and the main stack (MSP), which is used by IRQ (the only interrupt type for Cortex-M), is automatically
handled by the compiler.

So my questions are:

  1. Is 0x1500 the maximum Stack length for this processor/microcontroller?
    1. If not, can I manually change it in the sys_core.asm file?
  2. Does the Stack Size called out in the sys_link.cmd really do anything? (or what does it do?)
  3. Is there an issue with sys_link.cmd not matching the sys_core.asm?
  4. Where can I find information regarding the minimum/maximum stacks sizes for this processor?

Thanks for your time and information.

Regards,
Ryan

  • So I just realized that if I adjust the User Stack Length, the rest of stack length values update automatically... I feel really dumb.

    If you could address my other questions, I would apprecate it.

  • The stack size used by the CPU is what is defined in the sys_core.asm file. The stack size defined in the linker command file does not affect anything from an execution perspective. There is a c_int00 routine also included in the rts library. This routine includes a function to set up the stacks for the different CPU modes, and this routine uses the values defined in the linker command file.

    So if you use the c_int00 routine generated by HALCoGen then the stack sizes in the linker command file are ignored. You can also modify the sys_core.asm file to actually use the values defined in the linker command file versus using hard-coded (per your configuration of course) values generated by HALCoGen.

    The max stack size is only limited by the amount of RAM. If you have external memory connected via EMIF, you can also choose to place the stack in the off-chip memory (not recommended due to the latency involved).

  • thanks for the info. That helped clear up my confusion.