cancel
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) https://community.st.com/s/question/0D50X00009XkbIt/rtc-lselsi-settings-from-stm32cubef4-does-not-work-solved-2-bugs-in-cube

2 REPLIES 2
PAdam.11
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:
PAdam11_0-1702893328439.png

 

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;
	}
}

 

PAdam11_0-1702914141047.png