cancel
Showing results for 
Search instead for 
Did you mean: 

STM32 Bootloader Vector table relocation problem which is linked with CubeMX version

BBİNG.11
Associate II

Hello All,

I need to start the flash program from 0x08020000 origin. I have updated the linker file with that value as you can see at below.

/* Memories definition */
MEMORY
{
  RAM    (xrw)    : ORIGIN = 0x20000000,   LENGTH = 64K
  FLASH    (rx)    : ORIGIN = 0x8020000,   LENGTH = 128K //previous one was 256K
}

Indeed, I have updated the vector table register which is VTOR from system_stm32f4xx.c. You can see the SystemInit function at below.

/*!< Uncomment the following line if you need to relocate your vector Table in
     Internal SRAM. */
/* #define VECT_TAB_SRAM */
#define VECT_TAB_OFFSET 0x00 /*!< Vector Table base offset field. //0x00
                                   This value must be a multiple of 0x200. */
/******************************************************************************/
 
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 HSION bit */
    RCC->CR |= (uint32_t)0x00000001;
 
    /* Reset CFGR register */
    RCC->CFGR = 0x00000000;
 
    /* Reset HSEON, CSSON and PLLON bits */
    RCC->CR &= (uint32_t)0xFEF6FFFF;
 
    /* Reset PLLCFGR register */
    RCC->PLLCFGR = 0x24003010;
 
    /* Reset HSEBYP bit */
    RCC->CR &= (uint32_t)0xFFFBFFFF;
 
    /* Disable all interrupts */
    RCC->CIR = 0x00000000;
 
#if defined (DATA_IN_ExtSRAM) || defined (DATA_IN_ExtSDRAM)
  SystemInit_ExtMemCtl(); 
#endif /* DATA_IN_ExtSRAM || DATA_IN_ExtSDRAM */
 
  /* 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 = 0x08020000UL | VECT_TAB_OFFSET; /* Vector Table Relocation in Internal FLASH */
#endif
}

When I configure and compile this project with STM32CubeMX version 5.0.0, everything works fine. However, when I configure and compile this project with STM32CubeMX version 6.1.1, I receive independent watchdog timer reset. What would be the source of problem? It costs my 2-3 days approximately. How can i solve the problem? Thanks in advance.

12 REPLIES 12
BBİNG.11
Associate II

So, the MCU is STM32F401RCT6.

>>What would be the source of problem?

Sounds like the watchdog timer not being kicked.

Does the loader application at 0x08000000 start the watchdog?

Does your system Hard Fault, or otherwise enter an infinite while loop?

Are you sure its not in the Default Handler because the loader started an interrupt you're not servicing?

Instrument your system, especially the Hard Fault and Error Handlers so you know what's happening in your own system.

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

As I mentioned, the system is working accurately with CubeMX version 5.0.0, but it doesn't work above 5.0.0. Some questions have answers with this information.

I have also debugged the system, the system enters hard fault and VTOR register returns the FLASH_BASE value which is 0x08000000. __HAL_RCC_GET_FLAG(RCC_FLAG_IWDGRST) flag is triggered as well.

So you compare the sources produced by different Cube version and... ?

--pa

Not sure I'm going to introspect of the failings of CubeMX

So assuming it Hard Faults, and then watchdogs because it doesn't leave.

Instrument the Hard Fault Handler, dump the registers and look at exactly what's faulting, and work backward from there.

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

Maybe you dont properly understand init, you dont edit code, instead this you need set define value

#define VECT_TAB_OFFSET 0x20000 /*!< Vector Table base offset field. //0x00

too you realy use 128k as bootloader code , so big?

Personally I just set the SCB->VTOR to the vector table symbol and dispense with all the smoke and mirrors ORing values together that aren't synchronized to what the linker actually built.

But yes the size of the thing does suggest there is a kitchen sink full of issues, especially with the contract/handoff with the application

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

Dear All,

I have solved the problem. I have compared all the c and header files between previous version and updated version of stmcubeMX.

I detected that there is a difference between main.c files as you can see at below:

void Error_Handler(void)
{
  /* USER CODE BEGIN Error_Handler_Debug */
  /* User can add his own implementation to report the HAL error return state */
  __disable_irq();
  while (1)
  {
  }
  /* USER CODE END Error_Handler_Debug */
}

The updated one contains these lines. When the progam enters error_handler, irq is disabled and entered to infinite loop.

Previous one doesn't contain these lines. When I disable these lines, the program works accurately.

Do you have any idea about what's going on ?

Thanks in advance.

BBİNG.11
Associate II

So, the system enters to Error_Handler();

void SystemClock_Config(void)
{
  if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
  {
    Error_Handler();
  }
}

There is a problem about RCC_OscConfig as far as I understand. What may be the problem ?