cancel
Showing results for 
Search instead for 
Did you mean: 

High Precision RTC for STM32MP Linux Kernel

jandriea
Associate II

Hello everyone,

I am currently working on a project involving the STM32MP microprocessor and I've been exploring the Real-Time Clock (RTC) functionality in the Linux kernel for timekeeping purposes.

From what I've gathered so far, the datasheet (RM0441 - Chapter 48.3.12) mentioned that the RTC can be synchronized with a remote clock using the sub-second field (RTC_SSR or RTC_TSSSR). Additionally, the RTC_SHIFTR register can be used for fine adjustments, delaying and advancing the RTC's clock by a fraction of a second. However, I am unsure whether this feature is currently implemented in the Linux kernel for the STM32MP platform.

If any of you have experience with this feature or are aware of its current status in the main Linux kernel for STM32MP, I would greatly appreciate any information you could provide. Here are my specific queries:

  1. Is it already implemented in the latest Linux kernel release?
  2. If it is not yet developed, would it be feasible to implement this feature for the STM32MP platform in the Linux kernel?
  3. What would be the general approach or pointers for implementing this feature in the Linux kernel for STM32MP?

Thank you all for your time and support!

10 REPLIES 10
RhSilicon
Lead

About RTC, it may be interesting to compare the specifications of the RTC DS3231, synchronizing with high precision can be a lost service if over time the RTC cannot keep itself aligned usually due to temperature variation.

About implementing RTC on Linux, it might be interesting to see how RTC works on Raspberry Pi:

When connected to the Internet, the pi automatically gets the date and time from time servers.

http://www.intellamech.com/RaspberryPi-projects/rpi_RTCds3231

AScha.3
Chief III

why you want RTC subsecond sync ?   RTC anyway usually is not used for system time...  :)

its only used at system startup and after start if there is no working internet connection to sync the time.

see:

It’s important to note that the timedatectl command only affects the system clock, which is the main clock on the system used by the operating system and applications. The hardware clock, also known as the real-time clock (RTC), is a separate clock that runs independently of the system and is used to keep the time even when the system is powered off. To synchronize the hardware clock with the system clock, you need to run the following command:

https://tecadmin.net/synchronizing-a-linux-system-clock-with-ntp-server/

 

 


 

If you feel a post has answered your question, please click "Accept as Solution".

Thank you for your answer,

I understand the significance of maintaining the RTC's accuracy under varying temperatures. In this project, I have already developed a basic program to monitor temperature and perform digital compensation for the machine RTC. However, my main objective is to achieve even higher precision in timekeeping.

To my knowledge, the DS3231 lacks a register to store milliseconds, whereas the STM32MP possesses the necessary capabilities to accomplish this.

In this project, there will be times when the device is not connected to the internet, but my main goal remains to achieve enhanced clock synchronization accuracy.

It may also be interesting to use low PPM TCXO.

Thank you for your answer,

For this project, precise timekeeping is crucial. To ensure synchronization with the server when the device is offline, we will utilize the hardware sub-seconds to maintain accuracy.

I possess a comprehensive understanding of the distinction between the system clock and the hardware clock. As you know, the system clock boasts millisecond precision, while the hardware clock lacks this capability, at least for the moment. My primary objective is to achieve sub-second synchronization with the hardware clock directly from the user space. Your insights and assistance in achieving this goal would be greatly appreciated. Thank you!

Hello  @jandriea,

Do you have any update related to this topic? I'm really interested in the RTC precise auto-calibration of the stm32mp1 chip family.

All examples I was able to find were related to MCU software and timer16 usage or directly avoid the usage of the RTC in favor of STGEN clock.

I reviewed stm32-rtc.c driver but unfortunately it only sets prediv_a and prediv_s values completly ignoring the smooth calibration feature of the clock nor check if the clock source is reliable.