Pauli Nikula

KL17 LLWU wakeup gets stuck on interrupt handler

Discussion created by Pauli Nikula on Apr 13, 2018
Latest reply on Apr 16, 2018 by Kerry Zhou



I have encountered problem with KL17Z256 chip I'm working with. I have setup the MCU to go to VLLS1 mode, and wake up from external accelerometer pin interrupt, LPTMR0 interrupt and also RTC alarm. LPTMR0 and RTC interrupt is currently disabled as the problem seems to be caused by the interrupt pin. Problem is that if I generate one interrupt by tapping my table next to the chip (accelerometer is very sensitive), MCU wakes up normally and everything seems to work fine. But if I do multiple taps in rapid fashion, MCU might keep up usually 3-5 times (wakeup and go back to sleep quickly), but then crashes and stops doing anything. 


By using debugger I can see that MCU gets stuck in the LLWU IRQ handler. I suppose I'm clearing all the flags properly. To me the problem looks like that too rapid interrupts cause the LLWU to function abnormally during wake up. Here is my LLWU IRQhandler:



void LLWU_IRQHandler()

/* If wakeup by LPTMR. */
if ( LLWU->F3 & 0x01)

   wake = 1;

else if (LLWU->F3 & 0x20) //if wakeup from RTC alarm
   wake = 3;
   CLOCK_EnableClock(kCLOCK_Rtc0); //enable RTC bus clock so we can write registers
   RTC->TAR = RTC_REPORT_INTERVAL; //write to alarm register to clear interrupt flag

else if ( LLWU->F1 & 0x20) //if wakeup from accelerometer pin(LLWU P5)

   wake = 2;
   LLWU->F1 |= 0x20;
   LLWU->FILT1 |= 0x80;
   while(LLWU ->F1 & 0x20);



From debugger I can see that on the stuck state, MCU is continuously running on LLWU_IRQHandler, but is not entering any of my if conditions regarding the flags, which is quite puzzling.


Here is my initialization code:


int main(void)


   NVIC_EnableIRQ(LLWU_IRQn);//enable LLWU interrupts. if we wake up from VLLS mode, it means that next MCU
   //will jump to the LLWU interrupt vector
   PMC->REGSC |= 0x08; //acknowledge wake up to voltage regulator module, this is needed with LLWU wake up

   BOARD_InitPins(); //init all physical pins

   SysTick_Config(BOARD_DEBUG_UART_CLK_FREQ / 1000); //setup SysTick timer for 1ms interval for delay functions(see timing.h)

   configureSleepMode(); //set power mode protection and LLWU wakeup sources here

if (wake == 2) //wakeup by accelerometer


   PCprint("Woken by accelerometer\r\n");

   SMC_SetPowerModeVlls(SMC, &smc_power_mode_vlls_config);

   printInterruptFlags();  //sometimes something prevents entry to stop mode, try to catch here what it was