@@ -141,51 +141,15 @@ Information about STM32F1:
141
141
For date, there is no specific register, only a software structure.
142
142
It is then not a problem to not use shifts.
143
143
*/
144
- #if TARGET_STM32F1
145
144
time_t rtc_read (void )
146
145
{
147
- RTC_DateTypeDef dateStruct = {0 };
148
- RTC_TimeTypeDef timeStruct = {0 };
149
- struct tm timeinfo ;
146
+ #if TARGET_STM32F1
150
147
151
148
RtcHandle .Instance = RTC ;
152
-
153
- // Read actual date and time
154
- // Warning: the time must be read first!
155
- HAL_RTC_GetTime (& RtcHandle , & timeStruct , RTC_FORMAT_BIN );
156
- HAL_RTC_GetDate (& RtcHandle , & dateStruct , RTC_FORMAT_BIN );
157
-
158
- /* date information is null before first write procedure */
159
- /* set 01/01/1970 as default values */
160
- if (dateStruct .Year == 0 ) {
161
- dateStruct .Year = 2 ;
162
- dateStruct .Month = 1 ;
163
- dateStruct .Date = 1 ;
164
- }
165
-
166
- // Setup a tm structure based on the RTC
167
- /* tm_wday information is ignored by _rtc_maketime */
168
- /* tm_isdst information is ignored by _rtc_maketime */
169
- timeinfo .tm_mon = dateStruct .Month - 1 ;
170
- timeinfo .tm_mday = dateStruct .Date ;
171
- timeinfo .tm_year = dateStruct .Year + 68 ;
172
- timeinfo .tm_hour = timeStruct .Hours ;
173
- timeinfo .tm_min = timeStruct .Minutes ;
174
- timeinfo .tm_sec = timeStruct .Seconds ;
175
-
176
- // Convert to timestamp
177
- time_t t ;
178
- if (_rtc_maketime (& timeinfo , & t , RTC_4_YEAR_LEAP_YEAR_SUPPORT ) == false) {
179
- return 0 ;
180
- }
181
-
182
- return t ;
183
- }
149
+ return RTC_ReadTimeCounter (& RtcHandle );
184
150
185
151
#else /* TARGET_STM32F1 */
186
152
187
- time_t rtc_read (void )
188
- {
189
153
struct tm timeinfo ;
190
154
191
155
/* Since the shadow registers are bypassed we have to read the time twice and compare them until both times are the same */
@@ -223,12 +187,23 @@ time_t rtc_read(void)
223
187
}
224
188
225
189
return t ;
226
- }
227
190
228
191
#endif /* TARGET_STM32F1 */
192
+ }
193
+
194
+
229
195
230
196
void rtc_write (time_t t )
231
197
{
198
+ #if TARGET_STM32F1
199
+
200
+ RtcHandle .Instance = RTC ;
201
+ if (RTC_WriteTimeCounter (& RtcHandle , t ) != HAL_OK ) {
202
+ error ("RTC_WriteTimeCounter error\n" );
203
+ }
204
+
205
+ #else /* TARGET_STM32F1 */
206
+
232
207
RTC_DateTypeDef dateStruct = {0 };
233
208
RTC_TimeTypeDef timeStruct = {0 };
234
209
@@ -253,12 +228,9 @@ void rtc_write(time_t t)
253
228
timeStruct .Hours = timeinfo .tm_hour ;
254
229
timeStruct .Minutes = timeinfo .tm_min ;
255
230
timeStruct .Seconds = timeinfo .tm_sec ;
256
-
257
- #if !(TARGET_STM32F1 )
258
231
timeStruct .TimeFormat = RTC_HOURFORMAT_24 ;
259
232
timeStruct .DayLightSaving = RTC_DAYLIGHTSAVING_NONE ;
260
233
timeStruct .StoreOperation = RTC_STOREOPERATION_RESET ;
261
- #endif /* TARGET_STM32F1 */
262
234
263
235
#if DEVICE_LPTICKER && !MBED_CONF_TARGET_LPTICKER_LPTIM
264
236
/* Before setting the new time, we need to update the LPTICKER_counter value */
@@ -280,6 +252,7 @@ void rtc_write(time_t t)
280
252
}
281
253
282
254
core_util_critical_section_exit ();
255
+ #endif /* TARGET_STM32F1 */
283
256
}
284
257
285
258
int rtc_isenabled (void )
0 commit comments