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.

CCS/TMS570LS0432: Stack size linker option

Part Number: TMS570LS0432

Tool/software: Code Composer Studio

Hello TI support team,

Could you be so kind to help me with a questions related to a stack and its size definition?

After reading the following thread I'm a bit confused about using the option --stack_size:

https://e2e.ti.com/support/microcontrollers/hercules/f/312/t/738100?CCS-TMS570LS3137-How-to-chage-stack-size

Right now within my project I have the following linker file instructions:

    USER_STACK      (RW)    : origin=0x08000000 length=0x00000F00
    SVC_STACK       (RW)    : origin=0x08000F00 length=0x000000F0
    FIQ_STACK       (RW)    : origin=0x08000FF0 length=0x000000F0
    IRQ_STACK       (RW)    : origin=0x080010E0 length=0x000000F0
    ABORT_STACK     (RW)    : origin=0x080011D0 length=0x000000F0
    UNDEF_STACK     (RW)    : origin=0x080012C0 length=0x000000F0

At the same time, during startup each mode stack pointer is set to the corresponding memory area address.

Additionally I don't have declaration of the .stack section within the linker file. Everything works fine with such a configuration (at least I don't see any issues :)).

Do I really need to use --stack_size option in this case? What is the purpose of this option if stack memory is completely described by the linker file and stack pointers are set by the application?

Also the mentioned above thread contains the following information:

1. --stack_size=0x800 is defined in CCS linker options (your 2nd picture)
2. The memory section used for stack is defined in cmd file (your 1st picture). This region should be >= --stack_size defined in CCS linker options
3. The starting address of stack in cmd file should be consistent with the starting address defined in sys_core.asm

Why the marked condition has to be fulfilled? If I have several regions (separate stack area for each mode) which stack_size has to be used? Less than size of the USER mode stack region or...?

Thanks in advance for your help!

  • Dmitry,

    The general stack and heap requirement for applications has been explained by our compiler teams here which applies to the --stack_size option provided by the compiler. This typically applies only for the USer mode operation on Cortex R applications

    http://processors.wiki.ti.com/index.php/Stack_and_Heap_size_requirements

    For Cortex R4 and Cortex R5, you will notice that the core has following modes of operation:

    • User (USR) mode is the usual mode for the execution of ARM or Thumb programs. It is used for executing most application programs.
    • Fast interrupt (FIQ) mode is entered on taking a fast interrupt.
    • Interrupt (IRQ) mode is entered on taking a normal interrupt.
    • Supervisor (SVC) mode is a protected mode for the operating system and is entered on taking a Supervisor Call (SVC), formerly SWI.
    • Abort (ABT) mode is entered after a data or instruction abort.
    • Undefined (UND) mode is entered when an Undefined Instruction exception occurs.

    The stack in these modes is not shared and so you need to create stack for each mode of operation which is what the linker command file shows. The TI Compiler will put the core in USR mode when in main so for the most time it will use the USR stack but when the core changes mode to handle IRQ or needs to go to SVC state for CP15 setup then it will use the SVC stack.  I hope that clarifies the usage  

    If the --stack_size is not defined then the compiler assumes default stack of 0x800 (2048 bytes)

    Regards,

    Rahul

    PS: A good example of how the stack in different modes is handled is provided in the nested interrupts application note here:

    http://www.ti.com/lit/an/spna219/spna219.pdf

  • Hello Rahul,

    thank you very much for your answer.

    About different modes - it is clear, but unfortunately I still don't completely understand the purpose of the --stack_size option.

    What does this option change? Limit size of .stack section? I don't have this section at all.

    As I mentioned above, I've prepared memory area for each mode stack:

        USER_STACK      (RW)    : origin=0x08000000 length=0x00000F00
        SVC_STACK       (RW)    : origin=0x08000F00 length=0x000000F0
        FIQ_STACK       (RW)    : origin=0x08000FF0 length=0x000000F0
        IRQ_STACK       (RW)    : origin=0x080010E0 length=0x000000F0
        ABORT_STACK     (RW)    : origin=0x080011D0 length=0x000000F0
        UNDEF_STACK     (RW)    : origin=0x080012C0 length=0x000000F0

    And just after power up set the corresponding pointers by the application.

    If I open map file for my project, there is no .stack section and it works nice. What is the influence of --stack_size option in this case?

    Is it mandatory to define .stack section or could I live just with the memory areas declarations (see above) + pointer initialization?

    Thanks in advance!

    P.S. not sure 100% but I have a feeling that if I had used .stack section (which shares the same memory region as RAM, for example), then this option would have limited size of .stack.

    In my case, when .stack is not available, there is no any influence of the --stack_size.

    Please correct me if I'm wrong.

  • Please refer to compiler USer guide section 6.1.2. the value of --stack_size appears to be allocated to the global __STACK_SIZE and used during runtime to determine. With safety diagnostic library this doesn`t create a .stack section with this size in them but you can check posts from our compiler team on how to ascertain the STACK_START and STACK_END variables for the application from C code:

    https://e2e.ti.com/support/tools/ccs/f/81/t/92002

    For devices in which the stack is defined for all modes of operation, I am not sure that this variable get used other than at the link step where the compiler must be checking if global and local variables fit in this defined STACK size 

    Regards

    Rahul