Description
RTC should contain an assertion checking if the prescaler values are configured or not. Or check if configured and if not, call the function to compute the values.
This portion of code
Lines 382 to 398 in 95b7514
Line 391 in 95b7514
In case only a soft reset is performed, the RTC remains initialized, the above mentioned code is not executed and prescaler values are not calculated. Therefore they remain set to -1. Then when setting and RTC alarm with subseconds enabled, the following issue occurs:
- these variables remain set to the initial default value
Lines 69 to 71 in 95b7514
- RTC_AlaramStrucutre subsecond parameters are set here
Lines 611 to 612 in 95b7514
- the strucutre is passed to
Line 654 in 95b7514
- where it is used to compute the value to be written to register https://github.com/stm32duino/Arduino_Core_STM32/blob/491ddc80df212c417de88d8039ff43f800cf0c28/system/Drivers/STM32G0xx_HAL_Driver/Src/stm32g0xx_hal_rtc.c#L1298 (the specific file depends on used platform, for me it was this file), https://github.com/stm32duino/Arduino_Core_STM32/blob/main/system/Drivers/STM32G0xx_HAL_Driver/Src/stm32g0xx_hal_rtc.c#L1332
This leads to reserved bits in the register being written to 1 and generally incorrect behaviour. This is not easy to debug and just a note in the readme that the function setPrediv() must be called before begin() can easly be missed.
The examples also don't call this function, which makes the issue even more hidden. Maybe some boards ensure that invalid values are not written to registers and this issue is not observed on them.