KSDK Question about CLOCK_GetCoreSysClkFreq & SystemCoreClockUpdate

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 
已解决

KSDK Question about CLOCK_GetCoreSysClkFreq & SystemCoreClockUpdate

跳至解决方案
654 次查看
francoislion
Contributor I

Hello,

I have a question regarding Clock APIs of the KSDK.

 

Context:

  • K22F100 MCU and a 10MHz Crystal
  • the clocking system is configured in FEE mode with FRDIV=3 DRST_DRS=3 DMX32=0
  • I am using the new KSDK 2.0

I expect to have a 100MHz System clock with this configuration : 10MHz / 256 * 2560 = 100MHz.

However, all APIs from KSDK 2.0 or earlier (CLOCK_GetCoreSysClkFreq, SystemCoreClockUpdate) report a System clock of 99998720Hz.

 

I understand this is a rouding issue (10MHz/256 = 39062.5Hz), but I am wondering if the "real" System Clock is 100MHz or 99998720Hz due to some internal FLL behavior?

标签 (1)
0 项奖励
1 解答
483 次查看
xiangjunrong
Contributor IV

Hi, Francois,

The 99.99872MHz clock is not the real clock frequency, the real clock is 100MHz, in order to confirm it, you can output a clock to the PTC3 pin which is multiplexed with CLKOUT for K22 chip. You can set up the CLKOUTSEL bits in SIM_SOPT2 to output the BUS_CLK so that you can figure out the real clock frequency. 

Because the api function CLOCK_GetCoreSysClkFreq()  uses integer to compute the clock frequency based on MCG register configuration, so it gives the result because of rounding. Frankly speaking, the core has no way to know the real clock frequency.

Hope it can help you.

BR

Xiangjun rong

在原帖中查看解决方案

0 项奖励
2 回复数
483 次查看
francoislion
Contributor I

Thank you for the clarification.

0 项奖励
484 次查看
xiangjunrong
Contributor IV

Hi, Francois,

The 99.99872MHz clock is not the real clock frequency, the real clock is 100MHz, in order to confirm it, you can output a clock to the PTC3 pin which is multiplexed with CLKOUT for K22 chip. You can set up the CLKOUTSEL bits in SIM_SOPT2 to output the BUS_CLK so that you can figure out the real clock frequency. 

Because the api function CLOCK_GetCoreSysClkFreq()  uses integer to compute the clock frequency based on MCG register configuration, so it gives the result because of rounding. Frankly speaking, the core has no way to know the real clock frequency.

Hope it can help you.

BR

Xiangjun rong

0 项奖励