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