cancel
Showing results for 
Search instead for 
Did you mean: 

Vector Table Relocation

Odd Gunnar Dahl
Associate
Posted on December 11, 2017 at 20:04

To make the firmware (flash offset 0x20000) start properly when branched into from my Bootloader (flash offset 0x0), I had to make the following changes to the system_stm32f4xx.c file and define a project symbol 'VECT_TAB_OFFSET=0x20000':

/* &sharpdefine VECT_TAB_SRAM */

&sharpif !defined(VECT_TAB_OFFSET)

&sharpdefine VECT_TAB_OFFSET  0x00 /*!< Vector Table base offset field.

                                   This value must be a multiple of 0x200. */

&sharpendif

Memory regions definition in the linker file:

MEMORY

{

  FLASH (rx)      : ORIGIN = 0x08020000, LENGTH = 896K

  RAM (xrw)       : ORIGIN = 0x20000000, LENGTH = 192K

  MEMORY_B1 (rx)  : ORIGIN = 0x60000000, LENGTH = 0K

  CCMRAM (rw)     : ORIGIN = 0x10000000, LENGTH = 64K

}

Is there a better way to specify the address of the vector table without having to modify any Cube MX generated files?

#vector-table
5 REPLIES 5
Posted on December 11, 2017 at 21:06

Round here we use symbols exported by the linker to do the job, this has been described to ST engineers several times, but they continue to use the #define method

extern void *__Vectors; // Or whatever name your startup.s exports

void SystemInit(void)

{

..

  SCB->VTOR = (uint32_t)&__Vectors; // Let the linker do the job

}

You're going to have to modify something

Tips, buy me a coffee, or three.. PayPal Venmo Up vote any posts that you find helpful, it shows what's working..
Posted on December 12, 2017 at 18:02

 ,

 ,

Thanks for sharing Clive.

Personally I have no issue with the ♯ define itself and modifying one of ST's files would also be acceptable if my modifications didn't get lost each time I regenerate the code in CubeMX.

So, if anybody at ST are monitoring this community and read this, could you please allow modifications to stick in places where you foresee users will add new or modify existing code?

Posted on December 13, 2017 at 11:18

Hello,

I raised your feedback internally to CubeMx team.

Best Regards

Imen

When your question is answered, please close this topic by clicking "Accept as Solution".
Thanks
Imen
Jeanne Joly
Senior III
Posted on February 19, 2018 at 17:41

Hello

Dahl.Odd_Gunnar

,

First of all, sorry for my late answer.

Regarding the user code to add in the generated code, you have the section USER BEGIN and USER END to fill with the code you want. These sections are present in all files under User repertory in the generated code.

If you need a new user section at a particular place in a specific file,please send us your request in order toanalyze it.

BR. Jeanne

Posted on February 19, 2018 at 19:02

 ,

 ,

The deeper point is that you shouldn't have to edit .C files to reflect the address you're going to place them at, this whole ♯ define ,

VECT_TAB_OFFSET nonsense is *NOT* how rational people have solved the issue, you shouldn't have to fiddle with build addresses in multiple places, and keep them orthogonal/coherent, the linker determines where the code is fixated in memory, use symbols. That's what linkers and tools are built to do, there isn't a need for a bunch of human interaction. This is the kind of junior engineer hackary that needs to be purged from the code base by people who understand how tools work.

This stuff is generally in the system_stm32xyz.c files. Grep the source trees for ,

VECT_TAB_OFFSET to grasp the scope.

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