1 /**
2   ******************************************************************************
3   * @file    stm32l4xx_hal_rtc_ex.h
4   * @author  MCD Application Team
5   * @brief   Header file of RTC HAL Extended 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_EX_H
21 #define STM32L4xx_HAL_RTC_EX_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 RTCEx RTCEx
35   * @{
36   */
37 
38 /* Exported types ------------------------------------------------------------*/
39 /** @defgroup RTCEx_Exported_Types RTCEx Exported Types
40   * @{
41   */
42 
43 /** @defgroup RTCEx_Tamper_structure_definition RTCEx Tamper structure definition
44   * @{
45   */
46 typedef struct
47 {
48   uint32_t Tamper;                      /*!< Specifies the Tamper Pin.
49                                              This parameter can be a value of @ref RTCEx_Tamper_Pins_Definitions */
50 
51   uint32_t Interrupt;                   /*!< Specifies the Tamper Interrupt.
52                                              This parameter can be a value of @ref  RTCEx_Tamper_Interrupt_Definitions */
53 
54   uint32_t Trigger;                     /*!< Specifies the Tamper Trigger.
55                                              This parameter can be a value of @ref RTCEx_Tamper_Trigger_Definitions */
56 
57   uint32_t NoErase;                     /*!< Specifies the Tamper no erase mode.
58                                              This parameter can be a value of @ref RTCEx_Tamper_EraseBackUp_Definitions */
59 
60   uint32_t MaskFlag;                    /*!< Specifies the Tamper Flag masking.
61                                              This parameter can be a value of @ref RTCEx_Tamper_MaskFlag_Definitions   */
62 
63   uint32_t Filter;                      /*!< Specifies the TAMP Filter Tamper.
64                                              This parameter can be a value of @ref RTCEx_Tamper_Filter_Definitions */
65 
66   uint32_t SamplingFrequency;           /*!< Specifies the sampling frequency.
67                                              This parameter can be a value of @ref RTCEx_Tamper_Sampling_Frequencies_Definitions */
68 
69   uint32_t PrechargeDuration;           /*!< Specifies the Precharge Duration .
70                                              This parameter can be a value of @ref RTCEx_Tamper_Pin_Precharge_Duration_Definitions */
71 
72   uint32_t TamperPullUp;                /*!< Specifies the Tamper PullUp .
73                                              This parameter can be a value of @ref RTCEx_Tamper_Pull_UP_Definitions */
74 
75   uint32_t TimeStampOnTamperDetection;  /*!< Specifies the TimeStampOnTamperDetection.
76                                              This parameter can be a value of @ref RTCEx_Tamper_TimeStampOnTamperDetection_Definitions */
77 } RTC_TamperTypeDef;
78 /**
79   * @}
80   */
81 
82 /**
83   * @}
84   */
85 
86 /* Exported constants --------------------------------------------------------*/
87 
88 /** @defgroup RTCEx_Exported_Constants RTCEx Exported Constants
89   * @{
90   */
91 
92 /* ========================================================================== */
93 /*                 ##### RTC TimeStamp exported constants #####               */
94 /* ========================================================================== */
95 
96 /** @defgroup RTCEx_Time_Stamp_Edges_definitions RTCEx Time Stamp Edges Definitions
97   *
98   * @{
99   */
100 #define RTC_TIMESTAMPEDGE_RISING        0x00000000u
101 #define RTC_TIMESTAMPEDGE_FALLING       RTC_CR_TSEDGE
102 /**
103   * @}
104   */
105 
106 /** @defgroup RTCEx_TimeStamp_Pin_Selection RTCEx TimeStamp Pin Selection
107   * @{
108   */
109 #define RTC_TIMESTAMPPIN_DEFAULT              0x00000000u
110 /**
111   * @}
112   */
113 
114 /* ========================================================================== */
115 /*                   ##### RTC Wake-up exported constants #####               */
116 /* ========================================================================== */
117 
118 /** @defgroup RTCEx_Wakeup_Timer_Definitions RTCEx Wakeup Timer Definitions
119   * @{
120   */
121 #define RTC_WAKEUPCLOCK_RTCCLK_DIV16        0x00000000u
122 #define RTC_WAKEUPCLOCK_RTCCLK_DIV8         RTC_CR_WUCKSEL_0
123 #define RTC_WAKEUPCLOCK_RTCCLK_DIV4         RTC_CR_WUCKSEL_1
124 #define RTC_WAKEUPCLOCK_RTCCLK_DIV2         (RTC_CR_WUCKSEL_0 | RTC_CR_WUCKSEL_1)
125 #define RTC_WAKEUPCLOCK_CK_SPRE_16BITS      RTC_CR_WUCKSEL_2
126 #define RTC_WAKEUPCLOCK_CK_SPRE_17BITS      (RTC_CR_WUCKSEL_1 | RTC_CR_WUCKSEL_2)
127 /**
128   * @}
129   */
130 
131 /* ========================================================================== */
132 /*        ##### Extended RTC Peripheral Control exported constants #####      */
133 /* ========================================================================== */
134 
135 /** @defgroup RTCEx_Smooth_calib_period_Definitions RTCEx Smooth Calib Period Definitions
136   * @{
137   */
138 #define RTC_SMOOTHCALIB_PERIOD_32SEC   0x00000000u              /*!< If RTCCLK = 32768 Hz, Smooth calibration
139                                                                      period is 32s,  else 2exp20 RTCCLK pulses */
140 #define RTC_SMOOTHCALIB_PERIOD_16SEC   RTC_CALR_CALW16          /*!< If RTCCLK = 32768 Hz, Smooth calibration
141                                                                      period is 16s, else 2exp19 RTCCLK pulses */
142 #define RTC_SMOOTHCALIB_PERIOD_8SEC    RTC_CALR_CALW8           /*!< If RTCCLK = 32768 Hz, Smooth calibration
143                                                                      period is 8s, else 2exp18 RTCCLK pulses */
144 /**
145   * @}
146   */
147 
148 /** @defgroup RTCEx_Smooth_calib_Plus_pulses_Definitions RTCEx Smooth calib Plus pulses Definitions
149   * @{
150   */
151 #define RTC_SMOOTHCALIB_PLUSPULSES_SET    RTC_CALR_CALP         /*!< The number of RTCCLK pulses added
152                                                                      during a X -second window = Y - CALM[8:0]
153                                                                      with Y = 512, 256, 128 when X = 32, 16, 8 */
154 #define RTC_SMOOTHCALIB_PLUSPULSES_RESET  0x00000000u           /*!< The number of RTCCLK pulses subbstited
155                                                                      during a 32-second window = CALM[8:0] */
156 /**
157   * @}
158   */
159 
160 #if defined(STM32L412xx) || defined(STM32L422xx) || defined (STM32L4P5xx) || defined (STM32L4Q5xx)
161 /** @defgroup RTCEx_Smooth_Calib_Low_Power_Definitions RTCEx Smooth Calib Low Power Definitions
162   * @{
163   */
164 #define RTC_LPCAL_SET                     RTC_CALR_LPCAL        /*!< Calibration window is 220 ck_apre,
165                                                                      which is the required configuration for
166                                                                      ultra-low consumption mode. */
167 #define RTC_LPCAL_RESET                   0x00000000u           /*!< Calibration window is 220 RTCCLK,
168                                                                      which is a high-consumption mode.
169                                                                      This mode should be set only when less
170                                                                      than 32s calibration window is required. */
171 /**
172   * @}
173   */
174 #endif /* #if defined(STM32L412xx) || defined(STM32L422xx) || defined (STM32L4P5xx) || defined (STM32L4Q5xx) */
175 
176 /** @defgroup RTCEx_Calib_Output_selection_Definitions RTCEx Calib Output Selection Definitions
177   * @{
178   */
179 #define RTC_CALIBOUTPUT_512HZ            0x00000000u
180 #define RTC_CALIBOUTPUT_1HZ              RTC_CR_COSEL
181 /**
182   * @}
183   */
184 
185 /** @defgroup RTCEx_Add_1_Second_Parameter_Definitions RTC Add 1 Second Parameter Definitions
186   * @{
187   */
188 #define RTC_SHIFTADD1S_RESET      0x00000000u
189 #define RTC_SHIFTADD1S_SET        RTC_SHIFTR_ADD1S
190 /**
191   * @}
192   */
193 
194 
195 /* ========================================================================== */
196 /*                    ##### RTC Tamper exported constants #####               */
197 /* ========================================================================== */
198 
199 /** @defgroup RTCEx_Tamper_Pins_Definitions RTCEx Tamper Pins Definitions
200   * @{
201   */
202 #if defined(STM32L412xx) || defined(STM32L422xx) || defined (STM32L4P5xx) || defined (STM32L4Q5xx)
203 #if defined(RTC_TAMPER1_SUPPORT)
204 #define RTC_TAMPER_1                        TAMP_CR1_TAMP1E
205 #endif /* RTC_TAMPER1_SUPPORT */
206 #define RTC_TAMPER_2                        TAMP_CR1_TAMP2E
207 #if defined(RTC_TAMPER3_SUPPORT)
208 #define RTC_TAMPER_3                        TAMP_CR1_TAMP3E
209 #endif /* RTC_TAMPER3_SUPPORT */
210 #if defined(RTC_TAMPER3_SUPPORT)
211 #define RTC_TAMPER_ALL                      (TAMP_CR1_TAMP1E | TAMP_CR1_TAMP2E | TAMP_CR1_TAMP3E)
212 #else
213 #define RTC_TAMPER_ALL                      (TAMP_CR1_TAMP1E | TAMP_CR1_TAMP2E)
214 #endif
215 #else /* #if defined(STM32L412xx) || defined(STM32L422xx) || defined (STM32L4P5xx) || defined (STM32L4Q5xx) */
216 #if defined(RTC_TAMPER1_SUPPORT)
217 #define RTC_TAMPER_1                        RTC_TAMPCR_TAMP1E
218 #endif /* RTC_TAMPER1_SUPPORT */
219 #define RTC_TAMPER_2                        RTC_TAMPCR_TAMP2E
220 #if defined(RTC_TAMPER3_SUPPORT)
221 #define RTC_TAMPER_3                        RTC_TAMPCR_TAMP3E
222 #endif /* RTC_TAMPER3_SUPPORT */
223 #endif /* #if defined(STM32L412xx) || defined(STM32L422xx) || defined (STM32L4P5xx) || defined (STM32L4Q5xx) */
224 /**
225   * @}
226   */
227 
228 /** @defgroup RTCEx_Tamper_Trigger_Definitions RTCEx Tamper Triggers Definitions
229   * @{
230   */
231 #if defined(STM32L412xx) || defined(STM32L422xx) || defined (STM32L4P5xx) || defined (STM32L4Q5xx)
232 #define RTC_TAMPERTRIGGER_RISINGEDGE        0x00u  /*!< Warning : Filter must be RTC_TAMPERFILTER_DISABLE */
233 #define RTC_TAMPERTRIGGER_FALLINGEDGE       0x01u  /*!< Warning : Filter must be RTC_TAMPERFILTER_DISABLE */
234 #define RTC_TAMPERTRIGGER_LOWLEVEL          0x02u  /*!< Warning : Filter must not be RTC_TAMPERFILTER_DISABLE */
235 #define RTC_TAMPERTRIGGER_HIGHLEVEL         0x03u  /*!< Warning : Filter must not be RTC_TAMPERFILTER_DISABLE */
236 #else
237 #define RTC_TAMPERTRIGGER_RISINGEDGE        ((uint32_t)0x00000000)
238 #define RTC_TAMPERTRIGGER_FALLINGEDGE       ((uint32_t)0x00000002)
239 #define RTC_TAMPERTRIGGER_LOWLEVEL          RTC_TAMPERTRIGGER_RISINGEDGE
240 #define RTC_TAMPERTRIGGER_HIGHLEVEL         RTC_TAMPERTRIGGER_FALLINGEDGE
241 #endif
242 /**
243   * @}
244   */
245 
246 /** @defgroup RTCEx_Tamper_MaskFlag_Definitions RTCEx Tamper Mask Flag Definitions
247   * @{
248   */
249 #if defined(STM32L412xx) || defined(STM32L422xx) || defined (STM32L4P5xx) || defined (STM32L4Q5xx)
250 #define RTC_TAMPERMASK_FLAG_DISABLE         0x00u
251 #define RTC_TAMPERMASK_FLAG_ENABLE          0x01u
252 #else
253 #define RTC_TAMPERMASK_FLAG_DISABLE         0x00000000u
254 #define RTC_TAMPERMASK_FLAG_ENABLE          0x00040000u
255 #endif
256 /**
257   * @}
258   */
259 
260 /** @defgroup RTCEx_Tamper_EraseBackUp_Definitions RTCEx Tamper EraseBackUp Definitions
261 * @{
262 */
263 #if defined(STM32L412xx) || defined(STM32L422xx) || defined (STM32L4P5xx) || defined (STM32L4Q5xx)
264 #define RTC_TAMPER_ERASE_BACKUP_ENABLE      0x00u
265 #define RTC_TAMPER_ERASE_BACKUP_DISABLE     0x01u
266 #else
267 #define RTC_TAMPER_ERASE_BACKUP_ENABLE      0x00000000u
268 #define RTC_TAMPER_ERASE_BACKUP_DISABLE     0x00020000u
269 #endif
270 /**
271   * @}
272   */
273 
274 /** @defgroup RTCEx_Tamper_Filter_Definitions RTCEx Tamper Filter Definitions
275   * @{
276   */
277 #if defined(STM32L412xx) || defined(STM32L422xx) || defined (STM32L4P5xx) || defined (STM32L4Q5xx)
278 #define RTC_TAMPERFILTER_DISABLE           0x00000000U             /*!< Tamper filter is disabled */
279 
280 #define RTC_TAMPERFILTER_2SAMPLE           TAMP_FLTCR_TAMPFLT_0    /*!< Tamper is activated after 2
281                                                                          consecutive samples at the active level */
282 #define RTC_TAMPERFILTER_4SAMPLE           TAMP_FLTCR_TAMPFLT_1    /*!< Tamper is activated after 4
283                                                                          consecutive samples at the active level */
284 #define RTC_TAMPERFILTER_8SAMPLE           TAMP_FLTCR_TAMPFLT      /*!< Tamper is activated after 8
285                                                                          consecutive samples at the active level */
286 #else /* #if defined(STM32L412xx) || defined(STM32L422xx) || defined (STM32L4P5xx) || defined (STM32L4Q5xx) */
287 #define RTC_TAMPERFILTER_DISABLE           0x00000000u             /*!< Tamper filter is disabled */
288 
289 #define RTC_TAMPERFILTER_2SAMPLE           RTC_TAMPCR_TAMPFLT_0    /*!< Tamper is activated after 2
290                                                                         consecutive samples at the active level */
291 #define RTC_TAMPERFILTER_4SAMPLE           RTC_TAMPCR_TAMPFLT_1    /*!< Tamper is activated after 4
292                                                                          consecutive samples at the active level */
293 #define RTC_TAMPERFILTER_8SAMPLE           RTC_TAMPCR_TAMPFLT      /*!< Tamper is activated after 8
294                                                                          consecutive samples at the active level. */
295 #endif /*#if defined(STM32L412xx) || defined(STM32L422xx) || defined (STM32L4P5xx) || defined (STM32L4Q5xx) */
296 
297 /**
298   * @}
299   */
300 
301 /** @defgroup RTCEx_Tamper_Sampling_Frequencies_Definitions RTCEx Tamper Sampling Frequencies Definitions
302   * @{
303   */
304 #if defined(STM32L412xx) || defined(STM32L422xx) || defined (STM32L4P5xx) || defined (STM32L4Q5xx)
305 #define RTC_TAMPERSAMPLINGFREQ_RTCCLK_DIV32768  0x00000000U                                     /*!< Each of the tamper inputs are sampled
306                                                                                                       with a frequency =  RTCCLK / 32768 */
307 #define RTC_TAMPERSAMPLINGFREQ_RTCCLK_DIV16384  TAMP_FLTCR_TAMPFREQ_0                           /*!< Each of the tamper inputs are sampled
308                                                                                                       with a frequency =  RTCCLK / 16384 */
309 #define RTC_TAMPERSAMPLINGFREQ_RTCCLK_DIV8192   TAMP_FLTCR_TAMPFREQ_1                           /*!< Each of the tamper inputs are sampled
310                                                                                                       with a frequency =  RTCCLK / 8192  */
311 #define RTC_TAMPERSAMPLINGFREQ_RTCCLK_DIV4096   (TAMP_FLTCR_TAMPFREQ_0 | TAMP_FLTCR_TAMPFREQ_1) /*!< Each of the tamper inputs are sampled
312                                                                                                       with a frequency =  RTCCLK / 4096  */
313 #define RTC_TAMPERSAMPLINGFREQ_RTCCLK_DIV2048   TAMP_FLTCR_TAMPFREQ_2                           /*!< Each of the tamper inputs are sampled
314                                                                                                       with a frequency =  RTCCLK / 2048  */
315 #define RTC_TAMPERSAMPLINGFREQ_RTCCLK_DIV1024   (TAMP_FLTCR_TAMPFREQ_0 | TAMP_FLTCR_TAMPFREQ_2) /*!< Each of the tamper inputs are sampled
316                                                                                                       with a frequency =  RTCCLK / 1024  */
317 #define RTC_TAMPERSAMPLINGFREQ_RTCCLK_DIV512    (TAMP_FLTCR_TAMPFREQ_1 | TAMP_FLTCR_TAMPFREQ_2) /*!< Each of the tamper inputs are sampled
318                                                                                                       with a frequency =  RTCCLK / 512   */
319 #define RTC_TAMPERSAMPLINGFREQ_RTCCLK_DIV256    TAMP_FLTCR_TAMPFREQ                             /*!< Each of the tamper inputs are sampled
320                                                                                                       with a frequency =  RTCCLK / 256   */
321 #define RTC_TAMPERSAMPLINGFREQ_RTCCLK_MASK      TAMP_FLTCR_TAMPFREQ                             /*!< Masking all bits except those of
322                                                                                                       field TAMPFREQ[2:0]*/
323 #else /* #if defined(STM32L412xx) || defined(STM32L422xx) || defined (STM32L4P5xx) || defined (STM32L4Q5xx) */
324 
325 #define RTC_TAMPERSAMPLINGFREQ_RTCCLK_DIV32768  0x00000000u                                     /*!< Each of the tamper inputs are sampled
326                                                                                                       with a frequency =  RTCCLK / 32768 */
327 #define RTC_TAMPERSAMPLINGFREQ_RTCCLK_DIV16384  RTC_TAMPCR_TAMPFREQ_0                           /*!< Each of the tamper inputs are sampled
328                                                                                                       with a frequency =  RTCCLK / 16384 */
329 #define RTC_TAMPERSAMPLINGFREQ_RTCCLK_DIV8192   RTC_TAMPCR_TAMPFREQ_1                           /*!< Each of the tamper inputs are sampled
330                                                                                                       with a frequency =  RTCCLK / 8192  */
331 #define RTC_TAMPERSAMPLINGFREQ_RTCCLK_DIV4096   (RTC_TAMPCR_TAMPFREQ_0 | RTC_TAMPCR_TAMPFREQ_1) /*!< Each of the tamper inputs are sampled
332                                                                                                       with a frequency =  RTCCLK / 4096  */
333 #define RTC_TAMPERSAMPLINGFREQ_RTCCLK_DIV2048   RTC_TAMPCR_TAMPFREQ_2                           /*!< Each of the tamper inputs are sampled
334                                                                                                       with a frequency =  RTCCLK / 2048  */
335 #define RTC_TAMPERSAMPLINGFREQ_RTCCLK_DIV1024   (RTC_TAMPCR_TAMPFREQ_0 | RTC_TAMPCR_TAMPFREQ_2)  /*!< Each of the tamper inputs are sampled
336                                                                                                       with a frequency =  RTCCLK / 1024  */
337 #define RTC_TAMPERSAMPLINGFREQ_RTCCLK_DIV512    (RTC_TAMPCR_TAMPFREQ_1 | RTC_TAMPCR_TAMPFREQ_2)  /*!< Each of the tamper inputs are sampled
338                                                                                                       with a frequency =  RTCCLK / 512   */
339 #define RTC_TAMPERSAMPLINGFREQ_RTCCLK_DIV256    RTC_TAMPCR_TAMPFREQ                              /*!< Each of the tamper inputs are sampled
340                                                                                                       with a frequency =  RTCCLK / 256   */
341 #define RTC_TAMPERSAMPLINGFREQ_RTCCLK_MASK      RTC_TAMPCR_TAMPFREQ                             /*!< Masking all bits except those of
342                                                                                                       field TAMPFREQ[2:0]*/
343 #endif /* #if defined(STM32L412xx) || defined(STM32L422xx) || defined (STM32L4P5xx) || defined (STM32L4Q5xx) */
344 /**
345   * @}
346   */
347 
348 /** @defgroup RTCEx_Tamper_Pin_Precharge_Duration_Definitions RTCEx Tamper Pin Precharge Duration Definitions
349   * @{
350   */
351 #if defined(STM32L412xx) || defined(STM32L422xx) || defined (STM32L4P5xx) || defined (STM32L4Q5xx)
352 #define RTC_TAMPERPRECHARGEDURATION_1RTCCLK     0x00000000U                                       /*!< Tamper pins are pre-charged before
353                                                                                                         sampling during 1 RTCCLK cycle  */
354 #define RTC_TAMPERPRECHARGEDURATION_2RTCCLK     TAMP_FLTCR_TAMPPRCH_0                             /*!< Tamper pins are pre-charged before
355                                                                                                         sampling during 2 RTCCLK cycles */
356 #define RTC_TAMPERPRECHARGEDURATION_4RTCCLK     TAMP_FLTCR_TAMPPRCH_1                             /*!< Tamper pins are pre-charged before
357                                                                                                         sampling during 4 RTCCLK cycles */
358 #define RTC_TAMPERPRECHARGEDURATION_8RTCCLK     TAMP_FLTCR_TAMPPRCH     /*!< Tamper pins are pre-charged before
359                                                                          sampling during 8 RTCCLK cycles */
360 #else /* #if defined(STM32L412xx) || defined(STM32L422xx) || defined (STM32L4P5xx) || defined (STM32L4Q5xx) */
361 
362 #define RTC_TAMPERPRECHARGEDURATION_1RTCCLK     0x00000000u             /*!< Tamper pins are pre-charged before
363                                                                               sampling during 1 RTCCLK cycle  */
364 #define RTC_TAMPERPRECHARGEDURATION_2RTCCLK     RTC_TAMPCR_TAMPPRCH_0   /*!< Tamper pins are pre-charged before
365                                                                               sampling during 2 RTCCLK cycles */
366 #define RTC_TAMPERPRECHARGEDURATION_4RTCCLK     RTC_TAMPCR_TAMPPRCH_1   /*!< Tamper pins are pre-charged before
367                                                                               sampling during 4 RTCCLK cycles */
368 #define RTC_TAMPERPRECHARGEDURATION_8RTCCLK     RTC_TAMPCR_TAMPPRCH     /*!< Tamper pins are pre-charged before
369                                                                               sampling during 8 RTCCLK cycles */
370 #define RTC_TAMPERPRECHARGEDURATION_MASK        RTC_TAMPCR_TAMPPRCH     /*!< Masking all bits except those of
371                                                                               field TAMPPRCH[1:0] */
372 #endif /* #if defined(STM32L412xx) || defined(STM32L422xx) || defined (STM32L4P5xx) || defined (STM32L4Q5xx) */
373 /**
374   * @}
375   */
376 
377 /** @defgroup RTCEx_Tamper_Pull_UP_Definitions RTCEx Tamper Pull Up Definitions
378   * @{
379   */
380 #if defined(STM32L412xx) || defined(STM32L422xx) || defined (STM32L4P5xx) || defined (STM32L4Q5xx)
381 #define RTC_TAMPER_PULLUP_ENABLE           0x00000000u           /*!< Tamper pins are pre-charged before sampling */
382 #define RTC_TAMPER_PULLUP_DISABLE          TAMP_FLTCR_TAMPPUDIS  /*!< Tamper pins pre-charge is disabled          */
383 #else
384 #define RTC_TAMPER_PULLUP_ENABLE           0x00000000u           /*!< TimeStamp on Tamper Detection event saved        */
385 #define RTC_TAMPER_PULLUP_DISABLE          RTC_TAMPCR_TAMPPUDIS  /*!< TimeStamp on Tamper Detection event is not saved */
386 #endif
387 
388 /**
389   * @}
390   */
391 
392 /** @defgroup RTCEx_Tamper_TimeStampOnTamperDetection_Definitions RTCEx Tamper TimeStamp On Tamper Detection Definitions
393   * @{
394   */
395 #if defined(STM32L412xx) || defined(STM32L422xx) || defined (STM32L4P5xx) || defined (STM32L4Q5xx)
396 #define RTC_TIMESTAMPONTAMPERDETECTION_DISABLE  0x00000000u    /*!< TimeStamp on Tamper Detection event is not saved */
397 #define RTC_TIMESTAMPONTAMPERDETECTION_ENABLE   RTC_CR_TAMPTS  /*!< TimeStamp on Tamper Detection event saved        */
398 #else
399 #define RTC_TIMESTAMPONTAMPERDETECTION_DISABLE  0x00000000u        /*!< TimeStamp on Tamper Detection event is not saved */
400 #define RTC_TIMESTAMPONTAMPERDETECTION_ENABLE   RTC_TAMPCR_TAMPTS  /*!< TimeStamp on Tamper Detection event saved        */
401 #endif
402 /**
403   * @}
404   */
405 
406 /** @defgroup RTCEx_Tamper_Interrupt_Definitions RTC Tamper Interrupts Definitions
407   * @{
408   */
409 
410 #if defined(STM32L412xx) || defined(STM32L422xx)
411 #define RTC_IT_TAMP1                        TAMP_IER_TAMP1IE   /*!< Tamper 1 Interrupt */
412 #define RTC_IT_TAMP2                        TAMP_IER_TAMP2IE   /*!< Tamper 2 Interrupt */
413 #define RTC_IT_TAMP                         (TAMP_IER_TAMP1IE | TAMP_IER_TAMP2IE)  /*!< Enable all Tamper Interrupt */
414 #elif defined (STM32L4P5xx) || defined (STM32L4Q5xx)
415 #define RTC_IT_TAMP1                        TAMP_IER_TAMP1IE   /*!< Tamper 1 Interrupt */
416 #define RTC_IT_TAMP2                        TAMP_IER_TAMP2IE   /*!< Tamper 2 Interrupt */
417 #define RTC_IT_TAMP3                        TAMP_IER_TAMP3IE   /*!< Tamper 3 Interrupt */
418 #define RTC_IT_TAMP                         (TAMP_IER_TAMP1IE | TAMP_IER_TAMP2IE | TAMP_IER_TAMP3IE)  /*!< Enable all Tamper Interrupt */
419 #else
420 #define RTC_IT_TAMP                         RTC_TAMPCR_TAMPIE  /*!< Enable all Tamper Interrupt  */
421 #define RTC_IT_TAMP1                        RTC_TAMPCR_TAMP1IE /*!< Enable Tamper 1 Interrupt     */
422 #define RTC_IT_TAMP2                        RTC_TAMPCR_TAMP2IE /*!< Enable Tamper 2 Interrupt     */
423 #define RTC_IT_TAMP3                        RTC_TAMPCR_TAMP3IE /*!< Enable Tamper 3 Interrupt     */
424 #endif
425 #define RTC_IT_TAMPALL                      RTC_IT_TAMP
426 /**
427   * @}
428   */
429 
430 /** @defgroup RTCEx_Flags  RTCEx Flags
431   * @{
432   */
433 #if defined(STM32L412xx) || defined(STM32L422xx)
434 #define RTC_FLAG_TAMP1F                     TAMP_SR_TAMP1F
435 #define RTC_FLAG_TAMP2F                     TAMP_SR_TAMP2F
436 #define RTC_FLAG_TAMPALL                   (RTC_FLAG_TAMP1F | RTC_FLAG_TAMP2F)
437 #elif defined (STM32L4P5xx) || defined (STM32L4Q5xx)
438 #define RTC_FLAG_TAMP1F                     TAMP_SR_TAMP1F
439 #define RTC_FLAG_TAMP2F                     TAMP_SR_TAMP2F
440 #define RTC_FLAG_TAMP3F                     TAMP_SR_TAMP3F
441 #define RTC_FLAG_TAMPALL                   (RTC_FLAG_TAMP1F | RTC_FLAG_TAMP2F | RTC_FLAG_TAMP3F)
442 #else
443 #define RTC_FLAG_TAMP1F                     RTC_ISR_TAMP1F
444 #define RTC_FLAG_TAMP2F                     RTC_ISR_TAMP2F
445 #define RTC_FLAG_TAMP3F                     RTC_ISR_TAMP3F
446 #endif
447 /**
448   * @}
449   */
450 
451 /* ========================================================================== */
452 /*         ##### Extended RTC Backup registers exported constants #####       */
453 /* ========================================================================== */
454 
455 /** @defgroup RTCEx_Backup_Data_Registers_Number_Definitions RTC Backup Data Registers Number Definitions
456   * @{
457   */
458 #if defined(RTC_BKP_NUMBER)
459 #define BKP_REG_NUMBER                       RTC_BKP_NUMBER
460 #endif /* RTC_BKP_NUMBER */
461 #if defined(TAMP_BKP_NUMBER)
462 #define BKP_REG_NUMBER                       TAMP_BKP_NUMBER
463 #endif /* TAMP_BKP_NUMBER */
464 /**
465   * @}
466   */
467 
468 /** @defgroup RTCEx_Backup_Data_Registers_Definitions RTCEx Backup Data Registers Definitions
469   * @{
470   */
471 #define RTC_BKP_DR0                       0x00u
472 #define RTC_BKP_DR1                       0x01u
473 #define RTC_BKP_DR2                       0x02u
474 #define RTC_BKP_DR3                       0x03u
475 #define RTC_BKP_DR4                       0x04u
476 #define RTC_BKP_DR5                       0x05u
477 #define RTC_BKP_DR6                       0x06u
478 #define RTC_BKP_DR7                       0x07u
479 #define RTC_BKP_DR8                       0x08u
480 #define RTC_BKP_DR9                       0x09u
481 #define RTC_BKP_DR10                      0x0Au
482 #define RTC_BKP_DR11                      0x0Bu
483 #define RTC_BKP_DR12                      0x0Cu
484 #define RTC_BKP_DR13                      0x0Du
485 #define RTC_BKP_DR14                      0x0Eu
486 #define RTC_BKP_DR15                      0x0Fu
487 #define RTC_BKP_DR16                      0x10u
488 #define RTC_BKP_DR17                      0x11u
489 #define RTC_BKP_DR18                      0x12u
490 #define RTC_BKP_DR19                      0x13u
491 #define RTC_BKP_DR20                      0x14u
492 #define RTC_BKP_DR21                      0x15u
493 #define RTC_BKP_DR22                      0x16u
494 #define RTC_BKP_DR23                      0x17u
495 #define RTC_BKP_DR24                      0x18u
496 #define RTC_BKP_DR25                      0x19u
497 #define RTC_BKP_DR26                      0x1Au
498 #define RTC_BKP_DR27                      0x1Bu
499 #define RTC_BKP_DR28                      0x1Cu
500 #define RTC_BKP_DR29                      0x1Du
501 #define RTC_BKP_DR30                      0x1Eu
502 #define RTC_BKP_DR31                      0x1Fu
503 /**
504   * @}
505   */
506 
507 
508 
509 
510 /** @defgroup RTCEx_Tamper_Interrupt_Definitions RTC Tamper Interrupts Definitions
511   * @{
512   */
513 #if defined(STM32L412xx) || defined(STM32L422xx)
514 #define RTC_TAMPER1_INTERRUPT              TAMP_IER_TAMP1IE
515 #define RTC_TAMPER2_INTERRUPT              TAMP_IER_TAMP2IE
516 #define RTC_ALL_TAMPER_INTERRUPT           (TAMP_IER_TAMP1IE | TAMP_IER_TAMP2IE)
517 #elif defined (STM32L4P5xx) || defined (STM32L4Q5xx)
518 #define RTC_TAMPER1_INTERRUPT              TAMP_IER_TAMP1IE
519 #define RTC_TAMPER2_INTERRUPT              TAMP_IER_TAMP2IE
520 #define RTC_TAMPER3_INTERRUPT              TAMP_IER_TAMP3IE
521 #define RTC_ALL_TAMPER_INTERRUPT           (TAMP_IER_TAMP1IE | TAMP_IER_TAMP2IE | TAMP_IER_TAMP3IE)
522 #else /* #if defined(STM32L412xx) || defined(STM32L422xx) */
523 #if defined(RTC_TAMPER1_SUPPORT)
524 #define RTC_TAMPER1_INTERRUPT              RTC_TAMPCR_TAMP1IE
525 #endif /* RTC_TAMPER1_SUPPORT */
526 #define RTC_TAMPER2_INTERRUPT              RTC_TAMPCR_TAMP2IE
527 #if defined(RTC_TAMPER3_SUPPORT)
528 #define RTC_TAMPER3_INTERRUPT              RTC_TAMPCR_TAMP3IE
529 #endif /* RTC_TAMPER3_SUPPORT */
530 #define RTC_ALL_TAMPER_INTERRUPT           RTC_TAMPCR_TAMPIE
531 #endif /* #if defined(STM32L412xx) || defined(STM32L422xx) */
532 
533 
534 #if defined (STM32L4P5xx) || defined (STM32L4Q5xx)
535 /** @defgroup RTCEx_Binary_Mode RTC Binary Mode (32-bit free-running counter configuration).
536   *           Warning : It Should not be confused with the Binary format @ref RTC_Input_parameter_format_definitions.
537   * @{
538   */
539 #define RTC_BINARY_NONE                     0x00000000u      /*!< Free running BCD calendar mode (Binary mode disabled). */
540 #define RTC_BINARY_ONLY                     RTC_ICSR_BIN_0   /*!< Free running Binary mode (BCD mode disabled) */
541 #define RTC_BINARY_MIX                      RTC_ICSR_BIN_1   /*!< Free running BCD calendar and Binary modes */
542 /**
543   * @}
544   */
545 
546 /** @defgroup RTCEx_Binary_mix_BCDU If Binary mode is RTC_BINARY_MIX, the BCD calendar second is incremented using the SSR Least Significant Bits.
547   * @{
548   */
549 #define RTC_BINARY_MIX_BCDU_0  0x00000000u                   /*!<  The 1s BCD calendar increment is generated each time SS[7:0] = 0 */
550 #define RTC_BINARY_MIX_BCDU_1  (0x1UL << RTC_ICSR_BCDU_Pos)  /*!<  The 1s BCD calendar increment is generated each time SS[8:0] = 0 */
551 #define RTC_BINARY_MIX_BCDU_2  (0x2UL << RTC_ICSR_BCDU_Pos)  /*!<  The 1s BCD calendar increment is generated each time SS[9:0] = 0 */
552 #define RTC_BINARY_MIX_BCDU_3  (0x3UL << RTC_ICSR_BCDU_Pos)  /*!<  The 1s BCD calendar increment is generated each time SS[10:0] = 0 */
553 #define RTC_BINARY_MIX_BCDU_4  (0x4UL << RTC_ICSR_BCDU_Pos)  /*!<  The 1s BCD calendar increment is generated each time SS[11:0] = 0 */
554 #define RTC_BINARY_MIX_BCDU_5  (0x5UL << RTC_ICSR_BCDU_Pos)  /*!<  The 1s BCD calendar increment is generated each time SS[12:0] = 0 */
555 #define RTC_BINARY_MIX_BCDU_6  (0x6UL << RTC_ICSR_BCDU_Pos)  /*!<  The 1s BCD calendar increment is generated each time SS[13:0] = 0 */
556 #define RTC_BINARY_MIX_BCDU_7  (0x7UL << RTC_ICSR_BCDU_Pos)  /*!<  The 1s BCD calendar increment is generated each time SS[14:0] = 0 */
557 /**
558   * @}
559   */
560 
561 /** @defgroup RTCEx_Alarm_Sub_Seconds_binary_Masks_Definitions RTC Alarm Sub Seconds with binary mode Masks Definitions
562   * @{
563   */
564 #define RTC_ALARMSUBSECONDBINMASK_ALL           0x00000000u                                                             /*!< All Alarm SS fields are masked.
565                                                                                                                           There is no comparison on sub seconds for Alarm */
566 #define RTC_ALARMSUBSECONDBINMASK_SS31_1        (1UL << RTC_ALRMASSR_MASKSS_Pos)                                        /*!< SS[31:1] are don't care in Alarm
567                                                                                                                           comparison. Only SS[0] is compared.    */
568 #define RTC_ALARMSUBSECONDBINMASK_SS31_2        (2UL << RTC_ALRMASSR_MASKSS_Pos)                                        /*!< SS[31:2] are don't care in Alarm
569                                                                                                                           comparison. Only SS[1:0] are compared  */
570 #define RTC_ALARMSUBSECONDBINMASK_SS31_3        (3UL << RTC_ALRMASSR_MASKSS_Pos)                                        /*!< SS[31:3] are don't care in Alarm
571                                                                                                                           comparison. Only SS[2:0] are compared  */
572 #define RTC_ALARMSUBSECONDBINMASK_SS31_4        (4UL << RTC_ALRMASSR_MASKSS_Pos)                                        /*!< SS[31:4] are don't care in Alarm
573                                                                                                                           comparison. Only SS[3:0] are compared  */
574 #define RTC_ALARMSUBSECONDBINMASK_SS31_5        (5UL << RTC_ALRMASSR_MASKSS_Pos)                                        /*!< SS[31:5] are don't care in Alarm
575                                                                                                                           comparison. Only SS[4:0] are compared  */
576 #define RTC_ALARMSUBSECONDBINMASK_SS31_6        (6UL << RTC_ALRMASSR_MASKSS_Pos)                                        /*!< SS[31:6] are don't care in Alarm
577                                                                                                                           comparison. Only SS[5:0] are compared  */
578 #define RTC_ALARMSUBSECONDBINMASK_SS31_7        (7UL << RTC_ALRMASSR_MASKSS_Pos)                                        /*!< SS[31:7] are don't care in Alarm
579                                                                                                                           comparison. Only SS[6:0] are compared  */
580 #define RTC_ALARMSUBSECONDBINMASK_SS31_8        (8UL << RTC_ALRMASSR_MASKSS_Pos)                                        /*!< SS[31:8] are don't care in Alarm
581                                                                                                                           comparison. Only SS[7:0] are compared  */
582 #define RTC_ALARMSUBSECONDBINMASK_SS31_9        (9UL << RTC_ALRMASSR_MASKSS_Pos)                                        /*!< SS[31:9] are don't care in Alarm
583                                                                                                                           comparison. Only SS[8:0] are compared  */
584 #define RTC_ALARMSUBSECONDBINMASK_SS31_10      (10UL << RTC_ALRMASSR_MASKSS_Pos)                                        /*!< SS[31:10] are don't care in Alarm
585                                                                                                                           comparison. Only SS[9:0] are compared  */
586 #define RTC_ALARMSUBSECONDBINMASK_SS31_11      (11UL << RTC_ALRMASSR_MASKSS_Pos)                                        /*!< SS[31:11] are don't care in Alarm
587                                                                                                                           comparison. Only SS[10:0] are compared */
588 #define RTC_ALARMSUBSECONDBINMASK_SS31_12      (12UL << RTC_ALRMASSR_MASKSS_Pos)                                        /*!< SS[31:12] are don't care in Alarm
589                                                                                                                           comparison.Only SS[11:0] are compared  */
590 #define RTC_ALARMSUBSECONDBINMASK_SS31_13      (13UL << RTC_ALRMASSR_MASKSS_Pos)                                        /*!< SS[31:13] are don't care in Alarm
591                                                                                                                           comparison. Only SS[12:0] are compared */
592 #define RTC_ALARMSUBSECONDBINMASK_SS31_14      (14UL << RTC_ALRMASSR_MASKSS_Pos)                                        /*!< SS[31:14] are don't care in Alarm
593                                                                                                                           comparison. Only SS[13:0] are compared */
594 #define RTC_ALARMSUBSECONDBINMASK_SS31_15      (15UL << RTC_ALRMASSR_MASKSS_Pos)                                        /*!< SS[31:15] are don't care in Alarm
595                                                                                                                           comparison. Only SS[14:0] are compared */
596 #define RTC_ALARMSUBSECONDBINMASK_SS31_16      (16UL << RTC_ALRMASSR_MASKSS_Pos)                                        /*!< SS[31:16] are don't care in Alarm
597                                                                                                                           comparison. Only SS[15:0] are compared */
598 #define RTC_ALARMSUBSECONDBINMASK_SS31_17      (17UL << RTC_ALRMASSR_MASKSS_Pos)                                        /*!< SS[31:17] are don't care in Alarm
599                                                                                                                           comparison. Only SS[16:0] are compared */
600 #define RTC_ALARMSUBSECONDBINMASK_SS31_18      (18UL << RTC_ALRMASSR_MASKSS_Pos)                                        /*!< SS[31:18] are don't care in Alarm
601                                                                                                                           comparison. Only SS[17:0] are compared */
602 #define RTC_ALARMSUBSECONDBINMASK_SS31_19      (19UL << RTC_ALRMASSR_MASKSS_Pos)                                        /*!< SS[31:19] are don't care in Alarm
603                                                                                                                           comparison. Only SS[18:0] are compared */
604 #define RTC_ALARMSUBSECONDBINMASK_SS31_20      (20UL << RTC_ALRMASSR_MASKSS_Pos)                                        /*!< SS[31:20] are don't care in Alarm
605                                                                                                                           comparison. Only SS[19:0] are compared */
606 #define RTC_ALARMSUBSECONDBINMASK_SS31_21      (21UL << RTC_ALRMASSR_MASKSS_Pos)                                        /*!< SS[31:21] are don't care in Alarm
607                                                                                                                           comparison. Only SS[20:0] are compared */
608 #define RTC_ALARMSUBSECONDBINMASK_SS31_22      (22UL << RTC_ALRMASSR_MASKSS_Pos)                                        /*!< SS[31:22] are don't care in Alarm
609                                                                                                                           comparison. Only SS[21:0] are compared */
610 #define RTC_ALARMSUBSECONDBINMASK_SS31_23      (23UL << RTC_ALRMASSR_MASKSS_Pos)                                        /*!< SS[31:23] are don't care in Alarm
611                                                                                                                           comparison. Only SS[22:0] are compared */
612 #define RTC_ALARMSUBSECONDBINMASK_SS31_24      (24UL << RTC_ALRMASSR_MASKSS_Pos)                                        /*!< SS[31:24] are don't care in Alarm
613                                                                                                                           comparison. Only SS[23:0] are compared */
614 #define RTC_ALARMSUBSECONDBINMASK_SS31_25      (25UL << RTC_ALRMASSR_MASKSS_Pos)                                        /*!< SS[31:25] are don't care in Alarm
615                                                                                                                           comparison. Only SS[24:0] are compared */
616 #define RTC_ALARMSUBSECONDBINMASK_SS31_26      (26UL << RTC_ALRMASSR_MASKSS_Pos)                                        /*!< SS[31:26] are don't care in Alarm
617                                                                                                                           comparison. Only SS[25:0] are compared */
618 #define RTC_ALARMSUBSECONDBINMASK_SS31_27      (27UL << RTC_ALRMASSR_MASKSS_Pos)                                        /*!< SS[31:27] are don't care in Alarm
619                                                                                                                           comparison. Only SS[26:0] are compared */
620 #define RTC_ALARMSUBSECONDBINMASK_SS31_28      (28UL << RTC_ALRMASSR_MASKSS_Pos)                                        /*!< SS[31:28] are don't care in Alarm
621                                                                                                                           comparison. Only SS[27:0] are compared */
622 #define RTC_ALARMSUBSECONDBINMASK_SS31_29      (29UL << RTC_ALRMASSR_MASKSS_Pos)                                        /*!< SS[31:29] are don't care in Alarm
623                                                                                                                           comparison. Only SS[28:0] are compared */
624 #define RTC_ALARMSUBSECONDBINMASK_SS31_30      (30UL << RTC_ALRMASSR_MASKSS_Pos)                                        /*!< SS[31:30] are don't care in Alarm
625                                                                                                                           comparison. Only SS[29:0] are compared */
626 #define RTC_ALARMSUBSECONDBINMASK_SS31         (31UL << RTC_ALRMASSR_MASKSS_Pos)                                        /*!< SS[31] is don't care in Alarm
627                                                                                                                           comparison. Only SS[30:0] are compared  */
628 #define RTC_ALARMSUBSECONDBINMASK_NONE         (32UL << RTC_ALRMASSR_MASKSS_Pos)                                        /*!< SS[31:0] are compared and must match to activate alarm. */
629 /**
630   * @}
631   */
632 
633 /** @defgroup RTCEx_Alarm_Sub_Seconds_binary_Clear_Definitions RTC Alarm Sub Seconds with binary mode auto clear Definitions
634   * @{
635   */
636 #define RTC_ALARMSUBSECONDBIN_AUTOCLR_NO    0UL                  /*!<  The synchronous Binary counter (SS[31:0] in RTC_SSR) is free-running. */
637 #define RTC_ALARMSUBSECONDBIN_AUTOCLR_YES   RTC_ALRMASSR_SSCLR   /*!<  The synchronous Binary counter (SS[31:0] in RTC_SSR) is running from 0xFFFF FFFF to
638                                                                           RTC_ALRMABINR -> SS[31:0] value and is automatically reloaded with 0xFFFF FFFF
639                                                                           whenreaching RTC_ALRMABINR -> SS[31:0]. */
640 /**
641   * @}
642   */
643 #endif /* #if defined (STM32L4P5xx) || defined (STM32L4Q5xx) */
644 
645 
646 /**
647   * @}
648   */
649 
650 /* Exported macros -----------------------------------------------------------*/
651 /** @defgroup RTCEx_Exported_Macros RTCEx Exported Macros
652   * @{
653   */
654 
655 #if defined(STM32L412xx) || defined(STM32L422xx) || defined (STM32L4P5xx) || defined (STM32L4Q5xx)
656 /** @brief  Clear the specified RTC pending flag.
657   * @param  __HANDLE__ specifies the RTC Handle.
658   * @param  __FLAG__ specifies the flag to check.
659   *          This parameter can be any combination of the following values:
660   *            @arg @ref RTC_CLEAR_ITSF               Clear Internal Time-stamp flag
661   *            @arg @ref RTC_CLEAR_TSOVF              Clear Time-stamp overflow flag
662   *            @arg @ref RTC_CLEAR_TSF                Clear Time-stamp flag
663   *            @arg @ref RTC_CLEAR_WUTF               Clear Wakeup timer flag
664   *            @arg @ref RTC_CLEAR_ALRBF              Clear Alarm B flag
665   *            @arg @ref RTC_CLEAR_ALRAF              Clear Alarm A flag
666   * @retval None
667   */
668 #define __HAL_RTC_CLEAR_FLAG(__HANDLE__, __FLAG__)   ((__HANDLE__)->Instance->SCR = (__FLAG__))
669 
670 /** @brief  Check whether the specified RTC flag is set or not.
671   * @param  __HANDLE__ specifies the RTC Handle.
672   * @param  __FLAG__ specifies the flag to check.
673   *          This parameter can be any combination of the following values:
674   *            @arg @ref RTC_FLAG_RECALPF             Recalibration pending Flag
675   *            @arg @ref RTC_FLAG_INITF               Initialization flag
676   *            @arg @ref RTC_FLAG_RSF                 Registers synchronization flag
677   *            @arg @ref RTC_FLAG_INITS               Initialization status flag
678   *            @arg @ref RTC_FLAG_SHPF                Shift operation pending flag
679   *            @arg @ref RTC_FLAG_WUTWF               Wakeup timer write flag
680   *            @arg @ref RTC_FLAG_ALRBWF              Alarm B write flag
681   *            @arg @ref RTC_FLAG_ALRAWF              Alarm A write flag
682   *            @arg @ref RTC_FLAG_ITSF                Internal Time-stamp flag
683   *            @arg @ref RTC_FLAG_TSOVF               Time-stamp overflow flag
684   *            @arg @ref RTC_FLAG_TSF                 Time-stamp flag
685   *            @arg @ref RTC_FLAG_WUTF                Wakeup timer flag
686   *            @arg @ref RTC_FLAG_ALRBF               Alarm B flag
687   *            @arg @ref RTC_FLAG_ALRAF               Alarm A flag
688   * @retval None
689   */
690 #define __HAL_RTC_GET_FLAG(__HANDLE__, __FLAG__)    (((((__FLAG__)) >> 8U) == 1U) ? ((__HANDLE__)->Instance->ICSR & (1U << (((uint16_t)(__FLAG__)) & RTC_FLAG_MASK))) : \
691                                                      ((__HANDLE__)->Instance->SR & (1U << (((uint16_t)(__FLAG__)) & RTC_FLAG_MASK))))
692 #endif /*#if defined(STM32L412xx) || defined(STM32L422xx) || defined (STM32L4P5xx) || defined (STM32L4Q5xx) */
693 
694 /* ---------------------------------WAKEUPTIMER---------------------------------*/
695 /** @defgroup RTCEx_WakeUp_Timer RTC WakeUp Timer
696   * @{
697   */
698 /**
699   * @brief  Enable the RTC WakeUp Timer peripheral.
700   * @param  __HANDLE__ specifies the RTC handle.
701   * @retval None
702   */
703 #define __HAL_RTC_WAKEUPTIMER_ENABLE(__HANDLE__)                      ((__HANDLE__)->Instance->CR |= (RTC_CR_WUTE))
704 
705 /**
706   * @brief  Disable the RTC WakeUp Timer peripheral.
707   * @param  __HANDLE__ specifies the RTC handle.
708   * @retval None
709   */
710 #define __HAL_RTC_WAKEUPTIMER_DISABLE(__HANDLE__)                     ((__HANDLE__)->Instance->CR &= ~(RTC_CR_WUTE))
711 
712 /**
713   * @brief  Enable the RTC WakeUpTimer interrupt.
714   * @param  __HANDLE__ specifies the RTC handle.
715   * @param  __INTERRUPT__ specifies the RTC WakeUpTimer interrupt sources to be enabled.
716   *         This parameter can be:
717   *            @arg @ref RTC_IT_WUT WakeUpTimer interrupt
718   * @retval None
719   */
720 #define __HAL_RTC_WAKEUPTIMER_ENABLE_IT(__HANDLE__, __INTERRUPT__)    ((__HANDLE__)->Instance->CR |= (__INTERRUPT__))
721 
722 /**
723   * @brief  Disable the RTC WakeUpTimer interrupt.
724   * @param  __HANDLE__ specifies the RTC handle.
725   * @param  __INTERRUPT__ specifies the RTC WakeUpTimer interrupt sources to be disabled.
726   *         This parameter can be:
727   *            @arg @ref RTC_IT_WUT WakeUpTimer interrupt
728   * @retval None
729   */
730 #define __HAL_RTC_WAKEUPTIMER_DISABLE_IT(__HANDLE__, __INTERRUPT__)   ((__HANDLE__)->Instance->CR &= ~(__INTERRUPT__))
731 
732 
733 /**
734   * @brief  Check whether the specified RTC WakeUpTimer interrupt has occurred or not.
735   * @param  __HANDLE__ specifies the RTC handle.
736   * @param  __INTERRUPT__ specifies the RTC WakeUpTimer interrupt sources to check.
737   *         This parameter can be:
738   *            @arg @ref RTC_IT_WUT  WakeUpTimer interrupt
739   * @retval None
740   */
741 #if defined(STM32L412xx) || defined(STM32L422xx) || defined (STM32L4P5xx) || defined (STM32L4Q5xx)
742 #define __HAL_RTC_WAKEUPTIMER_GET_IT(__HANDLE__, __INTERRUPT__)       (((((__HANDLE__)->Instance->MISR) & ((__INTERRUPT__) >> 12)) != 0U) ? 1U : 0U)
743 #else
744 #define __HAL_RTC_WAKEUPTIMER_GET_IT(__HANDLE__, __INTERRUPT__)       (((((__HANDLE__)->Instance->ISR) & ((__INTERRUPT__) >> 4)) != 0U) ? 1U : 0U)
745 #endif
746 
747 /**
748   * @brief  Check whether the specified RTC Wake Up timer interrupt has been enabled or not.
749   * @param  __HANDLE__ specifies the RTC handle.
750   * @param  __INTERRUPT__ specifies the RTC Wake Up timer interrupt sources to check.
751   *         This parameter can be:
752   *            @arg @ref RTC_IT_WUT  WakeUpTimer interrupt
753   * @retval None
754   */
755 #define __HAL_RTC_WAKEUPTIMER_GET_IT_SOURCE(__HANDLE__, __INTERRUPT__)   (((((__HANDLE__)->Instance->CR) & (__INTERRUPT__)) != 0U) ? 1U : 0U)
756 
757 /**
758   * @brief  Get the selected RTC WakeUpTimer's flag status.
759   * @param  __HANDLE__ specifies the RTC handle.
760   * @param  __FLAG__ specifies the RTC WakeUpTimer Flag is pending or not.
761   *          This parameter can be:
762   *             @arg @ref RTC_FLAG_WUTF
763   *             @arg @ref RTC_FLAG_WUTWF
764   * @retval Flag status
765   */
766 #if defined(STM32L412xx) || defined(STM32L422xx) || defined (STM32L4P5xx) || defined (STM32L4Q5xx)
767 #define __HAL_RTC_WAKEUPTIMER_GET_FLAG(__HANDLE__, __FLAG__)   (__HAL_RTC_GET_FLAG((__HANDLE__), (__FLAG__)))
768 #else
769 #define __HAL_RTC_WAKEUPTIMER_GET_FLAG(__HANDLE__, __FLAG__)   (((((__HANDLE__)->Instance->ISR) & (__FLAG__)) != 0U) ? 1U : 0U)
770 #endif
771 
772 /**
773   * @brief  Clear the RTC Wake Up timers pending flags.
774   * @param  __HANDLE__ specifies the RTC handle.
775   * @param  __FLAG__ specifies the RTC WakeUpTimer Flag to clear.
776   *         This parameter can be:
777   *            @arg @ref RTC_FLAG_WUTF
778   * @retval None
779   */
780 #if defined(STM32L412xx) || defined(STM32L422xx) || defined (STM32L4P5xx) || defined (STM32L4Q5xx)
781 #define __HAL_RTC_WAKEUPTIMER_CLEAR_FLAG(__HANDLE__, __FLAG__)     (__HAL_RTC_CLEAR_FLAG((__HANDLE__), RTC_CLEAR_WUTF))
782 #else
783 #define __HAL_RTC_WAKEUPTIMER_CLEAR_FLAG(__HANDLE__, __FLAG__) ((__HANDLE__)->Instance->ISR) = (~((__FLAG__) | RTC_ISR_INIT)|((__HANDLE__)->Instance->ISR & RTC_ISR_INIT))
784 #endif
785 
786 
787 /* WAKE-UP TIMER EXTI */
788 /* ------------------ */
789 /**
790   * @brief  Enable interrupt on the RTC WakeUp Timer associated Exti line.
791   * @retval None
792   */
793 #define __HAL_RTC_WAKEUPTIMER_EXTI_ENABLE_IT()       (EXTI->IMR1 |= RTC_EXTI_LINE_WAKEUPTIMER_EVENT)
794 
795 /**
796   * @brief  Disable interrupt on the RTC WakeUp Timer associated Exti line.
797   * @retval None
798   */
799 #define __HAL_RTC_WAKEUPTIMER_EXTI_DISABLE_IT()      (EXTI->IMR1 &= ~(RTC_EXTI_LINE_WAKEUPTIMER_EVENT))
800 
801 /**
802   * @brief  Enable event on the RTC WakeUp Timer associated Exti line.
803   * @retval None
804   */
805 #define __HAL_RTC_WAKEUPTIMER_EXTI_ENABLE_EVENT()    (EXTI->EMR1 |= RTC_EXTI_LINE_WAKEUPTIMER_EVENT)
806 
807 /**
808   * @brief  Disable event on the RTC WakeUp Timer associated Exti line.
809   * @retval None
810   */
811 #define __HAL_RTC_WAKEUPTIMER_EXTI_DISABLE_EVENT()   (EXTI->EMR1 &= ~(RTC_EXTI_LINE_WAKEUPTIMER_EVENT))
812 
813 /**
814   * @brief  Enable falling edge trigger on the RTC WakeUp Timer associated Exti line.
815   * @retval None
816   */
817 #define __HAL_RTC_WAKEUPTIMER_EXTI_ENABLE_FALLING_EDGE()   (EXTI->FTSR1 |= RTC_EXTI_LINE_WAKEUPTIMER_EVENT)
818 
819 /**
820   * @brief  Disable falling edge trigger on the RTC WakeUp Timer associated Exti line.
821   * @retval None
822   */
823 #define __HAL_RTC_WAKEUPTIMER_EXTI_DISABLE_FALLING_EDGE()  (EXTI->FTSR1 &= ~(RTC_EXTI_LINE_WAKEUPTIMER_EVENT))
824 
825 /**
826   * @brief  Enable rising edge trigger on the RTC WakeUp Timer associated Exti line.
827   * @retval None
828   */
829 #define __HAL_RTC_WAKEUPTIMER_EXTI_ENABLE_RISING_EDGE()    (EXTI->RTSR1 |= RTC_EXTI_LINE_WAKEUPTIMER_EVENT)
830 
831 /**
832   * @brief  Disable rising edge trigger on the RTC WakeUp Timer associated Exti line.
833   * @retval None
834   */
835 #define __HAL_RTC_WAKEUPTIMER_EXTI_DISABLE_RISING_EDGE()   (EXTI->RTSR1 &= ~(RTC_EXTI_LINE_WAKEUPTIMER_EVENT))
836 
837 /**
838   * @brief  Enable rising & falling edge trigger on the RTC WakeUp Timer associated Exti line.
839   * @retval None
840   */
841 #define __HAL_RTC_WAKEUPTIMER_EXTI_ENABLE_RISING_FALLING_EDGE()  do { \
842                                                                    __HAL_RTC_WAKEUPTIMER_EXTI_ENABLE_RISING_EDGE();  \
843                                                                    __HAL_RTC_WAKEUPTIMER_EXTI_ENABLE_FALLING_EDGE(); \
844                                                                  } while(0)
845 
846 /**
847   * @brief  Disable rising & falling edge trigger on the RTC WakeUp Timer associated Exti line.
848   * This parameter can be:
849   * @retval None
850   */
851 #define __HAL_RTC_WAKEUPTIMER_EXTI_DISABLE_RISING_FALLING_EDGE()  do { \
852                                                                    __HAL_RTC_WAKEUPTIMER_EXTI_DISABLE_RISING_EDGE();  \
853                                                                    __HAL_RTC_WAKEUPTIMER_EXTI_DISABLE_FALLING_EDGE(); \
854                                                                   } while(0)
855 
856 /**
857   * @brief Check whether the RTC WakeUp Timer associated Exti line interrupt flag is set or not.
858   * @retval Line Status.
859   */
860 #define __HAL_RTC_WAKEUPTIMER_EXTI_GET_FLAG()              (EXTI->PR1 & RTC_EXTI_LINE_WAKEUPTIMER_EVENT)
861 
862 /**
863   * @brief Clear the RTC WakeUp Timer associated Exti line flag.
864   * @retval None
865   */
866 #define __HAL_RTC_WAKEUPTIMER_EXTI_CLEAR_FLAG()            (EXTI->PR1 = RTC_EXTI_LINE_WAKEUPTIMER_EVENT)
867 
868 /**
869   * @brief Generate a Software interrupt on the RTC WakeUp Timer associated Exti line.
870   * @retval None
871   */
872 #define __HAL_RTC_WAKEUPTIMER_EXTI_GENERATE_SWIT()         (EXTI->SWIER1 |= RTC_EXTI_LINE_WAKEUPTIMER_EVENT)
873 
874 /**
875   * @}
876   */
877 
878 /* ---------------------------------TIMESTAMP---------------------------------*/
879 /** @defgroup RTCEx_Timestamp RTC Timestamp
880   * @{
881   */
882 /**
883   * @brief  Enable the RTC TimeStamp peripheral.
884   * @param  __HANDLE__ specifies the RTC handle.
885   * @retval None
886   */
887 #define __HAL_RTC_TIMESTAMP_ENABLE(__HANDLE__)                       ((__HANDLE__)->Instance->CR |= (RTC_CR_TSE))
888 
889 /**
890   * @brief  Disable the RTC TimeStamp peripheral.
891   * @param  __HANDLE__ specifies the RTC handle.
892   * @retval None
893   */
894 #define __HAL_RTC_TIMESTAMP_DISABLE(__HANDLE__)                      ((__HANDLE__)->Instance->CR &= ~(RTC_CR_TSE))
895 
896 /**
897   * @brief  Enable the RTC TimeStamp interrupt.
898   * @param  __HANDLE__ specifies the RTC handle.
899   * @param  __INTERRUPT__ specifies the RTC TimeStamp interrupt source to be enabled.
900   *         This parameter can be:
901   *            @arg @ref RTC_IT_TS TimeStamp interrupt
902   * @retval None
903   */
904 #define __HAL_RTC_TIMESTAMP_ENABLE_IT(__HANDLE__, __INTERRUPT__)     ((__HANDLE__)->Instance->CR |= (__INTERRUPT__))
905 
906 /**
907   * @brief  Disable the RTC TimeStamp interrupt.
908   * @param  __HANDLE__ specifies the RTC handle.
909   * @param  __INTERRUPT__ specifies the RTC TimeStamp interrupt source to be disabled.
910   *         This parameter can be:
911   *            @arg @ref RTC_IT_TS TimeStamp interrupt
912   * @retval None
913   */
914 #define __HAL_RTC_TIMESTAMP_DISABLE_IT(__HANDLE__, __INTERRUPT__)    ((__HANDLE__)->Instance->CR &= ~(__INTERRUPT__))
915 
916 /**
917   * @brief  Check whether the specified RTC TimeStamp interrupt has occurred or not.
918   * @param  __HANDLE__ specifies the RTC handle.
919   * @param  __INTERRUPT__ specifies the RTC TimeStamp interrupt source to check.
920   *         This parameter can be:
921   *            @arg @ref RTC_IT_TS TimeStamp interrupt
922   * @retval None
923   */
924 #if defined(STM32L412xx) || defined(STM32L422xx) || defined (STM32L4P5xx) || defined (STM32L4Q5xx)
925 #define __HAL_RTC_TIMESTAMP_GET_IT(__HANDLE__, __INTERRUPT__)        (((((__HANDLE__)->Instance->MISR) & ((__INTERRUPT__) >> 12)) != 0U) ? 1U : 0U)
926 #else
927 #define __HAL_RTC_TIMESTAMP_GET_IT(__HANDLE__, __INTERRUPT__)        (((((__HANDLE__)->Instance->ISR) & ((__INTERRUPT__) >> 4)) != 0U) ? 1U : 0U)
928 #endif
929 /**
930   * @brief  Check whether the specified RTC Time Stamp interrupt has been enabled or not.
931   * @param  __HANDLE__ specifies the RTC handle.
932   * @param  __INTERRUPT__ specifies the RTC Time Stamp interrupt source to check.
933   *         This parameter can be:
934   *            @arg @ref RTC_IT_TS TimeStamp interrupt
935   * @retval None
936   */
937 #define __HAL_RTC_TIMESTAMP_GET_IT_SOURCE(__HANDLE__, __INTERRUPT__)     (((((__HANDLE__)->Instance->CR) & (__INTERRUPT__)) != 0U) ? 1U : 0U)
938 
939 /**
940   * @brief  Get the selected RTC TimeStamp's flag status.
941   * @param  __HANDLE__ specifies the RTC handle.
942   * @param  __FLAG__ specifies the RTC TimeStamp Flag is pending or not.
943   *         This parameter can be:
944   *            @arg @ref RTC_FLAG_TSF
945   *            @arg @ref RTC_FLAG_TSOVF
946   * @retval Flag status
947   */
948 #if defined(STM32L412xx) || defined(STM32L422xx) || defined (STM32L4P5xx) || defined (STM32L4Q5xx)
949 #define __HAL_RTC_TIMESTAMP_GET_FLAG(__HANDLE__, __FLAG__)     (__HAL_RTC_GET_FLAG((__HANDLE__),(__FLAG__)))
950 #else
951 #define __HAL_RTC_TIMESTAMP_GET_FLAG(__HANDLE__, __FLAG__)     (((((__HANDLE__)->Instance->ISR) & (__FLAG__)) != 0U) ? 1U : 0U)
952 #endif
953 
954 /**
955   * @brief  Clear the RTC Time Stamps pending flags.
956   * @param  __HANDLE__ specifies the RTC handle.
957   * @param  __FLAG__ specifies the RTC TimeStamp Flag to clear.
958   *          This parameter can be:
959   *             @arg @ref RTC_FLAG_TSF
960   *             @arg @ref RTC_FLAG_TSOVF
961   * @retval None
962   */
963 #if defined(STM32L412xx) || defined(STM32L422xx) || defined (STM32L4P5xx) || defined (STM32L4Q5xx)
964 #define __HAL_RTC_TIMESTAMP_CLEAR_FLAG(__HANDLE__, __FLAG__)   (__HAL_RTC_CLEAR_FLAG((__HANDLE__), (__FLAG__)))
965 #else
966 #define __HAL_RTC_TIMESTAMP_CLEAR_FLAG(__HANDLE__, __FLAG__)   ((__HANDLE__)->Instance->ISR) = (~((__FLAG__) | RTC_ISR_INIT)|((__HANDLE__)->Instance->ISR & RTC_ISR_INIT))
967 #endif
968 
969 /**
970   * @brief  Enable the RTC internal TimeStamp peripheral.
971   * @param  __HANDLE__ specifies the RTC handle.
972   * @retval None
973   */
974 #define __HAL_RTC_INTERNAL_TIMESTAMP_ENABLE(__HANDLE__)                ((__HANDLE__)->Instance->CR |= (RTC_CR_ITSE))
975 
976 /**
977   * @brief  Disable the RTC internal TimeStamp peripheral.
978   * @param  __HANDLE__ specifies the RTC handle.
979   * @retval None
980   */
981 #define __HAL_RTC_INTERNAL_TIMESTAMP_DISABLE(__HANDLE__)               ((__HANDLE__)->Instance->CR &= ~(RTC_CR_ITSE))
982 
983 /**
984   * @brief  Get the selected RTC Internal Time Stamps flag status.
985   * @param  __HANDLE__ specifies the RTC handle.
986   * @param  __FLAG__ specifies the RTC Internal Time Stamp Flag is pending or not.
987   *         This parameter can be:
988   *            @arg @ref RTC_FLAG_ITSF
989   * @retval None
990   */
991 #if defined(STM32L412xx) || defined(STM32L422xx) || defined (STM32L4P5xx) || defined (STM32L4Q5xx)
992 #define __HAL_RTC_INTERNAL_TIMESTAMP_GET_FLAG(__HANDLE__, __FLAG__)     (__HAL_RTC_GET_FLAG((__HANDLE__),(__FLAG__)))
993 #else
994 #define __HAL_RTC_INTERNAL_TIMESTAMP_GET_FLAG(__HANDLE__, __FLAG__)    (((((__HANDLE__)->Instance->ISR) & (__FLAG__)) != 0U) ? 1U : 0U)
995 #endif
996 
997 /**
998   * @brief  Clear the RTC Internal Time Stamps pending flags.
999   * @param  __HANDLE__ specifies the RTC handle.
1000   * @param  __FLAG__ specifies the RTC Internal Time Stamp Flag source to clear.
1001   * This parameter can be:
1002   *             @arg @ref RTC_FLAG_ITSF
1003   * @retval None
1004   */
1005 #if defined(STM32L412xx) || defined(STM32L422xx) || defined (STM32L4P5xx) || defined (STM32L4Q5xx)
1006 #define __HAL_RTC_INTERNAL_TIMESTAMP_CLEAR_FLAG(__HANDLE__, __FLAG__)     (__HAL_RTC_CLEAR_FLAG((__HANDLE__), RTC_CLEAR_ITSF))
1007 #else
1008 #define __HAL_RTC_INTERNAL_TIMESTAMP_CLEAR_FLAG(__HANDLE__, __FLAG__)  ((__HANDLE__)->Instance->ISR) = (~((__FLAG__) | RTC_ISR_INIT)|((__HANDLE__)->Instance->ISR & RTC_ISR_INIT))
1009 #endif
1010 
1011 
1012 #if defined(STM32L412xx) || defined(STM32L422xx) || defined (STM32L4P5xx) || defined (STM32L4Q5xx)
1013 /**
1014   * @brief  Enable the RTC TimeStamp on Tamper detection.
1015   * @param  __HANDLE__ specifies the RTC handle.
1016   * @retval None
1017   */
1018 #define __HAL_RTC_TAMPTS_ENABLE(__HANDLE__)                       ((__HANDLE__)->Instance->CR |= (RTC_CR_TAMPTS))
1019 
1020 /**
1021   * @brief  Disable the RTC TimeStamp on Tamper detection.
1022   * @param  __HANDLE__ specifies the RTC handle.
1023   * @retval None
1024   */
1025 #define __HAL_RTC_TAMPTS_DISABLE(__HANDLE__)                      ((__HANDLE__)->Instance->CR &= ~(RTC_CR_TAMPTS))
1026 
1027 /**
1028   * @brief  Enable the RTC Tamper detection output.
1029   * @param  __HANDLE__ specifies the RTC handle.
1030   * @retval None
1031   */
1032 #define __HAL_RTC_TAMPOE_ENABLE(__HANDLE__)                       ((__HANDLE__)->Instance->CR |= (RTC_CR_TAMPOE))
1033 
1034 /**
1035   * @brief  Disable the RTC Tamper detection output.
1036   * @param  __HANDLE__ specifies the RTC handle.
1037   * @retval None
1038   */
1039 #define __HAL_RTC_TAMPOE_DISABLE(__HANDLE__)                      ((__HANDLE__)->Instance->CR &= ~(RTC_CR_TAMPOE))
1040 
1041 
1042 /**
1043   * @}
1044   */
1045 #endif /* #if defined(STM32L412xx) || defined(STM32L422xx) || defined (STM32L4P5xx) || defined (STM32L4Q5xx) */
1046 
1047 /* ------------------------------Calibration----------------------------------*/
1048 /** @defgroup RTCEx_Calibration RTC Calibration
1049   * @{
1050   */
1051 
1052 /**
1053   * @brief  Enable the RTC calibration output.
1054   * @param  __HANDLE__ specifies the RTC handle.
1055   * @retval None
1056   */
1057 #define __HAL_RTC_CALIBRATION_OUTPUT_ENABLE(__HANDLE__)               ((__HANDLE__)->Instance->CR |= (RTC_CR_COE))
1058 
1059 /**
1060   * @brief  Disable the calibration output.
1061   * @param  __HANDLE__ specifies the RTC handle.
1062   * @retval None
1063   */
1064 #define __HAL_RTC_CALIBRATION_OUTPUT_DISABLE(__HANDLE__)              ((__HANDLE__)->Instance->CR &= ~(RTC_CR_COE))
1065 
1066 /**
1067   * @brief  Enable the clock reference detection.
1068   * @param  __HANDLE__ specifies the RTC handle.
1069   * @retval None
1070   */
1071 #define __HAL_RTC_CLOCKREF_DETECTION_ENABLE(__HANDLE__)               ((__HANDLE__)->Instance->CR |= (RTC_CR_REFCKON))
1072 
1073 /**
1074   * @brief  Disable the clock reference detection.
1075   * @param  __HANDLE__ specifies the RTC handle.
1076   * @retval None
1077   */
1078 #define __HAL_RTC_CLOCKREF_DETECTION_DISABLE(__HANDLE__)              ((__HANDLE__)->Instance->CR &= ~(RTC_CR_REFCKON))
1079 
1080 /**
1081   * @brief  Get the selected RTC shift operation's flag status.
1082   * @param  __HANDLE__ specifies the RTC handle.
1083   * @param  __FLAG__ specifies the RTC shift operation Flag is pending or not.
1084   *          This parameter can be:
1085   *             @arg @ref RTC_FLAG_SHPF
1086   * @retval None
1087   */
1088 #if defined(STM32L412xx) || defined(STM32L422xx) || defined (STM32L4P5xx) || defined (STM32L4Q5xx)
1089 #define __HAL_RTC_SHIFT_GET_FLAG(__HANDLE__, __FLAG__)                (__HAL_RTC_GET_FLAG((__HANDLE__), (__FLAG__)))
1090 #else
1091 #define __HAL_RTC_SHIFT_GET_FLAG(__HANDLE__, __FLAG__)         (((((__HANDLE__)->Instance->ISR) & (__FLAG__)) != 0U) ? 1U : 0U)
1092 #endif
1093 
1094 /**
1095   * @}
1096   */
1097 
1098 
1099 /* ------------------------------Tamper----------------------------------*/
1100 /** @defgroup RTCEx_Tamper RTCEx tamper
1101   * @{
1102   */
1103 #if defined(RTC_TAMPER1_SUPPORT)
1104 /**
1105   * @brief  Enable the RTC Tamper1 input detection.
1106   * @param  __HANDLE__ specifies the RTC handle.
1107   * @retval None
1108   */
1109 #if defined(STM32L412xx) || defined(STM32L422xx) || defined (STM32L4P5xx) || defined (STM32L4Q5xx)
1110 #define __HAL_RTC_TAMPER1_ENABLE(__HANDLE__)           (((TAMP_TypeDef *)((uint32_t)((__HANDLE__)->Instance) + (__HANDLE__)->TampOffset))->CR1 |= (TAMP_CR1_TAMP1E))
1111 #else
1112 #define __HAL_RTC_TAMPER1_ENABLE(__HANDLE__)           ((__HANDLE__)->Instance->TAMPCR |= (RTC_TAMPCR_TAMP1E))
1113 #endif
1114 
1115 /**
1116   * @brief  Disable the RTC Tamper1 input detection.
1117   * @param  __HANDLE__ specifies the RTC handle.
1118   * @retval None
1119   */
1120 #if defined(STM32L412xx) || defined(STM32L422xx) || defined (STM32L4P5xx) || defined (STM32L4Q5xx)
1121 #define __HAL_RTC_TAMPER1_DISABLE(__HANDLE__)          (((TAMP_TypeDef *)((uint32_t)((__HANDLE__)->Instance) + (__HANDLE__)->TampOffset))->CR1 &= ~(RTC_TAMPCR_TAMP1E))
1122 #else
1123 #define __HAL_RTC_TAMPER1_DISABLE(__HANDLE__)          ((__HANDLE__)->Instance->TAMPCR &= ~(RTC_TAMPCR_TAMP1E))
1124 #endif
1125 #endif /* RTC_TAMPER1_SUPPORT */
1126 
1127 /**
1128   * @brief  Enable the RTC Tamper2 input detection.
1129   * @param  __HANDLE__ specifies the RTC handle.
1130   * @retval None
1131   */
1132 #if defined(STM32L412xx) || defined(STM32L422xx) || defined (STM32L4P5xx) || defined (STM32L4Q5xx)
1133 #define __HAL_RTC_TAMPER2_ENABLE(__HANDLE__)           (((TAMP_TypeDef *)((uint32_t)((__HANDLE__)->Instance) + (__HANDLE__)->TampOffset))->CR1 |= (TAMP_CR1_TAMP2E))
1134 #else
1135 #define __HAL_RTC_TAMPER2_ENABLE(__HANDLE__)           ((__HANDLE__)->Instance->TAMPCR |= (RTC_TAMPCR_TAMP2E))
1136 #endif
1137 
1138 /**
1139   * @brief  Disable the RTC Tamper2 input detection.
1140   * @param  __HANDLE__ specifies the RTC handle.
1141   * @retval None
1142   */
1143 #if defined(STM32L412xx) || defined(STM32L422xx) || defined (STM32L4P5xx) || defined (STM32L4Q5xx)
1144 #define __HAL_RTC_TAMPER2_DISABLE(__HANDLE__)          (((TAMP_TypeDef *)((uint32_t)((__HANDLE__)->Instance) + (__HANDLE__)->TampOffset))->CR1 &= ~(RTC_TAMPCR_TAMP2E))
1145 #else
1146 #define __HAL_RTC_TAMPER2_DISABLE(__HANDLE__)          ((__HANDLE__)->Instance->TAMPCR &= ~(RTC_TAMPCR_TAMP2E))
1147 #endif
1148 
1149 #if defined(RTC_TAMPER3_SUPPORT)
1150 /**
1151   * @brief  Enable the RTC Tamper3 input detection.
1152   * @param  __HANDLE__ specifies the RTC handle.
1153   * @retval None
1154   */
1155 #define __HAL_RTC_TAMPER3_ENABLE(__HANDLE__)                         ((__HANDLE__)->Instance->TAMPCR |= (RTC_TAMPCR_TAMP3E))
1156 
1157 /**
1158   * @brief  Disable the RTC Tamper3 input detection.
1159   * @param  __HANDLE__ specifies the RTC handle.
1160   * @retval None
1161   */
1162 #define __HAL_RTC_TAMPER3_DISABLE(__HANDLE__)                        ((__HANDLE__)->Instance->TAMPCR &= ~(RTC_TAMPCR_TAMP3E))
1163 #endif /* RTC_TAMPER3_SUPPORT */
1164 
1165 /**************************************************************************************************/
1166 /**
1167   * @brief  Enable the TAMP Tamper interrupt.
1168   * @param  __HANDLE__ specifies the RTC handle.
1169   * @param  __INTERRUPT__ specifies the RTC Tamper interrupt sources to be enabled.
1170   *          This parameter can be any combination of the following values:
1171   *             @arg  RTC_IT_TAMPALL: All tampers interrupts
1172   *             @arg  RTC_IT_TAMP1: Tamper1 interrupt
1173   *             @arg  RTC_IT_TAMP2: Tamper2 interrupt
1174   *             @arg  RTC_IT_TAMP3: Tamper3 interrupt
1175   * @retval None
1176   */
1177 #if defined(STM32L412xx) || defined(STM32L422xx) || defined (STM32L4P5xx) || defined (STM32L4Q5xx)
1178 #define __HAL_RTC_TAMPER_ENABLE_IT(__HANDLE__, __INTERRUPT__)        (((TAMP_TypeDef *)((uint32_t)((__HANDLE__)->Instance) + (__HANDLE__)->TampOffset))->IER |= (__INTERRUPT__))
1179 #else
1180 #define __HAL_RTC_TAMPER_ENABLE_IT(__HANDLE__, __INTERRUPT__)        ((__HANDLE__)->Instance->TAMPCR |= (__INTERRUPT__))
1181 #endif
1182 /**
1183   * @brief  Disable the TAMP Tamper interrupt.
1184   * @param  __HANDLE__ specifies the RTC handle.
1185   * @param  __INTERRUPT__ specifies the RTC Tamper interrupt sources to be disabled.
1186   *         This parameter can be any combination of the following values:
1187   *            @arg  RTC_IT_TAMPALL: All tampers interrupts
1188   *            @arg  RTC_IT_TAMP1: Tamper1 interrupt
1189   *            @arg  RTC_IT_TAMP2: Tamper2 interrupt
1190   *            @arg  RTC_IT_TAMP3: Tamper3 interrupt
1191   * @retval None
1192   */
1193 #if defined(STM32L412xx) || defined(STM32L422xx) || defined (STM32L4P5xx) || defined (STM32L4Q5xx)
1194 #define __HAL_RTC_TAMPER_DISABLE_IT(__HANDLE__, __INTERRUPT__)       (((TAMP_TypeDef *)((uint32_t)((__HANDLE__)->Instance) + (__HANDLE__)->TampOffset))->IER &= ~(__INTERRUPT__))
1195 #else
1196 #define __HAL_RTC_TAMPER_DISABLE_IT(__HANDLE__, __INTERRUPT__)       ((__HANDLE__)->Instance->TAMPCR &= ~(__INTERRUPT__))
1197 #endif
1198 
1199 
1200 /**************************************************************************************************/
1201 /**
1202   * @brief  Check whether the specified RTC Tamper interrupt has occurred or not.
1203   * @param  __HANDLE__ specifies the RTC handle.
1204   * @param  __INTERRUPT__ specifies the RTC Tamper interrupt to check.
1205   *         This parameter can be:
1206   *            @arg  RTC_IT_TAMPALL: All tampers interrupts
1207   *            @arg  RTC_IT_TAMP1: Tamper1 interrupt
1208   *            @arg  RTC_IT_TAMP2: Tamper2 interrupt
1209   *            @arg  RTC_IT_TAMP3: Tamper3 interrupt
1210   * @retval None
1211   */
1212 #if defined(STM32L412xx) || defined(STM32L422xx) || defined (STM32L4P5xx) || defined (STM32L4Q5xx)
1213 #define __HAL_RTC_TAMPER_GET_IT(__HANDLE__, __INTERRUPT__)     ((((((TAMP_TypeDef *)((uint32_t)((__HANDLE__)->Instance) + (__HANDLE__)->TampOffset))->MISR) & (__INTERRUPT__)) != 0U) ? 1U : 0U)
1214 #else /* #if defined(STM32L412xx) || defined(STM32L422xx) || defined (STM32L4P5xx) || defined (STM32L4Q5xx) */
1215 #define __HAL_RTC_TAMPER_GET_IT(__HANDLE__, __INTERRUPT__)     (((((__HANDLE__)->Instance->ISR) & (__INTERRUPT__)) != 0U) ? 1U : 0U)
1216 #endif /* #if defined(STM32L412xx) || defined(STM32L422xx) || defined (STM32L4P5xx) || defined (STM32L4Q5xx) */
1217 /**
1218   * @brief  Check whether the specified RTC Tamper interrupt has been enabled or not.
1219   * @param  __HANDLE__ specifies the RTC handle.
1220   * @param  __INTERRUPT__ specifies the RTC Tamper interrupt source to check.
1221   *         This parameter can be:
1222   *            @arg  RTC_IT_TAMPALL: All tampers interrupts
1223   *            @arg  RTC_IT_TAMP1: Tamper1 interrupt
1224   *            @arg  RTC_IT_TAMP2: Tamper2 interrupt
1225   *            @arg  RTC_IT_TAMP3: Tamper3 interrupt
1226   * @retval None
1227   */
1228 #if defined(STM32L412xx) || defined(STM32L422xx) || defined (STM32L4P5xx) || defined (STM32L4Q5xx)
1229 #define __HAL_RTC_TAMPER_GET_IT_SOURCE(__HANDLE__, __INTERRUPT__)    ((((((TAMP_TypeDef *)((uint32_t)((__HANDLE__)->Instance) + (__HANDLE__)->TampOffset))->IER) & (__INTERRUPT__)) != 0U) ? 1U : 0U)
1230 #else
1231 #define __HAL_RTC_TAMPER_GET_IT_SOURCE(__HANDLE__, __INTERRUPT__)    (((((__HANDLE__)->Instance->TAMPCR) & (__INTERRUPT__)) != 0U) ? 1U : 0U)
1232 #endif
1233 
1234 /**
1235   * @brief  Get the selected RTC Tamper's flag status.
1236   * @param  __HANDLE__ specifies the RTC handle.
1237   * @param  __FLAG__ specifies the RTC Tamper Flag is pending or not.
1238   *          This parameter can be:
1239   *             @arg RTC_FLAG_TAMP1F: Tamper1 flag
1240   *             @arg RTC_FLAG_TAMP2F: Tamper2 flag
1241   *             @arg RTC_FLAG_TAMP3F: Tamper3 flag
1242   * @retval None
1243   */
1244 #if defined(STM32L412xx) || defined(STM32L422xx) || defined (STM32L4P5xx) || defined (STM32L4Q5xx)
1245 #define __HAL_RTC_TAMPER_GET_FLAG(__HANDLE__, __FLAG__)        (((((TAMP_TypeDef *)((uint32_t)((__HANDLE__)->Instance) + (__HANDLE__)->TampOffset))->SR) & (__FLAG__)) != 0U)
1246 #else
1247 #define __HAL_RTC_TAMPER_GET_FLAG(__HANDLE__, __FLAG__)        (((((__HANDLE__)->Instance->ISR) & (__FLAG__)) != 0U) ? 1U : 0U)
1248 #endif
1249 /**
1250   * @brief  Clear the RTC Tamper's pending flags.
1251   * @param  __HANDLE__ specifies the RTC handle.
1252   * @param  __FLAG__ specifies the RTC Tamper Flag to clear.
1253   *          This parameter can be:
1254   *             @arg RTC_FLAG_TAMP1F: Tamper1 flag
1255   *             @arg RTC_FLAG_TAMP2F: Tamper2 flag
1256   *             @arg RTC_FLAG_TAMP3F: Tamper3 flag
1257   * @retval None
1258   */
1259 #if defined(STM32L412xx) || defined(STM32L422xx) || defined (STM32L4P5xx) || defined (STM32L4Q5xx)
1260 #define __HAL_RTC_TAMPER_CLEAR_FLAG(__HANDLE__, __FLAG__)      ((((TAMP_TypeDef *)((uint32_t)((__HANDLE__)->Instance) + (__HANDLE__)->TampOffset))->SCR) = (__FLAG__))
1261 #else
1262 #define __HAL_RTC_TAMPER_CLEAR_FLAG(__HANDLE__, __FLAG__)      ((__HANDLE__)->Instance->ISR) = (~((__FLAG__) | RTC_ISR_INIT)|((__HANDLE__)->Instance->ISR & RTC_ISR_INIT))
1263 #endif
1264 
1265 /**
1266   * @brief  Enable interrupt on the RTC Tamper and Timestamp associated Exti line.
1267   * @retval None
1268   */
1269 #define __HAL_RTC_TAMPER_TIMESTAMP_EXTI_ENABLE_IT()        (EXTI->IMR1 |= RTC_EXTI_LINE_TAMPER_TIMESTAMP_EVENT)
1270 
1271 /**
1272   * @brief  Disable interrupt on the RTC Tamper and Timestamp associated Exti line.
1273   * @retval None
1274   */
1275 #define __HAL_RTC_TAMPER_TIMESTAMP_EXTI_DISABLE_IT()       (EXTI->IMR1 &= ~(RTC_EXTI_LINE_TAMPER_TIMESTAMP_EVENT))
1276 
1277 /**
1278   * @brief  Enable event on the RTC Tamper and Timestamp associated Exti line.
1279   * @retval None
1280   */
1281 #define __HAL_RTC_TAMPER_TIMESTAMP_EXTI_ENABLE_EVENT()    (EXTI->EMR1 |= RTC_EXTI_LINE_TAMPER_TIMESTAMP_EVENT)
1282 
1283 /**
1284   * @brief  Disable event on the RTC Tamper and Timestamp associated Exti line.
1285   * @retval None
1286   */
1287 #define __HAL_RTC_TAMPER_TIMESTAMP_EXTI_DISABLE_EVENT()   (EXTI->EMR1 &= ~(RTC_EXTI_LINE_TAMPER_TIMESTAMP_EVENT))
1288 
1289 /**
1290   * @brief  Enable falling edge trigger on the RTC Tamper and Timestamp associated Exti line.
1291   * @retval None
1292   */
1293 #define __HAL_RTC_TAMPER_TIMESTAMP_EXTI_ENABLE_FALLING_EDGE()   (EXTI->FTSR1 |= RTC_EXTI_LINE_TAMPER_TIMESTAMP_EVENT)
1294 
1295 /**
1296   * @brief  Disable falling edge trigger on the RTC Tamper and Timestamp associated Exti line.
1297   * @retval None
1298   */
1299 #define __HAL_RTC_TAMPER_TIMESTAMP_EXTI_DISABLE_FALLING_EDGE()  (EXTI->FTSR1 &= ~(RTC_EXTI_LINE_TAMPER_TIMESTAMP_EVENT))
1300 
1301 /**
1302   * @brief  Enable rising edge trigger on the RTC Tamper and Timestamp associated Exti line.
1303   * @retval None
1304   */
1305 #define __HAL_RTC_TAMPER_TIMESTAMP_EXTI_ENABLE_RISING_EDGE()    (EXTI->RTSR1 |= RTC_EXTI_LINE_TAMPER_TIMESTAMP_EVENT)
1306 
1307 /**
1308   * @brief  Disable rising edge trigger on the RTC Tamper and Timestamp associated Exti line.
1309   * @retval None
1310   */
1311 #define __HAL_RTC_TAMPER_TIMESTAMP_EXTI_DISABLE_RISING_EDGE()   (EXTI->RTSR1 &= ~(RTC_EXTI_LINE_TAMPER_TIMESTAMP_EVENT))
1312 
1313 /**
1314   * @brief  Enable rising & falling edge trigger on the RTC Tamper and Timestamp associated Exti line.
1315   * @retval None
1316   */
1317 #define __HAL_RTC_TAMPER_TIMESTAMP_EXTI_ENABLE_RISING_FALLING_EDGE()  do { \
1318                                                                         __HAL_RTC_TAMPER_TIMESTAMP_EXTI_ENABLE_RISING_EDGE();  \
1319                                                                         __HAL_RTC_TAMPER_TIMESTAMP_EXTI_ENABLE_FALLING_EDGE(); \
1320                                                                       } while(0)
1321 
1322 /**
1323   * @brief  Disable rising & falling edge trigger on the RTC Tamper and Timestamp associated Exti line.
1324   * @retval None
1325   */
1326 #define __HAL_RTC_TAMPER_TIMESTAMP_EXTI_DISABLE_RISING_FALLING_EDGE()  do { \
1327                                                                         __HAL_RTC_TAMPER_TIMESTAMP_EXTI_DISABLE_RISING_EDGE();  \
1328                                                                         __HAL_RTC_TAMPER_TIMESTAMP_EXTI_DISABLE_FALLING_EDGE(); \
1329                                                                        } while(0)
1330 
1331 /**
1332   * @brief Check whether the RTC Tamper and Timestamp associated Exti line interrupt flag is set or not.
1333   * @retval Line Status.
1334   */
1335 #define __HAL_RTC_TAMPER_TIMESTAMP_EXTI_GET_FLAG()         (EXTI->PR1 & RTC_EXTI_LINE_TAMPER_TIMESTAMP_EVENT)
1336 
1337 /**
1338   * @brief Clear the RTC Tamper and Timestamp associated Exti line flag.
1339   * @retval None
1340   */
1341 #define __HAL_RTC_TAMPER_TIMESTAMP_EXTI_CLEAR_FLAG()       (EXTI->PR1 = RTC_EXTI_LINE_TAMPER_TIMESTAMP_EVENT)
1342 
1343 /**
1344   * @brief Generate a Software interrupt on the RTC Tamper and Timestamp associated Exti line
1345   * @retval None
1346   */
1347 #define __HAL_RTC_TAMPER_TIMESTAMP_EXTI_GENERATE_SWIT()    (EXTI->SWIER1 |= RTC_EXTI_LINE_TAMPER_TIMESTAMP_EVENT)
1348 
1349 /**
1350   * @}
1351   */
1352 
1353 #if defined (STM32L4P5xx) || defined (STM32L4Q5xx)
1354 /* --------------------------------- SSR Underflow ---------------------------------*/
1355 /** @defgroup RTCEx_SSR_Underflow RTC SSR Underflow
1356   * @{
1357   */
1358 
1359 /**
1360   * @brief  Enable the RTC SSRU interrupt.
1361   * @param  __HANDLE__ specifies the RTC handle.
1362   * @param  __INTERRUPT__ specifies the RTC SSRU interrupt sources to be enabled.
1363   *         This parameter can be:
1364   *            @arg @ref RTC_IT_SSRU SSRU interrupt
1365   * @retval None
1366   */
1367 #define __HAL_RTC_SSRU_ENABLE_IT(__HANDLE__, __INTERRUPT__)    (RTC->CR |= (__INTERRUPT__))
1368 
1369 /**
1370   * @brief  Disable the RTC SSRU interrupt.
1371   * @param  __HANDLE__ specifies the RTC handle.
1372   * @param  __INTERRUPT__ specifies the RTC SSRU interrupt sources to be disabled.
1373   *         This parameter can be:
1374   *            @arg @ref RTC_IT_SSRU SSRU interrupt
1375   * @retval None
1376   */
1377 #define __HAL_RTC_SSRU_DISABLE_IT(__HANDLE__, __INTERRUPT__)   (RTC->CR &= ~(__INTERRUPT__))
1378 
1379 
1380 /**
1381   * @brief  Check whether the specified RTC SSRU interrupt has occurred or not.
1382   * @param  __HANDLE__ specifies the RTC handle.
1383   * @param  __INTERRUPT__ specifies the RTC SSRU interrupt to check.
1384   *         This parameter can be:
1385   *            @arg @ref RTC_IT_SSRU  SSRU interrupt
1386   * @retval None
1387   */
1388 #define __HAL_RTC_SSRU_GET_IT(__HANDLE__, __INTERRUPT__)       ((((RTC->MISR) & ((__INTERRUPT__) >> 1) != 0U) ? 1U : 0U)
1389 /**
1390   * @brief  Check whether the specified RTC Wake Up timer interrupt has been enabled or not.
1391   * @param  __HANDLE__ specifies the RTC handle.
1392   * @param  __INTERRUPT__ specifies the RTC Wake Up timer interrupt sources to check.
1393   *         This parameter can be:
1394   *            @arg @ref RTC_IT_SSRU  SSRU interrupt
1395   * @retval None
1396   */
1397 #define __HAL_RTC_SSRU_GET_IT_SOURCE(__HANDLE__, __INTERRUPT__)   ((((RTC->CR) & (__INTERRUPT__)) != 0U) ? 1U : 0U)
1398 
1399 /**
1400   * @brief  Get the selected RTC SSRU's flag status.
1401   * @param  __HANDLE__ specifies the RTC handle.
1402   * @param  __FLAG__ specifies the RTC SSRU Flag is pending or not.
1403   *          This parameter can be:
1404   *             @arg @ref RTC_FLAG_SSRUF
1405   *             @arg @ref RTC_FLAG_SSRUWF
1406   * @retval None
1407   */
1408 #define __HAL_RTC_SSRU_GET_FLAG(__HANDLE__, __FLAG__)   (__HAL_RTC_GET_FLAG((__HANDLE__), (__FLAG__)))
1409 
1410 /**
1411   * @brief  Clear the RTC Wake Up timer's pending flags.
1412   * @param  __HANDLE__ specifies the RTC handle.
1413   * @param  __FLAG__ specifies the RTC SSRU Flag to clear.
1414   *         This parameter can be:
1415   *            @arg @ref RTC_FLAG_SSRUF
1416   * @retval None
1417   */
1418 #define __HAL_RTC_SSRU_CLEAR_FLAG(__HANDLE__, __FLAG__)     (__HAL_RTC_CLEAR_FLAG((__HANDLE__), RTC_CLEAR_SSRUF))
1419 
1420 /* WAKE-UP TIMER EXTI */
1421 /* ------------------ */
1422 /**
1423   * @brief  Enable interrupt on the RTC SSR Underflow associated Exti line.
1424   * @retval None
1425   */
1426 #define __HAL_RTC_SSRU_EXTI_ENABLE_IT()       (EXTI->IMR1 |= RTC_EXTI_LINE_SSRU_EVENT)
1427 
1428 /**
1429   * @brief  Disable interrupt on the RTC SSR Underflow associated Exti line.
1430   * @retval None
1431   */
1432 #define __HAL_RTC_SSRU_EXTI_DISABLE_IT()      (EXTI->IMR1 &= ~(RTC_EXTI_LINE_SSRU_EVENT))
1433 
1434 /**
1435   * @brief  Enable event on the RTC SSR Underflow associated Exti line.
1436   * @retval None
1437   */
1438 #define __HAL_RTC_SSRU_EXTI_ENABLE_EVENT()    (EXTI->EMR1 |= RTC_EXTI_LINE_SSRU_EVENT)
1439 
1440 /**
1441   * @brief  Disable event on the RTC SSR Underflow associated Exti line.
1442   * @retval None
1443   */
1444 #define __HAL_RTC_SSRU_EXTI_DISABLE_EVENT()   (EXTI->EMR1 &= ~(RTC_EXTI_LINE_SSRU_EVENT))
1445 
1446 /**
1447   * @}
1448   */
1449 
1450 #endif /* #if defined (STM32L4P5xx) || defined (STM32L4Q5xx) */
1451 
1452 /**
1453   * @}
1454   */
1455 
1456 /* Exported functions --------------------------------------------------------*/
1457 
1458 /** @defgroup RTCEx_Exported_Functions RTCEx Exported Functions
1459   * @{
1460   */
1461 
1462 /* ========================================================================== */
1463 /*                  ##### RTC TimeStamp exported functions #####              */
1464 /* ========================================================================== */
1465 
1466 /* RTC TimeStamp functions ****************************************************/
1467 
1468 /** @defgroup RTCEx_Exported_Functions_Group1 Extended RTC TimeStamp functions
1469   * @{
1470   */
1471 HAL_StatusTypeDef HAL_RTCEx_SetTimeStamp(RTC_HandleTypeDef *hrtc, uint32_t TimeStampEdge, uint32_t RTC_TimeStampPin);
1472 HAL_StatusTypeDef HAL_RTCEx_SetTimeStamp_IT(RTC_HandleTypeDef *hrtc, uint32_t TimeStampEdge, uint32_t RTC_TimeStampPin);
1473 HAL_StatusTypeDef HAL_RTCEx_DeactivateTimeStamp(RTC_HandleTypeDef *hrtc);
1474 HAL_StatusTypeDef HAL_RTCEx_SetInternalTimeStamp(RTC_HandleTypeDef *hrtc);
1475 HAL_StatusTypeDef HAL_RTCEx_DeactivateInternalTimeStamp(RTC_HandleTypeDef *hrtc);
1476 HAL_StatusTypeDef HAL_RTCEx_GetTimeStamp(RTC_HandleTypeDef *hrtc, RTC_TimeTypeDef *sTimeStamp, RTC_DateTypeDef *sTimeStampDate, uint32_t Format);
1477 void              HAL_RTCEx_TamperTimeStampIRQHandler(RTC_HandleTypeDef *hrtc);
1478 void              HAL_RTCEx_TimeStampEventCallback(RTC_HandleTypeDef *hrtc);
1479 HAL_StatusTypeDef HAL_RTCEx_PollForTimeStampEvent(RTC_HandleTypeDef *hrtc, uint32_t Timeout);
1480 /**
1481   * @}
1482   */
1483 
1484 /* ========================================================================== */
1485 /*                   ##### RTC Wake-up exported functions #####               */
1486 /* ========================================================================== */
1487 
1488 /* RTC Wake-up functions ******************************************************/
1489 
1490 /** @defgroup RTCEx_Exported_Functions_Group2 Extended RTC Wake-up functions
1491  * @{
1492  */
1493 HAL_StatusTypeDef HAL_RTCEx_SetWakeUpTimer(RTC_HandleTypeDef *hrtc, uint32_t WakeUpCounter, uint32_t WakeUpClock);
1494 #if defined(STM32L412xx) || defined(STM32L422xx) || defined (STM32L4P5xx) || defined (STM32L4Q5xx)
1495 HAL_StatusTypeDef HAL_RTCEx_SetWakeUpTimer_IT(RTC_HandleTypeDef *hrtc, uint32_t WakeUpCounter, uint32_t WakeUpClock, uint32_t WakeUpAutoClr);
1496 #else
1497 HAL_StatusTypeDef HAL_RTCEx_SetWakeUpTimer_IT(RTC_HandleTypeDef *hrtc, uint32_t WakeUpCounter, uint32_t WakeUpClock);
1498 #endif
1499 HAL_StatusTypeDef HAL_RTCEx_DeactivateWakeUpTimer(RTC_HandleTypeDef *hrtc);
1500 uint32_t          HAL_RTCEx_GetWakeUpTimer(RTC_HandleTypeDef *hrtc);
1501 void              HAL_RTCEx_WakeUpTimerIRQHandler(RTC_HandleTypeDef *hrtc);
1502 void              HAL_RTCEx_WakeUpTimerEventCallback(RTC_HandleTypeDef *hrtc);
1503 HAL_StatusTypeDef HAL_RTCEx_PollForWakeUpTimerEvent(RTC_HandleTypeDef *hrtc, uint32_t Timeout);
1504 /**
1505   * @}
1506   */
1507 
1508 /* ========================================================================== */
1509 /*        ##### Extended RTC Peripheral Control exported functions #####      */
1510 /* ========================================================================== */
1511 
1512 /* Extended RTC Peripheral Control functions **********************************/
1513 
1514 /** @defgroup RTCEx_Exported_Functions_Group3 Extended Peripheral Control functions
1515  * @{
1516  */
1517 HAL_StatusTypeDef HAL_RTCEx_SetSmoothCalib(RTC_HandleTypeDef *hrtc, uint32_t SmoothCalibPeriod, uint32_t SmoothCalibPlusPulses, uint32_t SmoothCalibMinusPulsesValue);
1518 #if defined(STM32L412xx) || defined(STM32L422xx) || defined (STM32L4P5xx) || defined (STM32L4Q5xx)
1519 HAL_StatusTypeDef HAL_RTCEx_SetLowPowerCalib(RTC_HandleTypeDef *hrtc, uint32_t LowPowerCalib);
1520 #endif
1521 HAL_StatusTypeDef HAL_RTCEx_SetSynchroShift(RTC_HandleTypeDef *hrtc, uint32_t ShiftAdd1S, uint32_t ShiftSubFS);
1522 HAL_StatusTypeDef HAL_RTCEx_SetCalibrationOutPut(RTC_HandleTypeDef *hrtc, uint32_t CalibOutput);
1523 HAL_StatusTypeDef HAL_RTCEx_DeactivateCalibrationOutPut(RTC_HandleTypeDef *hrtc);
1524 HAL_StatusTypeDef HAL_RTCEx_SetRefClock(RTC_HandleTypeDef *hrtc);
1525 HAL_StatusTypeDef HAL_RTCEx_DeactivateRefClock(RTC_HandleTypeDef *hrtc);
1526 HAL_StatusTypeDef HAL_RTCEx_EnableBypassShadow(RTC_HandleTypeDef *hrtc);
1527 HAL_StatusTypeDef HAL_RTCEx_DisableBypassShadow(RTC_HandleTypeDef *hrtc);
1528 #if defined (STM32L4P5xx) || defined (STM32L4Q5xx)
1529 HAL_StatusTypeDef HAL_RTCEx_SetSSRU_IT(RTC_HandleTypeDef *hrtc);
1530 HAL_StatusTypeDef HAL_RTCEx_DeactivateSSRU(RTC_HandleTypeDef *hrtc);
1531 void              HAL_RTCEx_SSRUIRQHandler(RTC_HandleTypeDef *hrtc);
1532 void              HAL_RTCEx_SSRUEventCallback(RTC_HandleTypeDef *hrtc);
1533 #endif
1534 /**
1535   * @}
1536   */
1537 
1538 /* Extended RTC features functions *******************************************/
1539 /** @defgroup RTCEx_Exported_Functions_Group4 Extended features functions
1540   * @{
1541   */
1542 
1543 void              HAL_RTCEx_AlarmBEventCallback(RTC_HandleTypeDef *hrtc);
1544 HAL_StatusTypeDef HAL_RTCEx_PollForAlarmBEvent(RTC_HandleTypeDef *hrtc, uint32_t Timeout);
1545 /**
1546   * @}
1547   */
1548 
1549 /** @defgroup RTCEx_Exported_Functions_Group5 Extended RTC Tamper functions
1550   * @{
1551   */
1552 HAL_StatusTypeDef HAL_RTCEx_SetTamper(RTC_HandleTypeDef *hrtc, RTC_TamperTypeDef *sTamper);
1553 HAL_StatusTypeDef HAL_RTCEx_SetTamper_IT(RTC_HandleTypeDef *hrtc, RTC_TamperTypeDef *sTamper);
1554 HAL_StatusTypeDef HAL_RTCEx_DeactivateTamper(RTC_HandleTypeDef *hrtc, uint32_t Tamper);
1555 
1556 #if defined(RTC_TAMPER1_SUPPORT)
1557 HAL_StatusTypeDef HAL_RTCEx_PollForTamper1Event(RTC_HandleTypeDef *hrtc, uint32_t Timeout);
1558 #endif /* RTC_TAMPER1_SUPPORT */
1559 HAL_StatusTypeDef HAL_RTCEx_PollForTamper2Event(RTC_HandleTypeDef *hrtc, uint32_t Timeout);
1560 #if defined(RTC_TAMPER3_SUPPORT)
1561 HAL_StatusTypeDef HAL_RTCEx_PollForTamper3Event(RTC_HandleTypeDef *hrtc, uint32_t Timeout);
1562 #endif /* RTC_TAMPER3_SUPPORT */
1563 
1564 #if defined(RTC_TAMPER1_SUPPORT)
1565 void              HAL_RTCEx_Tamper1EventCallback(RTC_HandleTypeDef *hrtc);
1566 #endif /* RTC_TAMPER1_SUPPORT */
1567 void              HAL_RTCEx_Tamper2EventCallback(RTC_HandleTypeDef *hrtc);
1568 #if defined(RTC_TAMPER3_SUPPORT)
1569 void              HAL_RTCEx_Tamper3EventCallback(RTC_HandleTypeDef *hrtc);
1570 #endif /* RTC_TAMPER3_SUPPORT */
1571 
1572 
1573 /**
1574   * @}
1575   */
1576 
1577 /** @defgroup RTCEx_Exported_Functions_Group6 Extended RTC Backup register functions
1578  * @{
1579  */
1580 void              HAL_RTCEx_BKUPWrite(RTC_HandleTypeDef *hrtc, uint32_t BackupRegister, uint32_t Data);
1581 uint32_t          HAL_RTCEx_BKUPRead(RTC_HandleTypeDef *hrtc, uint32_t BackupRegister);
1582 /**
1583   * @}
1584   */
1585 
1586 /**
1587   * @}
1588   */
1589 
1590 /* Private types -------------------------------------------------------------*/
1591 /* Private variables ---------------------------------------------------------*/
1592 /* Private constants ---------------------------------------------------------*/
1593 /** @defgroup RTCEx_Private_Constants RTCEx Private Constants
1594   * @{
1595   */
1596 #if defined (STM32L4P5xx) || defined (STM32L4Q5xx)
1597 #define RTC_EXTI_LINE_SSRU_EVENT              EXTI_IMR1_IM18  /*!< External interrupt line 18 Connected to the RTC SSR Underflow event  */
1598 #endif
1599 
1600 #define RTC_EXTI_LINE_TAMPER_TIMESTAMP_EVENT  EXTI_IMR1_IM19  /*!< External interrupt line 19 Connected to the RTC Tamper and Time Stamp events */
1601 
1602 #define RTC_EXTI_LINE_WAKEUPTIMER_EVENT       EXTI_IMR1_IM20  /*!< External interrupt line 20 Connected to the RTC Wakeup event */
1603 
1604 /**
1605   * @}
1606   */
1607 
1608 /* Private macros ------------------------------------------------------------*/
1609 /** @defgroup RTCEx_Private_Macros RTCEx Private Macros
1610   * @{
1611   */
1612 
1613 /** @defgroup RTCEx_IS_RTC_Definitions Private macros to check input parameters
1614   * @{
1615   */
1616 #define IS_TIMESTAMP_EDGE(EDGE) (((EDGE) == RTC_TIMESTAMPEDGE_RISING) || \
1617                                  ((EDGE) == RTC_TIMESTAMPEDGE_FALLING))
1618 
1619 #define IS_RTC_TAMPER_INTERRUPT(INTERRUPT) ((((INTERRUPT) & 0xFFB6FFFBU) == 0x00U) && ((INTERRUPT) != 0U))
1620 
1621 #define IS_RTC_TIMESTAMP_PIN(PIN)  (((PIN) == RTC_TIMESTAMPPIN_DEFAULT))
1622 
1623 #define IS_RTC_WAKEUP_CLOCK(CLOCK) (((CLOCK) == RTC_WAKEUPCLOCK_RTCCLK_DIV16)   || \
1624                                     ((CLOCK) == RTC_WAKEUPCLOCK_RTCCLK_DIV8)    || \
1625                                     ((CLOCK) == RTC_WAKEUPCLOCK_RTCCLK_DIV4)    || \
1626                                     ((CLOCK) == RTC_WAKEUPCLOCK_RTCCLK_DIV2)    || \
1627                                     ((CLOCK) == RTC_WAKEUPCLOCK_CK_SPRE_16BITS) || \
1628                                     ((CLOCK) == RTC_WAKEUPCLOCK_CK_SPRE_17BITS))
1629 
1630 #define IS_RTC_WAKEUP_COUNTER(COUNTER)  ((COUNTER) <= RTC_WUTR_WUT)
1631 
1632 #define IS_RTC_SMOOTH_CALIB_PERIOD(PERIOD) (((PERIOD) == RTC_SMOOTHCALIB_PERIOD_32SEC) || \
1633                                             ((PERIOD) == RTC_SMOOTHCALIB_PERIOD_16SEC) || \
1634                                             ((PERIOD) == RTC_SMOOTHCALIB_PERIOD_8SEC))
1635 
1636 #define IS_RTC_SMOOTH_CALIB_PLUS(PLUS) (((PLUS) == RTC_SMOOTHCALIB_PLUSPULSES_SET) || \
1637                                         ((PLUS) == RTC_SMOOTHCALIB_PLUSPULSES_RESET))
1638 
1639 #define IS_RTC_SMOOTH_CALIB_MINUS(VALUE) ((VALUE) <= RTC_CALR_CALM)
1640 
1641 #if defined(STM32L412xx) || defined(STM32L422xx) || defined (STM32L4P5xx) || defined (STM32L4Q5xx)
1642 #define IS_RTC_LOW_POWER_CALIB(LPCAL) (((LPCAL) == RTC_LPCAL_SET) || \
1643                                        ((LPCAL) == RTC_LPCAL_RESET))
1644 #endif
1645 
1646 #if defined(STM32L412xx) || defined(STM32L422xx) || defined (STM32L4P5xx) || defined (STM32L4Q5xx)
1647 #define IS_RTC_TAMPER(__TAMPER__)                ((((__TAMPER__) & RTC_TAMPER_ALL) != 0x00U) && \
1648                                                   (((__TAMPER__) & ~RTC_TAMPER_ALL) == 0x00U))
1649 #else
1650 #define IS_RTC_TAMPER(TAMPER) ((((TAMPER) & 0xFFFFFFD6U) == 0x00U) && ((TAMPER) != 0U))
1651 #endif
1652 
1653 
1654 #define IS_RTC_TAMPER_TRIGGER(__TRIGGER__)       (((__TRIGGER__) == RTC_TAMPERTRIGGER_RISINGEDGE)  || \
1655                                                   ((__TRIGGER__) == RTC_TAMPERTRIGGER_FALLINGEDGE) || \
1656                                                   ((__TRIGGER__) == RTC_TAMPERTRIGGER_LOWLEVEL)    || \
1657                                                   ((__TRIGGER__) == RTC_TAMPERTRIGGER_HIGHLEVEL))
1658 
1659 #define IS_RTC_TAMPER_ERASE_MODE(__MODE__)       (((__MODE__) == RTC_TAMPER_ERASE_BACKUP_ENABLE) || \
1660                                                   ((__MODE__) == RTC_TAMPER_ERASE_BACKUP_DISABLE))
1661 
1662 #define IS_RTC_TAMPER_MASKFLAG_STATE(__STATE__)  (((__STATE__) == RTC_TAMPERMASK_FLAG_ENABLE) || \
1663                                                   ((__STATE__) == RTC_TAMPERMASK_FLAG_DISABLE))
1664 
1665 #define IS_RTC_TAMPER_FILTER(__FILTER__)         (((__FILTER__) == RTC_TAMPERFILTER_DISABLE)  || \
1666                                                   ((__FILTER__) == RTC_TAMPERFILTER_2SAMPLE) || \
1667                                                   ((__FILTER__) == RTC_TAMPERFILTER_4SAMPLE) || \
1668                                                   ((__FILTER__) == RTC_TAMPERFILTER_8SAMPLE))
1669 
1670 #define IS_RTC_TAMPER_SAMPLING_FREQ(__FREQ__)    (((__FREQ__) == RTC_TAMPERSAMPLINGFREQ_RTCCLK_DIV32768)|| \
1671                                                   ((__FREQ__) == RTC_TAMPERSAMPLINGFREQ_RTCCLK_DIV16384)|| \
1672                                                   ((__FREQ__) == RTC_TAMPERSAMPLINGFREQ_RTCCLK_DIV8192) || \
1673                                                   ((__FREQ__) == RTC_TAMPERSAMPLINGFREQ_RTCCLK_DIV4096) || \
1674                                                   ((__FREQ__) == RTC_TAMPERSAMPLINGFREQ_RTCCLK_DIV2048) || \
1675                                                   ((__FREQ__) == RTC_TAMPERSAMPLINGFREQ_RTCCLK_DIV1024) || \
1676                                                   ((__FREQ__) == RTC_TAMPERSAMPLINGFREQ_RTCCLK_DIV512)  || \
1677                                                   ((__FREQ__) == RTC_TAMPERSAMPLINGFREQ_RTCCLK_DIV256))
1678 
1679 #define IS_RTC_TAMPER_PRECHARGE_DURATION(__DURATION__)   (((__DURATION__) == RTC_TAMPERPRECHARGEDURATION_1RTCCLK) || \
1680                                                           ((__DURATION__) == RTC_TAMPERPRECHARGEDURATION_2RTCCLK) || \
1681                                                           ((__DURATION__) == RTC_TAMPERPRECHARGEDURATION_4RTCCLK) || \
1682                                                           ((__DURATION__) == RTC_TAMPERPRECHARGEDURATION_8RTCCLK))
1683 
1684 #define IS_RTC_TAMPER_PULLUP_STATE(__STATE__)    (((__STATE__) == RTC_TAMPER_PULLUP_ENABLE) || \
1685                                                   ((__STATE__) == RTC_TAMPER_PULLUP_DISABLE))
1686 
1687 #define IS_RTC_TAMPER_TIMESTAMPONTAMPER_DETECTION(DETECTION) (((DETECTION) == RTC_TIMESTAMPONTAMPERDETECTION_ENABLE) || \
1688                                                               ((DETECTION) == RTC_TIMESTAMPONTAMPERDETECTION_DISABLE))
1689 
1690 #define IS_RTC_BKP(__BKP__)   ((__BKP__) < RTC_BKP_NUMBER)
1691 
1692 #define IS_RTC_SHIFT_ADD1S(SEL) (((SEL) == RTC_SHIFTADD1S_RESET) || \
1693                                  ((SEL) == RTC_SHIFTADD1S_SET))
1694 
1695 #define IS_RTC_SHIFT_SUBFS(FS) ((FS) <= RTC_SHIFTR_SUBFS)
1696 
1697 #define IS_RTC_CALIB_OUTPUT(OUTPUT)  (((OUTPUT) == RTC_CALIBOUTPUT_512HZ) || \
1698                                       ((OUTPUT) == RTC_CALIBOUTPUT_1HZ))
1699 
1700 #if defined (STM32L4P5xx) || defined (STM32L4Q5xx)
1701 #define IS_RTC_BINARY_MODE(MODE) (((MODE) == RTC_BINARY_NONE) || \
1702                                   ((MODE) == RTC_BINARY_ONLY) || \
1703                                    ((MODE) == RTC_BINARY_MIX ))
1704 
1705 #define IS_RTC_BINARY_MIX_BCDU(BDCU) (((BDCU) == RTC_BINARY_MIX_BCDU_0) || \
1706                                       ((BDCU) == RTC_BINARY_MIX_BCDU_1) || \
1707                                       ((BDCU) == RTC_BINARY_MIX_BCDU_2) || \
1708                                       ((BDCU) == RTC_BINARY_MIX_BCDU_3) || \
1709                                       ((BDCU) == RTC_BINARY_MIX_BCDU_4) || \
1710                                       ((BDCU) == RTC_BINARY_MIX_BCDU_5) || \
1711                                       ((BDCU) == RTC_BINARY_MIX_BCDU_6) || \
1712                                       ((BDCU) == RTC_BINARY_MIX_BCDU_7))
1713 
1714 #define IS_RTC_ALARM_SUB_SECOND_BINARY_MASK(MASK)   (((MASK) == 0U) || \
1715                                                     (((MASK) >= RTC_ALARMSUBSECONDBINMASK_SS31_1) && ((MASK) <= RTC_ALARMSUBSECONDBINMASK_NONE)))
1716 
1717 #define IS_RTC_ALARMSUBSECONDBIN_AUTOCLR(SEL) (((SEL) == RTC_ALARMSUBSECONDBIN_AUTOCLR_NO) || \
1718                                                ((SEL) == RTC_ALARMSUBSECONDBIN_AUTOCLR_YES))
1719 #endif /* #if defined (STM32L4P5xx) || defined (STM32L4Q5xx) */
1720 /**
1721   * @}
1722   */
1723 
1724 /**
1725   * @}
1726   */
1727 
1728 /**
1729   * @}
1730   */
1731 
1732 /**
1733   * @}
1734   */
1735 
1736 #ifdef __cplusplus
1737 }
1738 #endif /* __cplusplus */
1739 
1740 #endif /* STM32L4xx_HAL_RTC_EX_H */
1741