Skip to content

Commit b77627d

Browse files
committed
Update STM32L0 HAL API to support STM32CUBE_L0 v1.5
1 parent ce436d5 commit b77627d

File tree

1 file changed

+24
-14
lines changed
  • libraries/mbed/targets/hal/TARGET_STM/TARGET_STM32L0

1 file changed

+24
-14
lines changed

libraries/mbed/targets/hal/TARGET_STM/TARGET_STM32L0/rtc_api.c

Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ static RTC_HandleTypeDef RtcHandle;
4242
void rtc_init(void)
4343
{
4444
RCC_OscInitTypeDef RCC_OscInitStruct;
45+
RCC_PeriphCLKInitTypeDef PeriphClkInitStruct;
4546
uint32_t rtc_freq = 0;
4647

4748
#if DEVICE_RTC_LSI
@@ -51,26 +52,30 @@ void rtc_init(void)
5152

5253
RtcHandle.Instance = RTC;
5354

55+
// Note : Due to a change inside stm32l0xx_hal_rcc.c (v1.2 to v1.5) the bit DBP of the register
56+
// PWR_CR is now reset by the fonction HAL_RCC_OscConfig().
57+
// Enable Power clock
58+
__PWR_CLK_ENABLE();
59+
60+
// Enable access to Backup domain
61+
HAL_PWR_EnableBkUpAccess();
62+
5463
#if !DEVICE_RTC_LSI
5564
// Enable LSE Oscillator
5665
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_LSE;
5766
RCC_OscInitStruct.PLL.PLLState = RCC_PLL_NONE; // Mandatory, otherwise the PLL is reconfigured!
5867
RCC_OscInitStruct.LSEState = RCC_LSE_ON; // External 32.768 kHz clock on OSC_IN/OSC_OUT
59-
if (HAL_RCC_OscConfig(&RCC_OscInitStruct) == HAL_OK) {
60-
// Connect LSE to RTC
61-
__HAL_RCC_RTC_CLKPRESCALER(RCC_RTCCLKSOURCE_LSE);
62-
__HAL_RCC_RTC_CONFIG(RCC_RTCCLKSOURCE_LSE);
63-
rtc_freq = LSE_VALUE;
64-
} else {
68+
if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK) {
6569
error("Cannot initialize RTC with LSE\n");
6670
}
71+
// Connect LSE to RTC
72+
PeriphClkInitStruct.PeriphClockSelection = RCC_PERIPHCLK_RTC;
73+
PeriphClkInitStruct.RTCClockSelection = RCC_RTCCLKSOURCE_LSE;
74+
if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInitStruct) != HAL_OK) {
75+
error("Cannot initialize RTC with LSI\n");
76+
}
77+
rtc_freq = LSE_VALUE;
6778
#else
68-
// Enable Power clock
69-
__PWR_CLK_ENABLE();
70-
71-
// Enable access to Backup domain
72-
HAL_PWR_EnableBkUpAccess();
73-
7479
// Reset Backup domain
7580
__HAL_RCC_BACKUPRESET_FORCE();
7681
__HAL_RCC_BACKUPRESET_RELEASE();
@@ -84,8 +89,11 @@ void rtc_init(void)
8489
error("RTC error: LSI clock initialization failed.");
8590
}
8691
// Connect LSI to RTC
87-
__HAL_RCC_RTC_CLKPRESCALER(RCC_RTCCLKSOURCE_LSI);
88-
__HAL_RCC_RTC_CONFIG(RCC_RTCCLKSOURCE_LSI);
92+
PeriphClkInitStruct.PeriphClockSelection = RCC_PERIPHCLK_RTC;
93+
PeriphClkInitStruct.RTCClockSelection = RCC_RTCCLKSOURCE_LSI;
94+
if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInitStruct) != HAL_OK) {
95+
error("Cannot initialize RTC with LSI\n");
96+
}
8997
// This value is LSI typical value. To be measured precisely using a timer input capture for example.
9098
rtc_freq = 38000;
9199
#endif
@@ -186,6 +194,8 @@ time_t rtc_read(void)
186194
timeinfo.tm_hour = timeStruct.Hours;
187195
timeinfo.tm_min = timeStruct.Minutes;
188196
timeinfo.tm_sec = timeStruct.Seconds;
197+
// Daylight Saving Time information is not available
198+
timeinfo.tm_isdst = -1;
189199

190200
// Convert to timestamp
191201
time_t t = mktime(&timeinfo);

0 commit comments

Comments
 (0)