The Real-Time Clock (RTC) is a hardware component that tracks wall clock time and is battery backed so it works even with system power off. Such clocks will normally not track the local time zone or daylight saving time but will instead be set to Coordinated Universal Time.

On the ConnectCore 93:

  • The i.MX93 SoC provides one RTC

On the ConnectCore 93 Development Kit:

  • One RV3028 RTC chip is connected to LPI2C3

Kernel configuration

You can manage the real-time clock driver support through the following kernel configuration options:

  • NXP BBNSM RTC support (CONFIG_RTC_DRV_BBNSM)

  • Micro Crystal RV3028 (CONFIG_RTC_DRV_RV3028)

These options are enabled as built-in on the default ConnectCore 93 Development Kit kernel configuration file.

Kernel driver

File Description

drivers/rtc/rtc-bbnsm.c

Driver for the NXP BBNSM RTC device

drivers/rtc/rtc-rv3028.c

Driver for the RV3028 RTC device

Device tree bindings and customization

The device tree for the i.MX93 RTC is defined in the ConnectCore 93.

ConnectCore 93 device tree
bbnsm: bbnsm@44440000 {
	compatible = "syscon", "simple-mfd";
	reg = <0x44440000 0x10000>;

	bbnsm_rtc: rtc {
		compatible = "nxp,bbnsm-rtc";
		regmap = <&bbnsm>;
		interrupts = <GIC_SPI 73 IRQ_TYPE_LEVEL_HIGH>;
	};

The Micro Crystal RV3028 I2C interface device tree binding is documented at Documentation/devicetree/bindings/rtc/trivial-rtc.yaml.

The device tree for the RV3028 RTC is defined in the ConnectCore 93 Development Kit.

ConnectCore 93 Development Kit device tree
ext_rtc: ext_rtc@52 {
	compatible = "microcrystal,rv3028";
	reg = <0x52>;
	pinctrl-names = "default";
	pinctrl-0 = <&pinctrl_rtc>;
	interrupt-parent = <&gpio2>;
	interrupts = <18 IRQ_TYPE_EDGE_FALLING>;
	wakeup-source;
};

&iomuxc {
	/* RTC INT */
	pinctrl_rtc: rtc_grp {
		fsl,pins = <
			MX93_PAD_GPIO_IO18__GPIO2_IO18		0x31e
		>;
	};

RTC user space usage

The different RTCs are accessible via the following file descriptors:

  • /dev/rtc0 (for the i.MX93 RTC)

  • /dev/rtc1 (for the external RV3028 RTC)

The /dev/rtc device is a symbolic link to /dev/rtc0.

For more information, refer to the Linux kernel documentation at Documentation/devicetree/bindings/rtc/rtc.yaml.

Initializing the RTC

When connected to the Internet, Digi Embedded Yocto uses an NTP (Network Time Protocol) daemon to set the RTC time and keep the system time up to date. You must initialize the RTC the first time you power the board after unpacking the kit and whenever power is completely lost (including RTC backup battery). When not initialized, or if the date is set to a value before the year 1970, the Linux system reports the following error message:

system time... hwclock: settimeofday() failed: Invalid
Linux cannot handle dates before the year 1970.

To initialize the RTC from the Linux shell, set a correct system time using the date command and then issue hwclock -w to write the system time into the RTC.

RTC test application

Digi Embedded Yocto provides a basic RTC test application. Build the package dey-examples-rtc in your Yocto project to install the test application rtc_test.

The RTC test application allows you to read the current time from the RTC; set it using the system time; and read, set, and test the alarm interrupt.

Syntax

To display the application syntax, run:

# rtc_test -h

Examples

Test the alarm interrupt with the specified seconds:

# rtc_test -e -s 20

In this case, the test sets the RTC alarm to 20 seconds from the current time and then waits for the alarm interrupt to occur.