Enable real time clock (ds3231 module) on raspberry pi 4

Is there any instruction on what package requirement and how to install it? I'm using latest snapshot build on raspberry pi 4 (july 5th, no stable version yet) and I've tried enabling all possible module related to i2c, enabling it in /boot/config.txt but I when I tried hwclock -r it still doesn't detect the hardware clock.

Also in some tutorials I've seen kmod-rtc-ds1307 required but the package doesn't appear in opkg list.

grep 'i2c' /boot/config.txt
grep 'i2c' /boot/distroconfig.txt
opkg list-installed | grep -E '(rpi|i2c)'

here's the result of grep 'i2c' /boot/config.txt

dtparam=i2c1=on
dtoverlay=i2c-rtc,ds3231

grep 'i2c' /boot/distroconfig.txt shows nothing though. when I use i2cdetect -y 1 here's the result :

i2cdetect -y 1
     0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
00:          -- -- -- -- -- -- -- -- -- -- -- -- --
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
60: -- -- -- -- -- -- -- -- 68 -- -- -- -- -- -- --
70: -- -- -- -- -- -- -- --

edit :
opkg list-installed | grep -E '(rpi|i2c)' shows :

cypress-nvram-43455-sdio-rpi-4b - 2019-09-03-e7b78df2-1
i2c-tools - 4.1-4
kmod-i2c-algo-bit - 5.4.50-1
kmod-i2c-bcm2835 - 5.4.50-1
kmod-i2c-core - 5.4.50-1
kmod-i2c-gpio - 5.4.50-1
libi2c - 4.1-4
1 Like
i2cget -y 1 0x68
lsmod | grep ds
grep i2c /etc/rc.local

i2cget -y 1 0x68 result :

0x25

lsmod | grep ds result :

x_tables               32768 40 xt_connlimit,xt_state,xt_nat,xt_helper,xt_conntrack,xt_connmark,xt_connbytes,xt_REDIRECT,xt_MASQUERADE,xt_FLOWOFFLOAD,xt_CT,ipt_REJECT,xt_time,xt_tcpudp,xt_tcpmss,xt_statistic,xt_recent,xt_multiport,xt_mark,xt_mac,xt_limit,xt_length,xt_hl,xt_ecn,xt_dscp,xt_comment,xt_TCPMSS,xt_LOG,xt_HL,xt_DSCP,xt_CLASSIFY,iptable_raw,iptable_mangle,iptable_filter,ipt_ECN,ip_tables,ip6table_mangle,ip6table_filter,ip6_tables,ip6t_REJECT
xt_dscp                16384  0

grep i2c /etc/rc.local doesn't show anything though.

well, you still have some setup to do... but i'm calling missing driver;

################################### .config.set
# CONFIG_RTC_DRV_DS3232 is not set
# CONFIG_RTC_DRV_DS3234 is not set
1 Like

Is there instruction on what driver I have to install first? kmod-rtc-ds1307 doesn't exist in openwrt repository (or at least in this snapshot repo).

edit : eventually I have to compile my build from snapshot and include kmod-rtc-ds1307, after flashing new firmware rtc works! :smile:

2 Likes

Dear Ark,
can you tell me how you build the new kmod-rtc-ds1307 module? I am also looking for adding it to my Rpi build. Which config file did you modify?

Thank you a lot,
Filippo

It's been awhile I already forgot how, wait I try to search for my notes, essentially I don't use image builder but compile my own build (from tutorials in the internet) which need many prerequisites (I'm installing it on linux hosted vps, but a local vm will do) and then select kmod-rtc-ds1307 since it's not included as default packages on image builder.

There's a kmod-rtc-ds1307 in stock 19.07 (probably in 21.02 too, haven't checked),
have you tried using it ?

Thank you Ark,
re-building is not a problem but I cannot find where to enable the kmod-rtc-ds1307 package as it doesn't exist in original packages, as you say. I tried in config, but no luck.

Frollic, unfortunately the module doesn't exist in 21.02 for RPI4.

Fil

you will not find it outside of make kernel... / kconfig option

Sorry wulfy23, I am not sure I understood your reply. Can you please specify better if I am allowed to build my own additional kernel modules and which files I need to modify in the build process?
When years ago I was building my 2.4.x Linux kernel I was editing config file with menuconfig but I am not sure what's the way with OpenWrt.

Thank you again for your time,
Fil

Ah sorry, maybe now I got you correct: you mean that I need to add ```
CONFIG_RTC_CLASS=y
CONFIG_RTC_DRV_DS1307=y
CONFIG_RTC_I2C_AND_SPI=y

to target/linux/bcm27xx/bcm2711/config-5.4.

Is this correct?
Fil

1 Like

yeah that's pretty close... (for 21.02.x)... master uses config-5.10

this is likely a modifcation not an add...

dont' have an (3v)rtc(or level shifter) so never tried myself...

you can fgrep RTC for all targets to peek around or maybe try the 'rtc' feature flag...

So you mean it is better to avoid enabling the above?
I checked other config files (for example mvebu arch) and I can see the following, so I think it could fit for RPI too.

CONFIG_RTC_CLASS=y
CONFIG_RTC_I2C_AND_SPI=y

I will let you know if it works...

Fil

no I mean there is already a line present which disables that flag... so it's an edit not and addition

Did anyone manage to install this RTC on 21? how?

@Ark