STM32CubeIDE reset the chip and restart debug produces hard fault interrupt
Hi guys,
I am using STM32CubeIDE so I use the generated code to initlialize my STM32F030C micro (clock configuration code below). When I hit debug from my C perpective the software compiles and launches the debug session ... everything works flawlessly. But if I want to reset the chip and restart de debug session as I used to do with Atollic I get a hard fault interrupt if I just hit the Resume play icon (F8).
The HardFault_Handler is triggered normally in the first while loop Wait till HSI s ready although sometimes if I debug step by step it can be stuck in other while loop. Eventually If I debug step by step sometimes it get through the system clock configuration, and the pogram execution starts fine...
The work around this is to use terminate and relaunch but this involves a slow flash rewrite process which it is not needed.
Any ideas why this may be happening?
Thanks a lot in advance!
void SystemClock_Config(void)
{
LL_FLASH_SetLatency(LL_FLASH_LATENCY_0);
if(LL_FLASH_GetLatency() != LL_FLASH_LATENCY_0)
{
Error_Handler();
}
LL_RCC_HSI_Enable();
/* Wait till HSI is ready */
while(LL_RCC_HSI_IsReady() != 1)
{
}
LL_RCC_HSI_SetCalibTrimming(16);
LL_RCC_HSI14_Enable();
/* Wait till HSI14 is ready */
while(LL_RCC_HSI14_IsReady() != 1)
{
}
LL_RCC_HSI14_SetCalibTrimming(16);
LL_RCC_LSI_Enable();
/* Wait till LSI is ready */
while(LL_RCC_LSI_IsReady() != 1)
{
}
LL_PWR_EnableBkUpAccess();
LL_RCC_ForceBackupDomainReset();
LL_RCC_ReleaseBackupDomainReset();
LL_RCC_SetRTCClockSource(LL_RCC_RTC_CLKSOURCE_LSI);
LL_RCC_EnableRTC();
LL_RCC_SetAHBPrescaler(LL_RCC_SYSCLK_DIV_1);
LL_RCC_SetAPB1Prescaler(LL_RCC_APB1_DIV_1);
LL_RCC_SetSysClkSource(LL_RCC_SYS_CLKSOURCE_HSI);
/* Wait till System clock is ready */
while(LL_RCC_GetSysClkSource() != LL_RCC_SYS_CLKSOURCE_STATUS_HSI)
{
}
LL_SetSystemCoreClock(8000000);
/* Update the time base */
if (HAL_InitTick (TICK_INT_PRIORITY) != HAL_OK)
{
Error_Handler();
};
LL_RCC_HSI14_EnableADCControl();
LL_RCC_SetUSARTClockSource(LL_RCC_USART1_CLKSOURCE_PCLK1);
LL_RCC_SetI2CClockSource(LL_RCC_I2C1_CLKSOURCE_HSI);
}