Skip to main content
Handzic.Dirk
Associate III
January 9, 2019
Solved

STM32F071C PLL never gets ready on some boards

  • January 9, 2019
  • 4 replies
  • 1415 views

I have a problem on a STM32F071C board. The PLL will not reach ready state. I am using the HSI and in order to reduce current consumption I want to devide PLL from 8MHz down to 2MHz. This works fine on most board (18 out of 20) but on some the PLL_RDY is never set. Do I violate any requirements by using RCC->CFGR2 = RCC_CFGR2_PREDIV_DIV4?

   

/* Enable Prefetch Buffer and set Flash Latency */

   FLASH->ACR = FLASH_ACR_PRFTBE | FLASH_ACR_LATENCY;

   /* HCLK = SYSCLK */

   RCC->CFGR |= (uint32_t)RCC_CFGR_HPRE_DIV1;

   /* PCLK = HCLK */

   RCC->CFGR |= (uint32_t)RCC_CFGR_PPRE_DIV1;

   /* PLL configuration = HSI * 2 = 4 MHz */

   RCC->CFGR &= (uint32_t)((uint32_t)~(RCC_CFGR_PLLSRC | RCC_CFGR_PLLXTPRE | RCC_CFGR_PLLMUL));

   RCC->CFGR |= (uint32_t)(RCC_CFGR_PLLSRC_HSI_PREDIV | RCC_CFGR_PLLMUL2);

   RCC->CFGR2 = RCC_CFGR2_PREDIV_DIV4;

   /* Enable PLL */

   RCC->CR |= RCC_CR_PLLON;

   /* Wait till PLL is ready */

   while((RCC->CR & RCC_CR_PLLRDY) == 0)

   {

   }

   /* Select PLL as system clock source */

   RCC->CFGR &= (uint32_t)((uint32_t)~(RCC_CFGR_SW));

   RCC->CFGR |= (uint32_t)RCC_CFGR_SW_PLL;   

   /* Wait till PLL is used as system clock source */

   while ((RCC->CFGR & (uint32_t)RCC_CFGR_SWS) != (uint32_t)RCC_CFGR_SWS_PLL)

   {

   }

This topic has been closed for replies.
Best answer by Danish1

As a comment, I don't like the way you modify RCC->CFGR, doing it in two hits with the first to clear some bits and the second to set others.

Looking at the data sheet section 6.3.9, I think the PLL should be able to sing between 16 and 48 MHz. So maybe getting the PLL to run at 8 MHz is outside the specification, and you have to run it at 16 MHz and divide by 2 (or whatever you want) to get HCLK.

Hope this helps,

Danish

4 replies

Danish1
Danish1Best answer
Lead III
January 9, 2019

As a comment, I don't like the way you modify RCC->CFGR, doing it in two hits with the first to clear some bits and the second to set others.

Looking at the data sheet section 6.3.9, I think the PLL should be able to sing between 16 and 48 MHz. So maybe getting the PLL to run at 8 MHz is outside the specification, and you have to run it at 16 MHz and divide by 2 (or whatever you want) to get HCLK.

Hope this helps,

Danish

Handzic.Dirk
Associate III
January 9, 2019

You are right, I only checked the PLL input frequency which is ok down to 1 MHz but the min output frequency is 16 MHz. That is probably the problem.

Thanks!

Uwe Bonnes
Chief
January 9, 2019

Why do you need PLL at all? Use HSI16 with AHB Prescaler 2 to get 8 MHz.

Handzic.Dirk
Associate III
January 9, 2019

I am now running directly out of the HSI8 and PLL turned off. Problem solved!