2012-07-16 10:50 AM
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-system2012-07-16 11:25 AM
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.2012-07-17 02:43 AM
Thanks for your reply.
I've scoped it and yes it's not correctly connected! But what does it have to do with HSI?2012-07-17 05:17 AM
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)
{
}
2012-07-17 05:50 AM
Thanks for that.
The PLL never gets ready! It's not getting out from the first while statement!2012-07-17 06:37 AM
Sounds like you have bigger issues with the board/project.
2012-11-17 05:07 AM
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