xref: /btstack/port/stm32-l451-miromico-sx1280/Drivers/STM32L4xx_HAL_Driver/Inc/stm32l4xx_hal_rtc.h (revision 2fd737d36a1de5d778cacc671d4b4d8c4f3fed82)
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   * <h2><center>&copy; Copyright (c) 2017 STMicroelectronics.
10   * All rights reserved.</center></h2>
11   *
12   * This software component is licensed by ST under BSD 3-Clause license,
13   * the "License"; You may not use this file except in compliance with the
14   * License. You may obtain a copy of the License at:
15   *                        opensource.org/licenses/BSD-3-Clause
16   *
17   ******************************************************************************
18   */
19 
20 /* Define to prevent recursive inclusion -------------------------------------*/
21 #ifndef STM32L4xx_HAL_RTC_H
22 #define STM32L4xx_HAL_RTC_H
23 
24 #ifdef __cplusplus
25 extern "C" {
26 #endif
27 
28 /* Includes ------------------------------------------------------------------*/
29 #include "stm32l4xx_hal_def.h"
30 
31 /** @addtogroup STM32L4xx_HAL_Driver
32   * @{
33   */
34 
35 /** @defgroup RTC RTC
36   * @{
37   */
38 
39 /* Exported types ------------------------------------------------------------*/
40 /** @defgroup RTC_Exported_Types RTC Exported Types
41   * @{
42   */
43 
44 /**
45   * @brief  HAL State structures definition
46   */
47 typedef enum
48 {
49   HAL_RTC_STATE_RESET             = 0x00U,  /*!< RTC not yet initialized or disabled */
50   HAL_RTC_STATE_READY             = 0x01U,  /*!< RTC initialized and ready for use   */
51   HAL_RTC_STATE_BUSY              = 0x02U,  /*!< RTC process is ongoing              */
52   HAL_RTC_STATE_TIMEOUT           = 0x03U,  /*!< RTC timeout state                   */
53   HAL_RTC_STATE_ERROR             = 0x04U   /*!< RTC error state                     */
54 
55 } HAL_RTCStateTypeDef;
56 
57 /**
58   * @brief  RTC Configuration Structure definition
59   */
60 typedef struct
61 {
62   uint32_t HourFormat;      /*!< Specifies the RTC Hour Format.
63                                  This parameter can be a value of @ref RTC_Hour_Formats */
64 
65   uint32_t AsynchPrediv;    /*!< Specifies the RTC Asynchronous Predivider value.
66                                  This parameter must be a number between Min_Data = 0x00 and Max_Data = 0x7F */
67 
68   uint32_t SynchPrediv;     /*!< Specifies the RTC Synchronous Predivider value.
69                                  This parameter must be a number between Min_Data = 0x00 and Max_Data = 0x7FFF */
70 
71   uint32_t OutPut;          /*!< Specifies which signal will be routed to the RTC output.
72                                  This parameter can be a value of @ref RTCEx_Output_selection_Definitions */
73 
74   uint32_t OutPutRemap;     /*!< Specifies the remap for RTC output.
75                                  This parameter can be a value of @ref  RTC_Output_ALARM_OUT_Remap */
76 
77   uint32_t OutPutPolarity;  /*!< Specifies the polarity of the output signal.
78                                  This parameter can be a value of @ref RTC_Output_Polarity_Definitions */
79 
80   uint32_t OutPutType;      /*!< Specifies the RTC Output Pin mode.
81                                  This parameter can be a value of @ref RTC_Output_Type_ALARM_OUT */
82 #if defined(STM32L412xx) || defined(STM32L422xx) || defined (STM32L4P5xx) || defined (STM32L4Q5xx)
83   uint32_t OutPutPullUp;    /*!< Specifies the RTC Output Pull-Up mode.
84                                  This parameter can be a value of @ref RTC_Output_PullUp_ALARM_OUT */
85 #endif
86 
87 #if defined (STM32L4P5xx) || defined (STM32L4Q5xx)
88   uint32_t BinMode;         /*!< Specifies the RTC binary mode.
89                                  This parameter can be a value of @ref RTCEx_Binary_Mode */
90 
91   uint32_t BinMixBcdU;      /*!< Specifies the BCD calendar update if and only if BinMode = RTC_BINARY_MIX.
92                                  This parameter can be a value of @ref RTCEx_Binary_mix_BCDU */
93 #endif
94 } RTC_InitTypeDef;
95 
96 /**
97   * @brief  RTC Time structure definition
98   */
99 typedef struct
100 {
101   uint8_t Hours;            /*!< Specifies the RTC Time Hour.
102                                  This parameter must be a number between Min_Data = 0 and Max_Data = 12 if the RTC_HourFormat_12 is selected.
103                                  This parameter must be a number between Min_Data = 0 and Max_Data = 23 if the RTC_HourFormat_24 is selected */
104 
105   uint8_t Minutes;          /*!< Specifies the RTC Time Minutes.
106                                  This parameter must be a number between Min_Data = 0 and Max_Data = 59 */
107 
108   uint8_t Seconds;          /*!< Specifies the RTC Time Seconds.
109                                  This parameter must be a number between Min_Data = 0 and Max_Data = 59 */
110 
111   uint8_t TimeFormat;       /*!< Specifies the RTC AM/PM Time.
112                                  This parameter can be a value of @ref RTC_AM_PM_Definitions */
113 
114 #if defined (STM32L4P5xx) || defined (STM32L4Q5xx)
115   uint32_t SubSeconds;      /*!< Specifies the RTC_SSR RTC Sub Second register content.
116                                  This field is not used by HAL_RTC_SetTime.
117                                  If the free running 32 bit counter is not activated (mode binary none)
118                                     - This parameter corresponds to a time unit range between [0-1] Second with [1 Sec / SecondFraction +1] granularity
119                                  else
120                                     - This parameter corresponds to the free running 32 bit counter. */
121 #else
122   uint32_t SubSeconds;      /*!< Specifies the RTC_SSR RTC Sub Second register content.
123                                  This parameter corresponds to a time unit range between [0-1] Second
124                                  with [1 Sec / SecondFraction +1] granularity */
125 #endif
126 
127   uint32_t SecondFraction;  /*!< Specifies the range or granularity of Sub Second register content
128                                  corresponding to Synchronous pre-scaler factor value (PREDIV_S)
129                                  This parameter corresponds to a time unit range between [0-1] Second
130                                  with [1 Sec / SecondFraction +1] granularity.
131                                  This field will be used only by HAL_RTC_GetTime function */
132 
133   uint32_t DayLightSaving;  /*!< Specifies RTC_DayLightSaveOperation: the value of hour adjustment.
134                                  This parameter can be a value of @ref RTC_DayLightSaving_Definitions */
135 
136   uint32_t StoreOperation;  /*!< Specifies RTC_StoreOperation value to be written in the BKP bit
137                                  in CR register to store the operation.
138                                  This parameter can be a value of @ref RTC_StoreOperation_Definitions */
139 } RTC_TimeTypeDef;
140 
141 /**
142   * @brief  RTC Date structure definition
143   */
144 typedef struct
145 {
146   uint8_t WeekDay;  /*!< Specifies the RTC Date WeekDay.
147                          This parameter can be a value of @ref RTC_WeekDay_Definitions */
148 
149   uint8_t Month;    /*!< Specifies the RTC Date Month (in BCD format).
150                          This parameter can be a value of @ref RTC_Month_Date_Definitions */
151 
152   uint8_t Date;     /*!< Specifies the RTC Date.
153                          This parameter must be a number between Min_Data = 1 and Max_Data = 31 */
154 
155   uint8_t Year;     /*!< Specifies the RTC Date Year.
156                          This parameter must be a number between Min_Data = 0 and Max_Data = 99 */
157 
158 } RTC_DateTypeDef;
159 
160 /**
161   * @brief  RTC Alarm structure definition
162   */
163 typedef struct
164 {
165   RTC_TimeTypeDef AlarmTime;     /*!< Specifies the RTC Alarm Time members */
166 
167   uint32_t AlarmMask;            /*!< Specifies the RTC Alarm Masks.
168                                       This parameter can be a value of @ref RTC_AlarmMask_Definitions */
169 
170 #if defined (STM32L4P5xx) || defined (STM32L4Q5xx)
171   uint32_t SubSeconds;           /*!< Specifies the RTC_SSR RTC Sub Second register content.
172                                       This field is not used by HAL_RTC_SetTime.
173                                        If the free running 32 bit counter is not activated (mode binary none)
174                                           - This parameter corresponds to a time unit range between [0-1] Second with [1 Sec / SecondFraction +1] granularity
175                                        else
176                                           - This parameter corresponds to the free running 32 bit counter. */
177   uint32_t BinaryAutoClr;        /*!< Clear synchronously counter (RTC_SSR) on binary alarm.
178                                       RTC_ALARMSUBSECONDBIN_AUTOCLR_YES must only be used if Binary mode is RTC_BINARY_ONLY
179                                       This parameter can be a value of @ref RTCEx_Alarm_Sub_Seconds_binary_Clear_Definitions */
180 #else
181   uint32_t SubSeconds;           /*!< Specifies the RTC_SSR RTC Sub Second register content. */
182 #endif
183 
184   uint32_t AlarmSubSecondMask;   /*!< Specifies the RTC Alarm SubSeconds Masks.
185                                       This parameter can be a value of @ref RTC_Alarm_Sub_Seconds_Masks_Definitions */
186 
187   uint32_t AlarmDateWeekDaySel;  /*!< Specifies the RTC Alarm is on Date or WeekDay.
188                                      This parameter can be a value of @ref RTC_AlarmDateWeekDay_Definitions */
189 
190   uint8_t AlarmDateWeekDay;      /*!< Specifies the RTC Alarm Date/WeekDay.
191                                       If the Alarm Date is selected, this parameter must be set to a value in the 1-31 range.
192                                       If the Alarm WeekDay is selected, this parameter can be a value of @ref RTC_WeekDay_Definitions */
193 
194   uint32_t Alarm;                /*!< Specifies the alarm .
195                                       This parameter can be a value of @ref RTC_Alarms_Definitions */
196 } RTC_AlarmTypeDef;
197 
198 /**
199   * @brief  RTC Handle Structure definition
200   */
201 #if (USE_HAL_RTC_REGISTER_CALLBACKS == 1)
202 typedef struct __RTC_HandleTypeDef
203 #else
204 typedef struct
205 #endif /* (USE_HAL_RTC_REGISTER_CALLBACKS) */
206 {
207   RTC_TypeDef               *Instance;  /*!< Register base address    */
208 
209 #if defined(STM32L412xx) || defined(STM32L422xx) || defined (STM32L4P5xx) || defined (STM32L4Q5xx)
210   uint32_t                  TampOffset; /*!< Offset to TAMP instance  */
211 #endif
212   RTC_InitTypeDef           Init;       /*!< RTC required parameters  */
213 
214   HAL_LockTypeDef           Lock;       /*!< RTC locking object       */
215 
216   __IO HAL_RTCStateTypeDef  State;      /*!< Time communication state */
217 
218 #if (USE_HAL_RTC_REGISTER_CALLBACKS == 1)
219   void (* AlarmAEventCallback)(struct __RTC_HandleTypeDef *hrtc);                    /*!< RTC Alarm A Event callback            */
220   void (* AlarmBEventCallback)(struct __RTC_HandleTypeDef *hrtc);                    /*!< RTC Alarm B Event callback            */
221   void (* TimeStampEventCallback)(struct __RTC_HandleTypeDef *hrtc);                 /*!< RTC TimeStamp Event callback          */
222   void (* WakeUpTimerEventCallback)(struct __RTC_HandleTypeDef *hrtc);               /*!< RTC WakeUpTimer Event callback        */
223 #if defined (STM32L4P5xx) || defined (STM32L4Q5xx)
224   void (* SSRUEventCallback)(struct __RTC_HandleTypeDef *hrtc);                      /*!< RTC SSRU Event callback               */
225 #endif
226 #if defined(RTC_TAMPER1_SUPPORT)
227   void (* Tamper1EventCallback)(struct __RTC_HandleTypeDef *hrtc);                   /*!< RTC Tamper 1 Event callback           */
228 #endif /* RTC_TAMPER1_SUPPORT */
229   void (* Tamper2EventCallback)(struct __RTC_HandleTypeDef *hrtc);                   /*!< RTC Tamper 2 Event callback           */
230 #if defined(RTC_TAMPER3_SUPPORT)
231   void (* Tamper3EventCallback)(struct __RTC_HandleTypeDef *hrtc);                   /*!< RTC Tamper 3 Event callback           */
232 #endif /* RTC_TAMPER3_SUPPORT */
233   void (* MspInitCallback)(struct __RTC_HandleTypeDef *hrtc);                        /*!< RTC Msp Init callback                 */
234   void (* MspDeInitCallback)(struct __RTC_HandleTypeDef *hrtc);                      /*!< RTC Msp DeInit callback               */
235 #endif /* (USE_HAL_RTC_REGISTER_CALLBACKS == 1) */
236 
237 } RTC_HandleTypeDef;
238 
239 #if (USE_HAL_RTC_REGISTER_CALLBACKS == 1)
240 /**
241   * @brief  HAL RTC Callback ID enumeration definition
242   */
243 typedef enum
244 {
245   HAL_RTC_ALARM_A_EVENT_CB_ID            =  0u,    /*!< RTC Alarm A Event Callback ID      */
246   HAL_RTC_ALARM_B_EVENT_CB_ID            =  1u,    /*!< RTC Alarm B Event Callback ID      */
247   HAL_RTC_TIMESTAMP_EVENT_CB_ID          =  2u,    /*!< RTC TimeStamp Event Callback ID    */
248   HAL_RTC_WAKEUPTIMER_EVENT_CB_ID        =  3u,    /*!< RTC WakeUp Timer Event Callback ID */
249 #if defined(RTC_TAMPER1_SUPPORT)
250   HAL_RTC_TAMPER1_EVENT_CB_ID            =  4u,    /*!< RTC Tamper 1 Callback ID           */
251 #endif /* RTC_TAMPER1_SUPPORT */
252   HAL_RTC_TAMPER2_EVENT_CB_ID            =  5u,    /*!< RTC Tamper 2 Callback ID           */
253 #if defined(RTC_TAMPER3_SUPPORT)
254   HAL_RTC_TAMPER3_EVENT_CB_ID            =  6u,    /*!< RTC Tamper 3 Callback ID           */
255 #endif /* RTC_TAMPER3_SUPPORT */
256   HAL_RTC_MSPINIT_CB_ID                  =  7u,    /*!< RTC Msp Init callback ID           */
257   HAL_RTC_MSPDEINIT_CB_ID                =  8u     /*!< RTC Msp DeInit callback ID         */
258 } HAL_RTC_CallbackIDTypeDef;
259 
260 /**
261   * @brief  HAL RTC Callback pointer definition
262   */
263 typedef  void (*pRTC_CallbackTypeDef)(RTC_HandleTypeDef *hrtc);  /*!< pointer to an RTC callback function */
264 #endif /* (USE_HAL_RTC_REGISTER_CALLBACKS == 1) */
265 
266 /**
267   * @}
268   */
269 
270 /* Exported constants --------------------------------------------------------*/
271 /** @defgroup RTC_Exported_Constants RTC Exported Constants
272   * @{
273   */
274 
275 /** @defgroup RTC_Hour_Formats_Definitions RTC Hour Formats Definitions
276   * @{
277   */
278 #define RTC_HOURFORMAT_24                   0x00000000u
279 #define RTC_HOURFORMAT_12                   RTC_CR_FMT
280 /**
281   * @}
282   */
283 
284 /** @defgroup RTCEx_Output_selection_Definitions RTCEx Output Selection Definitions
285   * @{
286   */
287 #define RTC_OUTPUT_DISABLE                  0x00000000u
288 #define RTC_OUTPUT_ALARMA                   RTC_CR_OSEL_0
289 #define RTC_OUTPUT_ALARMB                   RTC_CR_OSEL_1
290 #define RTC_OUTPUT_WAKEUP                   RTC_CR_OSEL
291 #if defined(STM32L412xx) || defined(STM32L422xx) || defined (STM32L4P5xx) || defined (STM32L4Q5xx)
292 #define RTC_OUTPUT_TAMPER                   RTC_CR_TAMPOE
293 #endif
294 /**
295   * @}
296   */
297 
298 /** @defgroup RTC_Output_Polarity_Definitions RTC Output Polarity Definitions
299   * @{
300   */
301 #define RTC_OUTPUT_POLARITY_HIGH            0x00000000u
302 #define RTC_OUTPUT_POLARITY_LOW             RTC_CR_POL
303 /**
304   * @}
305   */
306 
307 /** @defgroup RTC_Output_Type_ALARM_OUT RTC Output Type ALARM OUT
308   * @{
309   */
310 #if defined(STM32L412xx) || defined(STM32L422xx) || defined (STM32L4P5xx) || defined (STM32L4Q5xx)
311 #define RTC_OUTPUT_TYPE_PUSHPULL            0x00000000u
312 #define RTC_OUTPUT_TYPE_OPENDRAIN           RTC_CR_TAMPALRM_TYPE
313 #else
314 #define RTC_OUTPUT_TYPE_PUSHPULL            RTC_OR_ALARMOUTTYPE
315 #define RTC_OUTPUT_TYPE_OPENDRAIN           0x00000000u
316 #endif
317 /**
318   * @}
319   */
320 
321 /** @defgroup RTC_Output_PullUp_ALARM_OUT RTC Output Pull-Up ALARM OUT
322   * @{
323   */
324 #if defined(STM32L412xx) || defined(STM32L422xx) || defined (STM32L4P5xx) || defined (STM32L4Q5xx)
325 #define RTC_OUTPUT_PULLUP_NONE              0x00000000u
326 #define RTC_OUTPUT_PULLUP_ON                RTC_CR_TAMPALRM_PU
327 #endif
328 /**
329   * @}
330   */
331 
332 /** @defgroup RTC_Output_ALARM_OUT_Remap RTC Output ALARM OUT Remap
333   * @{
334   */
335 #if defined(STM32L412xx) || defined(STM32L422xx) || defined (STM32L4P5xx) || defined (STM32L4Q5xx)
336 #define RTC_OUTPUT_REMAP_NONE               0x00000000u
337 #define RTC_OUTPUT_REMAP_POS1               RTC_CR_OUT2EN
338 #else
339 #define RTC_OUTPUT_REMAP_NONE               0x00000000u
340 #define RTC_OUTPUT_REMAP_POS1               RTC_OR_OUT_RMP
341 #endif
342 /**
343   * @}
344   */
345 
346 /** @defgroup RTC_AM_PM_Definitions RTC AM PM Definitions
347   * @{
348   */
349 #define RTC_HOURFORMAT12_AM            ((uint8_t)0x00)
350 #define RTC_HOURFORMAT12_PM            ((uint8_t)0x01)
351 /**
352   * @}
353   */
354 
355 /** @defgroup RTC_DayLightSaving_Definitions RTC DayLightSaving Definitions
356   * @{
357   */
358 #define RTC_DAYLIGHTSAVING_SUB1H            RTC_CR_SUB1H
359 #define RTC_DAYLIGHTSAVING_ADD1H            RTC_CR_ADD1H
360 #define RTC_DAYLIGHTSAVING_NONE             0x00000000u
361 /**
362   * @}
363   */
364 
365 /** @defgroup RTC_StoreOperation_Definitions RTC StoreOperation Definitions
366   * @{
367   */
368 #define RTC_STOREOPERATION_RESET            0x00000000u
369 #define RTC_STOREOPERATION_SET              RTC_CR_BKP
370 /**
371   * @}
372   */
373 
374 #if defined (STM32L4P5xx) || defined (STM32L4Q5xx)
375 /** @defgroup RTC_Input_parameter_format_definitions RTC input or output data format for date (Year, Month, Weekday) and time (Hours, Minutes, Seconds).
376   *           Warning : It Should not be confused with the Binary mode @ref RTCEx_Binary_Mode.
377   * @{
378   */
379 #define RTC_FORMAT_BIN                      0x00000000u /* This parameter will trigger a SW conversion to fit with the native BCD format of the HW Calendar.
380                                                            It should not be confused with the Binary mode @ref RTCEx_Binary_Mode. */
381 
382 #define RTC_FORMAT_BCD                      0x00000001u /* Native format of the HW Calendar.
383                                                            It should not be confused with the Binary mode @ref RTCEx_Binary_Mode. */
384 /**
385   * @}
386   */
387 #else
388 
389 /** @defgroup RTC_Input_parameter_format_definitions RTC Input Parameter Format Definitions
390   * @{
391   */
392 #define RTC_FORMAT_BIN                      0x00000000u
393 #define RTC_FORMAT_BCD                      0x00000001u
394 /**
395   * @}
396   */
397 #endif
398 
399 /** @defgroup RTC_Month_Date_Definitions RTC Month Date Definitions (in BCD format)
400   * @{
401   */
402 
403 /* Coded in BCD format */
404 #define RTC_MONTH_JANUARY                   ((uint8_t)0x01U)
405 #define RTC_MONTH_FEBRUARY                  ((uint8_t)0x02U)
406 #define RTC_MONTH_MARCH                     ((uint8_t)0x03U)
407 #define RTC_MONTH_APRIL                     ((uint8_t)0x04U)
408 #define RTC_MONTH_MAY                       ((uint8_t)0x05U)
409 #define RTC_MONTH_JUNE                      ((uint8_t)0x06U)
410 #define RTC_MONTH_JULY                      ((uint8_t)0x07U)
411 #define RTC_MONTH_AUGUST                    ((uint8_t)0x08U)
412 #define RTC_MONTH_SEPTEMBER                 ((uint8_t)0x09U)
413 #define RTC_MONTH_OCTOBER                   ((uint8_t)0x10U)
414 #define RTC_MONTH_NOVEMBER                  ((uint8_t)0x11U)
415 #define RTC_MONTH_DECEMBER                  ((uint8_t)0x12U)
416 
417 /**
418   * @}
419   */
420 
421 /** @defgroup RTC_WeekDay_Definitions RTC WeekDay Definitions
422   * @{
423   */
424 #define RTC_WEEKDAY_MONDAY                  ((uint8_t)0x01U)
425 #define RTC_WEEKDAY_TUESDAY                 ((uint8_t)0x02U)
426 #define RTC_WEEKDAY_WEDNESDAY               ((uint8_t)0x03U)
427 #define RTC_WEEKDAY_THURSDAY                ((uint8_t)0x04U)
428 #define RTC_WEEKDAY_FRIDAY                  ((uint8_t)0x05U)
429 #define RTC_WEEKDAY_SATURDAY                ((uint8_t)0x06U)
430 #define RTC_WEEKDAY_SUNDAY                  ((uint8_t)0x07U)
431 
432 /**
433   * @}
434   */
435 
436 /** @defgroup RTC_AlarmDateWeekDay_Definitions RTC AlarmDateWeekDay Definitions
437   * @{
438   */
439 #define RTC_ALARMDATEWEEKDAYSEL_DATE        0x00000000u
440 #define RTC_ALARMDATEWEEKDAYSEL_WEEKDAY     RTC_ALRMAR_WDSEL
441 
442 /**
443   * @}
444   */
445 
446 /** @defgroup RTC_AlarmMask_Definitions RTC AlarmMask Definitions
447   * @{
448   */
449 #define RTC_ALARMMASK_NONE                  0x00000000u
450 #define RTC_ALARMMASK_DATEWEEKDAY           RTC_ALRMAR_MSK4
451 #define RTC_ALARMMASK_HOURS                 RTC_ALRMAR_MSK3
452 #define RTC_ALARMMASK_MINUTES               RTC_ALRMAR_MSK2
453 #define RTC_ALARMMASK_SECONDS               RTC_ALRMAR_MSK1
454 #define RTC_ALARMMASK_ALL                   (RTC_ALARMMASK_DATEWEEKDAY | RTC_ALARMMASK_HOURS  | \
455                                              RTC_ALARMMASK_MINUTES | RTC_ALARMMASK_SECONDS)
456 
457 /**
458   * @}
459   */
460 
461 /** @defgroup RTC_Alarms_Definitions RTC Alarms Definitions
462   * @{
463   */
464 #define RTC_ALARM_A                         RTC_CR_ALRAE
465 #define RTC_ALARM_B                         RTC_CR_ALRBE
466 
467 /**
468   * @}
469   */
470 
471 
472 /** @defgroup RTC_Alarm_Sub_Seconds_Masks_Definitions RTC Alarm Sub Seconds Masks Definitions
473   * @{
474   */
475 #define RTC_ALARMSUBSECONDMASK_ALL          0x00000000u                                                              /*!< All Alarm SS fields are masked.
476                                                                                                                           There is no comparison on sub seconds
477                                                                                                                           for Alarm */
478 #define RTC_ALARMSUBSECONDMASK_SS14_1       RTC_ALRMASSR_MASKSS_0                                                    /*!< SS[14:1] are don't care in Alarm
479                                                                                                                           comparison. Only SS[0] is compared.    */
480 #define RTC_ALARMSUBSECONDMASK_SS14_2       RTC_ALRMASSR_MASKSS_1                                                    /*!< SS[14:2] are don't care in Alarm
481                                                                                                                           comparison. Only SS[1:0] are compared  */
482 #define RTC_ALARMSUBSECONDMASK_SS14_3       (RTC_ALRMASSR_MASKSS_0 | RTC_ALRMASSR_MASKSS_1)                          /*!< SS[14:3] are don't care in Alarm
483                                                                                                                           comparison. Only SS[2:0] are compared  */
484 #define RTC_ALARMSUBSECONDMASK_SS14_4       RTC_ALRMASSR_MASKSS_2                                                    /*!< SS[14:4] are don't care in Alarm
485                                                                                                                           comparison. Only SS[3:0] are compared  */
486 #define RTC_ALARMSUBSECONDMASK_SS14_5       (RTC_ALRMASSR_MASKSS_0 | RTC_ALRMASSR_MASKSS_2)                          /*!< SS[14:5] are don't care in Alarm
487                                                                                                                           comparison. Only SS[4:0] are compared  */
488 #define RTC_ALARMSUBSECONDMASK_SS14_6       (RTC_ALRMASSR_MASKSS_1 | RTC_ALRMASSR_MASKSS_2)                          /*!< SS[14:6] are don't care in Alarm
489                                                                                                                           comparison. Only SS[5:0] are compared  */
490 #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
491                                                                                                                           comparison. Only SS[6:0] are compared  */
492 #define RTC_ALARMSUBSECONDMASK_SS14_8       RTC_ALRMASSR_MASKSS_3                                                    /*!< SS[14:8] are don't care in Alarm
493                                                                                                                           comparison. Only SS[7:0] are compared  */
494 #define RTC_ALARMSUBSECONDMASK_SS14_9       (RTC_ALRMASSR_MASKSS_0 | RTC_ALRMASSR_MASKSS_3)                          /*!< SS[14:9] are don't care in Alarm
495                                                                                                                           comparison. Only SS[8:0] are compared  */
496 #define RTC_ALARMSUBSECONDMASK_SS14_10      (RTC_ALRMASSR_MASKSS_1 | RTC_ALRMASSR_MASKSS_3)                          /*!< SS[14:10] are don't care in Alarm
497                                                                                                                           comparison. Only SS[9:0] are compared  */
498 #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
499                                                                                                                           comparison. Only SS[10:0] are compared */
500 #define RTC_ALARMSUBSECONDMASK_SS14_12      (RTC_ALRMASSR_MASKSS_2 | RTC_ALRMASSR_MASKSS_3)                          /*!< SS[14:12] are don't care in Alarm
501                                                                                                                           comparison.Only SS[11:0] are compared  */
502 #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
503                                                                                                                           comparison. Only SS[12:0] are compared */
504 #define RTC_ALARMSUBSECONDMASK_SS14         (RTC_ALRMASSR_MASKSS_1 | RTC_ALRMASSR_MASKSS_2 | RTC_ALRMASSR_MASKSS_3)  /*!< SS[14] is don't care in Alarm
505                                                                                                                           comparison.Only SS[13:0] are compared  */
506 #define RTC_ALARMSUBSECONDMASK_NONE         RTC_ALRMASSR_MASKSS                                                      /*!< SS[14:0] are compared and must match
507                                                                                                                           to activate alarm. */
508 /**
509   * @}
510   */
511 
512 /** @defgroup RTC_Interrupts_Definitions RTC Interrupts Definitions
513   * @{
514   */
515 #define RTC_IT_TS                           RTC_CR_TSIE        /*!< Enable Timestamp Interrupt    */
516 #define RTC_IT_WUT                          RTC_CR_WUTIE       /*!< Enable Wakeup timer Interrupt */
517 #if defined (STM32L4P5xx) || defined (STM32L4Q5xx)
518 #define RTC_IT_SSRU                         RTC_CR_SSRUIE      /*!< Enable SSR Underflow Interrupt */
519 #endif
520 #define RTC_IT_ALRA                         RTC_CR_ALRAIE      /*!< Enable Alarm A Interrupt      */
521 #define RTC_IT_ALRB                         RTC_CR_ALRBIE      /*!< Enable Alarm B Interrupt      */
522 /**
523   * @}
524   */
525 
526 #if defined(STM32L412xx) || defined(STM32L422xx) || defined (STM32L4P5xx) || defined (STM32L4Q5xx)
527 /** @defgroup RTC_Flag_Mask    RTC Flag Mask (5bits) describe in RTC_Flags_Definitions
528   * @{
529   */
530 #define RTC_FLAG_MASK                       0x001Fu            /*!< RTC flags mask (5bits) */
531 /**
532   * @}
533   */
534 
535 /** @defgroup RTC_Flags_Definitions RTC Flags Definitions
536   *        Elements values convention: 000000XX000YYYYYb
537   *           - YYYYY  : Interrupt flag position in the XX register (5bits)
538   *           - XX  : Interrupt status register (2bits)
539   *                 - 01: ICSR register
540   *                 - 10: SR or SCR or MISR or SMISR registers
541   * @{
542   */
543 #define RTC_FLAG_RECALPF                    (0x00000100U | RTC_ICSR_RECALPF_Pos) /*!< Recalibration pending Flag */
544 #define RTC_FLAG_INITF                      (0x00000100U | RTC_ICSR_INITF_Pos)   /*!< Initialization flag */
545 #define RTC_FLAG_RSF                        (0x00000100U | RTC_ICSR_RSF_Pos)     /*!< Registers synchronization flag */
546 #define RTC_FLAG_INITS                      (0x00000100U | RTC_ICSR_INITS_Pos)   /*!< Initialization status flag */
547 #define RTC_FLAG_SHPF                       (0x00000100U | RTC_ICSR_SHPF_Pos)    /*!< Shift operation pending flag */
548 #define RTC_FLAG_WUTWF                      (0x00000100U | RTC_ICSR_WUTWF_Pos)   /*!< Wakeup timer write flag */
549 #if defined (STM32L4P5xx) || defined (STM32L4Q5xx)
550 #define RTC_FLAG_SSRUF                      (0x00000200U | RTC_SR_SSRUF_Pos)     /*!< SSR underflow flag */
551 #endif
552 #define RTC_FLAG_ITSF                       (0x00000200U | RTC_SR_ITSF_Pos)      /*!< Internal Time-stamp flag */
553 #define RTC_FLAG_TSOVF                      (0x00000200U | RTC_SR_TSOVF_Pos)     /*!< Time-stamp overflow flag */
554 #define RTC_FLAG_TSF                        (0x00000200U | RTC_SR_TSF_Pos)       /*!< Time-stamp flag */
555 #define RTC_FLAG_WUTF                       (0x00000200U | RTC_SR_WUTF_Pos)      /*!< Wakeup timer flag */
556 #define RTC_FLAG_ALRBF                      (0x00000200U | RTC_SR_ALRBF_Pos)     /*!< Alarm B flag */
557 #define RTC_FLAG_ALRAF                      (0x00000200U | RTC_SR_ALRAF_Pos)     /*!< Alarm A flag */
558 /**
559   * @}
560   */
561 
562 /** @defgroup RTC_Clear_Flags_Definitions RTC Clear Flags Definitions
563   * @{
564   */
565 #if defined (STM32L4P5xx) || defined (STM32L4Q5xx)
566 #define RTC_CLEAR_SSRUF                     RTC_SCR_CSSRUF   /*!< Clear SSR underflow flag */
567 #endif
568 #define RTC_CLEAR_ITSF                      RTC_SCR_CITSF    /*!< Clear Internal Time-stamp flag */
569 #define RTC_CLEAR_TSOVF                     RTC_SCR_CTSOVF   /*!< Clear Time-stamp overflow flag */
570 #define RTC_CLEAR_TSF                       RTC_SCR_CTSF     /*!< Clear Time-stamp flag */
571 #define RTC_CLEAR_WUTF                      RTC_SCR_CWUTF    /*!< Clear Wakeup timer flag */
572 #define RTC_CLEAR_ALRBF                     RTC_SCR_CALRBF   /*!< Clear Alarm B flag */
573 #define RTC_CLEAR_ALRAF                     RTC_SCR_CALRAF   /*!< Clear Alarm A flag */
574 
575 /**
576   * @}
577   */
578 
579 #else /* #if defined(STM32L412xx) || defined(STM32L422xx) || defined (STM32L4P5xx) || defined (STM32L4Q5xx) */
580 
581 /** @defgroup RTC_Flags_Definitions RTC Flags Definitions
582   * @{
583   */
584 #define RTC_FLAG_RECALPF                    RTC_ISR_RECALPF
585 #define RTC_FLAG_TSOVF                      RTC_ISR_TSOVF
586 #define RTC_FLAG_TSF                        RTC_ISR_TSF
587 #define RTC_FLAG_ITSF                       RTC_ISR_ITSF
588 #define RTC_FLAG_WUTF                       RTC_ISR_WUTF
589 #define RTC_FLAG_ALRBF                      RTC_ISR_ALRBF
590 #define RTC_FLAG_ALRAF                      RTC_ISR_ALRAF
591 #define RTC_FLAG_INITF                      RTC_ISR_INITF
592 #define RTC_FLAG_RSF                        RTC_ISR_RSF
593 #define RTC_FLAG_INITS                      RTC_ISR_INITS
594 #define RTC_FLAG_SHPF                       RTC_ISR_SHPF
595 #define RTC_FLAG_WUTWF                      RTC_ISR_WUTWF
596 #define RTC_FLAG_ALRBWF                     RTC_ISR_ALRBWF
597 #define RTC_FLAG_ALRAWF                     RTC_ISR_ALRAWF
598 /**
599   * @}
600   */
601 #endif /* #if defined(STM32L412xx) || defined(STM32L422xx) || defined (STM32L4P5xx) || defined (STM32L4Q5xx) */
602 
603 /**
604   * @}
605   */
606 
607 /* Exported macros -----------------------------------------------------------*/
608 /** @defgroup RTC_Exported_Macros RTC Exported Macros
609   * @{
610   */
611 
612 /** @brief Reset RTC handle state
613   * @param  __HANDLE__ RTC handle.
614   * @retval None
615   */
616 #if (USE_HAL_RTC_REGISTER_CALLBACKS == 1)
617 #define __HAL_RTC_RESET_HANDLE_STATE(__HANDLE__) do{\
618                                                       (__HANDLE__)->State = HAL_RTC_STATE_RESET;\
619                                                       (__HANDLE__)->MspInitCallback = NULL;\
620                                                       (__HANDLE__)->MspDeInitCallback = NULL;\
621                                                      }while(0u)
622 #else
623 #define __HAL_RTC_RESET_HANDLE_STATE(__HANDLE__) ((__HANDLE__)->State = HAL_RTC_STATE_RESET)
624 #endif /* USE_HAL_RTC_REGISTER_CALLBACKS */
625 
626 /**
627   * @brief  Disable the write protection for RTC registers.
628   * @param  __HANDLE__ specifies the RTC handle.
629   * @retval None
630   */
631 #define __HAL_RTC_WRITEPROTECTION_DISABLE(__HANDLE__)             \
632                         do{                                       \
633                             (__HANDLE__)->Instance->WPR = 0xCAU;   \
634                             (__HANDLE__)->Instance->WPR = 0x53U;   \
635                           } while(0u)
636 
637 /**
638   * @brief  Enable the write protection for RTC registers.
639   * @param  __HANDLE__ specifies the RTC handle.
640   * @retval None
641   */
642 #define __HAL_RTC_WRITEPROTECTION_ENABLE(__HANDLE__)              \
643                         do{                                       \
644                             (__HANDLE__)->Instance->WPR = 0xFFU;   \
645                           } while(0u)
646 
647 /**
648   * @brief  Add 1 hour (summer time change).
649   * @param  __HANDLE__ specifies the RTC handle.
650   * @param  __BKP__ Backup
651   *         This parameter can be:
652   *            @arg @ref RTC_STOREOPERATION_RESET
653   *            @arg @ref RTC_STOREOPERATION_SET
654   * @retval None
655   */
656 #define __HAL_RTC_DAYLIGHT_SAVING_TIME_ADD1H(__HANDLE__, __BKP__)                         \
657                         do {                                                              \
658                             __HAL_RTC_WRITEPROTECTION_DISABLE(__HANDLE__);                \
659                             SET_BIT((__HANDLE__)->Instance->CR, RTC_CR_ADD1H);            \
660                             MODIFY_REG((__HANDLE__)->Instance->CR, RTC_CR_BKP , (__BKP__)); \
661                             __HAL_RTC_WRITEPROTECTION_ENABLE(__HANDLE__);                 \
662                         } while(0u);
663 
664 /**
665   * @brief  Subtract 1 hour (winter time change).
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 /**
924   * @}
925   */
926 
927 /** @defgroup RTC_Exported_Functions_Group3 RTC Alarm functions
928   * @{
929   */
930 /* RTC Alarm functions ********************************************************/
931 HAL_StatusTypeDef HAL_RTC_SetAlarm(RTC_HandleTypeDef *hrtc, RTC_AlarmTypeDef *sAlarm, uint32_t Format);
932 HAL_StatusTypeDef HAL_RTC_SetAlarm_IT(RTC_HandleTypeDef *hrtc, RTC_AlarmTypeDef *sAlarm, uint32_t Format);
933 HAL_StatusTypeDef HAL_RTC_DeactivateAlarm(RTC_HandleTypeDef *hrtc, uint32_t Alarm);
934 HAL_StatusTypeDef HAL_RTC_GetAlarm(RTC_HandleTypeDef *hrtc, RTC_AlarmTypeDef *sAlarm, uint32_t Alarm, uint32_t Format);
935 void              HAL_RTC_AlarmIRQHandler(RTC_HandleTypeDef *hrtc);
936 void              HAL_RTC_AlarmAEventCallback(RTC_HandleTypeDef *hrtc);
937 HAL_StatusTypeDef HAL_RTC_PollForAlarmAEvent(RTC_HandleTypeDef *hrtc, uint32_t Timeout);
938 /**
939   * @}
940   */
941 
942 /** @defgroup  RTC_Exported_Functions_Group4 Peripheral Control functions
943   * @{
944   */
945 /* Peripheral Control functions ***********************************************/
946 HAL_StatusTypeDef   HAL_RTC_WaitForSynchro(RTC_HandleTypeDef *hrtc);
947 /**
948   * @}
949   */
950 
951 /** @defgroup RTC_Exported_Functions_Group5 Peripheral State functions
952   * @{
953   */
954 /* Peripheral State functions *************************************************/
955 HAL_RTCStateTypeDef HAL_RTC_GetState(RTC_HandleTypeDef *hrtc);
956 /**
957   * @}
958   */
959 
960 /**
961   * @}
962   */
963 
964 /* Private types -------------------------------------------------------------*/
965 /* Private variables ---------------------------------------------------------*/
966 /* Private constants ---------------------------------------------------------*/
967 /** @defgroup RTC_Private_Constants RTC Private Constants
968   * @{
969   */
970 /* Masks Definition */
971 #define RTC_TR_RESERVED_MASK                (RTC_TR_PM | RTC_TR_HT | RTC_TR_HU | \
972                                             RTC_TR_MNT | RTC_TR_MNU| RTC_TR_ST | \
973                                             RTC_TR_SU)
974 
975 #define RTC_DR_RESERVED_MASK                (RTC_DR_YT | RTC_DR_YU | RTC_DR_WDU | \
976                                             RTC_DR_MT | RTC_DR_MU | RTC_DR_DT  | \
977                                             RTC_DR_DU)
978 
979 #define RTC_INIT_MASK                       0xFFFFFFFFu
980 #if defined(STM32L412xx) || defined(STM32L422xx) || defined (STM32L4P5xx) || defined (STM32L4Q5xx)
981 #define RTC_RSF_MASK                        (~(RTC_ICSR_INIT | RTC_ICSR_RSF))
982 #else
983 #define RTC_RSF_MASK                        (~(RTC_ISR_INIT | RTC_ISR_RSF))
984 #endif
985 
986 #define RTC_TIMEOUT_VALUE                   1000u
987 
988 #define RTC_EXTI_LINE_ALARM_EVENT           EXTI_IMR1_IM18  /*!< External interrupt line 18 Connected to the RTC Alarm event */
989 
990 /**
991   * @}
992   */
993 
994 /* Private macros ------------------------------------------------------------*/
995 /** @defgroup RTC_Private_Macros RTC Private Macros
996   * @{
997   */
998 
999 /** @defgroup RTC_IS_RTC_Definitions RTC Private macros to check input parameters
1000   * @{
1001   */
1002 #if defined(STM32L412xx) || defined(STM32L422xx) || defined (STM32L4P5xx) || defined (STM32L4Q5xx)
1003 #define IS_RTC_OUTPUT(OUTPUT) (((OUTPUT) == RTC_OUTPUT_DISABLE) || \
1004                                 ((OUTPUT) == RTC_OUTPUT_ALARMA)  || \
1005                                 ((OUTPUT) == RTC_OUTPUT_ALARMB)  || \
1006                                 ((OUTPUT) == RTC_OUTPUT_WAKEUP)  || \
1007                                 ((OUTPUT) == RTC_OUTPUT_TAMPER))
1008 #else
1009 #define IS_RTC_OUTPUT(OUTPUT) (((OUTPUT) == RTC_OUTPUT_DISABLE) || \
1010                                ((OUTPUT) == RTC_OUTPUT_ALARMA)  || \
1011                                ((OUTPUT) == RTC_OUTPUT_ALARMB)  || \
1012                                ((OUTPUT) == RTC_OUTPUT_WAKEUP))
1013 #endif
1014 
1015 #define IS_RTC_HOUR_FORMAT(FORMAT)     (((FORMAT) == RTC_HOURFORMAT_12) || \
1016                                         ((FORMAT) == RTC_HOURFORMAT_24))
1017 
1018 #define IS_RTC_OUTPUT_POL(POL) (((POL) == RTC_OUTPUT_POLARITY_HIGH) || \
1019                                 ((POL) == RTC_OUTPUT_POLARITY_LOW))
1020 
1021 #define IS_RTC_OUTPUT_TYPE(TYPE) (((TYPE) == RTC_OUTPUT_TYPE_OPENDRAIN) || \
1022                                   ((TYPE) == RTC_OUTPUT_TYPE_PUSHPULL))
1023 
1024 #if defined(STM32L412xx) || defined(STM32L422xx) || defined (STM32L4P5xx) || defined (STM32L4Q5xx)
1025 #define IS_RTC_OUTPUT_PULLUP(TYPE) (((TYPE) == RTC_OUTPUT_PULLUP_NONE) || \
1026                                     ((TYPE) == RTC_OUTPUT_PULLUP_ON))
1027 #endif
1028 
1029 #define IS_RTC_OUTPUT_REMAP(REMAP)   (((REMAP) == RTC_OUTPUT_REMAP_NONE) || \
1030                                       ((REMAP) == RTC_OUTPUT_REMAP_POS1))
1031 
1032 #define IS_RTC_HOURFORMAT12(PM)  (((PM) == RTC_HOURFORMAT12_AM) || \
1033                                   ((PM) == RTC_HOURFORMAT12_PM))
1034 
1035 #define IS_RTC_DAYLIGHT_SAVING(SAVE) (((SAVE) == RTC_DAYLIGHTSAVING_SUB1H) || \
1036                                       ((SAVE) == RTC_DAYLIGHTSAVING_ADD1H) || \
1037                                       ((SAVE) == RTC_DAYLIGHTSAVING_NONE))
1038 
1039 #define IS_RTC_STORE_OPERATION(OPERATION) (((OPERATION) == RTC_STOREOPERATION_RESET) || \
1040                                            ((OPERATION) == RTC_STOREOPERATION_SET))
1041 
1042 #define IS_RTC_FORMAT(FORMAT) (((FORMAT) == RTC_FORMAT_BIN) || \
1043                                ((FORMAT) == RTC_FORMAT_BCD))
1044 
1045 #define IS_RTC_YEAR(YEAR)              ((YEAR) <= 99u)
1046 
1047 #define IS_RTC_MONTH(MONTH)            (((MONTH) >= 1u) && ((MONTH) <= 12u))
1048 
1049 #define IS_RTC_DATE(DATE)              (((DATE) >= 1u) && ((DATE) <= 31u))
1050 
1051 #define IS_RTC_WEEKDAY(WEEKDAY) (((WEEKDAY) == RTC_WEEKDAY_MONDAY)    || \
1052                                  ((WEEKDAY) == RTC_WEEKDAY_TUESDAY)   || \
1053                                  ((WEEKDAY) == RTC_WEEKDAY_WEDNESDAY) || \
1054                                  ((WEEKDAY) == RTC_WEEKDAY_THURSDAY)  || \
1055                                  ((WEEKDAY) == RTC_WEEKDAY_FRIDAY)    || \
1056                                  ((WEEKDAY) == RTC_WEEKDAY_SATURDAY)  || \
1057                                  ((WEEKDAY) == RTC_WEEKDAY_SUNDAY))
1058 
1059 #define IS_RTC_ALARM_DATE_WEEKDAY_DATE(DATE) (((DATE) >0u) && ((DATE) <= 31u))
1060 
1061 #define IS_RTC_ALARM_DATE_WEEKDAY_WEEKDAY(WEEKDAY) (((WEEKDAY) == RTC_WEEKDAY_MONDAY)    || \
1062                                                     ((WEEKDAY) == RTC_WEEKDAY_TUESDAY)   || \
1063                                                     ((WEEKDAY) == RTC_WEEKDAY_WEDNESDAY) || \
1064                                                     ((WEEKDAY) == RTC_WEEKDAY_THURSDAY)  || \
1065                                                     ((WEEKDAY) == RTC_WEEKDAY_FRIDAY)    || \
1066                                                     ((WEEKDAY) == RTC_WEEKDAY_SATURDAY)  || \
1067                                                     ((WEEKDAY) == RTC_WEEKDAY_SUNDAY))
1068 
1069 #define IS_RTC_ALARM_DATE_WEEKDAY_SEL(SEL) (((SEL) == RTC_ALARMDATEWEEKDAYSEL_DATE) || \
1070                                             ((SEL) == RTC_ALARMDATEWEEKDAYSEL_WEEKDAY))
1071 
1072 #define IS_RTC_ALARM_MASK(MASK)  (((MASK) & ~(RTC_ALARMMASK_ALL)) == 0U)
1073 
1074 #define IS_RTC_ALARM(ALARM)      (((ALARM) == RTC_ALARM_A) || \
1075                                   ((ALARM) == RTC_ALARM_B))
1076 
1077 #define IS_RTC_ALARM_SUB_SECOND_VALUE(VALUE) ((VALUE) <= RTC_ALRMASSR_SS)
1078 
1079 #define IS_RTC_ALARM_SUB_SECOND_MASK(MASK)          (((MASK) == 0u) || \
1080                                                     (((MASK) >= RTC_ALARMSUBSECONDMASK_SS14_1) && ((MASK) <= RTC_ALARMSUBSECONDMASK_NONE)))
1081 
1082 #define IS_RTC_ASYNCH_PREDIV(PREDIV)   ((PREDIV) <= (RTC_PRER_PREDIV_A >> RTC_PRER_PREDIV_A_Pos))
1083 
1084 #define IS_RTC_SYNCH_PREDIV(PREDIV)    ((PREDIV) <= (RTC_PRER_PREDIV_S >> RTC_PRER_PREDIV_S_Pos))
1085 
1086 #define IS_RTC_HOUR12(HOUR)            (((HOUR) > 0u) && ((HOUR) <= 12u))
1087 
1088 #define IS_RTC_HOUR24(HOUR)            ((HOUR) <= 23u)
1089 
1090 #define IS_RTC_MINUTES(MINUTES)        ((MINUTES) <= 59u)
1091 
1092 #define IS_RTC_SECONDS(SECONDS)        ((SECONDS) <= 59u)
1093 
1094 /**
1095   * @}
1096   */
1097 
1098 /**
1099   * @}
1100   */
1101 
1102 /* Private functions -------------------------------------------------------------*/
1103 /** @defgroup RTC_Private_Functions RTC Private Functions
1104   * @{
1105   */
1106 HAL_StatusTypeDef  RTC_EnterInitMode(RTC_HandleTypeDef *hrtc);
1107 HAL_StatusTypeDef  RTC_ExitInitMode(RTC_HandleTypeDef *hrtc);
1108 uint8_t            RTC_ByteToBcd2(uint8_t Value);
1109 uint8_t            RTC_Bcd2ToByte(uint8_t Value);
1110 /**
1111   * @}
1112   */
1113 
1114 
1115 /**
1116   * @}
1117   */
1118 
1119 /**
1120   * @}
1121   */
1122 
1123 /**
1124   * @}
1125   */
1126 
1127 #ifdef __cplusplus
1128 }
1129 #endif
1130 
1131 #endif /* STM32L4xx_HAL_RTC_H */
1132 
1133 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
1134 
1135