odroid-n2:application_note:rtc_wakeup_time

H/W Clock setup and wake up

ODROID-N2 has onboard hardware RTC (NXP PCF8563TS) on I2C bus (CH #3) and can retain the time if RTC backup battery (DC 3V) is connected to the dedicated connector (J3). Backup battery connection

This section will show you how you can set the time the H/W RTC component.

The package tzdata let you select your local timezone on your ODROID-N2.

target
$ sudo apt update
$ sudo apt install tzdata
$ sudo dpkg-reconfigure tzdata

The command hwclock can access the H/W clock in order to set the system time or query the time.

Set the current time to the H/W clock

$ sudo hwclock -w

Query the current H/W clock

$ sudo hwclock 
2019-03-04 23:35:57.575009-0500

NTP is a networking protocol for clock synchronization between a computer and a time server. By installing the package NTP, your system will keep the accurate time on your system.

$ sudo apt update
$ sudo apt install ntp

You also can specify your local NTP server or build your own NTP server using GPS. https://wiki.odroid.com/odroid-n2/application_note/gpspps_ntp_server

Update
If your network firewall is blocking the ntp service or no internet connection, you must stop the ntp service.
Once the NTP failed, the RTC value could be reset !!!


To stop ntpd:

target
$ sudo /etc/init.d/ntp stop

or

target
$ sudo service ntp stop

To prevent it from starting at boot:

target
$ sudo update-rc.d -f ntp remove

ODROID-N2 can wake up from the shutdown state as RTC triggers the signal at the time set before entering the shutdown state. RTC backup battery must be connected

This script to let ODROID-N2 to shutdown and wakeup 4 minutes later.

bash
#!/bin/bash
echo 0 > /sys/class/rtc/rtc0/wakealarm
echo `date '+%s' -d '+ 4 minutes'` > /sys/class/rtc/rtc0/wakealarm
shutdown -h now

Trouble shooting

hwclock: ioctl(RTC_RD_TIME) to /dev/rtc to read the time failed: Invalid argument

RTC backup battery is not connected or RTC is not configured to be accessed.

cannot access '/dev/rtc0': No such file or directory

If the H/W clock is not configured yet, the RTC device node is not created. Please check if the driver is load rtc_pcf8563 and I2C bus is enabled.

$ lsmod
Module                  Size  Used by
rtc_pcf8563            20480  0
i2c_meson_master       20480  0
ip_tables              32768  0
x_tables               49152  1 ip_tables
ipv6                  479232  28
$ cat /proc/device-tree/soc/cbus@ffd00000/i2c@1c000/status 
okay

Also the H/W clock can be probed using i2cdetect at @51 on I2C bus.

target
$ sudo apt update
$ sudo apt install i2c-tools
$ sudo i2cdetect -y 3
     0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
00:          -- -- -- -- -- -- -- -- -- -- -- -- -- 
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
50: -- UU -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
70: -- -- -- -- -- -- -- --

rtc-pcf8563 3-0051: low voltage detected, date/time is not reliable

This error log is printed at the very begining of Linux kernel start regardless RTC backup battery is fine or not. If so, the log can be ignored. Unless it's really the RTC backup battery is low and it has to be replaced.

RTC time not synced at startup

Kernel hctosys works before RTC hardware initialized. Because the i2c/rtc drivers are modules.
You can edit /etc/rc.local to synchronize the HW RTC time with the system time at boot time.

target
$ sudo nano /etc/rc.local
 
if [ -f /aafirstboot ]; then /aafirstboot start ; fi
 
hwclock -s
 
exit 0

In order to apply the change, your system must be rebooted.

target
$ sudo reboot
ODROID-N2 is configured to run RTC by default, so you are already ready to use H/W RTC. The instructions in this section is only required when you had been set GPIO pins #474 and #475 as generic GPIO pins from I2C and you want to revert them to I2C.

Enable H/W clock component

In order to make H/W clock component rtc-pcf8563 run, the device tree file must be modified with a tool fdtset and it can be installed with the package device-tree-compiler.

$ sudo apt update
$ sudo apt install device-tree-compiler

The H/W clock is connected to I2C bus. By default, if you have not configured to run the H/W clock yet, this command will show you disabled which disabled the I2C bus connected to the H/W clock.

Please note that the path of the device tree file could be different on your running OS, it would be /boot or /media/boot.
$ sudo fdtget /boot/meson64_odroidn2.dtb /soc/cbus@ffd00000/i2c@1c000 status
disabled

In order to enable I2C bus, you must change the device tree file with this command.

$ sudo fdtput -t s /boot/meson64_odroidn2.dtb /soc/cbus@ffd00000/i2c@1c000 status okay

In order to apply the change, your system must be rebooted.

$ sudo fdtget /boot/meson64_odroidn2.dtb /soc/cbus@ffd00000/i2c@1c000 status
okay
$ sudo reboot
  • odroid-n2/application_note/rtc_wakeup_time.txt
  • Last modified: 2019/07/16 11:33
  • by ck.kim