Waking up from VLLS0 with a push button - Kinetis K22

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

Waking up from VLLS0 with a push button - Kinetis K22

967 Views
felipeveraa
Contributor II

I'm having an issue with waking up a Kinetis K22 microcontroller from Very Low Leakage mode with LLWU tied to the E.1 port signal (LLWU0)

Interrupt for the button effectively puts the microcontroller to sleep and LLWU seemingly wakes up the microcontroller, as the current for the microcontroller goes up a bit, but it doesn't effectively reset the microcontroller to the Main function.

I made a little work bench with Processor Expert to make it run in a custom K22 board I made for a project.

 

Here's the code.

 

-- Called before putting the MCU in Deep Sleep mode --

void method_PowerOffDevice()
{
    uint32_t llwu_temp, dummyread;

    // Set LLWU to Button E.1 (LLWU unit 0, external pin)
    llwu_temp =     LLWU_PE1;
    llwu_temp &=     ~LLWU_PE1_WUPE0_MASK;
    llwu_temp |=     LLWU_PE1_WUPE0(0b11);
    LLWU_PE1 =        llwu_temp;

    LLWU_F1 =        LLWU_F1_WUF0_MASK;

    // Setup Sleep mode.
    PMC_REGSC |= PMC_REGSC_ACKISO_MASK;

    SMC_PMCTRL =     SMC_PMCTRL_STOPM(0x04);
    PORTD_PCR5 =    PORT_PCR_ISF_MASK;

    // Application note recommended me this after writing PMCTRL
    dummyread =     SMC_PMCTRL;
    dummyread++;

    // Activating VLLS3
    SMC_STOPCTRL =    SMC_STOPCTRL_LLSM(0x00);
    SCB_SCR =        SCB_SCR | 0x04;                    // Sleep deep mode set in the ARM core. Puts even the JTAG to sleep!

    __asm("WFI");
}

 

-- E.1 GPIO interrupt manager, tied from a GPIO_LDD component in Processor Expert. btnflag activates the method_PowerOffDevice routine to be called from the Main loop --

void BTN1_OnPortEvent(LDD_TUserData *UserDataPtr)
{
  /* Write your code here ... */
    btnflag = 1;
    PORTD_PCR5 =    PORT_PCR_ISF_MASK;
}

-- LLWU interrupt service, tied to a Init_LLWU component, with priority zero --

PE_ISR(LLWU_Button1)
{
    uint32_t    ct;

    PORTD_PCR5 = PORTD_PCR5 & ~(PORT_PCR_MUX_MASK | PORT_PCR_DSE_MASK) |
                                    (PORT_PCR_MUX(1) | PORT_PCR_DSE_MASK);
    GPIOD_PDDR = GPIOD_PDDR | (1 << 7);
    GPIOD_PSOR |= (1 << 7);

    LLWU_F1 =        LLWU_F1_WUF0_MASK;
    PORTE_PCR1 =    PORTE_PCR1 & ~PORT_PCR_IRQC_MASK | PORT_PCR_IRQC(0x0);
    PORTE_ISFR =    (1 << 1);

    // Button ISR clear
    PORTD_PCR5 =    PORT_PCR_ISF_MASK;
}

 

Here I include the test bench I'm using. I'm using Kinetis Studio 3.2.0 with GCC and Olimex JTAG. I'd prefer to keep solutions open source.

 

Thanks in advance.

Original Attachment has been moved to: Test_bench.zip

Labels (1)
3 Replies

707 Views
kerryzhou
NXP TechSupport
NXP TechSupport

Hi Felipe Vera,

    I have checked your project.

    You can change your clock mode to FEI mode(just use one clock mode) in PE, and try again ,it will work.

   It seems the your wake up problem is caused by the clock mode.

   I suggest you refer to our KSDK2.0-FRDM_K22F120M code, which can be download from this link:

Welcome to Kinetis Expert | Kinetis Expert

 Folder:SDK_2.1_FRDM-K22F\boards\frdmk22f\demo_apps\power_manager

I have modified the power_manager.c, it can enter VLLS0 and use PTE1 to wakeup, after wake up, it will enter the VLLS0 again.


Have a great day,
Kerry

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

707 Views
felipeveraa
Contributor II

Hi Kerry,

I tried by changing CPU clock mode to FEI in the test bench project Processor Expert file as you said but it keeps stuck somewhere and doesn't complete its reset.

So I tried to run power_manager.c project you supplied, with the SDK FRDM-K22F board code on my custom board but it resets on BOARD_BootClockRUN(), specifically after changing MCG register C1, when setting PEE mode. This is located on power_manager_frdmk22f/drivers/fsl_clock.c

MCG->C1 = (MCG->C1 & ~MCG_C1_CLKS_MASK) | MCG_C1_CLKS(kMCG_ClkOutSrcOut);

So I suspect that something similar happens when waking the CPU up in my board; and I am certain that it is not a hardware error, as both RTC and CPU run flawlessly when testing the supplied test program, before putting CPU into VLLS0.

I tried to search information about how to configure CPU clock manually in order to port my working project's clock configuration into the Freedom K22 board example projects -by writing into the processor registers- to make the Freedom Board code work, with no avail.

0 Kudos

707 Views
kerryzhou
NXP TechSupport
NXP TechSupport

Hi Felipe Vera,

    I have attached your project, which I have modified it to the FEI mode, and also modify the main function.

   It works on my FRDM-K22F board, download the code, after power on, and about 4-5seconds, the code enter vlls0, then connect PTE1 to ground, the MCU will wake up, and after about 4 seconds, it enter VLLS0 again.

   You can try my attached project.

   About the KSDK2.0-FRDM-K22 board, it doesn't work on your side, I think it caused by the external crystal, the FRDM-K22 is using 8Mhz crystal, but it seems you are using 16Mhz.

So, you need to modify the KSDK2.0 external crystal to your own board's frequency.

Wish it helps you!


Have a great day,
Kerry

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------