# RTC：校准错误，每日漂移超过5 ppm

- **ID:** `embedded/rtc-calibration-drift`
- **领域:** embedded
- **类别:** config_error
- **验证级别:** ai_generated
- **修复率:** 80%

## 根因

RTC校准寄存器配置错误或温度引起的频率偏移导致时间漂移过大。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| STM32Cube_FW_L4_V1.18.0 | active | — | — |
| IAR EWARM 9.40.1 | active | — | — |
| ARM GCC 10.3.1 | active | — | — |

## 解决方案

1. ```
   Recalibrate RTC using HAL_RTCEx_SetCalibration(): call HAL_RTCEx_SetCalibration(&hrtc, RTC_CALIBRATION_SIGN_POSITIVE, 0, 0x80); then measure drift and adjust CALP/CALM bits accordingly.
   ```
2. ```
   Implement temperature compensation in software: read internal temperature sensor and adjust calibration register via HAL_RTCEx_SetCalibration() every 10 minutes.
   ```
3. ```
   Use a dedicated external RTC chip (e.g., DS3231) over I2C and fallback to internal RTC only for backup.
   ```

## 无效尝试

- **Manually adjusting RTC time every hour in firmware** — Does not address root cause; drift continues between adjustments and wastes CPU cycles. (95% 失败率)
- **Replacing the external crystal with a higher-precision one without recalibrating** — Crystal tolerance alone does not compensate for internal RTC calibration errors. (80% 失败率)
- **Disabling RTC calibration entirely** — Drift worsens without calibration; not a viable fix for time-sensitive applications. (90% 失败率)
