Bug in LL_RTC_WaitForSynchro() function in stm32l1xx_ll_rtc.c?
I think there is a bug in the function LL_RTC_WaitForSynchro(). It waits for the RTC_ISR_RSF to become 0 (on row 15). I think this is a bug. It should wait for the RTC_ISR_RSF to become 1 as in the old STM32 Standard Peripheral Libraries. My code sometimes gets stuck in this loop.
ErrorStatus LL_RTC_WaitForSynchro(RTC_TypeDef *RTCx)
{
__IO uint32_t timeout = RTC_SYNCHRO_TIMEOUT;
ErrorStatus status = SUCCESS;
uint32_t tmp;
/* Check the parameter */
assert_param(IS_RTC_ALL_INSTANCE(RTCx));
/* Clear RSF flag */
LL_RTC_ClearFlag_RS(RTCx);
/* Wait the registers to be synchronised */
tmp = LL_RTC_IsActiveFlag_RS(RTCx);
while ((timeout != 0U) && (tmp != 0U))
{
if (LL_SYSTICK_IsActiveCounterFlag() == 1U)
{
timeout--;
}
tmp = LL_RTC_IsActiveFlag_RS(RTCx);
if (timeout == 0U)
{
status = ERROR;
}
}
if (status != ERROR)
{
timeout = RTC_SYNCHRO_TIMEOUT;
tmp = LL_RTC_IsActiveFlag_RS(RTCx);
while ((timeout != 0U) && (tmp != 1U))
{
if (LL_SYSTICK_IsActiveCounterFlag() == 1U)
{
timeout--;
}
tmp = LL_RTC_IsActiveFlag_RS(RTCx);
if (timeout == 0U)
{
status = ERROR;
}
}
}
return (status);
}Compare it to the similar function RTC_WaitForSynchro() in STM32 Standard Peripheral Libraries (stm32l1xx_rtc.c). Here we wait for the RTC_ISR_RSF to become 1 (row 19).
ErrorStatus RTC_WaitForSynchro(void)
{
__IO uint32_t synchrocounter = 0;
ErrorStatus status = ERROR;
uint32_t synchrostatus = 0x00;
/* Disable the write protection for RTC registers */
RTC->WPR = 0xCA;
RTC->WPR = 0x53;
/* Clear RSF flag */
RTC->ISR &= (uint32_t)RTC_RSF_MASK;
/* Wait the registers to be synchronised */
do
{
synchrostatus = RTC->ISR & RTC_ISR_RSF;
synchrocounter++;
} while((synchrocounter != SYNCHRO_TIMEOUT) && (synchrostatus == 0x00));
if ((RTC->ISR & RTC_ISR_RSF) != RESET)
{
status = SUCCESS;
}
else
{
status = ERROR;
}
/* Enable the write protection for RTC registers */
RTC->WPR = 0xFF;
return (status);
}