Re: DS3231 RTC module not detected

From: Archimedes Gaviola <archimedes.gaviola_at_gmail.com>
Date: Fri, 18 Feb 2022 14:22:30 UTC
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