3

I'm using STM32L152RB board and I'm trying to configure system clock to use PLL clock but the RCC_FLAG_PLLRDY flag is getting set so the program is stuck in while loop. please let what I'm doing wrong

EnableHSI();
RCC_PLLConfig(RCC_PLLSource_HSI,RCC_PLLMul_3,RCC_PLLDiv_2);
RCC_PLLCmd(ENABLE);
while(RCC_GetFlagStatus(RCC_FLAG_PLLRDY) == RESET);
RCC_SYSCLKConfig( RCC_SYSCLKSource_PLLCLK);
t=GetSystemClockSource();

1 Answer 1

5

Take a look in the reference manual for "Relation between CPU clock frequency and Flash memory read time". It says what for the CPU speed higher than 16MHz you should set flash latency for 1WS (wait state). Something like this before setting PLL as clock source:

FLASH->ACR  = FLASH_ACR_ACC64;   // 64-bit access
FLASH->ACR |= FLASH_ACR_LATENCY; // one wait state
FLASH->ACR |= FLASH_ACR_PRFTEN;  // prefetch enable
4
  • Old question but I'm having exactly same issue as the op. I start my system with hsi as system clock sourcr(8mhz) and the attemptinto change the clock source to pll. Same as op, my pll ready flag never gets set. Can you explain how changing the flash latency would solve this as the status of the pll ready flag is being checked BEFORE setting pll as clock source ie. at this point the system clock is still from hsi
    – Ankit
    Commented May 14, 2016 at 6:39
  • Maybe, when you trying to switch to higher frequency without tuning waitstates, the PLL is unable to lock. I've played with my L151, tried to switch to PLL without setting one wait state: no luck, mostly the PLLRDY bit is not set, sometimes (rare) it fall to hardfault.
    – LonelyWolf
    Commented Jun 6, 2016 at 1:03
  • Thanks for this. I don't know why they didn't provide a reference to this in the RCC section. Spent a lot of time wondering why my stm32f411ret6 worked at 42Mhz but not at 84. Increasing wait states to 4, the LED blink program works all the way to 100MHz. Commented Jan 9, 2018 at 10:37
  • I can confirm that this needs to be done before you enable PLL, or the ready bit will never be set (And the PLL will never turn on; this will result in a hang if you're polling until it's ready) Commented Jan 4, 2021 at 3:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.