Explain the microcontroller boot sequence (ARM Cortex-M).
When a microcontroller powers on or resets, it executes a startup sequence before reaching the application's main() function.
- Reset: The processor enters its initial reset state.
- Initialize MSP: The CPU loads the initial Main Stack Pointer from vector table address
0x00000000. - Load Reset Handler: The CPU loads the reset handler address from
0x00000004into the Program Counter (PC). - Initialize .data: Copy initialized global and static variables from flash to RAM.
- Initialize .bss: Zero-initialize uninitialized global and static variables in RAM.
- System initialization: Configure clocks, FPU (if available) and other required hardware, typically through
SystemInit(). - C/C++ runtime initialization: Execute required runtime setup and global C++ constructors, if applicable.
- Call main(): Transfer control to the application.
Power ON / Reset
|
Load MSP from 0x00000000
|
Load PC from 0x00000004
|
Reset_Handler()
|
Copy .data and zero .bss
|
System and runtime initialization
|
main()
|
Application / Super Loop
Note: The startup file contains the vector table and reset handler. The linker script defines the memory layout and section addresses. The addresses shown assume the reset vector table is mapped at zero. The exact initialization order depends on the MCU and toolchain; a device-specific ROM bootloader may also execute before the application startup code. Interrupt masking and enabling are startup-policy dependent. The .bss section is zeroed in RAM, not copied from flash.