Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 18 Feb 2022 22:22:30 +0800
From:      Archimedes Gaviola <archimedes.gaviola@gmail.com>
To:        "Daniel O'Connor" <darius@dons.net.au>
Cc:        freebsd-arm@freebsd.org
Subject:   Re: DS3231 RTC module not detected
Message-ID:  <CAJFbk7Ed2R8M2xAkJQAjiivZie=8Ca_Rt50YEG4P3yWzQLQhrg@mail.gmail.com>
In-Reply-To: <F2EFEDCC-1E00-4221-8AF9-3744A7AC359C@dons.net.au>
References:  <CAJFbk7EtkjnFBJgr-L3faxaQ2saNgEQ%2BLRPWbRySpwY8wJRh=Q@mail.gmail.com> <F2EFEDCC-1E00-4221-8AF9-3744A7AC359C@dons.net.au>

next in thread | previous in thread | raw e-mail | index | archive | help
--00000000000016a43205d84b9e1e
Content-Type: text/plain; charset="UTF-8"

On Fri, Feb 18, 2022 at 7:08 AM Daniel O'Connor <darius@dons.net.au> wrote:

>
>
> > On 18 Feb 2022, at 02:02, Archimedes Gaviola <
> archimedes.gaviola@gmail.com> wrote:
> > I have a DS3231 real-time clock module (
> http://wiki.sunfounder.cc/index.php?title=DS3231_Real_Time_Clock_Module_for_Raspberry_Pi)
> but cannot be detected with FreeBSD 13.0-RELEASE and 14.0-CURRENT. My
> config.txt have this following lines;
> >
> > dtparam=i2c_arm=on
> > dtoverlay=i2c-rtc,ds3231
> >
> > and then I fetched a copy of the i2c-rtc.dtbo file here
> https://github.com/raspberrypi/firmware/blob/master/boot/overlays/i2c-rtc.dtbo
> and put it in the /boot/msdos/overlays directory.
>
> I have a DS1307 board on an RPi4 and I made the following modifications:
>
> I have /boot/msdos/overlays/ds1307.dtso with the following contents:
> // Definition for RPi3 I2C based Real Time Clock
> /dts-v1/;
> /plugin/;
>
> / {
>         compatible = "brcm,bcm2835";
>
>         fragment@0 {
>                 target = <&i2c1>;
>                 __overlay__ {
>                         #address-cells = <1>;
>                         #size-cells = <0>;
>                         status = "okay";
>                                 ds1307: ds1307@68 {
>                                         compatible = "maxim,ds1307";
>                                         reg = <0x68>;
>                                         status = "okay";
>                         };
>                 };
>         };
>         __overrides__ {
>                 ds1307 = <&ds1307>,"status";
>         };
> };
>
> Then compiled it with..
> sudo dtc -O dtb -o /boot/msdos/overlays/ds1307.dtbo -b 0 -@
> /boot/msdos/overlays/ds1307.dtso
>
> In /boot/msdos/config.txt I have..
>
> [all]
> ...
> # DS1307 RTC
> dtparam=i2c_arm=on
> dtoverlay=ds1307
> ...
> [pi4]
> # For I2C as per
> # https://lists.freebsd.org/pipermail/freebsd-arm/2021-May/023713.html
> gpio=2,3=a0
>
> If it doesn't work post your dmesg output, but I suspect changing the
> config.txt as just above will fix it.
>

Hi Daniel,

Thanks for the info! I followed similar with your DS1307 RTC by creating a
ds3231.dtso file and then compiling it with dtc to generate a ds3231.dtbo.
The result is it is detected as MAX77620 RTC on 0xd0 address but when I run
an i2c scan, the address detected is 68. Does this should match?

With this setup I could update the date and time now by initiating an
ntpdate to match our time plus invoking tzsetup command for my timezone
which is doing well without any issue. Now, the moment I shutdown the
system and plug back the power cable (with disconnected Ethernet cable just
to make sure NTP servers are not called for updates upon restart) the time
remains as it was before shutting down and then upon bootup system clock
continues. I am expecting that it should be real time even if the RPi4
system is shutdown or detached from power due to the battery that will
sustain the continuity of the clock. I'm sure that I'm having good DS3231
modules as I also tested my existing and another new spare and it is tested
with OpenBSD too. Below are the system info. Is there anything I've missed?
FreeBSD 13.0-RELEASE have the same outcome and behavior.

freebsd@generic:~ % uname -a
FreeBSD generic 14.0-CURRENT FreeBSD 14.0-CURRENT #0
main-n253065-8dc42f98047: Thu Feb 10 09:27:01 UTC 2022
root@releng1.nyi.freebsd.org:/usr/obj/usr/src/arm64.aarch64/sys/GENERIC
 arm64

freebsd@generic:~ % dmesg | grep iic
iichb0: <BCM2708/2835 BSC controller> mem 0x7e804000-0x7e804fff irq 26 on
simplebus0
iicbus0: <OFW I2C bus> on iichb0
iic0: <I2C generic I/O> on iicbus0
rtc0: <MAX77620 RTC> at addr 0xd0 on iicbus0
rtc0: registered as a time-of-day clock, resolution 1.000000s

root@generic:~ # i2c -s
68

root@generic:~ # sysctl -a | grep rtc
rtc0: <MAX77620 RTC> at addr 0xd0 on iicbus0
rtc0: registered as a time-of-day clock, resolution 1.000000s
"max77620_rtc","bcm_bsc"
"rtc list","max77620_rtc"
machdep.disable_rtc_set: 0
machdep.rtc_save_period: 1800
dev.rtc.0.%parent: iicbus0
dev.rtc.0.%pnpinfo: name=ds3231@68 compat=maxim,ds3231
dev.rtc.0.%location: addr=0xd0
dev.rtc.0.%driver: rtc
dev.rtc.0.%desc: MAX77620 RTC
dev.rtc.%parent:

freebsd@generic:~ % cat /boot/msdos/overlays/ds3231.dtso
// Definition for RPi3 I2C based Real Time Clock
/dts-v1/;
/plugin/;

/ {
        compatible = "brcm,bcm2835";

        fragment@0 {
                target = <&i2c1>;
                __overlay__ {
                        #address-cells = <1>;
                        #size-cells = <0>;
                        status = "okay";
                                ds3231: ds3231@68 {
                                        compatible = "maxim,ds3231";
                                        reg = <0x68>;
                                        status = "okay";
                        };
                };
        };
        __overrides__ {
                ds3231 = <&ds3231>,"status";
        };
};

and my config.txt have

dtparam=i2c_arm=on
dtoverlay=ds3231
gpio=2,3=a0

Thanks,
Archimedes

--00000000000016a43205d84b9e1e
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr"><div dir=3D"ltr"><br></div><br><div class=3D"gmail_quote">=
<div dir=3D"ltr" class=3D"gmail_attr">On Fri, Feb 18, 2022 at 7:08 AM Danie=
l O&#39;Connor &lt;<a href=3D"mailto:darius@dons.net.au">darius@dons.net.au=
</a>&gt; wrote:<br></div><blockquote class=3D"gmail_quote" style=3D"margin:=
0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">=
<br>
<br>
&gt; On 18 Feb 2022, at 02:02, Archimedes Gaviola &lt;<a href=3D"mailto:arc=
himedes.gaviola@gmail.com" target=3D"_blank">archimedes.gaviola@gmail.com</=
a>&gt; wrote:<br>
&gt; I have a DS3231 real-time clock module (<a href=3D"http://wiki.sunfoun=
der.cc/index.php?title=3DDS3231_Real_Time_Clock_Module_for_Raspberry_Pi" re=
l=3D"noreferrer" target=3D"_blank">http://wiki.sunfounder.cc/index.php?titl=
e=3DDS3231_Real_Time_Clock_Module_for_Raspberry_Pi</a>) but cannot be detec=
ted with FreeBSD 13.0-RELEASE and 14.0-CURRENT. My config.txt have this fol=
lowing lines;<br>
&gt; <br>
&gt; dtparam=3Di2c_arm=3Don<br>
&gt; dtoverlay=3Di2c-rtc,ds3231<br>
&gt; <br>
&gt; and then I fetched a copy of the i2c-rtc.dtbo file here <a href=3D"htt=
ps://github.com/raspberrypi/firmware/blob/master/boot/overlays/i2c-rtc.dtbo=
" rel=3D"noreferrer" target=3D"_blank">https://github.com/raspberrypi/firmw=
are/blob/master/boot/overlays/i2c-rtc.dtbo</a> and put it in the /boot/msdo=
s/overlays directory. <br>
<br>
I have a DS1307 board on an RPi4 and I made the following modifications:<br=
>
<br>
I have /boot/msdos/overlays/ds1307.dtso with the following contents:<br>
// Definition for RPi3 I2C based Real Time Clock<br>
/dts-v1/;<br>
/plugin/;<br>
<br>
/ {<br>
=C2=A0 =C2=A0 =C2=A0 =C2=A0 compatible =3D &quot;brcm,bcm2835&quot;;<br>
<br>
=C2=A0 =C2=A0 =C2=A0 =C2=A0 fragment@0 {<br>
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 target =3D &lt;&amp=
;i2c1&gt;;<br>
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 __overlay__ {<br>
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=
=A0 =C2=A0 #address-cells =3D &lt;1&gt;;<br>
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 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>
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 ds1307 =3D &lt;&amp=
;ds1307&gt;,&quot;status&quot;;<br>
=C2=A0 =C2=A0 =C2=A0 =C2=A0 };<br>
};<br>
<br>
Then compiled it with..<br>
sudo dtc -O dtb -o /boot/msdos/overlays/ds1307.dtbo -b 0 -@ /boot/msdos/ove=
rlays/ds1307.dtso<br>
<br>
In /boot/msdos/config.txt I have..<br>
<br>
[all]<br>
...<br>
# DS1307 RTC<br>
dtparam=3Di2c_arm=3Don<br>
dtoverlay=3Dds1307<br>
...<br>
[pi4]<br>
# For I2C as per<br>
# <a href=3D"https://lists.freebsd.org/pipermail/freebsd-arm/2021-May/02371=
3.html" rel=3D"noreferrer" target=3D"_blank">https://lists.freebsd.org/pipe=
rmail/freebsd-arm/2021-May/023713.html</a><br>
gpio=3D2,3=3Da0<br>
<br>
If it doesn&#39;t work post your dmesg output, but I suspect changing the c=
onfig.txt as just above will fix it.<br></blockquote><div><br></div></div><=
div class=3D"gmail_quote">Hi Daniel,</div><div class=3D"gmail_quote"><br></=
div><div class=3D"gmail_quote">Thanks for the info! I followed similar with=
 your DS1307 RTC by creating a ds3231.dtso file and then compiling it with =
dtc to generate a ds3231.dtbo. The result is it is detected as MAX77620 RTC=
 on 0xd0 address but when I run an i2c scan, the address detected is 68. Do=
es this should match?<br></div><div class=3D"gmail_quote"><br></div><div cl=
ass=3D"gmail_quote">With this setup I could update the date and time now by=
 initiating an ntpdate to match our time plus invoking tzsetup command for =
my timezone which is doing well without any issue. Now, the moment I shutdo=
wn the system and plug back the power cable (with disconnected Ethernet cab=
le just to make sure NTP servers are not called for updates upon restart) t=
he time remains as it was before shutting down and then upon bootup system =
clock continues. I am expecting that it should be real time even if the RPi=
4 system is shutdown or detached from power due to the battery that will su=
stain the continuity of the clock. I&#39;m sure that I&#39;m having good DS=
3231 modules as I also tested my existing and another new spare and it is t=
ested with OpenBSD too. Below are the system info. Is there anything I&#39;=
ve missed? FreeBSD 13.0-RELEASE have the same outcome and behavior.<br></di=
v><div class=3D"gmail_quote"></div><div class=3D"gmail_quote"><br></div><di=
v class=3D"gmail_quote">freebsd@generic:~ % uname -a<br>FreeBSD generic 14.=
0-CURRENT FreeBSD 14.0-CURRENT #0 main-n253065-8dc42f98047: Thu Feb 10 09:2=
7:01 UTC 2022 =C2=A0 =C2=A0 root@releng1.nyi.freebsd.org:/usr/obj/usr/src/a=
rm64.aarch64/sys/GENERIC =C2=A0arm64</div><div class=3D"gmail_quote"><br></=
div><div class=3D"gmail_quote">freebsd@generic:~ % dmesg | grep iic<br>iich=
b0: &lt;BCM2708/2835 BSC controller&gt; mem 0x7e804000-0x7e804fff irq 26 on=
 simplebus0<br>iicbus0: &lt;OFW I2C bus&gt; on iichb0<br>iic0: &lt;I2C gene=
ric I/O&gt; on iicbus0<br>rtc0: &lt;MAX77620 RTC&gt; at addr 0xd0 on iicbus=
0</div><div class=3D"gmail_quote">
rtc0: registered as a time-of-day clock, resolution 1.000000s

</div><div class=3D"gmail_quote"><br></div><div class=3D"gmail_quote">
root@generic:~ # i2c -s<br>68</div><div class=3D"gmail_quote"><br></div><di=
v class=3D"gmail_quote">root@generic:~ # sysctl -a | grep rtc<br>rtc0: &lt;=
MAX77620 RTC&gt; at addr 0xd0 on iicbus0<br>rtc0: registered as a time-of-d=
ay clock, resolution 1.000000s<br>&quot;max77620_rtc&quot;,&quot;bcm_bsc&qu=
ot;<br>&quot;rtc list&quot;,&quot;max77620_rtc&quot;<br>machdep.disable_rtc=
_set: 0<br>machdep.rtc_save_period: 1800<br>dev.rtc.0.%parent: iicbus0<br>d=
ev.rtc.0.%pnpinfo: name=3Dds3231@68 compat=3Dmaxim,ds3231<br>dev.rtc.0.%loc=
ation: addr=3D0xd0<br>dev.rtc.0.%driver: rtc<br>dev.rtc.0.%desc: MAX77620 R=
TC<br>dev.rtc.%parent:</div><div class=3D"gmail_quote"><br></div><div class=
=3D"gmail_quote"></div><div class=3D"gmail_quote">freebsd@generic:~ % cat /=
boot/msdos/overlays/ds3231.dtso<br>// Definition for RPi3 I2C based Real Ti=
me Clock<br>/dts-v1/;<br>/plugin/;<br><br>/ {<br>=C2=A0 =C2=A0 =C2=A0 =C2=
=A0 compatible =3D &quot;brcm,bcm2835&quot;;<br><br>=C2=A0 =C2=A0 =C2=A0 =
=C2=A0 fragment@0 {<br>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=
=A0 target =3D &lt;&amp;i2c1&gt;;<br>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=
=A0 =C2=A0 =C2=A0 __overlay__ {<br>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=
=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 #address-cells =3D &lt;1&gt;;=
<br>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =
=C2=A0 =C2=A0 #size-cells =3D &lt;0&gt;;<br>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=
=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 status =3D &quot;okay&=
quot;;<br>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 ds3231: ds3231@68 {<br>=C2=
=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 compatible =
=3D &quot;maxim,ds3231&quot;;<br>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=
=A0 =C2=A0 =C2=A0 =C2=A0 reg =3D &lt;0x68&gt;;<br>=C2=A0 =C2=A0 =C2=A0 =C2=
=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 status =3D &quot;okay&quot;;<br>=
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=
=A0 =C2=A0 };<br>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 };=
<br>=C2=A0 =C2=A0 =C2=A0 =C2=A0 };<br>=C2=A0 =C2=A0 =C2=A0 =C2=A0 __overrid=
es__ {<br>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 ds3231 =
=3D &lt;&amp;ds3231&gt;,&quot;status&quot;;<br>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =
};<br>};</div><div class=3D"gmail_quote"><br></div><div class=3D"gmail_quot=
e">and my config.txt have</div><div class=3D"gmail_quote"><br></div><div cl=
ass=3D"gmail_quote">dtparam=3Di2c_arm=3Don</div><div class=3D"gmail_quote">=
dtoverlay=3Dds3231</div><div class=3D"gmail_quote">gpio=3D2,3=3Da0</div><di=
v class=3D"gmail_quote"><br></div><div class=3D"gmail_quote">Thanks,</div><=
div class=3D"gmail_quote">Archimedes</div></div>

--00000000000016a43205d84b9e1e--



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?CAJFbk7Ed2R8M2xAkJQAjiivZie=8Ca_Rt50YEG4P3yWzQLQhrg>