Interrupt Vector Table in RAM Topic is solved

Use this forum for requesting small changes in ChibiOS. Large changes should be discussed in the development forum. This forum is NOT for support.
kdums
Posts: 13
Joined: Tue Oct 17, 2017 4:06 pm
Has thanked: 1 time

Interrupt Vector Table in RAM  Topic is solved

Postby kdums » Tue Nov 09, 2021 8:48 am

Hi!
We need to have the Vector table in RAM, because we can have a problem with code fetch from flash.

Kind regards,
Klaus

We suggest the following change:

--- \os\common\startup\ARMCMx\compilers\GCC\crt0_v7m.S 2020-09-04 09:54:04.000000000 +0100
+++ \os\common\startup\ARMCMx\compilers\GCC\crt0_v7m.S 2021-11-09 08:39:59.000000000 +0100
@@ -197,12 +197,27 @@

/* PSP stack pointers initialization.*/
ldr r0, =__process_stack_end__
msr PSP, r0

#if CRT0_VTOR_INIT == TRUE
+ /* copy Vector Table to RAM */
+ /* Data initialization. Note, it assumes that the DATA size
+ is a multiple of 4 so the linker file must ensure this.*/
+ ldr r1, =_ram_vectors_load
+ ldr r2, =_ram_vectors_start
+ ldr r3, =_ram_vectors_end
+vloop:
+ cmp r2, r3
+ ittt lo
+ ldrlo r0, [r1], #4
+ strlo r0, [r2], #4
+ blo vloop
+
+ /* set base address of Vector Table */
ldr r0, =_vectors
movw r1, #SCB_VTOR & 0xFFFF
movt r1, #SCB_VTOR >> 16
str r0, [r1]
#endif

User avatar
Giovanni
Site Admin
Posts: 13809
Joined: Wed May 27, 2009 8:48 am
Location: Salerno, Italy
Has thanked: 934 times
Been thanked: 797 times
Contact:

Re: Interrupt Vector Table in RAM

Postby Giovanni » Tue Nov 09, 2021 9:52 am

Hi,

I added the initialization code to crt0_v7m.S but the option to enable is CRT0_INIT_VECTORS (CRT0_VTOR_INIT is about initializing the register).

In your linker script you also need to do something like this:

Code: Select all

/* Flash region to be used for exception vectors.*/
REGION_ALIAS("VECTORS_FLASH", ram0);
REGION_ALIAS("VECTORS_FLASH_LMA", flash0);


On startup vectors are copied just before DATA segment initialization. Note that __early_init() is called with vectors still placed in flash, it is mean to be "early" so no initializations are done before calling that.

The code is in trunk, if it is fine for you I will look into back-porting it in 21.11.1.

Giovanni

kdums
Posts: 13
Joined: Tue Oct 17, 2017 4:06 pm
Has thanked: 1 time

Re: Interrupt Vector Table in RAM

Postby kdums » Mon Nov 15, 2021 3:16 pm

Thanks!


Return to “Small Change Requests”

Who is online

Users browsing this forum: No registered users and 1 guest