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