1 /**
2   ******************************************************************************
3   * @file    stm32f7xx_hal_rtc_ex.h
4   * @author  MCD Application Team
5   * @brief   Header file of RTC HAL Extended module.
6   ******************************************************************************
7   * @attention
8   *
9   * Copyright (c) 2017 STMicroelectronics.
10   * All rights reserved.
11   *
12   * This software is licensed under terms that can be found in the LICENSE file
13   * in the root directory of this software component.
14   * If no LICENSE file comes with this software, it is provided AS-IS.
15   *
16   ******************************************************************************
17   */
18 
19 /* Define to prevent recursive inclusion -------------------------------------*/
20 #ifndef STM32F7xx_HAL_RTC_EX_H
21 #define STM32F7xx_HAL_RTC_EX_H
22 
23 #ifdef __cplusplus
24 extern "C" {
25 #endif
26 
27 /* Includes ------------------------------------------------------------------*/
28 
29 #include "stm32f7xx_hal_def.h"
30 
31 /** @addtogroup STM32F7xx_HAL_Driver
32   * @{
33   */
34 
35 /** @addtogroup RTCEx
36   * @{
37   */
38 
39 /* Exported types ------------------------------------------------------------*/
40 
41 /** @defgroup RTCEx_Exported_Types RTCEx Exported Types
42   * @{
43   */
44 
45 /**
46   * @brief  RTC Tamper structure definition
47   */
48 typedef struct
49 {
50   uint32_t Tamper;                      /*!< Specifies the Tamper Pin.
51                                              This parameter can be a value of @ref RTCEx_Tamper_Pin_Definitions */
52 
53   uint32_t Interrupt;                   /*!< Specifies the Tamper Interrupt.
54                                              This parameter can be a value of @ref RTCEx_Tamper_Interrupt_Definitions */
55 
56   uint32_t Trigger;                     /*!< Specifies the Tamper Trigger.
57                                              This parameter can be a value of @ref RTCEx_Tamper_Trigger_Definitions */
58 
59   uint32_t NoErase;                     /*!< Specifies the Tamper no erase mode.
60                                              This parameter can be a value of @ref RTCEx_Tamper_EraseBackUp_Definitions */
61 
62   uint32_t MaskFlag;                     /*!< Specifies the Tamper Flag masking.
63                                              This parameter can be a value of @ref RTCEx_Tamper_MaskFlag_Definitions   */
64 
65   uint32_t Filter;                      /*!< Specifies the RTC Filter Tamper.
66                                              This parameter can be a value of @ref RTCEx_Tamper_Filter_Definitions */
67 
68   uint32_t SamplingFrequency;           /*!< Specifies the sampling frequency.
69                                              This parameter can be a value of @ref RTCEx_Tamper_Sampling_Frequencies_Definitions */
70 
71   uint32_t PrechargeDuration;           /*!< Specifies the Precharge Duration .
72                                              This parameter can be a value of @ref RTCEx_Tamper_Pin_Precharge_Duration_Definitions */
73 
74   uint32_t TamperPullUp;                /*!< Specifies the Tamper PullUp .
75                                              This parameter can be a value of @ref RTCEx_Tamper_Pull_Up_Definitions */
76 
77   uint32_t TimeStampOnTamperDetection;  /*!< Specifies the TimeStampOnTamperDetection.
78                                              This parameter can be a value of @ref RTCEx_Tamper_TimeStampOnTamperDetection_Definitions */
79 } RTC_TamperTypeDef;
80 /**
81   * @}
82   */
83 
84 /* Exported constants --------------------------------------------------------*/
85 
86 /** @defgroup RTCEx_Exported_Constants RTCEx Exported Constants
87   * @{
88   */
89 
90 /** @defgroup RTCEx_Backup_Registers_Definitions RTCEx Backup Registers Definitions
91   * @{
92   */
93 #define RTC_BKP_DR0                       0x00000000U
94 #define RTC_BKP_DR1                       0x00000001U
95 #define RTC_BKP_DR2                       0x00000002U
96 #define RTC_BKP_DR3                       0x00000003U
97 #define RTC_BKP_DR4                       0x00000004U
98 #define RTC_BKP_DR5                       0x00000005U
99 #define RTC_BKP_DR6                       0x00000006U
100 #define RTC_BKP_DR7                       0x00000007U
101 #define RTC_BKP_DR8                       0x00000008U
102 #define RTC_BKP_DR9                       0x00000009U
103 #define RTC_BKP_DR10                      0x0000000AU
104 #define RTC_BKP_DR11                      0x0000000BU
105 #define RTC_BKP_DR12                      0x0000000CU
106 #define RTC_BKP_DR13                      0x0000000DU
107 #define RTC_BKP_DR14                      0x0000000EU
108 #define RTC_BKP_DR15                      0x0000000FU
109 #define RTC_BKP_DR16                      0x00000010U
110 #define RTC_BKP_DR17                      0x00000011U
111 #define RTC_BKP_DR18                      0x00000012U
112 #define RTC_BKP_DR19                      0x00000013U
113 #define RTC_BKP_DR20                      0x00000014U
114 #define RTC_BKP_DR21                      0x00000015U
115 #define RTC_BKP_DR22                      0x00000016U
116 #define RTC_BKP_DR23                      0x00000017U
117 #define RTC_BKP_DR24                      0x00000018U
118 #define RTC_BKP_DR25                      0x00000019U
119 #define RTC_BKP_DR26                      0x0000001AU
120 #define RTC_BKP_DR27                      0x0000001BU
121 #define RTC_BKP_DR28                      0x0000001CU
122 #define RTC_BKP_DR29                      0x0000001DU
123 #define RTC_BKP_DR30                      0x0000001EU
124 #define RTC_BKP_DR31                      0x0000001FU
125 /**
126   * @}
127   */
128 
129 /** @defgroup RTCEx_Timestamp_Edges_Definitions RTCEx Timestamp Edges Definitions
130   * @{
131   */
132 #define RTC_TIMESTAMPEDGE_RISING          0x00000000U
133 #define RTC_TIMESTAMPEDGE_FALLING         RTC_CR_TSEDGE
134 /**
135   * @}
136   */
137 
138 /** @defgroup RTCEx_Timestamp_Pin_Selection RTC Timestamp Pin Selection
139   * @{
140   */
141 #define RTC_TIMESTAMPPIN_DEFAULT            0x00000000U
142 #define RTC_TIMESTAMPPIN_POS1               RTC_OR_TSINSEL_0
143 #define RTC_TIMESTAMPPIN_POS2               RTC_OR_TSINSEL_1
144 /**
145   * @}
146   */
147 
148 /** @defgroup RTCEx_Tamper_Pin_Definitions RTCEx Tamper Pins Definitions
149   * @{
150   */
151 #define RTC_TAMPER_1                    RTC_TAMPCR_TAMP1E
152 #define RTC_TAMPER_2                    RTC_TAMPCR_TAMP2E
153 #define RTC_TAMPER_3                    RTC_TAMPCR_TAMP3E
154 /**
155   * @}
156   */
157 
158 /** @defgroup RTCEx_Tamper_Pin_Selection RTC tamper Pins Selection
159   * @{
160   */
161 #define RTC_TAMPERPIN_DEFAULT               0x00000000U
162 /**
163   * @}
164   */
165 
166 /** @defgroup RTCEx_Tamper_Interrupt_Definitions RTCEx Tamper Interrupt Definitions
167   * @{
168   */
169 #define RTC_IT_TAMP                       RTC_TAMPCR_TAMPIE   /*!< Enable global Tamper Interrupt           */
170 #define RTC_IT_TAMP1                      RTC_TAMPCR_TAMP1IE  /*!< Enable Tamper 1 Interrupt                */
171 #define RTC_IT_TAMP2                      RTC_TAMPCR_TAMP2IE  /*!< Enable Tamper 2 Interrupt                */
172 #define RTC_IT_TAMP3                      RTC_TAMPCR_TAMP3IE  /*!< Enable Tamper 3 Interrupt                */
173 /**
174   * @}
175   */
176 
177 /** @defgroup RTCEx_Tamper_Trigger_Definitions RTCEx Tamper Triggers Definitions
178   * @{
179   */
180 #define RTC_TAMPERTRIGGER_RISINGEDGE       0x00000000U
181 #define RTC_TAMPERTRIGGER_FALLINGEDGE      RTC_TAMPCR_TAMP1TRG
182 #define RTC_TAMPERTRIGGER_LOWLEVEL         RTC_TAMPERTRIGGER_RISINGEDGE
183 #define RTC_TAMPERTRIGGER_HIGHLEVEL        RTC_TAMPERTRIGGER_FALLINGEDGE
184 /**
185   * @}
186   */
187 
188 /** @defgroup RTCEx_Tamper_EraseBackUp_Definitions RTCEx Tamper EraseBackUp Definitions
189   * @{
190   */
191 #define RTC_TAMPER_ERASE_BACKUP_ENABLE             0x00000000U
192 #define RTC_TAMPER_ERASE_BACKUP_DISABLE            RTC_TAMPCR_TAMP1NOERASE
193 /**
194   * @}
195   */
196 
197 /** @defgroup RTCEx_Tamper_MaskFlag_Definitions RTCEx Tamper MaskFlag Definitions
198   * @{
199   */
200 #define RTC_TAMPERMASK_FLAG_DISABLE                0x00000000U
201 #define RTC_TAMPERMASK_FLAG_ENABLE                 RTC_TAMPCR_TAMP1MF
202 /**
203   * @}
204   */
205 
206 /** @defgroup RTCEx_Tamper_Filter_Definitions RTCEx Tamper Filter Definitions
207   * @{
208   */
209 #define RTC_TAMPERFILTER_DISABLE   0x00000000U             /*!< Tamper filter is disabled */
210 
211 #define RTC_TAMPERFILTER_2SAMPLE   RTC_TAMPCR_TAMPFLT_0    /*!< Tamper is activated after 2
212                                                                  consecutive samples at the active level */
213 #define RTC_TAMPERFILTER_4SAMPLE   RTC_TAMPCR_TAMPFLT_1    /*!< Tamper is activated after 4
214                                                                  consecutive samples at the active level */
215 #define RTC_TAMPERFILTER_8SAMPLE   RTC_TAMPCR_TAMPFLT      /*!< Tamper is activated after 8
216                                                                  consecutive samples at the active level */
217 #define RTC_TAMPERFILTER_MASK      RTC_TAMPCR_TAMPFLT      /*!< Masking all bits except those of
218                                                                  field TAMPFLT                           */
219 /**
220   * @}
221   */
222 
223 /** @defgroup RTCEx_Tamper_Sampling_Frequencies_Definitions RTCEx Tamper Sampling Frequencies Definitions
224   * @{
225   */
226 #define RTC_TAMPERSAMPLINGFREQ_RTCCLK_DIV32768  0x00000000U                                     /*!< Each of the tamper inputs are sampled
227                                                                                                       with a frequency =  RTCCLK / 32768 */
228 #define RTC_TAMPERSAMPLINGFREQ_RTCCLK_DIV16384  RTC_TAMPCR_TAMPFREQ_0                           /*!< Each of the tamper inputs are sampled
229                                                                                                       with a frequency =  RTCCLK / 16384 */
230 #define RTC_TAMPERSAMPLINGFREQ_RTCCLK_DIV8192   RTC_TAMPCR_TAMPFREQ_1                           /*!< Each of the tamper inputs are sampled
231                                                                                                       with a frequency =  RTCCLK / 8192  */
232 #define RTC_TAMPERSAMPLINGFREQ_RTCCLK_DIV4096   (RTC_TAMPCR_TAMPFREQ_0 | RTC_TAMPCR_TAMPFREQ_1) /*!< Each of the tamper inputs are sampled
233                                                                                                       with a frequency =  RTCCLK / 4096  */
234 #define RTC_TAMPERSAMPLINGFREQ_RTCCLK_DIV2048   RTC_TAMPCR_TAMPFREQ_2                           /*!< Each of the tamper inputs are sampled
235                                                                                                       with a frequency =  RTCCLK / 2048  */
236 #define RTC_TAMPERSAMPLINGFREQ_RTCCLK_DIV1024   (RTC_TAMPCR_TAMPFREQ_0 | RTC_TAMPCR_TAMPFREQ_2) /*!< Each of the tamper inputs are sampled
237                                                                                                       with a frequency =  RTCCLK / 1024  */
238 #define RTC_TAMPERSAMPLINGFREQ_RTCCLK_DIV512    (RTC_TAMPCR_TAMPFREQ_1 | RTC_TAMPCR_TAMPFREQ_2) /*!< Each of the tamper inputs are sampled
239                                                                                                       with a frequency =  RTCCLK / 512   */
240 #define RTC_TAMPERSAMPLINGFREQ_RTCCLK_DIV256    RTC_TAMPCR_TAMPFREQ                             /*!< Each of the tamper inputs are sampled
241                                                                                                       with a frequency =  RTCCLK / 256   */
242 #define RTC_TAMPERSAMPLINGFREQ_RTCCLK_MASK      RTC_TAMPCR_TAMPFREQ                             /*!< Masking all bits except those of
243                                                                                                       field TAMPFREQ                     */
244 /**
245   * @}
246   */
247 
248 /** @defgroup RTCEx_Tamper_Pin_Precharge_Duration_Definitions RTCEx Tamper Pin Precharge Duration Definitions
249   * @{
250   */
251 #define RTC_TAMPERPRECHARGEDURATION_1RTCCLK     0x00000000U             /*!< Tamper pins are pre-charged before
252                                                                               sampling during 1 RTCCLK cycle  */
253 #define RTC_TAMPERPRECHARGEDURATION_2RTCCLK     RTC_TAMPCR_TAMPPRCH_0   /*!< Tamper pins are pre-charged before
254                                                                               sampling during 2 RTCCLK cycles */
255 #define RTC_TAMPERPRECHARGEDURATION_4RTCCLK     RTC_TAMPCR_TAMPPRCH_1   /*!< Tamper pins are pre-charged before
256                                                                               sampling during 4 RTCCLK cycles */
257 #define RTC_TAMPERPRECHARGEDURATION_8RTCCLK     RTC_TAMPCR_TAMPPRCH     /*!< Tamper pins are pre-charged before
258                                                                               sampling during 8 RTCCLK cycles */
259 #define RTC_TAMPERPRECHARGEDURATION_MASK        RTC_TAMPCR_TAMPPRCH     /*!< Masking all bits except those of
260                                                                               field TAMPPRCH                  */
261 /**
262   * @}
263   */
264 
265 /** @defgroup  RTCEx_Tamper_Pull_Up_Definitions RTCEx Tamper Pull Up Definitions
266   * @{
267   */
268 #define RTC_TAMPER_PULLUP_ENABLE  0x00000000U           /*!< Tamper pins are pre-charged before sampling     */
269 #define RTC_TAMPER_PULLUP_DISABLE RTC_TAMPCR_TAMPPUDIS   /*!< Tamper pins are not pre-charged before sampling */
270 #define RTC_TAMPER_PULLUP_MASK    RTC_TAMPCR_TAMPPUDIS   /*!< Masking all bits except bit TAMPPUDIS           */
271 /**
272   * @}
273   */
274 
275 /** @defgroup RTCEx_Tamper_TimeStampOnTamperDetection_Definitions RTCEx Tamper TimeStamp On Tamper Detection Definitions
276   * @{
277   */
278 #define RTC_TIMESTAMPONTAMPERDETECTION_ENABLE  RTC_TAMPCR_TAMPTS  /*!< TimeStamp on Tamper Detection event saved        */
279 #define RTC_TIMESTAMPONTAMPERDETECTION_DISABLE 0x00000000U       /*!< TimeStamp on Tamper Detection event is not saved */
280 #define RTC_TIMESTAMPONTAMPERDETECTION_MASK    RTC_TAMPCR_TAMPTS  /*!< Masking all bits except bit TAMPTS               */
281 /**
282   * @}
283   */
284 
285 /** @defgroup RTCEx_Wakeup_Timer_Definitions RTCEx Wakeup Timer Definitions
286   * @{
287   */
288 #define RTC_WAKEUPCLOCK_RTCCLK_DIV16        0x00000000U
289 #define RTC_WAKEUPCLOCK_RTCCLK_DIV8         RTC_CR_WUCKSEL_0
290 #define RTC_WAKEUPCLOCK_RTCCLK_DIV4         RTC_CR_WUCKSEL_1
291 #define RTC_WAKEUPCLOCK_RTCCLK_DIV2         (RTC_CR_WUCKSEL_0 | RTC_CR_WUCKSEL_1)
292 #define RTC_WAKEUPCLOCK_CK_SPRE_16BITS      RTC_CR_WUCKSEL_2
293 #define RTC_WAKEUPCLOCK_CK_SPRE_17BITS      (RTC_CR_WUCKSEL_1 | RTC_CR_WUCKSEL_2)
294 /**
295   * @}
296   */
297 
298 /** @defgroup RTCEx_Smooth_calib_period_Definitions RTCEx Smooth Calib Period Definitions
299   * @{
300   */
301 #define RTC_SMOOTHCALIB_PERIOD_32SEC   0x00000000U      /*!< If RTCCLK = 32768 Hz, smooth calibration
302                                                               period is 32s, otherwise 2^20 RTCCLK pulses */
303 #define RTC_SMOOTHCALIB_PERIOD_16SEC   RTC_CALR_CALW16  /*!< If RTCCLK = 32768 Hz, smooth calibration
304                                                               period is 16s, otherwise 2^19 RTCCLK pulses */
305 #define RTC_SMOOTHCALIB_PERIOD_8SEC    RTC_CALR_CALW8   /*!< If RTCCLK = 32768 Hz, smooth calibration
306                                                               period is 8s, otherwise 2^18 RTCCLK pulses  */
307 /**
308   * @}
309   */
310 
311 /** @defgroup RTCEx_Smooth_calib_Plus_pulses_Definitions RTCEx Smooth Calib Plus Pulses Definitions
312   * @{
313   */
314 #define RTC_SMOOTHCALIB_PLUSPULSES_SET    RTC_CALR_CALP           /*!< The number of RTCCLK pulses added
315                                                                         during a X -second window = Y - CALM[8:0]
316                                                                         with Y = 512, 256, 128 when X = 32, 16, 8 */
317 #define RTC_SMOOTHCALIB_PLUSPULSES_RESET  0x00000000U             /*!< The number of RTCCLK pulses subbstited
318                                                                         during a 32-second window = CALM[8:0] */
319 /**
320   * @}
321   */
322 
323 /** @defgroup RTCEx_Add_1_Second_Parameter_Definitions RTCEx Add 1 Second Parameter Definitions
324   * @{
325   */
326 #define RTC_SHIFTADD1S_RESET      0x00000000U
327 #define RTC_SHIFTADD1S_SET        RTC_SHIFTR_ADD1S
328 /**
329   * @}
330   */
331 
332 /** @defgroup RTCEx_Calib_Output_selection_Definitions RTCEx Calib Output Selection Definitions
333   * @{
334   */
335 #define RTC_CALIBOUTPUT_512HZ            0x00000000U
336 #define RTC_CALIBOUTPUT_1HZ              RTC_CR_COSEL
337 /**
338   * @}
339   */
340 
341 /**
342   * @}
343   */
344 
345 /* Exported macros -----------------------------------------------------------*/
346 
347 /** @defgroup RTCEx_Exported_Macros RTCEx Exported Macros
348   * @{
349   */
350 
351 /* ---------------------------------WAKEUPTIMER-------------------------------*/
352 
353 /** @defgroup RTCEx_WakeUp_Timer RTCEx WakeUp Timer
354   * @{
355   */
356 
357 /**
358   * @brief  Enable the RTC WakeUp Timer peripheral.
359   * @param  __HANDLE__ specifies the RTC handle.
360   * @retval None
361   */
362 #define __HAL_RTC_WAKEUPTIMER_ENABLE(__HANDLE__)                      ((__HANDLE__)->Instance->CR |= (RTC_CR_WUTE))
363 
364 /**
365   * @brief  Disable the RTC Wakeup Timer peripheral.
366   * @param  __HANDLE__ specifies the RTC handle.
367   * @retval None
368   */
369 #define __HAL_RTC_WAKEUPTIMER_DISABLE(__HANDLE__)                     ((__HANDLE__)->Instance->CR &= ~(RTC_CR_WUTE))
370 
371 /**
372   * @brief  Enable the RTC Wakeup Timer interrupt.
373   * @param  __HANDLE__ specifies the RTC handle.
374   * @param  __INTERRUPT__ specifies the RTC Wakeup Timer interrupt sources to be enabled or disabled.
375   *         This parameter can be:
376   *            @arg RTC_IT_WUT: Wakeup Timer interrupt
377   * @retval None
378   */
379 #define __HAL_RTC_WAKEUPTIMER_ENABLE_IT(__HANDLE__, __INTERRUPT__)    ((__HANDLE__)->Instance->CR |= (__INTERRUPT__))
380 
381 /**
382   * @brief  Disable the RTC Wakeup Timer interrupt.
383   * @param  __HANDLE__ specifies the RTC handle.
384   * @param  __INTERRUPT__ specifies the RTC Wakeup Timer interrupt sources to be enabled or disabled.
385   *         This parameter can be:
386   *            @arg RTC_IT_WUT: Wakeup Timer interrupt
387   * @retval None
388   */
389 #define __HAL_RTC_WAKEUPTIMER_DISABLE_IT(__HANDLE__, __INTERRUPT__)   ((__HANDLE__)->Instance->CR &= ~(__INTERRUPT__))
390 
391 /**
392   * @brief  Check whether the specified RTC Wakeup Timer interrupt has occurred or not.
393   * @param  __HANDLE__ specifies the RTC handle.
394   * @param  __INTERRUPT__ specifies the RTC Wakeup Timer interrupt to check.
395   *         This parameter can be:
396   *            @arg RTC_IT_WUT: Wakeup Timer interrupt
397   * @retval None
398   */
399 #define __HAL_RTC_WAKEUPTIMER_GET_IT(__HANDLE__, __INTERRUPT__)          (((((__HANDLE__)->Instance->ISR) & ((__INTERRUPT__) >> 4U)) != 0U) ? 1U : 0U)
400 
401 /**
402   * @brief  Check whether the specified RTC Wakeup timer interrupt has been enabled or not.
403   * @param  __HANDLE__ specifies the RTC handle.
404   * @param  __INTERRUPT__ specifies the RTC Wakeup timer interrupt sources to check.
405   *         This parameter can be:
406   *            @arg RTC_IT_WUT: WakeUpTimer interrupt
407   * @retval None
408   */
409 #define __HAL_RTC_WAKEUPTIMER_GET_IT_SOURCE(__HANDLE__, __INTERRUPT__)   (((((__HANDLE__)->Instance->CR) & (__INTERRUPT__)) != 0U) ? 1U : 0U)
410 
411 /**
412   * @brief  Get the selected RTC Wakeup Timer's flag status.
413   * @param  __HANDLE__ specifies the RTC handle.
414   * @param  __FLAG__ specifies the RTC Wakeup Timer flag to check.
415   *          This parameter can be:
416   *             @arg RTC_FLAG_WUTF: Wakeup Timer interrupt flag
417   *             @arg RTC_FLAG_WUTWF: Wakeup Timer 'write allowed' flag
418   * @retval None
419   */
420 #define __HAL_RTC_WAKEUPTIMER_GET_FLAG(__HANDLE__, __FLAG__)          (((((__HANDLE__)->Instance->ISR) & (__FLAG__)) != 0U)? 1U : 0U)
421 
422 /**
423   * @brief  Clear the RTC Wakeup timer's pending flags.
424   * @param  __HANDLE__ specifies the RTC handle.
425   * @param  __FLAG__ specifies the RTC Wakeup Timer Flag to clear.
426   *         This parameter can be:
427   *             @arg RTC_FLAG_WUTF: Wakeup Timer interrupt Flag
428   * @retval None
429   */
430 #define __HAL_RTC_WAKEUPTIMER_CLEAR_FLAG(__HANDLE__, __FLAG__)            ((__HANDLE__)->Instance->ISR) = (~((__FLAG__) | RTC_ISR_INIT)|((__HANDLE__)->Instance->ISR & RTC_ISR_INIT))
431 
432 /**
433   * @brief  Enable interrupt on the RTC Wakeup Timer associated EXTI line.
434   * @retval None
435   */
436 #define __HAL_RTC_WAKEUPTIMER_EXTI_ENABLE_IT()       (EXTI->IMR |= RTC_EXTI_LINE_WAKEUPTIMER_EVENT)
437 
438 /**
439   * @brief  Disable interrupt on the RTC Wakeup Timer associated EXTI line.
440   * @retval None
441   */
442 #define __HAL_RTC_WAKEUPTIMER_EXTI_DISABLE_IT()      (EXTI->IMR &= ~RTC_EXTI_LINE_WAKEUPTIMER_EVENT)
443 
444 /**
445   * @brief  Enable event on the RTC Wakeup Timer associated EXTI line.
446   * @retval None.
447   */
448 #define __HAL_RTC_WAKEUPTIMER_EXTI_ENABLE_EVENT()    (EXTI->EMR |= RTC_EXTI_LINE_WAKEUPTIMER_EVENT)
449 
450 /**
451   * @brief  Disable event on the RTC Wakeup Timer associated EXTI line.
452   * @retval None.
453   */
454 #define __HAL_RTC_WAKEUPTIMER_EXTI_DISABLE_EVENT()   (EXTI->EMR &= ~RTC_EXTI_LINE_WAKEUPTIMER_EVENT)
455 
456 /**
457   * @brief  Enable falling edge trigger on the RTC Wakeup Timer associated EXTI line.
458   * @retval None.
459   */
460 #define __HAL_RTC_WAKEUPTIMER_EXTI_ENABLE_FALLING_EDGE()   (EXTI->FTSR |= RTC_EXTI_LINE_WAKEUPTIMER_EVENT)
461 
462 /**
463   * @brief  Disable falling edge trigger on the RTC Wakeup Timer associated EXTI line.
464   * @retval None.
465   */
466 #define __HAL_RTC_WAKEUPTIMER_EXTI_DISABLE_FALLING_EDGE()  (EXTI->FTSR &= ~RTC_EXTI_LINE_WAKEUPTIMER_EVENT)
467 
468 /**
469   * @brief  Enable rising edge trigger on the RTC Wakeup Timer associated EXTI line.
470   * @retval None.
471   */
472 #define __HAL_RTC_WAKEUPTIMER_EXTI_ENABLE_RISING_EDGE()    (EXTI->RTSR |= RTC_EXTI_LINE_WAKEUPTIMER_EVENT)
473 
474 /**
475   * @brief  Disable rising edge trigger on the RTC Wakeup Timer associated EXTI line.
476   * @retval None.
477   */
478 #define __HAL_RTC_WAKEUPTIMER_EXTI_DISABLE_RISING_EDGE()   (EXTI->RTSR &= ~RTC_EXTI_LINE_WAKEUPTIMER_EVENT)
479 
480 /**
481   * @brief  Enable rising & falling edge trigger on the RTC Wakeup Timer associated EXTI line.
482   * @retval None.
483   */
484 #define __HAL_RTC_WAKEUPTIMER_EXTI_ENABLE_RISING_FALLING_EDGE() do {                                                   \
485                                                                      __HAL_RTC_WAKEUPTIMER_EXTI_ENABLE_RISING_EDGE();  \
486                                                                      __HAL_RTC_WAKEUPTIMER_EXTI_ENABLE_FALLING_EDGE(); \
487                                                                    } while(0U)
488 
489 /**
490   * @brief  Disable rising & falling edge trigger on the RTC Wakeup Timer associated EXTI line.
491   * This parameter can be:
492   * @retval None.
493   */
494 #define __HAL_RTC_WAKEUPTIMER_EXTI_DISABLE_RISING_FALLING_EDGE() do {                                                    \
495                                                                       __HAL_RTC_WAKEUPTIMER_EXTI_DISABLE_RISING_EDGE();  \
496                                                                       __HAL_RTC_WAKEUPTIMER_EXTI_DISABLE_FALLING_EDGE(); \
497                                                                     } while(0U)
498 
499 /**
500   * @brief Check whether the RTC Wakeup Timer associated EXTI line interrupt flag is set or not.
501   * @retval Line Status.
502   */
503 #define __HAL_RTC_WAKEUPTIMER_EXTI_GET_FLAG()              (EXTI->PR & RTC_EXTI_LINE_WAKEUPTIMER_EVENT)
504 
505 /**
506   * @brief Clear the RTC Wakeup Timer associated EXTI line flag.
507   * @retval None.
508   */
509 #define __HAL_RTC_WAKEUPTIMER_EXTI_CLEAR_FLAG()            (EXTI->PR = RTC_EXTI_LINE_WAKEUPTIMER_EVENT)
510 
511 /**
512   * @brief Generate a Software interrupt on the RTC Wakeup Timer associated EXTI line.
513   * @retval None.
514   */
515 #define __HAL_RTC_WAKEUPTIMER_EXTI_GENERATE_SWIT()         (EXTI->SWIER |= RTC_EXTI_LINE_WAKEUPTIMER_EVENT)
516 
517 /**
518   * @}
519   */
520 
521 /* ---------------------------------TIMESTAMP---------------------------------*/
522 
523 /** @defgroup RTCEx_Timestamp RTCEx Timestamp
524   * @{
525   */
526 
527 /**
528   * @brief  Enable the RTC Timestamp peripheral.
529   * @param  __HANDLE__ specifies the RTC handle.
530   * @retval None
531   */
532 #define __HAL_RTC_TIMESTAMP_ENABLE(__HANDLE__)                        ((__HANDLE__)->Instance->CR |= (RTC_CR_TSE))
533 
534 /**
535   * @brief  Disable the RTC Timestamp peripheral.
536   * @param  __HANDLE__ specifies the RTC handle.
537   * @retval None
538   */
539 #define __HAL_RTC_TIMESTAMP_DISABLE(__HANDLE__)                       ((__HANDLE__)->Instance->CR &= ~(RTC_CR_TSE))
540 
541 /**
542   * @brief  Enable the RTC Timestamp interrupt.
543   * @param  __HANDLE__ specifies the RTC handle.
544   * @param  __INTERRUPT__ specifies the RTC Timestamp interrupt sources to be enabled or disabled.
545   *         This parameter can be:
546   *            @arg RTC_IT_TS: TimeStamp interrupt
547   * @retval None
548   */
549 #define __HAL_RTC_TIMESTAMP_ENABLE_IT(__HANDLE__, __INTERRUPT__)      ((__HANDLE__)->Instance->CR |= (__INTERRUPT__))
550 
551 /**
552   * @brief  Disable the RTC Timestamp interrupt.
553   * @param  __HANDLE__ specifies the RTC handle.
554   * @param  __INTERRUPT__ specifies the RTC Timestamp interrupt sources to be enabled or disabled.
555   *         This parameter can be:
556   *            @arg RTC_IT_TS: TimeStamp interrupt
557   * @retval None
558   */
559 #define __HAL_RTC_TIMESTAMP_DISABLE_IT(__HANDLE__, __INTERRUPT__)     ((__HANDLE__)->Instance->CR &= ~(__INTERRUPT__))
560 
561 /**
562   * @brief  Check whether the specified RTC Timestamp interrupt has occurred or not.
563   * @param  __HANDLE__ specifies the RTC handle.
564   * @param  __INTERRUPT__ specifies the RTC Timestamp interrupt to check.
565   *         This parameter can be:
566   *            @arg RTC_IT_TS: TimeStamp interrupt
567   * @retval None
568   */
569 #define __HAL_RTC_TIMESTAMP_GET_IT(__HANDLE__, __INTERRUPT__)         (((((__HANDLE__)->Instance->ISR) & ((__INTERRUPT__) >> 4U)) != 0U) ? 1U : 0U)
570 
571 /**
572   * @brief  Check whether the specified RTC Timestamp interrupt has been enabled or not.
573   * @param  __HANDLE__ specifies the RTC handle.
574   * @param  __INTERRUPT__ specifies the RTC Timestamp interrupt source to check.
575   *         This parameter can be:
576   *            @arg RTC_IT_TS: TimeStamp interrupt
577   * @retval None
578   */
579 #define __HAL_RTC_TIMESTAMP_GET_IT_SOURCE(__HANDLE__, __INTERRUPT__)     (((((__HANDLE__)->Instance->CR) & (__INTERRUPT__)) != 0U) ? 1U : 0U)
580 
581 /**
582   * @brief  Get the selected RTC Timestamp's flag status.
583   * @param  __HANDLE__ specifies the RTC handle.
584   * @param  __FLAG__ specifies the RTC Timestamp flag to check.
585   *         This parameter can be:
586   *            @arg RTC_FLAG_TSF: Timestamp interrupt flag
587   *            @arg RTC_FLAG_TSOVF: Timestamp overflow flag
588   * @retval None
589   */
590 #define __HAL_RTC_TIMESTAMP_GET_FLAG(__HANDLE__, __FLAG__)            (((((__HANDLE__)->Instance->ISR) & (__FLAG__)) != 0U)? 1U : 0U)
591 
592 /**
593   * @brief  Clear the RTC Timestamp's pending flags.
594   * @param  __HANDLE__ specifies the RTC handle.
595   * @param  __FLAG__ specifies the RTC Timestamp flag to clear.
596   *         This parameter can be:
597   *            @arg RTC_FLAG_TSF: Timestamp interrupt flag
598   *            @arg RTC_FLAG_TSOVF: Timestamp overflow flag
599   * @retval None
600   */
601 #define __HAL_RTC_TIMESTAMP_CLEAR_FLAG(__HANDLE__, __FLAG__)          ((__HANDLE__)->Instance->ISR) = (~((__FLAG__) | RTC_ISR_INIT)|((__HANDLE__)->Instance->ISR & RTC_ISR_INIT))
602 
603 /**
604   * @brief  Enable the RTC internal TimeStamp peripheral.
605   * @param  __HANDLE__ specifies the RTC handle.
606   * @retval None
607   */
608 #define __HAL_RTC_INTERNAL_TIMESTAMP_ENABLE(__HANDLE__)                ((__HANDLE__)->Instance->CR |= (RTC_CR_ITSE))
609 
610 /**
611   * @brief  Disable the RTC internal TimeStamp peripheral.
612   * @param  __HANDLE__ specifies the RTC handle.
613   * @retval None
614   */
615 #define __HAL_RTC_INTERNAL_TIMESTAMP_DISABLE(__HANDLE__)               ((__HANDLE__)->Instance->CR &= ~(RTC_CR_ITSE))
616 
617 /**
618   * @brief  Get the selected RTC Internal Timestamp's flag status.
619   * @param  __HANDLE__ specifies the RTC handle.
620   * @param  __FLAG__ specifies the RTC Internal Timestamp flag is pending or not.
621   *         This parameter can be:
622   *            @arg RTC_FLAG_ITSF: Internal Timestamp interrupt flag
623   * @retval None
624   */
625 #define __HAL_RTC_INTERNAL_TIMESTAMP_GET_FLAG(__HANDLE__, __FLAG__)    (((((__HANDLE__)->Instance->ISR) & (__FLAG__)) != 0U) ? 1U : 0U)
626 
627 /**
628   * @brief  Clear the RTC Internal Timestamp's pending flags.
629   * @param  __HANDLE__ specifies the RTC handle.
630   * @param  __FLAG__ specifies the RTC Internal Timestamp flag to clear.
631   *          This parameter can be:
632   *            @arg RTC_FLAG_ITSF: Internal Timestamp interrupt flag
633   * @retval None
634   */
635 #define __HAL_RTC_INTERNAL_TIMESTAMP_CLEAR_FLAG(__HANDLE__, __FLAG__)  ((__HANDLE__)->Instance->ISR) = (~(((__FLAG__) | RTC_ISR_INIT)& 0x0003FFFFU)|((__HANDLE__)->Instance->ISR & RTC_ISR_INIT))
636 
637 /**
638   * @}
639   */
640 
641 /* ---------------------------------TAMPER------------------------------------*/
642 
643 /** @defgroup RTCEx_Tamper RTCEx Tamper
644   * @{
645   */
646 
647 /**
648   * @brief  Enable the RTC Tamper1 input detection.
649   * @param  __HANDLE__ specifies the RTC handle.
650   * @retval None
651   */
652 #define __HAL_RTC_TAMPER1_ENABLE(__HANDLE__)                         ((__HANDLE__)->Instance->TAMPCR |= (RTC_TAMPCR_TAMP1E))
653 
654 /**
655   * @brief  Disable the RTC Tamper1 input detection.
656   * @param  __HANDLE__ specifies the RTC handle.
657   * @retval None
658   */
659 #define __HAL_RTC_TAMPER1_DISABLE(__HANDLE__)                        ((__HANDLE__)->Instance->TAMPCR &= ~(RTC_TAMPCR_TAMP1E))
660 
661 /**
662   * @brief  Enable the RTC Tamper2 input detection.
663   * @param  __HANDLE__ specifies the RTC handle.
664   * @retval None
665   */
666 #define __HAL_RTC_TAMPER2_ENABLE(__HANDLE__)                         ((__HANDLE__)->Instance->TAMPCR |= (RTC_TAMPCR_TAMP2E))
667 
668 /**
669   * @brief  Disable the RTC Tamper2 input detection.
670   * @param  __HANDLE__ specifies the RTC handle.
671   * @retval None
672   */
673 #define __HAL_RTC_TAMPER2_DISABLE(__HANDLE__)                        ((__HANDLE__)->Instance->TAMPCR &= ~(RTC_TAMPCR_TAMP2E))
674 
675 /**
676   * @brief  Enable the RTC Tamper3 input detection.
677   * @param  __HANDLE__ specifies the RTC handle.
678   * @retval None
679   */
680 #define __HAL_RTC_TAMPER3_ENABLE(__HANDLE__)                         ((__HANDLE__)->Instance->TAMPCR |= (RTC_TAMPCR_TAMP3E))
681 
682 /**
683   * @brief  Disable the RTC Tamper3 input detection.
684   * @param  __HANDLE__ specifies the RTC handle.
685   * @retval None
686   */
687 #define __HAL_RTC_TAMPER3_DISABLE(__HANDLE__)                        ((__HANDLE__)->Instance->TAMPCR &= ~(RTC_TAMPCR_TAMP3E))
688 
689 /**
690   * @brief  Enable the RTC Tamper interrupt.
691   * @param  __HANDLE__ specifies the RTC handle.
692   * @param  __INTERRUPT__ specifies the RTC Tamper interrupt sources to be enabled.
693   *          This parameter can be any combination of the following values:
694   *            @arg RTC_IT_TAMP: Tamper global interrupt
695   *            @arg RTC_IT_TAMP1: Tamper 1 interrupt
696   *            @arg RTC_IT_TAMP2: Tamper 2 interrupt
697   *            @arg RTC_IT_TAMP3: Tamper 3 interrupt
698   * @retval None
699   */
700 #define __HAL_RTC_TAMPER_ENABLE_IT(__HANDLE__, __INTERRUPT__)        ((__HANDLE__)->Instance->TAMPCR |= (__INTERRUPT__))
701 
702 /**
703   * @brief  Disable the RTC Tamper interrupt.
704   * @param  __HANDLE__ specifies the RTC handle.
705   * @param  __INTERRUPT__ specifies the RTC Tamper interrupt sources to be disabled.
706   *         This parameter can be any combination of the following values:
707   *            @arg RTC_IT_TAMP: Tamper global interrupt
708   *            @arg RTC_IT_TAMP1: Tamper 1 interrupt
709   *            @arg RTC_IT_TAMP2: Tamper 2 interrupt
710   *            @arg RTC_IT_TAMP3: Tamper 3 interrupt
711   * @retval None
712   */
713 #define __HAL_RTC_TAMPER_DISABLE_IT(__HANDLE__, __INTERRUPT__)       ((__HANDLE__)->Instance->TAMPCR &= ~(__INTERRUPT__))
714 
715 /**
716   * @brief  Check whether the specified RTC Tamper interrupt has occurred or not.
717   * @param  __HANDLE__ specifies the RTC handle.
718   * @param  __INTERRUPT__ specifies the RTC Tamper interrupt to check.
719   *         This parameter can be:
720   *            @arg RTC_IT_TAMP1: Tamper 1 interrupt
721   *            @arg RTC_IT_TAMP2: Tamper 2 interrupt
722   *            @arg RTC_IT_TAMP3: Tamper 3 interrupt
723   * @retval None
724   */
725 #define __HAL_RTC_TAMPER_GET_IT(__HANDLE__, __INTERRUPT__)       (((((__HANDLE__)->Instance->ISR) & ((__INTERRUPT__) >> 4U)) != 0U) ? 1U : 0U)
726 
727 /**
728   * @brief  Check whether the specified RTC Tamper interrupt has been enabled or not.
729   * @param  __HANDLE__ specifies the RTC handle.
730   * @param  __INTERRUPT__ specifies the RTC Tamper interrupt source to check.
731   *         This parameter can be:
732   *            @arg RTC_IT_TAMP: Tamper global interrupt
733   *            @arg RTC_IT_TAMP1: Tamper 1 interrupt
734   *            @arg RTC_IT_TAMP2: Tamper 2 interrupt
735   *            @arg RTC_IT_TAMP3: Tamper 3 interrupt
736   * @retval None
737   */
738 #define __HAL_RTC_TAMPER_GET_IT_SOURCE(__HANDLE__, __INTERRUPT__)     (((((__HANDLE__)->Instance->TAMPCR) & (__INTERRUPT__)) != 0U) ? 1U : 0U)
739 
740 /**
741   * @brief  Get the selected RTC Tamper's flag status.
742   * @param  __HANDLE__ specifies the RTC handle.
743   * @param  __FLAG__ specifies the RTC Tamper flag to be checked.
744   *          This parameter can be:
745   *             @arg RTC_FLAG_TAMP1F: Tamper 1 interrupt flag
746   *             @arg RTC_FLAG_TAMP2F: Tamper 2 interrupt flag
747   *             @arg RTC_FLAG_TAMP3F: Tamper 3 interrupt flag
748   * @retval None
749   */
750 #define __HAL_RTC_TAMPER_GET_FLAG(__HANDLE__, __FLAG__)               (((((__HANDLE__)->Instance->ISR) & (__FLAG__)) != 0U)? 1U : 0U)
751 
752 /**
753   * @brief  Clear the RTC Tamper's pending flags.
754   * @param  __HANDLE__ specifies the RTC handle.
755   * @param  __FLAG__ specifies the RTC Tamper Flag to clear.
756   *          This parameter can be:
757   *             @arg RTC_FLAG_TAMP1F: Tamper 1 interrupt flag
758   *             @arg RTC_FLAG_TAMP2F: Tamper 2 interrupt flag
759   *             @arg RTC_FLAG_TAMP3F: Tamper 3 interrupt flag
760   * @retval None
761   */
762 #define __HAL_RTC_TAMPER_CLEAR_FLAG(__HANDLE__, __FLAG__)         ((__HANDLE__)->Instance->ISR) = (~((__FLAG__) | RTC_ISR_INIT)|((__HANDLE__)->Instance->ISR & RTC_ISR_INIT))
763 /**
764   * @}
765   */
766 
767 /* --------------------------TAMPER/TIMESTAMP---------------------------------*/
768 /** @defgroup RTCEx_Tamper_Timestamp EXTI RTC Tamper Timestamp EXTI
769   * @{
770   */
771 
772 /**
773   * @brief  Enable interrupt on the RTC Tamper and Timestamp associated EXTI line.
774   * @retval None
775   */
776 #define __HAL_RTC_TAMPER_TIMESTAMP_EXTI_ENABLE_IT()        (EXTI->IMR |= RTC_EXTI_LINE_TAMPER_TIMESTAMP_EVENT)
777 
778 /**
779   * @brief  Disable interrupt on the RTC Tamper and Timestamp associated EXTI line.
780   * @retval None
781   */
782 #define __HAL_RTC_TAMPER_TIMESTAMP_EXTI_DISABLE_IT()       (EXTI->IMR &= ~RTC_EXTI_LINE_TAMPER_TIMESTAMP_EVENT)
783 
784 /**
785   * @brief  Enable event on the RTC Tamper and Timestamp associated EXTI line.
786   * @retval None.
787   */
788 #define __HAL_RTC_TAMPER_TIMESTAMP_EXTI_ENABLE_EVENT()    (EXTI->EMR |= RTC_EXTI_LINE_TAMPER_TIMESTAMP_EVENT)
789 
790 /**
791   * @brief  Disable event on the RTC Tamper and Timestamp associated EXTI line.
792   * @retval None.
793   */
794 #define __HAL_RTC_TAMPER_TIMESTAMP_EXTI_DISABLE_EVENT()   (EXTI->EMR &= ~RTC_EXTI_LINE_TAMPER_TIMESTAMP_EVENT)
795 
796 /**
797   * @brief  Enable falling edge trigger on the RTC Tamper and Timestamp associated EXTI line.
798   * @retval None.
799   */
800 #define __HAL_RTC_TAMPER_TIMESTAMP_EXTI_ENABLE_FALLING_EDGE()   (EXTI->FTSR |= RTC_EXTI_LINE_TAMPER_TIMESTAMP_EVENT)
801 
802 /**
803   * @brief  Disable falling edge trigger on the RTC Tamper and Timestamp associated EXTI line.
804   * @retval None.
805   */
806 #define __HAL_RTC_TAMPER_TIMESTAMP_EXTI_DISABLE_FALLING_EDGE()  (EXTI->FTSR &= ~RTC_EXTI_LINE_TAMPER_TIMESTAMP_EVENT)
807 
808 /**
809   * @brief  Enable rising edge trigger on the RTC Tamper and Timestamp associated EXTI line.
810   * @retval None.
811   */
812 #define __HAL_RTC_TAMPER_TIMESTAMP_EXTI_ENABLE_RISING_EDGE()    (EXTI->RTSR |= RTC_EXTI_LINE_TAMPER_TIMESTAMP_EVENT)
813 
814 /**
815   * @brief  Disable rising edge trigger on the RTC Tamper and Timestamp associated EXTI line.
816   * @retval None.
817   */
818 #define __HAL_RTC_TAMPER_TIMESTAMP_EXTI_DISABLE_RISING_EDGE()   (EXTI->RTSR &= ~RTC_EXTI_LINE_TAMPER_TIMESTAMP_EVENT)
819 
820 /**
821   * @brief  Enable rising & falling edge trigger on the RTC Tamper and Timestamp associated EXTI line.
822   * @retval None.
823   */
824 #define __HAL_RTC_TAMPER_TIMESTAMP_EXTI_ENABLE_RISING_FALLING_EDGE() do {                                                        \
825                                                                           __HAL_RTC_TAMPER_TIMESTAMP_EXTI_ENABLE_RISING_EDGE();  \
826                                                                           __HAL_RTC_TAMPER_TIMESTAMP_EXTI_ENABLE_FALLING_EDGE(); \
827                                                                         } while(0U)
828 
829 /**
830   * @brief  Disable rising & falling edge trigger on the RTC Tamper and Timestamp associated EXTI line.
831   * This parameter can be:
832   * @retval None.
833   */
834 #define __HAL_RTC_TAMPER_TIMESTAMP_EXTI_DISABLE_RISING_FALLING_EDGE() do {                                                         \
835                                                                            __HAL_RTC_TAMPER_TIMESTAMP_EXTI_DISABLE_RISING_EDGE();  \
836                                                                            __HAL_RTC_TAMPER_TIMESTAMP_EXTI_DISABLE_FALLING_EDGE(); \
837                                                                          } while(0U)
838 
839 /**
840   * @brief Check whether the RTC Tamper and Timestamp associated EXTI line interrupt flag is set or not.
841   * @retval Line Status.
842   */
843 #define __HAL_RTC_TAMPER_TIMESTAMP_EXTI_GET_FLAG()         (EXTI->PR & RTC_EXTI_LINE_TAMPER_TIMESTAMP_EVENT)
844 
845 /**
846   * @brief Clear the RTC Tamper and Timestamp associated EXTI line flag.
847   * @retval None.
848   */
849 #define __HAL_RTC_TAMPER_TIMESTAMP_EXTI_CLEAR_FLAG()       (EXTI->PR = RTC_EXTI_LINE_TAMPER_TIMESTAMP_EVENT)
850 
851 /**
852   * @brief Generate a Software interrupt on the RTC Tamper and Timestamp associated EXTI line
853   * @retval None.
854   */
855 #define __HAL_RTC_TAMPER_TIMESTAMP_EXTI_GENERATE_SWIT()    (EXTI->SWIER |= RTC_EXTI_LINE_TAMPER_TIMESTAMP_EVENT)
856 /**
857   * @}
858   */
859 
860 /* ------------------------------CALIBRATION----------------------------------*/
861 
862 /** @defgroup RTCEx_Calibration RTCEx Calibration
863   * @{
864   */
865 
866 /**
867   * @brief  Enable the RTC calibration output.
868   * @param  __HANDLE__ specifies the RTC handle.
869   * @retval None
870   */
871 #define __HAL_RTC_CALIBRATION_OUTPUT_ENABLE(__HANDLE__)                 ((__HANDLE__)->Instance->CR |= (RTC_CR_COE))
872 
873 /**
874   * @brief  Disable the calibration output.
875   * @param  __HANDLE__ specifies the RTC handle.
876   * @retval None
877   */
878 #define __HAL_RTC_CALIBRATION_OUTPUT_DISABLE(__HANDLE__)                ((__HANDLE__)->Instance->CR &= ~(RTC_CR_COE))
879 
880 /**
881   * @brief  Enable the clock reference detection.
882   * @param  __HANDLE__ specifies the RTC handle.
883   * @retval None
884   */
885 #define __HAL_RTC_CLOCKREF_DETECTION_ENABLE(__HANDLE__)                 ((__HANDLE__)->Instance->CR |= (RTC_CR_REFCKON))
886 
887 /**
888   * @brief  Disable the clock reference detection.
889   * @param  __HANDLE__ specifies the RTC handle.
890   * @retval None
891   */
892 #define __HAL_RTC_CLOCKREF_DETECTION_DISABLE(__HANDLE__)                ((__HANDLE__)->Instance->CR &= ~(RTC_CR_REFCKON))
893 
894 /**
895   * @brief  Get the selected RTC shift operation's flag status.
896   * @param  __HANDLE__ specifies the RTC handle.
897   * @param  __FLAG__ specifies the RTC shift operation Flag is pending or not.
898   *          This parameter can be:
899   *             @arg RTC_FLAG_SHPF: Shift pending flag
900   * @retval None
901   */
902 #define __HAL_RTC_SHIFT_GET_FLAG(__HANDLE__, __FLAG__)                (((((__HANDLE__)->Instance->ISR) & (__FLAG__)) != 0U)? 1U : 0U)
903 /**
904   * @}
905   */
906 
907 /**
908   * @}
909   */
910 
911 /* Exported functions --------------------------------------------------------*/
912 
913 /** @defgroup RTCEx_Exported_Functions RTCEx Exported Functions
914   * @{
915   */
916 
917 /** @addtogroup RTCEx_Exported_Functions_Group1
918   * @{
919   */
920 /* RTC Timestamp and Tamper functions *****************************************/
921 HAL_StatusTypeDef HAL_RTCEx_SetTimeStamp(RTC_HandleTypeDef *hrtc, uint32_t RTC_TimeStampEdge, uint32_t RTC_TimeStampPin);
922 HAL_StatusTypeDef HAL_RTCEx_SetTimeStamp_IT(RTC_HandleTypeDef *hrtc, uint32_t RTC_TimeStampEdge, uint32_t RTC_TimeStampPin);
923 HAL_StatusTypeDef HAL_RTCEx_DeactivateTimeStamp(RTC_HandleTypeDef *hrtc);
924 HAL_StatusTypeDef HAL_RTCEx_SetInternalTimeStamp(RTC_HandleTypeDef *hrtc);
925 HAL_StatusTypeDef HAL_RTCEx_DeactivateInternalTimeStamp(RTC_HandleTypeDef *hrtc);
926 HAL_StatusTypeDef HAL_RTCEx_GetTimeStamp(RTC_HandleTypeDef *hrtc, RTC_TimeTypeDef *sTimeStamp, RTC_DateTypeDef *sTimeStampDate, uint32_t Format);
927 
928 HAL_StatusTypeDef HAL_RTCEx_SetTamper(RTC_HandleTypeDef *hrtc, RTC_TamperTypeDef *sTamper);
929 HAL_StatusTypeDef HAL_RTCEx_SetTamper_IT(RTC_HandleTypeDef *hrtc, RTC_TamperTypeDef *sTamper);
930 HAL_StatusTypeDef HAL_RTCEx_DeactivateTamper(RTC_HandleTypeDef *hrtc, uint32_t Tamper);
931 void              HAL_RTCEx_TamperTimeStampIRQHandler(RTC_HandleTypeDef *hrtc);
932 
933 void              HAL_RTCEx_Tamper1EventCallback(RTC_HandleTypeDef *hrtc);
934 void              HAL_RTCEx_Tamper2EventCallback(RTC_HandleTypeDef *hrtc);
935 void              HAL_RTCEx_Tamper3EventCallback(RTC_HandleTypeDef *hrtc);
936 void              HAL_RTCEx_TimeStampEventCallback(RTC_HandleTypeDef *hrtc);
937 HAL_StatusTypeDef HAL_RTCEx_PollForTimeStampEvent(RTC_HandleTypeDef *hrtc, uint32_t Timeout);
938 HAL_StatusTypeDef HAL_RTCEx_PollForTamper1Event(RTC_HandleTypeDef *hrtc, uint32_t Timeout);
939 HAL_StatusTypeDef HAL_RTCEx_PollForTamper2Event(RTC_HandleTypeDef *hrtc, uint32_t Timeout);
940 HAL_StatusTypeDef HAL_RTCEx_PollForTamper3Event(RTC_HandleTypeDef *hrtc, uint32_t Timeout);
941 /**
942   * @}
943   */
944 
945 /** @addtogroup RTCEx_Exported_Functions_Group2
946   * @{
947   */
948 /* RTC Wakeup functions ******************************************************/
949 HAL_StatusTypeDef HAL_RTCEx_SetWakeUpTimer(RTC_HandleTypeDef *hrtc, uint32_t WakeUpCounter, uint32_t WakeUpClock);
950 HAL_StatusTypeDef HAL_RTCEx_SetWakeUpTimer_IT(RTC_HandleTypeDef *hrtc, uint32_t WakeUpCounter, uint32_t WakeUpClock);
951 HAL_StatusTypeDef HAL_RTCEx_DeactivateWakeUpTimer(RTC_HandleTypeDef *hrtc);
952 uint32_t          HAL_RTCEx_GetWakeUpTimer(RTC_HandleTypeDef *hrtc);
953 void              HAL_RTCEx_WakeUpTimerIRQHandler(RTC_HandleTypeDef *hrtc);
954 void              HAL_RTCEx_WakeUpTimerEventCallback(RTC_HandleTypeDef *hrtc);
955 HAL_StatusTypeDef HAL_RTCEx_PollForWakeUpTimerEvent(RTC_HandleTypeDef *hrtc, uint32_t Timeout);
956 /**
957   * @}
958   */
959 
960 /** @addtogroup RTCEx_Exported_Functions_Group3
961   * @{
962   */
963 /* Extended Control functions ************************************************/
964 void              HAL_RTCEx_BKUPWrite(RTC_HandleTypeDef *hrtc, uint32_t BackupRegister, uint32_t Data);
965 uint32_t          HAL_RTCEx_BKUPRead(RTC_HandleTypeDef *hrtc, uint32_t BackupRegister);
966 
967 HAL_StatusTypeDef HAL_RTCEx_SetSmoothCalib(RTC_HandleTypeDef *hrtc, uint32_t SmoothCalibPeriod, uint32_t SmoothCalibPlusPulses, uint32_t SmoothCalibMinusPulsesValue);
968 HAL_StatusTypeDef HAL_RTCEx_SetSynchroShift(RTC_HandleTypeDef *hrtc, uint32_t ShiftAdd1S, uint32_t ShiftSubFS);
969 HAL_StatusTypeDef HAL_RTCEx_SetCalibrationOutPut(RTC_HandleTypeDef *hrtc, uint32_t CalibOutput);
970 HAL_StatusTypeDef HAL_RTCEx_DeactivateCalibrationOutPut(RTC_HandleTypeDef *hrtc);
971 HAL_StatusTypeDef HAL_RTCEx_SetRefClock(RTC_HandleTypeDef *hrtc);
972 HAL_StatusTypeDef HAL_RTCEx_DeactivateRefClock(RTC_HandleTypeDef *hrtc);
973 HAL_StatusTypeDef HAL_RTCEx_EnableBypassShadow(RTC_HandleTypeDef *hrtc);
974 HAL_StatusTypeDef HAL_RTCEx_DisableBypassShadow(RTC_HandleTypeDef *hrtc);
975 /**
976   * @}
977   */
978 
979 /** @addtogroup RTCEx_Exported_Functions_Group4
980   * @{
981   */
982 /* Extended RTC features functions *******************************************/
983 void HAL_RTCEx_AlarmBEventCallback(RTC_HandleTypeDef *hrtc);
984 HAL_StatusTypeDef HAL_RTCEx_PollForAlarmBEvent(RTC_HandleTypeDef *hrtc, uint32_t Timeout);
985 /**
986   * @}
987   */
988 
989 /**
990   * @}
991   */
992 
993 /* Private types -------------------------------------------------------------*/
994 /* Private variables ---------------------------------------------------------*/
995 /* Private constants ---------------------------------------------------------*/
996 
997 /** @defgroup RTCEx_Private_Constants RTCEx Private Constants
998   * @{
999   */
1000 #define RTC_EXTI_LINE_TAMPER_TIMESTAMP_EVENT  EXTI_IMR_IM21  /*!< External interrupt line 21 Connected to the RTC Tamper and Timestamp event */
1001 #define RTC_EXTI_LINE_WAKEUPTIMER_EVENT       EXTI_IMR_IM22  /*!< External interrupt line 22 Connected to the RTC Wakeup event */
1002 /**
1003   * @}
1004   */
1005 
1006 /** @defgroup RTCEx_Private_Constants RTCEx Private Constants
1007   * @{
1008   */
1009 /* Masks Definition */
1010 #define RTC_TAMPER_ENABLE_BITS_MASK         ((uint32_t) (RTC_TAMPER_1 | \
1011                                                          RTC_TAMPER_2 | \
1012                                                          RTC_TAMPER_3))
1013 
1014 #define RTC_TAMPER_FLAGS_MASK               ((uint32_t) (RTC_FLAG_TAMP1F | \
1015                                                          RTC_FLAG_TAMP2F | \
1016                                                          RTC_FLAG_TAMP3F))
1017 
1018 #define RTC_TAMPER_IT_ENABLE_BITS_MASK      ((uint32_t) (RTC_IT_TAMP1 | \
1019                                                          RTC_IT_TAMP2 | \
1020                                                          RTC_IT_TAMP3 | \
1021                                                          RTC_IT_TAMP))
1022 /**
1023   * @}
1024   */
1025 
1026 /* Private macros ------------------------------------------------------------*/
1027 
1028 /** @defgroup RTCEx_Private_Macros RTCEx Private Macros
1029   * @{
1030   */
1031 
1032 /** @defgroup RTCEx_IS_RTC_Definitions Private macros to check input parameters
1033   * @{
1034   */
1035 #define IS_RTC_BKP(BKP)     ((BKP) < (uint32_t) RTC_BKP_NUMBER)
1036 
1037 #define IS_TIMESTAMP_EDGE(EDGE) (((EDGE) == RTC_TIMESTAMPEDGE_RISING) || \
1038                                  ((EDGE) == RTC_TIMESTAMPEDGE_FALLING))
1039 
1040 #define IS_RTC_TAMPER(TAMPER) ((((TAMPER) & ((uint32_t)~RTC_TAMPER_ENABLE_BITS_MASK)) == 0x00U) && ((TAMPER) != 0U))
1041 
1042 #define IS_RTC_TAMPER_PIN(PIN) ((PIN) == RTC_TAMPERPIN_DEFAULT)
1043 
1044 #define IS_RTC_TIMESTAMP_PIN(PIN) (((PIN) == RTC_TIMESTAMPPIN_DEFAULT) || \
1045                                    ((PIN) == RTC_TIMESTAMPPIN_POS1)    || \
1046                                    ((PIN) == RTC_TIMESTAMPPIN_POS2))
1047 
1048 #define IS_RTC_TAMPER_INTERRUPT(INTERRUPT) ((((INTERRUPT) & ((uint32_t)~RTC_TAMPER_IT_ENABLE_BITS_MASK  )) == 0x00U) && ((INTERRUPT) != 0U))
1049 
1050 #define IS_RTC_TAMPER_TRIGGER(TRIGGER) (((TRIGGER) == RTC_TAMPERTRIGGER_RISINGEDGE)  || \
1051                                         ((TRIGGER) == RTC_TAMPERTRIGGER_FALLINGEDGE) || \
1052                                         ((TRIGGER) == RTC_TAMPERTRIGGER_LOWLEVEL)    || \
1053                                         ((TRIGGER) == RTC_TAMPERTRIGGER_HIGHLEVEL))
1054 
1055 #define IS_RTC_TAMPER_ERASE_MODE(MODE)          (((MODE) == RTC_TAMPER_ERASE_BACKUP_ENABLE) || \
1056                                                  ((MODE) == RTC_TAMPER_ERASE_BACKUP_DISABLE))
1057 
1058 #define IS_RTC_TAMPER_MASKFLAG_STATE(STATE)     (((STATE) == RTC_TAMPERMASK_FLAG_ENABLE) || \
1059                                                  ((STATE) == RTC_TAMPERMASK_FLAG_DISABLE))
1060 
1061 #define IS_RTC_TAMPER_FILTER(FILTER)  (((FILTER) == RTC_TAMPERFILTER_DISABLE) || \
1062                                        ((FILTER) == RTC_TAMPERFILTER_2SAMPLE) || \
1063                                        ((FILTER) == RTC_TAMPERFILTER_4SAMPLE) || \
1064                                        ((FILTER) == RTC_TAMPERFILTER_8SAMPLE))
1065 
1066 #define IS_RTC_TAMPER_FILTER_CONFIG_CORRECT(FILTER, TRIGGER)                  \
1067                         (  (  ((FILTER) != RTC_TAMPERFILTER_DISABLE)          \
1068                            && (  ((TRIGGER) == RTC_TAMPERTRIGGER_LOWLEVEL)    \
1069                               || ((TRIGGER) == RTC_TAMPERTRIGGER_HIGHLEVEL))) \
1070                         || (  ((FILTER) == RTC_TAMPERFILTER_DISABLE)          \
1071                            && (  ((TRIGGER) == RTC_TAMPERTRIGGER_RISINGEDGE)  \
1072                               || ((TRIGGER) == RTC_TAMPERTRIGGER_FALLINGEDGE))))
1073 
1074 #define IS_RTC_TAMPER_SAMPLING_FREQ(FREQ) (((FREQ) == RTC_TAMPERSAMPLINGFREQ_RTCCLK_DIV32768)|| \
1075                                            ((FREQ) == RTC_TAMPERSAMPLINGFREQ_RTCCLK_DIV16384)|| \
1076                                            ((FREQ) == RTC_TAMPERSAMPLINGFREQ_RTCCLK_DIV8192) || \
1077                                            ((FREQ) == RTC_TAMPERSAMPLINGFREQ_RTCCLK_DIV4096) || \
1078                                            ((FREQ) == RTC_TAMPERSAMPLINGFREQ_RTCCLK_DIV2048) || \
1079                                            ((FREQ) == RTC_TAMPERSAMPLINGFREQ_RTCCLK_DIV1024) || \
1080                                            ((FREQ) == RTC_TAMPERSAMPLINGFREQ_RTCCLK_DIV512)  || \
1081                                            ((FREQ) == RTC_TAMPERSAMPLINGFREQ_RTCCLK_DIV256))
1082 
1083 #define IS_RTC_TAMPER_PRECHARGE_DURATION(DURATION) (((DURATION) == RTC_TAMPERPRECHARGEDURATION_1RTCCLK) || \
1084                                                     ((DURATION) == RTC_TAMPERPRECHARGEDURATION_2RTCCLK) || \
1085                                                     ((DURATION) == RTC_TAMPERPRECHARGEDURATION_4RTCCLK) || \
1086                                                     ((DURATION) == RTC_TAMPERPRECHARGEDURATION_8RTCCLK))
1087 
1088 #define IS_RTC_TAMPER_PULLUP_STATE(STATE) (((STATE) == RTC_TAMPER_PULLUP_ENABLE) || \
1089                                            ((STATE) == RTC_TAMPER_PULLUP_DISABLE))
1090 
1091 #define IS_RTC_TAMPER_TIMESTAMPONTAMPER_DETECTION(DETECTION) (((DETECTION) == RTC_TIMESTAMPONTAMPERDETECTION_ENABLE) || \
1092                                                               ((DETECTION) == RTC_TIMESTAMPONTAMPERDETECTION_DISABLE))
1093 
1094 #define IS_RTC_WAKEUP_CLOCK(CLOCK) (((CLOCK) == RTC_WAKEUPCLOCK_RTCCLK_DIV16)   || \
1095                                     ((CLOCK) == RTC_WAKEUPCLOCK_RTCCLK_DIV8)    || \
1096                                     ((CLOCK) == RTC_WAKEUPCLOCK_RTCCLK_DIV4)    || \
1097                                     ((CLOCK) == RTC_WAKEUPCLOCK_RTCCLK_DIV2)    || \
1098                                     ((CLOCK) == RTC_WAKEUPCLOCK_CK_SPRE_16BITS) || \
1099                                     ((CLOCK) == RTC_WAKEUPCLOCK_CK_SPRE_17BITS))
1100 
1101 #define IS_RTC_WAKEUP_COUNTER(COUNTER)  ((COUNTER) <= RTC_WUTR_WUT)
1102 
1103 #define IS_RTC_SMOOTH_CALIB_PERIOD(PERIOD) (((PERIOD) == RTC_SMOOTHCALIB_PERIOD_32SEC) || \
1104                                             ((PERIOD) == RTC_SMOOTHCALIB_PERIOD_16SEC) || \
1105                                             ((PERIOD) == RTC_SMOOTHCALIB_PERIOD_8SEC))
1106 
1107 #define IS_RTC_SMOOTH_CALIB_PLUS(PLUS) (((PLUS) == RTC_SMOOTHCALIB_PLUSPULSES_SET) || \
1108                                         ((PLUS) == RTC_SMOOTHCALIB_PLUSPULSES_RESET))
1109 
1110 #define  IS_RTC_SMOOTH_CALIB_MINUS(VALUE) ((VALUE) <= RTC_CALR_CALM)
1111 
1112 #define IS_RTC_SHIFT_ADD1S(SEL) (((SEL) == RTC_SHIFTADD1S_RESET) || \
1113                                  ((SEL) == RTC_SHIFTADD1S_SET))
1114 
1115 #define IS_RTC_SHIFT_SUBFS(FS) ((FS) <= RTC_SHIFTR_SUBFS)
1116 
1117 #define IS_RTC_CALIB_OUTPUT(OUTPUT)  (((OUTPUT) == RTC_CALIBOUTPUT_512HZ) || \
1118                                       ((OUTPUT) == RTC_CALIBOUTPUT_1HZ))
1119 /**
1120   * @}
1121   */
1122 
1123 /**
1124   * @}
1125   */
1126 
1127 /**
1128   * @}
1129   */
1130 
1131 /**
1132   * @}
1133   */
1134 
1135 #ifdef __cplusplus
1136 }
1137 #endif
1138 
1139 #endif /* STM32F7xx_HAL_RTC_EX_H */
1140