cancel
Showing results for 
Search instead for 
Did you mean: 

Problem with stm32f100c6 clock configuration

shrfhegazy
Associate II
Posted on July 16, 2012 at 19:50

Hi everybody!

I'm using STM32F100C6 with IAR Embedded Workbench IDE and i'm trying to configure the system clock.

First i tried to use the external oscillator HSE that's built on the board, 20MHz, here's the code related:

       /* Enable the HSE */

       RCC_HSEConfig(RCC_HSE_ON);

       /* Wait till HSE is ready and if Time out is reached exit */

       HSEStartUpStatus = RCC_WaitForHSEStartUp();

       while(HSEStartUpStatus == ERROR)

       {}

The problem is that it stays there forever!

So i made some search for other way to deliver the 24 MHz that i need in my application and i found that i can use the HSI.

Here's the code related:

    /* Reset the RCC clock configuration to the default reset state */

    RCC_DeInit();

    /* Enable Internal High Speed oscillator */

    RCC_HSICmd(ENABLE);

    /* Configure HCLK such as HCLK = SYSCLK */

    RCC_HCLKConfig(RCC_SYSCLK_Div1);

    /* Configure PCLK2 such as PCLK2 = HCLK */

    RCC_PCLK2Config(RCC_HCLK_Div1);

    /* Configure PCLK1 such as PCLK1 = HCLK */

    RCC_PCLK1Config(RCC_HCLK_Div1);

    /* Set PLL clock output to 24MHz using HSI (8MHz) as entry clock */

    RCC_PLLConfig(RCC_PLLSource_HSI_Div2, RCC_PLLMul_6);

    /* Enable the PLL */

    RCC_PLLCmd(ENABLE);

    /* Select the PLL as system clock source */

    RCC_SYSCLKConfig(RCC_SYSCLKSource_PLLCLK);

I made a check after that to see how the code affected the system clock:

    RCC_ClocksTypeDef RCC_Clocks;

    RCC_GetClocksFreq(&RCC_Clocks);

System clock, HCLK, PCLK1 and PCLK2 are 8MHz

Any help in that please?

Thanks in advance!

#stm32-clock-system
6 REPLIES 6
Posted on July 16, 2012 at 20:25

What board?

Have you scoped the pins of the external oscillators? If it's not actually started, or not connected due to solder bridges or options on the board, it's never going to come ready.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
shrfhegazy
Associate II
Posted on July 17, 2012 at 11:43

Thanks for your reply.

I've scoped it and yes it's not correctly connected! But what does it have to do with HSI?

Posted on July 17, 2012 at 14:17

HSI observations.

HSI should already be ON, if it's not you have to wait for it to start PLL you need to wait for it to start/lock before switching to it. After switching to the PLL source, you need to wait for it to be selected.

...
/* PLLCLK = 4MHz * 6 = 24 MHz */
RCC_PLLConfig(RCC_PLLSource_HSI_Div2, RCC_PLLMul_6);
/* Enable PLL */
RCC_PLLCmd(ENABLE);
/* Wait till PLL is ready */
while(RCC_GetFlagStatus(RCC_FLAG_PLLRDY) == RESET)
{
}
/* Select PLL as system clock source */
RCC_SYSCLKConfig(RCC_SYSCLKSource_PLLCLK);
/* Wait till PLL is used as system clock source */
while(RCC_GetSYSCLKSource() != 0x08)
{
}

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
shrfhegazy
Associate II
Posted on July 17, 2012 at 14:50

Thanks for that.

The PLL never gets ready! It's not getting out from the first while statement!

Posted on July 17, 2012 at 15:37

Sounds like you have bigger issues with the board/project.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
ameno12008
Associate II
Posted on November 17, 2012 at 14:07

Check this please 

''Options for target'' -> ''Debug'' -> check box of  Use Emulator not Simulator and check box of Run to main() 

and everything will work normally