From 526bbcdc3ee6e92495d4170baf1b2872e40410d8 Mon Sep 17 00:00:00 2001 From: adustm Date: Mon, 11 Jan 2016 18:11:19 +0100 Subject: [PATCH] [STM all] Fix #1480: change location of check for RTC already initialised Need to keep PWR_CLK_ENABLE and LSE LSI oscillator configuration. Just skip the HAL_RTC_Init in case INITS flag is already set. --- .../mbed/targets/hal/TARGET_STM/TARGET_STM32F0/rtc_api.c | 6 +++--- .../mbed/targets/hal/TARGET_STM/TARGET_STM32F3/rtc_api.c | 6 +++--- .../mbed/targets/hal/TARGET_STM/TARGET_STM32F4/rtc_api.c | 6 +++--- .../mbed/targets/hal/TARGET_STM/TARGET_STM32F7/rtc_api.c | 4 ++-- .../TARGET_STM/TARGET_STM32L0/TARGET_DISCO_L053C8/rtc_api.c | 6 +++--- .../TARGET_STM32L0/TARGET_NUCLEO_L053R8/rtc_api.c | 6 +++--- .../TARGET_STM32L0/TARGET_NUCLEO_L073RZ/rtc_api.c | 6 +++--- .../mbed/targets/hal/TARGET_STM/TARGET_STM32L1/rtc_api.c | 6 +++--- .../mbed/targets/hal/TARGET_STM/TARGET_STM32L4/rtc_api.c | 6 +++--- 9 files changed, 26 insertions(+), 26 deletions(-) diff --git a/libraries/mbed/targets/hal/TARGET_STM/TARGET_STM32F0/rtc_api.c b/libraries/mbed/targets/hal/TARGET_STM/TARGET_STM32F0/rtc_api.c index 37b9a160066..9de355c1de7 100644 --- a/libraries/mbed/targets/hal/TARGET_STM/TARGET_STM32F0/rtc_api.c +++ b/libraries/mbed/targets/hal/TARGET_STM/TARGET_STM32F0/rtc_api.c @@ -45,9 +45,6 @@ void rtc_init(void) { rtc_inited = 1; RtcHandle.Instance = RTC; - - // Check if RTC is already initialized - if ((RTC->ISR & RTC_ISR_INITS) == RTC_ISR_INITS) return; // Enable Power clock __PWR_CLK_ENABLE(); @@ -82,6 +79,9 @@ void rtc_init(void) { rtc_freq = LSI_VALUE; } + // Check if RTC is already initialized + if ((RTC->ISR & RTC_ISR_INITS) == RTC_ISR_INITS) return; + // Enable RTC __HAL_RCC_RTC_ENABLE(); diff --git a/libraries/mbed/targets/hal/TARGET_STM/TARGET_STM32F3/rtc_api.c b/libraries/mbed/targets/hal/TARGET_STM/TARGET_STM32F3/rtc_api.c index 489f95219ad..a848fd517cb 100644 --- a/libraries/mbed/targets/hal/TARGET_STM/TARGET_STM32F3/rtc_api.c +++ b/libraries/mbed/targets/hal/TARGET_STM/TARGET_STM32F3/rtc_api.c @@ -46,9 +46,6 @@ void rtc_init(void) rtc_inited = 1; RtcHandle.Instance = RTC; - - // Check if RTC is already initialized - if ((RTC->ISR & RTC_ISR_INITS) == RTC_ISR_INITS) return; // Enable Power clock __PWR_CLK_ENABLE(); @@ -83,6 +80,9 @@ void rtc_init(void) rtc_freq = LSI_VALUE; } + // Check if RTC is already initialized + if ((RTC->ISR & RTC_ISR_INITS) == RTC_ISR_INITS) return; + // Enable RTC __HAL_RCC_RTC_ENABLE(); diff --git a/libraries/mbed/targets/hal/TARGET_STM/TARGET_STM32F4/rtc_api.c b/libraries/mbed/targets/hal/TARGET_STM/TARGET_STM32F4/rtc_api.c index 36bcbdb31ad..36d5184b9b1 100644 --- a/libraries/mbed/targets/hal/TARGET_STM/TARGET_STM32F4/rtc_api.c +++ b/libraries/mbed/targets/hal/TARGET_STM/TARGET_STM32F4/rtc_api.c @@ -46,9 +46,6 @@ void rtc_init(void) rtc_inited = 1; RtcHandle.Instance = RTC; - - // Check if RTC is already initialized - if ((RTC->ISR & RTC_ISR_INITS) == RTC_ISR_INITS) return; // Enable Power clock __PWR_CLK_ENABLE(); @@ -85,6 +82,9 @@ void rtc_init(void) rtc_freq = LSI_VALUE; } + // Check if RTC is already initialized + if ((RTC->ISR & RTC_ISR_INITS) == RTC_ISR_INITS) return; + // Enable RTC __HAL_RCC_RTC_ENABLE(); diff --git a/libraries/mbed/targets/hal/TARGET_STM/TARGET_STM32F7/rtc_api.c b/libraries/mbed/targets/hal/TARGET_STM/TARGET_STM32F7/rtc_api.c index a634594586d..d25acb860fd 100644 --- a/libraries/mbed/targets/hal/TARGET_STM/TARGET_STM32F7/rtc_api.c +++ b/libraries/mbed/targets/hal/TARGET_STM/TARGET_STM32F7/rtc_api.c @@ -40,8 +40,6 @@ void rtc_init(void) RCC_OscInitTypeDef RCC_OscInitStruct; uint32_t rtc_freq = 0; - if((RTC->ISR & RTC_ISR_INITS) == RTC_ISR_INITS) { // RTC initialization and status register (RTC_ISR), cold start (with no backup domain power) RTC reset value - RtcHandle.Instance = RTC; // Enable Power clock @@ -79,6 +77,8 @@ void rtc_init(void) rtc_freq = LSI_VALUE; } + if((RTC->ISR & RTC_ISR_INITS) == RTC_ISR_INITS) { // RTC initialization and status register (RTC_ISR), cold start (with no backup domain power) RTC reset value + // Enable RTC __HAL_RCC_RTC_ENABLE(); diff --git a/libraries/mbed/targets/hal/TARGET_STM/TARGET_STM32L0/TARGET_DISCO_L053C8/rtc_api.c b/libraries/mbed/targets/hal/TARGET_STM/TARGET_STM32L0/TARGET_DISCO_L053C8/rtc_api.c index f118e1fa8b3..cc3dc8c0393 100644 --- a/libraries/mbed/targets/hal/TARGET_STM/TARGET_STM32L0/TARGET_DISCO_L053C8/rtc_api.c +++ b/libraries/mbed/targets/hal/TARGET_STM/TARGET_STM32L0/TARGET_DISCO_L053C8/rtc_api.c @@ -54,9 +54,6 @@ void rtc_init(void) rtc_inited = 1; RtcHandle.Instance = RTC; - - // Check if RTC is already initialized - if ((RTC->ISR & RTC_ISR_INITS) == RTC_ISR_INITS) return; // Enable Power clock __PWR_CLK_ENABLE(); @@ -97,6 +94,9 @@ void rtc_init(void) } #endif + // Check if RTC is already initialized + if ((RTC->ISR & RTC_ISR_INITS) == RTC_ISR_INITS) return; + // Enable RTC __HAL_RCC_RTC_ENABLE(); diff --git a/libraries/mbed/targets/hal/TARGET_STM/TARGET_STM32L0/TARGET_NUCLEO_L053R8/rtc_api.c b/libraries/mbed/targets/hal/TARGET_STM/TARGET_STM32L0/TARGET_NUCLEO_L053R8/rtc_api.c index 592b0d0005d..ab71bf586b4 100644 --- a/libraries/mbed/targets/hal/TARGET_STM/TARGET_STM32L0/TARGET_NUCLEO_L053R8/rtc_api.c +++ b/libraries/mbed/targets/hal/TARGET_STM/TARGET_STM32L0/TARGET_NUCLEO_L053R8/rtc_api.c @@ -46,9 +46,6 @@ void rtc_init(void) rtc_inited = 1; RtcHandle.Instance = RTC; - - // Check if RTC is already initialized - if ((RTC->ISR & RTC_ISR_INITS) == RTC_ISR_INITS) return; // Enable Power clock __PWR_CLK_ENABLE(); @@ -85,6 +82,9 @@ void rtc_init(void) rtc_freq = 32000; } + // Check if RTC is already initialized + if ((RTC->ISR & RTC_ISR_INITS) == RTC_ISR_INITS) return; + // Enable RTC __HAL_RCC_RTC_ENABLE(); diff --git a/libraries/mbed/targets/hal/TARGET_STM/TARGET_STM32L0/TARGET_NUCLEO_L073RZ/rtc_api.c b/libraries/mbed/targets/hal/TARGET_STM/TARGET_STM32L0/TARGET_NUCLEO_L073RZ/rtc_api.c index 592b0d0005d..ab71bf586b4 100644 --- a/libraries/mbed/targets/hal/TARGET_STM/TARGET_STM32L0/TARGET_NUCLEO_L073RZ/rtc_api.c +++ b/libraries/mbed/targets/hal/TARGET_STM/TARGET_STM32L0/TARGET_NUCLEO_L073RZ/rtc_api.c @@ -46,9 +46,6 @@ void rtc_init(void) rtc_inited = 1; RtcHandle.Instance = RTC; - - // Check if RTC is already initialized - if ((RTC->ISR & RTC_ISR_INITS) == RTC_ISR_INITS) return; // Enable Power clock __PWR_CLK_ENABLE(); @@ -85,6 +82,9 @@ void rtc_init(void) rtc_freq = 32000; } + // Check if RTC is already initialized + if ((RTC->ISR & RTC_ISR_INITS) == RTC_ISR_INITS) return; + // Enable RTC __HAL_RCC_RTC_ENABLE(); diff --git a/libraries/mbed/targets/hal/TARGET_STM/TARGET_STM32L1/rtc_api.c b/libraries/mbed/targets/hal/TARGET_STM/TARGET_STM32L1/rtc_api.c index f67e691090b..b53fcbf809a 100755 --- a/libraries/mbed/targets/hal/TARGET_STM/TARGET_STM32L1/rtc_api.c +++ b/libraries/mbed/targets/hal/TARGET_STM/TARGET_STM32L1/rtc_api.c @@ -46,9 +46,6 @@ void rtc_init(void) rtc_inited = 1; RtcHandle.Instance = RTC; - - // Check if RTC is already initialized - if ((RTC->ISR & RTC_ISR_INITS) == RTC_ISR_INITS) return; // Enable Power clock __PWR_CLK_ENABLE(); @@ -85,6 +82,9 @@ void rtc_init(void) rtc_freq = 40000; } + // Check if RTC is already initialized + if ((RTC->ISR & RTC_ISR_INITS) == RTC_ISR_INITS) return; + // Enable RTC __HAL_RCC_RTC_ENABLE(); diff --git a/libraries/mbed/targets/hal/TARGET_STM/TARGET_STM32L4/rtc_api.c b/libraries/mbed/targets/hal/TARGET_STM/TARGET_STM32L4/rtc_api.c index 89f3f1bab9f..61dfd2bb5e4 100644 --- a/libraries/mbed/targets/hal/TARGET_STM/TARGET_STM32L4/rtc_api.c +++ b/libraries/mbed/targets/hal/TARGET_STM/TARGET_STM32L4/rtc_api.c @@ -48,9 +48,6 @@ void rtc_init(void) RtcHandle.Instance = RTC; - // Check if RTC is already initialized - if ((RTC->ISR & RTC_ISR_INITS) == RTC_ISR_INITS) return; - // Enable Power clock __HAL_RCC_PWR_CLK_ENABLE(); @@ -91,6 +88,9 @@ void rtc_init(void) rtc_freq = 40000; } + // Check if RTC is already initialized + if ((RTC->ISR & RTC_ISR_INITS) == RTC_ISR_INITS) return; + // Enable RTC __HAL_RCC_RTC_ENABLE();