Skip to main content
MViti.6
Visitor II
May 8, 2019
Question

stack pointer initialization

  • May 8, 2019
  • 1 reply
  • 2669 views

Hi,

I'm pretty new to ARM processor and STM32 microcontroller, so my question is very basic.

In the startup file for a SW4STM32 project (eg startup_stm32f446xx.s) the stack pointer is set in Reset_Handler with the line

ldr  sp, =_estack     /* set stack pointer */

why is this needed? I mean as far as I know the ARM Cortex-M is fetching automatically the value of the stack pointer as first step during the booting sequence. Why has it to be done a second time via software? I looks like it is initialized twice to the same value (_estack) since the vector table has the form:

.word _estack

.word Reset_Handler

.

.

.

This topic has been closed for replies.

1 reply

Tesla DeLorean
Guru
May 9, 2019

It has zero real cost.

Why? Well perhaps so that the code can be called into externally, ie jump from a loader, and moving the stack pointer is more complex/hazardous from calling end. Once it is in the Reset_Handler there is no expectation it will return.

One might also want to use CCM, or other memory for the stack. A value of 0x20002000 in the vector table could be a good placeholder while the CCM clock is enabled, or the memory buses initialized.

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