1. What I'm trying to do:
a- Put KL03 into VLPS mode
b- Switch from using the 48MHz HIRC to the 2MHz LIRC2M
c- Reduce power consumption from a few mA's to something lower than 100uA
d- Go from VLPS back to RUN mode on an SPI slave mode receive through AWIC
2. How I'm doing it:
a- Here are the 2 functions I am using to enter and exit VLPS:
SMC_PMCTRL = SMC_PMCTRL_STOPM(2));
dummyread = SMC_PMCTRL;
SCB_SCR |= SCB_SCR_SLEEPDEEP_MASK;
SMC_PMCTRL &= ~SMC_PMCTRL_STOPM_MASK;
SCB_SCR &= ~(SCB_SCR_SLEEPDEEP_MASK | SCB_SCR_SLEEPONEXIT_MASK);
b- Here are the 2 functions I use to switch from HIRC to LIRC2M:
MCG_MC |= MCG_MC_HIRCEN_MASK;
MCG_C1 = MCG_C1_CLKS(0);
MCG_C2 = 0;
while (((MCG_S & MCG_S_CLKST_MASK) >> MCG_S_CLKST_SHIFT) != 0x00);
MCG_MC = 0;
MCG_C1 = MCG_C1_CLKS(1);
MCG_C2 = 0;
while (((MCG_S & MCG_S_CLKST_MASK) >> MCG_S_CLKST_SHIFT) != 0x01);
c- At bootup I run this to enable HIRC and enable going into VLPS and VLLS modes:
SMC_PMPROT = (SMC_PMPROT_AVLP_MASK | SMC_PMPROT_AVLLS_MASK);
d- When the conditions to enter VLPS are met (KL03 is idle and has no pending tasks), I call the 2 functions like this:
// KL03 is in VLPS here
d- My KL03 is configured as an SPI slave (with SPISWAI bit set in SPI0_C2 register) and expect that the KL03 would exit VLPS whenever an SPI transfer is coming its way
3. What I'm seeing:
a- With the code I have above, I measured current consumption at 0.9mA which seems very high to me in VLPS and there's no peripherals running (no ADC, no LPUART... nothing)
b- Another problem is that with this code, the KL03 never properly wakes up and processes the SPI transfer it's receiving.
c- However, if I just remove the set_LIRC() call, power consumption goes to 1.8mA and the SPI transfer works great and I have no issues (other than the high power consumption)
4. My questions:
a- The power numbers I'm seeing are high, is there anything else I need to change to get very low numbers in the 100uA range?
b- Any thoughts on wether the switch to LIRC2M is actually needed?
c- Any idea why if I switch to LIRC2M, the SPI wakeup doesn't work?
Any help is greatly appreciated.