From c571d8d6f820a2d0decc39880edfb9e3b3b5eed7 Mon Sep 17 00:00:00 2001 From: bcostm Date: Fri, 6 Oct 2017 15:44:16 +0200 Subject: [PATCH 1/2] STM32 RTC: initializes structures --- targets/TARGET_STM/rtc_api.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/targets/TARGET_STM/rtc_api.c b/targets/TARGET_STM/rtc_api.c index c9e9341cf8..3be15602c6 100644 --- a/targets/TARGET_STM/rtc_api.c +++ b/targets/TARGET_STM/rtc_api.c @@ -57,8 +57,8 @@ static void RTC_IRQHandler(void); void rtc_init(void) { - RCC_OscInitTypeDef RCC_OscInitStruct; - RCC_PeriphCLKInitTypeDef PeriphClkInitStruct; + RCC_OscInitTypeDef RCC_OscInitStruct = {0}; + RCC_PeriphCLKInitTypeDef PeriphClkInitStruct = {0}; // Enable access to Backup domain HAL_PWR_EnableBkUpAccess(); @@ -162,7 +162,7 @@ void rtc_free(void) #endif // Disable LSI and LSE clocks - RCC_OscInitTypeDef RCC_OscInitStruct; + RCC_OscInitTypeDef RCC_OscInitStruct = {0}; RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_LSI | RCC_OSCILLATORTYPE_LSE; RCC_OscInitStruct.PLL.PLLState = RCC_PLL_NONE; RCC_OscInitStruct.LSIState = RCC_LSI_OFF; @@ -217,8 +217,8 @@ It is then not a problem to not use shifts. time_t rtc_read(void) { - RTC_DateTypeDef dateStruct; - RTC_TimeTypeDef timeStruct; + RTC_DateTypeDef dateStruct = {0}; + RTC_TimeTypeDef timeStruct = {0}; struct tm timeinfo; RtcHandle.Instance = RTC; @@ -247,8 +247,8 @@ time_t rtc_read(void) void rtc_write(time_t t) { - RTC_DateTypeDef dateStruct; - RTC_TimeTypeDef timeStruct; + RTC_DateTypeDef dateStruct = {0}; + RTC_TimeTypeDef timeStruct = {0}; RtcHandle.Instance = RTC; From 992722df2ac6cc9d91631f6050b8496d10d45a9a Mon Sep 17 00:00:00 2001 From: bcostm Date: Tue, 10 Oct 2017 16:42:08 +0200 Subject: [PATCH 2/2] Initialize State variable --- targets/TARGET_STM/rtc_api.c | 1 + 1 file changed, 1 insertion(+) diff --git a/targets/TARGET_STM/rtc_api.c b/targets/TARGET_STM/rtc_api.c index 3be15602c6..fe6239177e 100644 --- a/targets/TARGET_STM/rtc_api.c +++ b/targets/TARGET_STM/rtc_api.c @@ -64,6 +64,7 @@ void rtc_init(void) HAL_PWR_EnableBkUpAccess(); RtcHandle.Instance = RTC; + RtcHandle.State = HAL_RTC_STATE_RESET; #if !RTC_LSI RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_LSE;