# RTC: calibration error, drift exceeds 5 ppm per day

- **ID:** `embedded/rtc-calibration-drift`
- **Domain:** embedded
- **Category:** config_error
- **Verification:** ai_generated
- **Fix Rate:** 80%

## Root Cause

RTC calibration register misconfiguration or temperature-induced frequency shift causes excessive time drift.

## Version Compatibility

| Version | Status | Introduced | Deprecated |
|---------|--------|------------|------------|
| STM32Cube_FW_L4_V1.18.0 | active | — | — |
| IAR EWARM 9.40.1 | active | — | — |
| ARM GCC 10.3.1 | active | — | — |

## Workarounds

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.** (85% success)
   ```
   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.** (80% success)
   ```
   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.** (90% success)
   ```
   Use a dedicated external RTC chip (e.g., DS3231) over I2C and fallback to internal RTC only for backup.
   ```

## Dead Ends

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