2019-05-08 01:18 AM
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
.
.
.
2019-05-09 07:06 AM
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.