RTC

The Real Time Clock (RTC) on the phyCORE-AM64x 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 rtc0 on the phyCORE-AM64x development kit to verify functionality when power is lost. To learn more information about the phyCORE-AM64x RTC interface, please see section 11.3 in the Hardware Manual.

RTC Naming

Note

rtc0 is named after the physical IC populated on the SOM at U6.

  • Verify the name of the RTC device by checking the name file in the interface’s sysfs directory:

Target (Linux)
cat /sys/class/rtc/rtc0/name
Expected Output
root@phyboard-electra-am64xx-2:~# 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:

    Target (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:

    Target (Linux)
    hwclock -w -f /dev/rtc0
    

Reading the RTC

  • The RTC’s time can be read using the following command:

    Target (Linux)
    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:

Example Output
root@phyboard-electra-am64xx-2:~# 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.

Expected Output
root@phyboard-electra-am64xx-2:~# hwclock -r -f /dev/rtc0
Mon Oct  2 21:36:33 2023  0.000000 seconds