Showing results for 
Search instead for 
Did you mean: 

What Is the Macro Definition for the Highest Address of the User Mode Stack (or the RAM)?



Though my current work is on a Nucleo-STM32G070 board, I am going to target on multiple STM32MCUs later, and I would like to know the macro definition so that my code would be more adaptive to different target processors.

The ld file gives following information:


but the stm32g070xx.h gives different size of the RAM:


Anyone could explain it?  And which macro I should use for the highest address of the RAM?



Lead II

The explanation of 32 vs. 36 KiB may be found in the Reference Manual. The software uses the linker-defined _estack symbol as stack bottom location. You may reconfigure the MCU and edit the linker file to change the amount of RAM available to software to 36 KiB.


Correction: This is supervisor mode stack in no-OS environment. User mode stacks are normally used by RTOS threads only.


In this case, the SRAM size depends on if you have parity enabled or not.


If it is disabled, you have 36 kB. If it is enabled, you have 32 kB.

Parity is enabled/disabled in the option bytes, which you can access with STM32CubeProgrammer.

As @gbm mentioned, _estack is the top of the stack, and memory gets allocated starting just below that point.

If you feel a post has answered your question, please click "Accept as Solution".

It's not a macro, it's a computation the linker can do, referencing the length you specified for the memory section/region in question.

Here's some documentation, if that's helpful, or you're unfamiliar with finding such things.


The SP/R13 auto-decrements, but needs/expects alignment, so pointing at the byte beyond the end is Ok.

ie 0x20009000 is Ok, 0x20008FFF would not be

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