# SysTick：定时器下溢检测到，系统滴答计数损坏

- **ID:** `embedded/arm-systick-timer-underflow`
- **领域:** embedded
- **类别:** runtime_error
- **验证级别:** ai_generated
- **修复率:** 90%

## 根因

SysTick定时器重载值设置过低或时钟分频器配置错误，导致计数器在中断服务程序递增滴答计数之前下溢。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| CMSIS 5.9.0 | active | — | — |
| FreeRTOS 10.4.6 | active | — | — |
| ARM Cortex-M4 r1p1 | active | — | — |

## 解决方案

1. ```
   Set SysTick reload value to (SystemCoreClock / 1000) - 1 for 1ms tick, and ensure CLKSOURCE bit selects processor clock. Example: SysTick_Config(SystemCoreClock / 1000);
   ```
2. ```
   Add a guard in SysTick_Handler to check reload value: if (SysTick->LOAD == 0) { SysTick->LOAD = (SystemCoreClock / 1000) - 1; }
   ```

## 无效尝试

- **** — Increasing SysTick interrupt priority does not fix the underflow, as the issue is timer reload value, not priority masking. (85% 失败率)
- **** — Adding more delay loops in main loop does not prevent timer underflow; the problem is deterministic and timing-independent. (90% 失败率)
