cancel
Showing results for 
Search instead for 
Did you mean: 

Millisecond granularity on RTC (STM32F4 Cube HAL Library)

mehmetemredoruktiryaki
Associate II
Posted on December 16, 2015 at 08:55

Hi,

I just noticed something strange using the RTC of STM32F407 with CUBE HAL Library.

When calling HAL_RTC_SetTime(); I see no register writes are performed for the SecondFraction field of the RTC_TimeTypeDef structure reference I pass as an argument.

Am I missing something? Am I not able to set the second fraction to 999. It always returns as 255.

My Cube HAL library version is 1.10.0 by the way.

Looking through the cube reference rev 3, page 666 🙂 (RCT_TimeTypeDef Data Fields) the Field Documentation section mentions the situation as below:

uint32_t RTC_TimeTypeDef::SecondFraction

Specifies the range or granularity of Sub Second register content corresponding to

Synchronous pre-scaler factor value (PREDIV_S) This parameter corresponds to a

time unit range between [0-1] Second with [1 Sec / SecondFraction +1] granularity.

This field will be used only by HAL_RTC_GetTime function

Well my question stands. How do I get a millisecond granularity then?

Thanks in advance for all the support.

Best Regards,

Emre

#rtc-cube
3 REPLIES 3
Posted on December 16, 2015 at 09:45

> Well my question stands. How do I get a millisecond granularity then?

Unless you use some highly non-standard crystal (such as 32000.00Hz), you don't.

It's not the purpose of RTC to provide millisecond granularity. You could get granularity in multiples of crystal's period multiplied by the asynchronous prescaler's factor. You may decrease the asynchronous prescaler to decrease granularity, but note that that increases VBAT consumption. The RTC chapter in RM goes into painful details, please read it if you intend to use the RTC in a nonstandard way.

I don't comment on Cube/CubeMX, I don't use it.

JW

mehmetemredoruktiryaki
Associate II
Posted on December 22, 2015 at 08:43

Hi waclawek.jan,

Thanks for directing me to a better point of view on the subject.

Best Regards,

Emre

Posted on December 22, 2015 at 17:49

May be it's a HAL issue, several people have complained about it in recent months. From a HW perspective the fractional second portion of the RTC functions as documented.

I don't think you get to write to the prescaler's counter, you likely have to synchronize your writes to the RTC registers to the top-of-second to get the alignment you desire.

https://my.st.com/public/STe2ecommunities/mcu/Lists/cortex_mx_stm32/Flat.aspx?RootFolder=https://my.st.com/public/STe2ecommunities/mcu/Lists/cortex_mx_stm32/Get%20more%20resolution%20from%20RTC%20clock&FolderCTID=0x01200200770978C69A1141439FE559EB459D7580009C4E14902C3CDE46A77F0FFD06506F5B&currentvie...

Tips, buy me a coffee, or three.. PayPal Venmo Up vote any posts that you find helpful, it shows what's working..