What Happens Inside a Microcontroller in the First Few Microseconds After Power-On?
When power is applied to a microcontroller, the CPU does not immediately start executing your program.
Instead, a sequence of hardware-controlled steps occurs to prepare the system for execution.
Understanding this startup process helps explain how embedded systems begin running firmware.
1. Power Is Applied
When the device receives power:
Internal circuits begin initializing.
The microcontroller enters a reset state to ensure safe startup.
During this stage, the CPU is held in reset and cannot execute instructions yet.
2. Internal Oscillator Starts
Most microcontrollers start using an internal RC oscillator.
The reason is simple:
It starts very quickly
It does not require external components
It allows the processor to begin operating immediately
This oscillator provides the initial system clock.
3. Reset Controller Holds the CPU
Even though the clock has started, the CPU is still held in reset by the reset controller.
This ensures:
Power is stable
Clock is stable
Internal hardware is ready
Only after these conditions are satisfied will the processor be allowed to run.
4. CPU Released From Reset
Once the system becomes stable, the reset signal is released.
At this moment, the CPU begins executing instructions.
But where does it start executing?
5. Vector Table Is Read
In most modern microcontrollers (such as ARM Cortex-M), the CPU reads a structure called the vector table, which is stored in Flash memory.
The vector table contains important startup information.
The first two entries are:
Address
Description
0x00000000
Initial Stack Pointer value
0x00000004
Reset Handler address
6. Stack Pointer and Program Counter Are Loaded
The processor automatically loads:
SP = *(0x00000000)
PC = *(0x00000004)
The Stack Pointer (SP) is initialized.
The Program Counter (PC) is loaded with the address of the Reset Handler.
7. Reset Handler Executes
The CPU now jumps to the Reset Handler, which is the first piece of firmware executed.
This startup code typically performs tasks such as:
Initializing memory
Copying initialized data to RAM
Clearing uninitialized variables
Configuring system clocks
After these steps are completed, the program eventually reaches the main() function.
Summary
The startup process of a microcontroller follows this sequence:
Power ON
↓
Internal oscillator starts
↓
CPU held in reset
↓
Reset released
↓
Vector table read
↓
Stack Pointer loaded
↓
Program Counter loaded
↓
Reset Handler executes
Only after this sequence does the microcontroller begin running the main application.
#arm
#MCUS
#Microcontrollers
#embeddedsystems
Comments
Post a Comment
Thanks for reading through the Embedded Systems World.
Feel free to ask questions or share your thoughts on the topic.