AnsweredAssumed Answered

FRDM-K64: WFI used, but does not sleep

Question asked by Brian Dwyer on Jul 14, 2016
Latest reply on Jul 14, 2016 by Kerry Zhou

I am trying to prove that I can put the K64 module on the FRDM board to LLS sleep mode, but when I execute the __asm("WFI") command, it skips over any sleep attempts and moves on to the next line of code.


A brief into to my code, and the order of operation: Green LED is turned on and the wake handler is supposed to turn it off. This never happens. In fact with debugger I have seen that the asm("WFI") code is practically skipped over. An external pin is supposed to be used to trigger wake on rising edge. Any help is appreciated.

[code begin]


#define GLED_ON (GPIOE_PDOR &= ~(1<< 26))

#define GLED_OFF (GPIOE_PDOR |= (1<<26) )


static void



//This function is used when RTC is known to keep pending interrupt at startup...(erratta note)

  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





     //Is only used to turn off the GREEN led on board





     PORTC_PCR11 = 0x00090102;    // PTC11 Wakeup rising edge, Pull-down, rising edge reset, enable IRQ

     LLWU_PE3 = 0x40;    // LLWU_P11 rising edge detection

     OSA_InstallIntHandler(LLWU_IRQn, wakeIRQHandler);





  SIM_HAL_EnableClock(SIM,kSimClockGatePortC);     //For wake pin

  SIM_HAL_EnableClock(SIM,kSimClockGatePortE);     //For green led pin

  PORTE_PCR26 = 0x00000103;

  GPIOE_PDDR = (1 << 26); // Make led-green an output

  GLED_ON;     // Make sure green LED is on







volatile unsigned int sync_read;

    LLWU_F1 = 0xFF;

    LLWU_F2 = 0xFF;


    SMC_PMCTRL = 0x03; // set stop mode to LLS

    sync_read = SMC_PMCTRL;

    sync_read++;     // Silence compiler warning


    __asm("WFI"); //Issue wait for interrupt asm

    sync_read++;     // Silence compiler warning



int main()


  /*** Processor Expert internal initialization. DON'T REMOVE THIS CODE!!! ***/


  /*** End of Processor Expert internal initialization.                    ***/






//never get here

return 0;


[code end]