how to change K64F system clock without PE?

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

how to change K64F system clock without PE?

跳至解决方案
2,367 次查看
gloria
Contributor III

Hi, I want to change the K64F system clock to 100MHz. What files should I change to do it? I am using KDS3.0+KSDK1.2.0 without PE.

Many thank!

标签 (1)
1 解答
1,890 次查看
EarlOrlando
Senior Contributor II

Hello Gloria,

The FRDM-K64F contains an external reference of 50 MHz provided by the Ethernet Phy which is used to feed the MCU. As you can see in the image below it is divided by a factor which usually is configured as PRDIV = 0x13 to divide the external reference clock by a factor of 20 to feed the PLL with a 2.5 MHz signal. The PLL internally multiplies the frequency by a factor defined by VDIV0 which usually is configured as 0x18 to multiply by a factor of 48 to get 120 MHz. Since you want a 100 MHz output you need to modify this factor to 40 to get that frequency so you need to configure VDIV0 = 0x10.

2015-07-23_11-01-42.png

pastedImage_2.png

pastedImage_1.png

So, what you need to do is to change that value in the KSDK configurations. In the file board.c is defined an structure called clock_manager_user_config_t g_defaultClockConfigRun which contains these configurations.

const clock_manager_user_config_t g_defaultClockConfigRun =

{

    .mcgConfig =

    {

        .mcg_mode           = kMcgModePEE,   // Work in PEE mode.

        .irclkEnable        = true,  // MCGIRCLK enable.

        .irclkEnableInStop  = false, // MCGIRCLK disable in STOP mode.

        .ircs               = kMcgIrcSlow, // Select IRC32k.

        .fcrdiv             = 0U,    // FCRDIV is 0.

        .frdiv   = 7U,

        .drs     = kMcgDcoRangeSelLow,  // Low frequency range

        .dmx32   = kMcgDmx32Default,    // DCO has a default range of 25%

        .oscsel  = kMcgOscselOsc,       // Select OSC

        .pll0EnableInFllMode = false,  // PLL0 disable

        .pll0EnableInStop    = false,  // PLL0 disalbe in STOP mode

        .prdiv0              = 0x13U,

        .vdiv0               = 0x18U,

    },

    .simConfig =

    {

        .pllFllSel = kClockPllFllSelPll,    // PLLFLLSEL select PLL.

        .er32kSrc  = kClockEr32kSrcRtc,     // ERCLK32K selection, use RTC.

        .outdiv1   = 0U,

        .outdiv2   = 1U,

        .outdiv3   = 1U,

        .outdiv4   = 4U,

    },

    .oscerConfig =

    {

        .enable       = true,  // OSCERCLK enable.

        .enableInStop = false, // OSCERCLK disable in STOP mode.

    }

};

Change the value for the field vdiv to 0x10 and you will obtain a 100 MHz core clock.

Best regards,

Earl.

/* If this post answers your question please click the Correct answer ​button. */

在原帖中查看解决方案

0 项奖励
回复
4 回复数
1,891 次查看
EarlOrlando
Senior Contributor II

Hello Gloria,

The FRDM-K64F contains an external reference of 50 MHz provided by the Ethernet Phy which is used to feed the MCU. As you can see in the image below it is divided by a factor which usually is configured as PRDIV = 0x13 to divide the external reference clock by a factor of 20 to feed the PLL with a 2.5 MHz signal. The PLL internally multiplies the frequency by a factor defined by VDIV0 which usually is configured as 0x18 to multiply by a factor of 48 to get 120 MHz. Since you want a 100 MHz output you need to modify this factor to 40 to get that frequency so you need to configure VDIV0 = 0x10.

2015-07-23_11-01-42.png

pastedImage_2.png

pastedImage_1.png

So, what you need to do is to change that value in the KSDK configurations. In the file board.c is defined an structure called clock_manager_user_config_t g_defaultClockConfigRun which contains these configurations.

const clock_manager_user_config_t g_defaultClockConfigRun =

{

    .mcgConfig =

    {

        .mcg_mode           = kMcgModePEE,   // Work in PEE mode.

        .irclkEnable        = true,  // MCGIRCLK enable.

        .irclkEnableInStop  = false, // MCGIRCLK disable in STOP mode.

        .ircs               = kMcgIrcSlow, // Select IRC32k.

        .fcrdiv             = 0U,    // FCRDIV is 0.

        .frdiv   = 7U,

        .drs     = kMcgDcoRangeSelLow,  // Low frequency range

        .dmx32   = kMcgDmx32Default,    // DCO has a default range of 25%

        .oscsel  = kMcgOscselOsc,       // Select OSC

        .pll0EnableInFllMode = false,  // PLL0 disable

        .pll0EnableInStop    = false,  // PLL0 disalbe in STOP mode

        .prdiv0              = 0x13U,

        .vdiv0               = 0x18U,

    },

    .simConfig =

    {

        .pllFllSel = kClockPllFllSelPll,    // PLLFLLSEL select PLL.

        .er32kSrc  = kClockEr32kSrcRtc,     // ERCLK32K selection, use RTC.

        .outdiv1   = 0U,

        .outdiv2   = 1U,

        .outdiv3   = 1U,

        .outdiv4   = 4U,

    },

    .oscerConfig =

    {

        .enable       = true,  // OSCERCLK enable.

        .enableInStop = false, // OSCERCLK disable in STOP mode.

    }

};

Change the value for the field vdiv to 0x10 and you will obtain a 100 MHz core clock.

Best regards,

Earl.

/* If this post answers your question please click the Correct answer ​button. */

0 项奖励
回复
1,890 次查看
gloria
Contributor III

Hi Earl,

Could I change the value of .div0 by switch on the board when the program is running? I want to change the frequency of bus clock when the program is running. Many thanks!

Best Regards,

Gloria

0 项奖励
回复
1,890 次查看
EarlOrlando
Senior Contributor II

Hi,

Yes but you need to call the function BOARD_ClockInit() again.

Best regards,

Earl.

0 项奖励
回复
1,890 次查看
gloria
Contributor III

Hi Earl,

Thank you very much! I have solved this problem accourding your instruction!

Best Regards,

Gloria

0 项奖励
回复