1 /**
2   ******************************************************************************
3   * @file    stm32h7xx_hal_rtc_ex.h
4   * @author  MCD Application Team
5   * @brief   Header file of RTC HAL Extension module.
6   ******************************************************************************
7   * @attention
8   *
9   * Copyright (c) 2017 STMicroelectronics.
10   * All rights reserved.
11   *
12   * This software is licensed under terms that can be found in the LICENSE file
13   * in the root directory of this software component.
14   * If no LICENSE file comes with this software, it is provided AS-IS.
15   *
16   ******************************************************************************
17   */
18 
19 /* Define to prevent recursive inclusion -------------------------------------*/
20 #ifndef STM32H7xx_HAL_RTC_EX_H
21 #define STM32H7xx_HAL_RTC_EX_H
22 
23 #ifdef __cplusplus
24 extern "C" {
25 #endif /* __cplusplus */
26 
27 /* Includes ------------------------------------------------------------------*/
28 #include "stm32h7xx_hal_def.h"
29 
30 /** @addtogroup STM32H7xx_HAL_Driver
31   * @{
32   */
33 
34 /** @defgroup RTCEx RTCEx
35   * @{
36   */
37 
38 /* Exported types ------------------------------------------------------------*/
39 
40 /** @defgroup RTCEx_Exported_Types RTCEx Exported Types
41   * @{
42   */
43 
44 /** @defgroup RTCEx_Tamper_structure_definition RTC Tamper structure definition
45   * @{
46   */
47 typedef struct
48 {
49   uint32_t Tamper;                      /*!< Specifies the Tamper Pin.
50                                              This parameter can be a value of @ref RTCEx_Tamper_Pins_Definitions */
51 
52   uint32_t Interrupt;                   /*!< Specifies the Tamper Interrupt.
53                                              This parameter can be a value of @ref  RTCEx_Tamper_Interrupt_Definitions */
54 
55   uint32_t Trigger;                     /*!< Specifies the Tamper Trigger.
56                                              This parameter can be a value of @ref RTCEx_Tamper_Trigger_Definitions */
57 
58   uint32_t NoErase;                     /*!< Specifies the Tamper no erase mode.
59                                              This parameter can be a value of @ref RTCEx_Tamper_EraseBackUp_Definitions */
60 
61   uint32_t MaskFlag;                     /*!< Specifies the Tamper Flag masking.
62                                              This parameter can be a value of @ref RTCEx_Tamper_MaskFlag_Definitions   */
63 
64   uint32_t Filter;                      /*!< Specifies the TAMP Filter Tamper.
65                                              This parameter can be a value of @ref RTCEx_Tamper_Filter_Definitions */
66 
67   uint32_t SamplingFrequency;           /*!< Specifies the sampling frequency.
68                                              This parameter can be a value of @ref RTCEx_Tamper_Sampling_Frequencies_Definitions */
69 
70   uint32_t PrechargeDuration;           /*!< Specifies the Precharge Duration .
71                                              This parameter can be a value of @ref RTCEx_Tamper_Pin_Precharge_Duration_Definitions */
72 
73   uint32_t TamperPullUp;                /*!< Specifies the Tamper PullUp .
74                                              This parameter can be a value of @ref RTCEx_Tamper_Pull_UP_Definitions */
75 
76   uint32_t TimeStampOnTamperDetection;  /*!< Specifies the TimeStampOnTamperDetection.
77                                              This parameter can be a value of @ref RTCEx_Tamper_TimeStampOnTamperDetection_Definitions */
78 } RTC_TamperTypeDef;
79 /**
80   * @}
81   */
82 
83 #if defined(TAMP)
84 /** @defgroup RTCEx_Internal_Tamper_structure_definition RTCEx Internal Tamper structure definition
85   * @{
86   */
87 typedef struct
88 {
89   uint32_t IntTamper;                   /*!< Specifies the Internal Tamper Pin.
90                                              This parameter can be a value of @ref RTCEx_Internal_Tamper_Pins_Definitions */
91 
92   uint32_t TimeStampOnTamperDetection;  /*!< Specifies the TimeStampOnTamperDetection.
93                                              This parameter can be a value of @ref RTCEx_Tamper_TimeStampOnTamperDetection_Definitions */
94 } RTC_InternalTamperTypeDef;
95 /**
96   * @}
97   */
98 
99 /** @defgroup RTCEx_Active_Seed_Size Seed size Definitions
100   * @{
101   */
102 #define RTC_ATAMP_SEED_NB_UINT32        4U
103 /**
104   * @}
105   */
106 
107 /** @defgroup RTCEx_Active_Tampers_Number Active Tampers number Definitions
108   * @{
109   */
110 #define RTC_TAMP_NB                     3u
111 /**
112   * @}
113   */
114 
115 /** @defgroup RTCEx_ActiveTamper_structures_definition RTC Active Tamper structures definitions
116   * @{
117   */
118 typedef struct
119 {
120   uint32_t Enable;                      /*!< Specifies the Tamper input is active.
121                                              This parameter can be a value of @ref RTCEx_ActiveTamper_Enable */
122 
123   uint32_t Interrupt;                    /*!< Specifies the interrupt mode
124                                              This parameter can be a value of @ref RTCEx_ActiveTamper_Interrupt */
125 
126   uint32_t Output;                      /*!< Specifies the TAMP output to be compared with.
127                                              The same output can be used for several tamper inputs.
128                                              This parameter can be a value of @ref RTCEx_ActiveTamper_Sel */
129 
130   uint32_t NoErase;                     /*!< Specifies the Tamper no erase mode.
131                                              This parameter can be a value of @ref RTCEx_Tamper_EraseBackUp_Definitions */
132 
133   uint32_t MaskFlag;                    /*!< Specifies the Tamper Flag masking.
134                                              This parameter can be a value of @ref RTCEx_Tamper_MaskFlag_Definitions */
135 
136 } RTC_ATampInputTypeDef;
137 
138 
139 typedef struct
140 {
141   uint32_t ActiveFilter;                /*!< Specifies the Active tamper filter enable.
142                                              This parameter can be a value of @ref RTCEx_ActiveTamper_Filter */
143 
144   uint32_t ActiveAsyncPrescaler;        /*!< Specifies the Active Tamper asynchronous Prescaler clock.
145                                              This parameter can be a value of @ref RTCEx_ActiveTamper_Async_prescaler */
146 
147   uint32_t TimeStampOnTamperDetection;  /*!< Specifies the timeStamp on tamper detection.
148                                              This parameter can be a value of @ref RTCEx_Tamper_TimeStampOnTamperDetection_Definitions */
149 
150   uint32_t ActiveOutputChangePeriod;    /*!< Specifies the Active Tamper output change period .
151                                              This parameter can be a value from 0 to 7. */
152 
153   uint32_t Seed[RTC_ATAMP_SEED_NB_UINT32];
154   /*!< Specifies the Active Tamper RNG Seed value .
155        This parameter can be a value from 0 to (2^32-1) */
156 
157   RTC_ATampInputTypeDef TampInput[RTC_TAMP_NB];
158   /*!< Specifies configuration of all active tampers.
159        The index of TampInput[RTC_TAMP_NB] can be a value of RTCEx_ActiveTamper_Sel */
160 } RTC_ActiveTampersTypeDef;
161 
162 /**
163   * @}
164   */
165 #endif /* TAMP */
166 
167 /**
168   * @}
169   */
170 
171 /* Exported constants --------------------------------------------------------*/
172 
173 /** @defgroup RTCEx_Exported_Constants RTC Exported Constants
174   * @{
175   */
176 
177 /* ========================================================================== */
178 /*         ##### Extended RTC Backup registers exported constants #####       */
179 /* ========================================================================== */
180 
181 /** @defgroup RTCEx_Backup_Registers_Number_Definitions RTC Backup Registers Number Definitions
182   * @{
183   */
184 #if defined(TAMP)
185 #define BKP_REG_NUMBER                       TAMP_BKP_NUMBER
186 #else
187 #define BKP_REG_NUMBER                       RTC_BKP_NUMBER
188 #endif /* TAMP */
189 /**
190   * @}
191   */
192 
193 /** @defgroup RTCEx_Backup_Registers_Definitions RTC Backup Registers Definitions
194   * @{
195   */
196 #define RTC_BKP_DR0                       0x00u
197 #define RTC_BKP_DR1                       0x01u
198 #define RTC_BKP_DR2                       0x02u
199 #define RTC_BKP_DR3                       0x03u
200 #define RTC_BKP_DR4                       0x04u
201 #define RTC_BKP_DR5                       0x05u
202 #define RTC_BKP_DR6                       0x06u
203 #define RTC_BKP_DR7                       0x07u
204 #define RTC_BKP_DR8                       0x08u
205 #define RTC_BKP_DR9                       0x09u
206 #define RTC_BKP_DR10                      0x0Au
207 #define RTC_BKP_DR11                      0x0Bu
208 #define RTC_BKP_DR12                      0x0Cu
209 #define RTC_BKP_DR13                      0x0Du
210 #define RTC_BKP_DR14                      0x0Eu
211 #define RTC_BKP_DR15                      0x0Fu
212 #define RTC_BKP_DR16                      0x10u
213 #define RTC_BKP_DR17                      0x11u
214 #define RTC_BKP_DR18                      0x12u
215 #define RTC_BKP_DR19                      0x13u
216 #define RTC_BKP_DR20                      0x14u
217 #define RTC_BKP_DR21                      0x15u
218 #define RTC_BKP_DR22                      0x16u
219 #define RTC_BKP_DR23                      0x17u
220 #define RTC_BKP_DR24                      0x18u
221 #define RTC_BKP_DR25                      0x19u
222 #define RTC_BKP_DR26                      0x1Au
223 #define RTC_BKP_DR27                      0x1Bu
224 #define RTC_BKP_DR28                      0x1Cu
225 #define RTC_BKP_DR29                      0x1Du
226 #define RTC_BKP_DR30                      0x1Eu
227 #define RTC_BKP_DR31                      0x1Fu
228 /**
229   * @}
230   */
231 
232 /* ========================================================================== */
233 /*                 ##### RTC TimeStamp exported constants #####               */
234 /* ========================================================================== */
235 
236 /** @defgroup RTCEx_TimeStamp_Edges_definitions RTC TimeStamp Edges Definitions
237   *
238   * @{
239   */
240 #define RTC_TIMESTAMPEDGE_RISING            0x00000000u
241 #define RTC_TIMESTAMPEDGE_FALLING           RTC_CR_TSEDGE
242 /**
243   * @}
244   */
245 
246 /** @defgroup RTCEx_TimeStamp_Pin_Selection RTC TimeStamp Pin Selection
247   * @{
248   */
249 #define RTC_TIMESTAMPPIN_DEFAULT              0x00000000u
250 /**
251   * @}
252   */
253 
254 
255 /* ========================================================================== */
256 /*                    ##### RTC Tamper exported constants #####               */
257 /* ========================================================================== */
258 
259 /** @defgroup RTCEx_Tamper_Pins_Definitions RTC Tamper Pins Definitions
260   * @{
261   */
262 #if defined(TAMP)
263 #define RTC_TAMPER_1                       TAMP_CR1_TAMP1E
264 #define RTC_TAMPER_2                       TAMP_CR1_TAMP2E
265 #define RTC_TAMPER_3                       TAMP_CR1_TAMP3E
266 #else
267 #define RTC_TAMPER_1                       RTC_TAMPCR_TAMP1E
268 #define RTC_TAMPER_2                       RTC_TAMPCR_TAMP2E
269 #define RTC_TAMPER_3                       RTC_TAMPCR_TAMP3E
270 #endif /* TAMP */
271 
272 #define RTC_TAMPER_ALL                     (RTC_TAMPER_1 | RTC_TAMPER_2 | RTC_TAMPER_3)
273 /**
274   * @}
275   */
276 
277 /** @defgroup RTCEx_Tamper_Interrupt_Definitions RTC Tamper Interrupts Definitions
278   * @{
279   */
280 #if defined(TAMP)
281 #define RTC_IT_TAMP1                      TAMP_IER_TAMP1IE    /*!< Enable Tamper 1 Interrupt                */
282 #define RTC_IT_TAMP2                      TAMP_IER_TAMP2IE    /*!< Enable Tamper 2 Interrupt                */
283 #define RTC_IT_TAMP3                      TAMP_IER_TAMP3IE    /*!< Enable Tamper 3 Interrupt                */
284 #else
285 #define RTC_IT_TAMP1                      RTC_TAMPCR_TAMP1IE  /*!< Enable Tamper 1 Interrupt                */
286 #define RTC_IT_TAMP2                      RTC_TAMPCR_TAMP2IE  /*!< Enable Tamper 2 Interrupt                */
287 #define RTC_IT_TAMP3                      RTC_TAMPCR_TAMP3IE  /*!< Enable Tamper 3 Interrupt                */
288 #endif /* TAMP */
289 
290 #if defined(TAMP)
291 #define RTC_IT_TAMP                       0x00000000u         /*!< No such feature in RTC3                   */
292 #define RTC_IT_TAMPALL                    (RTC_IT_TAMP1 | RTC_IT_TAMP2 | RTC_IT_TAMP3)
293 #else
294 #define RTC_IT_TAMP                       RTC_TAMPCR_TAMPIE   /*!< Enable all Tamper Interrupts              */
295 #define RTC_IT_TAMPALL                    RTC_IT_TAMP
296 #endif /* TAMP */
297 /**
298   * @}
299   */
300 
301 /** @defgroup RTCEx_Internal_Tamper_Pins_Definitions  RTCEx Internal Tamper Pins Definition
302   * @{
303   */
304 #if defined(TAMP)
305 #define RTC_INT_TAMPER_1                    TAMP_CR1_ITAMP1E
306 #define RTC_INT_TAMPER_2                    TAMP_CR1_ITAMP2E
307 #define RTC_INT_TAMPER_3                    TAMP_CR1_ITAMP3E
308 #define RTC_INT_TAMPER_4                    TAMP_CR1_ITAMP4E
309 #define RTC_INT_TAMPER_5                    TAMP_CR1_ITAMP5E
310 #define RTC_INT_TAMPER_6                    TAMP_CR1_ITAMP6E
311 #define RTC_INT_TAMPER_8                    TAMP_CR1_ITAMP8E
312 
313 #define RTC_INT_TAMPER_ALL                  (RTC_INT_TAMPER_1 | RTC_INT_TAMPER_2 |\
314                                              RTC_INT_TAMPER_3 | RTC_INT_TAMPER_4 |\
315                                              RTC_INT_TAMPER_5 | RTC_INT_TAMPER_6 |\
316                                              RTC_INT_TAMPER_8)
317 #endif /* TAMP */
318 /**
319   * @}
320   */
321 
322 /** @defgroup RTCEx_Internal_Tamper_Interrupt_Definitions  RTC Internal Tamper Interrupt
323   * @{
324   */
325 #if defined(TAMP)
326 #define RTC_INTERNAL_TAMPER1_INTERRUPT     TAMP_IER_ITAMP1IE  /*!< Enable Internal Tamper 1 Interrupt   */
327 #define RTC_INTERNAL_TAMPER2_INTERRUPT     TAMP_IER_ITAMP2IE  /*!< Enable Internal Tamper 2 Interrupt   */
328 #define RTC_INTERNAL_TAMPER3_INTERRUPT     TAMP_IER_ITAMP3IE  /*!< Enable Internal Tamper 3 Interrupt   */
329 #define RTC_INTERNAL_TAMPER4_INTERRUPT     TAMP_IER_ITAMP4IE  /*!< Enable Internal Tamper 4 Interrupt   */
330 #define RTC_INTERNAL_TAMPER5_INTERRUPT     TAMP_IER_ITAMP5IE  /*!< Enable Internal Tamper 5 Interrupt   */
331 #define RTC_INTERNAL_TAMPER6_INTERRUPT     TAMP_IER_ITAMP6IE  /*!< Enable Internal Tamper 6 Interrupt   */
332 #define RTC_INTERNAL_TAMPER8_INTERRUPT     TAMP_IER_ITAMP8IE  /*!< Enable Internal Tamper 8 Interrupt   */
333 #endif /* TAMP */
334 /**
335   * @}
336   */
337 
338 /** @defgroup RTCEx_Tamper_Trigger_Definitions RTC Tamper Triggers Definitions
339   * @{
340   */
341 #define RTC_TAMPERTRIGGER_RISINGEDGE        0x01u  /*!< Warning : Filter must be RTC_TAMPERFILTER_DISABLE     */
342 #define RTC_TAMPERTRIGGER_FALLINGEDGE       0x02u  /*!< Warning : Filter must be RTC_TAMPERFILTER_DISABLE     */
343 #define RTC_TAMPERTRIGGER_LOWLEVEL          0x04u  /*!< Warning : Filter must not be RTC_TAMPERFILTER_DISABLE */
344 #define RTC_TAMPERTRIGGER_HIGHLEVEL         0x08u  /*!< Warning : Filter must not be RTC_TAMPERFILTER_DISABLE */
345 
346 #if defined(TAMP)
347 #define RTC_TAMPER_1_TRIGGER                TAMP_CR2_TAMP1TRG
348 #define RTC_TAMPER_2_TRIGGER                TAMP_CR2_TAMP2TRG
349 #define RTC_TAMPER_3_TRIGGER                TAMP_CR2_TAMP3TRG
350 #else
351 #define RTC_TAMPER_1_TRIGGER                RTC_TAMPCR_TAMP1TRG
352 #define RTC_TAMPER_2_TRIGGER                RTC_TAMPCR_TAMP2TRG
353 #define RTC_TAMPER_3_TRIGGER                RTC_TAMPCR_TAMP3TRG
354 #endif /* TAMP */
355 
356 #define RTC_TAMPER_X_TRIGGER                (RTC_TAMPER_1_TRIGGER |\
357                                              RTC_TAMPER_2_TRIGGER |\
358                                              RTC_TAMPER_3_TRIGGER)
359 /**
360   * @}
361   */
362 
363 /** @defgroup RTCEx_Tamper_EraseBackUp_Definitions RTC Tamper EraseBackUp Definitions
364 * @{
365 */
366 #if defined(TAMP)
367 #define RTC_TAMPER_ERASE_BACKUP_ENABLE     0x00u
368 #define RTC_TAMPER_ERASE_BACKUP_DISABLE    0x01u
369 #else
370 #define RTC_TAMPER_ERASE_BACKUP_ENABLE     0x00000000u
371 #define RTC_TAMPER_ERASE_BACKUP_DISABLE    RTC_TAMPCR_TAMP1NOERASE
372 #endif /* TAMP */
373 
374 #if defined(TAMP)
375 #define RTC_DISABLE_BKP_ERASE_ON_TAMPER_1  TAMP_CR2_TAMP1NOERASE
376 #define RTC_DISABLE_BKP_ERASE_ON_TAMPER_2  TAMP_CR2_TAMP2NOERASE
377 #define RTC_DISABLE_BKP_ERASE_ON_TAMPER_3  TAMP_CR2_TAMP3NOERASE
378 #else
379 #define RTC_DISABLE_BKP_ERASE_ON_TAMPER_1  RTC_TAMPCR_TAMP1NOERASE
380 #define RTC_DISABLE_BKP_ERASE_ON_TAMPER_2  RTC_TAMPCR_TAMP2NOERASE
381 #define RTC_DISABLE_BKP_ERASE_ON_TAMPER_3  RTC_TAMPCR_TAMP3NOERASE
382 #endif /* TAMP */
383 
384 #define RTC_DISABLE_BKP_ERASE_ON_TAMPER_MASK (RTC_DISABLE_BKP_ERASE_ON_TAMPER_1 |\
385                                               RTC_DISABLE_BKP_ERASE_ON_TAMPER_2 |\
386                                               RTC_DISABLE_BKP_ERASE_ON_TAMPER_3)
387 /**
388   * @}
389   */
390 
391 /** @defgroup RTCEx_Tamper_MaskFlag_Definitions RTC Tamper Mask Flag Definitions
392 * @{
393 */
394 #if defined(TAMP)
395 #define RTC_TAMPERMASK_FLAG_DISABLE        0x00u
396 #define RTC_TAMPERMASK_FLAG_ENABLE         0x01u
397 #else
398 #define RTC_TAMPERMASK_FLAG_DISABLE        0x00000000u
399 #define RTC_TAMPERMASK_FLAG_ENABLE         RTC_TAMPCR_TAMP1MF
400 #endif /* TAMP */
401 
402 #if defined(TAMP)
403 #define RTC_TAMPER_1_MASK_FLAG             TAMP_CR2_TAMP1MSK
404 #define RTC_TAMPER_2_MASK_FLAG             TAMP_CR2_TAMP2MSK
405 #define RTC_TAMPER_3_MASK_FLAG             TAMP_CR2_TAMP3MSK
406 #else
407 #define RTC_TAMPER_1_MASK_FLAG             RTC_TAMPCR_TAMP1MF
408 #define RTC_TAMPER_2_MASK_FLAG             RTC_TAMPCR_TAMP2MF
409 #define RTC_TAMPER_3_MASK_FLAG             RTC_TAMPCR_TAMP3MF
410 #endif /* TAMP */
411 
412 #define RTC_TAMPER_X_MASK_FLAG             (RTC_TAMPER_1_MASK_FLAG |\
413                                             RTC_TAMPER_2_MASK_FLAG |\
414                                             RTC_TAMPER_3_MASK_FLAG)
415 /**
416   * @}
417   */
418 
419 /** @defgroup RTCEx_Tamper_Filter_Definitions RTC Tamper Filter Definitions
420   * @{
421   */
422 #if defined(TAMP)
423 #define RTC_TAMPERFILTER_DISABLE   0x00000000U             /*!< Tamper filter is disabled */
424 
425 #define RTC_TAMPERFILTER_2SAMPLE   TAMP_FLTCR_TAMPFLT_0    /*!< Tamper is activated after 2
426                                                                  consecutive samples at the active level */
427 #define RTC_TAMPERFILTER_4SAMPLE   TAMP_FLTCR_TAMPFLT_1    /*!< Tamper is activated after 4
428                                                                  consecutive samples at the active level */
429 #define RTC_TAMPERFILTER_8SAMPLE   TAMP_FLTCR_TAMPFLT      /*!< Tamper is activated after 8
430                                                                  consecutive samples at the active level */
431 #define RTC_TAMPERFILTER_MASK      TAMP_FLTCR_TAMPFLT      /*!< Masking all bits except those of
432                                                                  field TAMPFLT[1:0]. */
433 #else
434 #define RTC_TAMPERFILTER_DISABLE   0x00000000u             /*!< Tamper filter is disabled */
435 
436 #define RTC_TAMPERFILTER_2SAMPLE   RTC_TAMPCR_TAMPFLT_0    /*!< Tamper is activated after 2
437                                                                  consecutive samples at the active level */
438 #define RTC_TAMPERFILTER_4SAMPLE   RTC_TAMPCR_TAMPFLT_1    /*!< Tamper is activated after 4
439                                                                  consecutive samples at the active level */
440 #define RTC_TAMPERFILTER_8SAMPLE   RTC_TAMPCR_TAMPFLT      /*!< Tamper is activated after 8
441                                                                  consecutive samples at the active level. */
442 #define RTC_TAMPERFILTER_MASK      RTC_TAMPCR_TAMPFLT      /*!< Masking all bits except those of
443                                                                  field TAMPFLT[1:0]. */
444 #endif /* TAMP */
445 /**
446   * @}
447   */
448 
449 /** @defgroup RTCEx_Tamper_Sampling_Frequencies_Definitions RTC Tamper Sampling Frequencies Definitions
450   * @{
451   */
452 #if defined(TAMP)
453 #define RTC_TAMPERSAMPLINGFREQ_RTCCLK_DIV32768  0x00000000U                                     /*!< Each of the tamper inputs are sampled
454                                                                                                       with a frequency =  RTCCLK / 32768 */
455 #define RTC_TAMPERSAMPLINGFREQ_RTCCLK_DIV16384  TAMP_FLTCR_TAMPFREQ_0                           /*!< Each of the tamper inputs are sampled
456                                                                                                       with a frequency =  RTCCLK / 16384 */
457 #define RTC_TAMPERSAMPLINGFREQ_RTCCLK_DIV8192   TAMP_FLTCR_TAMPFREQ_1                           /*!< Each of the tamper inputs are sampled
458                                                                                                       with a frequency =  RTCCLK / 8192  */
459 #define RTC_TAMPERSAMPLINGFREQ_RTCCLK_DIV4096   (TAMP_FLTCR_TAMPFREQ_0 | TAMP_FLTCR_TAMPFREQ_1) /*!< Each of the tamper inputs are sampled
460                                                                                                       with a frequency =  RTCCLK / 4096  */
461 #define RTC_TAMPERSAMPLINGFREQ_RTCCLK_DIV2048   TAMP_FLTCR_TAMPFREQ_2                           /*!< Each of the tamper inputs are sampled
462                                                                                                       with a frequency =  RTCCLK / 2048  */
463 #define RTC_TAMPERSAMPLINGFREQ_RTCCLK_DIV1024   (TAMP_FLTCR_TAMPFREQ_0 | TAMP_FLTCR_TAMPFREQ_2) /*!< Each of the tamper inputs are sampled
464                                                                                                       with a frequency =  RTCCLK / 1024  */
465 #define RTC_TAMPERSAMPLINGFREQ_RTCCLK_DIV512    (TAMP_FLTCR_TAMPFREQ_1 | TAMP_FLTCR_TAMPFREQ_2) /*!< Each of the tamper inputs are sampled
466                                                                                                       with a frequency =  RTCCLK / 512   */
467 #define RTC_TAMPERSAMPLINGFREQ_RTCCLK_DIV256    TAMP_FLTCR_TAMPFREQ                             /*!< Each of the tamper inputs are sampled
468                                                                                                       with a frequency =  RTCCLK / 256   */
469 #define RTC_TAMPERSAMPLINGFREQ_RTCCLK_MASK      TAMP_FLTCR_TAMPFREQ                             /*!< Masking all bits except those of
470                                                                                                       field TAMPFREQ[2:0]*/
471 #else
472 #define RTC_TAMPERSAMPLINGFREQ_RTCCLK_DIV32768  0x00000000u                                     /*!< Each of the tamper inputs are sampled
473                                                                                                       with a frequency =  RTCCLK / 32768 */
474 #define RTC_TAMPERSAMPLINGFREQ_RTCCLK_DIV16384  RTC_TAMPCR_TAMPFREQ_0                           /*!< Each of the tamper inputs are sampled
475                                                                                                       with a frequency =  RTCCLK / 16384 */
476 #define RTC_TAMPERSAMPLINGFREQ_RTCCLK_DIV8192   RTC_TAMPCR_TAMPFREQ_1                           /*!< Each of the tamper inputs are sampled
477                                                                                                       with a frequency =  RTCCLK / 8192  */
478 #define RTC_TAMPERSAMPLINGFREQ_RTCCLK_DIV4096   (RTC_TAMPCR_TAMPFREQ_0 | RTC_TAMPCR_TAMPFREQ_1) /*!< Each of the tamper inputs are sampled
479                                                                                                       with a frequency =  RTCCLK / 4096  */
480 #define RTC_TAMPERSAMPLINGFREQ_RTCCLK_DIV2048   RTC_TAMPCR_TAMPFREQ_2                           /*!< Each of the tamper inputs are sampled
481                                                                                                       with a frequency =  RTCCLK / 2048  */
482 #define RTC_TAMPERSAMPLINGFREQ_RTCCLK_DIV1024   (RTC_TAMPCR_TAMPFREQ_0 | RTC_TAMPCR_TAMPFREQ_2)  /*!< Each of the tamper inputs are sampled
483                                                                                                       with a frequency =  RTCCLK / 1024  */
484 #define RTC_TAMPERSAMPLINGFREQ_RTCCLK_DIV512    (RTC_TAMPCR_TAMPFREQ_1 | RTC_TAMPCR_TAMPFREQ_2)  /*!< Each of the tamper inputs are sampled
485                                                                                                       with a frequency =  RTCCLK / 512   */
486 #define RTC_TAMPERSAMPLINGFREQ_RTCCLK_DIV256    RTC_TAMPCR_TAMPFREQ                              /*!< Each of the tamper inputs are sampled
487                                                                                                       with a frequency =  RTCCLK / 256   */
488 #define RTC_TAMPERSAMPLINGFREQ_RTCCLK_MASK      RTC_TAMPCR_TAMPFREQ                             /*!< Masking all bits except those of
489                                                                                                       field TAMPFREQ[2:0]*/
490 #endif /* TAMP */
491 /**
492   * @}
493   */
494 
495 /** @defgroup RTCEx_Tamper_Pin_Precharge_Duration_Definitions RTC Tamper Pin Precharge Duration Definitions
496   * @{
497   */
498 #if defined(TAMP)
499 #define RTC_TAMPERPRECHARGEDURATION_1RTCCLK     0x00000000U             /*!< Tamper pins are pre-charged before
500                                                                               sampling during 1 RTCCLK cycle  */
501 #define RTC_TAMPERPRECHARGEDURATION_2RTCCLK     TAMP_FLTCR_TAMPPRCH_0   /*!< Tamper pins are pre-charged before
502                                                                               sampling during 2 RTCCLK cycles */
503 #define RTC_TAMPERPRECHARGEDURATION_4RTCCLK     TAMP_FLTCR_TAMPPRCH_1   /*!< Tamper pins are pre-charged before
504                                                                               sampling during 4 RTCCLK cycles */
505 #define RTC_TAMPERPRECHARGEDURATION_8RTCCLK     TAMP_FLTCR_TAMPPRCH     /*!< Tamper pins are pre-charged before
506                                                                               sampling during 8 RTCCLK cycles */
507 #define RTC_TAMPERPRECHARGEDURATION_MASK        TAMP_FLTCR_TAMPPRCH     /*!< Masking all bits except those of
508                                                                               field TAMPPRCH[1:0] */
509 #else
510 #define RTC_TAMPERPRECHARGEDURATION_1RTCCLK     0x00000000u             /*!< Tamper pins are pre-charged before
511                                                                               sampling during 1 RTCCLK cycle  */
512 #define RTC_TAMPERPRECHARGEDURATION_2RTCCLK     RTC_TAMPCR_TAMPPRCH_0   /*!< Tamper pins are pre-charged before
513                                                                               sampling during 2 RTCCLK cycles */
514 #define RTC_TAMPERPRECHARGEDURATION_4RTCCLK     RTC_TAMPCR_TAMPPRCH_1   /*!< Tamper pins are pre-charged before
515                                                                               sampling during 4 RTCCLK cycles */
516 #define RTC_TAMPERPRECHARGEDURATION_8RTCCLK     RTC_TAMPCR_TAMPPRCH     /*!< Tamper pins are pre-charged before
517                                                                               sampling during 8 RTCCLK cycles */
518 #define RTC_TAMPERPRECHARGEDURATION_MASK        RTC_TAMPCR_TAMPPRCH     /*!< Masking all bits except those of
519                                                                               field TAMPPRCH[1:0] */
520 #endif /* TAMP */
521 /**
522   * @}
523   */
524 
525 /** @defgroup RTCEx_Tamper_TimeStampOnTamperDetection_Definitions RTC Tamper TimeStamp On Tamper Detection Definitions
526   * @{
527   */
528 #if defined(TAMP)
529 #define RTC_TIMESTAMPONTAMPERDETECTION_DISABLE  0x00000000u                   /*!< TimeStamp on Tamper Detection event is not saved */
530 #define RTC_TIMESTAMPONTAMPERDETECTION_ENABLE   RTC_CR_TAMPTS                 /*!< TimeStamp on Tamper Detection event saved        */
531 #define RTC_TIMESTAMPONTAMPERDETECTION_MASK     RTC_CR_TAMPTS                 /*!< Masking all bits except bit TAMPTS               */
532 #else
533 #define RTC_TIMESTAMPONTAMPERDETECTION_DISABLE  0x00000000u                   /*!< TimeStamp on Tamper Detection event is not saved */
534 #define RTC_TIMESTAMPONTAMPERDETECTION_ENABLE   RTC_TAMPCR_TAMPTS             /*!< TimeStamp on Tamper Detection event saved        */
535 #define RTC_TIMESTAMPONTAMPERDETECTION_MASK     RTC_TAMPCR_TAMPTS             /*!< Masking all bits except bit TAMPTS               */
536 #endif /* TAMP */
537 /**
538   * @}
539   */
540 
541 /** @defgroup RTCEx_Tamper_Pull_UP_Definitions RTC Tamper Pull Up Definitions
542   * @{
543   */
544 #if defined(TAMP)
545 #define RTC_TAMPER_PULLUP_ENABLE           0x00000000u              /*!< Tamper pins are pre-charged before sampling */
546 #define RTC_TAMPER_PULLUP_DISABLE          TAMP_FLTCR_TAMPPUDIS     /*!< Tamper pins pre-charge is disabled          */
547 #define RTC_TAMPER_PULLUP_MASK             TAMP_FLTCR_TAMPPUDIS     /*!< Maskin all bits except bit TAMPPUDIS        */
548 #else
549 #define RTC_TAMPER_PULLUP_ENABLE           0x00000000u              /*!< TimeStamp on Tamper Detection event saved        */
550 #define RTC_TAMPER_PULLUP_DISABLE          RTC_TAMPCR_TAMPPUDIS     /*!< TimeStamp on Tamper Detection event is not saved */
551 #define RTC_TAMPER_PULLUP_MASK             RTC_TAMPCR_TAMPPUDIS     /*!< Maskin all bits except bit TAMPPUDIS        */
552 #endif /* TAMP */
553 /**
554   * @}
555   */
556 
557 /** @defgroup RTCEx_Tamper_DetectionOutput_Definitions RTC Tamper Detection Output Definitions
558   * @{
559   */
560 #if defined(TAMP)
561 #define RTC_TAMPERDETECTIONOUTPUT_DISABLE  0x00000000u                   /*!< The tamper flag is not routed on TAMPALRM */
562 #define RTC_TAMPERDETECTIONOUTPUT_ENABLE   RTC_CR_TAMPOE                 /*!< The tamper flag is routed on TAMPALRM combined with the signal
563                                                                                provided by OSEL and with the polarity provided by POL */
564 #endif  /* TAMP */
565 /**
566   * @}
567   */
568 
569 /** @defgroup RTC_Tamper_Flags_Definitions RTC Tamper Flags Definitions
570   * @{
571   */
572 #if defined(TAMP)
573 #define RTC_FLAG_TAMP1F                   TAMP_SR_TAMP1F
574 #define RTC_FLAG_TAMP2F                   TAMP_SR_TAMP2F
575 #define RTC_FLAG_TAMP3F                   TAMP_SR_TAMP3F
576 #else
577 #define RTC_FLAG_TAMP1F                   RTC_ISR_TAMP1F
578 #define RTC_FLAG_TAMP2F                   RTC_ISR_TAMP2F
579 #define RTC_FLAG_TAMP3F                   RTC_ISR_TAMP3F
580 #endif /* TAMP */
581 /**
582   * @}
583   */
584 
585 /** @defgroup RTCEx_ActiveTamper_Enable RTCEx_ActiveTamper_Enable Definitions
586   * @{
587   */
588 #define RTC_ATAMP_ENABLE                   1u
589 #define RTC_ATAMP_DISABLE                  0u
590 /**
591   * @}
592   */
593 
594 /** @defgroup RTCEx_ActiveTamper_Interrupt RTCEx_ActiveTamper_Interrupt Definitions
595   * @{
596   */
597 #define RTC_ATAMP_INTERRUPT_ENABLE        1u
598 #define RTC_ATAMP_INTERRUPT_DISABLE       0u
599 /**
600   * @}
601   */
602 
603 /** @defgroup RTCEx_ActiveTamper_Filter RTCEx_ActiveTamper_Filter Definitions
604   * @{
605   */
606 #define RTC_ATAMP_FILTER_ENABLE           TAMP_ATCR1_FLTEN
607 #define RTC_ATAMP_FILTER_DISABLE          0u
608 /**
609   * @}
610   */
611 
612 /** @defgroup RTCEx_ActiveTamper_Async_prescaler RTC Active_Tamper_Asynchronous_Prescaler clock Definitions
613   * @{
614   */
615 #define RTC_ATAMP_ASYNCPRES_RTCCLK        0u                                                                      /*!< RTCCLK */
616 #define RTC_ATAMP_ASYNCPRES_RTCCLK_2      TAMP_ATCR1_ATCKSEL_0                                                    /*!< RTCCLK/2 */
617 #define RTC_ATAMP_ASYNCPRES_RTCCLK_4      TAMP_ATCR1_ATCKSEL_1                                                    /*!< RTCCLK/4 */
618 #define RTC_ATAMP_ASYNCPRES_RTCCLK_8     (TAMP_ATCR1_ATCKSEL_1 | TAMP_ATCR1_ATCKSEL_0)                            /*!< RTCCLK/8 */
619 #define RTC_ATAMP_ASYNCPRES_RTCCLK_16     TAMP_ATCR1_ATCKSEL_2                                                    /*!< RTCCLK/16 */
620 #define RTC_ATAMP_ASYNCPRES_RTCCLK_32    (TAMP_ATCR1_ATCKSEL_2 | TAMP_ATCR1_ATCKSEL_0)                            /*!< RTCCLK/32 */
621 #define RTC_ATAMP_ASYNCPRES_RTCCLK_64    (TAMP_ATCR1_ATCKSEL_2 | TAMP_ATCR1_ATCKSEL_1)                            /*!< RTCCLK/64 */
622 #define RTC_ATAMP_ASYNCPRES_RTCCLK_128   (TAMP_ATCR1_ATCKSEL_2 | TAMP_ATCR1_ATCKSEL_1 | TAMP_ATCR1_ATCKSEL_0)     /*!< RTCCLK/128 */
623 /**
624   * @}
625   */
626 
627 /** @defgroup RTCEx_ActiveTamper_Sel  RTC Active Tamper selection Definition
628   * @{
629   */
630 #define RTC_ATAMP_1                       0u   /*!< Tamper 1 */
631 #define RTC_ATAMP_2                       1u   /*!< Tamper 2 */
632 #define RTC_ATAMP_3                       2u   /*!< Tamper 3 */
633 #define RTC_ATAMP_4                       3u   /*!< Tamper 4 */
634 #define RTC_ATAMP_5                       4u   /*!< Tamper 5 */
635 #define RTC_ATAMP_6                       5u   /*!< Tamper 6 */
636 #define RTC_ATAMP_7                       6u   /*!< Tamper 7 */
637 #define RTC_ATAMP_8                       7u   /*!< Tamper 8 */
638 /**
639   * @}
640   */
641 
642 /** @defgroup RTCEx_MonotonicCounter_Instance  RTCEx Monotonic Counter Instance Definition
643   * @{
644   */
645 #define RTC_MONOTONIC_COUNTER_1           0u   /*!< Monotonic counter 1 */
646 /**
647   * @}
648   */
649 
650 /** @defgroup RTCEx_Tamper_Registers_Offset  RTC Tamper Registers Offset
651   * @{
652   */
653 #if defined(TAMP)
654 /* Add this offset to RTC registers base address to reach TAMP registers base address. */
655 #define TAMP_OFFSET (TAMP_BASE - RTC_BASE)
656 #endif /* TAMP */
657 /**
658   * @}
659   */
660 
661 /* ========================================================================== */
662 /*                   ##### RTC Wake-up exported constants #####               */
663 /* ========================================================================== */
664 
665 /** @defgroup RTCEx_Wakeup_Timer_Definitions RTC Wakeup Timer Definitions
666   * @{
667   */
668 #define RTC_WAKEUPCLOCK_RTCCLK_DIV16        0x00000000u
669 #define RTC_WAKEUPCLOCK_RTCCLK_DIV8         RTC_CR_WUCKSEL_0
670 #define RTC_WAKEUPCLOCK_RTCCLK_DIV4         RTC_CR_WUCKSEL_1
671 #define RTC_WAKEUPCLOCK_RTCCLK_DIV2         (RTC_CR_WUCKSEL_0 | RTC_CR_WUCKSEL_1)
672 #define RTC_WAKEUPCLOCK_CK_SPRE_16BITS      RTC_CR_WUCKSEL_2
673 #define RTC_WAKEUPCLOCK_CK_SPRE_17BITS      (RTC_CR_WUCKSEL_1 | RTC_CR_WUCKSEL_2)
674 /**
675   * @}
676   */
677 
678 /* ========================================================================== */
679 /*        ##### Extended RTC Peripheral Control exported constants #####      */
680 /* ========================================================================== */
681 
682 /** @defgroup RTCEx_Smooth_calib_period_Definitions RTC Smooth Calib Period Definitions
683   * @{
684   */
685 #define RTC_SMOOTHCALIB_PERIOD_32SEC   0x00000000u             /*!< If RTCCLK = 32768 Hz, Smooth calibration
686                                                                     period is 32s,  else 2exp20 RTCCLK pulses */
687 #define RTC_SMOOTHCALIB_PERIOD_16SEC   RTC_CALR_CALW16         /*!< If RTCCLK = 32768 Hz, Smooth calibration
688                                                                     period is 16s, else 2exp19 RTCCLK pulses */
689 #define RTC_SMOOTHCALIB_PERIOD_8SEC    RTC_CALR_CALW8          /*!< If RTCCLK = 32768 Hz, Smooth calibration
690                                                                     period is 8s, else 2exp18 RTCCLK pulses */
691 /**
692   * @}
693   */
694 
695 /** @defgroup RTCEx_Smooth_calib_Plus_pulses_Definitions RTC Smooth Calib Plus pulses Definitions
696   * @{
697   */
698 #define RTC_SMOOTHCALIB_PLUSPULSES_SET    RTC_CALR_CALP           /*!< The number of RTCCLK pulses added
699                                                                        during a X -second window = Y - CALM[8:0]
700                                                                        with Y = 512, 256, 128 when X = 32, 16, 8 */
701 #define RTC_SMOOTHCALIB_PLUSPULSES_RESET  0x00000000u             /*!< The number of RTCCLK pulses subbstited
702                                                                        during a 32-second window = CALM[8:0] */
703 /**
704   * @}
705   */
706 
707 /** @defgroup RTCEx_Calib_Output_selection_Definitions RTC Calib Output Selection Definitions
708   * @{
709   */
710 #define RTC_CALIBOUTPUT_512HZ            0x00000000u
711 #define RTC_CALIBOUTPUT_1HZ              RTC_CR_COSEL
712 /**
713   * @}
714   */
715 
716 /** @defgroup RTCEx_Add_1_Second_Parameter_Definitions RTC Add 1 Second Parameter Definitions
717   * @{
718   */
719 #define RTC_SHIFTADD1S_RESET      0x00000000u
720 #define RTC_SHIFTADD1S_SET        RTC_SHIFTR_ADD1S
721 /**
722   * @}
723   */
724 
725 /**
726   * @}
727   */
728 
729 /* Exported macros -----------------------------------------------------------*/
730 
731 /** @defgroup RTCEx_Exported_Macros RTC Exported Macros
732   * @{
733   */
734 
735 /* ========================================================================== */
736 /*                    ##### RTC Wake-up exported macros #####                 */
737 /* ========================================================================== */
738 
739 /**
740   * @brief  Enable the RTC WakeUp Timer peripheral.
741   * @param  __HANDLE__ specifies the RTC handle.
742   * @retval None
743   */
744 #define __HAL_RTC_WAKEUPTIMER_ENABLE(__HANDLE__)                     ((__HANDLE__)->Instance->CR |= (RTC_CR_WUTE))
745 
746 /**
747   * @brief  Disable the RTC WakeUp Timer peripheral.
748   * @param  __HANDLE__ specifies the RTC handle.
749   * @retval None
750   */
751 #define __HAL_RTC_WAKEUPTIMER_DISABLE(__HANDLE__)                    ((__HANDLE__)->Instance->CR &= ~(RTC_CR_WUTE))
752 
753 /**
754   * @brief  Enable the RTC WakeUpTimer interrupt.
755   * @param  __HANDLE__ specifies the RTC handle.
756   * @param  __INTERRUPT__ specifies the RTC WakeUpTimer interrupt sources to be enabled.
757   *         This parameter can be:
758   *            @arg @ref RTC_IT_WUT WakeUpTimer interrupt
759   * @retval None
760   */
761 #define __HAL_RTC_WAKEUPTIMER_ENABLE_IT(__HANDLE__, __INTERRUPT__)    ((__HANDLE__)->Instance->CR |= (__INTERRUPT__))
762 
763 /**
764   * @brief  Disable the RTC WakeUpTimer interrupt.
765   * @param  __HANDLE__ specifies the RTC handle.
766   * @param  __INTERRUPT__ specifies the RTC WakeUpTimer interrupt sources to be disabled.
767   *         This parameter can be:
768   *            @arg @ref RTC_IT_WUT WakeUpTimer interrupt
769   * @retval None
770   */
771 #define __HAL_RTC_WAKEUPTIMER_DISABLE_IT(__HANDLE__, __INTERRUPT__)   ((__HANDLE__)->Instance->CR &= ~(__INTERRUPT__))
772 
773 /**
774   * @brief  Check whether the specified RTC WakeUpTimer interrupt has occurred or not.
775   * @param  __HANDLE__ specifies the RTC handle.
776   * @param  __INTERRUPT__ specifies the RTC WakeUpTimer interrupt sources to check.
777   *         This parameter can be:
778   *            @arg RTC_FLAG_WUTF WakeUpTimer interrupt flag
779   * @retval None
780   */
781 #if defined(TAMP)
782 #define __HAL_RTC_WAKEUPTIMER_GET_IT(__HANDLE__, __INTERRUPT__)     (((((__HANDLE__)->Instance->SR)  & (__INTERRUPT__)) != 0U) ? 1U : 0U)
783 #else
784 #define __HAL_RTC_WAKEUPTIMER_GET_IT(__HANDLE__, __INTERRUPT__)     (((((__HANDLE__)->Instance->ISR) & (__INTERRUPT__)) != 0U) ? 1U : 0U)
785 #endif /* TAMP */
786 
787 /**
788   * @brief  Check whether the specified RTC Wake Up timer interrupt has been enabled or not.
789   * @param  __HANDLE__ specifies the RTC handle.
790   * @param  __INTERRUPT__ specifies the RTC Wake Up timer interrupt sources to check.
791   *         This parameter can be:
792   *            @arg @ref RTC_IT_WUT  WakeUpTimer interrupt
793   * @retval None
794   */
795 #define __HAL_RTC_WAKEUPTIMER_GET_IT_SOURCE(__HANDLE__, __INTERRUPT__)   (((((__HANDLE__)->Instance->CR) & (__INTERRUPT__)) != 0U) ? 1U : 0U)
796 
797 #if defined(TAMP)
798 /**
799   * @brief  Get the selected RTC WakeUpTimer's flag status.
800   * @param  __HANDLE__ specifies the RTC handle.
801   * @param  __FLAG__ specifies the RTC WakeUpTimer Flag sources to check.
802   *          This parameter can be:
803   *             @arg @ref RTC_FLAG_WUTF
804   * @retval Flag status
805   */
806 #define __HAL_RTC_WAKEUPTIMER_GET_FLAG(__HANDLE__, __FLAG__)   (((((__HANDLE__)->Instance->SR)  & (__FLAG__)) != 0U) ? 1U : 0U)
807 #else
808 /**
809   * @brief  Get the selected RTC WakeUpTimer's flag status.
810   * @param  __HANDLE__ specifies the RTC handle.
811   * @param  __FLAG__ specifies the RTC WakeUpTimer Flag sources to check.
812   *          This parameter can be:
813   *             @arg @ref RTC_FLAG_WUTF
814   *             @arg @ref RTC_FLAG_WUTWF
815   * @retval Flag status
816   */
817 #define __HAL_RTC_WAKEUPTIMER_GET_FLAG(__HANDLE__, __FLAG__)   (((((__HANDLE__)->Instance->ISR) & (__FLAG__)) != 0U) ? 1U : 0U)
818 #endif /* TAMP */
819 
820 /**
821   * @brief  Clear the RTC Wake Up timer's pending flags.
822   * @param  __HANDLE__ specifies the RTC handle.
823   * @param  __FLAG__ specifies the RTC WakeUpTimer Flag to clear.
824   *         This parameter can be:
825   *            @arg @ref RTC_FLAG_WUTF
826   * @retval None
827   */
828 #if defined(TAMP)
829 #define __HAL_RTC_WAKEUPTIMER_CLEAR_FLAG(__HANDLE__, __FLAG__) ((__HANDLE__)->Instance->SCR |= __FLAG__)
830 #else
831 #define __HAL_RTC_WAKEUPTIMER_CLEAR_FLAG(__HANDLE__, __FLAG__) ((__HANDLE__)->Instance->ISR) = (~((__FLAG__) | RTC_ISR_INIT)|((__HANDLE__)->Instance->ISR & RTC_ISR_INIT))
832 #endif /* TAMP */
833 
834 /* ========================================================================== */
835 /*                     ##### RTC Tamper exported macros #####                 */
836 /* ========================================================================== */
837 
838 /**
839   * @brief  Enable the RTC Tamper1 input detection.
840   * @param  __HANDLE__ specifies the RTC handle.
841   * @retval None
842   */
843 #if defined(TAMP)
844 #define __HAL_RTC_TAMPER1_ENABLE(__HANDLE__)           (((TAMP_TypeDef *)((uint32_t)((__HANDLE__)->Instance) + TAMP_OFFSET))->CR1 |= (TAMP_CR1_TAMP1E))
845 #else
846 #define __HAL_RTC_TAMPER1_ENABLE(__HANDLE__)           ((__HANDLE__)->Instance->TAMPCR |= (RTC_TAMPCR_TAMP1E))
847 #endif /* TAMP */
848 
849 /**
850   * @brief  Disable the RTC Tamper1 input detection.
851   * @param  __HANDLE__ specifies the RTC handle.
852   * @retval None
853   */
854 #if defined(TAMP)
855 #define __HAL_RTC_TAMPER1_DISABLE(__HANDLE__)          (((TAMP_TypeDef *)((uint32_t)((__HANDLE__)->Instance) + TAMP_OFFSET))->CR1 &= ~(RTC_TAMPCR_TAMP1E))
856 #else
857 #define __HAL_RTC_TAMPER1_DISABLE(__HANDLE__)          ((__HANDLE__)->Instance->TAMPCR &= ~(RTC_TAMPCR_TAMP1E))
858 #endif /* TAMP */
859 
860 /**
861   * @brief  Enable the RTC Tamper2 input detection.
862   * @param  __HANDLE__ specifies the RTC handle.
863   * @retval None
864   */
865 #if defined(TAMP)
866 #define __HAL_RTC_TAMPER2_ENABLE(__HANDLE__)           (((TAMP_TypeDef *)((uint32_t)((__HANDLE__)->Instance) + TAMP_OFFSET))->CR1 |= (TAMP_CR1_TAMP2E))
867 #else
868 #define __HAL_RTC_TAMPER2_ENABLE(__HANDLE__)           ((__HANDLE__)->Instance->TAMPCR |= (RTC_TAMPCR_TAMP2E))
869 #endif /* TAMP */
870 
871 /**
872   * @brief  Disable the RTC Tamper2 input detection.
873   * @param  __HANDLE__ specifies the RTC handle.
874   * @retval None
875   */
876 #if defined(TAMP)
877 #define __HAL_RTC_TAMPER2_DISABLE(__HANDLE__)          (((TAMP_TypeDef *)((uint32_t)((__HANDLE__)->Instance) + (TAMP_OFFSET))->CR1 &= ~(RTC_TAMPCR_TAMP2E))
878 #else
879 #define __HAL_RTC_TAMPER2_DISABLE(__HANDLE__)          ((__HANDLE__)->Instance->TAMPCR &= ~(RTC_TAMPCR_TAMP2E))
880 #endif /* TAMP */
881 
882 /**
883   * @brief  Enable the RTC Tamper3 input detection.
884   * @param  __HANDLE__ specifies the RTC handle.
885   * @retval None
886   */
887 #if defined(TAMP)
888 #define __HAL_RTC_TAMPER3_ENABLE(__HANDLE__)          (((TAMP_TypeDef *)((uint32_t)((__HANDLE__)->Instance) + TAMP_OFFSET))->CR1 |= (TAMP_CR1_TAMP3E))
889 #else
890 #define __HAL_RTC_TAMPER3_ENABLE(__HANDLE__)          ((__HANDLE__)->Instance->TAMPCR |= (RTC_TAMPCR_TAMP3E))
891 #endif /* TAMP */
892 
893 /**
894   * @brief  Disable the RTC Tamper3 input detection.
895   * @param  __HANDLE__ specifies the RTC handle.
896   * @retval None
897   */
898 #if defined(TAMP)
899 #define __HAL_RTC_TAMPER3_DISABLE(__HANDLE__)          (((TAMP_TypeDef *)((uint32_t)((__HANDLE__)->Instance) + TAMP_OFFSET))->CR1 &= ~(RTC_TAMPCR_TAMP3E))
900 #else
901 #define __HAL_RTC_TAMPER3_DISABLE(__HANDLE__)          ((__HANDLE__)->Instance->TAMPCR &= ~(RTC_TAMPCR_TAMP3E))
902 #endif /* TAMP */
903 
904 /**
905   * @brief  Enable the RTC Tamper interrupt.
906   * @param  __HANDLE__ specifies the RTC handle.
907   * @param  __INTERRUPT__ specifies the RTC Tamper interrupt sources to be enabled.
908   *          This parameter can be any combination of the following values:
909   *             @arg  RTC_IT_TAMPALL: All tampers interrupts
910   *             @arg  RTC_IT_TAMP1: Tamper1 interrupt
911   *             @arg  RTC_IT_TAMP2: Tamper2 interrupt
912   *             @arg  RTC_IT_TAMP3: Tamper3 interrupt
913   * @retval None
914   */
915 #if defined(TAMP)
916 #define __HAL_RTC_TAMPER_ENABLE_IT(__HANDLE__, __INTERRUPT__)        (((TAMP_TypeDef *)((uint32_t)((__HANDLE__)->Instance) + TAMP_OFFSET))->IER |= (__INTERRUPT__))
917 #else
918 #define __HAL_RTC_TAMPER_ENABLE_IT(__HANDLE__, __INTERRUPT__)        ((__HANDLE__)->Instance->TAMPCR |= (__INTERRUPT__))
919 #endif /* TAMP */
920 
921 /**
922   * @brief  Disable the RTC Tamper interrupt.
923   * @param  __HANDLE__ specifies the RTC handle.
924   * @param  __INTERRUPT__ specifies the RTC Tamper interrupt sources to be disabled.
925   *         This parameter can be any combination of the following values:
926   *            @arg  RTC_IT_TAMP: All tampers interrupts
927   *            @arg  RTC_IT_TAMP1: Tamper1 interrupt
928   *            @arg  RTC_IT_TAMP2: Tamper2 interrupt
929   *            @arg  RTC_IT_TAMP3: Tamper3 interrupt
930   * @retval None
931   */
932 #if defined(TAMP)
933 #define __HAL_RTC_TAMPER_DISABLE_IT(__HANDLE__, __INTERRUPT__)       (((TAMP_TypeDef *)((uint32_t)((__HANDLE__)->Instance) + TAMP_OFFSET))->IER &= ~(__INTERRUPT__))
934 #else
935 #define __HAL_RTC_TAMPER_DISABLE_IT(__HANDLE__, __INTERRUPT__)       ((__HANDLE__)->Instance->TAMPCR &= ~(__INTERRUPT__))
936 #endif /* TAMP */
937 
938 /**
939   * @brief  Check whether the specified RTC Tamper interrupt has occurred or not.
940   * @param  __HANDLE__ specifies the RTC handle.
941   * @param  __INTERRUPT__ specifies the RTC Tamper interrupt to check.
942   *         This parameter can be:
943   *            @arg  RTC_FLAG_TAMP1F: Tamper1 interrupt flag
944   *            @arg  RTC_FLAG_TAMP2F: Tamper2 interrupt flag
945   *            @arg  RTC_FLAG_TAMP3F: Tamper3 interrupt flag
946   * @retval Flag status
947   */
948 #if defined(TAMP)
949 #define __HAL_RTC_TAMPER_GET_IT(__HANDLE__, __INTERRUPT__)     ((((((TAMP_TypeDef *)((uint32_t)((__HANDLE__)->Instance) + TAMP_OFFSET))->SR) & (__INTERRUPT__)) != 0U) ? 1U : 0U)
950 #else
951 #define __HAL_RTC_TAMPER_GET_IT(__HANDLE__, __INTERRUPT__)     (((((__HANDLE__)->Instance->ISR) & (__INTERRUPT__)) != 0U) ? 1U : 0U)
952 #endif /* TAMP */
953 
954 /**
955   * @brief  Check whether the specified RTC Tamper interrupt has been enabled or not.
956   * @param  __HANDLE__ specifies the RTC handle.
957   * @param  __INTERRUPT__ specifies the RTC Tamper interrupt source to check.
958   *         This parameter can be:
959   *            @arg  RTC_IT_TAMPALL: All tampers interrupts
960   *            @arg  RTC_IT_TAMP1: Tamper1 interrupt
961   *            @arg  RTC_IT_TAMP2: Tamper2 interrupt
962   *            @arg  RTC_IT_TAMP3: Tamper3 interrupt
963   * @retval Flag status
964   */
965 #if defined(TAMP)
966 #define __HAL_RTC_TAMPER_GET_IT_SOURCE(__HANDLE__, __INTERRUPT__)    ((((((TAMP_TypeDef *)((uint32_t)((__HANDLE__)->Instance) + TAMP_OFFSET))->IER) & (__INTERRUPT__)) != 0U) ? 1U : 0U)
967 #else
968 #define __HAL_RTC_TAMPER_GET_IT_SOURCE(__HANDLE__, __INTERRUPT__)    (((((__HANDLE__)->Instance->TAMPCR) & (__INTERRUPT__)) != 0U) ? 1U : 0U)
969 #endif /* TAMP */
970 
971 /**
972   * @brief  Get the selected RTC Tamper's flag status.
973   * @param  __HANDLE__ specifies the RTC handle.
974   * @param  __FLAG__ specifies the RTC Tamper Flag is pending or not.
975   *          This parameter can be:
976   *             @arg RTC_FLAG_TAMP1F: Tamper1 flag
977   *             @arg RTC_FLAG_TAMP2F: Tamper2 flag
978   *             @arg RTC_FLAG_TAMP3F: Tamper3 flag
979   * @retval Flag status
980   */
981 #if defined(TAMP)
982 #define __HAL_RTC_TAMPER_GET_FLAG(__HANDLE__, __FLAG__)   ((((((TAMP_TypeDef *)((uint32_t)((__HANDLE__)->Instance) + TAMP_OFFSET))->SR) & (__FLAG__)) != 0U) ? 1U : 0U)
983 #else
984 #define __HAL_RTC_TAMPER_GET_FLAG(__HANDLE__, __FLAG__)                                (((((__HANDLE__)->Instance->ISR)                 & (__FLAG__)) != 0U) ? 1U : 0U)
985 #endif /* TAMP */
986 
987 /**
988   * @brief  Clear the RTC Tamper's pending flags.
989   * @param  __HANDLE__ specifies the RTC handle.
990   * @param  __FLAG__ specifies the RTC Tamper Flag to clear.
991   *          This parameter can be:
992   *             @arg RTC_FLAG_TAMP1F: Tamper1 flag
993   *             @arg RTC_FLAG_TAMP2F: Tamper2 flag
994   *             @arg RTC_FLAG_TAMP3F: Tamper3 flag
995   * @retval None
996   */
997 #if defined(TAMP)
998 #define __HAL_RTC_TAMPER_CLEAR_FLAG(__HANDLE__, __FLAG__)      ((((TAMP_TypeDef *)((uint32_t)((__HANDLE__)->Instance) + TAMP_OFFSET))->SCR) |= (__FLAG__))
999 #else
1000 #define __HAL_RTC_TAMPER_CLEAR_FLAG(__HANDLE__, __FLAG__)      ((__HANDLE__)->Instance->ISR) = (~((__FLAG__) | RTC_ISR_INIT)|((__HANDLE__)->Instance->ISR & RTC_ISR_INIT))
1001 #endif /* TAMP */
1002 
1003 /**
1004   * @brief  Get the frequency at which each of the Tamper inputs are sampled.
1005   * @param  __HANDLE__ specifies the RTC handle.
1006   * @retval Sampling frequency
1007   *         This value can be:
1008   *            @arg RTC_TAMPERSAMPLINGFREQ_RTCCLK_DIV32768
1009   *            @arg RTC_TAMPERSAMPLINGFREQ_RTCCLK_DIV16384
1010   *            @arg RTC_TAMPERSAMPLINGFREQ_RTCCLK_DIV8192
1011   *            @arg RTC_TAMPERSAMPLINGFREQ_RTCCLK_DIV4096
1012   *            @arg RTC_TAMPERSAMPLINGFREQ_RTCCLK_DIV2048
1013   *            @arg RTC_TAMPERSAMPLINGFREQ_RTCCLK_DIV512
1014   *            @arg RTC_TAMPERSAMPLINGFREQ_RTCCLK_DIV256
1015   */
1016 #if defined(TAMP)
1017 #define __HAL_RTC_TAMPER_GET_SAMPLING_FREQ(__HANDLE__)   ((uint32_t)((((TAMP_TypeDef *)((uint32_t)((__HANDLE__)->Instance) + TAMP_OFFSET))->FLTCR) & (RTC_TAMPERSAMPLINGFREQ_RTCCLK_MASK)))
1018 #else
1019 #define __HAL_RTC_TAMPER_GET_SAMPLING_FREQ(__HANDLE__)   ((uint32_t)(((__HANDLE__)->Instance->TAMPCR) & (RTC_TAMPERSAMPLINGFREQ_RTCCLK_MASK)))
1020 #endif /* TAMP */
1021 
1022 /**
1023   * @brief  Get the number of consecutive samples at the specified level needed
1024   *         to activate a Tamper event.
1025   * @param  __HANDLE__ specifies the RTC handle.
1026   * @retval Number of consecutive samples
1027   *         This value can be:
1028   *            @arg RTC_TAMPERFILTER_DISABLE
1029   *            @arg RTC_TAMPERFILTER_2SAMPLE
1030   *            @arg RTC_TAMPERFILTER_4SAMPLE
1031   *            @arg RTC_TAMPERFILTER_8SAMPLE
1032   */
1033 #if defined(TAMP)
1034 #define __HAL_RTC_TAMPER_GET_SAMPLES_COUNT(__HANDLE__)   ((uint32_t)((((TAMP_TypeDef *)((uint32_t)((__HANDLE__)->Instance) + TAMP_OFFSET))->FLTCR) & (RTC_TAMPERFILTER_MASK)))
1035 #else
1036 #define __HAL_RTC_TAMPER_GET_SAMPLES_COUNT(__HANDLE__)   ((uint32_t)(((__HANDLE__)->Instance->TAMPCR) & (RTC_TAMPERFILTER_MASK)))
1037 #endif /* TAMP */
1038 
1039 /**
1040   * @brief  Get the pull-up resistors precharge duration.
1041   * @param  __HANDLE__ specifies the RTC handle.
1042   * @retval Number of consecutive samples
1043   *         This value can be:
1044   *            @arg RTC_TAMPERPRECHARGEDURATION_1RTCCLK
1045   *            @arg RTC_TAMPERPRECHARGEDURATION_2RTCCLK
1046   *            @arg RTC_TAMPERPRECHARGEDURATION_4RTCCLK
1047   *            @arg RTC_TAMPERPRECHARGEDURATION_8RTCCLK
1048   */
1049 #if defined(TAMP)
1050 #define __HAL_RTC_TAMPER_GET_PRCHRG_DURATION(__HANDLE__)   ((uint32_t)((((TAMP_TypeDef *)((uint32_t)((__HANDLE__)->Instance) + TAMP_OFFSET))->FLTCR) & (RTC_TAMPERPRECHARGEDURATION_MASK)))
1051 #else
1052 #define __HAL_RTC_TAMPER_GET_PRCHRG_DURATION(__HANDLE__)   ((uint32_t)(((__HANDLE__)->Instance->TAMPCR) & (RTC_TAMPERPRECHARGEDURATION_MASK)))
1053 #endif /* TAMP */
1054 
1055 /**
1056   * @brief  Get the pull-up resistors status.
1057   * @param  __HANDLE__ specifies the RTC handle.
1058   * @retval Pull-up resistors status
1059   *         This value can be:
1060   *            @arg RTC_TAMPER_PULLUP_ENABLE
1061   *            @arg RTC_TAMPER_PULLUP_DISABLE
1062   */
1063 #if defined(TAMP)
1064 #define __HAL_RTC_TAMPER_GET_PULLUP_STATUS(__HANDLE__)   ((uint32_t)((((TAMP_TypeDef *)((uint32_t)((__HANDLE__)->Instance) + TAMP_OFFSET))->FLTCR) & (RTC_TAMPER_PULLUP_MASK)))
1065 #else
1066 #define __HAL_RTC_TAMPER_GET_PULLUP_STATUS(__HANDLE__)   ((uint32_t)(((__HANDLE__)->Instance->TAMPCR) & (RTC_TAMPER_PULLUP_MASK)))
1067 #endif /* TAMP */
1068 
1069 /* ========================================================================== */
1070 /*                  ##### RTC TimeStamp exported macros #####                 */
1071 /* ========================================================================== */
1072 
1073 /**
1074   * @brief  Enable the RTC TimeStamp peripheral.
1075   * @param  __HANDLE__ specifies the RTC handle.
1076   * @retval None
1077   */
1078 #define __HAL_RTC_TIMESTAMP_ENABLE(__HANDLE__)                       ((__HANDLE__)->Instance->CR |= (RTC_CR_TSE))
1079 
1080 /**
1081   * @brief  Disable the RTC TimeStamp peripheral.
1082   * @param  __HANDLE__ specifies the RTC handle.
1083   * @retval None
1084   */
1085 #define __HAL_RTC_TIMESTAMP_DISABLE(__HANDLE__)                      ((__HANDLE__)->Instance->CR &= ~(RTC_CR_TSE))
1086 
1087 /**
1088   * @brief  Enable the RTC TimeStamp interrupt.
1089   * @param  __HANDLE__ specifies the RTC handle.
1090   * @param  __INTERRUPT__ specifies the RTC TimeStamp interrupt source to be enabled.
1091   *         This parameter can be:
1092   *            @arg @ref RTC_IT_TS TimeStamp interrupt
1093   * @retval None
1094   */
1095 #define __HAL_RTC_TIMESTAMP_ENABLE_IT(__HANDLE__, __INTERRUPT__)     ((__HANDLE__)->Instance->CR |= (__INTERRUPT__))
1096 
1097 /**
1098   * @brief  Disable the RTC TimeStamp interrupt.
1099   * @param  __HANDLE__ specifies the RTC handle.
1100   * @param  __INTERRUPT__ specifies the RTC TimeStamp interrupt source to be disabled.
1101   *         This parameter can be:
1102   *            @arg @ref RTC_IT_TS TimeStamp interrupt
1103   * @retval None
1104   */
1105 #define __HAL_RTC_TIMESTAMP_DISABLE_IT(__HANDLE__, __INTERRUPT__)    ((__HANDLE__)->Instance->CR &= ~(__INTERRUPT__))
1106 
1107 /**
1108   * @brief  Check whether the specified RTC TimeStamp interrupt has occurred or not.
1109   * @param  __HANDLE__ specifies the RTC handle.
1110   * @param  __INTERRUPT__ specifies the RTC TimeStamp interrupt source to check.
1111   *         This parameter can be:
1112   *            @arg @ref RTC_IT_TS TimeStamp interrupt
1113   * @retval None
1114   */
1115 #if defined(TAMP)
1116 #define __HAL_RTC_TIMESTAMP_GET_IT(__HANDLE__, __INTERRUPT__)        (((((__HANDLE__)->Instance->MISR) & ((__INTERRUPT__) >> 12)) != 0U) ? 1U : 0U)
1117 #else
1118 #define __HAL_RTC_TIMESTAMP_GET_IT(__HANDLE__, __INTERRUPT__)        (((((__HANDLE__)->Instance->ISR) & (__INTERRUPT__)) != 0U) ? 1U : 0U)
1119 #endif /* TAMP */
1120 /**
1121   * @brief  Check whether the specified RTC Time Stamp interrupt has been enabled or not.
1122   * @param  __HANDLE__ specifies the RTC handle.
1123   * @param  __INTERRUPT__ specifies the RTC Time Stamp interrupt source to check.
1124   *         This parameter can be:
1125   *            @arg @ref RTC_IT_TS TimeStamp interrupt
1126   * @retval None
1127   */
1128 #define __HAL_RTC_TIMESTAMP_GET_IT_SOURCE(__HANDLE__, __INTERRUPT__)     (((((__HANDLE__)->Instance->CR) & (__INTERRUPT__)) != 0U) ? 1U : 0U)
1129 
1130 /**
1131   * @brief  Get the selected RTC TimeStamp's flag status.
1132   * @param  __HANDLE__ specifies the RTC handle.
1133   * @param  __FLAG__ specifies the RTC TimeStamp Flag is pending or not.
1134   *         This parameter can be:
1135   *            @arg RTC_FLAG_TSF
1136   *            @arg RTC_FLAG_TSOVF
1137   * @retval Flag status
1138   */
1139 #if defined(TAMP)
1140 #define __HAL_RTC_TIMESTAMP_GET_FLAG(__HANDLE__, __FLAG__)     (((((__HANDLE__)->Instance->SR)  & (__FLAG__)) != 0U) ? 1U : 0U)
1141 #else
1142 #define __HAL_RTC_TIMESTAMP_GET_FLAG(__HANDLE__, __FLAG__)     (((((__HANDLE__)->Instance->ISR) & (__FLAG__)) != 0U) ? 1U : 0U)
1143 #endif /* TAMP */
1144 
1145 /**
1146   * @brief  Clear the RTC Time Stamp's pending flags.
1147   * @param  __HANDLE__ specifies the RTC handle.
1148   * @param  __FLAG__ specifies the RTC Alarm Flag sources to clear.
1149   *          This parameter can be:
1150   *             @arg RTC_FLAG_TSF
1151   *             @arg RTC_FLAG_TSOVF
1152   * @retval None
1153   */
1154 #if defined(TAMP)
1155 #define __HAL_RTC_TIMESTAMP_CLEAR_FLAG(__HANDLE__, __FLAG__)   ((__HANDLE__)->Instance->SCR |= __FLAG__)
1156 #else
1157 #define __HAL_RTC_TIMESTAMP_CLEAR_FLAG(__HANDLE__, __FLAG__)   ((__HANDLE__)->Instance->ISR = (~((__FLAG__) | RTC_ISR_INIT)|((__HANDLE__)->Instance->ISR & RTC_ISR_INIT)))
1158 #endif /* TAMP */
1159 
1160 /**
1161   * @brief  Enable the RTC internal TimeStamp peripheral.
1162   * @param  __HANDLE__ specifies the RTC handle.
1163   * @retval None
1164   */
1165 #define __HAL_RTC_INTERNAL_TIMESTAMP_ENABLE(__HANDLE__)                ((__HANDLE__)->Instance->CR |= (RTC_CR_ITSE))
1166 
1167 /**
1168   * @brief  Disable the RTC internal TimeStamp peripheral.
1169   * @param  __HANDLE__ specifies the RTC handle.
1170   * @retval None
1171   */
1172 #define __HAL_RTC_INTERNAL_TIMESTAMP_DISABLE(__HANDLE__)               ((__HANDLE__)->Instance->CR &= ~(RTC_CR_ITSE))
1173 
1174 /**
1175   * @brief  Get the selected RTC Internal Time Stamp's flag status.
1176   * @param  __HANDLE__ specifies the RTC handle.
1177   * @param  __FLAG__ specifies the RTC Internal Time Stamp Flag is pending or not.
1178   *         This parameter can be:
1179   *            @arg RTC_FLAG_ITSF
1180   * @retval Flag status
1181   */
1182 #if defined(TAMP)
1183 #define __HAL_RTC_INTERNAL_TIMESTAMP_GET_FLAG(__HANDLE__, __FLAG__)    (((((__HANDLE__)->Instance->SR)  & (__FLAG__)) != 0U) ? 1U : 0U)
1184 #else
1185 #define __HAL_RTC_INTERNAL_TIMESTAMP_GET_FLAG(__HANDLE__, __FLAG__)    (((((__HANDLE__)->Instance->ISR) & (__FLAG__)) != 0U) ? 1U : 0U)
1186 #endif /* TAMP */
1187 
1188 /**
1189   * @brief  Clear the RTC Internal Time Stamp's pending flags.
1190   * @param  __HANDLE__ specifies the RTC handle.
1191   * @param  __FLAG__ specifies the RTC Internal Time Stamp Flag source to clear.
1192   *          This parameter can be:
1193   *             @arg RTC_FLAG_ITSF
1194   * @note   This flag must be cleared together with TSF flag.
1195   * @retval None
1196   */
1197 #if defined(TAMP)
1198 #define __HAL_RTC_INTERNAL_TIMESTAMP_CLEAR_FLAG(__HANDLE__, __FLAG__)  ((__HANDLE__)->Instance->SCR |= __FLAG__)
1199 #else
1200 #define __HAL_RTC_INTERNAL_TIMESTAMP_CLEAR_FLAG(__HANDLE__, __FLAG__)  ((__HANDLE__)->Instance->ISR = (~((__FLAG__) | RTC_ISR_INIT)|((__HANDLE__)->Instance->ISR & RTC_ISR_INIT)))
1201 #endif /* TAMP */
1202 
1203 /**
1204   * @brief  Enable the RTC TimeStamp on Tamper detection.
1205   * @param  __HANDLE__ specifies the RTC handle.
1206   * @retval None
1207   */
1208 #if defined(TAMP)
1209 #define __HAL_RTC_TAMPTS_ENABLE(__HANDLE__)                       ((__HANDLE__)->Instance->CR |= (RTC_TIMESTAMPONTAMPERDETECTION_MASK))
1210 #else
1211 #define __HAL_RTC_TAMPTS_ENABLE(__HANDLE__)                       ((__HANDLE__)->Instance->TAMPCR |= (RTC_TIMESTAMPONTAMPERDETECTION_MASK))
1212 #endif /* TAMP */
1213 
1214 /**
1215   * @brief  Disable the RTC TimeStamp on Tamper detection.
1216   * @param  __HANDLE__ specifies the RTC handle.
1217   * @retval None
1218   */
1219 #if defined(TAMP)
1220 #define __HAL_RTC_TAMPTS_DISABLE(__HANDLE__)                      ((__HANDLE__)->Instance->CR &= ~(RTC_TIMESTAMPONTAMPERDETECTION_MASK))
1221 #else
1222 #define __HAL_RTC_TAMPTS_DISABLE(__HANDLE__)                      ((__HANDLE__)->Instance->TAMPCR &= ~(RTC_TIMESTAMPONTAMPERDETECTION_MASK))
1223 #endif /* TAMP */
1224 
1225 /**
1226   * @brief  Get activation status of the RTC TimeStamp on Tamper detection.
1227   * @param  __HANDLE__ specifies the RTC handle.
1228   * @retval Activation status of TimeStamp on Tamper detection
1229   *         This value can be:
1230   *            @arg RTC_TIMESTAMPONTAMPERDETECTION_ENABLE
1231   *            @arg RTC_TIMESTAMPONTAMPERDETECTION_DISABLE
1232   */
1233 #if defined(TAMP)
1234 #define __HAL_RTC_TAMPTS_GET_STATUS(__HANDLE__)                   ((__HANDLE__)->Instance->CR &= RTC_TIMESTAMPONTAMPERDETECTION_MASK)
1235 #else
1236 #define __HAL_RTC_TAMPTS_GET_STATUS(__HANDLE__)                   ((__HANDLE__)->Instance->TAMPCR &= RTC_TIMESTAMPONTAMPERDETECTION_MASK)
1237 #endif /* TAMP */
1238 
1239 #if defined(TAMP)
1240 /**
1241   * @brief  Enable the RTC Tamper detection output.
1242   * @param  __HANDLE__ specifies the RTC handle.
1243   * @retval None
1244   */
1245 #define __HAL_RTC_TAMPOE_ENABLE(__HANDLE__)                       ((__HANDLE__)->Instance->CR |= (RTC_CR_TAMPOE))
1246 
1247 /**
1248   * @brief  Disable the RTC Tamper detection output.
1249   * @param  __HANDLE__ specifies the RTC handle.
1250   * @retval None
1251   */
1252 #define __HAL_RTC_TAMPOE_DISABLE(__HANDLE__)                      ((__HANDLE__)->Instance->CR &= ~(RTC_CR_TAMPOE))
1253 #endif /* TAMP */
1254 
1255 /* ========================================================================== */
1256 /*         ##### Extended RTC Peripheral Control exported macros #####        */
1257 /* ========================================================================== */
1258 
1259 /**
1260   * @brief  Enable the RTC calibration output.
1261   * @param  __HANDLE__ specifies the RTC handle.
1262   * @retval None
1263   */
1264 #define __HAL_RTC_CALIBRATION_OUTPUT_ENABLE(__HANDLE__)                ((__HANDLE__)->Instance->CR |= (RTC_CR_COE))
1265 
1266 /**
1267   * @brief  Disable the calibration output.
1268   * @param  __HANDLE__ specifies the RTC handle.
1269   * @retval None
1270   */
1271 #define __HAL_RTC_CALIBRATION_OUTPUT_DISABLE(__HANDLE__)               ((__HANDLE__)->Instance->CR &= ~(RTC_CR_COE))
1272 
1273 /**
1274   * @brief  Enable the clock reference detection.
1275   * @param  __HANDLE__ specifies the RTC handle.
1276   * @retval None
1277   */
1278 #define __HAL_RTC_CLOCKREF_DETECTION_ENABLE(__HANDLE__)                ((__HANDLE__)->Instance->CR |= (RTC_CR_REFCKON))
1279 
1280 /**
1281   * @brief  Disable the clock reference detection.
1282   * @param  __HANDLE__ specifies the RTC handle.
1283   * @retval None
1284   */
1285 #define __HAL_RTC_CLOCKREF_DETECTION_DISABLE(__HANDLE__)               ((__HANDLE__)->Instance->CR &= ~(RTC_CR_REFCKON))
1286 
1287 /**
1288   * @brief  Get the selected RTC shift operation's flag status.
1289   * @param  __HANDLE__ specifies the RTC handle.
1290   * @param  __FLAG__ specifies the RTC shift operation Flag is pending or not.
1291   *          This parameter can be:
1292   *             @arg RTC_FLAG_SHPF
1293   * @retval Flag status
1294   */
1295 #if defined(TAMP)
1296 #define __HAL_RTC_SHIFT_GET_FLAG(__HANDLE__, __FLAG__)         (((((__HANDLE__)->Instance->ICSR) & (__FLAG__)) != 0U) ? 1U : 0U)
1297 #else
1298 #define __HAL_RTC_SHIFT_GET_FLAG(__HANDLE__, __FLAG__)         (((((__HANDLE__)->Instance->ISR)  & (__FLAG__)) != 0U) ? 1U : 0U)
1299 #endif /* TAMP */
1300 
1301 /* ========================================================================== */
1302 /*               ##### RTC Wake-up Interrupt exported macros #####            */
1303 /* ========================================================================== */
1304 
1305 /**
1306   * @brief  Enable interrupt on the RTC WakeUp Timer associated Exti line.
1307   * @retval None
1308   */
1309 #if defined(EXTI_D1)
1310 #define __HAL_RTC_WAKEUPTIMER_EXTI_ENABLE_IT()       (EXTI_D1->IMR1 |= RTC_EXTI_LINE_WAKEUPTIMER_EVENT)
1311 #else  /* EXTI */
1312 #define __HAL_RTC_WAKEUPTIMER_EXTI_ENABLE_IT()       (EXTI->IMR1    |= RTC_EXTI_LINE_WAKEUPTIMER_EVENT)
1313 #endif /* EXTI_D1 */
1314 /**
1315   * @brief  Disable interrupt on the RTC WakeUp Timer associated Exti line.
1316   * @retval None
1317   */
1318 #if defined(EXTI_D1)
1319 #define __HAL_RTC_WAKEUPTIMER_EXTI_DISABLE_IT()      (EXTI_D1->IMR1 &= ~(RTC_EXTI_LINE_WAKEUPTIMER_EVENT))
1320 #else  /* EXTI */
1321 #define __HAL_RTC_WAKEUPTIMER_EXTI_DISABLE_IT()      (EXTI->IMR1    &= ~(RTC_EXTI_LINE_WAKEUPTIMER_EVENT))
1322 #endif /* EXTI_D1 */
1323 
1324 /**
1325   * @brief  Enable event on the RTC WakeUp Timer associated Exti line.
1326   * @retval None
1327   */
1328 #if defined(EXTI_D1)
1329 #define __HAL_RTC_WAKEUPTIMER_EXTI_ENABLE_EVENT()    (EXTI_D1->EMR1 |= RTC_EXTI_LINE_WAKEUPTIMER_EVENT)
1330 #else  /* EXTI */
1331 #define __HAL_RTC_WAKEUPTIMER_EXTI_ENABLE_EVENT()    (EXTI->EMR1    |= RTC_EXTI_LINE_WAKEUPTIMER_EVENT)
1332 #endif /* EXTI_D1 */
1333 
1334 /**
1335   * @brief  Disable event on the RTC WakeUp Timer associated Exti line.
1336   * @retval None
1337   */
1338 #if defined(EXTI_D1)
1339 #define __HAL_RTC_WAKEUPTIMER_EXTI_DISABLE_EVENT()   (EXTI_D1->EMR1 &= ~(RTC_EXTI_LINE_WAKEUPTIMER_EVENT))
1340 #else  /* EXTI */
1341 #define __HAL_RTC_WAKEUPTIMER_EXTI_DISABLE_EVENT()   (EXTI->EMR1    &= ~(RTC_EXTI_LINE_WAKEUPTIMER_EVENT))
1342 #endif /* EXTI_D1 */
1343 
1344 /**
1345   * @brief  Enable event on the RTC WakeUp Timer associated D3 Exti line.
1346   * @retval None
1347   */
1348 #define __HAL_RTC_WAKEUPTIMER_EXTID3_ENABLE_EVENT()    (EXTI->D3PMR1 |= RTC_EXTI_LINE_WAKEUPTIMER_EVENT)
1349 
1350 /**
1351   * @brief  Disable event on the RTC WakeUp Timer associated D3 Exti line.
1352   * @retval None
1353   */
1354 #define __HAL_RTC_WAKEUPTIMER_EXTID3_DISABLE_EVENT()   (EXTI->D3PMR1 &= ~(RTC_EXTI_LINE_WAKEUPTIMER_EVENT))
1355 
1356 #if defined(DUAL_CORE)
1357 /**
1358   * @brief  Enable interrupt on the RTC WakeUp Timer associated D2 Exti line.
1359   * @retval None
1360   */
1361 #define __HAL_RTC_WAKEUPTIMER_EXTID2_ENABLE_IT()       (EXTI_D2->IMR1 |= RTC_EXTI_LINE_WAKEUPTIMER_EVENT)
1362 
1363 /**
1364   * @brief  Disable interrupt on the RTC WakeUp Timer associated D2 Exti line.
1365   * @retval None
1366   */
1367 #define __HAL_RTC_WAKEUPTIMER_EXTID2_DISABLE_IT()      (EXTI_D2->IMR1 &= ~(RTC_EXTI_LINE_WAKEUPTIMER_EVENT))
1368 
1369 /**
1370   * @brief  Enable event on the RTC WakeUp Timer associated D2 Exti line.
1371   * @retval None
1372   */
1373 #define __HAL_RTC_WAKEUPTIMER_EXTID2_ENABLE_EVENT()    (EXTI_D2->EMR1 |= RTC_EXTI_LINE_WAKEUPTIMER_EVENT)
1374 
1375 /**
1376   * @brief  Disable event on the RTC WakeUp Timer associated D2 Exti line.
1377   * @retval None
1378   */
1379 #define __HAL_RTC_WAKEUPTIMER_EXTID2_DISABLE_EVENT()   (EXTI_D2->EMR1 &= ~(RTC_EXTI_LINE_WAKEUPTIMER_EVENT))
1380 
1381 #endif /* DUAL_CORE */
1382 
1383 /**
1384   * @brief  Enable falling edge trigger on the RTC WakeUp Timer associated Exti line.
1385   * @retval None
1386   */
1387 #define __HAL_RTC_WAKEUPTIMER_EXTI_ENABLE_FALLING_EDGE()   (EXTI->FTSR1 |= RTC_EXTI_LINE_WAKEUPTIMER_EVENT)
1388 
1389 /**
1390   * @brief  Disable falling edge trigger on the RTC WakeUp Timer associated Exti line.
1391   * @retval None
1392   */
1393 #define __HAL_RTC_WAKEUPTIMER_EXTI_DISABLE_FALLING_EDGE()  (EXTI->FTSR1 &= ~(RTC_EXTI_LINE_WAKEUPTIMER_EVENT))
1394 
1395 /**
1396   * @brief  Enable rising edge trigger on the RTC WakeUp Timer associated Exti line.
1397   * @retval None
1398   */
1399 #define __HAL_RTC_WAKEUPTIMER_EXTI_ENABLE_RISING_EDGE()    (EXTI->RTSR1 |= RTC_EXTI_LINE_WAKEUPTIMER_EVENT)
1400 
1401 /**
1402   * @brief  Disable rising edge trigger on the RTC WakeUp Timer associated Exti line.
1403   * @retval None
1404   */
1405 #define __HAL_RTC_WAKEUPTIMER_EXTI_DISABLE_RISING_EDGE()   (EXTI->RTSR1 &= ~(RTC_EXTI_LINE_WAKEUPTIMER_EVENT))
1406 
1407 /**
1408   * @brief  Enable rising & falling edge trigger on the RTC WakeUp Timer associated Exti line.
1409   * @retval None
1410   */
1411 #define __HAL_RTC_WAKEUPTIMER_EXTI_ENABLE_RISING_FALLING_EDGE()  do { \
1412                                                                    __HAL_RTC_WAKEUPTIMER_EXTI_ENABLE_RISING_EDGE();  \
1413                                                                    __HAL_RTC_WAKEUPTIMER_EXTI_ENABLE_FALLING_EDGE(); \
1414                                                                  } while(0)
1415 
1416 /**
1417   * @brief  Disable rising & falling edge trigger on the RTC WakeUp Timer associated Exti line.
1418   * This parameter can be:
1419   * @retval None
1420   */
1421 #define __HAL_RTC_WAKEUPTIMER_EXTI_DISABLE_RISING_FALLING_EDGE()  do { \
1422                                                                    __HAL_RTC_WAKEUPTIMER_EXTI_DISABLE_RISING_EDGE();  \
1423                                                                    __HAL_RTC_WAKEUPTIMER_EXTI_DISABLE_FALLING_EDGE(); \
1424                                                                   } while(0)
1425 
1426 /**
1427   * @brief Check whether the RTC WakeUp Timer associated Exti line interrupt flag is set or not.
1428   * @retval Line Status.
1429   */
1430 #if defined(EXTI_D1)
1431 #define __HAL_RTC_WAKEUPTIMER_EXTI_GET_FLAG()              (EXTI_D1->PR1 & RTC_EXTI_LINE_WAKEUPTIMER_EVENT)
1432 #else  /* EXTI */
1433 #define __HAL_RTC_WAKEUPTIMER_EXTI_GET_FLAG()              (EXTI->PR1    & RTC_EXTI_LINE_WAKEUPTIMER_EVENT)
1434 #endif /* EXTI_D1 */
1435 
1436 /**
1437   * @brief Clear the RTC WakeUp Timer associated Exti line flag.
1438   * @retval None
1439   */
1440 #if defined(EXTI_D1)
1441 #define __HAL_RTC_WAKEUPTIMER_EXTI_CLEAR_FLAG()            (EXTI_D1->PR1 = RTC_EXTI_LINE_WAKEUPTIMER_EVENT)
1442 #else  /* EXTI */
1443 #define __HAL_RTC_WAKEUPTIMER_EXTI_CLEAR_FLAG()            (EXTI->PR1    = RTC_EXTI_LINE_WAKEUPTIMER_EVENT)
1444 #endif /* EXTI_D1 */
1445 
1446 /**
1447   * @brief Check whether the RTC WakeUp Timer associated D3 Exti line interrupt flag is set or not.
1448   * @retval Line Status
1449   */
1450 #define __HAL_RTC_WAKEUPTIMER_EXTID3_GET_FLAG()            (EXTI_D3->PR1 & RTC_EXTI_LINE_WAKEUPTIMER_EVENT)
1451 
1452 /**
1453   * @brief Clear the RTC WakeUp Timer associated D3 Exti line flag.
1454   * @retval None.
1455   */
1456 #define __HAL_RTC_WAKEUPTIMER_EXTID3_CLEAR_FLAG()          (EXTI_D3->PR1 = RTC_EXTI_LINE_WAKEUPTIMER_EVENT)
1457 
1458 /**
1459   * @brief Generate a Software interrupt on the RTC WakeUp Timer associated Exti line.
1460   * @retval None.
1461   */
1462 #define __HAL_RTC_WAKEUPTIMER_EXTI_GENERATE_SWIT()         (EXTI->SWIER1 |= RTC_EXTI_LINE_WAKEUPTIMER_EVENT)
1463 
1464 #if defined(DUAL_CORE)
1465 
1466 /**
1467   * @brief Check whether the RTC WakeUp Timer associated D2 Exti line interrupt flag is set or not.
1468   * @retval Line Status.
1469   */
1470 #define __HAL_RTC_WAKEUPTIMER_EXTID2_GET_FLAG()            (EXTI_D2->PR1 & RTC_EXTI_LINE_WAKEUPTIMER_EVENT)
1471 
1472 /**
1473   * @brief Clear the RTC WakeUp Timer associated D2 Exti line flag.
1474   * @retval None.
1475   */
1476 #define __HAL_RTC_WAKEUPTIMER_EXTID2_CLEAR_FLAG()          (EXTI_D2->PR1 = RTC_EXTI_LINE_WAKEUPTIMER_EVENT)
1477 
1478 #endif /* DUAL_CORE */
1479 
1480 /* ========================================================================== */
1481 /*       ##### RTC TimeStamp and Tamper Interrupt exported macros #####       */
1482 /* ========================================================================== */
1483 
1484 /**
1485   * @brief  Enable interrupt on the RTC Tamper and Timestamp associated Exti line.
1486   * @retval None
1487   */
1488 #if defined(EXTI_D1)
1489 #define __HAL_RTC_TAMPER_TIMESTAMP_EXTI_ENABLE_IT()        (EXTI_D1->IMR1 |= RTC_EXTI_LINE_TAMPER_TIMESTAMP_EVENT)
1490 #else  /* EXTI */
1491 #define __HAL_RTC_TAMPER_TIMESTAMP_EXTI_ENABLE_IT()        (EXTI->IMR1    |= RTC_EXTI_LINE_TAMPER_TIMESTAMP_EVENT)
1492 #endif /* EXTI_D1 */
1493 
1494 /**
1495   * @brief  Disable interrupt on the RTC Tamper and Timestamp associated Exti line.
1496   * @retval None
1497   */
1498 #if defined(EXTI_D1)
1499 #define __HAL_RTC_TAMPER_TIMESTAMP_EXTI_DISABLE_IT()       (EXTI_D1->IMR1 &= ~(RTC_EXTI_LINE_TAMPER_TIMESTAMP_EVENT))
1500 #else  /* EXTI */
1501 #define __HAL_RTC_TAMPER_TIMESTAMP_EXTI_DISABLE_IT()       (EXTI->IMR1    &= ~(RTC_EXTI_LINE_TAMPER_TIMESTAMP_EVENT))
1502 #endif /* EXTI_D1 */
1503 
1504 /**
1505   * @brief  Enable event on the RTC Tamper and Timestamp associated Exti line.
1506   * @retval None
1507   */
1508 #if defined(EXTI_D1)
1509 #define __HAL_RTC_TAMPER_TIMESTAMP_EXTI_ENABLE_EVENT()    (EXTI_D1->EMR1 |= RTC_EXTI_LINE_TAMPER_TIMESTAMP_EVENT)
1510 #else  /* EXTI */
1511 #define __HAL_RTC_TAMPER_TIMESTAMP_EXTI_ENABLE_EVENT()    (EXTI->EMR1    |= RTC_EXTI_LINE_TAMPER_TIMESTAMP_EVENT)
1512 #endif /* EXTI_D1 */
1513 
1514 /**
1515   * @brief  Disable event on the RTC Tamper and Timestamp associated Exti line.
1516   * @retval None
1517   */
1518 #if defined(EXTI_D1)
1519 #define __HAL_RTC_TAMPER_TIMESTAMP_EXTI_DISABLE_EVENT()   (EXTI_D1->EMR1 &= ~(RTC_EXTI_LINE_TAMPER_TIMESTAMP_EVENT))
1520 #else  /* EXTI */
1521 #define __HAL_RTC_TAMPER_TIMESTAMP_EXTI_DISABLE_EVENT()   (EXTI->EMR1    &= ~(RTC_EXTI_LINE_TAMPER_TIMESTAMP_EVENT))
1522 #endif /* EXTI_D1 */
1523 
1524 #if defined(DUAL_CORE)
1525 /**
1526   * @brief  Enable interrupt on the RTC Tamper and Timestamp associated D2 Exti line.
1527   * @retval None
1528   */
1529 #define __HAL_RTC_TAMPER_TIMESTAMP_EXTID2_ENABLE_IT()      (EXTI_D2->IMR1 |= RTC_EXTI_LINE_TAMPER_TIMESTAMP_EVENT)
1530 
1531 /**
1532   * @brief  Disable interrupt on the RTC Tamper and Timestamp associated D2 Exti line.
1533   * @retval None
1534   */
1535 #define __HAL_RTC_TAMPER_TIMESTAMP_EXTID2_DISABLE_IT()     (EXTI_D2->IMR1 &= ~(RTC_EXTI_LINE_TAMPER_TIMESTAMP_EVENT))
1536 
1537 
1538 /**
1539   * @brief  Enable event on the RTC Tamper and Timestamp associated D2 Exti line.
1540   * @retval None
1541   */
1542 #define __HAL_RTC_TAMPER_TIMESTAMP_EXTID2_ENABLE_EVENT()  (EXTI_D2->EMR1 |= RTC_EXTI_LINE_TAMPER_TIMESTAMP_EVENT)
1543 
1544 
1545 /**
1546   * @brief  Disable event on the RTC Tamper and Timestamp associated D2 Exti line.
1547   * @retval None
1548   */
1549 #define __HAL_RTC_TAMPER_TIMESTAMP_EXTID2_DISABLE_EVENT() (EXTI_D2->EMR1 &= ~(RTC_EXTI_LINE_TAMPER_TIMESTAMP_EVENT))
1550 
1551 #endif /* DUAL_CORE */
1552 
1553 /**
1554   * @brief  Enable falling edge trigger on the RTC Tamper and Timestamp associated Exti line.
1555   * @retval None
1556   */
1557 #define __HAL_RTC_TAMPER_TIMESTAMP_EXTI_ENABLE_FALLING_EDGE()   (EXTI->FTSR1 |= RTC_EXTI_LINE_TAMPER_TIMESTAMP_EVENT)
1558 
1559 /**
1560   * @brief  Disable falling edge trigger on the RTC Tamper and Timestamp associated Exti line.
1561   * @retval None
1562   */
1563 #define __HAL_RTC_TAMPER_TIMESTAMP_EXTI_DISABLE_FALLING_EDGE()  (EXTI->FTSR1 &= ~(RTC_EXTI_LINE_TAMPER_TIMESTAMP_EVENT))
1564 
1565 /**
1566   * @brief  Enable rising edge trigger on the RTC Tamper and Timestamp associated Exti line.
1567   * @retval None
1568   */
1569 #define __HAL_RTC_TAMPER_TIMESTAMP_EXTI_ENABLE_RISING_EDGE()    (EXTI->RTSR1 |= RTC_EXTI_LINE_TAMPER_TIMESTAMP_EVENT)
1570 
1571 /**
1572   * @brief  Disable rising edge trigger on the RTC Tamper and Timestamp associated Exti line.
1573   * @retval None
1574   */
1575 #define __HAL_RTC_TAMPER_TIMESTAMP_EXTI_DISABLE_RISING_EDGE()   (EXTI->RTSR1 &= ~(RTC_EXTI_LINE_TAMPER_TIMESTAMP_EVENT))
1576 
1577 /**
1578   * @brief  Enable rising & falling edge trigger on the RTC Tamper and Timestamp associated Exti line.
1579   * @retval None
1580   */
1581 #define __HAL_RTC_TAMPER_TIMESTAMP_EXTI_ENABLE_RISING_FALLING_EDGE()  do { \
1582                                                                         __HAL_RTC_TAMPER_TIMESTAMP_EXTI_ENABLE_RISING_EDGE();  \
1583                                                                         __HAL_RTC_TAMPER_TIMESTAMP_EXTI_ENABLE_FALLING_EDGE(); \
1584                                                                       } while(0)
1585 
1586 /**
1587   * @brief  Disable rising & falling edge trigger on the RTC Tamper and Timestamp associated Exti line.
1588   * @retval None
1589   */
1590 #define __HAL_RTC_TAMPER_TIMESTAMP_EXTI_DISABLE_RISING_FALLING_EDGE()  do { \
1591                                                                         __HAL_RTC_TAMPER_TIMESTAMP_EXTI_DISABLE_RISING_EDGE();  \
1592                                                                         __HAL_RTC_TAMPER_TIMESTAMP_EXTI_DISABLE_FALLING_EDGE(); \
1593                                                                        } while(0)
1594 
1595 /**
1596   * @brief Check whether the RTC Tamper and Timestamp associated Exti line interrupt flag is set or not.
1597   * @retval Line Status
1598   */
1599 #if defined(EXTI_D1)
1600 #define __HAL_RTC_TAMPER_TIMESTAMP_EXTI_GET_FLAG()         (EXTI_D1->PR1 & RTC_EXTI_LINE_TAMPER_TIMESTAMP_EVENT)
1601 #else  /* EXTI */
1602 #define __HAL_RTC_TAMPER_TIMESTAMP_EXTI_GET_FLAG()         (EXTI->PR1    & RTC_EXTI_LINE_TAMPER_TIMESTAMP_EVENT)
1603 #endif /* EXTI_D1 */
1604 
1605 /**
1606   * @brief Clear the RTC Tamper and Timestamp associated Exti line flag.
1607   * @retval None
1608   */
1609 #if defined(EXTI_D1)
1610 #define __HAL_RTC_TAMPER_TIMESTAMP_EXTI_CLEAR_FLAG()       (EXTI_D1->PR1 = RTC_EXTI_LINE_TAMPER_TIMESTAMP_EVENT)
1611 #else  /* EXTI */
1612 #define __HAL_RTC_TAMPER_TIMESTAMP_EXTI_CLEAR_FLAG()       (EXTI->PR1    = RTC_EXTI_LINE_TAMPER_TIMESTAMP_EVENT)
1613 #endif /* EXTI_D1 */
1614 
1615 #if defined(DUAL_CORE)
1616 /**
1617   * @brief Check whether the RTC Tamper and Timestamp associated D2 Exti line interrupt flag is set or not.
1618   * @retval Line Status
1619   */
1620 #define __HAL_RTC_TAMPER_TIMESTAMP_EXTID2_GET_FLAG()       (EXTI_D2->PR1 & RTC_EXTI_LINE_WAKEUPTIMER_EVENT)
1621 
1622 /**
1623   * @brief Clear the RTC Tamper and Timestamp associated D2 Exti line flag.
1624   * @retval None
1625   */
1626 #define __HAL_RTC_TAMPER_TIMESTAMP_EXTID2_CLEAR_FLAG()     (EXTI_D2->PR1 = RTC_EXTI_LINE_TAMPER_TIMESTAMP_EVENT)
1627 
1628 #endif  /* DUAL_CORE */
1629 
1630 /**
1631   * @brief Generate a Software interrupt on the RTC Tamper and Timestamp associated Exti line
1632   * @retval None
1633   */
1634 #define __HAL_RTC_TAMPER_TIMESTAMP_EXTI_GENERATE_SWIT()    (EXTI->SWIER1 |= RTC_EXTI_LINE_TAMPER_TIMESTAMP_EVENT)
1635 
1636 /**
1637   * @}
1638   */
1639 
1640 /* Exported functions --------------------------------------------------------*/
1641 
1642 /** @defgroup RTCEx_Exported_Functions RTC Exported Functions
1643   * @{
1644   */
1645 
1646 /* ========================================================================== */
1647 /*                  ##### RTC TimeStamp exported functions #####              */
1648 /* ========================================================================== */
1649 
1650 /* RTC TimeStamp functions ****************************************************/
1651 
1652 /** @defgroup RTCEx_Exported_Functions_Group1 Extended RTC TimeStamp functions
1653   * @{
1654   */
1655 HAL_StatusTypeDef HAL_RTCEx_SetTimeStamp(RTC_HandleTypeDef *hrtc, uint32_t TimeStampEdge, uint32_t RTC_TimeStampPin);
1656 HAL_StatusTypeDef HAL_RTCEx_SetTimeStamp_IT(RTC_HandleTypeDef *hrtc, uint32_t TimeStampEdge, uint32_t RTC_TimeStampPin);
1657 HAL_StatusTypeDef HAL_RTCEx_DeactivateTimeStamp(RTC_HandleTypeDef *hrtc);
1658 HAL_StatusTypeDef HAL_RTCEx_SetInternalTimeStamp(RTC_HandleTypeDef *hrtc);
1659 HAL_StatusTypeDef HAL_RTCEx_DeactivateInternalTimeStamp(RTC_HandleTypeDef *hrtc);
1660 HAL_StatusTypeDef HAL_RTCEx_GetTimeStamp(RTC_HandleTypeDef *hrtc, RTC_TimeTypeDef *sTimeStamp, RTC_DateTypeDef *sTimeStampDate, uint32_t Format);
1661 void              HAL_RTCEx_TamperTimeStampIRQHandler(RTC_HandleTypeDef *hrtc);
1662 void              HAL_RTCEx_TimeStampEventCallback(RTC_HandleTypeDef *hrtc);
1663 HAL_StatusTypeDef HAL_RTCEx_PollForTimeStampEvent(RTC_HandleTypeDef *hrtc, uint32_t Timeout);
1664 /**
1665   * @}
1666   */
1667 
1668 /* ========================================================================== */
1669 /*                    ##### RTC Tamper exported functions #####               */
1670 /* ========================================================================== */
1671 
1672 /* RTC Tamper functions *******************************************************/
1673 
1674 /** @defgroup RTCEx_Exported_Functions_Group5 Extended RTC Tamper functions
1675   * @{
1676   */
1677 HAL_StatusTypeDef HAL_RTCEx_SetTamper(RTC_HandleTypeDef *hrtc, RTC_TamperTypeDef *sTamper);
1678 HAL_StatusTypeDef HAL_RTCEx_SetTamper_IT(RTC_HandleTypeDef *hrtc, RTC_TamperTypeDef *sTamper);
1679 HAL_StatusTypeDef HAL_RTCEx_DeactivateTamper(RTC_HandleTypeDef *hrtc, uint32_t Tamper);
1680 HAL_StatusTypeDef HAL_RTCEx_PollForTamper1Event(RTC_HandleTypeDef *hrtc, uint32_t Timeout);
1681 HAL_StatusTypeDef HAL_RTCEx_PollForTamper2Event(RTC_HandleTypeDef *hrtc, uint32_t Timeout);
1682 HAL_StatusTypeDef HAL_RTCEx_PollForTamper3Event(RTC_HandleTypeDef *hrtc, uint32_t Timeout);
1683 void              HAL_RTCEx_Tamper1EventCallback(RTC_HandleTypeDef *hrtc);
1684 void              HAL_RTCEx_Tamper2EventCallback(RTC_HandleTypeDef *hrtc);
1685 void              HAL_RTCEx_Tamper3EventCallback(RTC_HandleTypeDef *hrtc);
1686 #if defined(TAMP)
1687 HAL_StatusTypeDef HAL_RTCEx_SetInternalTamper(RTC_HandleTypeDef *hrtc, RTC_InternalTamperTypeDef *sIntTamper);
1688 HAL_StatusTypeDef HAL_RTCEx_SetInternalTamper_IT(RTC_HandleTypeDef *hrtc, RTC_InternalTamperTypeDef *sIntTamper);
1689 HAL_StatusTypeDef HAL_RTCEx_DeactivateInternalTamper(RTC_HandleTypeDef *hrtc, uint32_t IntTamper);
1690 HAL_StatusTypeDef HAL_RTCEx_PollForInternalTamperEvent(RTC_HandleTypeDef *hrtc, uint32_t IntTamper, uint32_t Timeout);
1691 void              HAL_RTCEx_InternalTamper1EventCallback(RTC_HandleTypeDef *hrtc);
1692 void              HAL_RTCEx_InternalTamper2EventCallback(RTC_HandleTypeDef *hrtc);
1693 void              HAL_RTCEx_InternalTamper3EventCallback(RTC_HandleTypeDef *hrtc);
1694 void              HAL_RTCEx_InternalTamper4EventCallback(RTC_HandleTypeDef *hrtc);
1695 void              HAL_RTCEx_InternalTamper5EventCallback(RTC_HandleTypeDef *hrtc);
1696 void              HAL_RTCEx_InternalTamper6EventCallback(RTC_HandleTypeDef *hrtc);
1697 void              HAL_RTCEx_InternalTamper8EventCallback(RTC_HandleTypeDef *hrtc);
1698 HAL_StatusTypeDef HAL_RTCEx_SetActiveTampers(RTC_HandleTypeDef *hrtc, RTC_ActiveTampersTypeDef *sAllTamper);
1699 HAL_StatusTypeDef HAL_RTCEx_SetActiveSeed(RTC_HandleTypeDef *hrtc, uint32_t *pSeed);
1700 HAL_StatusTypeDef HAL_RTCEx_DeactivateActiveTampers(RTC_HandleTypeDef *hrtc);
1701 #endif /* TAMP */
1702 
1703 /**
1704   * @}
1705   */
1706 
1707 /* ========================================================================== */
1708 /*                   ##### RTC Wake-up exported functions #####               */
1709 /* ========================================================================== */
1710 
1711 /* RTC Wake-up functions ******************************************************/
1712 
1713 /** @defgroup RTCEx_Exported_Functions_Group2 Extended RTC Wake-up functions
1714   * @{
1715   */
1716 HAL_StatusTypeDef HAL_RTCEx_SetWakeUpTimer(RTC_HandleTypeDef *hrtc, uint32_t WakeUpCounter, uint32_t WakeUpClock);
1717 HAL_StatusTypeDef HAL_RTCEx_SetWakeUpTimer_IT(RTC_HandleTypeDef *hrtc, uint32_t WakeUpCounter, uint32_t WakeUpClock);
1718 HAL_StatusTypeDef HAL_RTCEx_DeactivateWakeUpTimer(RTC_HandleTypeDef *hrtc);
1719 uint32_t          HAL_RTCEx_GetWakeUpTimer(RTC_HandleTypeDef *hrtc);
1720 void              HAL_RTCEx_WakeUpTimerIRQHandler(RTC_HandleTypeDef *hrtc);
1721 void              HAL_RTCEx_WakeUpTimerEventCallback(RTC_HandleTypeDef *hrtc);
1722 HAL_StatusTypeDef HAL_RTCEx_PollForWakeUpTimerEvent(RTC_HandleTypeDef *hrtc, uint32_t Timeout);
1723 /**
1724   * @}
1725   */
1726 
1727 /* ========================================================================== */
1728 /*         ##### Extended RTC Backup registers exported functions #####       */
1729 /* ========================================================================== */
1730 
1731 /* Extended RTC Backup registers functions ************************************/
1732 
1733 /** @defgroup RTCEx_Exported_Functions_Group6 Extended RTC Backup register functions
1734   * @{
1735   */
1736 void     HAL_RTCEx_BKUPWrite(RTC_HandleTypeDef *hrtc, uint32_t BackupRegister, uint32_t Data);
1737 uint32_t HAL_RTCEx_BKUPRead(RTC_HandleTypeDef *hrtc, uint32_t BackupRegister);
1738 /**
1739   * @}
1740   */
1741 
1742 /* ========================================================================== */
1743 /*        ##### Extended RTC Peripheral Control exported functions #####      */
1744 /* ========================================================================== */
1745 
1746 /* Extended RTC Peripheral Control functions **********************************/
1747 
1748 /** @defgroup RTCEx_Exported_Functions_Group3 Extended Peripheral Control functions
1749   * @{
1750   */
1751 HAL_StatusTypeDef HAL_RTCEx_SetSmoothCalib(RTC_HandleTypeDef *hrtc, uint32_t SmoothCalibPeriod, uint32_t SmoothCalibPlusPulses, uint32_t SmoothCalibMinusPulsesValue);
1752 HAL_StatusTypeDef HAL_RTCEx_SetSynchroShift(RTC_HandleTypeDef *hrtc, uint32_t ShiftAdd1S, uint32_t ShiftSubFS);
1753 HAL_StatusTypeDef HAL_RTCEx_SetCalibrationOutPut(RTC_HandleTypeDef *hrtc, uint32_t CalibOutput);
1754 HAL_StatusTypeDef HAL_RTCEx_DeactivateCalibrationOutPut(RTC_HandleTypeDef *hrtc);
1755 HAL_StatusTypeDef HAL_RTCEx_SetRefClock(RTC_HandleTypeDef *hrtc);
1756 HAL_StatusTypeDef HAL_RTCEx_DeactivateRefClock(RTC_HandleTypeDef *hrtc);
1757 HAL_StatusTypeDef HAL_RTCEx_EnableBypassShadow(RTC_HandleTypeDef *hrtc);
1758 HAL_StatusTypeDef HAL_RTCEx_DisableBypassShadow(RTC_HandleTypeDef *hrtc);
1759 #if defined(TAMP)
1760 HAL_StatusTypeDef HAL_RTCEx_MonotonicCounterIncrement(RTC_HandleTypeDef *hrtc,  uint32_t Instance);
1761 HAL_StatusTypeDef HAL_RTCEx_MonotonicCounterGet(RTC_HandleTypeDef *hrtc, uint32_t *Counter,  uint32_t Instance);
1762 #endif /* TAMP */
1763 /**
1764   * @}
1765   */
1766 
1767 /* Extended RTC features functions *******************************************/
1768 
1769 /** @defgroup RTCEx_Exported_Functions_Group4 Extended features functions
1770   * @{
1771   */
1772 
1773 void              HAL_RTCEx_AlarmBEventCallback(RTC_HandleTypeDef *hrtc);
1774 HAL_StatusTypeDef HAL_RTCEx_PollForAlarmBEvent(RTC_HandleTypeDef *hrtc, uint32_t Timeout);
1775 /**
1776   * @}
1777   */
1778 
1779 /**
1780   * @}
1781   */
1782 
1783 /* Private types -------------------------------------------------------------*/
1784 /* Private variables ---------------------------------------------------------*/
1785 /* Private constants ---------------------------------------------------------*/
1786 /** @defgroup RTCEx_Private_Constants RTC Private Constants
1787   * @{
1788   */
1789 #define RTC_EXTI_LINE_TAMPER_TIMESTAMP_EVENT  EXTI_IMR1_IM18  /*!< External interrupt line 18 Connected to the RTC Tamper and Time Stamp events */
1790 #define RTC_EXTI_LINE_WAKEUPTIMER_EVENT       EXTI_IMR1_IM19  /*!< External interrupt line 19 Connected to the RTC Wakeup event */
1791 
1792 /* Masks Definition */
1793 #define RTC_TAMPER_X             ((uint32_t) (RTC_TAMPER_1 | RTC_TAMPER_2 | RTC_TAMPER_3))
1794 #define RTC_TAMPER_X_INTERRUPT   ((uint32_t) (RTC_IT_TAMP1 | RTC_IT_TAMP2 | RTC_IT_TAMP3))
1795 
1796 /**
1797   * @}
1798   */
1799 
1800 /* Private macros ------------------------------------------------------------*/
1801 /** @defgroup RTCEx_Private_Macros RTC Private Macros
1802   * @{
1803   */
1804 
1805 /** @defgroup RTCEx_IS_RTC_Definitions Private macros to check input parameters
1806   * @{
1807   */
1808 
1809 /* ========================================================================== */
1810 /*          ##### Extended RTC Backup registers private macros #####          */
1811 /* ========================================================================== */
1812 
1813 #define IS_RTC_BKP(__BKP__)                   ((__BKP__) < BKP_REG_NUMBER)
1814 
1815 /* ========================================================================== */
1816 /*                  ##### RTC TimeStamp private macros #####                  */
1817 /* ========================================================================== */
1818 
1819 #define IS_TIMESTAMP_EDGE(EDGE) (((EDGE) == RTC_TIMESTAMPEDGE_RISING) || \
1820                                  ((EDGE) == RTC_TIMESTAMPEDGE_FALLING))
1821 
1822 #define IS_RTC_TIMESTAMP_PIN(PIN) (((PIN) == RTC_TIMESTAMPPIN_DEFAULT))
1823 
1824 /* ========================================================================== */
1825 /*                    ##### RTC Wake-up private macros #####                  */
1826 /* ========================================================================== */
1827 
1828 #define IS_RTC_WAKEUP_CLOCK(CLOCK) (((CLOCK) == RTC_WAKEUPCLOCK_RTCCLK_DIV16)       || \
1829                                     ((CLOCK) == RTC_WAKEUPCLOCK_RTCCLK_DIV8)    || \
1830                                     ((CLOCK) == RTC_WAKEUPCLOCK_RTCCLK_DIV4)    || \
1831                                     ((CLOCK) == RTC_WAKEUPCLOCK_RTCCLK_DIV2)    || \
1832                                     ((CLOCK) == RTC_WAKEUPCLOCK_CK_SPRE_16BITS) || \
1833                                     ((CLOCK) == RTC_WAKEUPCLOCK_CK_SPRE_17BITS))
1834 
1835 #define IS_RTC_WAKEUP_COUNTER(COUNTER)  ((COUNTER) <= RTC_WUTR_WUT)
1836 
1837 /* ========================================================================== */
1838 /*               ##### RTC Smooth Calibration private macros #####            */
1839 /* ========================================================================== */
1840 
1841 #define IS_RTC_SMOOTH_CALIB_PERIOD(PERIOD) (((PERIOD) == RTC_SMOOTHCALIB_PERIOD_32SEC) || \
1842                                             ((PERIOD) == RTC_SMOOTHCALIB_PERIOD_16SEC) || \
1843                                             ((PERIOD) == RTC_SMOOTHCALIB_PERIOD_8SEC))
1844 
1845 #define IS_RTC_SMOOTH_CALIB_PLUS(PLUS) (((PLUS) == RTC_SMOOTHCALIB_PLUSPULSES_SET) || \
1846                                         ((PLUS) == RTC_SMOOTHCALIB_PLUSPULSES_RESET))
1847 
1848 #define  IS_RTC_SMOOTH_CALIB_MINUS(VALUE) ((VALUE) <= RTC_CALR_CALM)
1849 
1850 /* ========================================================================== */
1851 /*          ##### Extended RTC Peripheral Control private macros #####        */
1852 /* ========================================================================== */
1853 
1854 #define IS_RTC_SHIFT_ADD1S(SEL) (((SEL) == RTC_SHIFTADD1S_RESET) || \
1855                                  ((SEL) == RTC_SHIFTADD1S_SET))
1856 
1857 #define IS_RTC_SHIFT_SUBFS(FS) ((FS) <= RTC_SHIFTR_SUBFS)
1858 
1859 #define IS_RTC_CALIB_OUTPUT(OUTPUT)  (((OUTPUT) == RTC_CALIBOUTPUT_512HZ) || \
1860                                       ((OUTPUT) == RTC_CALIBOUTPUT_1HZ))
1861 
1862 /* ========================================================================== */
1863 /*                    ##### RTC Tamper private macros #####                   */
1864 /* ========================================================================== */
1865 
1866 #define IS_RTC_TAMPER(__TAMPER__)  ((((__TAMPER__) &  RTC_TAMPER_X) != 0x00U) &&  \
1867                                     (((__TAMPER__) & ~RTC_TAMPER_X) == 0x00U))
1868 
1869 #define IS_RTC_TAMPER_INTERRUPT(__INTERRUPT__)                                                           \
1870               ((((__INTERRUPT__) & (  RTC_TAMPER_X_INTERRUPT | RTC_IT_TAMPALL )) != 0x00U) &&  \
1871                (((__INTERRUPT__) & (~(RTC_TAMPER_X_INTERRUPT | RTC_IT_TAMPALL))) == 0x00U))
1872 
1873 #define IS_RTC_TAMPER_TRIGGER(__TRIGGER__) (((__TRIGGER__) == RTC_TAMPERTRIGGER_RISINGEDGE)    || \
1874                                             ((__TRIGGER__) == RTC_TAMPERTRIGGER_FALLINGEDGE)   || \
1875                                             ((__TRIGGER__) == RTC_TAMPERTRIGGER_LOWLEVEL)      || \
1876                                             ((__TRIGGER__) == RTC_TAMPERTRIGGER_HIGHLEVEL))
1877 
1878 #define IS_RTC_TAMPER_ERASE_MODE(__MODE__)             (((__MODE__) == RTC_TAMPER_ERASE_BACKUP_ENABLE) || \
1879                                                         ((__MODE__) == RTC_TAMPER_ERASE_BACKUP_DISABLE))
1880 
1881 #define IS_RTC_TAMPER_MASKFLAG_STATE(__STATE__)        (((__STATE__) == RTC_TAMPERMASK_FLAG_ENABLE) || \
1882                                                         ((__STATE__) == RTC_TAMPERMASK_FLAG_DISABLE))
1883 
1884 #define IS_RTC_TAMPER_FILTER(__FILTER__)  (((__FILTER__) == RTC_TAMPERFILTER_DISABLE) || \
1885                                            ((__FILTER__) == RTC_TAMPERFILTER_2SAMPLE) || \
1886                                            ((__FILTER__) == RTC_TAMPERFILTER_4SAMPLE) || \
1887                                            ((__FILTER__) == RTC_TAMPERFILTER_8SAMPLE))
1888 
1889 #define IS_RTC_TAMPER_SAMPLING_FREQ(__FREQ__) (((__FREQ__) == RTC_TAMPERSAMPLINGFREQ_RTCCLK_DIV32768)|| \
1890                                                ((__FREQ__) == RTC_TAMPERSAMPLINGFREQ_RTCCLK_DIV16384)|| \
1891                                                ((__FREQ__) == RTC_TAMPERSAMPLINGFREQ_RTCCLK_DIV8192) || \
1892                                                ((__FREQ__) == RTC_TAMPERSAMPLINGFREQ_RTCCLK_DIV4096) || \
1893                                                ((__FREQ__) == RTC_TAMPERSAMPLINGFREQ_RTCCLK_DIV2048) || \
1894                                                ((__FREQ__) == RTC_TAMPERSAMPLINGFREQ_RTCCLK_DIV1024) || \
1895                                                ((__FREQ__) == RTC_TAMPERSAMPLINGFREQ_RTCCLK_DIV512)  || \
1896                                                ((__FREQ__) == RTC_TAMPERSAMPLINGFREQ_RTCCLK_DIV256))
1897 
1898 #define IS_RTC_TAMPER_PRECHARGE_DURATION(__DURATION__) (((__DURATION__) == RTC_TAMPERPRECHARGEDURATION_1RTCCLK) || \
1899                                                         ((__DURATION__) == RTC_TAMPERPRECHARGEDURATION_2RTCCLK) || \
1900                                                         ((__DURATION__) == RTC_TAMPERPRECHARGEDURATION_4RTCCLK) || \
1901                                                         ((__DURATION__) == RTC_TAMPERPRECHARGEDURATION_8RTCCLK))
1902 
1903 #define IS_RTC_TAMPER_PULLUP_STATE(__STATE__) (((__STATE__) == RTC_TAMPER_PULLUP_ENABLE) || \
1904                                                ((__STATE__) == RTC_TAMPER_PULLUP_DISABLE))
1905 
1906 #define IS_RTC_TAMPER_TIMESTAMPONTAMPER_DETECTION(__DETECTION__) (((__DETECTION__) == RTC_TIMESTAMPONTAMPERDETECTION_ENABLE) || \
1907                                                                   ((__DETECTION__) == RTC_TIMESTAMPONTAMPERDETECTION_DISABLE))
1908 
1909 #if defined(TAMP)
1910 #define IS_RTC_TAMPER_TAMPERDETECTIONOUTPUT(__MODE__) (((__MODE__) == RTC_TAMPERDETECTIONOUTPUT_ENABLE) || \
1911                                                        ((__MODE__) == RTC_TAMPERDETECTIONOUTPUT_DISABLE))
1912 #endif /* TAMP */
1913 
1914 #define IS_RTC_TAMPER_FILTER_CONFIG_CORRECT(FILTER, TRIGGER)            \
1915                   (  (  ((FILTER) != RTC_TAMPERFILTER_DISABLE)          \
1916                      && (  ((TRIGGER) == RTC_TAMPERTRIGGER_LOWLEVEL)    \
1917                         || ((TRIGGER) == RTC_TAMPERTRIGGER_HIGHLEVEL))) \
1918                   || (  ((FILTER) == RTC_TAMPERFILTER_DISABLE)          \
1919                      && (  ((TRIGGER) == RTC_TAMPERTRIGGER_RISINGEDGE)  \
1920                         || ((TRIGGER) == RTC_TAMPERTRIGGER_FALLINGEDGE))))
1921 
1922 #define IS_RTC_INTERNAL_TAMPER(__INT_TAMPER__)   ((((__INT_TAMPER__) &  RTC_INT_TAMPER_ALL) != 0x00U) && \
1923                                                   (((__INT_TAMPER__) & ~RTC_INT_TAMPER_ALL) == 0x00U))
1924 
1925 /**
1926   * @}
1927   */
1928 
1929 /**
1930   * @}
1931   */
1932 
1933 /**
1934   * @}
1935   */
1936 
1937 /**
1938   * @}
1939   */
1940 
1941 #ifdef __cplusplus
1942 }
1943 #endif /* __cplusplus */
1944 
1945 #endif /* STM32H7xx_HAL_RTC_EX_H */
1946 
1947