1
\$\begingroup\$

I have a STM32F427 MCU with a 8MHz HSE crystal. I am setting up the clock as follows:

#include <stm32f4xx.h>
#include <stm32f4xx_rcc.h>

void initClocks(void);

void initClocks(void) {
    /*
    HSE: 8 MHz
    PLL: HSE / 8 * 192 => 192 MHz
    SysCLK:  PLL / 2 => 96 MHz
    PrphCLK: PLL / 4 => 48 MHz
    */
    RCC_PLLConfig(RCC_PLLSource_HSE, 8, 192, 2, 4);
    RCC_PLLCmd(ENABLE);

    // Wait
    while(RCC_GetFlagStatus(RCC_FLAG_PLLRDY) == RESET) continue;

    // Use PLL
    RCC_SYSCLKConfig(RCC_SYSCLKSource_PLLCLK);

    while (RCC_GetSYSCLKSource() != 0x08) continue;

    RCC_HCLKConfig(RCC_SYSCLK_Div1);
    RCC_PCLK2Config(RCC_SYSCLK_Div1);
    RCC_PCLK1Config(RCC_SYSCLK_Div1);
}

int main(void) {
    RCC_ClocksTypeDef ClksFreq;

    initClocks();
    SystemCoreClockUpdate();

    RCC_GetClocksFreq(&ClksFreq);

    while(1) {}
}

HSE_VALUE is defined to 8000000

My debugger shows that SYSCLK in ClksFreq is 57.6MHz, though I would expect it to be 96Mhz.

What am I missing?

\$\endgroup\$
2
  • \$\begingroup\$ Off topic, but while(x != y); is sufficient for a loop without the continue statement. I tend to reserve a second line and indent the ;. \$\endgroup\$
    – sherrellbc
    Commented Jun 20, 2014 at 17:11
  • \$\begingroup\$ @sherrellbc Yeah I know that continue is not necessary, but I feel adding it makes it a bit easier to read when there is a "verb". \$\endgroup\$
    – varesa
    Commented Jun 20, 2014 at 17:16

1 Answer 1

2
\$\begingroup\$

I managed to fix my problem by adding the following near the beginning:

RCC_HSEConfig(RCC_HSE_ON);

I had not started the HSE so most of the configuration was propably just ignored as the core still worked.

As a sidenote also the HCLK, PCLK1 and PCLK2 divisions were incorrect (over the frequency limit.) I had not spent so much attention on those as I tried to find out why SYSCLK was not getting set correctly.

\$\endgroup\$
1
  • \$\begingroup\$ @bitsmack I try to keep my questions "updated" - when I remember. I sometimes find year old questions that don't have an answer marked when I go through my profile :) \$\endgroup\$
    – varesa
    Commented Jun 23, 2014 at 22:04

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.