Ground Embedded KO Subscribe

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.

GROUND EMBEDDED · NOTEMachine Code & Assembly 07Vector table 1ldr r0, =0x40020014 2ldr r1, [r0] 3orr r1, r1, #0x20 4str r1, [r0] 5bl main 6b .

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 …)
Initial SP0x00Reset0x04NMI0x08HardFault0x0C…Peripheral interrupts
The vector table is a list of addresses at the very start of Flash.

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)

Bootloader's table0x0800_0000Change VTORApp's tableapp start addressApp's handlers are called
When passing from bootloader to application, VTOR is changed to the address of the application's vector table.

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.

FREE PDFGet the 3 free ebooksIf you want to keep reading this topic as one book: BLDC motor control, serial communication and sensors at book length. PDFs are in Korean.Get them free →