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  Add 1 hour (summer time change).
645   * @note   This interface is deprecated.
646   *         To manage Daylight Saving Time, please use HAL_RTC_DST_xxx functions
647   * @param  __HANDLE__ specifies the RTC handle.
648   * @param  __BKP__ Backup
649   *         This parameter can be:
650   *            @arg @ref RTC_STOREOPERATION_RESET
651   *            @arg @ref RTC_STOREOPERATION_SET
652   * @retval None
653   */
654 #define __HAL_RTC_DAYLIGHT_SAVING_TIME_ADD1H(__HANDLE__, __BKP__)                         \
655                         do {                                                              \
656                             __HAL_RTC_WRITEPROTECTION_DISABLE(__HANDLE__);                \
657                             SET_BIT((__HANDLE__)->Instance->CR, RTC_CR_ADD1H);            \
658                             MODIFY_REG((__HANDLE__)->Instance->CR, RTC_CR_BKP , (__BKP__)); \
659                             __HAL_RTC_WRITEPROTECTION_ENABLE(__HANDLE__);                 \
660                         } while(0u);
661 
662 /**
663   * @brief  Subtract 1 hour (winter time change).
664   * @note   This interface is deprecated.
665   *         To manage Daylight Saving Time, please use HAL_RTC_DST_xxx functions
666   * @param  __HANDLE__ specifies the RTC handle.
667   * @param  __BKP__ Backup
668   *         This parameter can be:
669   *            @arg @ref RTC_STOREOPERATION_RESET
670   *            @arg @ref RTC_STOREOPERATION_SET
671   * @retval None
672   */
673 #define __HAL_RTC_DAYLIGHT_SAVING_TIME_SUB1H(__HANDLE__, __BKP__)                         \
674                         do {                                                              \
675                             __HAL_RTC_WRITEPROTECTION_DISABLE(__HANDLE__);                \
676                             SET_BIT((__HANDLE__)->Instance->CR, RTC_CR_SUB1H);            \
677                             MODIFY_REG((__HANDLE__)->Instance->CR, RTC_CR_BKP , (__BKP__)); \
678                             __HAL_RTC_WRITEPROTECTION_ENABLE(__HANDLE__);                 \
679                         } while(0u);
680 
681 /**
682  * @brief  Enable the RTC ALARMA peripheral.
683  * @param  __HANDLE__ specifies the RTC handle.
684  * @retval None
685  */
686 #define __HAL_RTC_ALARMA_ENABLE(__HANDLE__)  ((__HANDLE__)->Instance->CR |= (RTC_CR_ALRAE))
687 
688 /**
689   * @brief  Disable the RTC ALARMA peripheral.
690   * @param  __HANDLE__ specifies the RTC handle.
691   * @retval None
692   */
693 #define __HAL_RTC_ALARMA_DISABLE(__HANDLE__)  ((__HANDLE__)->Instance->CR &= ~(RTC_CR_ALRAE))
694 
695 /**
696   * @brief  Enable the RTC ALARMB peripheral.
697   * @param  __HANDLE__ specifies the RTC handle.
698   * @retval None
699   */
700 #define __HAL_RTC_ALARMB_ENABLE(__HANDLE__)   ((__HANDLE__)->Instance->CR |= (RTC_CR_ALRBE))
701 
702 /**
703   * @brief  Disable the RTC ALARMB peripheral.
704   * @param  __HANDLE__ specifies the RTC handle.
705   * @retval None
706   */
707 #define __HAL_RTC_ALARMB_DISABLE(__HANDLE__)  ((__HANDLE__)->Instance->CR &= ~(RTC_CR_ALRBE))
708 
709 /**
710   * @brief  Enable the RTC Alarm interrupt.
711   * @param  __HANDLE__ specifies the RTC handle.
712   * @param  __INTERRUPT__ specifies the RTC Alarm interrupt sources to be enabled or disabled.
713   *          This parameter can be any combination of the following values:
714   *             @arg @ref RTC_IT_ALRA Alarm A interrupt
715   *             @arg @ref RTC_IT_ALRB Alarm B interrupt
716   * @retval None
717   */
718 #define __HAL_RTC_ALARM_ENABLE_IT(__HANDLE__, __INTERRUPT__)   ((__HANDLE__)->Instance->CR |= (__INTERRUPT__))
719 
720 /**
721   * @brief  Disable 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_DISABLE_IT(__HANDLE__, __INTERRUPT__) ((__HANDLE__)->Instance->CR &= ~(__INTERRUPT__))
730 
731 /**
732   * @brief  Check whether the specified RTC Alarm interrupt has occurred or not.
733   * @param  __HANDLE__ specifies the RTC handle.
734   * @param  __INTERRUPT__ specifies the RTC Alarm interrupt sources to check.
735   *         This parameter can be:
736   *            @arg @ref RTC_IT_ALRA Alarm A interrupt
737   *            @arg @ref RTC_IT_ALRB Alarm B interrupt
738   * @retval None
739   */
740 #if defined(STM32L412xx) || defined(STM32L422xx) || defined (STM32L4P5xx) || defined (STM32L4Q5xx)
741 #define __HAL_RTC_ALARM_GET_IT(__HANDLE__, __INTERRUPT__) (((((__HANDLE__)->Instance->MISR)& (__INTERRUPT__ >> 12)) != 0U)? 1U : 0U)
742 #else
743 #define __HAL_RTC_ALARM_GET_IT(__HANDLE__, __INTERRUPT__) (((((__HANDLE__)->Instance->ISR)& (__INTERRUPT__ >> 4)) != 0U)? 1U : 0U)
744 #endif
745 /**
746   * @brief  Check whether the specified RTC Alarm interrupt has been enabled or not.
747   * @param  __HANDLE__ specifies the RTC handle.
748   * @param  __INTERRUPT__ specifies the RTC Alarm interrupt sources to check.
749   *         This parameter can be:
750   *            @arg @ref RTC_IT_ALRA Alarm A interrupt
751   *            @arg @ref RTC_IT_ALRB Alarm B interrupt
752   * @retval None
753   */
754 #define __HAL_RTC_ALARM_GET_IT_SOURCE(__HANDLE__, __INTERRUPT__)     (((((__HANDLE__)->Instance->CR) & (__INTERRUPT__)) != 0U) ? 1U : 0U)
755 
756 #if defined(STM32L412xx) || defined(STM32L422xx) || defined (STM32L4P5xx) || defined (STM32L4Q5xx)
757 /**
758   * @brief  Get the selected RTC Alarm's flag status.
759   * @param  __HANDLE__ specifies the RTC handle.
760   * @param  __FLAG__ specifies the RTC Alarm Flag sources to check.
761   *         This parameter can be:
762   *            @arg @ref RTC_FLAG_ALRAF
763   *            @arg @ref RTC_FLAG_ALRBF
764   * @retval None
765   */
766 #define __HAL_RTC_ALARM_GET_FLAG(__HANDLE__, __FLAG__)   (__HAL_RTC_GET_FLAG((__HANDLE__), (__FLAG__)))
767 
768 #else /* #if defined(STM32L412xx) || defined(STM32L422xx) || defined (STM32L4P5xx) || defined (STM32L4Q5xx) */
769 
770 /**
771   * @brief  Get the selected RTC Alarm's flag status.
772   * @param  __HANDLE__ specifies the RTC handle.
773   * @param  __FLAG__ specifies the RTC Alarm Flag sources to check.
774   *         This parameter can be:
775   *            @arg @ref RTC_FLAG_ALRAF
776   *            @arg @ref RTC_FLAG_ALRBF
777   *            @arg @ref RTC_FLAG_ALRAWF
778   *            @arg @ref RTC_FLAG_ALRBWF
779   * @retval None
780   */
781 #define __HAL_RTC_ALARM_GET_FLAG(__HANDLE__, __FLAG__)  (((((__HANDLE__)->Instance->ISR) & (__FLAG__)) != 0U) ? 1U : 0U)
782 #endif /* #if defined(STM32L412xx) || defined(STM32L422xx) || defined (STM32L4P5xx) || defined (STM32L4Q5xx) */
783 
784 /**
785   * @brief  Clear the RTC Alarm's pending flags.
786   * @param  __HANDLE__ specifies the RTC handle.
787   * @param  __FLAG__ specifies the RTC Alarm Flag sources to clear.
788   *          This parameter can be:
789   *             @arg @ref RTC_FLAG_ALRAF
790   *             @arg @ref RTC_FLAG_ALRBF
791   * @retval None
792   */
793 #if defined(STM32L412xx) || defined(STM32L422xx) || defined (STM32L4P5xx) || defined (STM32L4Q5xx)
794 #define __HAL_RTC_ALARM_CLEAR_FLAG(__HANDLE__, __FLAG__)   (((__FLAG__) == RTC_FLAG_ALRAF) ? (((__HANDLE__)->Instance->SCR = (RTC_CLEAR_ALRAF))) : \
795                                                            ((__HANDLE__)->Instance->SCR = (RTC_CLEAR_ALRBF)))
796 #else
797 #define __HAL_RTC_ALARM_CLEAR_FLAG(__HANDLE__, __FLAG__)  ((__HANDLE__)->Instance->ISR = (~((__FLAG__) | RTC_ISR_INIT)|((__HANDLE__)->Instance->ISR & RTC_ISR_INIT)))
798 #endif
799 
800 /**
801   * @brief  Enable interrupt on the RTC Alarm associated Exti line.
802   * @retval None
803   */
804 #define __HAL_RTC_ALARM_EXTI_ENABLE_IT()            (EXTI->IMR1 |= RTC_EXTI_LINE_ALARM_EVENT)
805 
806 /**
807   * @brief  Disable interrupt on the RTC Alarm associated Exti line.
808   * @retval None
809   */
810 #define __HAL_RTC_ALARM_EXTI_DISABLE_IT()           (EXTI->IMR1 &= ~(RTC_EXTI_LINE_ALARM_EVENT))
811 
812 /**
813   * @brief  Enable event on the RTC Alarm associated Exti line.
814   * @retval None.
815   */
816 #define __HAL_RTC_ALARM_EXTI_ENABLE_EVENT()         (EXTI->EMR1 |= RTC_EXTI_LINE_ALARM_EVENT)
817 
818 /**
819   * @brief  Disable event on the RTC Alarm associated Exti line.
820   * @retval None.
821   */
822 #define __HAL_RTC_ALARM_EXTI_DISABLE_EVENT()         (EXTI->EMR1 &= ~(RTC_EXTI_LINE_ALARM_EVENT))
823 
824 /**
825   * @brief  Enable falling edge trigger on the RTC Alarm associated Exti line.
826   * @retval None
827   */
828 #define __HAL_RTC_ALARM_EXTI_ENABLE_FALLING_EDGE()   (EXTI->FTSR1 |= RTC_EXTI_LINE_ALARM_EVENT)
829 
830 /**
831   * @brief  Disable falling edge trigger on the RTC Alarm associated Exti line.
832   * @retval None
833   */
834 #define __HAL_RTC_ALARM_EXTI_DISABLE_FALLING_EDGE()  (EXTI->FTSR1 &= ~(RTC_EXTI_LINE_ALARM_EVENT))
835 
836 /**
837   * @brief  Enable rising edge trigger on the RTC Alarm associated Exti line.
838   * @retval None
839   */
840 #define __HAL_RTC_ALARM_EXTI_ENABLE_RISING_EDGE()    (EXTI->RTSR1 |= RTC_EXTI_LINE_ALARM_EVENT)
841 
842 /**
843   * @brief  Disable rising edge trigger on the RTC Alarm associated Exti line.
844   * @retval None
845   */
846 #define __HAL_RTC_ALARM_EXTI_DISABLE_RISING_EDGE()   (EXTI->RTSR1 &= ~(RTC_EXTI_LINE_ALARM_EVENT))
847 
848 /**
849   * @brief  Enable rising & falling edge trigger on the RTC Alarm associated Exti line.
850   * @retval None
851   */
852 #define __HAL_RTC_ALARM_EXTI_ENABLE_RISING_FALLING_EDGE()  do { \
853                                                              __HAL_RTC_ALARM_EXTI_ENABLE_RISING_EDGE();  \
854                                                              __HAL_RTC_ALARM_EXTI_ENABLE_FALLING_EDGE(); \
855                                                            } while(0u)
856 
857 /**
858   * @brief  Disable rising & falling edge trigger on the RTC Alarm associated Exti line.
859   * @retval None
860   */
861 #define __HAL_RTC_ALARM_EXTI_DISABLE_RISING_FALLING_EDGE() do { \
862                                                              __HAL_RTC_ALARM_EXTI_DISABLE_RISING_EDGE();  \
863                                                              __HAL_RTC_ALARM_EXTI_DISABLE_FALLING_EDGE(); \
864                                                            } while(0u)
865 
866 /**
867   * @brief Check whether the RTC Alarm associated Exti line interrupt flag is set or not.
868   * @retval Line Status.
869   */
870 #define __HAL_RTC_ALARM_EXTI_GET_FLAG()              (EXTI->PR1 & RTC_EXTI_LINE_ALARM_EVENT)
871 
872 /**
873   * @brief Clear the RTC Alarm associated Exti line flag.
874   * @retval None
875   */
876 #define __HAL_RTC_ALARM_EXTI_CLEAR_FLAG()            (EXTI->PR1 = RTC_EXTI_LINE_ALARM_EVENT)
877 
878 /**
879   * @brief Generate a Software interrupt on RTC Alarm associated Exti line.
880   * @retval None
881   */
882 #define __HAL_RTC_ALARM_EXTI_GENERATE_SWIT()         (EXTI->SWIER1 |= RTC_EXTI_LINE_ALARM_EVENT)
883 
884 /**
885   * @}
886   */
887 
888 /* Include RTC HAL Extended module */
889 #include "stm32l4xx_hal_rtc_ex.h"
890 
891 /* Exported functions --------------------------------------------------------*/
892 /** @defgroup RTC_Exported_Functions RTC Exported Functions
893   * @{
894   */
895 
896 /** @defgroup RTC_Exported_Functions_Group1 Initialization and de-initialization functions
897   * @{
898   */
899 /* Initialization and de-initialization functions  ****************************/
900 HAL_StatusTypeDef HAL_RTC_Init(RTC_HandleTypeDef *hrtc);
901 HAL_StatusTypeDef HAL_RTC_DeInit(RTC_HandleTypeDef *hrtc);
902 
903 void HAL_RTC_MspInit(RTC_HandleTypeDef *hrtc);
904 void HAL_RTC_MspDeInit(RTC_HandleTypeDef *hrtc);
905 
906 /* Callbacks Register/UnRegister functions  ***********************************/
907 #if (USE_HAL_RTC_REGISTER_CALLBACKS == 1)
908 HAL_StatusTypeDef HAL_RTC_RegisterCallback(RTC_HandleTypeDef *hrtc, HAL_RTC_CallbackIDTypeDef CallbackID, pRTC_CallbackTypeDef pCallback);
909 HAL_StatusTypeDef HAL_RTC_UnRegisterCallback(RTC_HandleTypeDef *hrtc, HAL_RTC_CallbackIDTypeDef CallbackID);
910 #endif /* (USE_HAL_RTC_REGISTER_CALLBACKS == 1) */
911 /**
912   * @}
913   */
914 
915 /** @defgroup RTC_Exported_Functions_Group2 RTC Time and Date functions
916   * @{
917   */
918 /* RTC Time and Date functions ************************************************/
919 HAL_StatusTypeDef HAL_RTC_SetTime(RTC_HandleTypeDef *hrtc, RTC_TimeTypeDef *sTime, uint32_t Format);
920 HAL_StatusTypeDef HAL_RTC_GetTime(RTC_HandleTypeDef *hrtc, RTC_TimeTypeDef *sTime, uint32_t Format);
921 HAL_StatusTypeDef HAL_RTC_SetDate(RTC_HandleTypeDef *hrtc, RTC_DateTypeDef *sDate, uint32_t Format);
922 HAL_StatusTypeDef HAL_RTC_GetDate(RTC_HandleTypeDef *hrtc, RTC_DateTypeDef *sDate, uint32_t Format);
923 void              HAL_RTC_DST_Add1Hour(RTC_HandleTypeDef *hrtc);
924 void              HAL_RTC_DST_Sub1Hour(RTC_HandleTypeDef *hrtc);
925 void              HAL_RTC_DST_SetStoreOperation(RTC_HandleTypeDef *hrtc);
926 void              HAL_RTC_DST_ClearStoreOperation(RTC_HandleTypeDef *hrtc);
927 uint32_t          HAL_RTC_DST_ReadStoreOperation(RTC_HandleTypeDef *hrtc);
928 /**
929   * @}
930   */
931 
932 /** @defgroup RTC_Exported_Functions_Group3 RTC Alarm functions
933   * @{
934   */
935 /* RTC Alarm functions ********************************************************/
936 HAL_StatusTypeDef HAL_RTC_SetAlarm(RTC_HandleTypeDef *hrtc, RTC_AlarmTypeDef *sAlarm, uint32_t Format);
937 HAL_StatusTypeDef HAL_RTC_SetAlarm_IT(RTC_HandleTypeDef *hrtc, RTC_AlarmTypeDef *sAlarm, uint32_t Format);
938 HAL_StatusTypeDef HAL_RTC_DeactivateAlarm(RTC_HandleTypeDef *hrtc, uint32_t Alarm);
939 HAL_StatusTypeDef HAL_RTC_GetAlarm(RTC_HandleTypeDef *hrtc, RTC_AlarmTypeDef *sAlarm, uint32_t Alarm, uint32_t Format);
940 void              HAL_RTC_AlarmIRQHandler(RTC_HandleTypeDef *hrtc);
941 void              HAL_RTC_AlarmAEventCallback(RTC_HandleTypeDef *hrtc);
942 HAL_StatusTypeDef HAL_RTC_PollForAlarmAEvent(RTC_HandleTypeDef *hrtc, uint32_t Timeout);
943 /**
944   * @}
945   */
946 
947 /** @defgroup  RTC_Exported_Functions_Group4 Peripheral Control functions
948   * @{
949   */
950 /* Peripheral Control functions ***********************************************/
951 HAL_StatusTypeDef   HAL_RTC_WaitForSynchro(RTC_HandleTypeDef *hrtc);
952 /**
953   * @}
954   */
955 
956 /** @defgroup RTC_Exported_Functions_Group5 Peripheral State functions
957   * @{
958   */
959 /* Peripheral State functions *************************************************/
960 HAL_RTCStateTypeDef HAL_RTC_GetState(RTC_HandleTypeDef *hrtc);
961 /**
962   * @}
963   */
964 
965 /**
966   * @}
967   */
968 
969 /* Private types -------------------------------------------------------------*/
970 /* Private variables ---------------------------------------------------------*/
971 /* Private constants ---------------------------------------------------------*/
972 /** @defgroup RTC_Private_Constants RTC Private Constants
973   * @{
974   */
975 /* Masks Definition */
976 #define RTC_TR_RESERVED_MASK                (RTC_TR_PM | RTC_TR_HT | RTC_TR_HU | \
977                                             RTC_TR_MNT | RTC_TR_MNU| RTC_TR_ST | \
978                                             RTC_TR_SU)
979 
980 #define RTC_DR_RESERVED_MASK                (RTC_DR_YT | RTC_DR_YU | RTC_DR_WDU | \
981                                             RTC_DR_MT | RTC_DR_MU | RTC_DR_DT  | \
982                                             RTC_DR_DU)
983 
984 #define RTC_INIT_MASK                       0xFFFFFFFFu
985 #if defined(STM32L412xx) || defined(STM32L422xx) || defined (STM32L4P5xx) || defined (STM32L4Q5xx)
986 #define RTC_RSF_MASK                        (~(RTC_ICSR_INIT | RTC_ICSR_RSF))
987 #else
988 #define RTC_RSF_MASK                        (~(RTC_ISR_INIT | RTC_ISR_RSF))
989 #endif
990 
991 #define RTC_TIMEOUT_VALUE                   1000u
992 
993 #define RTC_EXTI_LINE_ALARM_EVENT           EXTI_IMR1_IM18  /*!< External interrupt line 18 Connected to the RTC Alarm event */
994 
995 /**
996   * @}
997   */
998 
999 /* Private macros ------------------------------------------------------------*/
1000 /** @defgroup RTC_Private_Macros RTC Private Macros
1001   * @{
1002   */
1003 
1004 /** @defgroup RTC_IS_RTC_Definitions RTC Private macros to check input parameters
1005   * @{
1006   */
1007 #if defined(STM32L412xx) || defined(STM32L422xx) || defined (STM32L4P5xx) || defined (STM32L4Q5xx)
1008 #define IS_RTC_OUTPUT(OUTPUT) (((OUTPUT) == RTC_OUTPUT_DISABLE) || \
1009                                 ((OUTPUT) == RTC_OUTPUT_ALARMA)  || \
1010                                 ((OUTPUT) == RTC_OUTPUT_ALARMB)  || \
1011                                 ((OUTPUT) == RTC_OUTPUT_WAKEUP)  || \
1012                                 ((OUTPUT) == RTC_OUTPUT_TAMPER))
1013 #else
1014 #define IS_RTC_OUTPUT(OUTPUT) (((OUTPUT) == RTC_OUTPUT_DISABLE) || \
1015                                ((OUTPUT) == RTC_OUTPUT_ALARMA)  || \
1016                                ((OUTPUT) == RTC_OUTPUT_ALARMB)  || \
1017                                ((OUTPUT) == RTC_OUTPUT_WAKEUP))
1018 #endif
1019 
1020 #define IS_RTC_HOUR_FORMAT(FORMAT)     (((FORMAT) == RTC_HOURFORMAT_12) || \
1021                                         ((FORMAT) == RTC_HOURFORMAT_24))
1022 
1023 #define IS_RTC_OUTPUT_POL(POL) (((POL) == RTC_OUTPUT_POLARITY_HIGH) || \
1024                                 ((POL) == RTC_OUTPUT_POLARITY_LOW))
1025 
1026 #define IS_RTC_OUTPUT_TYPE(TYPE) (((TYPE) == RTC_OUTPUT_TYPE_OPENDRAIN) || \
1027                                   ((TYPE) == RTC_OUTPUT_TYPE_PUSHPULL))
1028 
1029 #if defined(STM32L412xx) || defined(STM32L422xx) || defined (STM32L4P5xx) || defined (STM32L4Q5xx)
1030 #define IS_RTC_OUTPUT_PULLUP(TYPE) (((TYPE) == RTC_OUTPUT_PULLUP_NONE) || \
1031                                     ((TYPE) == RTC_OUTPUT_PULLUP_ON))
1032 #endif
1033 
1034 #define IS_RTC_OUTPUT_REMAP(REMAP)   (((REMAP) == RTC_OUTPUT_REMAP_NONE) || \
1035                                       ((REMAP) == RTC_OUTPUT_REMAP_POS1))
1036 
1037 #define IS_RTC_HOURFORMAT12(PM)  (((PM) == RTC_HOURFORMAT12_AM) || \
1038                                   ((PM) == RTC_HOURFORMAT12_PM))
1039 
1040 #define IS_RTC_DAYLIGHT_SAVING(SAVE) (((SAVE) == RTC_DAYLIGHTSAVING_SUB1H) || \
1041                                       ((SAVE) == RTC_DAYLIGHTSAVING_ADD1H) || \
1042                                       ((SAVE) == RTC_DAYLIGHTSAVING_NONE))
1043 
1044 #define IS_RTC_STORE_OPERATION(OPERATION) (((OPERATION) == RTC_STOREOPERATION_RESET) || \
1045                                            ((OPERATION) == RTC_STOREOPERATION_SET))
1046 
1047 #define IS_RTC_FORMAT(FORMAT) (((FORMAT) == RTC_FORMAT_BIN) || \
1048                                ((FORMAT) == RTC_FORMAT_BCD))
1049 
1050 #define IS_RTC_YEAR(YEAR)              ((YEAR) <= 99u)
1051 
1052 #define IS_RTC_MONTH(MONTH)            (((MONTH) >= 1u) && ((MONTH) <= 12u))
1053 
1054 #define IS_RTC_DATE(DATE)              (((DATE) >= 1u) && ((DATE) <= 31u))
1055 
1056 #define IS_RTC_WEEKDAY(WEEKDAY) (((WEEKDAY) == RTC_WEEKDAY_MONDAY)    || \
1057                                  ((WEEKDAY) == RTC_WEEKDAY_TUESDAY)   || \
1058                                  ((WEEKDAY) == RTC_WEEKDAY_WEDNESDAY) || \
1059                                  ((WEEKDAY) == RTC_WEEKDAY_THURSDAY)  || \
1060                                  ((WEEKDAY) == RTC_WEEKDAY_FRIDAY)    || \
1061                                  ((WEEKDAY) == RTC_WEEKDAY_SATURDAY)  || \
1062                                  ((WEEKDAY) == RTC_WEEKDAY_SUNDAY))
1063 
1064 #define IS_RTC_ALARM_DATE_WEEKDAY_DATE(DATE) (((DATE) >0u) && ((DATE) <= 31u))
1065 
1066 #define IS_RTC_ALARM_DATE_WEEKDAY_WEEKDAY(WEEKDAY) (((WEEKDAY) == RTC_WEEKDAY_MONDAY)    || \
1067                                                     ((WEEKDAY) == RTC_WEEKDAY_TUESDAY)   || \
1068                                                     ((WEEKDAY) == RTC_WEEKDAY_WEDNESDAY) || \
1069                                                     ((WEEKDAY) == RTC_WEEKDAY_THURSDAY)  || \
1070                                                     ((WEEKDAY) == RTC_WEEKDAY_FRIDAY)    || \
1071                                                     ((WEEKDAY) == RTC_WEEKDAY_SATURDAY)  || \
1072                                                     ((WEEKDAY) == RTC_WEEKDAY_SUNDAY))
1073 
1074 #define IS_RTC_ALARM_DATE_WEEKDAY_SEL(SEL) (((SEL) == RTC_ALARMDATEWEEKDAYSEL_DATE) || \
1075                                             ((SEL) == RTC_ALARMDATEWEEKDAYSEL_WEEKDAY))
1076 
1077 #define IS_RTC_ALARM_MASK(MASK)  (((MASK) & ~(RTC_ALARMMASK_ALL)) == 0U)
1078 
1079 #define IS_RTC_ALARM(ALARM)      (((ALARM) == RTC_ALARM_A) || \
1080                                   ((ALARM) == RTC_ALARM_B))
1081 
1082 #define IS_RTC_ALARM_SUB_SECOND_VALUE(VALUE) ((VALUE) <= RTC_ALRMASSR_SS)
1083 
1084 #define IS_RTC_ALARM_SUB_SECOND_MASK(MASK)          (((MASK) == 0u) || \
1085                                                     (((MASK) >= RTC_ALARMSUBSECONDMASK_SS14_1) && ((MASK) <= RTC_ALARMSUBSECONDMASK_NONE)))
1086 
1087 #define IS_RTC_ASYNCH_PREDIV(PREDIV)   ((PREDIV) <= (RTC_PRER_PREDIV_A >> RTC_PRER_PREDIV_A_Pos))
1088 
1089 #define IS_RTC_SYNCH_PREDIV(PREDIV)    ((PREDIV) <= (RTC_PRER_PREDIV_S >> RTC_PRER_PREDIV_S_Pos))
1090 
1091 #define IS_RTC_HOUR12(HOUR)            (((HOUR) > 0u) && ((HOUR) <= 12u))
1092 
1093 #define IS_RTC_HOUR24(HOUR)            ((HOUR) <= 23u)
1094 
1095 #define IS_RTC_MINUTES(MINUTES)        ((MINUTES) <= 59u)
1096 
1097 #define IS_RTC_SECONDS(SECONDS)        ((SECONDS) <= 59u)
1098 
1099 /**
1100   * @}
1101   */
1102 
1103 /**
1104   * @}
1105   */
1106 
1107 /* Private functions -------------------------------------------------------------*/
1108 /** @defgroup RTC_Private_Functions RTC Private Functions
1109   * @{
1110   */
1111 HAL_StatusTypeDef  RTC_EnterInitMode(RTC_HandleTypeDef *hrtc);
1112 HAL_StatusTypeDef  RTC_ExitInitMode(RTC_HandleTypeDef *hrtc);
1113 uint8_t            RTC_ByteToBcd2(uint8_t Value);
1114 uint8_t            RTC_Bcd2ToByte(uint8_t Value);
1115 /**
1116   * @}
1117   */
1118 
1119 
1120 /**
1121   * @}
1122   */
1123 
1124 /**
1125   * @}
1126   */
1127 
1128 /**
1129   * @}
1130   */
1131 
1132 #ifdef __cplusplus
1133 }
1134 #endif
1135 
1136 #endif /* STM32L4xx_HAL_RTC_H */
1137