cancel
Showing results for 
Search instead for 
Did you mean: 

PLL is not working

kuntaramakrishna
Associate
Posted on June 25, 2014 at 09:31

Hello guys i m New to STM32 , i m using Keil ARM tools.

I have written LED Blinky code with STM32F051C8 the following code .In the below code if i change RCC_CFGR_PLLMULL2 to RCC_CFGR_PLLMULLX(X=3,4,6....12) My LED blinky code is not working where as its working fine for PLLMULL2 .....

help me guys why it is happening ...?

#include ''stm32f0xx.h''                  // Device header

#include <stdio.h>

void SystemCoreClockSetHSI(void) {

  RCC->CR |= ((uint32_t)RCC_CR_HSION);                      /* Enable HSI                        */

  while ((RCC->CR & RCC_CR_HSIRDY) == 0);                   /* Wait for HSI Ready                */

  RCC->CFGR = RCC_CFGR_SW_HSI;                              /* HSI is system clock               */

  while ((RCC->CFGR & RCC_CFGR_SWS) != RCC_CFGR_SWS_HSI);   /* Wait for HSI used as system clock */

  FLASH->ACR  = FLASH_ACR_PRFTBE;                           /* Enable Prefetch Buffer            */

  FLASH->ACR |= FLASH_ACR_LATENCY;                          /* Flash 1 wait state                */

  RCC->CFGR |= RCC_CFGR_HPRE_DIV1;                          /* HCLK = SYSCLK                     */

  RCC->CFGR |= RCC_CFGR_PPRE_DIV1;                          /* PCLK = HCLK                       */

  RCC->CR &= ~RCC_CR_PLLON;                                 /* Disable PLL */

  /*  PLL configuration:  = HSI/2 * 12 = 48 MHz */

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

  RCC->CFGR |=  (RCC_CFGR_PLLSRC_HSI_Div2 | RCC_CFGR_PLLMULL2);

  RCC->CR |= RCC_CR_PLLON;                                  /* Enable PLL                        */

  while((RCC->CR & RCC_CR_PLLRDY) == 0) __NOP();            /* Wait till PLL is ready            */

  RCC->CFGR &= ~RCC_CFGR_SW;                                /* Select PLL as system clock source */

  RCC->CFGR |=  RCC_CFGR_SW_PLL;

  while ((RCC->CFGR & RCC_CFGR_SWS) != RCC_CFGR_SWS_PLL);   /* Wait till PLL is system clock src */

}

void LED_on(void)

{

GPIOB->BSRR |= (1 << 11);

}

void LED_off(void)

{

GPIOB->BSRR |= (1 << 27);

}

void Delay(unsigned int time) {

   volatile unsigned int i,j;

for(i=0;i<time;i++)

for(j=0;j<1000;j++);

}

/*

 * main: initialize and start the system

 */

int main (void) {

SystemCoreClockSetHSI();

SystemCoreClockUpdate ();

RCC->AHBENR |=  (1 << 18);                   /* Enable GPIOB clock         */

/* Configure (PB.11,) pins as push-pull outputs, No pull-up, pull-down */

  GPIOB->MODER   &= ~((3 << 2*11));

  GPIOB->MODER   |=  ((1 << 2*11));

  GPIOB->OTYPER  &= ~((3 <<   11));

  GPIOB->OSPEEDR &= ~((3 << 2*11));

  GPIOB->OSPEEDR |=  ((3 << 2*11));

  GPIOB->PUPDR   &= ~((3 << 2*11));

while(1)

{

LED_on(); Delay(1000); 

LED_off();  Delay(1000); 

}

}

1 REPLY 1
Posted on June 25, 2014 at 13:04

And this is with what board?

Wouldn't the HSI already be running (CPU starts with it running), and the clock and PLL settings should already be set via SystemInit() which CMSIS typically calls before main()?
Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..