Skip to content

Commit 8bf2775

Browse files
Merge pull request #5269 from bcostm/fix_rtc_struct_init
STM32: Initialize RTC structures at init phase.
2 parents b9a48a4 + 992722d commit 8bf2775

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

targets/TARGET_STM/rtc_api.c

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -57,13 +57,14 @@ static void RTC_IRQHandler(void);
5757

5858
void rtc_init(void)
5959
{
60-
RCC_OscInitTypeDef RCC_OscInitStruct;
61-
RCC_PeriphCLKInitTypeDef PeriphClkInitStruct;
60+
RCC_OscInitTypeDef RCC_OscInitStruct = {0};
61+
RCC_PeriphCLKInitTypeDef PeriphClkInitStruct = {0};
6262

6363
// Enable access to Backup domain
6464
HAL_PWR_EnableBkUpAccess();
6565

6666
RtcHandle.Instance = RTC;
67+
RtcHandle.State = HAL_RTC_STATE_RESET;
6768

6869
#if !RTC_LSI
6970
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_LSE;
@@ -162,7 +163,7 @@ void rtc_free(void)
162163
#endif
163164

164165
// Disable LSI and LSE clocks
165-
RCC_OscInitTypeDef RCC_OscInitStruct;
166+
RCC_OscInitTypeDef RCC_OscInitStruct = {0};
166167
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_LSI | RCC_OSCILLATORTYPE_LSE;
167168
RCC_OscInitStruct.PLL.PLLState = RCC_PLL_NONE;
168169
RCC_OscInitStruct.LSIState = RCC_LSI_OFF;
@@ -217,8 +218,8 @@ It is then not a problem to not use shifts.
217218

218219
time_t rtc_read(void)
219220
{
220-
RTC_DateTypeDef dateStruct;
221-
RTC_TimeTypeDef timeStruct;
221+
RTC_DateTypeDef dateStruct = {0};
222+
RTC_TimeTypeDef timeStruct = {0};
222223
struct tm timeinfo;
223224

224225
RtcHandle.Instance = RTC;
@@ -247,8 +248,8 @@ time_t rtc_read(void)
247248

248249
void rtc_write(time_t t)
249250
{
250-
RTC_DateTypeDef dateStruct;
251-
RTC_TimeTypeDef timeStruct;
251+
RTC_DateTypeDef dateStruct = {0};
252+
RTC_TimeTypeDef timeStruct = {0};
252253

253254
RtcHandle.Instance = RTC;
254255

0 commit comments

Comments
 (0)