RTC

There are two Real Time Clock (RTC) interfaces on the phyCORE-i.MX7. The external RTC populated on the SOM at U10 is interfaced through rtc0 in the device tree and the RTC internal to the processor is interfaced through rtc1. These interfaces serve the 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 external RTC (rtc0) to verify functionality when power is lost.

RTC Naming

  • Verify the name of the RTC interface by checking the name file in the interface’s directory.

    The SOM provides an ordering option to populate an external RTC at U10 which is connected to the I2C1 bus at address 0x68.

    Target (Linux)
    cat /sys/class/rtc/rtc0/name
    cat /sys/class/rtc/rtc1/name
    
    Expected Output
    root@phyboard-zeta-imx7d-1:~# cat /sys/class/rtc/rtc0/name
    rtc-m41t80 0-0068
    root@phyboard-zeta-imx7d-1:~# cat /sys/class/rtc/rtc1/name
    snvs_rtc 30370000.snvs:snvs-rtc-lp
    

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):

Note

If your i.MX7 hardware is connected to the internet then it will not allow you to manually set the date and time unless we disable automatic time sync. Use the following command if your phyCORE-i.MX7 is connected to your network:

Target (Linux)
systemctl stop systemd-timesyncd

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

  • Read back the time to ensure it was set properly.

    Target (Linux)
    hwclock -r -f /dev/rtc0
    
  • Power off the he and disconnect power.

    The time set here should persist between boots and times without power as long as the VBAT pin of the SOM is supplied.

    Target (Linux)
    poweroff
    
  • Wait a little bit of time then return power back to the development kit and log into Linux.

  • Read the time again to verify that the system continued to keep time without power.

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

Note

If you had to disable automatic time sync at the beginning of this guide then you will likely want to re-enable it. Use the following command to do so:

Target (Linux)
systemctl start systemd-timesyncd