# FreeRTOS: tickless idle mode missed Systick interrupt, system clock drift detected

- **ID:** `embedded/rtos-tickless-idle-systick-missed`
- **Domain:** embedded
- **Category:** runtime_error
- **Error Code:** `configUSE_TICKLESS_IDLE`
- **Verification:** ai_generated
- **Fix Rate:** 75%

## Root Cause

In tickless idle mode, the MCU enters a deep sleep state and the Systick timer is stopped; if the wake-up source (e.g., RTC or external interrupt) triggers too late or the sleep exit time is longer than expected, the next Systick interrupt is missed, causing the system tick count to drift.

## Workarounds

1. **Implement a correction algorithm in the portSUPPRESS_TICKS_AND_SLEEP() macro. Example: #define portSUPPRESS_TICKS_AND_SLEEP(xExpectedIdleTime) \ do { \     uint32_t ulSysTickCount = SysTick->VAL; \     if (xExpectedIdleTime > 100) { \         // Enter sleep with RTC wake-up \         HAL_RTCEx_SetWakeUpTimer_IT(&hrtc, xExpectedIdleTime - 1, RTC_WAKEUPCLOCK_RTCCLK_DIV16); \         __WFI(); \         // Recalculate missed ticks \         xExpectedIdleTime = (xExpectedIdleTime - (ulSysTickCount - SysTick->VAL) / (SystemCoreClock / 1000)); \     } \ } while(0)** (80% success)
   ```
   Implement a correction algorithm in the portSUPPRESS_TICKS_AND_SLEEP() macro. Example: #define portSUPPRESS_TICKS_AND_SLEEP(xExpectedIdleTime) \ do { \     uint32_t ulSysTickCount = SysTick->VAL; \     if (xExpectedIdleTime > 100) { \         // Enter sleep with RTC wake-up \         HAL_RTCEx_SetWakeUpTimer_IT(&hrtc, xExpectedIdleTime - 1, RTC_WAKEUPCLOCK_RTCCLK_DIV16); \         __WFI(); \         // Recalculate missed ticks \         xExpectedIdleTime = (xExpectedIdleTime - (ulSysTickCount - SysTick->VAL) / (SystemCoreClock / 1000)); \     } \ } while(0)
   ```
2. **Use a dedicated low-power timer (LPTIM) as the wake-up source instead of the RTC, which provides finer granularity and reduces drift.** (85% success)
   ```
   Use a dedicated low-power timer (LPTIM) as the wake-up source instead of the RTC, which provides finer granularity and reduces drift.
   ```

## Dead Ends

- **** — Disabling tickless idle entirely (configUSE_TICKLESS_IDLE = 0) increases power consumption but does not fix the underlying issue of Systick wake-up timing. (50% fail)
- **** — Increasing the Systick interrupt priority does not prevent the miss because the issue is timing, not priority inversion. (80% fail)
