Showing results for 
Search instead for 
Did you mean: 

[BUG FOUND] STM32F4 RTC Stopped: (stm32f4xx_hal_rtc.c) HAL_RTC_GetTime() freezing count

Not applicable

To keep the count running, it was necessary to comment on this line:

(file: stm32f4xx_hal_rtc.c line: 864):

// sTime->SubSeconds = (uint32_t)(hrtc->Instance->SSR);

Ref.: (ivan239955)

Associate III

Hah, funky. I thought I had bug in code for H7. Started writing my function from scratch and found out that getting time with HAL lib actually freezes getting time. What is funny I cam across this problem back from 2y ago. Despite that good to have HAL as startign point.
Here effect before and after fix:


Actually seems I was wrong. I started getting some otther errors related to calendar. The I found comment:

" * @note You must call HAL_RTC_GetDate() after HAL_RTC_GetTime() to unlock the values
* in the higher-order calendar shadow registers to ensure consistency between the time and date values.
* Reading RTC current time locks the values in calendar shadow registers until Current date is read."

Finally it works as expected:

void rtc_device_get_time_date(rtc_time_t* time, rtc_date_t* date) {
	RTC_TimeTypeDef rtc_time;
	RTC_DateTypeDef rtc_date;

	HAL_RTC_GetTime(&hrtc, &rtc_time, RTC_FORMAT_BIN);
	HAL_RTC_GetDate(&hrtc, &rtc_date, RTC_FORMAT_BIN);

	if (time != NULL) {
		time->hour = rtc_time.Hours;
		time->minute = rtc_time.Minutes;
		time->second = rtc_time.Seconds;

	if (date != NULL) {
		date->year = rtc_date.Year;
		date->month = rtc_date.Month;
		date->day = rtc_date.Date;