@@ -149,51 +149,15 @@ Information about STM32F1:
149
149
For date, there is no specific register, only a software structure.
150
150
It is then not a problem to not use shifts.
151
151
*/
152
- #if TARGET_STM32F1
153
152
time_t rtc_read (void )
154
153
{
155
- RTC_DateTypeDef dateStruct = {0 };
156
- RTC_TimeTypeDef timeStruct = {0 };
157
- struct tm timeinfo ;
154
+ #if TARGET_STM32F1
158
155
159
156
RtcHandle .Instance = RTC ;
160
-
161
- // Read actual date and time
162
- // Warning: the time must be read first!
163
- HAL_RTC_GetTime (& RtcHandle , & timeStruct , RTC_FORMAT_BIN );
164
- HAL_RTC_GetDate (& RtcHandle , & dateStruct , RTC_FORMAT_BIN );
165
-
166
- /* date information is null before first write procedure */
167
- /* set 01/01/1970 as default values */
168
- if (dateStruct .Year == 0 ) {
169
- dateStruct .Year = 2 ;
170
- dateStruct .Month = 1 ;
171
- dateStruct .Date = 1 ;
172
- }
173
-
174
- // Setup a tm structure based on the RTC
175
- /* tm_wday information is ignored by _rtc_maketime */
176
- /* tm_isdst information is ignored by _rtc_maketime */
177
- timeinfo .tm_mon = dateStruct .Month - 1 ;
178
- timeinfo .tm_mday = dateStruct .Date ;
179
- timeinfo .tm_year = dateStruct .Year + 68 ;
180
- timeinfo .tm_hour = timeStruct .Hours ;
181
- timeinfo .tm_min = timeStruct .Minutes ;
182
- timeinfo .tm_sec = timeStruct .Seconds ;
183
-
184
- // Convert to timestamp
185
- time_t t ;
186
- if (_rtc_maketime (& timeinfo , & t , RTC_4_YEAR_LEAP_YEAR_SUPPORT ) == false) {
187
- return 0 ;
188
- }
189
-
190
- return t ;
191
- }
157
+ return RTC_ReadTimeCounter (& RtcHandle );
192
158
193
159
#else /* TARGET_STM32F1 */
194
160
195
- time_t rtc_read (void )
196
- {
197
161
struct tm timeinfo ;
198
162
199
163
/* Since the shadow registers are bypassed we have to read the time twice and compare them until both times are the same */
@@ -231,12 +195,23 @@ time_t rtc_read(void)
231
195
}
232
196
233
197
return t ;
234
- }
235
198
236
199
#endif /* TARGET_STM32F1 */
200
+ }
201
+
202
+
237
203
238
204
void rtc_write (time_t t )
239
205
{
206
+ #if TARGET_STM32F1
207
+
208
+ RtcHandle .Instance = RTC ;
209
+ if (RTC_WriteTimeCounter (& RtcHandle , t ) != HAL_OK ) {
210
+ error ("RTC_WriteTimeCounter error\n" );
211
+ }
212
+
213
+ #else /* TARGET_STM32F1 */
214
+
240
215
RTC_DateTypeDef dateStruct = {0 };
241
216
RTC_TimeTypeDef timeStruct = {0 };
242
217
@@ -261,12 +236,9 @@ void rtc_write(time_t t)
261
236
timeStruct .Hours = timeinfo .tm_hour ;
262
237
timeStruct .Minutes = timeinfo .tm_min ;
263
238
timeStruct .Seconds = timeinfo .tm_sec ;
264
-
265
- #if !(TARGET_STM32F1 )
266
239
timeStruct .TimeFormat = RTC_HOURFORMAT_24 ;
267
240
timeStruct .DayLightSaving = RTC_DAYLIGHTSAVING_NONE ;
268
241
timeStruct .StoreOperation = RTC_STOREOPERATION_RESET ;
269
- #endif /* TARGET_STM32F1 */
270
242
271
243
#if DEVICE_LPTICKER && !MBED_CONF_TARGET_LPTICKER_LPTIM
272
244
/* Need to update LP_continuous_time value before new RTC time */
@@ -293,6 +265,7 @@ void rtc_write(time_t t)
293
265
#endif /* DEVICE_LPTICKER && !MBED_CONF_TARGET_LPTICKER_LPTIM */
294
266
295
267
core_util_critical_section_exit ();
268
+ #endif /* TARGET_STM32F1 */
296
269
}
297
270
298
271
int rtc_isenabled (void )
0 commit comments