SoC
  • Home
  • Arm
  • Arm Cortex M0/M0+
  • Arm Cortex M4
  • Arm Cortex M3
  • Contact
Reading: What is Vector Table Offset Register (VTOR) in Arm Cortex-M series?
SUBSCRIBE
SoCSoC
Font ResizerAa
  • Home
  • Arm
  • Arm Cortex M0/M0+
  • Arm Cortex M4
Search
  • Home
  • Arm
  • Arm Cortex M0/M0+
  • Arm Cortex M4
Have an existing account? Sign In
Follow US
  • Looking for Something?
  • Privacy Policy
  • About Us
  • Sitemap
  • Contact Us
© S-O-C.ORG, All Rights Reserved.
Arm

What is Vector Table Offset Register (VTOR) in Arm Cortex-M series?

Scott Allen
Last updated: September 17, 2023 1:14 pm
Scott Allen 8 Min Read
Share
SHARE

The Vector Table Offset Register (VTOR) is a key register in Arm Cortex-M series processors that controls the location of the vector table in memory. The vector table contains the reset value for the stack pointer and the exception vector entries which hold the addresses of interrupt service routines. By changing the VTOR, the vector table can be relocated to a different memory region. This provides flexibility in placing the vector table in read-only memory or RAM based on application requirements.

Contents
Overview of Vector Table in Cortex-MVTOR Register DetailsRelocating Vector Table using VTOR1. Vector Table in Flash Memory (Default)2. Vector Table Relocated to RAM3. Vector Table in ROMVTOR Configuration in Cortex-MUsing VTOR to Configure Vector Table Location1. Default Vector Table in Flash2. Relocated Vector Table in RAMAdvantages of VTOR RelocationUse Cases for VTOR Relocation

Overview of Vector Table in Cortex-M

On reset or power-up, the Cortex-M processor loads the initial stack pointer value and starts execution at the reset vector located at the start of the vector table. The vector table is an array of exception vectors, with each vector consisting of a 32-bit address pointing to an exception handler routine. For Cortex-M3 and M4, the vector table comprises up to 240 vectors and occupies up to 0x600 bytes of memory. For Cortex-M0/M0+, the vector table size is reduced with up to 32 vectors occupying 0x80 bytes.

The vector table can be placed in read-only memory or RAM. Placing it in ROM saves RAM space while locating it in RAM allows dynamic updating of vector addresses. The VTOR register controls the starting address of the vector table. On reset, the processor loads the VTOR with the start address of the vector table which is typically 0x00000000 in flash memory. The processor fetches the initial stack pointer and exception vectors from this VTOR-defined vector table base address.

VTOR Register Details

The VTOR register is a 32-bit writeable CPU register present in all Cortex-M variants. It specifies a byte-aligned offset which gets added to the vector table base address defined in the system memory map. This provides the actual start address of the vector table. The VTOR offset can be changed dynamically to relocate the vector table.

The VTOR supports alias addresses 0xE000ED08, 0xE000ED0C and 0xE000ED10. Writing to any of these addresses updates the VTOR value. On reset, the processor loads the VTOR with the fixed vector table base address which is 0x00000000 for Cortex-M0/M0+ and 0x00000004 for Cortex-M3/M4. This maps the vector table to the start of the code memory region.

Bit[8:0] of the VTOR hold the offset value added to the vector table base address. The upper bits [31:9] are reserved. The offset can specify a 4KB aligned address range for the vector table anywhere in the 4GB memory space.

Relocating Vector Table using VTOR

Modifying the VTOR allows flexible positioning of the vector table in processor memory space. It can be moved to RAM for dynamic vector entries. Or it can be placed in read-only memory to save RAM space. Let’s look at how VTOR can relocate the vector table:

1. Vector Table in Flash Memory (Default)

By default, the vector table resides at the start of flash memory in the Cortex-M memory map. For this default mapping:

  • VTOR holds the flash base address (0x00000000 for M0/M0+, 0x00000004 for M3/M4).
  • No offset added to the base address.
  • Vector table positioned at the start of flash.

2. Vector Table Relocated to RAM

The VTOR can be programmed to relocate the vector table to RAM. For example:

  • MAP RAM to address 0x20000000 in memory map
  • Set VTOR to 0x20000000
  • Offset of 0x20000000 added to flash base address
  • Vector table now positioned at start of RAM

This allows dynamic modification of exception vectors.

3. Vector Table in ROM

To save RAM space, the vector table can also be placed in ROM via VTOR:

  • MAP ROM to address 0x10000000
  • Configure VTOR to 0x10000000
  • 0x10000000 offset added to flash base
  • Vector table located in ROM saving RAM.

VTOR Configuration in Cortex-M

The VTOR register can be configured and modified in different ways:

  • Startup code: The VTOR is typically configured in the processor startup code based on the memory map.
  • CMSIS functions: The CMSIS core header files provide API functions to set the VTOR value at runtime.
  • Direct access: VTOR can be directly written to in code via its alias addresses.
  • Debug probe: The VTOR can be modified via the debug interface using a debug probe.

This enables flexible positioning of the vector table by altering the VTOR dynamically as required.

Using VTOR to Configure Vector Table Location

Here is an example demonstrating how VTOR can be used to configure the vector table location in Cortex-M:

1. Default Vector Table in Flash

/* Flash memory starts at 0x08000000 */ /* Default vector table positioned at start of flash */ VTOR = 0x00000000; /* Exception vectors point to ISRs in flash */ Vector[0] = *((volatile uint32_t *)(VTOR + 0x00)); /* Reset ISR */ Vector[1] = *((volatile uint32_t *)(VTOR + 0x04)); /* NMI ISR */ …..

2. Relocated Vector Table in RAM

/* MAP RAM at 0x20000000 */ /* Relocate vector table to RAM */ VTOR = 0x20000000; /* Vectors now point to ISRs in RAM */ Vector[0] = *((volatile uint32_t *)(VTOR + 0x00)); /* Reset ISR */ Vector[1] = *((volatile uint32_t *)(VTOR + 0x04)); /* NMI ISR */ …..

This demonstrates VTOR’s ability to remap the vector table location in Cortex-M flash to RAM or ROM.

Advantages of VTOR Relocation

Key benefits of using VTOR to relocate the vector table include:

  • Position vector table in RAM for dynamic vector entries
  • Locate vector table in ROM to conserve RAM usage
  • Update vector addresses by modifying VTOR at runtime
  • Customize vector table placement for different applications
  • Provide flexibility in vector table memory mapping
  • Enable table placement in memory optimal for performance

Use Cases for VTOR Relocation

Some examples where modifying VTOR to relocate the vector table is useful:

  • Bootloaders: Position vector table in ROM separate from application area.
  • OS kernels: Move table to RAM for context switching between processes.
  • No-OS applications: Locate table in RAM for high-speed ISR switching.
  • Memory-constrained devices: Place table in ROM to conserve RAM.
  • Security apps: Isolate vector table from rest of code for protection.

Overall, intelligent VTOR configuration provides great flexibility in Cortex-M vector table placement to optimize performance, memory usage, and security.

Newsletter Form (#3)

More ARM insights right in your inbox

 


Share This Article
Facebook Twitter Email Copy Link Print
Previous Article What is ECC for TCM and Cache in Arm Cortex-M series?
Next Article What is ARMv6-M in Arm Cortex-M series?
Leave a comment Leave a comment

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

2k Followers Like
3k Followers Follow
10.1k Followers Pin
- Sponsored-
Ad image

You Might Also Like

How to activate Eventrecorder together with RTX5 using Cortex-M0?

Activating the Eventrecorder together with RTX5 on a Cortex-M0 microcontroller…

7 Min Read

Interrupt Handling During Multi-Cycle Atomic Operations in ARM Cortex M3

The ARM Cortex M3 processor implements interrupt handling in a…

5 Min Read

How Many Registers Are Provided in Arm Cortex-M0?

The ARM Cortex-M0 is the smallest and simplest processor in…

7 Min Read

ARM FPU Instruction Set

The ARM Floating Point Unit (FPU) provides hardware support for…

7 Min Read
SoCSoC
  • Looking for Something?
  • Privacy Policy
  • About Us
  • Sitemap
  • Contact Us
Welcome Back!

Sign in to your account