AnsweredAssumed Answered

Nucleo STM32F401

Question asked by kharitonenko.vladimi on Aug 30, 2014
Latest reply on Aug 31, 2014 by Clive One
Problem with oscillator source PLL.

Nucleo plate does't have HSE oscillator, and use internal 16 MHz HSI
I want to reconfigure tacting schematic to use as SYSCLK - PLL (by default for SYSCLK use HSI directly)

PLL configuration - M = 16, N = 366, P = 4. Q = 7

Here the code (use Keil v5)

int main (void)
{
     GPIO_InitTypeDef sGPIO;


     // Set PLL source to HSI, M div = 16, N mul = 336, P div = 4, Q div = 7
     // HSI = 16 MHz, after M div - 1 MHz, after mul - 336 MHz, PLL - /4 = 84 MHz, USB - /7 - 48 MHz
     RCC_PLLConfig (RCC_PLLSource_HSI, 16, 336, 4, 7);
          
     // Turn on PLL and wait for PLL lock
     RCC->CR |= RCC_CR_PLLON;
     while (!(RCC->CR & RCC_CR_PLLRDY));
     
     // Set AHB Prescaller /1, APB1 Prescaller /2
     RCC->CFGR |= RCC_CFGR_HPRE_DIV1;
     RCC->CFGR |= RCC_CFGR_PPRE1_DIV2;
     
     // Set system clock to PLL and wait for RDY flag
     RCC->CFGR |= RCC_CFGR_SW_1;
     while (!(RCC->CFGR & RCC_CFGR_SWS_1));
          
     // Allow clocks
     RCC_AHB1PeriphClockCmd (RCC_AHB1Periph_GPIOA, ENABLE);
     RCC_APB1PeriphClockCmd (RCC_APB1Periph_TIM2, ENABLE);


     // Config GPIO pin
     sGPIO.GPIO_Mode = GPIO_Mode_OUT;
     sGPIO.GPIO_OType = GPIO_OType_PP;
     sGPIO.GPIO_Pin = GPIO_Pin_5;
     sGPIO.GPIO_Speed = GPIO_Speed_50MHz;
     sGPIO.GPIO_PuPd = GPIO_PuPd_DOWN;
     GPIO_Init (GPIOA, &sGPIO);     

     while (1)
     {
          __nop ();
          __nop ();
          __nop ();
     }
}

In debug - after switch to SYSCLK to PLL - program drop to handler
If i set AHB prescaller to /2 - all Ok, but this is not maximum speed.
What is wrong in my clock initialization?

Outcomes