2026-04-20 7:12 AM
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;
2026-04-20 7:21 AM
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.
2026-04-20 7:31 AM
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.
2026-04-20 7:33 AM
I am quite puzzled as to why the L152 project needs to manually add this code?
2026-04-20 7:36 AM - edited 2026-04-20 7:36 AM
@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
2026-04-20 7:39 AM
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 */
}
2026-04-20 7:58 AM
It's grayed out:
Uncomment this define:
#define USER_VECT_TAB_ADDRESS
I don't know why it is commented out by default.
2026-04-20 6:42 PM
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().