Why KL03 is not going into VLPW mode using Processor Expert?

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

Why KL03 is not going into VLPW mode using Processor Expert?

1,003 Views
andymurray
Contributor II

Hi, I am a newbie in KL03. The objective of my code is to run in VLPR and VLPW depending on an external signal. In both modes the LPTMR, ADC and the LPUART should be fully functional. I have checked the power demo of KL03 in which you are able to select among different power modes and the wake up source, everything works fine.

 

Using the KDS and Processor Expert I tried to configure the two modes of operation (VLPR and VLPW) and 1 type of callback, and even if I ask the PE to initialize the system in VLPW, it initializes in VLPR and is not able to get into the VLPW with the instruction

POWER_SYS_SetMode(kPowerManagerVlpw, PowerManagerPolicyAgreement);

 

While debugging, when I run this SetMode instruction, I see that in fsl_power_manager.c the variable mode is not set to kPowerManagerVlpw but to kPowerManagerVlpr. I force mode to be kPowerManagerVlpw in the debugger, and it works for a while. The KL03 executes the code:

        case kPowerManagerVlpw:

            halModeConfig.powerModeName = kPowerModeVlpw;

            break;

 

and in fsl_smc_hal.c it executes the code:

       case kPowerModeVlpw:

                 /* Clear the SLEEPDEEP bit to disable deep sleep mode - enter wait mode*/

                  SCB->SCR &= ~SCB_SCR_SLEEPDEEP_Msk;

 

Until it gets to wfi.

 

What should I do to avoid setting the mode to kPowerManagerVlpw using the debugger (which is not realistic)? Running in VLPR, I use the following instruction to get to VLPW:

 

// Errata 8068 fix

SIM->SCGC6 |=SIM_SCGC6_RTC_MASK;          // enable clock to RTC

RTC->TSR = 0x00; // dummy write to RTC TSR per errata 8068

SIM->SCGC6 &= ~SIM_SCGC6_RTC_MASK; // disable clock to RTC

ret_power=POWER_SYS_SetMode(kPowerManagerVlpw, kPowerManagerPolicyAgreement); 

 

After searching for this in the NXP Community, I decided to manage the transitions between power modes with the registers. The following is the code that I adapted from NXP community sources:

 

void goToVLPW(){

       int a;

       int clk;

       update_clock(CLOCK_VLPR);

       CLOCK_SYS_GetFreq(kCoreClock, &freq);

       gpioEnableWakeUp();

       // Errata 8068 fix: https://community.nxp.com/thread/350259

       SIM->SCGC6 |=SIM_SCGC6_RTC_MASK;          // enable clock to RTC

       RTC->TSR = 0x00; // dummy write to RTC TSR per errata 8068

       SIM->SCGC6 &= ~SIM_SCGC6_RTC_MASK; // disable clock to RTC

 

       power_mode_status  = SMC_PMSTAT; //Pag. 206 RefMan

       if (power_mode_status == 4){

             //It is in VLPR

             SCB_SCR &=~ SCB_SCR_SLEEPDEEP_MASK; //SLEEPDEEP cleared; Pag. 213 RefMan

             SCB_SCR |= (SCB_SCR_SLEEPONEXIT_MASK); //Enter Sleep-On-Exit mode set

             dummyread = SCB_SCR;

             (void)dummyread;

             __asm("WFI");  //Enter VLPW

       }

       power_mode_status  = SMC_PMSTAT; //Pag. 206 RefMan

}

 

 

How is it possible to work with the ADC, LPTMR and LPUART when operating in VLPW? Is there a way to check if I am really entering into that mode (without measuring the current consumption in my FRDM-KL03 board)? My interrupt will be based on a GPIO input.  

 

I really appreciate any help you can provide.

Best,

Andy

0 Kudos
3 Replies

717 Views
mjbcswitzerland
Specialist V

Hi Andy

Turn on an LED each time you leave low power mode and turn it off each time you enter it - this allows the state to be seen or measured (when switching fast in and out).

Try the Open Source uTasker project for KL03 for powerful low power support (see links and videos below).

Regards

Mark


Kinetis: http://www.utasker.com/kinetis.html
Kinetis KL02/KL03/KL05:
- http://www.utasker.com/kinetis/FRDM-KL02Z.html
- http://www.utasker.com/kinetis/FRDM-KL03Z.html
- http://www.utasker.com/kinetis/FRDM-KL05Z.html
Low power mode with UARTs: https://community.nxp.com/message/421247#421247
Low power and LLWU: http://www.utasker.com/kinetis/LLWU.html
Low power videos:
- https://youtu.be/kWNlsAoMly4
- https://youtu.be/iZEMRiDmHzw
- https://youtu.be/v4UnfcDiaE4

Free Open Source solution: https://github.com/uTasker/uTasker-Kinetis
Working project in 15 minutes video: https://youtu.be/K8ScSgpgQ6M

For better, faster, cheaper product developments consider the uTasker developer's version, professional Kinetis support, one-on-one training and complete fast-track project solutions to set you apart from the herd : http://www.utasker.com/support.html

0 Kudos

717 Views
andymurray
Contributor II

Dear Mark,
thanks for your suggestion. However, I think my problem is a bit more difficult than that:
1) Processor Expert's configuration and later the instruction SetMode are not able to get the KL03 to VLPW (view my original message).
2) When I get to force the VLPW mode, something is automatically generating my interrupt, therefore I am not able to keep the KL03 in VLPW, and it goes back directly to the VLPR mode (This may be a problem of my code).

I really appreciate your comment and the links to uTasker and Youtube. However, as someone once answered you, I have invested a lot of energy understanding the KDS and Processor Expert for me to start another tool. In fact, I have decided to leave PE expert aside and start doing some more basic coding with registers, etc.

Do you have or know any code example that is always working in VLPW mode? Is it possible to keep the KL03 in only this mode without any transition to VLPR or Run?

Best, 

Andy

0 Kudos

717 Views
mjbcswitzerland
Specialist V

Andy

In any of the WAIT modes (using wif) the processor code is frozen so can't do anything. This means that there is no way to stay in the WAIT mode if there is anything that the processor needs to be able to do - the idea is that the processor stays in the WAIT mode whenever it doesn't need to actually need to work and then transitions to a RUN mode when there is something to do (due to a pending interrupt). It does its work as quickly as possibly and re-enters the WAIT mode again. All uTasker projects perform this as standard since there is no disadvantage in operation (as there can be in lower leakage modes).

Note that uTasker works with KDS so there is nothing new to be learned. It is pure register level code so would be what you are looking for. It is also strange that PE users always invest a large amount of time to get to a point where things are working but they still don't actually understand the code that they are using due to the fact that it is being generated for them. Also they tend to get stuck when PE doesn't support something because actual experience and understanding is still missing.

Regards

Mark


uTasker developer and supporter (+5'000 hours experience on +60 Kinetis derivatives in +80 product developments)
Kinetis: http://www.utasker.com/kinetis.html

0 Kudos