1 /**
2   ******************************************************************************
3   * @file    stm32l4xx_hal_rtc.h
4   * @author  MCD Application Team
5   * @brief   Header file of RTC HAL module.
6   ******************************************************************************
7   * @attention
8   *
9   * Copyright (c) 2017 STMicroelectronics.
10   * All rights reserved.
11   *
12   * This software is licensed under terms that can be found in the LICENSE file
13   * in the root directory of this software component.
14   * If no LICENSE file comes with this software, it is provided AS-IS.
15   *
16   ******************************************************************************
17   */
18 
19 /* Define to prevent recursive inclusion -------------------------------------*/
20 #ifndef STM32L4xx_HAL_RTC_H
21 #define STM32L4xx_HAL_RTC_H
22 
23 #ifdef __cplusplus
24 extern "C" {
25 #endif
26 
27 /* Includes ------------------------------------------------------------------*/
28 #include "stm32l4xx_hal_def.h"
29 
30 /** @addtogroup STM32L4xx_HAL_Driver
31   * @{
32   */
33 
34 /** @defgroup RTC RTC
35   * @{
36   */
37 
38 /* Exported types ------------------------------------------------------------*/
39 /** @defgroup RTC_Exported_Types RTC Exported Types
40   * @{
41   */
42 
43 /**
44   * @brief  HAL State structures definition
45   */
46 typedef enum
47 {
48   HAL_RTC_STATE_RESET             = 0x00U,  /*!< RTC not yet initialized or disabled */
49   HAL_RTC_STATE_READY             = 0x01U,  /*!< RTC initialized and ready for use   */
50   HAL_RTC_STATE_BUSY              = 0x02U,  /*!< RTC process is ongoing              */
51   HAL_RTC_STATE_TIMEOUT           = 0x03U,  /*!< RTC timeout state                   */
52   HAL_RTC_STATE_ERROR             = 0x04U   /*!< RTC error state                     */
53 
54 } HAL_RTCStateTypeDef;
55 
56 /**
57   * @brief  RTC Configuration Structure definition
58   */
59 typedef struct
60 {
61   uint32_t HourFormat;      /*!< Specifies the RTC Hour Format.
62                                  This parameter can be a value of @ref RTC_Hour_Formats */
63 
64   uint32_t AsynchPrediv;    /*!< Specifies the RTC Asynchronous Predivider value.
65                                  This parameter must be a number between Min_Data = 0x00 and Max_Data = 0x7F */
66 
67   uint32_t SynchPrediv;     /*!< Specifies the RTC Synchronous Predivider value.
68                                  This parameter must be a number between Min_Data = 0x00 and Max_Data = 0x7FFF */
69 
70   uint32_t OutPut;          /*!< Specifies which signal will be routed to the RTC output.
71                                  This parameter can be a value of @ref RTCEx_Output_selection_Definitions */
72 
73   uint32_t OutPutRemap;     /*!< Specifies the remap for RTC output.
74                                  This parameter can be a value of @ref  RTC_Output_ALARM_OUT_Remap */
75 
76   uint32_t OutPutPolarity;  /*!< Specifies the polarity of the output signal.
77                                  This parameter can be a value of @ref RTC_Output_Polarity_Definitions */
78 
79   uint32_t OutPutType;      /*!< Specifies the RTC Output Pin mode.
80                                  This parameter can be a value of @ref RTC_Output_Type_ALARM_OUT */
81 #if defined(STM32L412xx) || defined(STM32L422xx) || defined (STM32L4P5xx) || defined (STM32L4Q5xx)
82   uint32_t OutPutPullUp;    /*!< Specifies the RTC Output Pull-Up mode.
83                                  This parameter can be a value of @ref RTC_Output_PullUp_ALARM_OUT */
84 #endif
85 
86 #if defined (STM32L4P5xx) || defined (STM32L4Q5xx)
87   uint32_t BinMode;         /*!< Specifies the RTC binary mode.
88                                  This parameter can be a value of @ref RTCEx_Binary_Mode */
89 
90   uint32_t BinMixBcdU;      /*!< Specifies the BCD calendar update if and only if BinMode = RTC_BINARY_MIX.
91                                  This parameter can be a value of @ref RTCEx_Binary_mix_BCDU */
92 #endif
93 } RTC_InitTypeDef;
94 
95 /**
96   * @brief  RTC Time structure definition
97   */
98 typedef struct
99 {
100   uint8_t Hours;            /*!< Specifies the RTC Time Hour.
101                                  This parameter must be a number between Min_Data = 0 and Max_Data = 12 if the RTC_HourFormat_12 is selected.
102                                  This parameter must be a number between Min_Data = 0 and Max_Data = 23 if the RTC_HourFormat_24 is selected */
103 
104   uint8_t Minutes;          /*!< Specifies the RTC Time Minutes.
105                                  This parameter must be a number between Min_Data = 0 and Max_Data = 59 */
106 
107   uint8_t Seconds;          /*!< Specifies the RTC Time Seconds.
108                                  This parameter must be a number between Min_Data = 0 and Max_Data = 59 */
109 
110   uint8_t TimeFormat;       /*!< Specifies the RTC AM/PM Time.
111                                  This parameter can be a value of @ref RTC_AM_PM_Definitions */
112 
113 #if defined (STM32L4P5xx) || defined (STM32L4Q5xx)
114   uint32_t SubSeconds;      /*!< Specifies the RTC_SSR RTC Sub Second register content.
115                                  This field is not used by HAL_RTC_SetTime.
116                                  If the free running 32 bit counter is not activated (mode binary none)
117                                     - This parameter corresponds to a time unit range between [0-1] Second with [1 Sec / SecondFraction +1] granularity
118                                  else
119                                     - This parameter corresponds to the free running 32 bit counter. */
120 #else
121   uint32_t SubSeconds;      /*!< Specifies the RTC_SSR RTC Sub Second register content.
122                                  This parameter corresponds to a time unit range between [0-1] Second
123                                  with [1 Sec / SecondFraction +1] granularity */
124 #endif
125 
126   uint32_t SecondFraction;  /*!< Specifies the range or granularity of Sub Second register content
127                                  corresponding to Synchronous pre-scaler factor value (PREDIV_S)
128                                  This parameter corresponds to a time unit range between [0-1] Second
129                                  with [1 Sec / SecondFraction +1] granularity.
130                                  This field will be used only by HAL_RTC_GetTime function */
131 
132   uint32_t DayLightSaving;  /*!< This interface is deprecated. To manage Daylight Saving Time, please use HAL_RTC_DST_xxx functions */
133 
134   uint32_t StoreOperation;  /*!< This interface is deprecated. To manage Daylight Saving Time, please use HAL_RTC_DST_xxx functions */
135 } RTC_TimeTypeDef;
136 
137 /**
138   * @brief  RTC Date structure definition
139   */
140 typedef struct
141 {
142   uint8_t WeekDay;  /*!< Specifies the RTC Date WeekDay.
143                          This parameter can be a value of @ref RTC_WeekDay_Definitions */
144 
145   uint8_t Month;    /*!< Specifies the RTC Date Month (in BCD format).
146                          This parameter can be a value of @ref RTC_Month_Date_Definitions */
147 
148   uint8_t Date;     /*!< Specifies the RTC Date.
149                          This parameter must be a number between Min_Data = 1 and Max_Data = 31 */
150 
151   uint8_t Year;     /*!< Specifies the RTC Date Year.
152                          This parameter must be a number between Min_Data = 0 and Max_Data = 99 */
153 
154 } RTC_DateTypeDef;
155 
156 /**
157   * @brief  RTC Alarm structure definition
158   */
159 typedef struct
160 {
161   RTC_TimeTypeDef AlarmTime;     /*!< Specifies the RTC Alarm Time members */
162 
163   uint32_t AlarmMask;            /*!< Specifies the RTC Alarm Masks.
164                                       This parameter can be a value of @ref RTC_AlarmMask_Definitions */
165 
166 #if defined (STM32L4P5xx) || defined (STM32L4Q5xx)
167   uint32_t SubSeconds;           /*!< Specifies the RTC_SSR RTC Sub Second register content.
168                                       This field is not used by HAL_RTC_SetTime.
169                                        If the free running 32 bit counter is not activated (mode binary none)
170                                           - This parameter corresponds to a time unit range between [0-1] Second with [1 Sec / SecondFraction +1] granularity
171                                        else
172                                           - This parameter corresponds to the free running 32 bit counter. */
173   uint32_t BinaryAutoClr;        /*!< Clear synchronously counter (RTC_SSR) on binary alarm.
174                                       RTC_ALARMSUBSECONDBIN_AUTOCLR_YES must only be used if Binary mode is RTC_BINARY_ONLY
175                                       This parameter can be a value of @ref RTCEx_Alarm_Sub_Seconds_binary_Clear_Definitions */
176 #else
177   uint32_t SubSeconds;           /*!< Specifies the RTC_SSR RTC Sub Second register content. */
178 #endif
179 
180   uint32_t AlarmSubSecondMask;   /*!< Specifies the RTC Alarm SubSeconds Masks.
181                                       This parameter can be a value of @ref RTC_Alarm_Sub_Seconds_Masks_Definitions */
182 
183   uint32_t AlarmDateWeekDaySel;  /*!< Specifies the RTC Alarm is on Date or WeekDay.
184                                      This parameter can be a value of @ref RTC_AlarmDateWeekDay_Definitions */
185 
186   uint8_t AlarmDateWeekDay;      /*!< Specifies the RTC Alarm Date/WeekDay.
187                                       If the Alarm Date is selected, this parameter must be set to a value in the 1-31 range.
188                                       If the Alarm WeekDay is selected, this parameter can be a value of @ref RTC_WeekDay_Definitions */
189 
190   uint32_t Alarm;                /*!< Specifies the alarm .
191                                       This parameter can be a value of @ref RTC_Alarms_Definitions */
192 } RTC_AlarmTypeDef;
193 
194 /**
195   * @brief  RTC Handle Structure definition
196   */
197 #if (USE_HAL_RTC_REGISTER_CALLBACKS == 1)
198 typedef struct __RTC_HandleTypeDef
199 #else
200 typedef struct
201 #endif /* (USE_HAL_RTC_REGISTER_CALLBACKS) */
202 {
203   RTC_TypeDef               *Instance;  /*!< Register base address    */
204 
205 #if defined(STM32L412xx) || defined(STM32L422xx) || defined (STM32L4P5xx) || defined (STM32L4Q5xx)
206   uint32_t                  TampOffset; /*!< Offset to TAMP instance  */
207 #endif
208   RTC_InitTypeDef           Init;       /*!< RTC required parameters  */
209 
210   HAL_LockTypeDef           Lock;       /*!< RTC locking object       */
211 
212   __IO HAL_RTCStateTypeDef  State;      /*!< Time communication state */
213 
214 #if (USE_HAL_RTC_REGISTER_CALLBACKS == 1)
215   void (* AlarmAEventCallback)(struct __RTC_HandleTypeDef *hrtc);                    /*!< RTC Alarm A Event callback            */
216   void (* AlarmBEventCallback)(struct __RTC_HandleTypeDef *hrtc);                    /*!< RTC Alarm B Event callback            */
217   void (* TimeStampEventCallback)(struct __RTC_HandleTypeDef *hrtc);                 /*!< RTC TimeStamp Event callback          */
218   void (* WakeUpTimerEventCallback)(struct __RTC_HandleTypeDef *hrtc);               /*!< RTC WakeUpTimer Event callback        */
219 #if defined (STM32L4P5xx) || defined (STM32L4Q5xx)
220   void (* SSRUEventCallback)(struct __RTC_HandleTypeDef *hrtc);                      /*!< RTC SSRU Event callback               */
221 #endif
222 #if defined(RTC_TAMPER1_SUPPORT)
223   void (* Tamper1EventCallback)(struct __RTC_HandleTypeDef *hrtc);                   /*!< RTC Tamper 1 Event callback           */
224 #endif /* RTC_TAMPER1_SUPPORT */
225   void (* Tamper2EventCallback)(struct __RTC_HandleTypeDef *hrtc);                   /*!< RTC Tamper 2 Event callback           */
226 #if defined(RTC_TAMPER3_SUPPORT)
227   void (* Tamper3EventCallback)(struct __RTC_HandleTypeDef *hrtc);                   /*!< RTC Tamper 3 Event callback           */
228 #endif /* RTC_TAMPER3_SUPPORT */
229   void (* MspInitCallback)(struct __RTC_HandleTypeDef *hrtc);                        /*!< RTC Msp Init callback                 */
230   void (* MspDeInitCallback)(struct __RTC_HandleTypeDef *hrtc);                      /*!< RTC Msp DeInit callback               */
231 #endif /* (USE_HAL_RTC_REGISTER_CALLBACKS == 1) */
232 
233 } RTC_HandleTypeDef;
234 
235 #if (USE_HAL_RTC_REGISTER_CALLBACKS == 1)
236 /**
237   * @brief  HAL RTC Callback ID enumeration definition
238   */
239 typedef enum
240 {
241   HAL_RTC_ALARM_A_EVENT_CB_ID            =  0u,    /*!< RTC Alarm A Event Callback ID      */
242   HAL_RTC_ALARM_B_EVENT_CB_ID            =  1u,    /*!< RTC Alarm B Event Callback ID      */
243   HAL_RTC_TIMESTAMP_EVENT_CB_ID          =  2u,    /*!< RTC TimeStamp Event Callback ID    */
244   HAL_RTC_WAKEUPTIMER_EVENT_CB_ID        =  3u,    /*!< RTC WakeUp Timer Event Callback ID */
245 #if defined(RTC_TAMPER1_SUPPORT)
246   HAL_RTC_TAMPER1_EVENT_CB_ID            =  4u,    /*!< RTC Tamper 1 Callback ID           */
247 #endif /* RTC_TAMPER1_SUPPORT */
248   HAL_RTC_TAMPER2_EVENT_CB_ID            =  5u,    /*!< RTC Tamper 2 Callback ID           */
249 #if defined(RTC_TAMPER3_SUPPORT)
250   HAL_RTC_TAMPER3_EVENT_CB_ID            =  6u,    /*!< RTC Tamper 3 Callback ID           */
251 #endif /* RTC_TAMPER3_SUPPORT */
252   HAL_RTC_MSPINIT_CB_ID                  =  7u,    /*!< RTC Msp Init callback ID           */
253   HAL_RTC_MSPDEINIT_CB_ID                =  8u     /*!< RTC Msp DeInit callback ID         */
254 } HAL_RTC_CallbackIDTypeDef;
255 
256 /**
257   * @brief  HAL RTC Callback pointer definition
258   */
259 typedef  void (*pRTC_CallbackTypeDef)(RTC_HandleTypeDef *hrtc);  /*!< pointer to an RTC callback function */
260 #endif /* (USE_HAL_RTC_REGISTER_CALLBACKS == 1) */
261 
262 /**
263   * @}
264   */
265 
266 /* Exported constants --------------------------------------------------------*/
267 /** @defgroup RTC_Exported_Constants RTC Exported Constants
268   * @{
269   */
270 
271 /** @defgroup RTC_Hour_Formats_Definitions RTC Hour Formats Definitions
272   * @{
273   */
274 #define RTC_HOURFORMAT_24                   0x00000000u
275 #define RTC_HOURFORMAT_12                   RTC_CR_FMT
276 /**
277   * @}
278   */
279 
280 /** @defgroup RTCEx_Output_selection_Definitions RTCEx Output Selection Definitions
281   * @{
282   */
283 #define RTC_OUTPUT_DISABLE                  0x00000000u
284 #define RTC_OUTPUT_ALARMA                   RTC_CR_OSEL_0
285 #define RTC_OUTPUT_ALARMB                   RTC_CR_OSEL_1
286 #define RTC_OUTPUT_WAKEUP                   RTC_CR_OSEL
287 #if defined(STM32L412xx) || defined(STM32L422xx) || defined (STM32L4P5xx) || defined (STM32L4Q5xx)
288 #define RTC_OUTPUT_TAMPER                   RTC_CR_TAMPOE
289 #endif
290 /**
291   * @}
292   */
293 
294 /** @defgroup RTC_Output_Polarity_Definitions RTC Output Polarity Definitions
295   * @{
296   */
297 #define RTC_OUTPUT_POLARITY_HIGH            0x00000000u
298 #define RTC_OUTPUT_POLARITY_LOW             RTC_CR_POL
299 /**
300   * @}
301   */
302 
303 /** @defgroup RTC_Output_Type_ALARM_OUT RTC Output Type ALARM OUT
304   * @{
305   */
306 #if defined(STM32L412xx) || defined(STM32L422xx) || defined (STM32L4P5xx) || defined (STM32L4Q5xx)
307 #define RTC_OUTPUT_TYPE_PUSHPULL            0x00000000u
308 #define RTC_OUTPUT_TYPE_OPENDRAIN           RTC_CR_TAMPALRM_TYPE
309 #else
310 #define RTC_OUTPUT_TYPE_PUSHPULL            RTC_OR_ALARMOUTTYPE
311 #define RTC_OUTPUT_TYPE_OPENDRAIN           0x00000000u
312 #endif
313 /**
314   * @}
315   */
316 
317 /** @defgroup RTC_Output_PullUp_ALARM_OUT RTC Output Pull-Up ALARM OUT
318   * @{
319   */
320 #if defined(STM32L412xx) || defined(STM32L422xx) || defined (STM32L4P5xx) || defined (STM32L4Q5xx)
321 #define RTC_OUTPUT_PULLUP_NONE              0x00000000u
322 #define RTC_OUTPUT_PULLUP_ON                RTC_CR_TAMPALRM_PU
323 #endif
324 /**
325   * @}
326   */
327 
328 /** @defgroup RTC_Output_ALARM_OUT_Remap RTC Output ALARM OUT Remap
329   * @{
330   */
331 #if defined(STM32L412xx) || defined(STM32L422xx) || defined (STM32L4P5xx) || defined (STM32L4Q5xx)
332 #define RTC_OUTPUT_REMAP_NONE               0x00000000u
333 #define RTC_OUTPUT_REMAP_POS1               RTC_CR_OUT2EN
334 #else
335 #define RTC_OUTPUT_REMAP_NONE               0x00000000u
336 #define RTC_OUTPUT_REMAP_POS1               RTC_OR_OUT_RMP
337 #endif
338 /**
339   * @}
340   */
341 
342 /** @defgroup RTC_AM_PM_Definitions RTC AM PM Definitions
343   * @{
344   */
345 #define RTC_HOURFORMAT12_AM            ((uint8_t)0x00)
346 #define RTC_HOURFORMAT12_PM            ((uint8_t)0x01)
347 /**
348   * @}
349   */
350 
351 /** @defgroup RTC_DayLightSaving_Definitions RTC DayLightSaving Definitions
352   * @{
353   */
354 #define RTC_DAYLIGHTSAVING_SUB1H            RTC_CR_SUB1H
355 #define RTC_DAYLIGHTSAVING_ADD1H            RTC_CR_ADD1H
356 #define RTC_DAYLIGHTSAVING_NONE             0x00000000u
357 /**
358   * @}
359   */
360 
361 /** @defgroup RTC_StoreOperation_Definitions RTC StoreOperation Definitions
362   * @{
363   */
364 #define RTC_STOREOPERATION_RESET            0x00000000u
365 #define RTC_STOREOPERATION_SET              RTC_CR_BKP
366 /**
367   * @}
368   */
369 
370 #if defined (STM32L4P5xx) || defined (STM32L4Q5xx)
371 /** @defgroup RTC_Input_parameter_format_definitions RTC input or output data format for date (Year, Month, Weekday) and time (Hours, Minutes, Seconds).
372   *           Warning : It Should not be confused with the Binary mode @ref RTCEx_Binary_Mode.
373   * @{
374   */
375 #define RTC_FORMAT_BIN                      0x00000000u /* This parameter will trigger a SW conversion to fit with the native BCD format of the HW Calendar.
376                                                            It should not be confused with the Binary mode @ref RTCEx_Binary_Mode. */
377 
378 #define RTC_FORMAT_BCD                      0x00000001u /* Native format of the HW Calendar.
379                                                            It should not be confused with the Binary mode @ref RTCEx_Binary_Mode. */
380 /**
381   * @}
382   */
383 #else
384 
385 /** @defgroup RTC_Input_parameter_format_definitions RTC Input Parameter Format Definitions
386   * @{
387   */
388 #define RTC_FORMAT_BIN                      0x00000000u
389 #define RTC_FORMAT_BCD                      0x00000001u
390 /**
391   * @}
392   */
393 #endif
394 
395 /** @defgroup RTC_Month_Date_Definitions RTC Month Date Definitions (in BCD format)
396   * @{
397   */
398 
399 /* Coded in BCD format */
400 #define RTC_MONTH_JANUARY                   ((uint8_t)0x01U)
401 #define RTC_MONTH_FEBRUARY                  ((uint8_t)0x02U)
402 #define RTC_MONTH_MARCH                     ((uint8_t)0x03U)
403 #define RTC_MONTH_APRIL                     ((uint8_t)0x04U)
404 #define RTC_MONTH_MAY                       ((uint8_t)0x05U)
405 #define RTC_MONTH_JUNE                      ((uint8_t)0x06U)
406 #define RTC_MONTH_JULY                      ((uint8_t)0x07U)
407 #define RTC_MONTH_AUGUST                    ((uint8_t)0x08U)
408 #define RTC_MONTH_SEPTEMBER                 ((uint8_t)0x09U)
409 #define RTC_MONTH_OCTOBER                   ((uint8_t)0x10U)
410 #define RTC_MONTH_NOVEMBER                  ((uint8_t)0x11U)
411 #define RTC_MONTH_DECEMBER                  ((uint8_t)0x12U)
412 
413 /**
414   * @}
415   */
416 
417 /** @defgroup RTC_WeekDay_Definitions RTC WeekDay Definitions
418   * @{
419   */
420 #define RTC_WEEKDAY_MONDAY                  ((uint8_t)0x01U)
421 #define RTC_WEEKDAY_TUESDAY                 ((uint8_t)0x02U)
422 #define RTC_WEEKDAY_WEDNESDAY               ((uint8_t)0x03U)
423 #define RTC_WEEKDAY_THURSDAY                ((uint8_t)0x04U)
424 #define RTC_WEEKDAY_FRIDAY                  ((uint8_t)0x05U)
425 #define RTC_WEEKDAY_SATURDAY                ((uint8_t)0x06U)
426 #define RTC_WEEKDAY_SUNDAY                  ((uint8_t)0x07U)
427 
428 /**
429   * @}
430   */
431 
432 /** @defgroup RTC_AlarmDateWeekDay_Definitions RTC AlarmDateWeekDay Definitions
433   * @{
434   */
435 #define RTC_ALARMDATEWEEKDAYSEL_DATE        0x00000000u
436 #define RTC_ALARMDATEWEEKDAYSEL_WEEKDAY     RTC_ALRMAR_WDSEL
437 
438 /**
439   * @}
440   */
441 
442 /** @defgroup RTC_AlarmMask_Definitions RTC AlarmMask Definitions
443   * @{
444   */
445 #define RTC_ALARMMASK_NONE                  0x00000000u
446 #define RTC_ALARMMASK_DATEWEEKDAY           RTC_ALRMAR_MSK4
447 #define RTC_ALARMMASK_HOURS                 RTC_ALRMAR_MSK3
448 #define RTC_ALARMMASK_MINUTES               RTC_ALRMAR_MSK2
449 #define RTC_ALARMMASK_SECONDS               RTC_ALRMAR_MSK1
450 #define RTC_ALARMMASK_ALL                   (RTC_ALARMMASK_DATEWEEKDAY | RTC_ALARMMASK_HOURS  | \
451                                              RTC_ALARMMASK_MINUTES | RTC_ALARMMASK_SECONDS)
452 
453 /**
454   * @}
455   */
456 
457 /** @defgroup RTC_Alarms_Definitions RTC Alarms Definitions
458   * @{
459   */
460 #define RTC_ALARM_A                         RTC_CR_ALRAE
461 #define RTC_ALARM_B                         RTC_CR_ALRBE
462 
463 /**
464   * @}
465   */
466 
467 
468 /** @defgroup RTC_Alarm_Sub_Seconds_Masks_Definitions RTC Alarm Sub Seconds Masks Definitions
469   * @{
470   */
471 #define RTC_ALARMSUBSECONDMASK_ALL          0x00000000u                                                              /*!< All Alarm SS fields are masked.
472                                                                                                                           There is no comparison on sub seconds
473                                                                                                                           for Alarm */
474 #define RTC_ALARMSUBSECONDMASK_SS14_1       RTC_ALRMASSR_MASKSS_0                                                    /*!< SS[14:1] are don't care in Alarm
475                                                                                                                           comparison. Only SS[0] is compared.    */
476 #define RTC_ALARMSUBSECONDMASK_SS14_2       RTC_ALRMASSR_MASKSS_1                                                    /*!< SS[14:2] are don't care in Alarm
477                                                                                                                           comparison. Only SS[1:0] are compared  */
478 #define RTC_ALARMSUBSECONDMASK_SS14_3       (RTC_ALRMASSR_MASKSS_0 | RTC_ALRMASSR_MASKSS_1)                          /*!< SS[14:3] are don't care in Alarm
479                                                                                                                           comparison. Only SS[2:0] are compared  */
480 #define RTC_ALARMSUBSECONDMASK_SS14_4       RTC_ALRMASSR_MASKSS_2                                                    /*!< SS[14:4] are don't care in Alarm
481                                                                                                                           comparison. Only SS[3:0] are compared  */
482 #define RTC_ALARMSUBSECONDMASK_SS14_5       (RTC_ALRMASSR_MASKSS_0 | RTC_ALRMASSR_MASKSS_2)                          /*!< SS[14:5] are don't care in Alarm
483                                                                                                                           comparison. Only SS[4:0] are compared  */
484 #define RTC_ALARMSUBSECONDMASK_SS14_6       (RTC_ALRMASSR_MASKSS_1 | RTC_ALRMASSR_MASKSS_2)                          /*!< SS[14:6] are don't care in Alarm
485                                                                                                                           comparison. Only SS[5:0] are compared  */
486 #define RTC_ALARMSUBSECONDMASK_SS14_7       (RTC_ALRMASSR_MASKSS_0 | RTC_ALRMASSR_MASKSS_1 | RTC_ALRMASSR_MASKSS_2)  /*!< SS[14:7] are don't care in Alarm
487                                                                                                                           comparison. Only SS[6:0] are compared  */
488 #define RTC_ALARMSUBSECONDMASK_SS14_8       RTC_ALRMASSR_MASKSS_3                                                    /*!< SS[14:8] are don't care in Alarm
489                                                                                                                           comparison. Only SS[7:0] are compared  */
490 #define RTC_ALARMSUBSECONDMASK_SS14_9       (RTC_ALRMASSR_MASKSS_0 | RTC_ALRMASSR_MASKSS_3)                          /*!< SS[14:9] are don't care in Alarm
491                                                                                                                           comparison. Only SS[8:0] are compared  */
492 #define RTC_ALARMSUBSECONDMASK_SS14_10      (RTC_ALRMASSR_MASKSS_1 | RTC_ALRMASSR_MASKSS_3)                          /*!< SS[14:10] are don't care in Alarm
493                                                                                                                           comparison. Only SS[9:0] are compared  */
494 #define RTC_ALARMSUBSECONDMASK_SS14_11      (RTC_ALRMASSR_MASKSS_0 | RTC_ALRMASSR_MASKSS_1 | RTC_ALRMASSR_MASKSS_3)  /*!< SS[14:11] are don't care in Alarm
495                                                                                                                           comparison. Only SS[10:0] are compared */
496 #define RTC_ALARMSUBSECONDMASK_SS14_12      (RTC_ALRMASSR_MASKSS_2 | RTC_ALRMASSR_MASKSS_3)                          /*!< SS[14:12] are don't care in Alarm
497                                                                                                                           comparison.Only SS[11:0] are compared  */
498 #define RTC_ALARMSUBSECONDMASK_SS14_13      (RTC_ALRMASSR_MASKSS_0 | RTC_ALRMASSR_MASKSS_2 | RTC_ALRMASSR_MASKSS_3)  /*!< SS[14:13] are don't care in Alarm
499                                                                                                                           comparison. Only SS[12:0] are compared */
500 #define RTC_ALARMSUBSECONDMASK_SS14         (RTC_ALRMASSR_MASKSS_1 | RTC_ALRMASSR_MASKSS_2 | RTC_ALRMASSR_MASKSS_3)  /*!< SS[14] is don't care in Alarm
501                                                                                                                           comparison.Only SS[13:0] are compared  */
502 #define RTC_ALARMSUBSECONDMASK_NONE         RTC_ALRMASSR_MASKSS                                                      /*!< SS[14:0] are compared and must match
503                                                                                                                           to activate alarm. */
504 /**
505   * @}
506   */
507 
508 /** @defgroup RTC_Interrupts_Definitions RTC Interrupts Definitions
509   * @{
510   */
511 #define RTC_IT_TS                           RTC_CR_TSIE        /*!< Enable Timestamp Interrupt    */
512 #define RTC_IT_WUT                          RTC_CR_WUTIE       /*!< Enable Wakeup timer Interrupt */
513 #if defined (STM32L4P5xx) || defined (STM32L4Q5xx)
514 #define RTC_IT_SSRU                         RTC_CR_SSRUIE      /*!< Enable SSR Underflow Interrupt */
515 #endif
516 #define RTC_IT_ALRA                         RTC_CR_ALRAIE      /*!< Enable Alarm A Interrupt      */
517 #define RTC_IT_ALRB                         RTC_CR_ALRBIE      /*!< Enable Alarm B Interrupt      */
518 /**
519   * @}
520   */
521 
522 #if defined(STM32L412xx) || defined(STM32L422xx) || defined (STM32L4P5xx) || defined (STM32L4Q5xx)
523 /** @defgroup RTC_Flag_Mask    RTC Flag Mask (5bits) describe in RTC_Flags_Definitions
524   * @{
525   */
526 #define RTC_FLAG_MASK                       0x001Fu            /*!< RTC flags mask (5bits) */
527 /**
528   * @}
529   */
530 
531 /** @defgroup RTC_Flags_Definitions RTC Flags Definitions
532   *        Elements values convention: 000000XX000YYYYYb
533   *           - YYYYY  : Interrupt flag position in the XX register (5bits)
534   *           - XX  : Interrupt status register (2bits)
535   *                 - 01: ICSR register
536   *                 - 10: SR or SCR or MISR or SMISR registers
537   * @{
538   */
539 #define RTC_FLAG_RECALPF                    (0x00000100U | RTC_ICSR_RECALPF_Pos) /*!< Recalibration pending Flag */
540 #define RTC_FLAG_INITF                      (0x00000100U | RTC_ICSR_INITF_Pos)   /*!< Initialization flag */
541 #define RTC_FLAG_RSF                        (0x00000100U | RTC_ICSR_RSF_Pos)     /*!< Registers synchronization flag */
542 #define RTC_FLAG_INITS                      (0x00000100U | RTC_ICSR_INITS_Pos)   /*!< Initialization status flag */
543 #define RTC_FLAG_SHPF                       (0x00000100U | RTC_ICSR_SHPF_Pos)    /*!< Shift operation pending flag */
544 #define RTC_FLAG_WUTWF                      (0x00000100U | RTC_ICSR_WUTWF_Pos)   /*!< Wakeup timer write flag */
545 #if defined (STM32L4P5xx) || defined (STM32L4Q5xx)
546 #define RTC_FLAG_SSRUF                      (0x00000200U | RTC_SR_SSRUF_Pos)     /*!< SSR underflow flag */
547 #endif
548 #define RTC_FLAG_ITSF                       (0x00000200U | RTC_SR_ITSF_Pos)      /*!< Internal Time-stamp flag */
549 #define RTC_FLAG_TSOVF                      (0x00000200U | RTC_SR_TSOVF_Pos)     /*!< Time-stamp overflow flag */
550 #define RTC_FLAG_TSF                        (0x00000200U | RTC_SR_TSF_Pos)       /*!< Time-stamp flag */
551 #define RTC_FLAG_WUTF                       (0x00000200U | RTC_SR_WUTF_Pos)      /*!< Wakeup timer flag */
552 #define RTC_FLAG_ALRBF                      (0x00000200U | RTC_SR_ALRBF_Pos)     /*!< Alarm B flag */
553 #define RTC_FLAG_ALRAF                      (0x00000200U | RTC_SR_ALRAF_Pos)     /*!< Alarm A flag */
554 /**
555   * @}
556   */
557 
558 /** @defgroup RTC_Clear_Flags_Definitions RTC Clear Flags Definitions
559   * @{
560   */
561 #if defined (STM32L4P5xx) || defined (STM32L4Q5xx)
562 #define RTC_CLEAR_SSRUF                     RTC_SCR_CSSRUF   /*!< Clear SSR underflow flag */
563 #endif
564 #define RTC_CLEAR_ITSF                      RTC_SCR_CITSF    /*!< Clear Internal Time-stamp flag */
565 #define RTC_CLEAR_TSOVF                     RTC_SCR_CTSOVF   /*!< Clear Time-stamp overflow flag */
566 #define RTC_CLEAR_TSF                       RTC_SCR_CTSF     /*!< Clear Time-stamp flag */
567 #define RTC_CLEAR_WUTF                      RTC_SCR_CWUTF    /*!< Clear Wakeup timer flag */
568 #define RTC_CLEAR_ALRBF                     RTC_SCR_CALRBF   /*!< Clear Alarm B flag */
569 #define RTC_CLEAR_ALRAF                     RTC_SCR_CALRAF   /*!< Clear Alarm A flag */
570 
571 /**
572   * @}
573   */
574 
575 #else /* #if defined(STM32L412xx) || defined(STM32L422xx) || defined (STM32L4P5xx) || defined (STM32L4Q5xx) */
576 
577 /** @defgroup RTC_Flags_Definitions RTC Flags Definitions
578   * @{
579   */
580 #define RTC_FLAG_RECALPF                    RTC_ISR_RECALPF
581 #define RTC_FLAG_TSOVF                      RTC_ISR_TSOVF
582 #define RTC_FLAG_TSF                        RTC_ISR_TSF
583 #define RTC_FLAG_ITSF                       RTC_ISR_ITSF
584 #define RTC_FLAG_WUTF                       RTC_ISR_WUTF
585 #define RTC_FLAG_ALRBF                      RTC_ISR_ALRBF
586 #define RTC_FLAG_ALRAF                      RTC_ISR_ALRAF
587 #define RTC_FLAG_INITF                      RTC_ISR_INITF
588 #define RTC_FLAG_RSF                        RTC_ISR_RSF
589 #define RTC_FLAG_INITS                      RTC_ISR_INITS
590 #define RTC_FLAG_SHPF                       RTC_ISR_SHPF
591 #define RTC_FLAG_WUTWF                      RTC_ISR_WUTWF
592 #define RTC_FLAG_ALRBWF                     RTC_ISR_ALRBWF
593 #define RTC_FLAG_ALRAWF                     RTC_ISR_ALRAWF
594 /**
595   * @}
596   */
597 #endif /* #if defined(STM32L412xx) || defined(STM32L422xx) || defined (STM32L4P5xx) || defined (STM32L4Q5xx) */
598 
599 /**
600   * @}
601   */
602 
603 /* Exported macros -----------------------------------------------------------*/
604 /** @defgroup RTC_Exported_Macros RTC Exported Macros
605   * @{
606   */
607 
608 /** @brief Reset RTC handle state
609   * @param  __HANDLE__ RTC handle.
610   * @retval None
611   */
612 #if (USE_HAL_RTC_REGISTER_CALLBACKS == 1)
613 #define __HAL_RTC_RESET_HANDLE_STATE(__HANDLE__) do{\
614                                                       (__HANDLE__)->State = HAL_RTC_STATE_RESET;\
615                                                       (__HANDLE__)->MspInitCallback = NULL;\
616                                                       (__HANDLE__)->MspDeInitCallback = NULL;\
617                                                      }while(0u)
618 #else
619 #define __HAL_RTC_RESET_HANDLE_STATE(__HANDLE__) ((__HANDLE__)->State = HAL_RTC_STATE_RESET)
620 #endif /* USE_HAL_RTC_REGISTER_CALLBACKS */
621 
622 /**
623   * @brief  Disable the write protection for RTC registers.
624   * @param  __HANDLE__ specifies the RTC handle.
625   * @retval None
626   */
627 #define __HAL_RTC_WRITEPROTECTION_DISABLE(__HANDLE__)             \
628                         do{                                       \
629                             (__HANDLE__)->Instance->WPR = 0xCAU;   \
630                             (__HANDLE__)->Instance->WPR = 0x53U;   \
631                           } while(0u)
632 
633 /**
634   * @brief  Enable the write protection for RTC registers.
635   * @param  __HANDLE__ specifies the RTC handle.
636   * @retval None
637   */
638 #define __HAL_RTC_WRITEPROTECTION_ENABLE(__HANDLE__)              \
639                         do{                                       \
640                             (__HANDLE__)->Instance->WPR = 0xFFU;   \
641                           } while(0u)
642 
643 /**
644   * @brief  Check whether if the RTC Calendar is initialized.
645   * @param  __HANDLE__ specifies the RTC handle.
646   * @retval None
647   */
648 #if defined(STM32L412xx) || defined(STM32L422xx) || defined (STM32L4P5xx) || defined (STM32L4Q5xx)
649 #define __HAL_RTC_IS_CALENDAR_INITIALIZED(__HANDLE__)  ((((RTC->ICSR) & (RTC_ICSR_INITS)) == RTC_ICSR_INITS) ? 1U : 0U)
650 #else
651 #define __HAL_RTC_IS_CALENDAR_INITIALIZED(__HANDLE__)  (((((__HANDLE__)->Instance->ISR) & (RTC_FLAG_INITS)) == RTC_FLAG_INITS) ? 1U : 0U)
652 #endif /* #if defined(STM32L412xx) || defined(STM32L422xx) || defined (STM32L4P5xx) || defined (STM32L4Q5xx) */
653 
654 /**
655   * @brief  Add 1 hour (summer time change).
656   * @note   This interface is deprecated.
657   *         To manage Daylight Saving Time, please use HAL_RTC_DST_xxx functions
658   * @param  __HANDLE__ specifies the RTC handle.
659   * @param  __BKP__ Backup
660   *         This parameter can be:
661   *            @arg @ref RTC_STOREOPERATION_RESET
662   *            @arg @ref RTC_STOREOPERATION_SET
663   * @retval None
664   */
665 #define __HAL_RTC_DAYLIGHT_SAVING_TIME_ADD1H(__HANDLE__, __BKP__)                         \
666                         do {                                                              \
667                             __HAL_RTC_WRITEPROTECTION_DISABLE(__HANDLE__);                \
668                             SET_BIT((__HANDLE__)->Instance->CR, RTC_CR_ADD1H);            \
669                             MODIFY_REG((__HANDLE__)->Instance->CR, RTC_CR_BKP , (__BKP__)); \
670                             __HAL_RTC_WRITEPROTECTION_ENABLE(__HANDLE__);                 \
671                         } while(0u);
672 
673 /**
674   * @brief  Subtract 1 hour (winter time change).
675   * @note   This interface is deprecated.
676   *         To manage Daylight Saving Time, please use HAL_RTC_DST_xxx functions
677   * @param  __HANDLE__ specifies the RTC handle.
678   * @param  __BKP__ Backup
679   *         This parameter can be:
680   *            @arg @ref RTC_STOREOPERATION_RESET
681   *            @arg @ref RTC_STOREOPERATION_SET
682   * @retval None
683   */
684 #define __HAL_RTC_DAYLIGHT_SAVING_TIME_SUB1H(__HANDLE__, __BKP__)                         \
685                         do {                                                              \
686                             __HAL_RTC_WRITEPROTECTION_DISABLE(__HANDLE__);                \
687                             SET_BIT((__HANDLE__)->Instance->CR, RTC_CR_SUB1H);            \
688                             MODIFY_REG((__HANDLE__)->Instance->CR, RTC_CR_BKP , (__BKP__)); \
689                             __HAL_RTC_WRITEPROTECTION_ENABLE(__HANDLE__);                 \
690                         } while(0u);
691 
692 /**
693  * @brief  Enable the RTC ALARMA peripheral.
694  * @param  __HANDLE__ specifies the RTC handle.
695  * @retval None
696  */
697 #define __HAL_RTC_ALARMA_ENABLE(__HANDLE__)  ((__HANDLE__)->Instance->CR |= (RTC_CR_ALRAE))
698 
699 /**
700   * @brief  Disable the RTC ALARMA peripheral.
701   * @param  __HANDLE__ specifies the RTC handle.
702   * @retval None
703   */
704 #define __HAL_RTC_ALARMA_DISABLE(__HANDLE__)  ((__HANDLE__)->Instance->CR &= ~(RTC_CR_ALRAE))
705 
706 /**
707   * @brief  Enable the RTC ALARMB peripheral.
708   * @param  __HANDLE__ specifies the RTC handle.
709   * @retval None
710   */
711 #define __HAL_RTC_ALARMB_ENABLE(__HANDLE__)   ((__HANDLE__)->Instance->CR |= (RTC_CR_ALRBE))
712 
713 /**
714   * @brief  Disable the RTC ALARMB peripheral.
715   * @param  __HANDLE__ specifies the RTC handle.
716   * @retval None
717   */
718 #define __HAL_RTC_ALARMB_DISABLE(__HANDLE__)  ((__HANDLE__)->Instance->CR &= ~(RTC_CR_ALRBE))
719 
720 /**
721   * @brief  Enable the RTC Alarm interrupt.
722   * @param  __HANDLE__ specifies the RTC handle.
723   * @param  __INTERRUPT__ specifies the RTC Alarm interrupt sources to be enabled or disabled.
724   *          This parameter can be any combination of the following values:
725   *             @arg @ref RTC_IT_ALRA Alarm A interrupt
726   *             @arg @ref RTC_IT_ALRB Alarm B interrupt
727   * @retval None
728   */
729 #define __HAL_RTC_ALARM_ENABLE_IT(__HANDLE__, __INTERRUPT__)   ((__HANDLE__)->Instance->CR |= (__INTERRUPT__))
730 
731 /**
732   * @brief  Disable the RTC Alarm interrupt.
733   * @param  __HANDLE__ specifies the RTC handle.
734   * @param  __INTERRUPT__ specifies the RTC Alarm interrupt sources to be enabled or disabled.
735   *         This parameter can be any combination of the following values:
736   *            @arg @ref RTC_IT_ALRA Alarm A interrupt
737   *            @arg @ref RTC_IT_ALRB Alarm B interrupt
738   * @retval None
739   */
740 #define __HAL_RTC_ALARM_DISABLE_IT(__HANDLE__, __INTERRUPT__) ((__HANDLE__)->Instance->CR &= ~(__INTERRUPT__))
741 
742 /**
743   * @brief  Check whether the specified RTC Alarm interrupt has occurred or not.
744   * @param  __HANDLE__ specifies the RTC handle.
745   * @param  __INTERRUPT__ specifies the RTC Alarm interrupt sources to check.
746   *         This parameter can be:
747   *            @arg @ref RTC_IT_ALRA Alarm A interrupt
748   *            @arg @ref RTC_IT_ALRB Alarm B interrupt
749   * @retval None
750   */
751 #if defined(STM32L412xx) || defined(STM32L422xx) || defined (STM32L4P5xx) || defined (STM32L4Q5xx)
752 #define __HAL_RTC_ALARM_GET_IT(__HANDLE__, __INTERRUPT__) (((((__HANDLE__)->Instance->MISR)& (__INTERRUPT__ >> 12)) != 0U)? 1U : 0U)
753 #else
754 #define __HAL_RTC_ALARM_GET_IT(__HANDLE__, __INTERRUPT__) (((((__HANDLE__)->Instance->ISR)& (__INTERRUPT__ >> 4)) != 0U)? 1U : 0U)
755 #endif
756 /**
757   * @brief  Check whether the specified RTC Alarm interrupt has been enabled or not.
758   * @param  __HANDLE__ specifies the RTC handle.
759   * @param  __INTERRUPT__ specifies the RTC Alarm interrupt sources to check.
760   *         This parameter can be:
761   *            @arg @ref RTC_IT_ALRA Alarm A interrupt
762   *            @arg @ref RTC_IT_ALRB Alarm B interrupt
763   * @retval None
764   */
765 #define __HAL_RTC_ALARM_GET_IT_SOURCE(__HANDLE__, __INTERRUPT__)     (((((__HANDLE__)->Instance->CR) & (__INTERRUPT__)) != 0U) ? 1U : 0U)
766 
767 #if defined(STM32L412xx) || defined(STM32L422xx) || defined (STM32L4P5xx) || defined (STM32L4Q5xx)
768 /**
769   * @brief  Get the selected RTC Alarm's flag status.
770   * @param  __HANDLE__ specifies the RTC handle.
771   * @param  __FLAG__ specifies the RTC Alarm Flag sources to check.
772   *         This parameter can be:
773   *            @arg @ref RTC_FLAG_ALRAF
774   *            @arg @ref RTC_FLAG_ALRBF
775   * @retval None
776   */
777 #define __HAL_RTC_ALARM_GET_FLAG(__HANDLE__, __FLAG__)   (__HAL_RTC_GET_FLAG((__HANDLE__), (__FLAG__)))
778 
779 #else /* #if defined(STM32L412xx) || defined(STM32L422xx) || defined (STM32L4P5xx) || defined (STM32L4Q5xx) */
780 
781 /**
782   * @brief  Get the selected RTC Alarm's flag status.
783   * @param  __HANDLE__ specifies the RTC handle.
784   * @param  __FLAG__ specifies the RTC Alarm Flag sources to check.
785   *         This parameter can be:
786   *            @arg @ref RTC_FLAG_ALRAF
787   *            @arg @ref RTC_FLAG_ALRBF
788   *            @arg @ref RTC_FLAG_ALRAWF
789   *            @arg @ref RTC_FLAG_ALRBWF
790   * @retval None
791   */
792 #define __HAL_RTC_ALARM_GET_FLAG(__HANDLE__, __FLAG__)  (((((__HANDLE__)->Instance->ISR) & (__FLAG__)) != 0U) ? 1U : 0U)
793 #endif /* #if defined(STM32L412xx) || defined(STM32L422xx) || defined (STM32L4P5xx) || defined (STM32L4Q5xx) */
794 
795 /**
796   * @brief  Clear the RTC Alarm's pending flags.
797   * @param  __HANDLE__ specifies the RTC handle.
798   * @param  __FLAG__ specifies the RTC Alarm Flag sources to clear.
799   *          This parameter can be:
800   *             @arg @ref RTC_FLAG_ALRAF
801   *             @arg @ref RTC_FLAG_ALRBF
802   * @retval None
803   */
804 #if defined(STM32L412xx) || defined(STM32L422xx) || defined (STM32L4P5xx) || defined (STM32L4Q5xx)
805 #define __HAL_RTC_ALARM_CLEAR_FLAG(__HANDLE__, __FLAG__)   (((__FLAG__) == RTC_FLAG_ALRAF) ? (((__HANDLE__)->Instance->SCR = (RTC_CLEAR_ALRAF))) : \
806                                                            ((__HANDLE__)->Instance->SCR = (RTC_CLEAR_ALRBF)))
807 #else
808 #define __HAL_RTC_ALARM_CLEAR_FLAG(__HANDLE__, __FLAG__)  ((__HANDLE__)->Instance->ISR = (~((__FLAG__) | RTC_ISR_INIT)|((__HANDLE__)->Instance->ISR & RTC_ISR_INIT)))
809 #endif
810 
811 /**
812   * @brief  Enable interrupt on the RTC Alarm associated Exti line.
813   * @retval None
814   */
815 #define __HAL_RTC_ALARM_EXTI_ENABLE_IT()            (EXTI->IMR1 |= RTC_EXTI_LINE_ALARM_EVENT)
816 
817 /**
818   * @brief  Disable interrupt on the RTC Alarm associated Exti line.
819   * @retval None
820   */
821 #define __HAL_RTC_ALARM_EXTI_DISABLE_IT()           (EXTI->IMR1 &= ~(RTC_EXTI_LINE_ALARM_EVENT))
822 
823 /**
824   * @brief  Enable event on the RTC Alarm associated Exti line.
825   * @retval None.
826   */
827 #define __HAL_RTC_ALARM_EXTI_ENABLE_EVENT()         (EXTI->EMR1 |= RTC_EXTI_LINE_ALARM_EVENT)
828 
829 /**
830   * @brief  Disable event on the RTC Alarm associated Exti line.
831   * @retval None.
832   */
833 #define __HAL_RTC_ALARM_EXTI_DISABLE_EVENT()         (EXTI->EMR1 &= ~(RTC_EXTI_LINE_ALARM_EVENT))
834 
835 /**
836   * @brief  Enable falling edge trigger on the RTC Alarm associated Exti line.
837   * @retval None
838   */
839 #define __HAL_RTC_ALARM_EXTI_ENABLE_FALLING_EDGE()   (EXTI->FTSR1 |= RTC_EXTI_LINE_ALARM_EVENT)
840 
841 /**
842   * @brief  Disable falling edge trigger on the RTC Alarm associated Exti line.
843   * @retval None
844   */
845 #define __HAL_RTC_ALARM_EXTI_DISABLE_FALLING_EDGE()  (EXTI->FTSR1 &= ~(RTC_EXTI_LINE_ALARM_EVENT))
846 
847 /**
848   * @brief  Enable rising edge trigger on the RTC Alarm associated Exti line.
849   * @retval None
850   */
851 #define __HAL_RTC_ALARM_EXTI_ENABLE_RISING_EDGE()    (EXTI->RTSR1 |= RTC_EXTI_LINE_ALARM_EVENT)
852 
853 /**
854   * @brief  Disable rising edge trigger on the RTC Alarm associated Exti line.
855   * @retval None
856   */
857 #define __HAL_RTC_ALARM_EXTI_DISABLE_RISING_EDGE()   (EXTI->RTSR1 &= ~(RTC_EXTI_LINE_ALARM_EVENT))
858 
859 /**
860   * @brief  Enable rising & falling edge trigger on the RTC Alarm associated Exti line.
861   * @retval None
862   */
863 #define __HAL_RTC_ALARM_EXTI_ENABLE_RISING_FALLING_EDGE()  do { \
864                                                              __HAL_RTC_ALARM_EXTI_ENABLE_RISING_EDGE();  \
865                                                              __HAL_RTC_ALARM_EXTI_ENABLE_FALLING_EDGE(); \
866                                                            } while(0u)
867 
868 /**
869   * @brief  Disable rising & falling edge trigger on the RTC Alarm associated Exti line.
870   * @retval None
871   */
872 #define __HAL_RTC_ALARM_EXTI_DISABLE_RISING_FALLING_EDGE() do { \
873                                                              __HAL_RTC_ALARM_EXTI_DISABLE_RISING_EDGE();  \
874                                                              __HAL_RTC_ALARM_EXTI_DISABLE_FALLING_EDGE(); \
875                                                            } while(0u)
876 
877 /**
878   * @brief Check whether the RTC Alarm associated Exti line interrupt flag is set or not.
879   * @retval Line Status.
880   */
881 #define __HAL_RTC_ALARM_EXTI_GET_FLAG()              (EXTI->PR1 & RTC_EXTI_LINE_ALARM_EVENT)
882 
883 /**
884   * @brief Clear the RTC Alarm associated Exti line flag.
885   * @retval None
886   */
887 #define __HAL_RTC_ALARM_EXTI_CLEAR_FLAG()            (EXTI->PR1 = RTC_EXTI_LINE_ALARM_EVENT)
888 
889 /**
890   * @brief Generate a Software interrupt on RTC Alarm associated Exti line.
891   * @retval None
892   */
893 #define __HAL_RTC_ALARM_EXTI_GENERATE_SWIT()         (EXTI->SWIER1 |= RTC_EXTI_LINE_ALARM_EVENT)
894 
895 /**
896   * @}
897   */
898 
899 /* Include RTC HAL Extended module */
900 #include "stm32l4xx_hal_rtc_ex.h"
901 
902 /* Exported functions --------------------------------------------------------*/
903 /** @defgroup RTC_Exported_Functions RTC Exported Functions
904   * @{
905   */
906 
907 /** @defgroup RTC_Exported_Functions_Group1 Initialization and de-initialization functions
908   * @{
909   */
910 /* Initialization and de-initialization functions  ****************************/
911 HAL_StatusTypeDef HAL_RTC_Init(RTC_HandleTypeDef *hrtc);
912 HAL_StatusTypeDef HAL_RTC_DeInit(RTC_HandleTypeDef *hrtc);
913 
914 void HAL_RTC_MspInit(RTC_HandleTypeDef *hrtc);
915 void HAL_RTC_MspDeInit(RTC_HandleTypeDef *hrtc);
916 
917 /* Callbacks Register/UnRegister functions  ***********************************/
918 #if (USE_HAL_RTC_REGISTER_CALLBACKS == 1)
919 HAL_StatusTypeDef HAL_RTC_RegisterCallback(RTC_HandleTypeDef *hrtc, HAL_RTC_CallbackIDTypeDef CallbackID, pRTC_CallbackTypeDef pCallback);
920 HAL_StatusTypeDef HAL_RTC_UnRegisterCallback(RTC_HandleTypeDef *hrtc, HAL_RTC_CallbackIDTypeDef CallbackID);
921 #endif /* (USE_HAL_RTC_REGISTER_CALLBACKS == 1) */
922 /**
923   * @}
924   */
925 
926 /** @defgroup RTC_Exported_Functions_Group2 RTC Time and Date functions
927   * @{
928   */
929 /* RTC Time and Date functions ************************************************/
930 HAL_StatusTypeDef HAL_RTC_SetTime(RTC_HandleTypeDef *hrtc, RTC_TimeTypeDef *sTime, uint32_t Format);
931 HAL_StatusTypeDef HAL_RTC_GetTime(RTC_HandleTypeDef *hrtc, RTC_TimeTypeDef *sTime, uint32_t Format);
932 HAL_StatusTypeDef HAL_RTC_SetDate(RTC_HandleTypeDef *hrtc, RTC_DateTypeDef *sDate, uint32_t Format);
933 HAL_StatusTypeDef HAL_RTC_GetDate(RTC_HandleTypeDef *hrtc, RTC_DateTypeDef *sDate, uint32_t Format);
934 void              HAL_RTC_DST_Add1Hour(RTC_HandleTypeDef *hrtc);
935 void              HAL_RTC_DST_Sub1Hour(RTC_HandleTypeDef *hrtc);
936 void              HAL_RTC_DST_SetStoreOperation(RTC_HandleTypeDef *hrtc);
937 void              HAL_RTC_DST_ClearStoreOperation(RTC_HandleTypeDef *hrtc);
938 uint32_t          HAL_RTC_DST_ReadStoreOperation(RTC_HandleTypeDef *hrtc);
939 /**
940   * @}
941   */
942 
943 /** @defgroup RTC_Exported_Functions_Group3 RTC Alarm functions
944   * @{
945   */
946 /* RTC Alarm functions ********************************************************/
947 HAL_StatusTypeDef HAL_RTC_SetAlarm(RTC_HandleTypeDef *hrtc, RTC_AlarmTypeDef *sAlarm, uint32_t Format);
948 HAL_StatusTypeDef HAL_RTC_SetAlarm_IT(RTC_HandleTypeDef *hrtc, RTC_AlarmTypeDef *sAlarm, uint32_t Format);
949 HAL_StatusTypeDef HAL_RTC_DeactivateAlarm(RTC_HandleTypeDef *hrtc, uint32_t Alarm);
950 HAL_StatusTypeDef HAL_RTC_GetAlarm(RTC_HandleTypeDef *hrtc, RTC_AlarmTypeDef *sAlarm, uint32_t Alarm, uint32_t Format);
951 void              HAL_RTC_AlarmIRQHandler(RTC_HandleTypeDef *hrtc);
952 void              HAL_RTC_AlarmAEventCallback(RTC_HandleTypeDef *hrtc);
953 HAL_StatusTypeDef HAL_RTC_PollForAlarmAEvent(RTC_HandleTypeDef *hrtc, uint32_t Timeout);
954 /**
955   * @}
956   */
957 
958 /** @defgroup  RTC_Exported_Functions_Group4 Peripheral Control functions
959   * @{
960   */
961 /* Peripheral Control functions ***********************************************/
962 HAL_StatusTypeDef   HAL_RTC_WaitForSynchro(RTC_HandleTypeDef *hrtc);
963 /**
964   * @}
965   */
966 
967 /** @defgroup RTC_Exported_Functions_Group5 Peripheral State functions
968   * @{
969   */
970 /* Peripheral State functions *************************************************/
971 HAL_RTCStateTypeDef HAL_RTC_GetState(RTC_HandleTypeDef *hrtc);
972 /**
973   * @}
974   */
975 
976 /**
977   * @}
978   */
979 
980 /* Private types -------------------------------------------------------------*/
981 /* Private variables ---------------------------------------------------------*/
982 /* Private constants ---------------------------------------------------------*/
983 /** @defgroup RTC_Private_Constants RTC Private Constants
984   * @{
985   */
986 /* Masks Definition */
987 #define RTC_TR_RESERVED_MASK                (RTC_TR_PM | RTC_TR_HT | RTC_TR_HU | \
988                                             RTC_TR_MNT | RTC_TR_MNU| RTC_TR_ST | \
989                                             RTC_TR_SU)
990 
991 #define RTC_DR_RESERVED_MASK                (RTC_DR_YT | RTC_DR_YU | RTC_DR_WDU | \
992                                             RTC_DR_MT | RTC_DR_MU | RTC_DR_DT  | \
993                                             RTC_DR_DU)
994 
995 #define RTC_INIT_MASK                       0xFFFFFFFFu
996 
997 #if defined(STM32L412xx) || defined(STM32L422xx)
998 #define RTC_ICSR_RESERVED_MASK              0x000100FCu
999 #define RTC_RSF_MASK                        (~(RTC_ICSR_INIT | RTC_ICSR_RSF))
1000 #elif defined (STM32L4P5xx) || defined (STM32L4Q5xx)
1001 #define RTC_ICSR_RESERVED_MASK              0x00011FFCu
1002 #define RTC_RSF_MASK                        (~(RTC_ICSR_INIT | RTC_ICSR_RSF))
1003 #else
1004 #define RTC_ISR_RESERVED_MASK               0x0003FFFFu
1005 #define RTC_RSF_MASK                        (~(RTC_ISR_INIT | RTC_ISR_RSF))
1006 #endif
1007 
1008 #define RTC_TIMEOUT_VALUE                   1000u
1009 
1010 #define RTC_EXTI_LINE_ALARM_EVENT           EXTI_IMR1_IM18  /*!< External interrupt line 18 Connected to the RTC Alarm event */
1011 
1012 /**
1013   * @}
1014   */
1015 
1016 /* Private macros ------------------------------------------------------------*/
1017 /** @defgroup RTC_Private_Macros RTC Private Macros
1018   * @{
1019   */
1020 
1021 /** @defgroup RTC_IS_RTC_Definitions RTC Private macros to check input parameters
1022   * @{
1023   */
1024 #if defined(STM32L412xx) || defined(STM32L422xx) || defined (STM32L4P5xx) || defined (STM32L4Q5xx)
1025 #define IS_RTC_OUTPUT(OUTPUT) (((OUTPUT) == RTC_OUTPUT_DISABLE) || \
1026                                 ((OUTPUT) == RTC_OUTPUT_ALARMA)  || \
1027                                 ((OUTPUT) == RTC_OUTPUT_ALARMB)  || \
1028                                 ((OUTPUT) == RTC_OUTPUT_WAKEUP)  || \
1029                                 ((OUTPUT) == RTC_OUTPUT_TAMPER))
1030 #else
1031 #define IS_RTC_OUTPUT(OUTPUT) (((OUTPUT) == RTC_OUTPUT_DISABLE) || \
1032                                ((OUTPUT) == RTC_OUTPUT_ALARMA)  || \
1033                                ((OUTPUT) == RTC_OUTPUT_ALARMB)  || \
1034                                ((OUTPUT) == RTC_OUTPUT_WAKEUP))
1035 #endif
1036 
1037 #define IS_RTC_HOUR_FORMAT(FORMAT)     (((FORMAT) == RTC_HOURFORMAT_12) || \
1038                                         ((FORMAT) == RTC_HOURFORMAT_24))
1039 
1040 #define IS_RTC_OUTPUT_POL(POL) (((POL) == RTC_OUTPUT_POLARITY_HIGH) || \
1041                                 ((POL) == RTC_OUTPUT_POLARITY_LOW))
1042 
1043 #define IS_RTC_OUTPUT_TYPE(TYPE) (((TYPE) == RTC_OUTPUT_TYPE_OPENDRAIN) || \
1044                                   ((TYPE) == RTC_OUTPUT_TYPE_PUSHPULL))
1045 
1046 #if defined(STM32L412xx) || defined(STM32L422xx) || defined (STM32L4P5xx) || defined (STM32L4Q5xx)
1047 #define IS_RTC_OUTPUT_PULLUP(TYPE) (((TYPE) == RTC_OUTPUT_PULLUP_NONE) || \
1048                                     ((TYPE) == RTC_OUTPUT_PULLUP_ON))
1049 #endif
1050 
1051 #define IS_RTC_OUTPUT_REMAP(REMAP)   (((REMAP) == RTC_OUTPUT_REMAP_NONE) || \
1052                                       ((REMAP) == RTC_OUTPUT_REMAP_POS1))
1053 
1054 #define IS_RTC_HOURFORMAT12(PM)  (((PM) == RTC_HOURFORMAT12_AM) || \
1055                                   ((PM) == RTC_HOURFORMAT12_PM))
1056 
1057 #define IS_RTC_DAYLIGHT_SAVING(SAVE) (((SAVE) == RTC_DAYLIGHTSAVING_SUB1H) || \
1058                                       ((SAVE) == RTC_DAYLIGHTSAVING_ADD1H) || \
1059                                       ((SAVE) == RTC_DAYLIGHTSAVING_NONE))
1060 
1061 #define IS_RTC_STORE_OPERATION(OPERATION) (((OPERATION) == RTC_STOREOPERATION_RESET) || \
1062                                            ((OPERATION) == RTC_STOREOPERATION_SET))
1063 
1064 #define IS_RTC_FORMAT(FORMAT) (((FORMAT) == RTC_FORMAT_BIN) || \
1065                                ((FORMAT) == RTC_FORMAT_BCD))
1066 
1067 #define IS_RTC_YEAR(YEAR)              ((YEAR) <= 99u)
1068 
1069 #define IS_RTC_MONTH(MONTH)            (((MONTH) >= 1u) && ((MONTH) <= 12u))
1070 
1071 #define IS_RTC_DATE(DATE)              (((DATE) >= 1u) && ((DATE) <= 31u))
1072 
1073 #define IS_RTC_WEEKDAY(WEEKDAY) (((WEEKDAY) == RTC_WEEKDAY_MONDAY)    || \
1074                                  ((WEEKDAY) == RTC_WEEKDAY_TUESDAY)   || \
1075                                  ((WEEKDAY) == RTC_WEEKDAY_WEDNESDAY) || \
1076                                  ((WEEKDAY) == RTC_WEEKDAY_THURSDAY)  || \
1077                                  ((WEEKDAY) == RTC_WEEKDAY_FRIDAY)    || \
1078                                  ((WEEKDAY) == RTC_WEEKDAY_SATURDAY)  || \
1079                                  ((WEEKDAY) == RTC_WEEKDAY_SUNDAY))
1080 
1081 #define IS_RTC_ALARM_DATE_WEEKDAY_DATE(DATE) (((DATE) >0u) && ((DATE) <= 31u))
1082 
1083 #define IS_RTC_ALARM_DATE_WEEKDAY_WEEKDAY(WEEKDAY) (((WEEKDAY) == RTC_WEEKDAY_MONDAY)    || \
1084                                                     ((WEEKDAY) == RTC_WEEKDAY_TUESDAY)   || \
1085                                                     ((WEEKDAY) == RTC_WEEKDAY_WEDNESDAY) || \
1086                                                     ((WEEKDAY) == RTC_WEEKDAY_THURSDAY)  || \
1087                                                     ((WEEKDAY) == RTC_WEEKDAY_FRIDAY)    || \
1088                                                     ((WEEKDAY) == RTC_WEEKDAY_SATURDAY)  || \
1089                                                     ((WEEKDAY) == RTC_WEEKDAY_SUNDAY))
1090 
1091 #define IS_RTC_ALARM_DATE_WEEKDAY_SEL(SEL) (((SEL) == RTC_ALARMDATEWEEKDAYSEL_DATE) || \
1092                                             ((SEL) == RTC_ALARMDATEWEEKDAYSEL_WEEKDAY))
1093 
1094 #define IS_RTC_ALARM_MASK(MASK)  (((MASK) & ~(RTC_ALARMMASK_ALL)) == 0U)
1095 
1096 #define IS_RTC_ALARM(ALARM)      (((ALARM) == RTC_ALARM_A) || \
1097                                   ((ALARM) == RTC_ALARM_B))
1098 
1099 #define IS_RTC_ALARM_SUB_SECOND_VALUE(VALUE) ((VALUE) <= RTC_ALRMASSR_SS)
1100 
1101 #define IS_RTC_ALARM_SUB_SECOND_MASK(MASK)          (((MASK) == 0u) || \
1102                                                     (((MASK) >= RTC_ALARMSUBSECONDMASK_SS14_1) && ((MASK) <= RTC_ALARMSUBSECONDMASK_NONE)))
1103 
1104 #define IS_RTC_ASYNCH_PREDIV(PREDIV)   ((PREDIV) <= (RTC_PRER_PREDIV_A >> RTC_PRER_PREDIV_A_Pos))
1105 
1106 #define IS_RTC_SYNCH_PREDIV(PREDIV)    ((PREDIV) <= (RTC_PRER_PREDIV_S >> RTC_PRER_PREDIV_S_Pos))
1107 
1108 #define IS_RTC_HOUR12(HOUR)            (((HOUR) > 0u) && ((HOUR) <= 12u))
1109 
1110 #define IS_RTC_HOUR24(HOUR)            ((HOUR) <= 23u)
1111 
1112 #define IS_RTC_MINUTES(MINUTES)        ((MINUTES) <= 59u)
1113 
1114 #define IS_RTC_SECONDS(SECONDS)        ((SECONDS) <= 59u)
1115 
1116 /**
1117   * @}
1118   */
1119 
1120 /**
1121   * @}
1122   */
1123 
1124 /* Private functions -------------------------------------------------------------*/
1125 /** @defgroup RTC_Private_Functions RTC Private Functions
1126   * @{
1127   */
1128 HAL_StatusTypeDef  RTC_EnterInitMode(RTC_HandleTypeDef *hrtc);
1129 HAL_StatusTypeDef  RTC_ExitInitMode(RTC_HandleTypeDef *hrtc);
1130 uint8_t            RTC_ByteToBcd2(uint8_t Value);
1131 uint8_t            RTC_Bcd2ToByte(uint8_t Value);
1132 /**
1133   * @}
1134   */
1135 
1136 
1137 /**
1138   * @}
1139   */
1140 
1141 /**
1142   * @}
1143   */
1144 
1145 /**
1146   * @}
1147   */
1148 
1149 #ifdef __cplusplus
1150 }
1151 #endif
1152 
1153 #endif /* STM32L4xx_HAL_RTC_H */
1154