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