The microcontroller boot process is the sequence of events that occurs when a microcontroller is turned on or reset. The boot process typically includes the following steps:
- Power-on reset. When power is applied to the microcontroller, the reset pin is pulled low. This causes the microcontroller to enter a reset state.
- Fetching the reset vector. The microcontroller’s processor fetches the address of the reset vector from a special location in memory called the reset vector address.
- Executing the reset vector. The processor executes the instructions at the reset vector address. These instructions typically initialize the microcontroller’s hardware and prepare it for operation.
- Calling the main function. The processor calls the main function of the user’s application code. This is where the user’s application code begins execution.
The exact steps involved in the microcontroller boot process may vary depending on the specific microcontroller. However, the general steps outlined above are common to all microcontrollers.
Here is a more detailed explanation of each step in the microcontroller boot process:
Power-on reset
When power is applied to the microcontroller, the reset pin is pulled low. This causes the microcontroller to enter a reset state. In this state, the microcontroller’s processor is halted and its memory is erased.
Fetching the reset vector
The microcontroller’s processor fetches the address of the reset vector from a special location in memory called the reset vector address. The reset vector address is typically 0x0000.
Executing the reset vector
The processor executes the instructions at the reset vector address. These instructions typically initialize the microcontroller’s hardware and prepare it for operation. Some of the tasks that may be performed during the reset process include:
- Configuring the clock system
- Initializing the memory system
- Configuring the peripherals
- Clearing the uninitialized data segment
- Setting the stack pointer
Calling the main function
The processor calls the main function of the user’s application code. This is where the user’s application code begins execution. The main function is typically the first function that is called when the microcontroller is booted up.
The microcontroller boot process is a complex and important process. It is essential that the boot process is performed correctly in order for the microcontroller to operate properly.
Sample code:
// Declare the reset handler as the entry point for the application
void Reset_Handler(void);
// Define the vector table with the reset handler as the first entry
__attribute__((section(".isr_vector")))
void(*const g_pfnVectors[])(void) = { (void(*)(void))((uint32_t) &_estack), // The initial stack pointer
Reset_Handler, // The reset handler
// Other exception handlers
};
// The reset handler implementation
void Reset_Handler(void)
{
// Initialize the system clock and peripheral clocks
SystemInit();
// Enable the FPU if present
#
ifdef __FPU_PRESENT
SCB->CPACR |= ((3 UL << 10 *2) | (3 UL << 11 *2));#
endif
// Initialize global data variables
uint32_t *pSrc = &_sidata;
for (uint32_t *pDest = &_sdata; pDest<&_edata;)
{
*pDest++ = *pSrc++;
}
// Zero-initialize global and static variables
for (uint32_t *pDest = &_sbss; pDest<&_ebss;)
{
*pDest++ = 0;
}
// Call the application entry point
main();
}
- The MCU is powered on.
- The MCU checks the voltage rails to ensure that they are within the correct range.
- The MCU initializes the oscillator.
- The MCU copies the reset vector from flash memory to RAM.
- The MCU executes the instructions in the reset vector.
- The MCU initializes the peripherals.
- The MCU calls the main() function of the user’s application.
The MCU boot process is a critical part of ensuring that the MCU starts up correctly. If any of the steps in the boot process fail, the MCU may not start up correctly or may not function properly.