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