/* Waits until the RTC Time and Date registers (RTC_TR and RTC_DR) are synchronized with RTC APB clock.  */
ErrorStatus RTC_WaitForSynchro(void)
/* Waits until the RTC Time and Date registers (RTC_TR and RTC_DR) are synchronized with RTC APB clock.  */
ErrorStatus RTC_WaitForSynchro(void)
{
  __IO uint32_t synchrocounter = 0;
  ErrorStatus status = ERROR;
  uint32_t synchrostatus = 0x00;
  if ((RTC->CR & RTC_CR_BYPSHAD) != RESET)
  {
    status = SUCCESS;
  }
  else
  {
    RTC->WPR = 0xCA;
    RTC->WPR = 0x53;
    RTC->ISR &= (uint32_t)RTC_RSF_MASK;
    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;
    }
    RTC->WPR = 0xFF;
  }
  return (status);
}