4.17生成的代码和4.20.1的RTC初始化代码区别为红色部分,备份寄存器我做了其它用途,你这自动把RTC的备份配置到备份寄存器1上,不利于用户选择,能否在UI上让用户自行选择RTC的备份寄存器? /* RTC init function */ static void MX_RTC_Init(void) { RTC_TimeTypeDef sTime; RTC_DateTypeDef DateToUpdate; /**Initialize RTC Only */ hrtc.Instance = RTC; hrtc.Init.AsynchPrediv = RTC_AUTO_1_SECOND; hrtc.Init.OutPut = RTC_OUTPUTSOURCE_NONE; if (HAL_RTC_Init(&hrtc) != HAL_OK) { Error_Handler(); } /**Initialize RTC and set the Time and Date */ if(HAL_RTCEx_BKUPRead(&hrtc, RTC_BKP_DR1) != 0x32F2){ sTime.Hours = 0x1; sTime.Minutes = 0x0; sTime.Seconds = 0x0; if (HAL_RTC_SetTime(&hrtc, &sTime, RTC_FORMAT_BCD) != HAL_OK) { Error_Handler(); } DateToUpdate.WeekDay = RTC_WEEKDAY_MONDAY; DateToUpdate.Month = RTC_MONTH_JANUARY; DateToUpdate.Date = 0x1; DateToUpdate.Year = 0x0; if (HAL_RTC_SetDate(&hrtc, &DateToUpdate, RTC_FORMAT_BCD) != HAL_OK) { Error_Handler(); } HAL_RTCEx_BKUPWrite(&hrtc,RTC_BKP_DR1,0x32F2); } } |
楼主的建议不错,支持。 |