diff --git a/cores/arduino/board.h b/cores/arduino/board.h
index 194f4ebd7a..3ca81179e2 100644
--- a/cores/arduino/board.h
+++ b/cores/arduino/board.h
@@ -14,6 +14,7 @@ extern "C"{
#include "digital_io.h"
#include "hal_uart_emul.h"
#include "hw_config.h"
+#include "rtc.h"
#include "spi_com.h"
#include "stm32_eeprom.h"
#include "timer.h"
diff --git a/cores/arduino/stm32/rtc.c b/cores/arduino/stm32/rtc.c
new file mode 100644
index 0000000000..b5b97c6a05
--- /dev/null
+++ b/cores/arduino/stm32/rtc.c
@@ -0,0 +1,702 @@
+/**
+ ******************************************************************************
+ * @file rtc.c
+ * @author WI6LABS
+ * @version V1.0.0
+ * @date 12-December-2017
+ * @brief Provides a RTC driver
+ *
+ ******************************************************************************
+ * @attention
+ *
+ *
© COPYRIGHT(c) 2017 STMicroelectronics
+ *
+ * Redistribution and use in source and binary forms, with or without modification,
+ * are permitted provided that the following conditions are met:
+ * 1. Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ * 3. Neither the name of STMicroelectronics nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ ******************************************************************************
+ */
+
+#include "rtc.h"
+
+#ifdef HAL_RTC_MODULE_ENABLED
+
+#ifdef __cplusplus
+ extern "C" {
+#endif
+
+/* Private define ------------------------------------------------------------*/
+/* Private macro -------------------------------------------------------------*/
+/* Private variables ---------------------------------------------------------*/
+static RTC_HandleTypeDef RtcHandle = {0};
+static voidCallbackPtr RTCUserCallback = NULL;
+static void *callbackUserData = NULL;
+
+static int8_t AsynchPrediv = -1; // 1 to 127
+static int16_t SynchPrediv = -1; // 0 to 32767
+
+static hourFormat_t initFormat = HOUR_FORMAT_12;
+
+/* Private function prototypes -----------------------------------------------*/
+static void RTC_setClock(sourceClock_t source);
+static void RTC_getPrediv(uint32_t *asynch, uint32_t *synch);
+
+/* Exported functions --------------------------------------------------------*/
+
+/**
+ * @brief RTC clock initialization
+ * This function configures the hardware resources used.
+ * @param source: RTC clock source: LSE, LSI or HSE
+ * @note Care must be taken when HAL_RCCEx_PeriphCLKConfig() is used to select
+ * the RTC clock source; in this case the Backup domain will be reset in
+ * order to modify the RTC Clock source, as consequence RTC registers (including
+ * the backup registers) and RCC_CSR register are set to their reset values.
+ * @retval None
+ */
+static void RTC_setClock(sourceClock_t source)
+{
+ RCC_OscInitTypeDef RCC_OscInitStruct;
+ RCC_PeriphCLKInitTypeDef PeriphClkInit;
+
+ if(source == LSE_CLOCK) {
+ // Enable the clock if not already set by user.
+ if(__HAL_RCC_GET_FLAG(RCC_FLAG_LSERDY) == RESET) {
+#ifdef __HAL_RCC_LSEDRIVE_CONFIG
+ __HAL_RCC_LSEDRIVE_CONFIG(RCC_LSEDRIVE_LOW);
+#endif
+ RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_LSE;
+ RCC_OscInitStruct.PLL.PLLState = RCC_PLL_NONE;
+ RCC_OscInitStruct.LSEState = RCC_LSE_ON;
+ if(HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK) {
+ Error_Handler();
+ }
+ }
+
+ PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_RTC;
+ PeriphClkInit.RTCClockSelection = RCC_RTCCLKSOURCE_LSE;
+ if(HAL_RCCEx_PeriphCLKConfig(&PeriphClkInit) != HAL_OK) {
+ Error_Handler();
+ }
+ } else if(source == HSE_CLOCK) {
+ // Enable the clock if not already set by user.
+ if(__HAL_RCC_GET_FLAG(RCC_FLAG_HSERDY) == RESET) {
+ RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE;
+ RCC_OscInitStruct.PLL.PLLState = RCC_PLL_NONE;
+ RCC_OscInitStruct.HSEState = RCC_HSE_ON;
+ if(HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK) {
+ Error_Handler();
+ }
+ }
+
+ PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_RTC;
+#if defined(STM32F1xx)
+ PeriphClkInit.RTCClockSelection = RCC_RTCCLKSOURCE_HSE_DIV128;
+#elif defined(STM32L4xx) || defined(STM32F0xx) || defined(STM32F3xx)
+ PeriphClkInit.RTCClockSelection = RCC_RTCCLKSOURCE_HSE_DIV32;
+#else
+ PeriphClkInit.RTCClockSelection = RCC_RTCCLKSOURCE_HSE_DIV8;
+#endif
+ if(HAL_RCCEx_PeriphCLKConfig(&PeriphClkInit) != HAL_OK) {
+ Error_Handler();
+ }
+ } else {
+ // Enable the clock if not already set by user.
+ if(__HAL_RCC_GET_FLAG(RCC_FLAG_LSIRDY) == RESET) {
+ RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_LSI;
+ RCC_OscInitStruct.PLL.PLLState = RCC_PLL_NONE;
+ RCC_OscInitStruct.LSIState = RCC_LSI_ON;
+ if(HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK) {
+ Error_Handler();
+ }
+ }
+
+ PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_RTC;
+ PeriphClkInit.RTCClockSelection = RCC_RTCCLKSOURCE_LSI;
+ if(HAL_RCCEx_PeriphCLKConfig(&PeriphClkInit) != HAL_OK) {
+ Error_Handler();
+ }
+ }
+
+ __HAL_RCC_RTC_ENABLE();
+}
+
+/**
+ * @brief RTC_setPrediv
+ * Allow to user to set manually the prescaler values.
+ * @param Asynch: asynchronous prescaler value in range 1 - 127
+ * @param Synch: synchronous prescaler value in range 0 - 32767
+ * @retval None
+ */
+void RTC_setPrediv(int8_t Asynch, int16_t Synch)
+{
+ if((Asynch >= 1) && (Synch >= 0)) {
+ AsynchPrediv = Asynch;
+ SynchPrediv = Synch;
+ }
+}
+
+/**
+ * @brief RTC_getPrediv
+ * RTC prescalers are set to obtain the RTC clock to 1Hz. See AN4759.
+ * @param asynch: pointer where return asynchronous prescaler value.
+ * @param synch: pointer where return synchronous prescaler value.
+ * @retval None
+ */
+static void RTC_getPrediv(uint32_t *asynch, uint32_t *synch)
+{
+ uint32_t predivA;
+ uint32_t predivS;
+ uint32_t clk = 0;
+
+ if((asynch == NULL) || (synch == NULL)) {
+ return;
+ }
+
+ // Get user predividers if manually configured
+ if((AsynchPrediv > 0) && (SynchPrediv > 0)) {
+ *asynch = AsynchPrediv;
+ *synch = SynchPrediv;
+ return;
+ }
+
+ // Get clock frequency
+ if(__HAL_RCC_GET_RTC_SOURCE() == RCC_RTCCLKSOURCE_LSE) {
+ clk = LSE_VALUE;
+ }
+ #ifdef RCC_RTCCLKSOURCE_HSE_DIV2
+ else if(__HAL_RCC_GET_RTC_SOURCE() == RCC_RTCCLKSOURCE_HSE_DIV2) {
+ clk = HSE_VALUE / 2;
+ }
+ #endif
+ #ifdef RCC_RTCCLKSOURCE_HSE_DIV3
+ else if(__HAL_RCC_GET_RTC_SOURCE() == RCC_RTCCLKSOURCE_HSE_DIV3) {
+ clk = HSE_VALUE / 3;
+ }
+ #endif
+ #ifdef RCC_RTCCLKSOURCE_HSE_DIV4
+ else if(__HAL_RCC_GET_RTC_SOURCE() == RCC_RTCCLKSOURCE_HSE_DIV4) {
+ clk = HSE_VALUE / 4;
+ }
+ #endif
+ #ifdef RCC_RTCCLKSOURCE_HSE_DIV5
+ else if(__HAL_RCC_GET_RTC_SOURCE() == RCC_RTCCLKSOURCE_HSE_DIV5) {
+ clk = HSE_VALUE / 5;
+ }
+ #endif
+ #ifdef RCC_RTCCLKSOURCE_HSE_DIV6
+ else if(__HAL_RCC_GET_RTC_SOURCE() == RCC_RTCCLKSOURCE_HSE_DIV6) {
+ clk = HSE_VALUE / 6;
+ }
+ #endif
+ #ifdef RCC_RTCCLKSOURCE_HSE_DIV7
+ else if(__HAL_RCC_GET_RTC_SOURCE() == RCC_RTCCLKSOURCE_HSE_DIV7) {
+ clk = HSE_VALUE / 7;
+ }
+ #endif
+ #ifdef RCC_RTCCLKSOURCE_HSE_DIV8
+ else if(__HAL_RCC_GET_RTC_SOURCE() == RCC_RTCCLKSOURCE_HSE_DIV8) {
+ clk = HSE_VALUE / 8;
+ }
+ #endif
+ #ifdef RCC_RTCCLKSOURCE_HSE_DIV9
+ else if(__HAL_RCC_GET_RTC_SOURCE() == RCC_RTCCLKSOURCE_HSE_DIV9) {
+ clk = HSE_VALUE / 9;
+ }
+ #endif
+ #ifdef RCC_RTCCLKSOURCE_HSE_DIV10
+ else if(__HAL_RCC_GET_RTC_SOURCE() == RCC_RTCCLKSOURCE_HSE_DIV10) {
+ clk = HSE_VALUE / 10;
+ }
+ #endif
+ #ifdef RCC_RTCCLKSOURCE_HSE_DIV11
+ else if(__HAL_RCC_GET_RTC_SOURCE() == RCC_RTCCLKSOURCE_HSE_DIV11) {
+ clk = HSE_VALUE / 11;
+ }
+ #endif
+ #ifdef RCC_RTCCLKSOURCE_HSE_DIV12
+ else if(__HAL_RCC_GET_RTC_SOURCE() == RCC_RTCCLKSOURCE_HSE_DIV12) {
+ clk = HSE_VALUE / 12;
+ }
+ #endif
+ #ifdef RCC_RTCCLKSOURCE_HSE_DIV13
+ else if(__HAL_RCC_GET_RTC_SOURCE() == RCC_RTCCLKSOURCE_HSE_DIV13) {
+ clk = HSE_VALUE / 13;
+ }
+ #endif
+ #ifdef RCC_RTCCLKSOURCE_HSE_DIV14
+ else if(__HAL_RCC_GET_RTC_SOURCE() == RCC_RTCCLKSOURCE_HSE_DIV14) {
+ clk = HSE_VALUE / 14;
+ }
+ #endif
+ #ifdef RCC_RTCCLKSOURCE_HSE_DIV15
+ else if(__HAL_RCC_GET_RTC_SOURCE() == RCC_RTCCLKSOURCE_HSE_DIV15) {
+ clk = HSE_VALUE / 15;
+ }
+ #endif
+ #ifdef RCC_RTCCLKSOURCE_HSE_DIV16
+ else if(__HAL_RCC_GET_RTC_SOURCE() == RCC_RTCCLKSOURCE_HSE_DIV16) {
+ clk = HSE_VALUE / 16;
+ }
+ #endif
+ #ifdef RCC_RTCCLKSOURCE_HSE_DIV17
+ else if(__HAL_RCC_GET_RTC_SOURCE() == RCC_RTCCLKSOURCE_HSE_DIV17) {
+ clk = HSE_VALUE / 17;
+ }
+ #endif
+ #ifdef RCC_RTCCLKSOURCE_HSE_DIV18
+ else if(__HAL_RCC_GET_RTC_SOURCE() == RCC_RTCCLKSOURCE_HSE_DIV18) {
+ clk = HSE_VALUE / 18;
+ }
+ #endif
+ #ifdef RCC_RTCCLKSOURCE_HSE_DIV19
+ else if(__HAL_RCC_GET_RTC_SOURCE() == RCC_RTCCLKSOURCE_HSE_DIV19) {
+ clk = HSE_VALUE / 19;
+ }
+ #endif
+ #ifdef RCC_RTCCLKSOURCE_HSE_DIV20
+ else if(__HAL_RCC_GET_RTC_SOURCE() == RCC_RTCCLKSOURCE_HSE_DIV20) {
+ clk = HSE_VALUE / 20;
+ }
+ #endif
+ #ifdef RCC_RTCCLKSOURCE_HSE_DIV21
+ else if(__HAL_RCC_GET_RTC_SOURCE() == RCC_RTCCLKSOURCE_HSE_DIV21) {
+ clk = HSE_VALUE / 21;
+ }
+ #endif
+ #ifdef RCC_RTCCLKSOURCE_HSE_DIV22
+ else if(__HAL_RCC_GET_RTC_SOURCE() == RCC_RTCCLKSOURCE_HSE_DIV22) {
+ clk = HSE_VALUE / 22;
+ }
+ #endif
+ #ifdef RCC_RTCCLKSOURCE_HSE_DIV23
+ else if(__HAL_RCC_GET_RTC_SOURCE() == RCC_RTCCLKSOURCE_HSE_DIV23) {
+ clk = HSE_VALUE / 23;
+ }
+ #endif
+ #ifdef RCC_RTCCLKSOURCE_HSE_DIV24
+ else if(__HAL_RCC_GET_RTC_SOURCE() == RCC_RTCCLKSOURCE_HSE_DIV24) {
+ clk = HSE_VALUE / 24;
+ }
+ #endif
+ #ifdef RCC_RTCCLKSOURCE_HSE_DIV25
+ else if(__HAL_RCC_GET_RTC_SOURCE() == RCC_RTCCLKSOURCE_HSE_DIV25) {
+ clk = HSE_VALUE / 25;
+ }
+ #endif
+ #ifdef RCC_RTCCLKSOURCE_HSE_DIV26
+ else if(__HAL_RCC_GET_RTC_SOURCE() == RCC_RTCCLKSOURCE_HSE_DIV26) {
+ clk = HSE_VALUE / 26;
+ }
+ #endif
+ #ifdef RCC_RTCCLKSOURCE_HSE_DIV27
+ else if(__HAL_RCC_GET_RTC_SOURCE() == RCC_RTCCLKSOURCE_HSE_DIV27) {
+ clk = HSE_VALUE / 27;
+ }
+ #endif
+ #ifdef RCC_RTCCLKSOURCE_HSE_DIV28
+ else if(__HAL_RCC_GET_RTC_SOURCE() == RCC_RTCCLKSOURCE_HSE_DIV28) {
+ clk = HSE_VALUE / 28;
+ }
+ #endif
+ #ifdef RCC_RTCCLKSOURCE_HSE_DIV29
+ else if(__HAL_RCC_GET_RTC_SOURCE() == RCC_RTCCLKSOURCE_HSE_DIV29) {
+ clk = HSE_VALUE / 29;
+ }
+ #endif
+ #ifdef RCC_RTCCLKSOURCE_HSE_DIV30
+ else if(__HAL_RCC_GET_RTC_SOURCE() == RCC_RTCCLKSOURCE_HSE_DIV30) {
+ clk = HSE_VALUE / 30;
+ }
+ #endif
+ #ifdef RCC_RTCCLKSOURCE_HSE_DIV31
+ else if(__HAL_RCC_GET_RTC_SOURCE() == RCC_RTCCLKSOURCE_HSE_DIV31) {
+ clk = HSE_VALUE / 31;
+ }
+ #endif
+ #ifdef RCC_RTCCLKSOURCE_HSE_DIV32
+ else if(__HAL_RCC_GET_RTC_SOURCE() == RCC_RTCCLKSOURCE_HSE_DIV32) {
+ clk = HSE_VALUE / 32;
+ }
+ #endif
+ else {
+ clk = LSI_VALUE;
+ }
+
+ // Get prescalers
+ if(clk > 0) {
+ for(predivA = 128; predivA > 1; predivA--) {
+ predivS = clk / predivA;
+ if((predivS <= 32768) && ((predivS * predivA) == clk)) {
+ *asynch = predivA - 1;
+ *synch = predivS - 1;
+ break;
+ }
+ }
+ }
+}
+
+/**
+ * @brief RTC Initialization
+ * This function configures the RTC time and calendar. By default, the
+ * RTC is set to the 1st January 2017 0:0:0:00
+ * @param format: enable the RTC in 12 or 24 hours mode
+ * @retval None
+ */
+void RTC_init(hourFormat_t format, sourceClock_t source)
+{
+ initFormat = format;
+
+ // Set RTC clock
+ RTC_setClock(source);
+
+ RtcHandle.Instance = RTC;
+
+#if defined(STM32F1xx)
+ RtcHandle.Init.AsynchPrediv = RTC_AUTO_1_SECOND; //Leave HAL calculate the prescaler
+ RtcHandle.Init.OutPut = RTC_OUTPUTSOURCE_NONE;
+ UNUSED(format);
+#else
+ if(format == HOUR_FORMAT_12) {
+ RtcHandle.Init.HourFormat = RTC_HOURFORMAT_12;
+ } else {
+ RtcHandle.Init.HourFormat = RTC_HOURFORMAT_24;
+ }
+ RtcHandle.Init.OutPut = RTC_OUTPUT_DISABLE;
+ RTC_getPrediv(&(RtcHandle.Init.AsynchPrediv), &(RtcHandle.Init.SynchPrediv));
+#if defined(STM32L0xx) || defined(STM32L4xx)
+ RtcHandle.Init.OutPutRemap = RTC_OUTPUT_REMAP_NONE;
+#endif // defined(STM32L0xx) || defined(STM32L4xx)
+ RtcHandle.Init.OutPutPolarity = RTC_OUTPUT_POLARITY_HIGH;
+ RtcHandle.Init.OutPutType = RTC_OUTPUT_TYPE_OPENDRAIN;
+#endif // defined(STM32F1xx)
+
+ HAL_RTC_Init( &RtcHandle );
+
+ /*Sunday 1st January 2017*/
+ RTC_SetDate(17, 1, 1, 7);
+
+ /*at 0:0:0*/
+ RTC_SetTime(0,0,0,0,AM);
+
+#if !defined(STM32F1xx) && !defined(STM32F2xx)
+ /*Enable Direct Read of the calendar registers (not through Shadow) */
+ HAL_RTCEx_EnableBypassShadow(&RtcHandle);
+#endif // !defined(STM32F1xx) && !defined(STM32F2xx)
+
+ HAL_NVIC_SetPriority(RTC_Alarm_IRQn, 2, 0);
+ HAL_NVIC_EnableIRQ(RTC_Alarm_IRQn);
+}
+
+/**
+ * @brief RTC deinitialization. Stop the RTC.
+ * @retval None
+ */
+void RTC_DeInit(void)
+{
+ HAL_RTC_DeInit(&RtcHandle);
+ RTCUserCallback = NULL;
+ callbackUserData = NULL;
+}
+
+/**
+ * @brief Set RTC time
+ * @param hours: 0-12 or 0-23. Depends on the format used.
+ * @param minutes: 0-59
+ * @param seconds: 0-59
+ * @param subSeconds: 0-999
+ * @param format: select AM or PM format in case RTC is set in 12 hours mode. Else ingored.
+ * @retval None
+ */
+void RTC_SetTime(uint8_t hours, uint8_t minutes, uint8_t seconds, uint32_t subSeconds, hourAM_PM_t format)
+{
+ RTC_TimeTypeDef RTC_TimeStruct;
+
+ // Ignore time AM PM configuration if in 24 hours format
+ if(initFormat == HOUR_FORMAT_24) {
+ format = AM;
+ }
+
+ if((((initFormat == HOUR_FORMAT_24) && IS_RTC_HOUR24(hours)) || IS_RTC_HOUR12(hours))
+ && IS_RTC_MINUTES(minutes) && IS_RTC_SECONDS(seconds)) {
+ RTC_TimeStruct.Hours = hours;
+ RTC_TimeStruct.Minutes = minutes;
+ RTC_TimeStruct.Seconds = seconds;
+#if !defined(STM32F1xx)
+ if(format == PM) {
+ RTC_TimeStruct.TimeFormat = RTC_HOURFORMAT12_PM;
+ } else {
+ RTC_TimeStruct.TimeFormat = RTC_HOURFORMAT12_AM;
+ }
+#if !defined(STM32F2xx) && !defined(STM32L1xx)
+ RTC_TimeStruct.SubSeconds = subSeconds;
+ RTC_TimeStruct.SecondFraction = 0;
+#elif defined(STM32L100xBA) || defined (STM32L151xBA) || defined (STM32L152xBA) || defined(STM32L100xC) || defined (STM32L151xC) || defined (STM32L152xC) || defined (STM32L162xC) || defined(STM32L151xCA) || defined (STM32L151xD) || defined (STM32L152xCA) || defined (STM32L152xD) || defined (STM32L162xCA) || defined (STM32L162xD) || defined(STM32L151xE) || defined(STM32L151xDX) || defined (STM32L152xE) || defined (STM32L152xDX) || defined (STM32L162xE) || defined (STM32L162xDX)
+ RTC_TimeStruct.SubSeconds = subSeconds;
+ RTC_TimeStruct.SecondFraction = 0;
+#else
+ UNUSED(subSeconds);
+#endif //!defined(STM32F2xx) && !defined(STM32L1xx)
+ RTC_TimeStruct.DayLightSaving = RTC_STOREOPERATION_RESET;
+ RTC_TimeStruct.StoreOperation = RTC_DAYLIGHTSAVING_NONE;
+#else
+ UNUSED(subSeconds);
+ UNUSED(format);
+#endif // !defined(STM32F1xx)
+
+ HAL_RTC_SetTime(&RtcHandle , &RTC_TimeStruct, RTC_FORMAT_BIN);
+ }
+}
+
+/**
+ * @brief Get RTC time
+ * @param hours: 0-12 or 0-23. Depends on the format used.
+ * @param minutes: 0-59
+ * @param seconds: 0-59
+ * @param subSeconds: 0-999
+ * @param format: returns AM or PM format in case RTC is set in 12 hours mode.
+ * @retval None
+ */
+void RTC_GetTime(uint8_t *hours, uint8_t *minutes, uint8_t *seconds, uint32_t *subSeconds, hourAM_PM_t *format)
+{
+ RTC_TimeTypeDef RTC_TimeStruct;
+
+ if((hours != NULL) && (minutes != NULL) && (seconds != NULL) && (subSeconds != NULL) && (format != NULL)) {
+ HAL_RTC_GetTime(&RtcHandle , &RTC_TimeStruct, RTC_FORMAT_BIN);
+ *hours = RTC_TimeStruct.Hours;
+ *minutes = RTC_TimeStruct.Minutes;
+ *seconds = RTC_TimeStruct.Seconds;
+#if !defined(STM32F1xx)
+ if(RTC_TimeStruct.TimeFormat == RTC_HOURFORMAT12_PM) {
+ *format = PM;
+ } else {
+ *format = AM;
+ }
+#if !defined(STM32F2xx) && !defined(STM32L1xx)
+ *subSeconds = RTC_TimeStruct.SubSeconds;
+#elif defined(STM32L100xBA) || defined (STM32L151xBA) || defined (STM32L152xBA) || defined(STM32L100xC) || defined (STM32L151xC) || defined (STM32L152xC) || defined (STM32L162xC) || defined(STM32L151xCA) || defined (STM32L151xD) || defined (STM32L152xCA) || defined (STM32L152xD) || defined (STM32L162xCA) || defined (STM32L162xD) || defined(STM32L151xE) || defined(STM32L151xDX) || defined (STM32L152xE) || defined (STM32L152xDX) || defined (STM32L162xE) || defined (STM32L162xDX)
+ *subSeconds = RTC_TimeStruct.SubSeconds;
+#endif
+#endif // !defined(STM32F1xx)
+ }
+}
+
+/**
+ * @brief Set RTC calendar
+ * @param year: 0-99
+ * @param month: 1-12
+ * @param date: 1-31
+ * @param day: 1-7
+ * @retval None
+ */
+void RTC_SetDate(uint8_t year, uint8_t month, uint8_t date, uint8_t day)
+{
+ RTC_DateTypeDef RTC_DateStruct;
+
+ if(IS_RTC_YEAR(year) && IS_RTC_MONTH(month) && IS_RTC_DATE(date) && IS_RTC_WEEKDAY(day)) {
+ RTC_DateStruct.Year = year;
+ RTC_DateStruct.Month = month;
+ RTC_DateStruct.Date = date;
+ RTC_DateStruct.WeekDay = day;
+ HAL_RTC_SetDate(&RtcHandle , &RTC_DateStruct, RTC_FORMAT_BIN);
+ }
+}
+
+/**
+ * @brief Get RTC calendar
+ * @param year: 0-99
+ * @param month: 1-12
+ * @param date: 1-31
+ * @param day: 1-7
+ * @retval None
+ */
+void RTC_GetDate(uint8_t *year, uint8_t *month, uint8_t *date, uint8_t *day)
+{
+ RTC_DateTypeDef RTC_DateStruct;
+
+ if((year != NULL) && (month != NULL) && (date != NULL) && (day != NULL)) {
+ HAL_RTC_GetDate(&RtcHandle, &RTC_DateStruct, RTC_FORMAT_BIN);
+ *year = RTC_DateStruct.Year;
+ *month = RTC_DateStruct.Month;
+ *date = RTC_DateStruct.Date;
+ *day = RTC_DateStruct.WeekDay;
+ }
+}
+
+/**
+ * @brief Set RTC alarm and activate it with IT mode
+ * @param date: 1-31 (day of the month)
+ * @param hours: 0-12 or 0-23 depends on the hours mode.
+ * @param minutes: 0-59
+ * @param seconds: 0-59
+ * @param subSeconds: 0-999
+ * @param hours format: AM or PM if in 12 hours mode else ignored.
+ * @retval None
+ */
+void RTC_StartAlarm(uint8_t date, uint8_t hours, uint8_t minutes, uint8_t seconds, uint32_t subSeconds, hourAM_PM_t format)
+{
+ RTC_AlarmTypeDef RTC_AlarmStructure;
+
+ // Ignore time AM PM configuration if in 24 hours format
+ if(initFormat == HOUR_FORMAT_24) {
+ format = AM;
+ }
+
+ if((((initFormat == HOUR_FORMAT_24) && IS_RTC_HOUR24(hours)) || IS_RTC_HOUR12(hours))
+ && IS_RTC_DATE(date) && IS_RTC_MINUTES(minutes) && IS_RTC_SECONDS(seconds)) {
+ /* Set RTC_AlarmStructure with calculated values*/
+ RTC_AlarmStructure.Alarm = RTC_ALARM_A; //Use alarm A by default because it is common to all STM32 HAL.
+ RTC_AlarmStructure.AlarmTime.Seconds = seconds;
+ RTC_AlarmStructure.AlarmTime.Minutes = minutes;
+ RTC_AlarmStructure.AlarmTime.Hours = hours;
+#if !defined(STM32F1xx)
+#if !defined(STM32F2xx) && !defined(STM32L1xx)
+ RTC_AlarmStructure.AlarmSubSecondMask = RTC_ALARMSUBSECONDMASK_SS14_10;
+ RTC_AlarmStructure.AlarmTime.SubSeconds = subSeconds;
+#elif defined(STM32L100xBA) || defined (STM32L151xBA) || defined (STM32L152xBA) || defined(STM32L100xC) || defined (STM32L151xC) || defined (STM32L152xC) || defined (STM32L162xC) || defined(STM32L151xCA) || defined (STM32L151xD) || defined (STM32L152xCA) || defined (STM32L152xD) || defined (STM32L162xCA) || defined (STM32L162xD) || defined(STM32L151xE) || defined(STM32L151xDX) || defined (STM32L152xE) || defined (STM32L152xDX) || defined (STM32L162xE) || defined (STM32L162xDX)
+ RTC_AlarmStructure.AlarmSubSecondMask = RTC_ALARMSUBSECONDMASK_SS14_10;
+ RTC_AlarmStructure.AlarmTime.SubSeconds = subSeconds;
+#else
+ UNUSED(subSeconds);
+#endif
+ if(format == PM) {
+ RTC_AlarmStructure.AlarmTime.TimeFormat = RTC_HOURFORMAT12_PM;
+ } else {
+ RTC_AlarmStructure.AlarmTime.TimeFormat = RTC_HOURFORMAT12_AM;
+ }
+ RTC_AlarmStructure.AlarmTime.DayLightSaving = RTC_DAYLIGHTSAVING_NONE;
+ RTC_AlarmStructure.AlarmTime.StoreOperation = RTC_STOREOPERATION_RESET;
+ RTC_AlarmStructure.AlarmDateWeekDay = date;
+ RTC_AlarmStructure.AlarmDateWeekDaySel = RTC_ALARMDATEWEEKDAYSEL_DATE;
+ RTC_AlarmStructure.AlarmMask = RTC_ALARMMASK_NONE;
+#else
+ UNUSED(subSeconds);
+ UNUSED(format);
+ UNUSED(date);
+#endif // !defined(STM32F1xx)
+
+ /* Set RTC_Alarm */
+ HAL_RTC_SetAlarm_IT(&RtcHandle, &RTC_AlarmStructure, RTC_FORMAT_BIN);
+ }
+}
+
+/**
+ * @brief Disable RTC alarm
+ * @param None
+ * @retval None
+ */
+void RTC_StopAlarm(void)
+{
+ /* Clear RTC Alarm Flag */
+ __HAL_RTC_ALARM_CLEAR_FLAG(&RtcHandle, RTC_FLAG_ALRAF);
+
+ /* Disable the Alarm A interrupt */
+ HAL_RTC_DeactivateAlarm(&RtcHandle, RTC_ALARM_A);
+}
+
+/**
+ * @brief Get RTC alarm
+ * @param date: 1-31 (day of the month)
+ * @param hours: 0-12 or 0-23 depends on the hours mode.
+ * @param minutes: 0-59
+ * @param seconds: 0-59
+ * @param subSeconds: 0-999
+ * @param hours format: AM or PM
+ * @retval None
+ */
+void RTC_GetAlarm(uint8_t *date, uint8_t *hours, uint8_t *minutes, uint8_t *seconds, uint32_t *subSeconds, hourAM_PM_t *format)
+{
+ RTC_AlarmTypeDef RTC_AlarmStructure;
+
+ if((date != NULL) && (hours != NULL) && (minutes != NULL) && (seconds != NULL) && (subSeconds != NULL) && (format != NULL)) {
+ HAL_RTC_GetAlarm(&RtcHandle, &RTC_AlarmStructure, RTC_ALARM_A, RTC_FORMAT_BIN);
+
+ *seconds = RTC_AlarmStructure.AlarmTime.Seconds;
+ *minutes = RTC_AlarmStructure.AlarmTime.Minutes;
+ *hours = RTC_AlarmStructure.AlarmTime.Hours;
+#if !defined(STM32F1xx)
+ *date = RTC_AlarmStructure.AlarmDateWeekDay;
+ if(RTC_AlarmStructure.AlarmTime.TimeFormat == RTC_HOURFORMAT12_PM) {
+ *format = PM;
+ } else {
+ *format = AM;
+ }
+#if !defined(STM32F2xx) && !defined(STM32L1xx)
+ *subSeconds = RTC_AlarmStructure.AlarmTime.SubSeconds;
+#elif defined(STM32L100xBA) || defined (STM32L151xBA) || defined (STM32L152xBA) || defined(STM32L100xC) || defined (STM32L151xC) || defined (STM32L152xC) || defined (STM32L162xC) || defined(STM32L151xCA) || defined (STM32L151xD) || defined (STM32L152xCA) || defined (STM32L152xD) || defined (STM32L162xCA) || defined (STM32L162xD) || defined(STM32L151xE) || defined(STM32L151xDX) || defined (STM32L152xE) || defined (STM32L152xDX) || defined (STM32L162xE) || defined (STM32L162xDX)
+ *subSeconds = RTC_AlarmStructure.AlarmTime.SubSeconds;
+#endif
+#endif // !defined(STM32F1xx)
+ }
+}
+
+/**
+ * @brief Attach alarm callback.
+ * @param func: pointer to the callback
+ * @retval None
+ */
+void attachAlarmCallback(voidCallbackPtr func, void *data)
+{
+ RTCUserCallback = func;
+ callbackUserData = data;
+}
+
+/**
+ * @brief Detach alarm callback.
+ * @param None
+ * @retval None
+ */
+void detachAlarmCallback(void)
+{
+ RTCUserCallback = NULL;
+ callbackUserData = NULL;
+}
+
+/**
+ * @brief Alarm A callback.
+ * @param hrtc RTC handle
+ * @retval None
+ */
+void HAL_RTC_AlarmAEventCallback(RTC_HandleTypeDef *hrtc)
+{
+ UNUSED(hrtc);
+
+ if(RTCUserCallback != NULL)
+ RTCUserCallback(callbackUserData);
+}
+
+/**
+ * @brief RTC Alarm IRQHandler
+ * @param None
+ * @retval None
+ */
+void RTC_Alarm_IRQHandler(void)
+{
+ HAL_RTC_AlarmIRQHandler(&RtcHandle);
+}
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif // HAL_RTC_MODULE_ENABLED
+
+/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
diff --git a/cores/arduino/stm32/rtc.h b/cores/arduino/stm32/rtc.h
new file mode 100644
index 0000000000..631cb5d324
--- /dev/null
+++ b/cores/arduino/stm32/rtc.h
@@ -0,0 +1,128 @@
+/**
+ ******************************************************************************
+ * @file rtc.h
+ * @author WI6LABS
+ * @version V1.0.0
+ * @date 12-December-2017
+ * @brief Header for RTC driver
+ ******************************************************************************
+ * @attention
+ *
+ * © COPYRIGHT(c) 2017 STMicroelectronics
+ *
+ * Redistribution and use in source and binary forms, with or without modification,
+ * are permitted provided that the following conditions are met:
+ * 1. Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ * 3. Neither the name of STMicroelectronics nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ ******************************************************************************
+ */
+
+/* Define to prevent recursive inclusion -------------------------------------*/
+#ifndef __RTC_H
+#define __RTC_H
+
+/* Includes ------------------------------------------------------------------*/
+#include "stm32_def.h"
+
+#ifdef HAL_RTC_MODULE_ENABLED
+
+#ifdef __cplusplus
+ extern "C" {
+#endif
+
+/* Exported types ------------------------------------------------------------*/
+typedef enum {
+ HOUR_FORMAT_12,
+ HOUR_FORMAT_24
+} hourFormat_t;
+
+typedef enum {
+ AM,
+ PM
+} hourAM_PM_t;
+
+// Clock source selection
+typedef enum {
+ LSI_CLOCK,
+ LSE_CLOCK,
+ HSE_CLOCK
+} sourceClock_t;
+
+typedef void(*voidCallbackPtr)(void *);
+
+/* Exported constants --------------------------------------------------------*/
+#if defined(STM32F0xx) || defined(STM32L0xx)
+#define RTC_Alarm_IRQn RTC_IRQn
+#define RTC_Alarm_IRQHandler RTC_IRQHandler
+#endif
+
+#if defined(STM32F1xx) && !defined(IS_RTC_WEEKDAY)
+// Compensate missing HAL definition
+#define IS_RTC_WEEKDAY(WEEKDAY) (((WEEKDAY) == RTC_WEEKDAY_MONDAY) || \
+ ((WEEKDAY) == RTC_WEEKDAY_TUESDAY) || \
+ ((WEEKDAY) == RTC_WEEKDAY_WEDNESDAY) || \
+ ((WEEKDAY) == RTC_WEEKDAY_THURSDAY) || \
+ ((WEEKDAY) == RTC_WEEKDAY_FRIDAY) || \
+ ((WEEKDAY) == RTC_WEEKDAY_SATURDAY) || \
+ ((WEEKDAY) == RTC_WEEKDAY_SUNDAY))
+
+//F1 doesn't manage 12h format.
+#define IS_RTC_HOUR12(HOUR) IS_RTC_HOUR24(HOUR)
+#endif // defined(STM32F1xx) && !defined(IS_RTC_WEEKDAY)
+
+// __HAL_RCC_GET_RTC_SOURCE is not defined for F2, F4 and F7
+#ifndef __HAL_RCC_GET_RTC_SOURCE
+static uint32_t RTC_getSource(void) {
+ RCC_PeriphCLKInitTypeDef *PeriphClkInit;
+ HAL_RCCEx_GetPeriphCLKConfig(PeriphClkInit);
+ return PeriphClkInit->RTCClockSelection;
+}
+#define __HAL_RCC_GET_RTC_SOURCE() RTC_getSource()
+#endif
+
+/* Exported macro ------------------------------------------------------------*/
+/* Exported functions ------------------------------------------------------- */
+void RTC_setPrediv(int8_t Asynch, int16_t Synch);
+
+void RTC_init(hourFormat_t format, sourceClock_t source);
+void RTC_DeInit(void);
+
+void RTC_SetTime(uint8_t hours, uint8_t minutes, uint8_t seconds, uint32_t subSeconds, hourAM_PM_t format);
+void RTC_GetTime(uint8_t *hours, uint8_t *minutes, uint8_t *seconds, uint32_t *subSeconds, hourAM_PM_t *format);
+
+void RTC_SetDate(uint8_t year, uint8_t month, uint8_t date, uint8_t day);
+void RTC_GetDate(uint8_t *year, uint8_t *month, uint8_t *date, uint8_t *day);
+
+void RTC_StartAlarm(uint8_t date, uint8_t hours, uint8_t minutes, uint8_t seconds, uint32_t subSeconds, hourAM_PM_t format);
+void RTC_StopAlarm(void);
+void RTC_GetAlarm(uint8_t *date, uint8_t *hours, uint8_t *minutes, uint8_t *seconds, uint32_t *subSeconds, hourAM_PM_t *format);
+void attachAlarmCallback(voidCallbackPtr func, void *data);
+void detachAlarmCallback(void);
+
+#ifdef __cplusplus
+ }
+#endif
+
+#endif // HAL_RTC_MODULE_ENABLED
+
+#endif /* __RTC_H */
+
+/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
diff --git a/variants/DISCO_F100RB/stm32f1xx_hal_conf.h b/variants/DISCO_F100RB/stm32f1xx_hal_conf.h
index 0ff7f8d78a..f17549cb86 100644
--- a/variants/DISCO_F100RB/stm32f1xx_hal_conf.h
+++ b/variants/DISCO_F100RB/stm32f1xx_hal_conf.h
@@ -74,7 +74,7 @@
//#define HAL_PCD_MODULE_ENABLED
//#define HAL_PWR_MODULE_ENABLED
#define HAL_RCC_MODULE_ENABLED
-//#define HAL_RTC_MODULE_ENABLED
+#define HAL_RTC_MODULE_ENABLED
//#define HAL_SD_MODULE_ENABLED
//#define HAL_SMARTCARD_MODULE_ENABLED
#define HAL_SPI_MODULE_ENABLED
diff --git a/variants/DISCO_L072CZ_LRWAN1/stm32l0xx_hal_conf.h b/variants/DISCO_L072CZ_LRWAN1/stm32l0xx_hal_conf.h
index 1ab533250f..df2b858ef0 100644
--- a/variants/DISCO_L072CZ_LRWAN1/stm32l0xx_hal_conf.h
+++ b/variants/DISCO_L072CZ_LRWAN1/stm32l0xx_hal_conf.h
@@ -59,7 +59,7 @@
/*#define HAL_LCD_MODULE_ENABLED */
/*#define HAL_LPTIM_MODULE_ENABLED */
/*#define HAL_RNG_MODULE_ENABLED */
-/*#define HAL_RTC_MODULE_ENABLED */
+#define HAL_RTC_MODULE_ENABLED
#define HAL_SPI_MODULE_ENABLED
#define HAL_TIM_MODULE_ENABLED
/*#define HAL_TSC_MODULE_ENABLED */
diff --git a/variants/DISCO_L475VG_IOT/stm32l4xx_hal_conf.h b/variants/DISCO_L475VG_IOT/stm32l4xx_hal_conf.h
index 9d9c175ef7..e35f48aed9 100644
--- a/variants/DISCO_L475VG_IOT/stm32l4xx_hal_conf.h
+++ b/variants/DISCO_L475VG_IOT/stm32l4xx_hal_conf.h
@@ -86,7 +86,7 @@
#define HAL_QSPI_MODULE_ENABLED
#define HAL_RCC_MODULE_ENABLED
/* #define HAL_RNG_MODULE_ENABLED */
-/* #define HAL_RTC_MODULE_ENABLED */
+#define HAL_RTC_MODULE_ENABLED
#define HAL_SAI_MODULE_ENABLED
/* #define HAL_SD_MODULE_ENABLED */
/* #define HAL_SMARTCARD_MODULE_ENABLED */
diff --git a/variants/NUCLEO_F030R8/stm32f0xx_hal_conf.h b/variants/NUCLEO_F030R8/stm32f0xx_hal_conf.h
index 04e82c19c6..d455dc3986 100644
--- a/variants/NUCLEO_F030R8/stm32f0xx_hal_conf.h
+++ b/variants/NUCLEO_F030R8/stm32f0xx_hal_conf.h
@@ -68,7 +68,7 @@
//#define HAL_PCD_MODULE_ENABLED
//#define HAL_PWR_MODULE_ENABLED
#define HAL_RCC_MODULE_ENABLED
-//#define HAL_RTC_MODULE_ENABLED
+#define HAL_RTC_MODULE_ENABLED
//#define HAL_SMARTCARD_MODULE_ENABLED
//#define HAL_SMBUS_MODULE_ENABLED
#define HAL_SPI_MODULE_ENABLED
diff --git a/variants/NUCLEO_F091RC/stm32f0xx_hal_conf.h b/variants/NUCLEO_F091RC/stm32f0xx_hal_conf.h
index 801ba28da6..c7c47dcb91 100644
--- a/variants/NUCLEO_F091RC/stm32f0xx_hal_conf.h
+++ b/variants/NUCLEO_F091RC/stm32f0xx_hal_conf.h
@@ -68,7 +68,7 @@
//#define HAL_PCD_MODULE_ENABLED
//#define HAL_PWR_MODULE_ENABLED
#define HAL_RCC_MODULE_ENABLED
-//#define HAL_RTC_MODULE_ENABLED
+#define HAL_RTC_MODULE_ENABLED
//#define HAL_SMARTCARD_MODULE_ENABLED
//#define HAL_SMBUS_MODULE_ENABLED
#define HAL_SPI_MODULE_ENABLED
diff --git a/variants/NUCLEO_F103RB/stm32f1xx_hal_conf.h b/variants/NUCLEO_F103RB/stm32f1xx_hal_conf.h
index f7e43947ff..d996e5da9d 100644
--- a/variants/NUCLEO_F103RB/stm32f1xx_hal_conf.h
+++ b/variants/NUCLEO_F103RB/stm32f1xx_hal_conf.h
@@ -74,7 +74,7 @@
//#define HAL_PCD_MODULE_ENABLED
//#define HAL_PWR_MODULE_ENABLED
#define HAL_RCC_MODULE_ENABLED
-//#define HAL_RTC_MODULE_ENABLED
+#define HAL_RTC_MODULE_ENABLED
//#define HAL_SD_MODULE_ENABLED
//#define HAL_SMARTCARD_MODULE_ENABLED
#define HAL_SPI_MODULE_ENABLED
diff --git a/variants/NUCLEO_F207ZG/stm32f2xx_hal_conf.h b/variants/NUCLEO_F207ZG/stm32f2xx_hal_conf.h
index 1f0e92e3f9..156dd264c6 100644
--- a/variants/NUCLEO_F207ZG/stm32f2xx_hal_conf.h
+++ b/variants/NUCLEO_F207ZG/stm32f2xx_hal_conf.h
@@ -69,7 +69,7 @@
#define HAL_PWR_MODULE_ENABLED
#define HAL_RCC_MODULE_ENABLED
/*#define HAL_RNG_MODULE_ENABLED */
-/*#define HAL_RTC_MODULE_ENABLED */
+#define HAL_RTC_MODULE_ENABLED
/*#define HAL_SD_MODULE_ENABLED */
#define HAL_SPI_MODULE_ENABLED
#define HAL_TIM_MODULE_ENABLED
diff --git a/variants/NUCLEO_F302R8/stm32f3xx_hal_conf.h b/variants/NUCLEO_F302R8/stm32f3xx_hal_conf.h
index 9f389c875d..9585e0e819 100644
--- a/variants/NUCLEO_F302R8/stm32f3xx_hal_conf.h
+++ b/variants/NUCLEO_F302R8/stm32f3xx_hal_conf.h
@@ -74,7 +74,7 @@
// #define HAL_PCD_MODULE_ENABLED
// #define HAL_PWR_MODULE_ENABLED
#define HAL_RCC_MODULE_ENABLED
-// #define HAL_RTC_MODULE_ENABLED
+#define HAL_RTC_MODULE_ENABLED
// #define HAL_SDADC_MODULE_ENABLED
// #define HAL_SMARTCARD_MODULE_ENABLED
// #define HAL_SMBUS_MODULE_ENABLED
diff --git a/variants/NUCLEO_F303RE/stm32f3xx_hal_conf.h b/variants/NUCLEO_F303RE/stm32f3xx_hal_conf.h
index 5fbb6b1393..3a09bb6299 100644
--- a/variants/NUCLEO_F303RE/stm32f3xx_hal_conf.h
+++ b/variants/NUCLEO_F303RE/stm32f3xx_hal_conf.h
@@ -74,7 +74,7 @@
// #define HAL_PCD_MODULE_ENABLED
// #define HAL_PWR_MODULE_ENABLED
#define HAL_RCC_MODULE_ENABLED
-// #define HAL_RTC_MODULE_ENABLED
+#define HAL_RTC_MODULE_ENABLED
// #define HAL_SDADC_MODULE_ENABLED
// #define HAL_SMARTCARD_MODULE_ENABLED
// #define HAL_SMBUS_MODULE_ENABLED
diff --git a/variants/NUCLEO_F401RE/stm32f4xx_hal_conf.h b/variants/NUCLEO_F401RE/stm32f4xx_hal_conf.h
index 3dff96e9f6..c7eedbd2a9 100644
--- a/variants/NUCLEO_F401RE/stm32f4xx_hal_conf.h
+++ b/variants/NUCLEO_F401RE/stm32f4xx_hal_conf.h
@@ -76,7 +76,7 @@
/* #define HAL_QSPI_MODULE_ENABLED */
#define HAL_RCC_MODULE_ENABLED
/* #define HAL_RNG_MODULE_ENABLED */
-/* #define HAL_RTC_MODULE_ENABLED */
+#define HAL_RTC_MODULE_ENABLED
/* #define HAL_SAI_MODULE_ENABLED */
/* #define HAL_SD_MODULE_ENABLED */
#define HAL_SPI_MODULE_ENABLED
diff --git a/variants/NUCLEO_F411RE/stm32f4xx_hal_conf.h b/variants/NUCLEO_F411RE/stm32f4xx_hal_conf.h
index 3dff96e9f6..c7eedbd2a9 100644
--- a/variants/NUCLEO_F411RE/stm32f4xx_hal_conf.h
+++ b/variants/NUCLEO_F411RE/stm32f4xx_hal_conf.h
@@ -76,7 +76,7 @@
/* #define HAL_QSPI_MODULE_ENABLED */
#define HAL_RCC_MODULE_ENABLED
/* #define HAL_RNG_MODULE_ENABLED */
-/* #define HAL_RTC_MODULE_ENABLED */
+#define HAL_RTC_MODULE_ENABLED
/* #define HAL_SAI_MODULE_ENABLED */
/* #define HAL_SD_MODULE_ENABLED */
#define HAL_SPI_MODULE_ENABLED
diff --git a/variants/NUCLEO_F446RE/stm32f4xx_hal_conf.h b/variants/NUCLEO_F446RE/stm32f4xx_hal_conf.h
index e98ba0870d..4a4f6f2bbf 100644
--- a/variants/NUCLEO_F446RE/stm32f4xx_hal_conf.h
+++ b/variants/NUCLEO_F446RE/stm32f4xx_hal_conf.h
@@ -76,7 +76,7 @@
/* #define HAL_QSPI_MODULE_ENABLED */
#define HAL_RCC_MODULE_ENABLED
/* #define HAL_RNG_MODULE_ENABLED */
-/* #define HAL_RTC_MODULE_ENABLED */
+#define HAL_RTC_MODULE_ENABLED
/* #define HAL_SAI_MODULE_ENABLED */
/* #define HAL_SD_MODULE_ENABLED */
#define HAL_SPI_MODULE_ENABLED
diff --git a/variants/NUCLEO_L031K6/stm32l0xx_hal_conf.h b/variants/NUCLEO_L031K6/stm32l0xx_hal_conf.h
index ac01cbf299..f5c9bee9fc 100644
--- a/variants/NUCLEO_L031K6/stm32l0xx_hal_conf.h
+++ b/variants/NUCLEO_L031K6/stm32l0xx_hal_conf.h
@@ -61,7 +61,7 @@
/*#define HAL_LCD_MODULE_ENABLED */
/*#define HAL_LPTIM_MODULE_ENABLED */
/*#define HAL_RNG_MODULE_ENABLED */
-/*#define HAL_RTC_MODULE_ENABLED */
+#define HAL_RTC_MODULE_ENABLED
#define HAL_SPI_MODULE_ENABLED
#define HAL_TIM_MODULE_ENABLED
/*#define HAL_TSC_MODULE_ENABLED */
diff --git a/variants/NUCLEO_L053R8/stm32l0xx_hal_conf.h b/variants/NUCLEO_L053R8/stm32l0xx_hal_conf.h
index 69b47b742b..26b1b171f6 100644
--- a/variants/NUCLEO_L053R8/stm32l0xx_hal_conf.h
+++ b/variants/NUCLEO_L053R8/stm32l0xx_hal_conf.h
@@ -70,7 +70,7 @@
#define HAL_PWR_MODULE_ENABLED
#define HAL_RCC_MODULE_ENABLED
// #define HAL_RNG_MODULE_ENABLED
-// #define HAL_RTC_MODULE_ENABLED
+#define HAL_RTC_MODULE_ENABLED
#define HAL_SPI_MODULE_ENABLED
#define HAL_TIM_MODULE_ENABLED
// #define HAL_TSC_MODULE_ENABLED
diff --git a/variants/NUCLEO_L152RE/stm32l1xx_hal_conf.h b/variants/NUCLEO_L152RE/stm32l1xx_hal_conf.h
index 25299b213a..1932a2bfab 100644
--- a/variants/NUCLEO_L152RE/stm32l1xx_hal_conf.h
+++ b/variants/NUCLEO_L152RE/stm32l1xx_hal_conf.h
@@ -72,7 +72,7 @@
/*#define HAL_PCD_MODULE_ENABLED*/
#define HAL_PWR_MODULE_ENABLED
#define HAL_RCC_MODULE_ENABLED
-/*#define HAL_RTC_MODULE_ENABLED*/
+#define HAL_RTC_MODULE_ENABLED
/*#define HAL_SD_MODULE_ENABLED*/
/*#define HAL_SMARTCARD_MODULE_ENABLED*/
#define HAL_SPI_MODULE_ENABLED
diff --git a/variants/NUCLEO_L432KC/stm32l4xx_hal_conf.h b/variants/NUCLEO_L432KC/stm32l4xx_hal_conf.h
index 1adfa64bb6..e76e19cdbb 100644
--- a/variants/NUCLEO_L432KC/stm32l4xx_hal_conf.h
+++ b/variants/NUCLEO_L432KC/stm32l4xx_hal_conf.h
@@ -86,7 +86,7 @@
/* #define HAL_QSPI_MODULE_ENABLED */
#define HAL_RCC_MODULE_ENABLED
/* #define HAL_RNG_MODULE_ENABLED */
-/* #define HAL_RTC_MODULE_ENABLED */
+#define HAL_RTC_MODULE_ENABLED
/* #define HAL_SAI_MODULE_ENABLED */
/* #define HAL_SD_MODULE_ENABLED */
/* #define HAL_SMARTCARD_MODULE_ENABLED */
diff --git a/variants/NUCLEO_L476RG/stm32l4xx_hal_conf.h b/variants/NUCLEO_L476RG/stm32l4xx_hal_conf.h
index 1adfa64bb6..e76e19cdbb 100644
--- a/variants/NUCLEO_L476RG/stm32l4xx_hal_conf.h
+++ b/variants/NUCLEO_L476RG/stm32l4xx_hal_conf.h
@@ -86,7 +86,7 @@
/* #define HAL_QSPI_MODULE_ENABLED */
#define HAL_RCC_MODULE_ENABLED
/* #define HAL_RNG_MODULE_ENABLED */
-/* #define HAL_RTC_MODULE_ENABLED */
+#define HAL_RTC_MODULE_ENABLED
/* #define HAL_SAI_MODULE_ENABLED */
/* #define HAL_SD_MODULE_ENABLED */
/* #define HAL_SMARTCARD_MODULE_ENABLED */