Wakeup MCU from lowpower mode in RTOS

  1. I’m using STM32L4R5ZIT6 MCU on RTOS.
  2. I kept MCU in low power mode using SUPPRESS_TICKS_AND_SLEEP.
  3. I have enabled the external interrupt before calling Suppress ticks and sleep.
  4. On the external interrupt, MCU wakeup from sleep mode but it does not starts the threads.

My question,

  1. Is it possible to wake-up MCU using external interrupt?
  2. If yes, then what is wrong in my steps?

Yes

#2 looks suspicious. Are you calling portSUPPRESS_TICKS_AND_SLEEP() in your code? If so, you’re not supposed to do that. If you enable tickless idle, then the idle task calls portSUPPRESS_TICKS_AND_SLEEP() when conditions permit.

#4 could be an issue. Are you doing anything in the ISR to make task(s) ready? For example, you might send direct-to-task notifications or put something into a queue or signal a semaphore. If you don’t do something in the ISR to make task(s) ready, then FreeRTOS will just go back to sleep and not resume any task(s).

Thanks for the answer Jeff.
I was calling the portSUPPRESS_TICKS_AND_SLEEP() function directly, which I should not.

From the three running Thread, now I’ve disabled the 2 Threads with this function ‘osThreadSuspend()’ and one Thread is running.
Now, I’ve called the osDelay(8000) function in last and only running thread.

So, is there any way to check if my MCU is really went into the sleep mode for that amount of time?
Is this the right way to enter the MCU in low power mode for 8sec of time?

Assuming a 1ms tick, a call to osDelay(8000) delays for 8 seconds no matter what. It doesn’t matter whether you are using tickless idle, and it doesn’t matter whether something interrupts the sleep and wakes up the MCU early. It always delays 8 seconds. You don’t need to check to see if all 8 seconds elapsed.

Is this the right way to enter the MCU in low power mode for 8sec of time?

Yes, with a couple of caveats:

  • It’s typically best not to suspend tasks but instead to use your own API to induce the tasks to be prepared for sleep. For example, a GPS task could be told to stop by calling vGpsStop().
  • It would be rare for a real-life application to simply sleep for 8 seconds. Instead, you might wait for the user to press a button but time out after 8 seconds. While waiting, FreeRTOS would put the MCU into sleep mode. Your application code for this kind of delay might be ulTaskNotifyTake( pdTRUE, 8000 );
  • A small change in perspective can be helpful here. With tickless idle enabled, FreeRTOS puts the MCU into sleep mode whenever it can. If all the tasks in the application are waiting for something, then FreeRTOS will put the MCU to sleep. Instead of asking “how do I put the MCU into sleep mode”, you might ask “what should all my tasks be waiting for when my application is in the off state?”. And when all tasks are waiting, FreeRTOS will put the MCU to sleep.