KSDK Question about CLOCK_GetCoreSysClkFreq & SystemCoreClockUpdate

キャンセル
次の結果を表示 
表示  限定  | 次の代わりに検索 
もしかして: 

KSDK Question about CLOCK_GetCoreSysClkFreq & SystemCoreClockUpdate

ソリューションへジャンプ
655件の閲覧回数
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 解決策
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 件の賞賛
2 返答(返信)
484件の閲覧回数
francoislion
Contributor I

Thank you for the clarification.

0 件の賞賛
485件の閲覧回数
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 件の賞賛