10 RTC
1 RTC Real Time Clock Overview
RTC (Real Time Clock) is a hardware device specifically used to record time, and it is an important component in computer systems. The main function of RTC is to maintain time counting when the system is powered off or shut down, ensuring that the system can obtain accurate time information after restarting.
1.1 HYM8563 RTC Chip Specifications
Basic Parameters
- Chip Model: HYM8563
- Interface Type: I2C bus interface
- Working Voltage: 1.0V ~ 5.5V
- Backup Voltage: 1.0V ~ 5.5V
- I2C Address: 0x51 (7-bit address)
- I2C Rate: Supports standard mode (100kHz) and fast mode (400kHz)
Clock Accuracy
- Crystal Frequency: 32.768kHz
- Clock Accuracy: ±20ppm (25°C)
- Temperature Range: -40°C ~ +85°C
- Clock Error: About ±1 minute/month (25°C)
1.2 RTC System Architecture
Hardware Connection
RK3568J SoC
├── I2C2 Interface
│ ├── SDA (Data Line)
│ ├── SCL (Clock Line)
│ └── INT (Interrupt Line)
└── HYM8563 RTC Chip
├── 32.768kHz Crystal
├── CR2032 Coin Cell Battery
└── Power Management CircuitSoftware Architecture
Application Layer
├── date, hwclock commands
├── timedatectl tool
└── User Applications
│
Kernel Layer
├── RTC Subsystem
├── HYM8563 Driver
├── I2C Subsystem
└── Device Tree Configuration
│
Hardware Layer
├── I2C Controller
└── HYM8563 Chip1.3 Why Need RTC
Linux system time (wall time) can only be used when the system is running, and the time is lost when the system is shut down. RTC can rely on an external battery or other power source to continue working after the system is shut down, saving the time. This is particularly important for the following scenarios:
- No Network Environment: Offline devices that cannot synchronize time via NTP
- Data Integrity: Data recording systems that require accurate timestamps
- Scheduled Tasks: Systems that need to start automatically at a specific time
- Regulatory Requirements: Certain industries have strict requirements for time accuracy
2 Using RTC
The development board uses an external RTC (hym8563), and the rtc function of rk809 is disabled by default.
When using an external RTC, a coin cell battery needs to be connected.

1) RTC User Interface Call
Linux provides three user space calling interfaces. The corresponding paths on the board are:
SYSFS Interface: /sys/class/rtc/rtc0/
PROCFS Interface: /proc/driver/rtc
IOCTL Interface: /dev/rtc0
2) SYSFS Interface
cat proc/driver/rtc
rtc_time : 02:01:53
rtc_date : 2025-02-21
alrm_time : 00:00:00
alrm_date : 1970-01-01
alarm_IRQ : no
alrm_pending : no
update IRQ enabled : no
periodic IRQ enabled : no
periodic IRQ frequency : 1
max user IRQ frequency : 64
24hr : yes3) PROCFS Interface
cat /proc/driver/rtc
rtc_time : 09:50:05
rtc_date : 2024-10-21
alrm_time : 00:00:00
alrm_date : 1970-01-01
alarm_IRQ : no
alrm_pending : no
update IRQ enabled : no
periodic IRQ enabled : no
periodic IRQ frequency : 1
max user IRQ frequency : 64
24hr : yes4) IOCTL Interface
You can refer to the kernel documentation as an example: kernel/tools/testing/selftests/timers/rtcpie.c
3 Common Commands
date // Modify system clock, refer to man for specific command usage
hwclock -s // Synchronize hardware time to system time
hwclock -w // Synchronize system time to hardware time
timedatectl // Display system time, etc.
# After manually setting the time or synchronizing the time via network, use -w to write the system time to the hardware rtc, and then use -s to write the rtc time back to the system, so that the rtc time will be synchronized to the system time every time the board is restarted.
sudo date -s "2025-02-14 08:00:00" // Manually set time
sudo hwclock -w // Synchronize system time to hardware rtc
sudo hwclock -s // Synchronize hardware rtc to system3.1 NTP Time Synchronization
# Install NTP client
sudo apt-get install ntp ntpdate
# Manually synchronize time
sudo ntpdate -s time.nist.gov
# Configure NTP server
sudo nano /etc/ntp.conf
# Add NTP servers
server 0.pool.ntp.org iburst
server 1.pool.ntp.org iburst
server 2.pool.ntp.org iburst
server 3.pool.ntp.org iburst
# Start NTP service
sudo systemctl enable ntp
sudo systemctl start ntp
# Synchronize to hardware RTC
sudo hwclock -w3.2 Managing Time with timedatectl
# View time status
timedatectl status
# Set time zone
sudo timedatectl set-timezone Asia/Shanghai
# Enable NTP synchronization
sudo timedatectl set-ntp true
# Manually set time
sudo timedatectl set-time "2025-02-14 08:00:00"
# Synchronize to hardware RTC
sudo hwclock -w4 Troubleshooting
4.1 RTC Device Not Recognized
Check Steps:
# Check I2C devices
i2cdetect -y 2
# Check device tree configuration
cat /proc/device-tree/i2c@*/rtc@*/compatible
# Check kernel log
dmesg | grep -i rtc
dmesg | grep -i hym8563
# Check driver loading
lsmod | grep rtcSolution:
# Manually load RTC driver
sudo modprobe rtc-hym8563
# Check I2C bus configuration
sudo i2cget -y 2 0x51 0x004.2 Time Inaccurate or Drifting
Diagnosis Method:
# Compare system time and RTC time
date
hwclock -r
# Check clock source
cat /sys/devices/system/clocksource/clocksource0/current_clocksource
# Monitor clock drift
ntpq -pSolution:
# Calibrate RTC time
sudo ntpdate -s time.nist.gov
sudo hwclock -w
# Adjust system clock
sudo adjtimex -t4.3 Alarm Function Abnormal
Check Points:
# Check interrupt configuration
cat /proc/interrupts | grep rtc
# Check wakeup source
cat /sys/power/wakeup_count
# Test alarm function
echo +10 > /sys/class/rtc/rtc0/wakealarm
cat /sys/class/rtc/rtc0/wakealarm4.4 Low Battery
Check Method:
# Check battery voltage
cat /sys/class/rtc/rtc0/voltage
# Check low voltage flag
cat /proc/driver/rtc | grep voltage