STM32L151 fails to boot with CubeIDE autogenerated code
- 3 replies
- 1446 views
Hi everyone,
I recently triggered a bug in multiple projects using the same MCU STM32L151ZC. When booting the CPU I reproducibly get an assert_failed() call from HAL_RCC_OscConfig(). I created a clean project in CubeIDE to analyse the problem, which I attached. With this everyone should be able to reproduce the error. The only modifications I made to the autogenerated code are enabling the USE_FULL_ASSERT macro and forwarding all failure interrupts to Error_Handler().
Letting the code run in debug mode, triggers the assert_param() macro in stm32l1xx_hal_rcc.c line 692. This can be traced down to a wrong value (not the value thats written in the code) being written to RCC_OscInitStruct.PLL.PLLSource in SystemClock_Config(). Braking the execution before this line of code and stepping over it leads to the correct value being stored. Breaking right after this line of code leads to an 65535 being written instead of the correct value.
From what I found so far, it looks like the value of the line above (RCC_PLLSOURCE_HSE) gets written both to PLLState and PLLSource. When reordering the lines the double written value changes but the behaviour stays the same. I was thinking this might be a stack corruption problem and this doesn't occure, when I make the structure a global, but it don't see the SP changing and I found no IRQ to be executed... so no idea what would cause this. That the error doesn't occure while stepping in debug mode still hints to some timing problem.
Edit: I inserted HAL_Delay() calls from 1 to 100 ms between HAL_Init() and SystemClock_Config() which didn't influence the behaviour. So most likely not a timing problem...
When disabling the prefetch buffer in the CubeMX rcc settings, this also seems to make the problem disappear, but I am uncertain, whether its really gone or the simptoms are just not notable.
I am glad for every help, as I don't understand the mechanism and therefore mistrust every workaround.
Regards,
