Relocating Interrupt vector to an address in ROM crashes the FW

I am trying to relocate my Interrupt vector from 0x8000000 to 0x8010000. I start the code in debugger and after calling SystemInit, I set the address manually in VTOR in Register window. The program runs fine. But if I call a routine to set VTOR register then program crashes. Here is my routine:

__WEAK void SystemVTORSetup(void)
/* relocate vector table */

SCB->VTOR = (uint32_t)(&__Vectors);

Any help will be highly appreciated


Do you call it as early as possible means BEFORE any interrupt/exception might occur ?
You could set a breakpoint there and run the application to see if you even reach the code adjusting VTOR.
__disable/enable_irq(); doesn’t really help as this function must be invoked before any interupt is enabled.
Usually VTOR adjustment is done in the Reset_Handler before branching to main().

I am calling my routine to change the value in VTOR inside main, after systemInit(), but before my application runs. If changing it manually, this is the place I change manually in the Reg window as well.

Yes, I can put the breakpoint at the code that changes the VTOR value and I see it being changed correctly in the Register window in the debugger

So you can step thru the adjustment function (with interrupts not yet enabled due to MCU reset) and verify the properly changed VTOR value in the debugger ? When does the app crash ?

The app crashes when it tries to start the first task

Hmm … that’s a most likely a completely different issue you should have told earlier.
Standard question is (in case you start using FreeRTOS):
Did you define configASSERT and enable stack checking for development ?
This usually helps a lot to find out and fix initial issues running a FreeRTOS application.
Which FreeRTOS version and which MCU do you use ?
And do you know the valuable FreeRTOS FAQ - links to all RTOS FAQ pages ?

I will give it another try to the FAQ link. Will investigate the StackChecking as well. Thanks for the pointers.

In my opinion, the issue is the Vector address. Because if I dont change the vector address then everything is good.

Well, the address of your vector/exception table __vectors can be verified in the map file (output file of the linker). If the vector table is copied into RAM the address is different of course.

Yes, I have verified it in the map file and it is correct. The Vector table is not relocated in RAM. It is still in ROM

When I work with STM32F[47], the bootloader will use 0x0800000, and put the vector table there.

What platform do you use?

For the application, which starts at eg. 0x08010000, I copy the vector table to SRAM, and have SCB->VTOR point to the first byte in SRAM.

And also I have to configure SYSCFG->MEMRMP to remap SRAM. Note that the method is different in STM32F4 and STM32F7.

  • F4: the vectors are copied to 0x20000000 (SRAM), and address 0x0 is remapped to SRAM (MEMRMP=3).

  • F7: SCB->VTOR is set to point to SRAM (MEMRMP=0)

Here is some code that I used: (877 Bytes)

I’m not sure if it applies to your platform too.

Can we see your map and linker command files? What platform are you using?

Thanks for your help. Really appreciate it. It seems that my setup had some other issues. It runs good now. Thanks again

Thank you for sharing the code. Appreciate it. It will certainly be very helpful
if we decide to move the table to RAM