stm32 RTC_WaitForSynchro()死循环
- UID
- 1066743
|
stm32 RTC_WaitForSynchro()死循环
1.RTC_WaitForSynchro()死循环,发现是没有执行RTC_Configuration(),增加函数,但不知道对之后的时钟准确性有什么影响
/******************************************************************************** Function Name : RTC_Configuration* Description : Configures the RTC.* Input : None* Output : None* Return : 0 reday,-1 error.*******************************************************************************/int RTC_Configuration(void){ u32 countmax = 0x20000; u32 count = countmax; /* 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(); /* Enable LSE */ RCC_LSEConfig(RCC_LSE_ON); /* Wait till LSE is ready */ while((RCC_GetFlagStatus(RCC_FLAG_LSERDY) == RESET) && (--count)); if(count == 0) { count = countmax; //关闭外部低速晶振(LSE) RCC_LSEConfig(RCC_LSE_OFF); //如果失败,使用内部晶振 //使能或者失能内部低速晶振(LSI) RCC_LSICmd(ENABLE); //设置RTC时钟(RTCCLK) RCC_RTCCLKConfig(RCC_RTCCLKSource_LSI); /* Wait till LSI is ready */ while((RCC_GetFlagStatus(RCC_FLAG_LSIRDY) == RESET) && (--count)); if(count == 0) return 1; } else { /* Select LSE as RTC Clock Source */ RCC_RTCCLKConfig(RCC_RTCCLKSource_LSE);//设置RTC时钟(RTCCLK) } /* 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(); /* Set RTC prescaler: set RTC period to 1sec */ RTC_SetPrescaler(32767); /* RTC period = RTCCLK/RTC_PR = (32.768 KHz)/(32767+1) */ /* Wait until last write operation on RTC registers has finished */ RTC_WaitForLastTask(); return 0;}
void rt_hw_rtc_init(void){ rtc.type = RT_Device_Class_RTC; if(BKP_ReadBackupRegister(BKP_DR1) != 0xA5A5) { rt_kprintf("rtc is not configured\n"); rt_kprintf("please configure with set_date and set_time\n"); if(RTC_Configuration() != 0) { rt_kprintf("rtc configure fail...\r\n"); return ; } } else { if(RTC_Configuration() != 0) { rt_kprintf("rtc configure fail...\r\n"); return ; } /* Wait for RTC registers synchronization */ RTC_WaitForSynchro(); } /* register rtc device */ rtc.init = RT_NULL; rtc.open = rt_rtc_open; rtc.close = RT_NULL; rtc.read = rt_rtc_read; rtc.write = RT_NULL; rtc.control = rt_rtc_control; /* no private */ rtc.user_data = RT_NULL; rt_device_register(&rtc, "rtc", RT_DEVICE_FLAG_RDWR); return;} |
|
|
|
|
|