首先初始化RTC和millis
MILLIS_Init(); //初始化RTC为1Hz,同时初始化millis
MILLIS_Init() 函数的实现
void MILLIS_Init(void)
{
#ifdef USE_LSE
NVIC_InitTypeDef NVIC_InitStructure;
/* 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 */
if(PWR_GetFlagStatus(PWR_FLAG_WU) == SET) //判断是否被唤醒
{
PWR_ClearFlag(PWR_FLAG_WU); // 清除唤醒标志
}else
{
BKP_DeInit(); //复位备份区域
}
/* Enable LSE */
RCC_LSEConfig(RCC_LSE_ON);
/* Wait till LSE is ready */
while (RCC_GetFlagStatus(RCC_FLAG_LSERDY) == RESET)
{}
/* Select LSE as RTC Clock Source */
RCC_RTCCLKConfig(RCC_RTCCLKSource_LSE);
/* Enable RTC Clock */
RCC_RTCCLKCmd(ENABLE);
/* Wait for RTC registers synchronization */
RTC_WaitFo