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("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..:smileylaugh:). 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.
Just get the free Open Source uTasker project from GIT hub as reference since it integrates proper low power mode without any effort.
However, a typical first mistake is that you may find that your initialisation code is writing PMPROT to 0. This is a "write-once" register and so any additional writes that you attempt will be ignored - and then no low leakage modes will be accepted.
Low power and LLWU: http://www.utasker.com/kinetis/LLWU.html
Low power videos:
Professional Kinetis support, one-on-one training and complete fast-track project solutions: http://www.utasker.com/support.html
Yes, I have now found that the problem is again due to the, seemingly horrendous, mbed environment that I'm using. By reading PMCTRL after reset the STOPA bit was always high which probably means that there is still some interrupt doing its thing and preventing stop mode, although I have called disable_irq.
I'm used to work with Eclipse and STM32 standard libraries, so as a pleasant surprise I found the NXP Kinetis SDK wizard plug-in for Eclipse and all the peripheral drivers, which seem to be very similar to the STM32 system. Installation was quick and I got VLPS working in under 10 minutes! Remarkably, code size for a basic blinky program is about 4kb done with the Kinetis SDK and about 25kb with the mbed SDK. Ridiculous.
Thanks for the links. I'll have to look at uTasker too, seems useful.