AnsweredAssumed Answered

Low Power Mode using os_idle_demon in CMSIS trouble with wakeup and general understanding

Question asked by kenney.jacob on Aug 22, 2017

I'm working on a low power mode for my project using an STM32L476ZG to enter when no tasks are currently running, I want to wakeup with either an interrupt controlled by the RTC (connected to an external crystal LSE) and if I plug in the USB. To save power, I am just going to turn down the system clock speed and peripheral clocks and disable some peripherals that are not needed while in a low power state. Currently, I get to os_idle_demon and turn down the clock speed, disable peripherals I don't need, and set the RTC alarm to interrupt in 15 seconds and then turn back up the clocks and re-enable disabled peripherals. This part works fine, now I am running into issues when I try to also wake up with the USB being plugged into the device. I have it exit and crank up the clock speed as soon as the USB is detected but I run into a problem in os_error with OS_ERROR_FIFO_OVF. I was wondering if there was something I needed to watch out for to trigger the USB interrupt, get a valid connection, and be able to exit low power?

 

From what I see online, a lot of people do the following in os_idle_demon:

for (;;) {    
   sleep = os_suspend();
   if(sleep){
      /* Setup the wake-up timer ... */
      /* Power-down the system ... */
      SCB->SCR |= SCB_SCR_SLEEPDEEP_Msk;
      __WFE();
      /* After Wake-up */
      sleep = (tc - LPC_WWDT->TV) / 250;
   }
   os_resume(sleep);
}

But beings I just want to turn down some clocks and disable a few things, I don't think this is what I want but maybe instead of powering down the system disable peripherals at that point?

 

I'm still a little confused on what os_suspend() and os_resume() are going to do in my code if I do follow them and instead of using __WFE() use WFI() to wait for an interrupt on either the RTC alarm or USB connection. My current implementation just waits either for an RTC alarm interrupt or the USB pin to go high, not strictly for the interrupt to trigger.

 

If I could get a little information on os_suspend() and os_resume() that might help me decide whether or not they are what I want to use or not, also if __WFI() would work for the RTC Alarm interrupt and the USB interrupt.

 

Any help would be greatly appreciated, it's mainly a matter of correcting the OS_ERROR_FIFO_OVF and be able to wake up from low power mode as soon as the USB is connected and be able to handle the interrupt so I can communicate with the device over the virtual com port.

Outcomes