AnsweredAssumed Answered

Stm32f103c8 - clock configuration issue

Question asked by anton.bogdan on Sep 14, 2015
Latest reply on Sep 14, 2015 by anton.bogdan

Hello all, i started working with a small stm32f103c8t6 (medium size device)  which i want to use it without any external crystal, so i configured it
with usage of internal HSI oscilator.

From what i manage to figure is that HSI 8 mhz, is divided by 2 before the PLL, and then i multiply by 15,  so the math would be 8mhz/2 x 15 = 60 MHZ

As from what i know, the max sysclk frequency is 72 mhz

After the clocks should work as expected, i put a timer3 update  interupt eventwith period 5999 and prescale set to 499, this should give me a 20hz interupt update freq

The problem is if i set PLL multiplier to 15, the microcontroler is "dead", not even the red and green leds light....

But if i lower the PLL multiplier to 9, the microcontroler is alive again, and the leds are lighting normal...

What am i doing wrong?

Bellow is my code

int main(){
 
 
/******************** SETUP OF CLOCKS ******************************/
  RCC_DeInit();
  RCC_HSEConfig(RCC_HSE_OFF); //disable HSE oscilator
  RCC_PLLCmd(DISABLE); // disable pll
  RCC_HSICmd(ENABLE); // enable internal osc
  
  RCC_PLLConfig(RCC_PLLSource_HSI_Div2, RCC_PLLMul_15);// PLL clock should be    HSI /2  x 15 = 60MHZ
  
  RCC_PLLCmd(ENABLE); // enable  pll
 
    /* 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)
    {
    }
 
  /* Set HCLK, PCLK1, and PCLK2 to SCLK  */
  RCC_HCLKConfig(RCC_SYSCLK_Div1);  // HCLK is = SYSCLK
  RCC_PCLK1Config(RCC_HCLK_Div2);   // PCLK is 30MHZ,  and timer3 clk should be 2x PCLK ( 60 MHZ)
  RCC_PCLK2Config(RCC_HCLK_Div2);  
 
/******************* END OF CLOCKS SETUP **********************/
 
 
 TIM_TimeBaseInitTypeDef  TIM_TimeBaseStructure;
 NVIC_InitTypeDef NVIC_InitStructure;
 
   
 
 
 
  /**** setup some clocks for timers and gpios *****/
  RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE);
  RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM3 | RCC_APB2Periph_GPIOB, ENABLE); // timer3 & GPIOB  clocks - i expect it should be 60 MHZ since its 2xAPB1 clk, which is HCLK /2
   
 
  /* setup GPIO for LEDs */
  GPIO_InitStructure.GPIO_Pin = green | red ;
  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;//input pull up
  GPIO_Init(GPIOA, &GPIO_InitStructure);
  
  GPIO_SetBits(GPIOA, green); // just turn on the red LED
  GPIO_SetBits(GPIOA, red);   // just turn on the green Led
 
 
 /* setup some GPIOs for logic analyzing */
   GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2 | GPIO_Pin_3 ;
   GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
   GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;//input pull up
   GPIO_Init(GPIOB, &GPIO_InitStructure);
 
 
 TIM_TimeBaseStructure.TIM_Prescaler = 1;
 TIM_TimeBaseStructure.TIM_Period = 1;
 TIM_TimeBaseStructure.TIM_ClockDivision = TIM_CKD_DIV1;
 TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
 TIM_TimeBaseInit(TIM3, &TIM_TimeBaseStructure);
 
 TIM_ITConfig(TIM3, TIM_IT_Update, ENABLE);
 
 NVIC_InitStructure.NVIC_IRQChannel = TIM3_IRQn;
 NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority =6;
 NVIC_InitStructure.NVIC_IRQChannelSubPriority = 6;
 NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
 NVIC_Init(&NVIC_InitStructure);
 TIM_Cmd(TIM3, ENABLE);  // Start the Timer
 
 
}
 
 
 
 
 
void TIM3_IRQHandler()
{
    if (TIM_GetITStatus(TIM3, TIM_IT_Update) != RESET)
    {
        TIM_ClearITPendingBit(TIM3, TIM_IT_Update);
        GPIO_ToggleBits(GPIOB, GPIO_Pin_2);
    }
}

Outcomes