Skip to main content
DK.7
Associate III
January 26, 2024
Solved

How can I determine the starting address of the stack in CubeIDE?

  • January 26, 2024
  • 4 replies
  • 3981 views

In Keil, if you open a file with the extension .map, you can find information about starting address of stack and so on. See screen.

How can I determine the starting address of the stack in CubeIDE?Q.png

    This topic has been closed for replies.
    Best answer by Tesla DeLorean

    It should really use the space allocated by the linker, in this case ST just lets it descend into the end of the heap

    See _sbrk implementation in syscalls.c

    ST sets in to the end of RAM, and it auto-decrements from there, basically the first 32-bit word gets stored at _estack-4

    _bstack = (ORIGIN (RAM) + LENGTH (RAM) - _Min_Stack_Size)

    _estack = (ORIGIN (RAM) + LENGTH (RAM))

     

    In the Keil builds the initial stack is set to __initial_sp, and descends too Stack_Mem

    4 replies

    mƎALLEm
    Technical Moderator
    January 26, 2024

    Hello,

    Go to STM32CubeIDE\Debug and open .map file. Try to find the line

    _estack = (ORIGIN (RAM) + LENGTH (RAM))

     

    To give better visibility on the answered topics, please click "Best answer" on the reply which solved your issue or answered your question.
    DK.7
    DK.7Author
    Associate III
    January 26, 2024

    Thanks for the answer!

    I found the desired line in .map file

     

    _estack = (ORIGIN (RAM) + LENGTH (RAM))

     

    and I don’t understand what to do with it. See screen.Q.png

    mƎALLEm
    Technical Moderator
    January 26, 2024

     

    SofLit_1-1706284458542.png

     

    To give better visibility on the answered topics, please click "Best answer" on the reply which solved your issue or answered your question.
    DK.7
    DK.7Author
    Associate III
    January 26, 2024

    Thank you, but how to find out the end address of stack from this file?

    mƎALLEm
    Technical Moderator
    January 26, 2024

    _estack defines the end of the Stack which is the Top of the stack.

    So normally the stack starts at: _estack - _Min_Stack_Size

    To give better visibility on the answered topics, please click "Best answer" on the reply which solved your issue or answered your question.
    Tesla DeLorean
    Tesla DeLoreanBest answer
    Guru
    January 26, 2024

    It should really use the space allocated by the linker, in this case ST just lets it descend into the end of the heap

    See _sbrk implementation in syscalls.c

    ST sets in to the end of RAM, and it auto-decrements from there, basically the first 32-bit word gets stored at _estack-4

    _bstack = (ORIGIN (RAM) + LENGTH (RAM) - _Min_Stack_Size)

    _estack = (ORIGIN (RAM) + LENGTH (RAM))

     

    In the Keil builds the initial stack is set to __initial_sp, and descends too Stack_Mem

    Tips, Buy me a coffee, or three.. PayPal VenmoUp vote any posts that you find helpful, it shows what's working..