# FreeRTOS: Timer command queue overflow, timer service task cannot process commands

- **ID:** `embedded/freertos-timer-queue-overflow`
- **Domain:** embedded
- **Category:** resource_error
- **Verification:** ai_generated
- **Fix Rate:** 90%

## Root Cause

Timer command queue length (configTIMER_QUEUE_LENGTH) is insufficient for the number of concurrent timer API calls from ISRs or tasks, causing queue send failures.

## Version Compatibility

| Version | Status | Introduced | Deprecated |
|---------|--------|------------|------------|
| FreeRTOS v10.5.1 | active | — | — |
| STM32Cube_FW_L4 v1.18.0 | active | — | — |
| IAR EWARM v9.40.1 | active | — | — |

## Workarounds

1. **Increase configTIMER_QUEUE_LENGTH in FreeRTOSConfig.h to at least 2x the number of concurrent timer commands (e.g., from 10 to 20). Also set configTIMER_TASK_STACK_DEPTH to 256 to avoid stack overflow.** (93% success)
   ```
   Increase configTIMER_QUEUE_LENGTH in FreeRTOSConfig.h to at least 2x the number of concurrent timer commands (e.g., from 10 to 20). Also set configTIMER_TASK_STACK_DEPTH to 256 to avoid stack overflow.
   ```
2. **Batch timer commands: instead of calling xTimerChangePeriod() per timer, use a single xTimerStop() and xTimerStart() with new period for grouped timers.** (85% success)
   ```
   Batch timer commands: instead of calling xTimerChangePeriod() per timer, use a single xTimerStop() and xTimerStart() with new period for grouped timers.
   ```

## Dead Ends

- **Increase timer task priority to highest level** — Higher priority does not increase queue length; timer commands still overflow if queue is full. (95% fail)
- **Remove all timer API calls from ISRs** — ISR calls are often necessary for time-critical operations; removal may break functionality, and overflow can still occur from tasks. (65% fail)
