Reputation: 195
Is there a simple way to find the stack base pointer programmatically? I am coding for an STM32F4 microcontroller and compiling with arm-none-eabi-gcc compiler.
When I was using the Arm C compiler packaged with Keil uVision 5 I could use the ABI function __user_initial_stackheap()
to retrieve the stack base, but that doesn't seem to work with gcc.
Upvotes: 0
Views: 1412
Reputation: 195
This depends on how the different memory sections are set up (typically in a linker script). For instance, the linker script for an STM32F4 may define the stack base as:
__stack = ORIGIN(RAM) + LENGTH(RAM);
Then the linker script variables can be accessed in C code with
extern uint32_t __stack;
void foo() {
uint32_t stack_base = &__stack;
}
Upvotes: 1