cancel
Showing results for 
Search instead for 
Did you mean: 

TIM3 Clock Frequence is ZERO

Li JW
Associate II
Posted on January 31, 2017 at 10:02

Hi, everyone! I am writing code for a NucleoF303K8,using std periph lib . I am trying to output PWM via the D3 pin, which is PB0 of the chip. It doesn't work. So I try to find out what's wrong. But when checking the clocks, I found the TIM3 Clock's Freq is 0.

Here is I have done:

1) using the code below to get all the clocks:

  RCC_ClocksTypeDef board_clocks;

  RCC_GetClocksFreq(&board_clocks);

2) checking the sysclk:

    the board_clocks.SYSCLK_Frequency is 72000000

3) checking the TIM1 clock

    the board_clocks.TIM1CLK_Frequency is 72000000

4) checking the PCLK1:

    the board_clocks.PCLK1_Frequency is 36000000

5) checking the HCLK

    the board_clocks.HCLK_Frequency is 72000000

6) checking the TIM3 Clock

    the board_clocks.TIM3CLK_Frequency is 0

Now I can't figure out what's wrong and what I miss.

Waiting a little help from the forum!

4 REPLIES 4
Posted on January 31, 2017 at 11:10

This seems to be a bug in SPL

#ifdef STM32F303xE  

  uint32_t apb1presc = 0;

  apb1presc = APBAHBPrescTable[tmp];

  /* TIM2CLK clock frequency */

  if(((RCC->CFGR3 & RCC_CFGR3_TIM2SW) == RCC_CFGR3_TIM2SW)&& (RCC_Clocks->SYSCLK_Frequency == pllclk) \

  && (apb1presc == ahbpresc))

  {

    /* TIM2 Clock is pllclk */

    RCC_Clocks->TIM2CLK_Frequency = pllclk * 2 ;

  }

  else

  {

    /* TIM2 Clock is APB2 clock. */

    RCC_Clocks->TIM2CLK_Frequency = RCC_Clocks->PCLK1_Frequency;

  }

 

  /* TIM3CLK clock frequency */

  if(((RCC->CFGR3 & RCC_CFGR3_TIM3SW) == RCC_CFGR3_TIM3SW)&& (RCC_Clocks->SYSCLK_Frequency == pllclk) \

  && (apb1presc == ahbpresc))

  {

    /* TIM3 Clock is pllclk */

    RCC_Clocks->TIM3CLK_Frequency = pllclk * 2;

  }

  else

  {

    /* TIM3 Clock is APB2 clock. */

    RCC_Clocks->TIM3CLK_Frequency = RCC_Clocks->PCLK1_Frequency;

  }

#endif /* STM32F303xE */

JW
Posted on January 31, 2017 at 12:53

Hi, JW! Thanks for help. I am not sure that it is the bug in the RCC_GetClocksFreq(...), my project do not enable the macro STM32F303xE, but the STM32F334x8. Maybe I can read directly from the registers to figure out. Thank you!

Sirma Siang
ST Employee
Posted on January 31, 2017 at 13:54

Hello Li JW,

Are you using CubeMX to generate your skeleton code ?

Which version are you using ?

Could you attach your .ioc file ?

Are you working on Win, Linux or Mac machine ?

Great thanks in advance.

Kind regards

Sirma

Posted on January 31, 2017 at 13:14

> my project do not enable the macro STM32F303xE, but the STM32F334x8

That's why the code above does not get executed, resulting in xxx.TIM3CLK_Frequency not being set.

JW