Switching between Run mode and High Speed Run mode

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

Switching between Run mode and High Speed Run mode

3,574 Views
joebirch
Contributor III

Normally I am in High Speed Run mode but to program flash I have to switch to normal Run mode.

First is this correct? and second what is the proper way to switch modes during run time?

I prefer not to have to reboot.

 

I am using the MK22FN512 with KDS3.0 and KSDK 1.3. Currently using the FRDM-K22 eval board

 

Thanks

Joe

Labels (1)
0 Kudos
Reply
6 Replies

2,335 Views
xiangjun_rong
NXP TechSupport
NXP TechSupport

Hi, Joe,

Firstly, you are right, erasing/programming flash should be in normal RUM mode, erasing/programming flash in High Speed RUN mode is NOT allowed. This is the transition sequence from High speed RUN mode to normal run mode:

The K22 is running in High Speed RUN mode mode now.

1)change the FLL or PLL setting so that the core/system clock is in 80MHz or less, Bus clock frequency is 50M or less, and Flash clock is in 25mhz or less.

2)set the RUNM bit as 00 in binary so that the chip runs in normal mode.

3)polling the SMC_PMSTAT whether the chip is in Normak RUN mode

I copy the part from RM.

BR

XiangJun Rong

14.4.3.3 High Speed Run (HSRUN) mode

In HSRUN mode, the on-chip voltage regulator remains in a run regulation state, but with

a slightly elevated voltage output. In this state, the MCU is able to operate at a faster

frequency compared to normal RUN mode. See Power Management chapter for

maximum allowable frequencies.

While in this mode, the following restrictions must be adhered to:

• The maximum allowable change in frequency of the system, bus, flash or core clocks

is restricted to x2.

• Before exiting HSRUN mode, clock frequencies should be reduced back down to

those acceptable in RUN mode.

• Stop mode entry is not supported from HSRUN.

• Modifications to clock gating control bits are prohibited.

• Flash programming/erasing is not allowed.

To enter HSRUN mode, set RUNM=HSRUN. Before increasing clock frequencies, the

PMSTAT register should be polled to determine when the system has completed entry

into HSRUN mode. To reenter normal RUN mode, clear RUNM. Any reset will also

clear RUNM and cause the system to exit to normal RUN mode after the MCU exits its

reset flow.

0 Kudos
Reply

2,334 Views
joebirch
Contributor III

  Thank you for the info. changing from hsrun to normal run does allow me to erase and program flash

but when I change the clock speed the uart and usb connections stop functioning.

Do I have to reinitialize these. Or can I change my clocking configuration so they are not affected by switching power modes?

I don't really understand the clocking settings. I am just using examples I found in KSDK

I start in hsrun mode and made 2 functions: goHighSpeedRunMode(), goNormalRunMode() to go back and forth during run time

See attached for these functions and the initialization code

Any help is appreciated

Thanks

Joe

0 Kudos
Reply

2,334 Views
xiangjun_rong
NXP TechSupport
NXP TechSupport

Hi, Joe,

Firstly, if you change the RUN mode from High Speed Run mode to Normal Run mode, the bus clock will change accordingly, the UART driving clock will change if you use Bus clock as driving clock source of UART.

After you change the mode from HSRUN mode to Normal Run mode, you have to call the following function to change the baudrate based on New bus clock frequency.

  uint32_t uartSourceClock = CLOCK_SYS_GetUartFreq(UART0_IDX);

   LPUART_Type * base = g_uartBase[UART0_IDX];

  LPUART_HAL_SetBaudRate(base, uartSourceClock, BaudRate);

Regarding the USB,  I suppose that the USB uses dedicated IRC48M clock, which is Not effected by the bus clock.

BR

Xiangjun Rong

0 Kudos
Reply

2,334 Views
joebirch
Contributor III

Xiangjun Rong

I was able to correct the uart issue by deinitializing the uart before the run mode change and re-initializing after.

But the USB still does not survive the change.

You are right I am using IRC48M clock for USB.

Maybe it is because I use CLOCK_SYS_SetConfiguration() to change the clock before going to Normal run mode?

Here is the code

    CLOCK_SYS_SetConfiguration(&g_defaultClockConfigRun);

    smc_power_mode_config_t powerModeConfig = {.powerModeName = kPowerModeRun, };

    SMC_HAL_SetMode(SMC, &powerModeConfig);

can you advise on a better way?

Thanks

Joe

0 Kudos
Reply

2,334 Views
xiangjun_rong
NXP TechSupport
NXP TechSupport

Hi,

This is the USB clock diagram for K22. If you use IRC48MCLK source, I do not think there is any problem after you change the system/core clock. But if you use MCGPLL clock as the system/core clock, after you change the frequency, there is issue. Pls check the SIM_SOPT2[PLLFLLSEL] and determine the USB clock source. Not that the USB must use 48MHz clock with low jitter.

BR

Xiangjun Rong

pastedImage_0.png

0 Kudos
Reply

2,334 Views
joebirch
Contributor III

I am using IRC48MCLK.

But I made a change to the KSDK that seems to fix the problem.

background:

I use CLOCK_SYS_SetConfiguration() to change the clocks when changing the power mode.

after calling CLOCK_SYS_SetConfiguration USB stops sending.

I isolated the cause of the USB failure to CLOCK_SYS_SetMcgMode()

Although I am in PLL Engaged External(PEE)Mode in both the old and new configuration

it first switches to PLL Bypassed External(PBE) Mode then back to PEE

I think there is a mistake in mcgModeMatrix[8][8]

If old is PEE and new is PEE it goes to PBE

I changed it to stay in PEE and USB rides through the clock change

Here is the code, can you tell me if this is correct

fsl_clock_manager-snip.png

Thanks

Joe

0 Kudos
Reply