cancel
Showing results for 
Search instead for 
Did you mean: 

How to set VTOR contents from a linker command file

LThal
Associate II

I have the same code that I want to run in several different configurations. I have banked memory. The code will be run from both banks. In order to run the code from bank 2, the VTOR register needs to be set to the IVT address in the second bank. Since the code itself is the same, I'd like to be able to set the VTOR contents in the linker command file. Any ideas? Thanks.

Lee

3 REPLIES 3

So, you link different binaries from the same sources/objects?

Look into the startup code. There's surely some symbol defined at the beginning of the vector table, e.g. looking at [Cube]\Drivers\CMSIS\Device\ST\[STM32xxxxxx]\Source\Templates\gcc\[anyfile.s] I see:

g_pfnVectors:

 .word _estack

 .word Reset_Handler1

 .word NMI_Handler

[etc...]

So it should then be easy to use it in C:

#if defined(__ARMCC_VERSION)

   extern void *__Vectors;

   SCB->VTOR = (unsigned int) &__Vectors;

#elif defined(__IAR_SYSTEMS_ICC__)

   extern void *__vector_table;

   SCB->VTOR = (unsigned int) &__vector_table;

#elif defined(TOOLCHAIN_GCC_ARM)

   extern void *__isr_vector;

   SCB->VTOR = (unsigned int) &__isr_vector;

#else /* defined(__GNUC__) and others */

   extern void *g_pfnVectors;

   SCB->VTOR = (unsigned int) &g_pfnVectors;

#endif

(I've stolen the above code from internet, having gugled for g_pfnVectors and VTOR)

JW

LThal
Associate II

Jan, thanks for the suggestion. However, I need to set VTOR at run time, either when the code image is being loaded, or when it's running. Maybe I should consider setting it at the beginning of my application. I'll have to see if that is soon enough.

Would this do a PC relative load

                LDR     R1, =0xE000ED00 ; SCB
                LDR     R0, =__Vectors ;or  g_pfnVectors
                STR     R0, [R1, #8]    ; VTOR

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..