2024-07-19 04:06 PM
HAL RTC functions for the STM32L4 should, like HAL functions for other peripherals, have an
assert_param(IS_RTC_INSTANCE(hrtc->Instance));
All of the HAL_RTC_* functions accept an RTC_HandleTypeDef argument. However, the implementation of these function mix the use of hrtc->Instance->REG and RTC->REG. This inconsistency has led to some bugs creeping into my code. For example, one can successfully set date and time (HAL_RTC_SetDate(), HAL_RTC_SetTime()) without first calling HAL_RTC_Init() to initialize hrtc. But with a change to the STM32L4 HAL between 1.17.1 and 1.18.0, these functions still successfully set the date and time, but now return HAL_TIMEOUT. I really do need to call HAL_RTC_Init(), but the HAL should help the developer here.
It would be best if these functions either used only RTC or only hrtc->Instance for access to the device registers rather than mixing the two. But most importantly, the RTC HAL functions should validate that the RTC handle is properly initialized before using it.