Software timers with lowpower mode and tickless Idle

Hi

I am trying to start a software timer within an ISR handler. The workflow is as described below:

  1. Suppress the tick
  2. Enter sleep mode, waiting for an interrupt, and then use WFI.
    Then I wake up the MCU by an external interrupt, for example, a push button
    The MCU wakes up and enables the interrupts, then the ISR starts to run and tries to start the software timer from the ISR.
    What happens is that the software timer fires immediately, which I suspect that the timer fires because the tick is not yet restored and the OS tick is not stable.
    How can I solve this Issue?

Note: I am using STM32H562 MCU with tickless idle, and LPtimer following the concept from No-Drift FreeRTOS tick/tickless for STM32 via LPTIM · GitHub.

Hi Basel,

Yes you are correct about the root cause of the issue. The most common workaround is to call xTimerChangePeriodFromISR(). That function starts the timer after the tickless implementation updates the system tick count.

Hi Jeff,
How would the xTimerChangePeriodFromISR help? are you pointing to call xTimerChangePeriodFromISR instead of xTimerStartfromISR?

BR
Basel

@BaselHn Yes. If you call xTimerChangePeriodFromISR() instead of xTimerStartFromISR(), you’ll resolve this issue. It’s just a minor difference in the way these functions start the timer. xTimerStartFromISR() starts the timer from the tick count captured in the ISR, but xTimerChangePeriodFromISR() uses the tick count captured in the timer task context when it is starting the timer.

1 Like

Hi Jeff,

Thanks for the quick reply and help. When I finish my testing, I will update the thread as solved if everything goes correctly as expected. For the first test, this seems to solve the issue I faced. I want to make sure I don’t have any more issues.

BR
Basel

Hi Jeff,

Thanks for helping, it was very helpful.

BR
Basel

1 Like