diff Small_CPU/Src/rtc.c @ 232:f0069f002c55 div-fixes-4-1

Bugfix: make date/time setting work over reboots Setting the time/date over the UART interface or by the menu, seems to work, but a reboot of the RTE brings back strange, seemingly random, time. The reason for this is rather simple. In the settings, a time is stored, based on some flawed logic, and that time was restored on reboot. There is no reason to store any time, when the moment of restoring it is unrelated in time. So, the fix is simple: do not set time (in the RTC) based on some time from the past. The whole idea of a RTC is that it does preserve the time for you, as long its powered. Any attempt to do things better using stored time data is futile (and nonsense). And while working on his, also kick out some useless code from the RTE. There is no reason to initialize the time on the RTC to some random time/date in the past. A zero data/time is as good and any random date. Signed-off-by: Jan Mulder <jlmulder@xs4all.nl>
author Jan Mulder <jlmulder@xs4all.nl>
date Wed, 03 Apr 2019 21:11:56 +0200
parents 5f11787b4f42
children
line wrap: on
line diff
--- a/Small_CPU/Src/rtc.c	Wed Apr 03 14:33:12 2019 +0200
+++ b/Small_CPU/Src/rtc.c	Wed Apr 03 21:11:56 2019 +0200
@@ -33,7 +33,7 @@
 {
 
 	stimestructure.SubSeconds = 0;
-  stimestructure.TimeFormat = RTC_HOURFORMAT12_AM;
+  stimestructure.TimeFormat = RTC_HOURFORMAT_24;
   stimestructure.DayLightSaving = RTC_DAYLIGHTSAVING_NONE ;
   stimestructure.StoreOperation = RTC_STOREOPERATION_RESET;
 
@@ -104,13 +104,7 @@
 
 void MX_RTC_init(void)
 {
-
-  RTC_TimeTypeDef sTime;
-  RTC_DateTypeDef sDate;
-//  RTC_AlarmTypeDef sAlarm;
-
-    /**Initialize RTC and set the Time and Date 
-    */
+  /* Initialize RTC */
   RTCHandle.Instance = RTC;
   RTCHandle.Init.HourFormat = RTC_HOURFORMAT_24;
   RTCHandle.Init.AsynchPrediv = 127;
@@ -119,34 +113,6 @@
   RTCHandle.Init.OutPutPolarity = RTC_OUTPUT_POLARITY_HIGH;
   RTCHandle.Init.OutPutType = RTC_OUTPUT_TYPE_OPENDRAIN;
   HAL_RTC_Init(&RTCHandle);
-
-  sTime.Hours = 11;
-  sTime.Minutes = 0;
-  sTime.Seconds = 0;
-  sTime.SubSeconds = 0;
-  sTime.TimeFormat = RTC_HOURFORMAT12_AM;
-  sTime.DayLightSaving = RTC_DAYLIGHTSAVING_NONE;
-  sTime.StoreOperation = RTC_STOREOPERATION_RESET;
-  HAL_RTC_SetTime(&RTCHandle, &sTime, FORMAT_BCD);
-
-  sDate.WeekDay = RTC_WEEKDAY_SUNDAY;
-  sDate.Month = RTC_MONTH_FEBRUARY;
-  sDate.Date = 15;
-  sDate.Year = 17;
-  HAL_RTC_SetDate(&RTCHandle, &sDate, FORMAT_BCD);
-
-
-/*
-  RTCHandle.Instance = RTC; 
-  RTCHandle.Init.HourFormat = RTC_HOURFORMAT_24;
-  RTCHandle.Init.AsynchPrediv = RTC_ASYNCH_PREDIV;
-  RTCHandle.Init.SynchPrediv = RTC_SYNCH_PREDIV;
-  RTCHandle.Init.OutPut = RTC_OUTPUT_DISABLE;
-  RTCHandle.Init.OutPutPolarity = RTC_OUTPUT_POLARITY_HIGH;
-  RTCHandle.Init.OutPutType = RTC_OUTPUT_TYPE_OPENDRAIN;
-	
-	HAL_RTC_Init(&RTCHandle);
-*/	
 }