This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

How does the stack pointer work?

We have written our own softdevice, but now we have a question about the stack pointer. I read in the softdevice specification that the nordic softdevices share the stack with the application. That is what we want, so we thought we need to set the MSP to the value set by the application (first element in the application vector table). When our softdevice starts it gets initialised with a value at the end of region 0, as expected. Now the part I don't understand.

When I print the MSP in the application to uart I get a value at the end of the region 1. This is what we want. But how, I never did anything with the MSP to set it to this value.

We use the same startupcode for our softdevice as for our applications. The reset handler gets called from softdevice main. right before entering application reset handler the MSP is pointing to a region 0 ram address, in application main the MSP is pointing to region 1 ram address.

Can someone explain where the MSP gets set? I thought it was initialised once at core startup by the value set at address 0.

Related