An interrupt vector table is data in memory that gives the processor its initial stack pointer and the addresses of reset, exception, and interrupt handlers. On Cortex-M, the processor reads the first two words at reset: the initial Main Stack Pointer (MSP) value and the reset handler address. Later entries identify handlers for other events. section 5.4.5 section 4.2.1
The reset handler prepares memory before application code runs: it copies initialized .data into RAM and clears .bss. For a later exception or interrupt, the processor obtains the handler address from the table and saves context on the active stack. When the handler returns, the context is restored and the interrupted code resumes. section 1.2.2 section 4.5.1
A Cortex-M table has a fixed ordering, though available entries vary by device:
- Entries 0 and 1 hold the initial MSP value and reset handler address. Unlike the other handlers, reset starts privileged thread-mode execution. section 4.2.1 section 4.2.4
- The first 16 entries, numbered 0 through 15, are reserved for system exceptions. Peripheral interrupts follow, starting with IRQ0 at index 16. section 4.5.3
- Reserved entries can be represented by zero; handler entries contain function addresses. Check the device documentation for each peripheral’s IRQ number. section 4.5.3
Finding a timer handler slot
If device documentation maps TIM2 to IRQ28, its handler belongs at table index 44: the 16 initial entries plus 28. Use the IRQ number for the actual device rather than assuming every Cortex-M has the same peripheral layout. section 4.5.3 section 4.2.1
The table is commonly placed at the start of Flash. At reset, the Cortex-M core looks at address 0x00000000; on an STM32F1, boot configuration can alias physical Flash at 0x08000000 to that address. The linker script and the device’s boot mapping must agree on where the processor will find the table. section 4.1.3 section 5.4.5
SECTIONS
{
.vector_table :
{
LONG(ORIGIN(RAM) + LENGTH(RAM)); /* Initial stack pointer (
top of RAM) */
KEEP(*(.vector_table.reset_vector)) /* Reset vector (
entry point) */
KEEP(*(.vector_table.exceptions)) /* Other exceptions and
interrupts */
} > FLASH
This linker-script fragment places the table in Flash, computes the initial stack pointer from the end of RAM, and keeps the reset and exception entries from linker garbage collection. section 4.1.3
Rust symbols can be assigned to the input sections collected by the linker script using #[unsafe(link_section)]. The linker must collect them in the correct order: initial MSP, reset vector, exception table, and device interrupt table. Check especially the MSP, reset, NMI, and hard fault entries: missing, misaligned, or incorrect values can prevent boot or cause unpredictable behavior. section 5.4.5 section 4.2.4
For typical firmware, runtime crates such as cortex-m-rt provide startup and table placement without requiring all the glue to be written by hand. Projects with unusual layouts can customize placement or relocate the table, for example into RAM. section 1.3.3
