cancel
Showing results for 
Search instead for 
Did you mean: 

SCB->VTOR = FLASH_BASE | VECT_TAB_OFFSET;

YouXiaoquan
Associate II

I configured a nucleato-L152RE LED program using CubeMX6.17+STM32L1 Firmware Package V1.10.6 and found that the program kept restarting automatically. After adding the following code to the SystemInit() function generated by CubeMX, the problem was solved. What is the reason for this? And my other projects never need to include this line of code, such as F103, F411, G431, L051, and so on.
SCB->VTOR = FLASH_BASE | VECT_TAB_OFFSET;

7 REPLIES 7
mƎALLEm
ST Employee

Hello,

VTOR is the vector table offset register. That should be set at the start. It contains the start address of the interrupts routine list. 

Please refer to "Interrupt and exception vectors" in the RM0008.

"And my other projects never need to include this line of code, such as F103, F411, G431, L051, and so on."

It may be available but you didn't find it.

To give better visibility on the answered topics, please click on "Accept as Solution" on the reply which solved your issue or answered your question.

I added this code only after discovering that there was an issue with initializing the interrupt vector table, but other projects have never manually added this code. They are generated by CubeMX and and can run correctly.

I am quite puzzled as to why the L152 project needs to manually add this code?


@YouXiaoquan wrote:

I added this code only after discovering that there was an issue with initializing the interrupt vector table, but other projects have never manually added this code. They are generated by CubeMX and and can run correctly.


If you are using HAL, it's definitely set in system_stm32f1xx.c / SystemInit ():

#ifdef VECT_TAB_SRAM
  SCB->VTOR = SRAM_BASE | VECT_TAB_OFFSET; /* Vector Table Relocation in Internal SRAM. */
#else
  SCB->VTOR = FLASH_BASE | VECT_TAB_OFFSET; /* Vector Table Relocation in Internal FLASH. */
#endif 

 

To give better visibility on the answered topics, please click on "Accept as Solution" on the reply which solved your issue or answered your question.

But the code generated by CubeMX is like this:

void SystemInit (void)
{
  /* Configure the Vector Table location add offset address ------------------*/
#if defined (USER_VECT_TAB_ADDRESS)
  SCB->VTOR = VECT_TAB_BASE_ADDRESS | VECT_TAB_OFFSET; /* Vector Table Relocation in Internal SRAM */
#endif /* USER_VECT_TAB_ADDRESS */
}

It's grayed out:

mALLEm_0-1776696971937.png

Uncomment this define:

#define USER_VECT_TAB_ADDRESS

I don't know why it is commented out by default.

To give better visibility on the answered topics, please click on "Accept as Solution" on the reply which solved your issue or answered your question.

Other projects have similar annotations. If the default interrupt vector table configuration is used, this macro can be commented out.

I suspect that the VTOR register of L152 was not correctly assigned the default value (0x0x08000000) after power on, which resulted in the need to reassign the correct value in SystemInit().

捕获.PNG