This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Startup Code Microlib - Stack heap initialization

Hi,

I am trying to understand STM32F4-Discovery startup code that is added automatically to Keil project. i.e.

github.com/.../startup_stm32f407xx.s

I am using Keil MDK v5. Everything is clear except the following portion:

;*******************************************************************************
; User Stack and Heap initialization
;*******************************************************************************
                 IF      :DEF:__MICROLIB

                 EXPORT  __initial_sp
                 EXPORT  __heap_base
                 EXPORT  __heap_limit

                 ELSE

                 IMPORT  __use_two_region_memory
                 EXPORT  __user_initial_stackheap

__user_initial_stackheap

                 LDR     R0, =  Heap_Mem
                 LDR     R1, =(Stack_Mem + Stack_Size)
                 LDR     R2, = (Heap_Mem +  Heap_Size)
                 LDR     R3, = Stack_Mem
                 BX      LR

                 ALIGN

                 ENDIF

My Questions are:

1. Whats the purpose of this portion?
2. How does it initializes Stack and Heap as it only load Stack/Heap addresses in R0-R3?
3. Where is __use_two_region_memory defined that is imported here?

I search a lot but couldn't find any proper explanation. Any clue/reference will be highly appreciable.