Bare-Metal Startup Basics
Before main() runs, the MCU needs a clean runtime environment. Here’s what happens in a typical bare-metal startup sequence.
Reset vector and stack
The reset handler sets the stack pointer and jumps to the startup routine.
Copy .data, zero .bss
Initialized globals are copied from flash to RAM; uninitialized globals are zeroed.
Clock and peripheral init
System clocks, PLLs, and basic peripherals are configured before drivers run.
Run constructors (C++)
Static constructors are invoked before main() for C++ programs.
Understanding startup makes debugging early-boot issues much easier.