if(BKP_ReadBackupRegister(BKP_DR1) != 0xA6A7) { /* Backup data register value is not correct or not yet programmed (when the first time the program is executed) */
/* Enable the RTC Second */ RTC_ITConfig(RTC_IT_SEC, ENABLE); /* Wait until last write operation on RTC registers has finished */ RTC_WaitForLastTask(); }
#ifdef RTCClockSource_LSI RCC_LSICmd(ENABLE); /* Enable LSI */ while(RCC_GetFlagStatus(RCC_FLAG_LSIRDY) == RESET); /* Wait till LSI is ready */ RCC_RTCCLKConfig(RCC_RTCCLKSource_LSI); /* Select LSI as RTC Clock Source */
#elif defined RTCClockSource_LSE RCC_LSEConfig(RCC_LSE_ON); /* Enable LSE */ while(RCC_GetFlagStatus(RCC_FLAG_LSERDY) == RESET); /* Wait till LSE is ready */ RCC_RTCCLKConfig(RCC_RTCCLKSource_LSE);/* Select LSE as RTC Clock Source */ #endif
/* Enable RTC Clock */ RCC_RTCCLKCmd(ENABLE);
#ifdef RTCClockOutput_Enable /* Disable the Tamper Pin */ BKP_TamperPinCmd(DISABLE); /* To output RTCCLK/64 on Tamper pin, the tamper functionality must be disabled */ BKP_RTCCalibrationClockOutputCmd(ENABLE); /* Enable RTC Clock Output on Tamper Pin */ #endif
/* Wait for RTC registers synchronization */ RTC_WaitForSynchro(); RTC_WaitForLastTask(); /* Enable the RTC Second */ RTC_ITConfig(RTC_IT_SEC, ENABLE);
/* Set RTC prescaler: set RTC period to 1sec */ #ifdef RTCClockSource_LSI RTC_SetPrescaler(39999); /* RTC period = RTCCLK/RTC_PR = (40.000 KHz)/(39999+1) */ #elif defined RTCClockSource_LSE RTC_SetPrescaler(32767); /* RTC period = RTCCLK/RTC_PR = (32.768 KHz)/(32767+1) */ #endif /* Wait until last write operation on RTC registers has finished */ RTC_WaitForLastTask(); } ……………………………………………………………………………..