Notes / Machine Code & Assembly
Vector table: the address book of interrupts
A table holding, in order, the initial stack value and the addresses of the reset, exception and interrupt handlers. Including why a bootloader relocates it.
The vector table is an array of addresses at the very start of Flash.
| Number | Contents |
|---|---|
| 0 | Initial stack pointer value |
| 1 | Reset_Handler |
| 2 | NMI_Handler |
| 3 | HardFault_Handler |
| … | MemManage, BusFault, UsageFault, SVC, PendSV, SysTick |
| 16 onwards | Peripheral interrupts (USART1_IRQHandler, TIM1_UP_IRQHandler …) |
How handlers are connected
The startup file defines every handler name as a weak symbol, defaulting to an infinite loop (Default_Handler). If your code defines a function with the same name, it replaces the default.
void TIM2_IRQHandler(void) { ... } // the name must be exact
With a typo in the name there is no compile error; execution falls into Default_Handler and stops. This is a common cause of "it hangs when the interrupt fires".
Relocating the vector table (VTOR)
If the bootloader is at 0x0800_0000 and the application at 0x0800_8000, set SCB->VTOR = 0x08008000; before jumping so the CPU uses the application's vector table. There is also a technique of copying the vector table to RAM and changing handlers at run time.