KL25Z entry into VLPS mode from VLPR

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

KL25Z entry into VLPS mode from VLPR

1,233 Views
vaclavbajgar
Contributor I

Hi, I m working on a project with KL25Z and I need as low power consumption as possible. For my app, I basically would need the MCU to quickly do all the instructions in VLPR and then sleep (VLPS), until I wake him up with an interrupt. I am using Kinetis design studio 3 for compiling and Ozone 2.22 for debugging. I am also using kinetis SDK 2.1.

 

With my code, I am able to enter VLPR mode, with a current consumption of 770 uA measured on J4 jumper. For VLPR mode, I set the SMC and then MCG mode from FEI to BLPI, all according to reference manual, core clock 1 MHz, bus clock 500 KHz.

 

But then, I have problems with entering inthe VLPS (very low power stop) mode. The consumption is nowhere near 5 uA as it should be. It actually doesn't sleep at all, according to SMC_PMSTAT register, it goes to normal run mode .Attached please find my code. I am trying to enter the VLPS in a loop, during which it should sleep and wake up on an interrupt from LPTMR.

 

Can anyone please help me correct my code? Or maybe propose an alternative to my code, to make it sleep in VLPS?

 

Thanks for answers

Original Attachment has been moved to: code.txt.zip

Labels (1)
0 Kudos
Reply
4 Replies

850 Views
mjbcswitzerland
Specialist V

Hi

For complete low power solution see:
http://www.utasker.com/kinetis/FRDM-KL25Z.html

Some low power videos:
https://www.youtube.com/watch?v=kWNlsAoMly4&list=PLWKlVb_MqDQFZAulrUywU30v869JBYi9Q
https://www.youtube.com/watch?v=v4UnfcDiaE4&index=7&list=PLWKlVb_MqDQFZAulrUywU30v869JBYi9Q
https://www.youtube.com/watch?v=iZEMRiDmHzw&list=PLWKlVb_MqDQFZAulrUywU30v869JBYi9Q&index=5

There is available as open source
http://www.utasker.com/forum/index.php?topic=1721.msg7086#msg7086
or supported professional.


To be able to see what the problem is with your code I think that you need to show also SMC_PreEnterStopModes() etc.
Make sure that you are not missing executing the _wfi() instruction in the VLPS case, or setting the SLEEPDEEP flag beforehand.

Regards

Mark


Professional support for Kinetis: http://www.utasker.com/index.html
Remote desktop one-on-one coaching: http://www.utasker.com/services.html
Getting started to expert videos: https://www.youtube.com/results?search_query=utasker+shorts

0 Kudos
Reply

850 Views
vaclavbajgar
Contributor I

Hello, thanks for your reply.

I will try the utasker you propose.

In the functions : SMC_PreEnterStopModes(), SMC_SetPowerModeVlps(SMC) and SMC_PostExitStopModes(); are these instructions:

void SMC_PreEnterStopModes(void)
{
flash_prefetch_speculation_status_t speculationStatus =
{
kFLASH_prefetchSpeculationOptionDisable, /* Disable instruction speculation.*/
kFLASH_prefetchSpeculationOptionDisable, /* Disable data speculation.*/
};

__disable_irq();
__ISB();

/*
* Before enter stop modes, the flash cache prefetch should be disabled.
* Otherwise the prefetch might be interrupted by stop, then the data and
* and instruction from flash are wrong.
*/
FLASH_PflashSetPrefetchSpeculation(&speculationStatus);
}

---------------------------------------------------------------------

status_t SMC_SetPowerModeVlps(SMC_Type *base)
{
uint8_t reg;

/* configure VLPS mode */
reg = base->PMCTRL;
reg &= ~SMC_PMCTRL_STOPM_MASK;
reg |= (kSMC_StopVlps << SMC_PMCTRL_STOPM_SHIFT);
base->PMCTRL = reg;

/* Set the SLEEPDEEP bit to enable deep sleep mode */
SCB->SCR |= SCB_SCR_SLEEPDEEP_Msk;

/* read back to make sure the configuration valid before enter stop mode */
(void)base->PMCTRL;
__DSB();
__WFI();
__ISB();

/* check whether the power mode enter VLPS mode succeed */
if (base->PMCTRL & SMC_PMCTRL_STOPA_MASK)
{
return kStatus_SMC_StopAbort;
}
else
{
return kStatus_Success;
}
}

------------------------------------------------------------------------------

void SMC_PostExitStopModes(void)
{
flash_prefetch_speculation_status_t speculationStatus =
{
kFLASH_prefetchSpeculationOptionEnable, /* Enable instruction speculation.*/
kFLASH_prefetchSpeculationOptionEnable, /* Enable data speculation.*/
};

FLASH_PflashSetPrefetchSpeculation(&speculationStatus);

__enable_irq();
__ISB();
}

The __wfi() instruction and sleepdeep bit is set, I still dont really understand why there is such a high current consumption.

0 Kudos
Reply

850 Views
mjbcswitzerland
Specialist V

Hi

A couple of things:

1. The _wfi() sets the VLPS mode and it doesn't continue until a wakeup (interrupt) occurs. If the processor continues from this point it means that it has been woken and will be in VLPR again. You can only measure the VLPS current when the processor hasn't already been woken again.
2. If the VLPS current is higher than expected check whether there are clocks that are configured to continue running in the VLPS mode and ensure that non-needed ones do get stopped. Also verify that there are no floating inputs since these cause higher than expected current consumption: when you are sure the VLPS mode is active touch all pins on the processor and see whether the current changes when certain ones are touched - if so, ensure that their state is defined so that it doesn't happen (eg. set as outputs or enable pull-up or down on GPIO inputs or peripheral inputs).

Regards

Mark

0 Kudos
Reply

850 Views
vaclavbajgar
Contributor I

Hi Mark,

Thank you very much! Thanks to your first advice I went step by step through my code and tried to figure out what would cause the interrupt to wake my processor up.

For anyone who would have the same problem:

I kinda changed the transition into BLPI clock MCG mode, where I now dont go via FBE mode anymore. So going from FEI to BLPI directly through FBI made the difference and I was able to make it sleep. 

Also this line of code increased the consumption by 600 uA, so maybe I didnt rly  understand the reference manual, therefore I deleted this line in my code...

//Switch off the clock into SCGC6 register - FTF Flash memory, which prevents entry into low power mode
SIM->SCGC6 &=~ (1 <<0);

Then the LPTMR was badly set as well, I changed the clock source for LMPTR module to LPO 1KHz and then updated the LMPTR prescaler and compare value accordingly. Now I am able to make it sleep and wake up in a while cycle...

0 Kudos
Reply