2012-08-15 11:30 AM
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
2012-08-15 11:33 AM
One more question, since the Stack area is defined as NOINIT, from line #1
Why it's allocating memory on line #2?2012-08-15 12:33 PM
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_sp2012-08-15 01:06 PM
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!
2012-08-15 03:13 PM
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
2012-08-15 05:16 PM
Really appreciated!
2012-08-16 08:42 AM
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.2012-08-16 08:49 AM
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.