cancel
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)?

Chao
Senior

Hi,

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:

Chao_0-1707932863841.png

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

Chao_1-1707933001510.png

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

Regards

Chao

3 REPLIES 3
gbm
Lead III

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.

My STM32 stuff on github - compact USB device stack and more: https://github.com/gbm-ii/gbmUSBdevice
TDK
Guru

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

TDK_0-1707937499792.png

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.

https://ftp.gnu.org/old-gnu/Manuals/ld-2.9.1/html_chapter/ld_3.html

https://sourceware.org/binutils/docs/ld/Builtin-Functions.html

 

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..