Hi Haizhou Li,
according to the kinetis_50MHz_sc (Sample Code from Freescale), the procedure which PLL waits for entering PEE mode after waking up from the low power mode is described as following. Therefore the answer is the latter of your candidates.
(1) Check MCG is in PBE mode, if not then error.
if (!(
(((MCG_S & MCG_S_CLKST_MASK) >> MCG_S_CLKST_SHIFT) == 0x2) &&
(!(MCG_S & MCG_S_IREFST_MASK)) &&
(MCG_S & MCG_S_PLLST_MASK) &&
(!(MCG_C2 & MCG_C2_LP_MASK))
)) { return ERROR; }
(2) Check the PLL state before transitioning to PEE mode, if not then error.
for (i = 0 ; i < 2000 ; i++)
{
if (MCG_S & MCG_S_LOCK0_MASK) break;
}
if (!(MCG_S & MCG_S_LOCK0_MASK)) return ERROR;
(3) Clear CLKS to switch CLKS mux to select PLL as MCG_OUT.
MCG_C1 &= ~MCG_C1_CLKS_MASK;
(4) Wait for clock status bits to update, if not then error.
for (i = 0 ; i < 2000 ; i++)
{
if (((MCG_S & MCG_S_CLKST_MASK) >> MCG_S_CLKST_SHIFT) == 0x3) break;
}
if (((MCG_S & MCG_S_CLKST_MASK) >> MCG_S_CLKST_SHIFT) != 0x3) return ERROR;
I hope it will help you.
Best regards,
Yasuhiko Koumoto.