2024-06-20 01:53 AM
Hi,
Currently working on a STM32U575, I was happy to see that the RTC now have a binary mode option.
I've done some experimenting using the HAL (generated through CubeMX 1.15.1), and I'm intrigued about its init behavior, is it expected, buggy or lacking?
What I have seen is, when using the RTC in BCD Mode, the HAL_RTC_INIT function checks if the RTC calendar was previously initialized to avoid a new re-initializing, and thus avoiding losing the date and time. The check is done using:
if (__HAL_RTC_IS_CALENDAR_INITIALIZED(hrtc) == 0U)
which is a macro that checks if the RTC_ICSR_INITS flag is set.
But this check inevitably fails when using the RTC in Binary Mode only. Indeed the RTC_ICSR_INITS flag cannot be true, as it depends on the year field, which stays at its Backup domain reset default value (0x00). And thus, the RTC SSR register used in Binary Mode is always restored to 0xFFFFFFFF on a MCU reset, even though the RTC didn't lose power.
I may find an alternative doing this initialization myself or modifying the HAL file on my project, but I would have liked not to resort to this. Is there maybe something I'm missing? Maybe using a mixed BCD/Binary mode with calendar enabled? Or could this be a potential feature to upstream into the HAL?
Thanks,
2024-07-01 01:58 AM
Hello @gbesnard ,
Your reported issue is being taken into consideration and has been assigned the internal ticket number 185361 for a detailed investigation.
It is an internal tracking number and is not accessible or usable by customers.
2024-09-09 01:30 AM
Hello @gbesnard ,
The issue has been successfully resolved and the fix will be included in the upcoming U5 release.
Thank you for your report.
Regards,
2024-12-19 05:59 AM
Hi,
Thank you for taking this issue into account,
I've been able to test the fix from the HAL 1.7.0.
The added test works for not reinitializing the RTC.
But a problem still remains, in that specific case, the function will return its default value, which is HAL_ERROR, instead of HAL_OK. The function lack a "else". My proposition below :
/* Check whether the calendar needs to be initialized */
if (__HAL_RTC_IS_CALENDAR_INITIALIZED(hrtc) == 0U)
{
/* Check that the RTC mode is not 'binary only' */
if (__HAL_RTC_GET_BINARY_MODE(hrtc) != RTC_BINARY_ONLY)
{
...
}
else /* MISSING ELSE */
{
/* RTC mode is 'binary only' */
/* Set flag to OK */
status = HAL_OK;
}
}
else
{
/* Calendar is already initialized */
/* Set flag to OK */
status = HAL_OK;
}