Mercurial > public > ostc4
annotate Small_CPU/Src/rtc.c @ 319:d8e86af78474 fix-version
bugfix: correct packed main version number in dive header
This fixes a rather mysterious bug. Users report that up to 1.3.5 beta,
a correct version number is shown in libdivecomputer based
applications (like in Subsurface, in the extra data tab). Careful
examining the code in both libdivecomputer and the firmware shows
a subtle error in the bit mask and shift operation to pack a full
X.Y.Z.beta version number in 2 bytes (as is available in the
dive header) in the firmware end (as the libdivecomputer code
looks sane, assuming this is the right way to pack things).
Likely, this bug crept in in the conversion from the closed
source Keil period into the open source GCC setup of
the code base. So its impossible to document the exact
history of this problem here.
Further notice that the main version number is only 1 of 3 version
numbers, denoting the full version of the firmware (besides Font
and RTE).
Finally notice that this way of packing is limited to 2^5 bits
(decimal 32), so we could easily build a 1.4.21, but not a
1.4.55.
Signed-off-by: Jan Mulder <jlmulder@xs4all.nl>
author | Jan Mulder <jlmulder@xs4all.nl> |
---|---|
date | Wed, 19 Jun 2019 14:31:50 +0200 |
parents | f0069f002c55 |
children |
rev | line source |
---|---|
38 | 1 /** |
2 ****************************************************************************** | |
3 * @file rtc.c | |
4 * @author heinrichs weikamp gmbh | |
5 * @version V0.0.1 | |
6 * @date 10-Oct-2014 | |
7 * @brief Source code for rtc control | |
8 * | |
9 @verbatim | |
10 ============================================================================== | |
11 ##### How to use ##### | |
12 ============================================================================== | |
13 @endverbatim | |
14 ****************************************************************************** | |
15 * @attention | |
16 * | |
17 * <h2><center>© COPYRIGHT(c) 2015 heinrichs weikamp</center></h2> | |
18 * | |
19 ****************************************************************************** | |
20 */ | |
21 /* Includes ------------------------------------------------------------------*/ | |
22 #include "rtc.h" | |
23 #include "stm32f4xx_hal.h" | |
24 #include "stm32f4xx_hal_conf.h" | |
25 #include "baseCPU2.h" | |
26 | |
27 RTC_HandleTypeDef RTCHandle; | |
28 | |
29 static void RTC_Error_Handler(void); | |
30 | |
31 | |
32 void RTC_SetTime(RTC_TimeTypeDef stimestructure) | |
33 { | |
34 | |
35 stimestructure.SubSeconds = 0; | |
232
f0069f002c55
Bugfix: make date/time setting work over reboots
Jan Mulder <jlmulder@xs4all.nl>
parents:
38
diff
changeset
|
36 stimestructure.TimeFormat = RTC_HOURFORMAT_24; |
38 | 37 stimestructure.DayLightSaving = RTC_DAYLIGHTSAVING_NONE ; |
38 stimestructure.StoreOperation = RTC_STOREOPERATION_RESET; | |
39 | |
40 if(HAL_RTC_SetTime(&RTCHandle, &stimestructure, FORMAT_BIN) != HAL_OK) | |
41 { | |
42 RTC_Error_Handler(); | |
43 } | |
44 } | |
45 | |
46 | |
47 void RTC_SetDate(RTC_DateTypeDef sdatestructure) | |
48 { | |
49 if(HAL_RTC_SetDate(&RTCHandle, &sdatestructure, FORMAT_BIN) != HAL_OK) | |
50 { | |
51 RTC_Error_Handler(); | |
52 } | |
53 } | |
54 | |
55 | |
56 /* | |
57 static void RTC_CalendarConfig(void) | |
58 { | |
59 RTC_DateTypeDef sdatestructure; | |
60 RTC_TimeTypeDef stimestructure; | |
61 | |
62 //##-1- Configure the Date ################################################# | |
63 // Set Date: Monday April 14th 2014 | |
64 sdatestructure.Year = 0; | |
65 sdatestructure.Month = RTC_MONTH_JANUARY; | |
66 sdatestructure.Date = 1; | |
67 sdatestructure.WeekDay = RTC_WEEKDAY_MONDAY; | |
68 | |
69 if(HAL_RTC_SetDate(&RTCHandle,&sdatestructure,FORMAT_BCD) != HAL_OK) | |
70 { | |
71 RTC_Error_Handler(); | |
72 } | |
73 | |
74 //##-2- Configure the Time ################################################# | |
75 // Set Time: 02:00:00 | |
76 stimestructure.Hours = 0; | |
77 stimestructure.Minutes = 0; | |
78 stimestructure.Seconds = 0; | |
79 stimestructure.DayLightSaving = RTC_DAYLIGHTSAVING_NONE ; | |
80 stimestructure.StoreOperation = RTC_STOREOPERATION_RESET; | |
81 | |
82 if(HAL_RTC_SetTime(&RTCHandle,&stimestructure,FORMAT_BCD) != HAL_OK) | |
83 { | |
84 RTC_Error_Handler(); | |
85 } | |
86 | |
87 //##-3- Writes a data in a RTC Backup data Register0 ####################### | |
88 // HAL_RTCEx_BKUPWrite(&RTCHandle,RTC_BKP_DR0,0x32F2); | |
89 } | |
90 */ | |
91 | |
92 | |
93 /* ##-1- Configure the RTC peripheral ####################################### | |
94 Configure RTC prescaler and RTC data registers | |
95 RTC configured as follow: | |
96 - Hour Format = Format 24 | |
97 - Asynch Prediv = Value according to source clock | |
98 - Synch Prediv = Value according to source clock | |
99 - OutPut = Output Disable | |
100 - OutPutPolarity = High Polarity | |
101 - OutPutType = Open Drain | |
102 */ | |
103 | |
104 | |
105 void MX_RTC_init(void) | |
106 { | |
232
f0069f002c55
Bugfix: make date/time setting work over reboots
Jan Mulder <jlmulder@xs4all.nl>
parents:
38
diff
changeset
|
107 /* Initialize RTC */ |
38 | 108 RTCHandle.Instance = RTC; |
109 RTCHandle.Init.HourFormat = RTC_HOURFORMAT_24; | |
110 RTCHandle.Init.AsynchPrediv = 127; | |
111 RTCHandle.Init.SynchPrediv = 255; | |
112 RTCHandle.Init.OutPut = RTC_OUTPUT_DISABLE; | |
113 RTCHandle.Init.OutPutPolarity = RTC_OUTPUT_POLARITY_HIGH; | |
114 RTCHandle.Init.OutPutType = RTC_OUTPUT_TYPE_OPENDRAIN; | |
115 HAL_RTC_Init(&RTCHandle); | |
116 } | |
117 | |
118 | |
119 void RTC_StopMode_2seconds(void) | |
120 { | |
121 /* Enable Power Control clock */ | |
122 __HAL_RCC_PWR_CLK_ENABLE(); | |
123 | |
124 /* Disable Wake-up timer */ | |
125 HAL_RTCEx_DeactivateWakeUpTimer(&RTCHandle); | |
126 | |
127 /* Enable Wake-up timer */ | |
128 HAL_RTCEx_SetWakeUpTimer_IT(&RTCHandle, (0x1000-1), RTC_WAKEUPCLOCK_RTCCLK_DIV16); | |
129 | |
130 /* FLASH Deep Power Down Mode enabled */ | |
131 HAL_PWREx_EnableFlashPowerDown(); | |
132 | |
133 /*## Enter Stop Mode #######################################################*/ | |
134 HAL_PWR_EnterSTOPMode(PWR_LOWPOWERREGULATOR_ON, PWR_STOPENTRY_WFI); | |
135 | |
136 /* Configures system clock after wake-up from STOP: enable HSI, PLL and select | |
137 PLL as system clock source (HSI and PLL are disabled in STOP mode) */ | |
138 SYSCLKConfig_STOP(); | |
139 | |
140 HAL_RTCEx_DeactivateWakeUpTimer(&RTCHandle); | |
141 } | |
142 | |
143 | |
144 void RTC_Stop_11ms(void) | |
145 { | |
146 /* Disable Wake-up timer */ | |
147 HAL_RTCEx_DeactivateWakeUpTimer(&RTCHandle); | |
148 | |
149 /* Enable Wake-up timer */ | |
150 HAL_RTCEx_SetWakeUpTimer_IT(&RTCHandle, (0x18-1), RTC_WAKEUPCLOCK_RTCCLK_DIV16); | |
151 | |
152 /* FLASH Deep Power Down Mode enabled */ | |
153 HAL_PWREx_DisableFlashPowerDown(); | |
154 | |
155 /*## Enter Stop Mode #######################################################*/ | |
156 HAL_PWR_EnterSTOPMode(PWR_MAINREGULATOR_ON, PWR_STOPENTRY_WFI); | |
157 | |
158 /* Configures system clock after wake-up from STOP: enable HSI, PLL and select | |
159 PLL as system clock source (HSI and PLL are disabled in STOP mode) */ | |
160 SYSCLKConfig_STOP(); | |
161 | |
162 HAL_RTCEx_DeactivateWakeUpTimer(&RTCHandle); | |
163 } | |
164 | |
165 | |
166 static void RTC_Error_Handler(void) | |
167 { | |
168 while(1); | |
169 } | |
170 | |
171 | |
172 /************************ (C) COPYRIGHT heinrichs weikamp *****END OF FILE****/ |