Home | Projects | Notes > ARM Cortex-M3/M4 Processor > Reset Sequence
When you reset the processor (e.g., press the reset button on the boad), the PC is loaded with the value 0x0000_0000. (Memory location 0x0000_0000 belongs to a Flash memory, or ROM memory, or Program memory.)
Then the processor reads the value at the memory location 0x0000_0000 into the MSP.
MSP = value at 0x0000_0000
MSP is the Main Stack Pointer register. This means that the processor, upon reset, first initializes the Stack Pointer.
Then the processor reads the value at the memory location 0x000_0004 into PC. That value is actually the address of the reset handler. (In other words, the address of the reset handler gets stored into PC.)
PC jumps to the reset handler.
A reset handler is just a C or assembly function written by you to carry out any initialization required.
From the reset handler, main()
function of the application gets called.
This is how the control reaches your program's main()
function after reset.
Reset handler does the early initialization after which the call to the user program (main()
) is made:
Processor reset
__libc_init_array();
)
main()
)
Remember! The main()
function cannot be called without these important early initializations.
xxxxxxxxxx
431/* a section of startup file (startup_stm32f407vgtx.s) */
2
3Reset_Handler:
4 ldr r0, =_estack
5 mov sp, r0 /* set stack pointer */
6/* Call the clock system initialization function.*/
7 bl SystemInit
8
9/* Copy the data segment initializers from flash to SRAM */
10 ldr r0, =_sdata
11 ldr r1, =_edata
12 ldr r2, =_sidata
13 movs r3, #0
14 b LoopCopyDataInit
15
16CopyDataInit:
17 ldr r4, [r2, r3]
18 str r4, [r0, r3]
19 adds r3, r3, #4
20
21LoopCopyDataInit:
22 adds r4, r0, r3
23 cmp r4, r1
24 bcc CopyDataInit
25
26/* Zero fill the bss segment. */
27 ldr r2, =_sbss
28 ldr r4, =_ebss
29 movs r3, #0
30 b LoopFillZerobss
31
32FillZerobss:
33 str r3, [r2]
34 adds r2, r2, #4
35
36LoopFillZerobss:
37 cmp r2, r4
38 bcc FillZerobss
39
40/* Call static constructors */
41 bl __libc_init_array
42/* Call the application's entry point.*/
43 bl main
Nayak, K. (2022). Embedded Systems Programming on ARM Cortex-M3/M4 Processor [Video file]. Retrieved from https://www.udemy.com/course/embedded-system-programming-on-arm-cortex-m3m4/