🛠 Ajouter une RTC au CM4 (PCF8523 sur I2C1 via dt-blob)

Raspberry Pi Compute Module 4 (CM4, 2020) — Board Sheet · intermediaire · Schéma : IMG-compute-module-4-intermediaire-2-rtc-i2c-dt-blob-cm4.svg — CM4 sur IO Board ; sur l'empreinte HAT 40 broches, un module RTC PCF8523 avec pile bouton est branché sur SDA1/SCL1 (GPIO44/45) ; un porte-pile est aussi dessiné sur le connecteur RTC dédié de l'IO Board.

Objectives

The CM4 module has neither a battery-backed RTC nor an embedded real-time clock (contrary to what one might think: the datasheet lists none — it is the carrier board that provides one, with the IO Board having an RTC connector with a battery holder). This tutorial adds a PCF8523 RTC on I2C1 using the dt-blob workflow from the Peripheral Software Guide — the official method for configuring pins on a custom carrier board from the earliest stages of boot — then wires the system time to the RTC.

Hardware

Complete code

# 1) Exposer I2C1 sur GPIO44/45 via dt-blob (méthode Peripheral Software Guide)
cat > minimal-cm-dt-blob.dts <<'EOF'
/dts-v1/; /plugin/;
/ {
  pin-config {
    pin@p44 { function = "i2c1"; termination = "pull_up"; };  // SDA1
    pin@p45 { function = "i2c1"; termination = "pull_up"; };  // SCL1
  };
};
EOF
sudo dtc -I dts -O dtb -o /boot/firmware/dt-blob.bin minimal-cm-dt-blob.dts

# 2) Activer le driver RTC et purger la fausse horloge
echo 'dtoverlay=i2c-rtc,pcf8523' | sudo tee -a /boot/firmware/config.txt
sudo apt remove -y fake-hwclock || true
sudo systemctl disable -q fake-hwclock.service 2>/dev/null || true
sudo reboot

# 3) Après reboot : vérifier bus, RTC et heure
sudo i2cdetect -y 1                     # 68 = PCF8523 présent
sudo hwclock -s                         # RTC -> heure système
date && timedatectl | head -3
sudo hwclock -r -f /dev/rtc0            # lit l'heure de la RTC

Expected verification

i2cdetect -y 1 displays address 0x68; /dev/rtc0 exists; after a 5-minute power cut, date returns the correct time without NTP. dmesg | grep -i pcf8523 confirms the driver probe.

Common errors

Other tutorials for this board

Code examples for this board

← Back to the board 🛠 All tutorials