cancel
Showing results for 
Search instead for 
Did you mean: 

Buggy SystemClock_Config()

nicolas
Associate III

I use STM32CubeIDE 1.13.0 to generate code for NUCLEO-L476RG.

The generated SystemClock_Config() put flash latency configuration after the clock configuration. I don't know why it works for the first call, but if I call it after exiting stop mode, it make some weird error.

If i put the flash latency configuration after the voltage configuration and before clock configuration, it works correctly.

Is there a reason to put the flash latency configuration after the clock configuration ?

Would it be better to generate code that put the flash latency configuration before the clock configuration so we can use the same function for exiting stop mode ?

1 ACCEPTED SOLUTION

Accepted Solutions
My problem was coming by using HAL_PWR_EnterSLEEPMode(PWR_LOWPOWERREGULATOR_ON, PWR_SLEEPENTRY_WFI) without lowering the frequency, it was messing my SystemClock_Config() after exiting stop mode.
The problem is resolved by using the PWR_MAINREGULATOR_ON for the sleep mode.

View solution in original post

4 REPLIES 4
Sarra.S
ST Employee

Hello @nicolas

>>but if I call it after exiting stop mode, it makes some weird error.

Could you please specify/show the error 

Actually, when changing the CPU frequency, depending on increasing or decreasing it, there is a software sequence that must be applied in order (check RM0411, the Read access latency section also PWR Control section 5.1.8)

To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.

IIRC, sometime it was hardfaulting, sometime closing my debugger.

I didn't found the RM0411, but i found the RM0351 instead.

There is also a sequence chapter 3.3.3. But the problem is the code generated by ST tools doesn't follows those sequence so it can sometime fail.

 

Apparently my error is similar to this one

I was wrongly thinking it was from flash config. My program crash only when i'm using a clock of 64 MHz or higher but works with 56 MHz.

My problem was coming by using HAL_PWR_EnterSLEEPMode(PWR_LOWPOWERREGULATOR_ON, PWR_SLEEPENTRY_WFI) without lowering the frequency, it was messing my SystemClock_Config() after exiting stop mode.
The problem is resolved by using the PWR_MAINREGULATOR_ON for the sleep mode.