Jump to content

Recommended Posts

Posted

ROCK64 is a RK3328 Quad-Core ARM Cortex A53 board with up to 4 GB of RAM. Unfortunately it has a non-functional RTC (/dev/rtc0), which is not battery backed. If your board is not connected to internet 7/24, you can not use the NTP or systemd-timesyncd. Therefore you need to connect a battery-backed external RTC module to the ROCK64 header, and get the time via the i2c protocol. The good news is, the GPIO headers on ROCK64 is compatible with Raspberry Pi headers. Therefore almost any Raspberry Pi RTC module will work on ROCK64. But you need to do some tweaking to communicate with the RTC module. I will explain the required steps which worked for me.

 

1. Buy an external RTC module for Raspberry Pi, preferably with DS1307 chip. Here is an example:

https://www.abelectronics.co.uk/p/70/rtc-pi

 

2. Install i2c-tools package:

sudo apt-get install i2c-tools

 

3. Connect the RTC module to the board as in the attached picture.

 

4. Right now, you can not probe the RTC module, because most of the GPIO headers on ROCK64 board is disabled by default. (See https://github.com/ayufan-rock64/linux-build/blob/master/recipes/additional-devices.md for details.)

Therefore if you try to probe i2c-0, you will get the error below:

root@rock64:~# sudo i2cdetect -y 0
Error: Could not open file `/dev/i2c-0' or `/dev/i2c/0': No such file or directory

Ayufan wrote a nice script named "enable_dtoverlay" to enable the GPIO headers on-the-fly. Here is the link: https://raw.githubusercontent.com/ayufan-rock64/linux-package/master/root/usr/local/sbin/enable_dtoverlay

Download this script and copy it under /bin and make it executable. We will enable "i2c-0" with this script, which we need for the RTC module. The command to enable i2c-0 is as follows:

/bin/enable_dtoverlay i2c0 i2c@ff150000 okay

After you run this command, /dev/i2c-0 becomes available, and we can probe it via the command below:
 

root@rock64:~# sudo i2cdetect -y 0
     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: -- -- -- -- -- -- -- --

If you see the number 68, you are on the right track.

 

5. Now we need the kernel driver for DS1307. Unfortunately DS1307 driver is not available with armbian kernel (see below).

root@rock64:~# cat /boot/config-4.4.162-rockchip64 | grep DS1307
# CONFIG_RTC_DRV_DS1307 is not set

So we need to recompile the Armbian kernel with this option enabled. I will not cover the steps to compile the kernel, you can find it here: https://docs.armbian.com/Developer-Guide_Build-Preparation/
Let's hope @Igor or any other Armbian developer will enable this module by default, and save us from this burden.

 

After we compile the kernel with DS1307 driver, we are almost done. We need to tell the kernel that a DS1307 chip is using the i2c-0. Here is the way to do that:

echo ds1307 0x68 > /sys/class/i2c-adapter/i2c-0/new_device

After we execute this command, /dev/rtc1 becomes available, and points to our external RTC module. Please note that /dev/rtc0 is the onboard RTC, which does not work, and should be avoided.

 

We need to update the date/time information from the system for the first time. Here is the command to do that:

hwclock --rtc /dev/rtc1 --systohc

Now our external RTC clock is set, and ready to take over NTP.

 

6. Edit /lib/udev/hwclock-set. Find the lines below, and update as shown:

if [ -e /run/systemd/system ] ; then
#    exit 0
     /bin/enable_dtoverlay i2c0 i2c@ff150000 okay
     echo ds1307 0x68 > /sys/class/i2c-adapter/i2c-0/new_device
fi

 

7. Edit /etc/rc.local, add the following lines to set the system clock for every boot:
 

/lib/udev/hwclock-set /dev/rtc1

 

8. Disable the below services, as we don't need them anymore:

systemctl stop systemd-timesyncd.service
systemctl disable systemd-timesyncd.service

systemctl stop fake-hwclock.service
systemctl disable fake-hwclock.service

 

9. Reboot and enjoy your RTC module.

46526003_10156324103031633_5569059156695973888_n.jpg

Posted
52 minutes ago, turkerali said:

Let's hope @Igor or any other Armbian developer will enable this module by default, and save us from this burden.


We would need a few full time employees/volunteers to catch up with community wishes. This one is really small, but still. I need to solve others before and waiting time is easily 12 months ... which is ridiculous. Until we don't have the luxury of help: https://www.armbian.com/get-involved

Posted
13 hours ago, Igor said:


We would need a few full time employees/volunteers to catch up with community wishes. This one is really small, but still. I need to solve others before and waiting time is easily 12 months ... which is ridiculous. Until we don't have the luxury of help: https://www.armbian.com/get-involved

Fair enough. I've just sent a pull request for this small change. Hope I won't break anything :)

Posted
On 11/22/2018 at 9:56 AM, turkerali said:

Fair enough. I've just sent a pull request for this small change. Hope I won't break anything :)

Hello, hello, I have test the method you have posted, while It always tell me "Your kernel does not support CONFIG OF OVERLAY", and my folder /sys/kernel/config is empty.  Is that mean I need to compile linux firmware by myself to enable I2c interface?  The firmware I used is Raw Firmware ubuntu16.04 provided by  Firefly official. Thanks a lot for your help.

Posted
1 hour ago, fanbowo said:

The firmware I used is Raw Firmware ubuntu16.04 provided by  Firefly official.

This image is not an Armbian image !

No one can help you here if you are not using Armbian image...

Posted (edited)

Hello, this was my way to make RTC DS3231 works on rock64.

 

apt-get install i2c-tools

 

- /etc/rc.local

/lib/udev/hwclock-set /dev/rtc1
exit 0

- /lib/udev/hwclock-set

if [ -e /run/systemd/system ] ; then
#    exit 0
     /bin/enable_dtoverlay i2c0 i2c@ff150000 okay
     echo ds1307 0x68 > /sys/class/i2c-adapter/i2c-0/new_device
fi

#if [ -e /run/udev/hwclock-set ]; then
#    exit 0
#fi

HCTOSYS_DEVICE=rtc1

 

Copy to /bin/ and make executable

https://raw.githubusercontent.com/ayufan-rock64/linux-package/master/root/usr/local/sbin/enable_dtoverlay

 

systemctl stop systemd-timesyncd.service
systemctl disable systemd-timesyncd.service
systemctl stop fake-hwclock.service
systemctl disable fake-hwclock.service

 

sudo apt-get -y remove fake-hwclock

apt install chrony

Edited by rbr
Guest
This topic is now closed to further replies.
×
×
  • Create New...

Important Information

Terms of Use - Privacy Policy - Guidelines