# Relocating Interrupt vector to an address in ROM crashes the FW

**URL:** <https://forums.freertos.org/t/relocating-interrupt-vector-to-an-address-in-rom-crashes-the-fw/19202>\
**Category:** Libraries\
**Created:** [February 16, 2024, 7:21pm UTC](https://forums.freertos.org/t/relocating-interrupt-vector-to-an-address-in-rom-crashes-the-fw/19202 "2024-02-16T19:21:03Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![jaink](https://avatars.discourse-cdn.com/v4/letter/j/77aa72/32.png) [@jaink](https://forums.freertos.org/u/jaink)\
**Post date:** [February 16, 2024, 7:21pm UTC](https://forums.freertos.org/t/relocating-interrupt-vector-to-an-address-in-rom-crashes-the-fw/19202/1 "2024-02-16T19:21:04Z")

</div>

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 \*/

\_\_disable\_irq();  
SCB-\>VTOR = (uint32\_t)(&\_\_Vectors);  
\_\_DSB();  
\_\_enable\_irq();  
}

Any help will be highly appreciated

Thanks

---

<div class="post-metadata">

**Author:** ![hs2](https://avatars.discourse-cdn.com/v4/letter/h/a4c791/32.png) [@hs2](https://forums.freertos.org/u/hs2)\
**Post date:** [February 16, 2024, 7:33pm UTC](https://forums.freertos.org/t/relocating-interrupt-vector-to-an-address-in-rom-crashes-the-fw/19202/2 "2024-02-16T19:33:53Z")

</div>

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()`.

---

<div class="post-metadata">

**Author:** ![jaink](https://avatars.discourse-cdn.com/v4/letter/j/77aa72/32.png) [@jaink](https://forums.freertos.org/u/jaink)\
**Post date:** [February 16, 2024, 7:37pm UTC](https://forums.freertos.org/t/relocating-interrupt-vector-to-an-address-in-rom-crashes-the-fw/19202/3 "2024-02-16T19:37:53Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![hs2](https://avatars.discourse-cdn.com/v4/letter/h/a4c791/32.png) [@hs2](https://forums.freertos.org/u/hs2)\
**Post date:** [February 16, 2024, 7:43pm UTC](https://forums.freertos.org/t/relocating-interrupt-vector-to-an-address-in-rom-crashes-the-fw/19202/4 "2024-02-16T19:43:12Z")

</div>

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 ?

---

<div class="post-metadata">

**Author:** ![jaink](https://avatars.discourse-cdn.com/v4/letter/j/77aa72/32.png) [@jaink](https://forums.freertos.org/u/jaink)\
**Post date:** [February 16, 2024, 7:43pm UTC](https://forums.freertos.org/t/relocating-interrupt-vector-to-an-address-in-rom-crashes-the-fw/19202/5 "2024-02-16T19:43:47Z")

</div>

The app crashes when it tries to start the first task

---

<div class="post-metadata">

**Author:** ![hs2](https://avatars.discourse-cdn.com/v4/letter/h/a4c791/32.png) [@hs2](https://forums.freertos.org/u/hs2)\
**Post date:** [February 16, 2024, 7:47pm UTC](https://forums.freertos.org/t/relocating-interrupt-vector-to-an-address-in-rom-crashes-the-fw/19202/6 "2024-02-16T19:47:02Z")

</div>

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](https://www.freertos.org/Stacks-and-stack-overflow-checking.html) 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](https://freertos.org/FAQ.html) ?

---

<div class="post-metadata">

**Author:** ![jaink](https://avatars.discourse-cdn.com/v4/letter/j/77aa72/32.png) [@jaink](https://forums.freertos.org/u/jaink)\
**Post date:** [February 16, 2024, 7:49pm UTC](https://forums.freertos.org/t/relocating-interrupt-vector-to-an-address-in-rom-crashes-the-fw/19202/7 "2024-02-16T19:49:38Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![hs2](https://avatars.discourse-cdn.com/v4/letter/h/a4c791/32.png) [@hs2](https://forums.freertos.org/u/hs2)\
**Post date:** [February 16, 2024, 8:36pm UTC](https://forums.freertos.org/t/relocating-interrupt-vector-to-an-address-in-rom-crashes-the-fw/19202/8 "2024-02-16T20:36:00Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![jaink](https://avatars.discourse-cdn.com/v4/letter/j/77aa72/32.png) [@jaink](https://forums.freertos.org/u/jaink)\
**Post date:** [February 16, 2024, 9:30pm UTC](https://forums.freertos.org/t/relocating-interrupt-vector-to-an-address-in-rom-crashes-the-fw/19202/9 "2024-02-16T21:30:54Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![htibosch](https://d3iykfbgfh8zhg.cloudfront.net/user_avatar/forums.freertos.org/htibosch/32/62_2.png) [@htibosch](https://forums.freertos.org/u/htibosch)\
**Post date:** [February 17, 2024, 4:49am UTC](https://forums.freertos.org/t/relocating-interrupt-vector-to-an-address-in-rom-crashes-the-fw/19202/10 "2024-02-17T04:49:41Z")

</div>

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:

[remap\_vtor\_table\_to\_ram.zip](https://forums.freertos.org/uploads/short-url/pS7U5QbT1XZgbieIWl79Tnqm4d4.zip) (877 Bytes)

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

---

<div class="post-metadata">

**Author:** ![RAc](https://d3iykfbgfh8zhg.cloudfront.net/user_avatar/forums.freertos.org/rac/32/1389_2.png) [@RAc](https://forums.freertos.org/u/RAc)\
**Post date:** [February 17, 2024, 8:09am UTC](https://forums.freertos.org/t/relocating-interrupt-vector-to-an-address-in-rom-crashes-the-fw/19202/11 "2024-02-17T08:09:07Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![jaink](https://avatars.discourse-cdn.com/v4/letter/j/77aa72/32.png) [@jaink](https://forums.freertos.org/u/jaink)\
**Post date:** [February 17, 2024, 1:08pm UTC](https://forums.freertos.org/t/relocating-interrupt-vector-to-an-address-in-rom-crashes-the-fw/19202/12 "2024-02-17T13:08:22Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![jaink](https://avatars.discourse-cdn.com/v4/letter/j/77aa72/32.png) [@jaink](https://forums.freertos.org/u/jaink)\
**Post date:** [February 17, 2024, 1:09pm UTC](https://forums.freertos.org/t/relocating-interrupt-vector-to-an-address-in-rom-crashes-the-fw/19202/13 "2024-02-17T13:09:32Z")

</div>

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