RTC
The Real Time Clock (RTC) on the phyCORE-AM62x serves the basic purpose of keeping time of day, as well as providing tamper proofing for digital rights management and waking up the rest of the chip from a power down state. The RTC can keep track of the year, month, date, weekday, hour, minute, and seconds and has timer, alarm, and external event input functionality. This guide will show you how to use RTC on the phyCORE-AM62x development kit to verify functionality when power is lost. To learn more information about the phyCORE-AM62x RTC interface, please see section 12.4 in the Hardware Manual.
RTC Naming
Note
rtc0 is named after the physical IC populated on the SOM at U19.
Verify the name of the RTC device by checking the name file in the interface’s sysfs directory:
cat /sys/class/rtc/rtc0/name
root@phyboard-lyra-am62xx-3:~# cat /sys/class/rtc/rtc0/name
rtc-rv3028 0-0052
Setting the System Time
Set the RTC time by first setting the system time. We can do this manually or leverage the Network Time Protocol (NTP):
Manually
Use the following command to set an arbitrary time as the system time in Linux:
date 071916142016
Note
The argument in the above command broken down is:
07-19 16:14 2016
date time year
Setting the RTC
With the system time set according to the above steps, you can now write this time to the RTC using the following command:
hwclock -w -f /dev/rtc0
Reading the RTC
The RTC’s time can be read using the following command:
hwclock -r -f /dev/rtc0
The time set here should persist between boots and times without power as long as the VBAT pin of the SOM is supplied.
Warning
A new SOM with an unprogrammed rtc may throw errors when read:
root@phyboard-lyra-am62xx-1:~# hwclock -r -f /dev/rtc0
hwclock: ioctl(RTC_RD_TIME) to /dev/rtc0 to read the time failed: Invalid argument
Set the RTC time according to the steps above to resolve this.
root@phyboard-lyra-am62xx-3:~# hwclock -r -f /dev/rtc0
Tue Jul 19 16:16:34 2016 0.000000 seconds