configUSE_TICKLESS_IDLE embedded runtime_error ai_generated true

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

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

ID: embedded/rtos-tickless-idle-systick-missed

其他格式: JSON · Markdown 中文 · English
75%修复率
83%置信度
1证据数
2024-01-10首次发现

根因分析

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

English

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.

generic

官方文档

https://www.freertos.org/Documentation/RTOS_book.html

解决方案

  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.

无效尝试

常见但无效的做法:

  1. 50% 失败

    Disabling tickless idle entirely (configUSE_TICKLESS_IDLE = 0) increases power consumption but does not fix the underlying issue of Systick wake-up timing.

  2. 80% 失败

    Increasing the Systick interrupt priority does not prevent the miss because the issue is timing, not priority inversion.