Skip to main content
PSoco.1
Associate II
May 13, 2021
Solved

Why ST keep implementing RTC as calendar instead of RTC binary counter?

I am not an ST expert nor RTC expert, whatever that means. but I have seen several implementations made by other companies and I have to say RTC as counter (the HW that provide interface to a posix compatible timestamp, usually 32 bit seconds + 15 fractional bits) is faster (at driver level the posix time value is written and read without conversion to expanded form), math friendlier (non trivial time calculation is really hard in expanded form so everyone tends to use posix form converting it) and I suspect since the lower amount of transistor, much simpler, lower power and cheaper. I never liked the RTC calendar HW implementation since it is overcomplicated in both HW and driver and I cannot see any benefit on such implementation. I understand that calendar implementation make sense 30 years ago on 4 bit processors when RTC was mainly used to produce a digital clock; now today cpu are used mostly for IoT and other device that are not just a simple clock printing the date/time over 7 segment LED display, they do calculation so conversion take place often, usually way too often removing any benefit from having HW calendar. can someone name a good readon to stick with calendar HW implementation? why STM32 keep feeding us an RTC calendar in a STM32H7 with CM7 @ >500MHz? thanks, if someone can provide any good reason about this nonsense. by the way, truly love STM32H7, amazing CPU amazing feats, and maybe because I love it, I spend the 10 minutes asking about this odd implementation choice. hope to see in the future a review on ST RTC, a combined calendar + counter so that ST can make happy both users, or maybe better, just ditch the calendar, since with HAL drivers customer won't notice the upgrade, and those do not use HAL will be happier to develop a much simpler and trivial driver.

This topic has been closed for replies.
waclawek.jan
waclawek.janBest answer
Super User
June 10, 2021

What guidance do you need exactly? This is only a hypothetical "what if" thread. The RTC is implemented in the way it is, just face it.

JW

28 replies

MBin
Associate
November 12, 2021

@PSoco.1​ I have the same frustration !

All this while I thought Calendar is the way forward, given how sophisticated it is as apposed to a simple counter register. I'm so glad I stumbled upon this thread !

I have no use of Calendar at all, I have been converting Calendar to 32-bit Unix timestamp, it was slow. I'm in Stop Mode all the time, so I can't use SysTick as timestamp, I can't use LPTIM either since it is occupied by my encoder.

Finally I had enough and use the Systick interrupt to increment a uint64 counter which I initialized with a real timestamp(calculated from RTC). I also have to re-sync the counter after waking up from Stop Mode. So now rather than always having to calculate timestamp, I just read my uint64 counter.

This solves haha.

waclawek.jan
Super User
November 12, 2021

Nice trick, thanks for sharing it.

JW

waclawek.jan
Super User
November 12, 2021

@PSoco.1​ ,

Maybe you should have a look at the newest STM32U5 https://www.st.com/en/microcontrollers-microprocessors/stm32u5-series.html . They do have implemented the binary mode in RTC, btw.

JW

PSoco.1
PSoco.1Author
Associate II
November 12, 2021

yes, this is what I am talking about, ultra low power, decent security (now with PKA yea :) ) and good performance