Skip to main content
nicolas
Senior II
July 13, 2023
Solved

Buggy SystemClock_Config()

  • July 13, 2023
  • 1 reply
  • 1863 views

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 ?

    This topic has been closed for replies.
    Best answer by nicolas
    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.

    1 reply

    ST Employee
    July 14, 2023

    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.
    nicolas
    nicolasAuthor
    Senior II
    July 14, 2023

    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.

     

    nicolas
    nicolasAuthor
    Senior II
    July 14, 2023

    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.