cancel
Showing results for 
Search instead for 
Did you mean: 

Value of ''__initial_sp''

n.serina
Associate III
Posted on December 11, 2017 at 13:30

Hello ,

I am new to ARM cortex M processors and while doing some coding on my board using KEIL  i found that

at location 0x0000_0000 my debugger shows the value '0x2000_0660' . Thats the value of the MSP loaded.

but i really dont understand how linker arrived at that value using __initial_sp

i checked in the startup file and found this

; Amount of memory (in bytes) allocated for Stack

; Tailor this value to your application needs

; <h> Stack Configuration

; <o> Stack Size (in Bytes) <0x0-0xFFFFFFFF:8>

; </h>

Stack_Size EQU 0x00000400

AREA STACK, NOINIT, READWRITE, ALIGN=3

Stack_Mem SPACE Stack_Size

__initial_sp

How this turns out to be __initial_sp = 0x2000_0660 ???

#cortex-m3 #keil-mdk5 #stm32-f4
1 REPLY 1
Posted on December 11, 2017 at 15:13

The stack moves backward, __initial_sp being at the end of the region allocated. The stack and heap are placed after the RAM variables you have allocated toward the front of the RAM space.

Review the .MAP file to observe what variables/structures are placed where.

One your example Stack_Mem would be at 0x20000260, with the next available address being += 0x400 (ie 0x20000660), the SP pre-decrements by 4 when a value is pushed on the stack, first value will get stored at 0x2000065C

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