diff --git a/targets/TARGET_STM/rtc_api.c b/targets/TARGET_STM/rtc_api.c index ab3087df6d..eea48c02ae 100644 --- a/targets/TARGET_STM/rtc_api.c +++ b/targets/TARGET_STM/rtc_api.c @@ -55,8 +55,13 @@ void rtc_init(void) RCC_PeriphCLKInitTypeDef PeriphClkInitStruct = {0}; // Enable access to Backup domain + __HAL_RCC_PWR_CLK_ENABLE(); HAL_PWR_EnableBkUpAccess(); + if (rtc_isenabled()) { + return; + } + #if !RTC_LSI /* => LSE */ RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_LSE; RCC_OscInitStruct.PLL.PLLState = RCC_PLL_NONE; // Mandatory, otherwise the PLL is reconfigured! @@ -76,12 +81,7 @@ void rtc_init(void) error("PeriphClkInitStruct RTC failed with LSE\n"); } - if (rtc_isenabled()) return; #else /* => RTC_LSI */ - if (rtc_isenabled()) return; - - __HAL_RCC_PWR_CLK_ENABLE(); - // Reset Backup domain __HAL_RCC_BACKUPRESET_FORCE(); __HAL_RCC_BACKUPRESET_RELEASE();