{
  "id": "embedded/rtc-calibration-drift",
  "signature": "RTC: calibration error, drift exceeds 5 ppm per day",
  "signature_zh": "RTC：校准错误，每日漂移超过5 ppm",
  "regex": "RTC:\\s*calibration\\s+error,\\s*drift\\s+exceeds\\s+\\d+\\s+ppm\\s+per\\s+day",
  "domain": "embedded",
  "category": "config_error",
  "subcategory": null,
  "root_cause": "RTC calibration register misconfiguration or temperature-induced frequency shift causes excessive time drift.",
  "root_cause_type": "generic",
  "root_cause_zh": "RTC校准寄存器配置错误或温度引起的频率偏移导致时间漂移过大。",
  "versions": [
    {
      "version": "STM32Cube_FW_L4_V1.18.0",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "IAR EWARM 9.40.1",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "ARM GCC 10.3.1",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    }
  ],
  "os_specific": {},
  "dead_ends": [
    {
      "action": "Manually adjusting RTC time every hour in firmware",
      "why_fails": "Does not address root cause; drift continues between adjustments and wastes CPU cycles.",
      "fail_rate": 0.95,
      "condition": "",
      "sources": []
    },
    {
      "action": "Replacing the external crystal with a higher-precision one without recalibrating",
      "why_fails": "Crystal tolerance alone does not compensate for internal RTC calibration errors.",
      "fail_rate": 0.8,
      "condition": "",
      "sources": []
    },
    {
      "action": "Disabling RTC calibration entirely",
      "why_fails": "Drift worsens without calibration; not a viable fix for time-sensitive applications.",
      "fail_rate": 0.9,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "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.",
      "success_rate": 0.85,
      "how": "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.",
      "condition": "",
      "sources": []
    },
    {
      "action": "Implement temperature compensation in software: read internal temperature sensor and adjust calibration register via HAL_RTCEx_SetCalibration() every 10 minutes.",
      "success_rate": 0.8,
      "how": "Implement temperature compensation in software: read internal temperature sensor and adjust calibration register via HAL_RTCEx_SetCalibration() every 10 minutes.",
      "condition": "",
      "sources": []
    },
    {
      "action": "Use a dedicated external RTC chip (e.g., DS3231) over I2C and fallback to internal RTC only for backup.",
      "success_rate": 0.9,
      "how": "Use a dedicated external RTC chip (e.g., DS3231) over I2C and fallback to internal RTC only for backup.",
      "condition": "",
      "sources": []
    }
  ],
  "workarounds_zh": [
    "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.",
    "Implement temperature compensation in software: read internal temperature sensor and adjust calibration register via HAL_RTCEx_SetCalibration() every 10 minutes.",
    "Use a dedicated external RTC chip (e.g., DS3231) over I2C and fallback to internal RTC only for backup."
  ],
  "transition_graph": {
    "leads_to": [],
    "preceded_by": [],
    "frequently_confused_with": []
  },
  "official_doc_url": "https://www.st.com/resource/en/application_note/dm00257205-rtc-calibration-on-stm32-microcontrollers-stmicroelectronics.pdf",
  "official_doc_section": null,
  "error_code": null,
  "verification_tier": "ai_generated",
  "confidence": 0.82,
  "fix_success_rate": 0.8,
  "resolvable": "true",
  "first_seen": "2023-11-20",
  "last_confirmed": "2024-06-01",
  "last_updated": "2024-06-01",
  "evidence_count": 1,
  "tags": [],
  "locale": "en",
  "aliases": []
}