KSDK Question about CLOCK_GetCoreSysClkFreq & SystemCoreClockUpdate

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

KSDK Question about CLOCK_GetCoreSysClkFreq & SystemCoreClockUpdate

Jump to solution
593 Views
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?

Labels (1)
0 Kudos
1 Solution
422 Views
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

View solution in original post

0 Kudos
2 Replies
422 Views
francoislion
Contributor I

Thank you for the clarification.

0 Kudos
423 Views
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 Kudos