Skip to content

Commit

Permalink
[XXX_L15XX] Move erasing of BkUpR in RTC API
Browse files Browse the repository at this point in the history
the erasing of back up register is only needed when using LSI
  • Loading branch information
dbestm authored and 0xc0170 committed Apr 4, 2016
1 parent c90b7f8 commit 76649d8
Showing 1 changed file with 12 additions and 10 deletions.
22 changes: 12 additions & 10 deletions libraries/mbed/targets/hal/TARGET_STM/TARGET_STM32L1/rtc_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -51,16 +51,6 @@ void rtc_init(void)

RtcHandle.Instance = RTC;

// Enable Power clock
__PWR_CLK_ENABLE();

// Enable access to Backup domain
HAL_PWR_EnableBkUpAccess();

// Reset Backup domain
__HAL_RCC_BACKUPRESET_FORCE();
__HAL_RCC_BACKUPRESET_RELEASE();

#if !DEVICE_RTC_LSI
// Enable LSE Oscillator
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_LSI | RCC_OSCILLATORTYPE_LSE;
Expand All @@ -76,6 +66,16 @@ void rtc_init(void)
error("Cannot initialize RTC with LSE\n");
}
#else
// Enable Power clock
__PWR_CLK_ENABLE();

// Enable access to Backup domain
HAL_PWR_EnableBkUpAccess();

// Reset Backup domain
__HAL_RCC_BACKUPRESET_FORCE();
__HAL_RCC_BACKUPRESET_RELEASE();

// Enable LSI clock
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_LSI | RCC_OSCILLATORTYPE_LSE;
RCC_OscInitStruct.PLL.PLLState = RCC_PLL_NONE; // Mandatory, otherwise the PLL is reconfigured!
Expand Down Expand Up @@ -114,6 +114,7 @@ void rtc_init(void)

void rtc_free(void)
{
#if DEVICE_RTC_LSI
// Enable Power clock
__PWR_CLK_ENABLE();

Expand All @@ -126,6 +127,7 @@ void rtc_free(void)

// Disable access to Backup domain
HAL_PWR_DisableBkUpAccess();
#endif

// Disable LSI and LSE clocks
RCC_OscInitTypeDef RCC_OscInitStruct;
Expand Down

0 comments on commit 76649d8

Please sign in to comment.