/* Allow access to BKP Domain */ PWR_BackupAccessCmd(ENABLE);
/* Reset Backup Domain */ BKP_DeInit();
do { //delay about 0.1ms for(delay = 0;delay < 5000;delay++); // Enable HSE RCC_LSEConfig(RCC_LSE_ON); } while(RCC_GetFlagStatus(RCC_FLAG_LSERDY) == RESET); // Select HSE as RTC Clock Source RCC_RTCCLKConfig(RCC_RTCCLKSource_LSE);
/* 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 */
/* Wait for RTC registers synchronization */ RTC_WaitForSynchro();
/* Wait until last write operation on RTC registers has finished */ RTC_WaitForLastTask();
/* Enable the RTC Second */ RTC_ITConfig(RTC_IT_SEC, ENABLE);
/* Wait until last write operation on RTC registers has finished */ RTC_WaitForLastTask();
/* Set RTC prescaler: set RTC period to 1sec */ RTC_SetPrescaler(32767); /* RTC period = RTCCLK/RTC_PR = (32.768 KHz)/(32767+1) */ //RTC_SetPrescaler(62499); /* RTC period = RTCCLK/RTC_PR = (8M/128=62.5kHz)/(62499+1) */
/* Wait until last write operation on RTC registers has finished */ RTC_WaitForLastTask();
/* To output second signal on Tamper pin, the tamper functionality must be disabled (by default this functionality is disabled) */ BKP_TamperPinCmd(DISABLE);
/* Enable the RTC Second Output on Tamper Pin */ BKP_RTCOutputConfig(BKP_RTCOutputSource_Second);
/* Wait till PLL is ready */ while (RCC_GetFlagStatus(RCC_FLAG_PLLRDY) == RESET) {}
/* Select PLL as system clock source */ RCC_SYSCLKConfig(RCC_SYSCLKSource_PLLCLK);
/* Wait till PLL is used as system clock source */ while (RCC_GetSYSCLKSource() != 0x08) {} } } /******************************************************************** * Function Name : RTC_Configuration * Description : Configures the RTC. * Input : None * Output : None * Return : None ********************************************************************/ void RTC_Configuration(void) { u32 delay; /* Enable PWR and BKP clocks */ RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR | RCC_APB1Periph_BKP, ENABLE);
/* Allow access to BKP Domain */ PWR_BackupAccessCmd(ENABLE);
/* Reset Backup Domain */ BKP_DeInit();
// Select HSE/128 as RTC Clock Source RCC_RTCCLKConfig(RCC_RTCCLKSource_HSE_Div128);
/* Enable RTC Clock */ RCC_RTCCLKCmd(ENABLE);
/* Wait for RTC registers synchronization */ RTC_WaitForSynchro();
/* Wait until last write operation on RTC registers has finished */ RTC_WaitForLastTask();
/* Enable the RTC Second */ RTC_ITConfig(RTC_IT_SEC, ENABLE);
/* Wait until last write operation on RTC registers has finished */ RTC_WaitForLastTask();
/* Set RTC prescaler: set RTC period to 1sec */ RTC_SetPrescaler(62499); /* RTC period = RTCCLK/RTC_PR = (8M/128=62.5kHz)/(62499+1) */
/* Wait until last write operation on RTC registers has finished */ RTC_WaitForLastTask();
/* To output second signal on Tamper pin, the tamper functionality must be disabled (by default this functionality is disabled) */ BKP_TamperPinCmd(DISABLE);
/* Enable the RTC Second Output on Tamper Pin */ BKP_RTCOutputConfig(BKP_RTCOutputSource_Second);
#ifdef RTCClockOutput_Enable /* Disable the Tamper Pin */ BKP_TamperPinCmd(DISABLE); /* To output RTCCLK/64 on Tamper pin, the tamper functionality must be disabled */ /* Enable RTC Clock Output on Tamper Pin */ BKP_RTCCalibrationClockOutputCmd(ENABLE); #endif }