2
votes

I am wondering that on a ARM M3 based MCU, what is the benefit of using VTOR register to relocate vector table? The reasons to my understanding is:

  1. The vector table needs to be changed at runtime, and the default address (0x0 is readonly)
  2. Reading from SRAM (say it is relocated to the beginning of SRAM region)is probably faster than the flash region?

Does that mean if all the interrupt handler is defined and known during compilation time, there is no need to use VTOR at all?

3

3 Answers

7
votes

There are many reasons. However I think there are probably three main reasons.

  1. You are using a bootloader, which would be based at 0x00000000. When the bootloader has finished doing its stuff it jumps to the application. The application would likely want to have its own vector table so the bootloader can set the address before starting the app.

  2. You want a RAM based vector table so that you can install different handlers at runtime.

  3. The application might load from some external ROM into RAM before running.

2
votes

Every time when ARM M3 has reset, by default it takes value from address 0x00000000 and put it to SP register and value from address 0x00000004 to PC. This is start point for bootcode execution. This happens because VTOR register is by default set to 0 and vector table start address are set at 0x0000000.

Bootcode checks if there is demand from UART to start with boot code receive new firmware. If there is demand, bootcode receive byte by byte and program FLASH memory with this data received from UART port.

After this job is done, bootcode change VTOR register to 0x08001000 and jump to address 0x0001000 where is new vector table start address. This is start user code

void main() 

This feature with programmable VTOR for Cortex M are excellent and simplified boot code procedure and code. Usually microprocessor/microcontroller has fixed address for vector value.

1
votes

The purpose of such features is bootloaders. For example while a bootloader is programming the flash where the user-defined vector table is located, the MCU will have to use a vector table located elsewhere in the meantime.