Pauli Nikula

K64F how to enter VLPS stop mode

Discussion created by Pauli Nikula on Dec 15, 2017
Latest reply on Dec 16, 2017 by Pauli Nikula

I have been struggling to get my FRDM K64F board to enter VLPS mode. Here's my code to enter stop mode:

 

       disable_irq(); // Disable Interrupts


SMC ->PMPROT |= 0x20; //allow VLPS mode

SMC ->PMCTRL |= 0x02; //select VLPS mode

tmp = SMC ->PMCTRL; //dummy read

 

//clear watchdog STOPEN for giggles, maybe it's the culprit

WDOG ->UNLOCK = 0xC520;
WDOG ->UNLOCK = 0xD928;
WDOG ->STCTRLH &= ~0x0040;

//WDGEN is already 0

 

SCB ->SCR |= SCB_SCR_SLEEPDEEP_Msk;

asm("NOP");
asm("NOP");
asm("NOP");

asm("WFI"); //sleep instruction

 

Nothing happens and my test blinky keeps running. 

 

Should I disable all peripherals first? Is it enough to disable the clock gates for the peripherals? Should the 48Mhz IRC clock be disabled? I think it is disabled at least in MCG_C7 and SIM_SOPT2. The USB RECOVER_IRC_EN register I could not check because my program would lock up when I try to read it(explanation for this would also be nice..). Should I change system clock source to the 4Mhz IRC first? I'm starting to go nuts with the reference manual. It does not clearly state any of these things. 

Outcomes