cancel
Showing results for 
Search instead for 
Did you mean: 

Clock problem

jenya7
Associate II
Posted on October 28, 2013 at 10:53

I work with STM32F103RBT6.

In stm32f10x.h i set  #define STM32F10X_MD, it leads us to :

#define SYSCLK_FREQ_72MHz 72000000 in system_stm32f10x.h.

So SystemInit() function should go to SetSysClockTo72().

However on MCO pin configured as PLL/2 i see frequency 12Mhz i.e 24Mhz system clock instead of 72Mhz.

What could be a problem?
4 REPLIES 4
Posted on October 28, 2013 at 12:45

Check the code that's setting the PLL up, what settings, etc.

Check that the external oscillator is starting, and what speed it is.

Check the HSE_VALUE define for the project, and if it matches the external.

Use a debugger and step through the SystemInit() code.
Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
jenya7
Associate II
Posted on October 28, 2013 at 13:22

On HSE I see nice 8Mhz clock - it's defined in .h file.

SystemInit jumps to

SetSysClockTo24(),

cant figure why. Any way it went as it went. After that i fire my own function

void SysClockInit(void)
{
__IO uint32_t StartUpCounter = 0, HSEStatus = 0;
/* Configuration SYSCLK, HCLK, PCLK2 и PCLK1 ---------------------------*/
/* Switch on HSE */
RCC->CR |= ((uint32_t)RCC_CR_HSEON);
/* Wait for HSE ready bit or timeout*/
do
{
HSEStatus = RCC->CR & RCC_CR_HSERDY;
StartUpCounter++;
} while( (HSEStatus == 0) && (StartUpCounter != HSEStartUp_TimeOut));
if ( (RCC->CR & RCC_CR_HSERDY) != RESET)
{
HSEStatus = (uint32_t)0x01;
}
else
{
HSEStatus = (uint32_t)0x00;
}
/* if HSE started good */
if ( HSEStatus == (uint32_t)0x01)
{
FLASH->ACR |= FLASH_ACR_PRFTBE;
FLASH->ACR &= (uint32_t)((uint32_t)~FLASH_ACR_LATENCY);
FLASH->ACR |= (uint32_t)FLASH_ACR_LATENCY_2;
/* HCLK = SYSCLK */
RCC->CFGR |= (uint32_t)RCC_CFGR_HPRE_DIV1;
/* PCLK2 = HCLK */
RCC->CFGR |= (uint32_t)RCC_CFGR_PPRE2_DIV1;
/* PCLK1 = HCLK */
RCC->CFGR |= (uint32_t)RCC_CFGR_PPRE1_DIV2;
/* PLL configuration: PLLCLK = HSE * 9 = 72 MHz */
RCC->CFGR &= (uint32_t)((uint32_t)~(RCC_CFGR_PLLSRC | RCC_CFGR_PLLXTPRE |
RCC_CFGR_PLLMULL));
RCC->CFGR |= (uint32_t)(RCC_CFGR_PLLSRC_HSE | RCC_CFGR_PLLMULL9); 
/* Switch on PLL */
RCC->CR |= RCC_CR_PLLON;
/* wait for PLL ready bit */
while((RCC->CR & RCC_CR_PLLRDY) == 0) { }
/* choose PLL as system clock source */
RCC->CFGR &= (uint32_t)((uint32_t)~(RCC_CFGR_SW));
RCC->CFGR |= (uint32_t)RCC_CFGR_SW_PLL;
while ((RCC->CFGR & (uint32_t)RCC_CFGR_SWS) != (uint32_t)0x08) { }
}
else
{
/* All is bad... HSE didn't turn on... Something wrong... */
}
//return HSEStatus;
}

And 24Mhz stays on.
Posted on October 28, 2013 at 14:24

Then I guess you'll need to look into what the compiler is seeing/doing. That it's looking at file you think it is, and that the pre-processor defines passed to the compiler are what they should be.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
jenya7
Associate II
Posted on October 28, 2013 at 14:29

Thanks. I'll look into it.