0
0
Cnc-programmingConceptBeginner · 3 min read

What is Vector Table in ARM Cortex-M: Explanation and Example

The vector table in ARM Cortex-M is a special memory area that holds the starting addresses of interrupt and exception handlers. It acts like a map that the processor uses to find the correct code to run when an event like an interrupt occurs.
⚙️

How It Works

The vector table is like a directory or a list at the start of the microcontroller's memory. Each entry in this list points to a specific function that handles an interrupt or exception. When an event happens, the processor looks up the vector table to find the address of the handler function it needs to run.

Think of it like a phone book where each phone number corresponds to a different emergency service. If you need the fire department, you look up their number and call them. Similarly, the processor uses the vector table to quickly find and jump to the right handler code.

This table usually starts at a fixed memory address (like 0x00000000) and contains the initial stack pointer value followed by addresses for reset, NMI, hard fault, and other interrupts. This setup allows the processor to respond immediately and correctly to various system events.

💻

Example

This example shows a simplified vector table in C for an ARM Cortex-M microcontroller. It defines the initial stack pointer and handlers for reset and a simple interrupt.

c
typedef void (*ISR)(void);

extern unsigned int _estack; // Defined in linker script

void Reset_Handler(void) {
    // Initialization code here
    while(1) {}
}

void Default_Handler(void) {
    while(1) {}
}

__attribute__((section(".isr_vector")))
ISR vector_table[] = {
    (ISR)&_estack,       // Initial Stack Pointer
    Reset_Handler,       // Reset Handler
    Default_Handler,     // NMI Handler
    Default_Handler,     // Hard Fault Handler
    // Other handlers can be added here
};
🎯

When to Use

The vector table is essential in any ARM Cortex-M based system to manage interrupts and exceptions. You use it whenever you want your microcontroller to respond to events like timers, button presses, or communication signals.

For example, in embedded systems controlling motors or sensors, interrupts allow the processor to react quickly without constantly checking the device status. The vector table ensures the processor knows exactly where to jump when these events happen.

Developers often customize the vector table to add their own interrupt handlers or to relocate it in memory for advanced features like bootloaders or operating systems.

Key Points

  • The vector table holds addresses of interrupt and exception handlers.
  • It starts with the initial stack pointer value.
  • The processor uses it to quickly find the right code to run on events.
  • It is located at a fixed memory address but can be relocated.
  • Customizing the vector table is common in embedded development.

Key Takeaways

The vector table maps interrupts to their handler functions in ARM Cortex-M.
It starts with the initial stack pointer and reset handler addresses.
The processor uses it to respond quickly to interrupts and exceptions.
Customizing the vector table allows control over interrupt handling.
It is a fundamental part of ARM Cortex-M system startup and interrupt management.