How ARM Cortex-M Processor Boots: Step-by-Step Explanation
When an ARM Cortex-M processor boots, it first loads the initial stack pointer value from address
0x00000000 and the reset vector (start address) from 0x00000004. Then it sets the stack pointer and jumps to the reset handler to begin executing the startup code.Syntax
The boot process uses two key memory addresses in the vector table:
- 0x00000000: Initial Main Stack Pointer (MSP) value.
- 0x00000004: Reset vector address (initial program counter).
The processor reads these values automatically on reset to set up the stack and start execution.
plaintext
Vector Table: 0x00000000: Initial MSP value 0x00000004: Reset Handler address On reset: MSP = *0x00000000 PC = *0x00000004
Example
This example shows a simplified vector table and startup code snippet for an ARM Cortex-M processor.
c
/* Vector table located at start of flash memory */ __attribute__((section(".isr_vector"))) uint32_t vector_table[] = { (uint32_t) &_estack, // Initial MSP value (uint32_t) Reset_Handler, // Reset vector // Other interrupt vectors follow... }; void Reset_Handler(void) { // Initialize data and bss sections // Call main application main(); } int main(void) { // Application code starts here while(1) { // Loop forever } }
Output
Processor starts executing main() after reset handler completes initialization.
Common Pitfalls
Common mistakes during Cortex-M boot include:
- Incorrect vector table placement in memory, causing wrong MSP or PC values.
- Not defining the reset handler properly, leading to undefined behavior.
- Failing to initialize the stack pointer before executing code.
Always ensure the vector table is at the correct memory address and the reset handler is correctly linked.
c
/* Wrong: Vector table not at address 0x0 */ __attribute__((section(".wrong_section"))) uint32_t vector_table[] = { ... }; /* Correct: Vector table placed at start of flash */ __attribute__((section(".isr_vector"))) uint32_t vector_table[] = { ... };
Quick Reference
| Step | Description |
|---|---|
| 1 | Processor reset triggers reading MSP from 0x00000000 |
| 2 | Processor reads reset vector (PC) from 0x00000004 |
| 3 | Stack pointer is set to MSP value |
| 4 | Program counter jumps to reset handler address |
| 5 | Reset handler runs startup code and calls main() |
Key Takeaways
The ARM Cortex-M boots by loading the initial stack pointer and reset vector from fixed memory addresses.
The vector table must be correctly placed at the start of memory for proper boot.
The reset handler initializes the system and starts the main application.
Incorrect vector table placement or missing reset handler causes boot failures.
Understanding the boot sequence helps in debugging startup issues on Cortex-M devices.