Sounds like you should use the default implementation of tickless idle from FreeRTOS (not the one from ST). Set configUSE_TICKLESS_IDLE
to 1. Then you should implement the configPRE_SLEEP_PROCESSING()
macro to select STOP mode (SCB->SCR |= SCB_SCR_SLEEPDEEP_Msk;
) in place of standard sleep mode if your application code is ready for STOP mode. (Don’t use stop mode while your application is actively working.) Then in configPOST_SLEEP_PROCESSING()
, select sleep mode instead of stop mode (SCB->SCR &= ~SCB_SCR_SLEEPDEEP_Msk;
).
With this solution, time will stand still during STOP mode. You’ll wake up at the same tick count you went to sleep with, even if hours have passed.