# FreeRTOS：定时器服务任务超时，守护任务错过截止时间

- **ID:** `embedded/freertos-timer-service-task-overrun`
- **领域:** embedded
- **类别:** runtime_error
- **验证级别:** ai_generated
- **修复率:** 88%

## 根因

定时器服务任务（守护任务）因过多活动软件定时器或回调执行时间过长而过载，导致错过调度截止时间。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| FreeRTOS 10.5.1 | active | — | — |
| ESP-IDF 5.1.2 | active | — | — |

## 解决方案

1. ```
   Reduce number of active timers or move long callbacks to separate tasks. Example: if (xTimerIsTimerActive(xTimer)) { xTimerStop(xTimer, 0); }
   ```
2. ```
   Increase configTIMER_TASK_STACK_DEPTH in FreeRTOSConfig.h to 512 or more to prevent stack overflow, and set configTIMER_QUEUE_LENGTH to 20.
   ```

## 无效尝试

- **** — Increasing timer service task priority does not fix overrun; the issue is CPU time exhaustion, not priority inversion. (88% 失败率)
- **** — Adding more timer service tasks creates contention and worsens overrun due to scheduler overhead. (92% 失败率)
