cancel
Showing results for 
Search instead for 
Did you mean: 

About __initial_sp

shaolei198
Associate II
Posted on August 15, 2012 at 20:30

I am reading the STM32 startup code right now, got a question about stack section, hope you guys can help me.

1.
AREA STACK, NOINIT, READWRITE, ALIGN=3
2.
Stack_Mem SPACE Stack_Size
3.
__initial_sp

So from line #2, Stack_Mem should pointing to the bottom of the Stack, right? and this __initial_sp is a global variable, and based goggle, it's point to the top of the stack right? So my question is, how __initial_sp got assigned? Thank you guys
7 REPLIES 7
shaolei198
Associate II
Posted on August 15, 2012 at 20:33

One more question, since the Stack area is defined as NOINIT, from line #1

Why it's allocating memory on line #2?

Posted on August 15, 2012 at 21:33

The bottom of the stack is at the end of the memory region, it descends into lower memory, PUSH predecrements.

__initial_sp is a label which takes the origin (ORG) value of the assembler after it allocates the space. Look at a .LST or .MAP file.

NOINIT means the memory behind the stack is not set to any value by the startup code, and thus will contain whatever random junk is already there. There will be no data in the ELF/AXF file for this area.

Where Stack_Size = 0x800

0x20002000 Stack_Mem

0x20002800 __initial_sp

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
shaolei198
Associate II
Posted on August 15, 2012 at 22:06

Thanks for ur replay, hope you don't mind I ask some more questions.

1. for the heap:

__heap_base
Heap_Mem SPACE Heap_Size
__heap_limit

heap_base will have the address before memory allocation, and heap_limit will have the address after the allocation, right? 2. I couldn't find any explanation about keyword THUMB in the startup code.

PRESERVE8 ;current file use byte align
THUMB

Does THURM means the rest of code will use thrum 2 instruction set? 3.

1.
PROC
2.
EXPORT MemManage_Handler [WEAK]
3.
B .
4.
ENDP

what does B . in line #3 mean? I actually want to know what the dot stands for Appreciated!
Posted on August 16, 2012 at 00:13

1 Yes,

__heap_base

=

Heap_Mem

__heap_limit = Heap_Mem +

Heap_Size

2 Thumb indicates that it will use 16-bit instruction encoding, not 32-bit ARM instruction encoding. Thumb 1 vs 2 will depend on the opcode/operands you use. And perhaps a command line architecture option. 3 . (dot) is the current assembler origin for the line, other assemblers might use $ B . is a branch to the current line, ie an infinite loop
Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
shaolei198
Associate II
Posted on August 16, 2012 at 02:16

Really appreciated!

shaolei198
Associate II
Posted on August 16, 2012 at 17:42

I just had one final question,

Is there anyway to debug this startup code? i wanna step by step go through the code and check the memory update.

I searched the internet, seems like running the code in RAM is similar to what I am looking for here. However, i dont think thats exactly what i am looking for.

Hope you can give me some help.

Posted on August 16, 2012 at 17:49

You appear to be using Keil, uncheck the ''Run to Main'' option in the debug tab, and then you can step through the initialization code. It will execute SystemInit before going into __main (the compilers startup code) before going into your main function.

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