cancel
Showing results for 
Search instead for 
Did you mean: 

Cube: provide functions setting/reading date+time+subseconds at once

Posted on January 26, 2017 at 18:21

Barta.Hank

‌ in

https://community.st.com/community/stm32-community/stm32-forum/blog/2016/12/30/2017-stm32-wish-list?messageTarget=all&start=100&mode=comments&sharpcomment-1531

said:

Regarding the RTC and HAL library for the STM32F7 I'd like to address the following calls:

HAL_RTC_GetTime() & HAL_RTC_GetDate()

HAL_RTC_SetTime() & HAL_RTC_SetDate()

Some of us view time as a monotonically increasing single value. Splitting it into time and date is an artificial division. It results in problems which are addressed by locking the date register when time is read so that the date doesn't roll over before it is read. That's a little hackish but I appreciate the need and would prefer it would just be handled internally in a single library call.

There is no such warning about setting time and date and that leaves me wondering if there is a potential rollover issue with that. Maybe I just need to make sure that the time/date is not set near midnight.

HAL_RTC_GetTime() will return fractional seconds (read from the RTC_SSR.) HAL_RTC_SetTime() ignores this and as near as I can tell, resets the RTC_SSR. It would be cool if HAL_RTC_SetTime() would also set the fractional seconds.

The RTC provides a register that can shift time a bit (RTC_SHIFTR). I don't see any HAL call that uses that. It's a shame to have that in silicon and not have a driver to manipulate it.

Waclawek.Jan

‌

https://community.st.com/community/stm32-community/stm32-forum/blog/2016/12/30/2017-stm32-wish-list?messageTarget=all&start=100&mode=comments&sharpcomment-1498

:

I agree that it's not only dumb but also dangerous to have separate date and time set/read functions, once one wants to have an 'abstraction layer'.

There is no such warning about setting time and date and that leaves me wondering if there is a potential rollover issue with that. Maybe I just need to make sure that the time/date is not set near midnight.

While the hardware has provisions to avoid this (see Calendar initialization and configuration unnumbered subchapter in RMs) the 'library' is written so that it enters and exits the initialization clock-stopped state in both functions, so it re-creates the potential for rollover

Read the RM and the Cube sources to gain understanding before you use them.

It would be cool if HAL_RTC_SetTime() would also set the fractional seconds.

It can't do it directly, the RTC_SSR is read only. While it's not said in the RM, the INIT mechanism mentioned above probably reloads it with the synchronouos prescaler (ST: please clarify in RM this).

But, as you've pointed out, there *is* a mechanism designed to influence RTC_SSR through the 'shift' facility. It should be possible to write a function performing the date/time INIT and then use the shift to set also the SSR as required.

null
0 REPLIES 0