Skip to content

Commit 19e07e8

Browse files
authored
Merge pull request #6217 from jeromecoutant/PR_RTC
STM32 RTC : update free function
2 parents 153fa05 + 961c8da commit 19e07e8

File tree

1 file changed

+14
-24
lines changed

1 file changed

+14
-24
lines changed

targets/TARGET_STM/rtc_api.c

Lines changed: 14 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -144,28 +144,8 @@ void rtc_init(void)
144144

145145
void rtc_free(void)
146146
{
147-
#if !MBED_CONF_TARGET_LSE_AVAILABLE
148-
// Enable Power clock
149-
__HAL_RCC_PWR_CLK_ENABLE();
150-
151-
// Enable access to Backup domain
152-
HAL_PWR_EnableBkUpAccess();
153-
154-
// Reset Backup domain
155-
__HAL_RCC_BACKUPRESET_FORCE();
156-
__HAL_RCC_BACKUPRESET_RELEASE();
157-
158147
// Disable access to Backup domain
159148
HAL_PWR_DisableBkUpAccess();
160-
#endif
161-
162-
// Disable LSI and LSE clocks
163-
RCC_OscInitTypeDef RCC_OscInitStruct = {0};
164-
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_LSI | RCC_OSCILLATORTYPE_LSE;
165-
RCC_OscInitStruct.PLL.PLLState = RCC_PLL_NONE;
166-
RCC_OscInitStruct.LSIState = RCC_LSI_OFF;
167-
RCC_OscInitStruct.LSEState = RCC_LSE_OFF;
168-
HAL_RCC_OscConfig(&RCC_OscInitStruct);
169149
}
170150

171151
/*
@@ -209,7 +189,8 @@ So by moving it 68 years forward from 1970, it become 1969-2067 which include 19
209189
68 is also a multiple of 4 so it let the leap year synchronized.
210190
211191
Information about STM32F1:
212-
32bit register is used (no BCD format) for the seconds and a software structure to store dates.
192+
32bit register is used (no BCD format) for the seconds.
193+
For date, there is no specific register, only a software structure.
213194
It is then not a problem to not use shifts.
214195
*/
215196

@@ -226,16 +207,25 @@ time_t rtc_read(void)
226207
HAL_RTC_GetTime(&RtcHandle, &timeStruct, RTC_FORMAT_BIN);
227208
HAL_RTC_GetDate(&RtcHandle, &dateStruct, RTC_FORMAT_BIN);
228209

210+
#if TARGET_STM32F1
211+
/* date information is null before first write procedure */
212+
/* set 01/01/1970 as default values */
213+
if (dateStruct.Year == 0) {
214+
dateStruct.Year = 2 ;
215+
dateStruct.Month = 1 ;
216+
dateStruct.Date = 1 ;
217+
}
218+
#endif
219+
229220
// Setup a tm structure based on the RTC
230-
/* tm_wday information is ignored by mktime */
221+
/* tm_wday information is ignored by _rtc_maketime */
222+
/* tm_isdst information is ignored by _rtc_maketime */
231223
timeinfo.tm_mon = dateStruct.Month - 1;
232224
timeinfo.tm_mday = dateStruct.Date;
233225
timeinfo.tm_year = dateStruct.Year + 68;
234226
timeinfo.tm_hour = timeStruct.Hours;
235227
timeinfo.tm_min = timeStruct.Minutes;
236228
timeinfo.tm_sec = timeStruct.Seconds;
237-
// Daylight Saving Time information is not available
238-
timeinfo.tm_isdst = -1;
239229

240230
// Convert to timestamp
241231
time_t t;

0 commit comments

Comments
 (0)