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.