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();
Mustak U
  • 115
  • 2
  • 11

1 Answers1

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
LonelyWolf
  • 61
  • 1
  • 2
  • 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 May 14 '16 at 06: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 Jun 06 '16 at 01: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. – Plasty Grove Jan 09 '18 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) – Turtles Are Cute Jan 04 '21 at 03:21