KL82 switch from HSRUN to RUN

cancel
Showing results for 
Search instead for 
Did you mean: 

KL82 switch from HSRUN to RUN

378 Views
marcwillem
Contributor II

Hello,

I do have an issue switching from HSRUN mode to RUN mode.

After the configuration of the clocks, CLOCK_GetFllFreq() return 0 and my program is not working.

Although if I start in RUN mode, CLOCK_GetFllFreq() returns the correct value.

Can you please help me figure out, what I am missing when switching from HSRUN to RUN?

Thanks in advance.

Code for RUN

void CLK_RUN(void)
{
/* Set the system clock dividers in SIM to safe value. */
CLOCK_SetSimSafeDivs();
/* Configure RTC clock including enabling RTC oscillator. */
CLOCK_CONFIG_SetRtcClock(RTC_OSC_CAP_LOAD_12PF, RTC_RTC32KCLK_PERIPHERALS_ENABLED);
/* Set MCG to FBI mode. */
CLOCK_SetInternalRefClkConfig(mcgConfig_CLK_RUN.irclkEnableMode,
mcgConfig_CLK_RUN.ircs,
mcgConfig_CLK_RUN.fcrdiv);
#if FSL_CLOCK_DRIVER_VERSION >= MAKE_VERSION(2, 2, 0)
CLOCK_SetFbiMode(mcgConfig_CLK_RUN.dmx32,
mcgConfig_CLK_RUN.drs,
CLOCK_CONFIG_FllStableDelay);
#else
CLOCK_SetFbiMode(mcgConfig_CLK_RUN.drs,
CLOCK_CONFIG_FllStableDelay);
#endif
/* Select the MCG external reference clock. */
CLOCK_SetExternalRefClkConfig(mcgConfig_CLK_RUN.oscsel);
/* Set the clock configuration in SIM module. */
CLOCK_SetSimConfig(&simConfig_CLK_RUN);
/* Set SystemCoreClock variable. */
SystemCoreClock = CLK_RUN_CORE_CLOCK;
}

Code for HSRUN

/* Set HSRUN power mode */
SMC_SetPowerModeProtection(SMC, kSMC_AllowPowerModeAll);
SMC_SetPowerModeHsrun(SMC);
while (SMC_GetPowerModeState(SMC) != kSMC_PowerStateHsrun)
{
}
/* Set the system clock dividers in SIM to safe value. */
CLOCK_SetSimSafeDivs();
/* Configure RTC clock including enabling RTC oscillator. */
CLOCK_CONFIG_SetRtcClock(RTC_OSC_CAP_LOAD_12PF, RTC_RTC32KCLK_PERIPHERALS_ENABLED);
/* Initializes OSC0 according to board configuration. */
CLOCK_InitOsc0(&oscConfig_CLK_HSRUN);
CLOCK_SetXtal0Freq(oscConfig_CLK_HSRUN.freq);
/* Configure FLL external reference divider (FRDIV). */
CLOCK_CONFIG_SetFllExtRefDiv(mcgConfig_CLK_HSRUN.frdiv);
/* Set MCG to PEE mode. */
CLOCK_BootToPeeMode(mcgConfig_CLK_HSRUN.oscsel,
kMCG_PllClkSelPll0,
&mcgConfig_CLK_HSRUN.pll0Config);
/* Set the clock configuration in SIM module. */
CLOCK_SetSimConfig(&simConfig_CLK_HSRUN);
/* Set SystemCoreClock variable. */
SystemCoreClock = CLK_HSRUN_CORE_CLOCK;
/* Enable USB FS clock. */
CLOCK_EnableUsbfs0Clock(kCLOCK_UsbSrcPll0, SIM_USB_CLK_96000000HZ);

Tags (2)
0 Kudos
1 Reply

333 Views
kerryzhou
NXP TechSupport
NXP TechSupport

Hi marcwillem ,

  Do you check the run mode clock, whether you meet the following requirements:

pastedImage_1.png

The HSRUN can change to the RUN mode:

pastedImage_2.png

pastedImage_3.png

Please double-check the above points.

Make sure the core, bus clock meet the requirement, then set PMCTRL[RUNM]=00.

   Wish it helps you!

   If you still have questions about it, please kindly let me know.

   

Best Regards,

Kerry

 

-------------------------------------------------------------------------------
Note:
- If this post answers your question, please click the "Mark Correct" button. Thank you!

 

- We are following threads for 7 weeks after the last post, later replies are ignored
Please open a new thread and refer to the closed one, if you have a related question at a later point in time.
-------------------------------------------------------------------------------

0 Kudos