# FreeRTOS：无滴答空闲模式错过系统滴答中断，检测到系统时钟漂移

- **ID:** `embedded/rtos-tickless-idle-systick-missed`
- **领域:** embedded
- **类别:** runtime_error
- **错误码:** `configUSE_TICKLESS_IDLE`
- **验证级别:** ai_generated
- **修复率:** 75%

## 根因

在无滴答空闲模式下，MCU进入深度睡眠状态且系统滴答定时器停止；若唤醒源（如RTC或外部中断）触发过晚或退出睡眠时间超出预期，则下一个系统滴答中断被错过，导致系统滴答计数漂移。

## 解决方案

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)
   ```
2. ```
   Use a dedicated low-power timer (LPTIM) as the wake-up source instead of the RTC, which provides finer granularity and reduces drift.
   ```

## 无效尝试

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