RTC on RaspberryPi3

I have the ds3231 Real Time Clock working on RPi3 FreeBSD on -CURRENT with the device tree overlay method.

1)Compile kernel with device ds3231.(I used Crochet to build my image with these options)
/usr/src/sys/arm64/conf/GENERIC
I choose to use this file as freebsd-updates will not work on rpi or current.
Optionally comment out the full debug outputs. Look at GENERIC-NODEBUG for guidance if needed.
My thought is Witness and all the other debug features are unneeded for daily use.

2) Add these lines for the overlay. Can go at bottom
ee /boot/efi.config.txt
Code:
dtoverlay=ds3231
device_tree_param=i2c0=on
device_tree_param=i2c1=on

3)Save the overlay code below as /boot/efi/overlays/ds3231.dtso
cd /boot/efi/overlays/
ee /boot/efi/overlays/ds3231.dtso
Code:
// Definition for RPi3 I2C based Real Time Clock
/dts-v1/;
/plugin/;

/ {
        compatible = "brcm,bcm2708";

        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";
        };
};

4) Then run the dtc to compile into a dtbo.
dtc -O dtb -o ds3231.dtbo -b 0 -@ ds3231.dtso

Reboot and see what shows:
Code:
root@rpi3:~ # sysctl dev.ds3231
dev.ds3231.0.32khz_enable: 1
dev.ds3231.0.sqw_mode: interrupt
dev.ds3231.0.sqw_freq: 8192
dev.ds3231.0.bbsqw: 0
dev.ds3231.0.temp_conv: 0
dev.ds3231.0.temperature: 31.5C
dev.ds3231.0.%parent: iicbus1
dev.ds3231.0.%pnpinfo: name=ds3231@68 compat=maxim,ds3231
dev.ds3231.0.%location: addr=0xd0
dev.ds3231.0.%driver: ds3231
dev.ds3231.0.%desc: Maxim DS3231 RTC
Well that was my Thankgiving weekend...

ds32310: registered as a time-of-day clock, resolution 1.000000s
 
Back
Top