/* Waits until the RTC Time and Date registers (RTC_TSH and RTC_DATE) are synchronized with RTC APB clock.  */
ErrorStatus RTC_WaitForSynchro(void)
/* Waits until the RTC Time and Date registers (RTC_TSH and RTC_DATE) are synchronized with RTC APB clock.  */
ErrorStatus RTC_WaitForSynchro(void)
{
    __IO uint32_t synchrocounter = 0;
    ErrorStatus status           = ERROR;
    uint32_t synchrostatus       = 0x00;
    RTC->WRP = 0xCA;
    RTC->WRP = 0x53;
    RTC->INITSTS &= (uint32_t)RTC_RSF_MASK;
    do
    {
        synchrostatus = RTC->INITSTS & RTC_INITSTS_RSYF;
        synchrocounter++;
    } while ((synchrocounter != SYNCHRO_TIMEOUT) && (synchrostatus == 0x00));
    if ((RTC->INITSTS & RTC_INITSTS_RSYF) != RESET)
    {
        status = SUCCESS;
    }
    else
    {
        status = ERROR;
    }
    RTC->WRP = 0xFF;
    return (status);
}