cancel
Showing results for 
Search instead for 
Did you mean: 

Problem with SystemClock_Config() causing HardFault_Handler() when using code from new version of CubeMX Ver 5.5.0

SWrig.1
Associate

STM32L011F4

I have upgraded CubeMX and the latest firmware does not run on some hardware boards that were OK with older firmware. I have tracked it down to the SystemClock_Config() failing and causing a HardFault_Handler() The latest HAL version has timeouts defined in stm32l0xx_hal_rcc.h as

#define MSI_TIMEOUT_VALUE     (2U)   /* 2 ms (minimum Tick + 1) */

#define HSI_TIMEOUT_VALUE     (2U)   /* 2 ms (minimum Tick + 1) */

#define LSI_TIMEOUT_VALUE     (2U)   /* 2 ms (minimum Tick + 1) */

#define PLL_TIMEOUT_VALUE     (2U)   /* 2 ms (minimum Tick + 1) */

I'm using the 16MHz HSI and PLL set for x3 div 3 for an output of 16MHz and all clocks set for 16MHz. VCC is 3.3 Volt, 4 layer PCB and supply clean etc.

If I increase the timeout #defines to 100mS, all boards work OK with no problems. I cannot find any information on how long the PLL takes to stabilise but 1mS +1 seems to be too short on some of my PCBs.

Timeout values of 4mS work on all PCBs but 2mS does not. I've set it to 100mS as the actual value isn't important if the oscillators and PLL start up OK.

Could someone please check if my findings are correct or if I still have a hardware problem that I am masking with the long timeout values.

Thanks Stephen Wright

2 REPLIES 2
berendi
Principal

The timeouts are the same in older HAL versions since STM32CubeL0 Firmware Package V1.5.0 / 29-January-2016. Unless you have upgraded from a version older than that, I'd suspect there is an issue with CubeMX or HAL. Recent CubeMX/HAL releases have shown other problems with clock setup, like clocks missing or off by 10%.

If you want to be sure, reimplement SystemClock_Config() without HAL functions, using the register interface and the procedures in the RCC Clocks chapter of the reference manual.

SWrig.1
Associate

Hello Berendi, Thanks for your reply. I used the CubeMX generated code because it seemed easier but I agree probably best to do it myself. I've had a look at the RCC documentation and it looks fairly straightforward. I've also single stepped the HAL code version and viewed the registers to see when they get altered etc which helps clarify the documentation. I'll do what you've suggested thanks. :)