Course contentsShow
← Embedded Systems & Computer Architecture
Lesson 229 of 9363. Microcontroller Fundamentals and Bare-Metal CFree lesson

Placing the Vector Table at Fixed Hardware Addresses

Learners will ensure the interrupt vector table is positioned precisely at the beginning of FLASH memory to satisfy processor boot requirements.

In this lesson, you will learn how to anchor your interrupt vector table to the exact memory address required by the CPU to initiate a successful boot process.

The Processor’s Starting Line

When you press the reset button, the CPU does not know how to run your main() function automatically. Instead, it looks at a specific, hard-coded memory address (often 0x00000000 or 0x08000000 in many ARM Cortex-M microcontrollers) to find the Vector Table.

The Vector Table is simply an array of function pointers. The first entry is the initial stack pointer value, and the second entry is the "Reset Vector," which holds the memory address of your startup code. If this table is not exactly where the hardware expects it, the CPU will fetch junk data, jump to an invalid memory location, and immediately trigger a hard fault.

Enforcing Placement with the Linker Script

To ensure the table sits at the start of your FLASH memory, we use the MEMORY and SECTION commands in our linker script. We define the FLASH region, and then we force the vector table section to be the very first object placed inside that region.

MEMORY
{
    FLASH (rx) : ORIGIN = 0x08000000, LENGTH = 512K
}

SECTIONS
{
    .vectors :
    {
        . = ALIGN(4);
        KEEP(*(.isr_vector)) /* Keep this even if it looks unused */
        . = ALIGN(4);
    } > FLASH
}

By using the KEEP command, we prevent the linker from "optimizing away" the vector table, even if the compiler thinks it isn't being called by your C code (which it isn't—the hardware calls it directly). By placing this block at the top of the SECTIONS command, we ensure it occupies the lowest address in the FLASH memory region, matching the processor's hard-wired boot expectation.

If your vector table is even one byte offset from the required hardware address, the CPU will fail to find the reset handler, and your system will be effectively "bricked" from the perspective of a cold boot.

Key Takeaway: The Vector Table must be placed at the absolute beginning of your FLASH memory region to provide the CPU with the startup addresses it needs to execute your code upon reset.