Access Linux system time from cortex-m4

  • Hello F&S Team,

    We would like to use the cortex-m4 for time synchronization. The idea is to read the Linux system time and generate a hardware pulse at the beginning of every second.

    So I created a small test application for the cortex-m4 and was able to enable the SNVS_HP RTC, read the current time from the SNVS_HPRTCMR and SNVS_HPRTCLR register and generate a pulse on a gpio pin . This worked so far, but it seems that the time from SNVS_RTC is not equal to our current Linux system time.

    In the kernel log I do not see any hint, that SNVS_RTC is used by Linux. Do I need to enable this in the device tree first? Am I right, that it is possible to read the current Linux system time in the cortex-m4?

    Kind regards,


  • Short update.

    I found the snvn_rtc section in imx6sx.dtsi and enabled the rtc. Now I see in the kernel log during bootup the entry “snvs_rtc 20cc000.snvs:snvs-rtc-lp: setting system clock to 2021-08-30 14:27:21 UTC (1630333641)”. Looks like snvs_rtc is now working as hardware clock, but when I change the system time in Linux, it has no influence on the cortex-m4 application.

    Is the Linux system time not synchronized with SNVS_RTC?

    Kind regards,


  • Hello Stefan,

    the PicoCOM9X uses an extern RTC connected via I2C by default, as it is more precise.

    If you set the RTC time to the system-time with the hwclock -w command, it will set the extern RTC, not the intern RTC.

    If both RTCs are activated in your system you should see multiple RTCs at /dev/rtcX.

    You can set a specific RTC by using the command hwclock -w --rtc=/dev/rtcX.

    Please make sure to protect shared peripherals from simultaneous access by using e.g. Semaphores.

    Unfortunately, NXP did not implement RDC_Sema42 in the Linux Kernel, but you can use the normal Sema4.

    The driver drivers/char/imx_amp/imx_sema4.c can be used on Linux side, while the example

    freertos/examples/fsimx6sx/demo_apps/sema4_demo can be used on Cortex-M4 side.

    Your F&S Support Team

  • Thank you for your response. I disabled the external RTC (pcf8563) and enabled the internal RTC (snvs-rtc-lp). Now I have only /dev/rtc0 available and can read/ write time with the hwclock command. This is working fine, but I still have problems on the cortex-m4 side when I try to read the current rtc value.

    In my understanding, it should now be possible to use the cortex-m4 and read the SNVS_HP Real-Time Counter Registers (SNVS_HPRTCMR and SNVS_HPRTCLR) to get the current time. But the SNVS_HP RTC is not enabled and the counter registers do not change.

    I saw, that I activated in the device tree the snvs-rtc-lp (RTC_LP?) and try to read from RTC_HP. Are this two different RTC’s?

    Kind regards,


  • Hello,

    the SNVS_HPRTC and the SNVS_LPRTC seem to be two different RTCs. However, chapter

    58.4.2 Non-secure real-time counter of the imx6sx reference manual states, that they can be synchronized but does not explain how...

    The linux driver at drivers/rtc/snvs-rtc.c seems to read and write directly from/to the LPRTC but the access should be only possible with activated HPRTC, so maybe you could try to read from the LPRTC registers from the Cortex-M4 side.

    For more information please read 58.4 SNVS structure of the

    i.MX 6SoloX Applications Processor Reference Manual Rev. 4, 05/2020

    Your F&S Support Team

  • I went through the SNVS section in the reference manual and came to the same conclusion. The RTC in HP domain should be synchronized with the RTC in LP domain. It seems also to be the intended way to do this, because the LPRTC counter registers are not even documented in the reference manual….

    However, your hint with the rtc-snvs.c driver helped me to solve the problem. I took the memory offsets from this driver and was able to access the LPRTC counter registers directly. Now, everything is working as intended.

    Thank you for your help.

    Kind regards,