上文中讨论了通过sysfs来实例化i2c设备 (rtc ds3231)

https://blog.csdn.net/feiwatson/article/details/81048616

本文继续看看如何通过 DeviceTree Overlays来实例化rtc ds3231

write dts

首先,写一个dts

/dts-v1/;
/plugin/;
/ {
compatible = "brcm,bcm2835", "brcm,bcm2708", "brcm,bcm2709"; fragment@0 {
target = <&i2c1>;
__overlay__ {
#address-cells = <1>;
#size-cells = <0>;
rtc@68 {
compatible = "maxim,ds3231";
reg = <0x68>;
#address-cells = <2>;
#size-cells = <1>;
};
};
};
};

注:

1. compatible = “maxim,ds3231”, 源码 drivers\rtc\rtc-ds1307.c中定义

2. i2c1在arch\arm\boot\dts\bcm283x.dtsi中定义

保存为文件rasp-rtc.dts

compile

copy dts到树莓派中并编译,

dtc -I dts -O dtb -o /boot/overlays/rasp-rtc.dtbo rasp-rtc.dts

生成的.dtbo到/boot/overlays

update /boot/config.txt

首先要确认i2c是使能的。如果没有使能,通过raspi-config命令来使能。

使能后在config.txt可以看到

dtparam=i2c_arm=on

增加下面内容至config.txt

# Uncomment this to enable the rtc ds3231
dtoverlay=rasp-rtc

重启

reboot后,查看/dev可以看到rtc

pi@raspberrypi:/dev $ ls -la | grep rtc
lrwxrwxrwx 1 root root 4 Jul 16 13:49 rtc -> rtc0
crw------- 1 root root 253, 0 Jul 16 13:49 rtc0

测试

pi@raspberrypi:/dev $ sudo hwclock --debug
hwclock from util-linux 2.29.2
Using the /dev interface to the clock.
Assuming hardware clock is kept in UTC time.
Waiting for clock tick...
/dev/rtc does not have interrupt functions. Waiting in loop for time from /dev/rtc to change
...got clock tick
Time read from Hardware Clock: 2018/07/16 14:13:13
Hw clock time : 2018/07/16 14:13:13 = 1531750393 seconds since 1969
Time since last adjustment is 1531750393 seconds
Calculated Hardware Clock drift is 0.000000 seconds
2018-07-16 14:13:12.176793+0000

rtc driver Code

rtc-ds1307.c中定义compatible

#ifdef CONFIG_OF
static const struct of_device_id ds1307_of_match[] = {
{
.compatible = "dallas,ds1307",
.data = (void *)ds_1307
},
{
.compatible = "dallas,ds1308",
.data = (void *)ds_1308
},
{
.compatible = "dallas,ds1337",
.data = (void *)ds_1337
},
{
.compatible = "dallas,ds1338",
.data = (void *)ds_1338
},
{
.compatible = "dallas,ds1339",
.data = (void *)ds_1339
},
{
.compatible = "dallas,ds1388",
.data = (void *)ds_1388
},
{
.compatible = "dallas,ds1340",
.data = (void *)ds_1340
},
{
.compatible = "dallas,ds1341",
.data = (void *)ds_1341
},
{
.compatible = "maxim,ds3231",
.data = (void *)ds_3231
},
{
.compatible = "st,m41t0",
.data = (void *)m41t00
},
{
.compatible = "st,m41t00",
.data = (void *)m41t00
},
{
.compatible = "microchip,mcp7940x",
.data = (void *)mcp794xx
},
{
.compatible = "microchip,mcp7941x",
.data = (void *)mcp794xx
},
{
.compatible = "pericom,pt7c4338",
.data = (void *)ds_1307
},
{
.compatible = "epson,rx8025",
.data = (void *)rx_8025
},
{
.compatible = "isil,isl12057",
.data = (void *)ds_1337
},
{ }
};
MODULE_DEVICE_TABLE(of, ds1307_of_match);
#endif

树莓派 -- i2c学习 续(1) DeviceTree Overlay实例化rtc的更多相关文章

  1. 树莓派 -- i2c学习

    硬件平台 RaspberryPi-3B+ Pioneer600外扩版 i2c芯片为DS3231,adddress 0x68 首先来看一下i2ctool的使用 i2ctool 使用 https://i2 ...

  2. 树莓派3B+学习笔记:11、查看硬件信息

    1.查看CPU信息 cat /proc/cpuinfo 查看最后三行 如果只想查看最后三行,也可使用这个命令 /proc/cpuinfo lscpu 2.查看树莓派型号 cat /proc/devic ...

  3. 树莓派4B学习札记

    防静电 树莓派比较容易被静电损坏,要做好以下预防措施 使用的时候不要用手去触摸PCB和针脚!特别是上电之后! 拿板卡的时候,要习惯性拿板卡的边缘 勤洗手,勤摸墙壁,释放身上的静电 系统安装 8GB以上 ...

  4. 学习Spring(一) 实例化Spring IoC容器

    实例化Spring IoC容器 1,读取其配置来创建bean实例 2,然后从Spring IoC容器中得到可用的bean实例 Spring提供两种IoC容器实现类型 a,一种为bean工厂 b,应用程 ...

  5. yield学习续:yield return迭代块在Unity3D中的应用——协程

    必读好文推荐: Unity协程(Coroutine)原理深入剖析 Unity协程(Coroutine)原理深入剖析再续 上面的文章说得太透彻,所以这里就记一下自己的学习笔记了. 首先要说明的是,协程并 ...

  6. Spring学习笔记之Bean的实例化

    一.bean的实例化方法有3种, 1.构造器实例化 2.静态工厂方法实例化 3.实例工厂方法实例化 二.用构造器来实例化 <bean id="ShunDao" class=& ...

  7. qnx i2c 学习 二

    File still Updating.... many errors have been FOUND , need big change  qnx i2c structure  --written ...

  8. 树莓派3B+学习笔记:1、安装官方系统

    1.登录树莓派官方网站www.raspberrypi.org,点击Downloads: 2.点击NOOBS: 3.选择下载方式,可以选择下载BT种子或直接下载,这里我用迅雷直接下载,下载速度还是很快的 ...

  9. MSP430F5438 I2C学习笔记——AT24C02

    0.前言 对于大多数单片机来说,I2C成了一个老大难问题.从51时代开始,软件模拟I2C成了主流,甚至到ARMCortex M3大行其道的今天,软件模拟I2C依然是使用最广的方法.虽然软件模拟可以解决 ...

随机推荐

  1. python 高阶函数三 filter()和sorted()

    一.filter()函数 filter()接收一个函数和一个序列.filter()把传入的函数依次作用于每个元素,然后根据返回值是True还是False决定保留还是丢弃该元素. >>> ...

  2. 前缀和小结 By cellur925

    这篇主要是来介绍前缀和的QAQ. 前缀和有一维的和二维的,一维的很容易理解,高中数学必修5第二章数列给出了前n项和的概念,就是前缀和.一维的我们在这里简单说一句. 一维前缀和 预处理:在输入一个数列的 ...

  3. Windows中句柄和ID的区别

    写在前面:这里介绍句柄 对于“句柄”,在下一直停留在一知半解的认识层面,近日在下学习Windows编程,决定趁此机会将句柄彻底搞清楚.查阅了一些网络上的资料,发现网络上的讲解大概可以分为两类:一种是以 ...

  4. 超短的判断IE javascript代码

    首先说明该代码只能在IE 6~8中有效,再高级的IE已经修复这个BUG <script type=’text/javascript’> var ie = !-[1,]; alert(ie) ...

  5. _bzoj1008 [HNOI2008]越狱【计数】

    传送门:http://www.lydsy.com/JudgeOnline/problem.php?id=1008 水题... #include <cstdio> const int mod ...

  6. [USACO 2011 Dec Gold] Threatening Letter【后缀】

    Problem 3: Threatening Letter [J. Kuipers, 2002] FJ has had a terrible fight with his neighbor and w ...

  7. C++默认函数与函数重载

    一.默认参数 在C++中,可以为参数指定默认值.在函数调用时没有指定与形参相对应的实参时, 就自动使用默认参数. 默认参数的语法与使用:(1)在函数声明或定义时,直接对参数赋值.这就是默认参数: (2 ...

  8. Thinkpad x230设置启动顺序

    设置可以从CD或者USB启动1.F1进入BIOS,Security → Secure Boot ,设置为:Disabled2.Startup → UEFI/Legacy Boot ,设置为:Both( ...

  9. .NET下集中实现AOP编程的框架

    一.Castle 使用这个框架呢,首先是需要安装NuGet包. 先建立一个控制台项目,然后在NuGet中搜索Castle.Windsor,不出意外的话应该能找到如下的包 然后安装,会自动的安装包Cas ...

  10. yum 安装报错:*epel: mirrors.aliyun.comError: xzcompressionnot available

    环境背景:epel源下载地址: http://mirrors.aliyun.com/Centos内核内核版本[root@nfs01 ~]# uname -r2.6.32-642.el6.x86_64= ...