cancel
Showing results for 
Search instead for 
Did you mean: 

STM32CubeIDE 1.7, MCU package L4 Series 1.17 : VTOR is not initialized

MFred.2
Associate III

In file generated by CubeMx when creating a new project, the SystemInit function does not set the register of the interrupt vector table (SCB-> VTOR) !!!

The default value is zero, which causes a crash on the first interrupt trigger, i.e. the code loops to an address 0x1FFFxxxx (system memory)

  1. freshly generated code

/**

 * @brief Setup the microcontroller system.

 * @retval None

 */

void SystemInit(void)

{

#if defined(USER_VECT_TAB_ADDRESS)

 /* Configure the Vector Table location -------------------------------------*/

 SCB->VTOR = VECT_TAB_BASE_ADDRESS | VECT_TAB_OFFSET;

#endif

 /* FPU settings ------------------------------------------------------------*/

#if (__FPU_PRESENT == 1) && (__FPU_USED == 1)

 SCB->CPACR |= ((3UL << 20U)|(3UL << 22U)); /* set CP10 and CP11 Full Access */

#endif

 /* Reset the RCC clock configuration to the default reset state ------------*/

...

code of the previous version of the package

/**

 * @brief Setup the microcontroller system.

 * @param None

 * @retval None

 */

void SystemInit(void)

{

 /* FPU settings ------------------------------------------------------------*/

 #if (__FPU_PRESENT == 1) && (__FPU_USED == 1)

   SCB->CPACR |= ((3UL << 10*2)|(3UL << 11*2)); /* set CP10 and CP11 Full Access */

 #endif

 /* Reset the RCC clock configuration to the default reset state ------------*/

 /* Set MSION bit */

 RCC->CR |= RCC_CR_MSION;

 /* Reset CFGR register */

 RCC->CFGR = 0x00000000U;

 /* Reset HSEON, CSSON , HSION, and PLLON bits */

 RCC->CR &= 0xEAF6FFFFU;

 /* Reset PLLCFGR register */

 RCC->PLLCFGR = 0x00001000U;

 /* Reset HSEBYP bit */

 RCC->CR &= 0xFFFBFFFFU;

 /* Disable all interrupts */

 RCC->CIER = 0x00000000U;

 /* Configure the Vector Table location add offset address ------------------*/

#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

}

why this register is no longer set with the default flash memory address ?

Thanks for your help

1 ACCEPTED SOLUTION

Accepted Solutions
Imen.D
ST Employee

Hello @MFred.2​ ,

There is a change request which is deployed on all STM32 series:

the purpose is to set SCB->VTOR only when requested by user application. This is for protect Vector table modification following SRAM or FLASH preprocessor directive by a generic preprocessor directive : USER_VECT_TAB_ADDRESS

So, the following lines from the previous version of the package:

/* Configure the Vector Table location add offset address ------------------*/
#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
 

are updated as follow:

#if defined(USER_VECT_TAB_ADDRESS)
  /* Configure the Vector Table location -------------------------------------*/
  SCB->VTOR = VECT_TAB_BASE_ADDRESS | VECT_TAB_OFFSET;
#endif

If user want to force SCB-> VTOR configuration at start-up level, he shall just uncomment this line (Line 127) in system_stm32l4xx.c file:

/*!< Uncomment the following line if you need to relocate the vector table
     anywhere in Flash or Sram, else the vector table is kept at the automatic
     remap of boot address selected */
 
/* #define USER_VECT_TAB_ADDRESS */

Note that the system_stm32l4xx.c available in CMSIS file is provided as template file and user shall copy/past this file in his application and customize it as he wants.

I hope that is clear now 🙂.

Thanks for your contribution and do not hesitate to raise any issue/ feedback.

If you issue is solved, please close this post by clicking the "Select as Best" button. This will help other members of the community find this response more quickly 🙂

Imen

When your question is answered, please close this topic by clicking "Accept as Solution".
Thanks
Imen

View solution in original post

11 REPLIES 11

Trying to understand why, and why this wasn't done with symbols the linker could fix-up, will give anyone migraines..

Little appears to get tested, or scrutinized by QA

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

Your code have other issue, because this

#if defined(USER_VECT_TAB_ADDRESS)
 /* Configure the Vector Table location -------------------------------------*/
 SCB->VTOR = VECT_TAB_BASE_ADDRESS | VECT_TAB_OFFSET;
#endif

isnt used, and VTOR is initialized ok by HW. I have project with same SystemInit and works without problems.

But yes this defines seems as bug migraines

MFred.2
Associate III

Indeed, without setting VTOR, the code sometimes works depending on the configuration of the peripherals in CubeMx. I have encountered this same problem with the default NUCLEO L4XX board projects. Really very strange.

I do not understand the purpose of this modification !!!

Imen.D
ST Employee

Hello @MFred.2​ ,

There is a change request which is deployed on all STM32 series:

the purpose is to set SCB->VTOR only when requested by user application. This is for protect Vector table modification following SRAM or FLASH preprocessor directive by a generic preprocessor directive : USER_VECT_TAB_ADDRESS

So, the following lines from the previous version of the package:

/* Configure the Vector Table location add offset address ------------------*/
#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
 

are updated as follow:

#if defined(USER_VECT_TAB_ADDRESS)
  /* Configure the Vector Table location -------------------------------------*/
  SCB->VTOR = VECT_TAB_BASE_ADDRESS | VECT_TAB_OFFSET;
#endif

If user want to force SCB-> VTOR configuration at start-up level, he shall just uncomment this line (Line 127) in system_stm32l4xx.c file:

/*!< Uncomment the following line if you need to relocate the vector table
     anywhere in Flash or Sram, else the vector table is kept at the automatic
     remap of boot address selected */
 
/* #define USER_VECT_TAB_ADDRESS */

Note that the system_stm32l4xx.c available in CMSIS file is provided as template file and user shall copy/past this file in his application and customize it as he wants.

I hope that is clear now 🙂.

Thanks for your contribution and do not hesitate to raise any issue/ feedback.

If you issue is solved, please close this post by clicking the "Select as Best" button. This will help other members of the community find this response more quickly 🙂

Imen

When your question is answered, please close this topic by clicking "Accept as Solution".
Thanks
Imen

Thank you for this feedback

I understood this possibility of customizing the vector table, but I am not convinced by this new code. It breaks compatibility with all previous versions. In 98% of cases, the vector table is defined at the beginning of flash memory.

The interest of CubeMX is to generate a code template for people who are not necessarily micro-controller experts and which works without asking too much questions.

I have been using the Cube environment since the acquisition of Attolic Truestudio, and I was tricked by this code change. And it is not the innocuous sentence in the "CMSIS release note" file (Update VTOR configuration to be modified by user) which helped me.

Otherwise, I think the code below would have been better

#if defined(USER_VECT_TAB_ADDRESS)
      /* Configure the Vector Table location -------------------------------------*/
      SCB->VTOR = VECT_TAB_BASE_ADDRESS | VECT_TAB_OFFSET;
#else
      /* Vector Table Relocation in Internal FLASH */
     SCB->VTOR = FLASH_BASE | VECT_TAB_OFFSET;
#endif
 
 

best regards

Frederic

MFred.2
Associate III

Maybe it would be good to show this vector table configuration in the Project Manager tab of CubeMx?

best regards

Frederic

Thanks Frederic for taking the time to post your feedback. I will escalate this internally to the appropriate team.

Hi @Khouloud OTHMAN​ , @Khouloud ZEMMELI​ ,

Can you please take Frederic's request regarding the CubeMX part ?

Thanks

Imen

When your question is answered, please close this topic by clicking "Accept as Solution".
Thanks
Imen

I just spent 2 weeks of nightmare because of this. I have 2 old projects with a STM32L476 that were written with AC6 System Workbench. I needed a little modification on one of these and converted it to use CubeIDE and ... the bank switching didn't work anymore...I checked compiler options and ioc file many times, created a new simple blink led project that didn't work.

If there had been something in CubeMX I wouldn't have lost that much time figuring out what went wrong. I understand this change, but pleeeaase try to preserve backward compatibility by default when introducing such things.

This is still an issue.
I spent 2 hours trying to get a "blink led" working on an STM32G0 due to this.
The default behaviour shouldn't wind up with "HAL_Delay" causing a jump to random program space and a locked up MCU. Needing to find this thread then edit some random file before "blink LED" code works is not a useful pattern. If people are doing the fancy bits by all means allow them to do so, but the whole point of the pointy clicky cubemx setup is to make the basics work for most people most of the time.