Using the SNVS RTC on i.MX RT1170 Targets

Using the SNVS RTC on i.MX RT1170 Targets

1. Overview

This application note describes how to use the Real-Time Clock (RTC) on the i.MX RT1170 targets running the Emcraft uClinux BSP. The RTC is part of the SNVS (Secure Non-Volatile Storage) peripheral block on the i.MX RT1170 SoC. It allows Linux applications to read and set the hardware clock, synchronize the system time, and use RTC alarm interrupts. The functionality described in this document applies to both the IMXRT1170-EVK(B) and MaaXBoard-RT boards and is enabled by default in the rootfs project — no patches or additional configuration are required.

2. Kernel and Device Tree Configuration

The i.MX RT1170 SoC includes a Secure Non-Volatile Storage (SNVS) block with a Low-Power Real-Time Clock (RTC). The SNVS RTC is driven by a 32.768 kHz crystal and retains time as long as the SNVS domain is powered. The Linux kernel provides a device driver for this RTC, enabled with the CONFIG_RTC_DRV_SNVS build-time option. The RTC subsystem is enabled with the CONFIG_RTC_CLASS option. Both options are enabled by default in the rootfs project for all supported boards.

The SNVS RTC hardware is described in the imxrt1170.dtsi device tree include file shared by all i.MX RT1170 boards:

snvs: snvs@40c90000 { compatible = "fsl,sec-v4.0-mon", "syscon", "simple-mfd"; reg = <0x40c90000 0x4000>; snvs_rtc: snvs-rtc-lp { compatible = "fsl,sec-v4.0-mon-rtc-lp"; regmap = <&snvs>; offset = <0x34>; interrupts = <66>; }; };

No board-specific DTS changes are required — the SNVS RTC node is defined in the common imxrt1170.dtsi and is available on both the IMXRT1170-EVK(B) and MaaXBoard-RT boards.

The rootfs project includes the Busybox hwclock applet (CONFIG_HWCLOCK=y in the Busybox configuration), which provides a command-line interface for reading and setting the hardware clock.

3. Verifying RTC Operation

  1. Build and boot the rootfs project as usual:

    $ cd projects/rootfs $ make
  2. Boot the resulting rootfs.uImage to the target. The kernel log should show the SNVS RTC driver probing successfully:

    / # dmesg | grep rtc [ 1.240000] snvs_rtc 40c90000.snvs:snvs-rtc-lp: registered as rtc0 [ 1.250000] snvs_rtc 40c90000.snvs:snvs-rtc-lp: setting system clock to 1970-01-01T00:00:00 UTC (0)
  3. The driver creates the /dev/rtc0 device node automatically via devtmpfs. Verify it exists:

    / # ls -l /dev/rtc0 crw------- 1 root root 253, 0 Jan 1 00:00 /dev/rtc0

4. Reading the Hardware Clock

  1. Use the hwclock command to read the current RTC time:

    / # hwclock -r Thu Jan 1 00:01:23 1970 0.000000 seconds
  2. The RTC sysfs interface also provides access to the clock:

    / # cat /sys/class/rtc/rtc0/time 00:01:23 / # cat /sys/class/rtc/rtc0/date 1970-01-01

5. Setting the System Clock and Synchronizing to the RTC

Since the SNVS RTC does not have a battery backup on the EVK and MaaXBoard-RT boards, the RTC counter resets to zero on every power cycle. To set a meaningful time, first set the Linux system clock using the date command, then write it to the hardware clock:

  1. Set the system time:

    / # date -s "2026-04-06 12:00:00" Sun Apr 6 12:00:00 UTC 2026
  2. Write the system time to the RTC:

    / # hwclock -w
  3. Verify the RTC has been updated:

    / # hwclock -r Sun Apr 6 12:00:05 2026 0.000000 seconds

To perform the reverse operation — set the system clock from the hardware clock — use:

/ # hwclock -s

This is useful at boot time to restore the system clock from the RTC if the SNVS domain has retained power.

6. Using the RTC from Application Code

The RTC device can be accessed from user-space application code via standard ioctl calls on /dev/rtc0. The Linux RTC interface is documented in the kernel source at Documentation/rtc.txt. The key operations are:

  • RTC_RD_TIME — read the current RTC time.

  • RTC_SET_TIME — set the RTC time.

  • RTC_ALM_SET / RTC_ALM_READ — set or read the alarm time.

  • RTC_AIE_ON / RTC_AIE_OFF — enable or disable the alarm interrupt.

A minimal example of reading the RTC time from a C application:

#include <stdio.h> #include <fcntl.h> #include <unistd.h> #include <sys/ioctl.h> #include <linux/rtc.h> int main(void) { int fd; struct rtc_time tm; fd = open("/dev/rtc0", O_RDONLY); if (fd < 0) { perror("open /dev/rtc0"); return 1; } if (ioctl(fd, RTC_RD_TIME, &tm) < 0) { perror("RTC_RD_TIME"); close(fd); return 1; } printf("RTC time: %04d-%02d-%02d %02d:%02d:%02d\n", tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday, tm.tm_hour, tm.tm_min, tm.tm_sec); close(fd); return 0; }