linux调试外部RTC hym8563

DTS配置

bash 复制代码
&i2c5 {
	status = "okay";
		hym8563: hym8563@51 {
		status = "okay";
		compatible = "haoyu,hym8563";
		reg = <0x51>;
		pinctrl-names = "default";
		pinctrl-0 = <&hym8563_int>;
		interrupt-parent = <&gpio0>;
		interrupts = <RK_PD3 IRQ_TYPE_LEVEL_LOW>;
	};
};

RTC常用的调试命令

bash 复制代码
i2cdetect -l
i2cdetect -y 5
cat /sys/bus/i2c/devices/5-0051/name

date -s "2025-10-10 10:00:00"
date
ls -al /dev/rtc*

# 没有hwclock 可以暂时使用 busybox hwclock
sudo busybox hwclock --systohc --rtc=/dev/rtc1
sudo busybox hwclock --show --rtc=/dev/rtc1
sudo busybox hwclock --systohc

# 系统 → 硬件RTC   把系统时间写到 rtc1       
sudo hwclock -w
sudo hwclock --systohc
sudo hwclock --rtc=/dev/rtc1 --systohc

# 显示硬件时间
sudo hwclock
sudo hwclock --rtc=/dev/rtc1 --show

# 硬件RTC → 系统	读取并设置 硬件RTC时间 更新 系统时间
sudo hwclock -s
sudo hwclock --rtc=/dev/rtc1 --hctosys

# 从系统层读取 rtc1 的当前时间(硬件时钟)
cat /sys/class/rtc/rtc1/time
cat /sys/class/rtc/rtc1/date

# 合并显示
echo "$(cat /sys/class/rtc/rtc1/date) $(cat /sys/class/rtc/rtc1/time)"

# 输出hym8563
cat /sys/class/rtc/rtc1/name

发现默认多打开了一个没用的RTC,导致掉电后开机硬件时间默认从rtc0同步给系统时间(实际外部rtc使用的是rtc1),导致时间不准确,将其关掉。

bash 复制代码
# CONFIG_RTC_DRV_RK808 is not set

尽量使用hwclock,因为busybox hwclock 可能会忽略 /etc/adjtime 的 UTC/LOCAL 设置,导致时间差个时区错误。

bash 复制代码
# 正确的 adjtime 配置
cat /etc/adjtime
0.000000 1764923689 0.000000
1764923689
UTC

打印下面报错没关系,rtc 信息有效

bash 复制代码
[    3.175747] rtc-hym8563 5-0051: hym8563_init_device: error read i2c data -6
[    3.178347] rtc-hym8563 5-0051: rtc information is valid
[    3.185643] rtc-hym8563 5-0051: registered as rtc0

如果开机有打印下面错误

bash 复制代码
[    0.879621] rtc-hym8563 3-0051: could not init device, -6

可以参考火柴棍大佬的文章修改:https://huochaigun.blog.csdn.net/article/details/124230641?fromshare=blogdetail\&sharetype=blogdetail\&sharerId=124230641\&sharerefer=PC\&sharesource=2301_76966953\&sharefrom=from_link

相关推荐
fly_sunnn5 小时前
STM32-GPIO
stm32·单片机·嵌入式硬件
广州浮点FLOATLIC7 小时前
许可证服务器迁移后软件打不开:研发 IT 怎样定位连接问题
linux·服务器·数据库
BLUcoding7 小时前
接口服务公网超时排查记录:SecureRandom 阻塞问题分析与解决
java·linux·springboot·aes·securerandom
AIgorithmGEEK7 小时前
[Linux]从手写报头到内核套路:序列化、反序列化与自定义协议全链路
linux·运维·服务器·网络·序列化·反序列化
Nil2087 小时前
leetcode 139单词拆分
linux·运维·服务器
Starry-sky(jing)7 小时前
BUG: unable to handle kernel paging request 完整排查:dmesg 四要素与三路定罪
linux·运维·服务器·内核·排障
mounter6257 小时前
从硬件互连到操作系统变革:CXL 技术演进与 Linux 内核工程挑战
linux·运维·服务器
宵时待雨8 小时前
STM32基础1:嵌入式历史与生态
stm32·单片机·嵌入式硬件
xh didida9 小时前
Linux -- 基础IO
linux·服务器·开发语言·c++
不会代码的小猴9 小时前
启动文件
stm32·嵌入式硬件