2020-04-28 02:37 AM
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);
}
2020-04-28 03:14 AM
I am not sure if this has relation but I am using a custom bootloader that I place in Flash so I had to remap the vector table...
Also I get in the debug window: <signal handler called>() at 0xfffffff9
In the disassembly window:
...
20007fe4: bmi.n 0x20008032
20007fe6: lsrs r0, r0, #32
20007fe8: ldrb r0, [r7, #31]
20007fea: movs r0, #0
20007fec: lsls r0, r0, #8
20007fee: movs r0, r0
20007ff0: ldrb r0, [r7, #31]
20007ff2: movs r0, #0
20007ff4: bcs.n 0x20007f66
20007ff6: lsrs r0, r0, #32
20007ff8: Failed to execute MI command:
-data-disassemble -s 536903672 -e 536903705 -- 3
Error message from debugger back end:
Cannot access memory at address 0x20008000
20007ff9: Failed to execute MI command:
-data-disassemble -s 536903673 -e 536903849 -- 3
Error message from debugger back end:
Cannot access memory at address 0x20008000
20007ffa: Failed to execute MI command:
-data-disassemble -s 536903674 -e 536903850 -- 3
Error message from debugger back end:
Cannot access memory at address 0x20008000
Why this only happens when I use the reset the chip and restart the debug session option and not when I relaunch the debug session?
Thanks a lot in advance!
2020-04-28 06:09 AM
You should examine the SCB register during the hard fault to see the cause of the hard fault. It's not normal for it to be hardfaulting while waiting for HSI to enable.
2020-04-28 06:17 PM
> I am not sure if this has relation but I am using a custom bootloader that I place in Flash so I had to remap the vector table...
Then the bootloader does its job wrongly.
The debugger is smart enough to pick the start address of your image after loading, and executes from that address.
But when you reset, the debugger just lets the MCU go thru its normal hardware reset vector, which ends in your bootloader.
-- pa
2020-04-29 09:29 AM
Thanks a lot guys!!
I will study your advices.... BR