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 phyBOARD-Lyra AM62x development kit to verify functionality when power is lost. To learn more information about the phyCORE-AM62x RTC interface, please see RTC chapter in the Hardware Manual.
Naming
Verify the name of the RTC device by checking the name file in the interface’s sysfs directory:
root@phyboard-lyra-am62xx-3:~# cat /sys/class/rtc/rtc0/name
rtc-rv3028 0-0052
RTCs can be accessed via /dev/rtc*. Because PHYTEC boards have often more than one RTC, there might be more than one RTC device file.
To find the name of the RTC device, you can read its sysfs entry with:
phyboard-lyra-am62xx-3:~# cat /sys/class/rtc/rtc*/name
rtc-rv3028 0-0052
rtc-ti-k3 2b1f0000.rtc
Tip
This will list all RTCs including the non-I²C RTCs. Linux assigns RTC device IDs based on the device tree/aliases entries if present.
Setting Date and Time
Date and time can be manipulated with the hwclock
tool and the date
command. To show the current date and time set on the target:
phyboard-lyra-am62xx-3:~# date
Thu Jan 1 00:01:26 UTC 1970
Change the date and time with the date command. The date command sets the time with the following syntax “YYYY-MM-DD hh:mm:ss (+|-)hh:mm”:
phyboard-lyra-am62xx-3:~# date -s "2022-03-02 11:15:00 +0100"
Wed Mar 2 10:15:00 UTC 2022
Note
Your timezone (in this example +0100) may vary.
Using the date
command only changes the system time. To persist the time across reboots, you need to write it to the RTC hardware using the hwclock
command:
phyboard-lyra-am62xx-3:~# hwclock -w
After a reboot, you can verify the RTC kept the correct time:
phyboard-lyra-am62xx-3:~# date
Wed Mar 2 10:34:06 UTC 2022
To set the system time from the RTC:
phyboard-lyra-am62xx-3:~# hwclock -s
RTC Parameters
The RTC hardware has several configurable parameters that can be read and set using the hwclock
tool.
To check the supported RTC features:
phyboard-lyra-am62xx-3:~# hwclock --param-get features
The RTC parameter 0x0 is set to 0x70
The features value is a bitmask where each set bit indicates a supported feature:
Bit 0: RTC_FEATURE_ALARM - Basic alarm support
Bit 1: RTC_FEATURE_ALARM_RES_MINUTE - Minute resolution for alarms
Bit 2: RTC_FEATURE_NEED_WEEK_DAY - Requires weekday to be set
Bit 3: RTC_FEATURE_ALARM_RES_2S - 2 second resolution for alarms
Bit 4: RTC_FEATURE_UPDATE_INTERRUPT - Update interrupt support
Bit 5: RTC_FEATURE_CORRECTION - Time correction support
Bit 6: RTC_FEATURE_BACKUP_SWITCH_MODE - Backup power switching support
Bit 7: RTC_FEATURE_ALARM_WAKEUP_ONLY - Alarm can only wake system
Backup Switchover Mode
The Backup Switchover Mode (BSM) controls how the RTC handles switching to backup power when main power is lost.
To check the current BSM setting:
phyboard-lyra-am62xx-3:~# hwclock --param-get bsm
The RTC parameter 0x2 is set to 0x1
To change the BSM setting:
phyboard-lyra-am62xx-3:~# hwclock --param-set bsm=0x2
The RTC parameter 0x2 will be set to 0x2
The available BSM modes are:
0: RTC_BSM_DISABLED - Backup switching disabled
1: RTC_BSM_DIRECT - Direct Switching Mode (DSM)
2: RTC_BSM_LEVEL - Level Switching Mode (LSM)
3: RTC_BSM_STANDBY - Standby Mode
Tip
Set BSM mode to either DSM (1) or LSM (2) to enable automatic switching to backup power when main power is lost. Refer to the RV-3028 RTC datasheet for details on the differences between LSM and DSM modes.