AnsweredAssumed Answered

WFI not sending KL03 uproc into VLPS while using TPM

Question asked by CARLOS OTERO on Jun 24, 2015
Latest reply on Jun 25, 2015 by jeremyzhou

Hello dear Freescale community,

 

I have previously used VLPS modes to wake-up my KL03 from GPIO and it has worked fine. However, I am having issues trying to go into sleep mode using the TPM.

 

I want to bring the KL03 into deep sleep, then wake-up roughly every 6ms and perform some computation. I want to use the TPM as my wake-up source. However, the  WFI  instruction doesn't seem to be sending the microcontroller into deep sleep mode.  I have read before that WFI might act as a NOP if some conditions are valid, but AFAIK there is no condition to nullify the WFI call.

 

Here it is what I have tried:

 

- Using debugger and setting breakpoints on i++ and on the TPM0_IRQHandler. I see multiple sequences of i++  followed by a  TPM0_IRQHandler (when I should see a 1-to-1 interleaving).

- Disconnected debugger, and probe the FRDMKL03z J10's connection. I see a roughly constant voltage drop between 8-10mV over the 10ohm resistor in J10 (I had removed R27). If my code was working, I would expect a  lower power consumption for most of the time.

 

 

Attached is my code.  Any suggestions would be greatly appreciated. I use KDS and the default startup code.

 

Thank you!

 

<code>

 

int main(void)

{

    configure_clocks(); //Sets the MCGIR clock to 2M/8/8 = 31kHz

 

    memset(&tpm_driver_config, 0, sizeof(tpm_driver_config) );

    tpm_driver_config.isDBGMode=true;

 

    assert( TPM_DRV_Init(TPM_INSTANCE, &tpm_driver_config) == kStatusTpmSuccess);

    TPM_DRV_SetClock(TPM_INSTANCE, kClockTpmSrcMcgIrClk, kTpmDividedBy8);  //Do not divide by 8 at the end and you'll count 6.3ms

 

 

    //Configure sleep mode

    SMC_PMPROT = SMC_PMPROT_AVLP_MASK;    //Key to allow entering VLP sleep modes

    SMC_PMCTRL &= ~SMC_PMCTRL_STOPM_MASK; //Clean all other stop modes

    i = SMC_PMCTRL; //ensures the control register is written

 

    for (;;) {

        TPM_DRV_OutputCompareEnable( TPM_INSTANCE, 0, kTpmOutputNone,10000u, 5000u, true); //5k cycles for Ocompare at 31Khz/8 = 1.28s

        i++;  //Dummy computation

        SMC_PMCTRL |=  SMC_PMCTRL_STOPM(0x2);          //Allow going into VLPS

        i = SMC_PMCTRL;                               //ensures the control register is written

        __asm("WFI");

    }

    /* Never leave main */

    return 0;

}

 

 

 

void TPM0_IRQHandler( ) {

  TPM_DRV_IRQHandler(TPM_INSTANCE); //Clears appropriate flags

}

 

 

</code>

Outcomes