Stack Location (Cortex-M)

Hi guys,

I'm wishing to move the location of the stack but how is this possible? In the startup.s I have

                EXPORT  __initial_sp
Stack_Size      EQU     0x00000200

                AREA    STACK, NOINIT, READWRITE, ALIGN=3
Stack_Mem       SPACE   Stack_Size
__initial_sp

However there's no option for the location and nothing specific for the stack appears to show up in the generate scatter file.

I'm a little lost and would appreciate any help.

Many thanks

Parents
  • The Cortex chip is picking up the location of the stack before entering the code in the startup file. It is doing that by looking within the interrupt vector table. This is a neat trick that means the Cortex chip could start to run C code (minus the availability of initialized variables etc) directly from start.

    Your startup file probably have something looking like:

    __Vectors       DCD     __initial_sp              ; Top of Stack  <=== read by processor
                    DCD     Reset_Handler             ; Reset Handler
                    DCD     NMI_Handler               ; NMI Handler
                    DCD     HardFault_Handler         ; Hard Fault Handler
                    DCD     MemManage_Handler         ; MPU Fault Handler
    

    Ant that __initial_sp got computed from:

    Stack_Size      EQU     0x00000200
    
                    AREA    STACK, NOINIT, READWRITE, ALIGN=3
    Stack_Mem       SPACE   Stack_Size
    __initial_sp
    

    More interesting questions here - why do you want to move the stack? And where do you want it moved?

Reply
  • The Cortex chip is picking up the location of the stack before entering the code in the startup file. It is doing that by looking within the interrupt vector table. This is a neat trick that means the Cortex chip could start to run C code (minus the availability of initialized variables etc) directly from start.

    Your startup file probably have something looking like:

    __Vectors       DCD     __initial_sp              ; Top of Stack  <=== read by processor
                    DCD     Reset_Handler             ; Reset Handler
                    DCD     NMI_Handler               ; NMI Handler
                    DCD     HardFault_Handler         ; Hard Fault Handler
                    DCD     MemManage_Handler         ; MPU Fault Handler
    

    Ant that __initial_sp got computed from:

    Stack_Size      EQU     0x00000200
    
                    AREA    STACK, NOINIT, READWRITE, ALIGN=3
    Stack_Mem       SPACE   Stack_Size
    __initial_sp
    

    More interesting questions here - why do you want to move the stack? And where do you want it moved?

Children
More questions in this forum