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