1 /**
2   ******************************************************************************
3   * @file    stm32wbaxx_hal_rtc_ex.h
4   * @author  MCD Application Team
5   * @brief   Header file of RTC HAL Extended module.
6   ******************************************************************************
7   * @attention
8   *
9   * Copyright (c) 2022 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 STM32WBAxx_HAL_RTC_EX_H
21 #define STM32WBAxx_HAL_RTC_EX_H
22 
23 #ifdef __cplusplus
24 extern "C" {
25 #endif
26 
27 /* Includes ------------------------------------------------------------------*/
28 #include "stm32wbaxx_hal_def.h"
29 
30 /** @addtogroup STM32WBAxx_HAL_Driver
31   * @{
32   */
33 
34 /** @defgroup RTCEx RTCEx
35   * @{
36   */
37 
38 /* Exported types ------------------------------------------------------------*/
39 /** @defgroup RTCEx_Exported_Types RTCEx Exported Types
40   * @{
41   */
42 
43 /** @defgroup RTCEx_Tamper_structure_definition RTCEx Tamper structure definition
44   * @{
45   */
46 typedef struct
47 {
48   uint32_t Tamper;                      /*!< Specifies the Tamper Pin.
49                                              This parameter can be a value of @ref RTCEx_Tamper_Pins */
50 
51   uint32_t Trigger;                     /*!< Specifies the Tamper Trigger.
52                                              This parameter can be a value of @ref RTCEx_Tamper_Trigger */
53 
54   uint32_t NoErase;                     /*!< Specifies the Tamper no erase mode.
55                                              This parameter can be a value of @ref RTCEx_Tamper_EraseBackUp */
56 
57   uint32_t MaskFlag;                    /*!< Specifies the Tamper Flag masking.
58                                              This parameter can be a value of @ref RTCEx_Tamper_MaskFlag */
59 
60   uint32_t Filter;                      /*!< Specifies the TAMP Filter Tamper.
61                                              This parameter can be a value of @ref RTCEx_Tamper_Filter */
62 
63   uint32_t SamplingFrequency;           /*!< Specifies the sampling frequency.
64                                              This parameter can be a value of
65                                              @ref RTCEx_Tamper_Sampling_Frequencies */
66 
67   uint32_t PrechargeDuration;           /*!< Specifies the Precharge Duration.
68                                              This parameter can be a value of
69                                              @ref RTCEx_Tamper_Pin_Precharge_Duration */
70 
71   uint32_t TamperPullUp;                /*!< Specifies the Tamper PullUp.
72                                              This parameter can be a value of @ref RTCEx_Tamper_Pull_UP */
73 
74   uint32_t TimeStampOnTamperDetection;  /*!< Specifies the TimeStampOnTamperDetection.
75                                              This parameter can be a value of
76                                               @ref RTCEx_Tamper_TimeStampOnTamperDetection */
77 } RTC_TamperTypeDef;
78 /**
79   * @}
80   */
81 
82 
83 /** @defgroup RTCEx_Active_Seed_Size Seed size Definitions
84   * @{
85   */
86 #define RTC_ATAMP_SEED_NB_UINT32        4U
87 /**
88   * @}
89   */
90 
91 
92 /** @defgroup RTCEx_ActiveTamper_structures_definition RTCEx Active Tamper structures definitions
93   * @{
94   */
95 typedef struct
96 {
97   uint32_t Enable;                      /*!< Specifies the Tamper input is active.
98                                              This parameter can be a value of @ref RTCEx_ActiveTamper_Enable */
99 
100   uint32_t Interrupt;                    /*!< Specifies the interrupt mode.
101                                              This parameter can be a value of @ref RTCEx_ActiveTamper_Interrupt */
102 
103   uint32_t Output;                      /*!< Specifies the TAMP output to be compared with.
104                                              The same output can be used for several tamper inputs.
105                                              This parameter can be a value of @ref RTCEx_ActiveTamper_Sel */
106 
107   uint32_t NoErase;                     /*!< Specifies the Tamper no erase mode.
108                                              This parameter can be a value of @ref RTCEx_Tamper_EraseBackUp */
109 
110   uint32_t MaskFlag;                    /*!< Specifies the Tamper Flag masking.
111                                              This parameter can be a value of @ref RTCEx_Tamper_MaskFlag */
112 
113 } RTC_ATampInputTypeDef;
114 
115 
116 typedef struct
117 {
118   uint32_t ActiveFilter;                /*!< Specifies the Active tamper filter enable.
119                                              This parameter can be a value of @ref RTCEx_ActiveTamper_Filter */
120 
121   uint32_t ActiveAsyncPrescaler;        /*!< Specifies the Active Tamper asynchronous Prescaler clock.
122                                              This parameter can be a value of
123                                              @ref RTCEx_ActiveTamper_Async_prescaler */
124 
125   uint32_t TimeStampOnTamperDetection;  /*!< Specifies the timeStamp on tamper detection.
126                                              This parameter can be a value of
127                                              @ref RTCEx_Tamper_TimeStampOnTamperDetection */
128 
129   uint32_t ActiveOutputChangePeriod;    /*!< Specifies the Active Tamper output change period.
130                                              This parameter can be a value from 0 to 7 */
131 
132   uint32_t Seed[RTC_ATAMP_SEED_NB_UINT32];
133   /*!< Specifies the RNG Seed value.
134        This parameter is an array of value from 0 to 0xFFFFFFFF */
135 
136   RTC_ATampInputTypeDef TampInput[RTC_TAMP_NB];
137   /*!< Specifies configuration of all active tampers.
138        The index of TampInput[RTC_TAMP_NB] can be a value of RTCEx_ActiveTamper_Sel */
139 } RTC_ActiveTampersTypeDef;
140 /**
141   * @}
142   */
143 
144 /** @defgroup RTCEx_Internal_Tamper_structure_definition RTCEx Internal Tamper structure definition
145   * @{
146   */
147 typedef struct
148 {
149   uint32_t IntTamper;                   /*!< Specifies the Internal Tamper Pin.
150                                              This parameter can be a value of @ref RTCEx_Internal_Tamper_Pins */
151 
152   uint32_t TimeStampOnTamperDetection;  /*!< Specifies the TimeStampOnTamperDetection.
153                                              This parameter can be a value of
154                                              @ref RTCEx_Tamper_TimeStampOnTamperDetection */
155 
156   uint32_t NoErase;                     /*!< Specifies the internal Tamper no erase mode.
157                                              This parameter can be a value of @ref RTCEx_Tamper_EraseBackUp */
158 
159 } RTC_InternalTamperTypeDef;
160 /**
161   * @}
162   */
163 
164 /** @defgroup RTCEx_Secure_State_structure_definition RTCEx Secure structure definition
165   * @{
166   */
167 typedef struct
168 {
169   uint32_t rtcSecureFull;               /*!< Specifies If the RTC is fully secure or not.
170                                              This parameter can be a value of @ref RTCEx_RTC_Secure_Full */
171 
172   uint32_t rtcNonSecureFeatures;        /*!< Specifies the non-secure features.
173                                              This parameter is only relevant if RTC is not fully secure
174                                              (rtcSecureFull == RTC_SECURE_FULL_NO).
175                                              This parameter can be a combination of
176                                              @ref RTCEx_RTC_NonSecure_Features */
177 
178   uint32_t tampSecureFull;              /*!< Specifies If the TAMP is fully secure or not execpt monotonic counters
179                                              and BackUp registers.
180                                              This parameter can be a value of @ref RTCEx_TAMP_Secure_Full */
181 
182   uint32_t backupRegisterStartZone2;    /*!< Specifies the backup register start zone 2.
183                                              Zone 1 : read secure write secure.
184                                              Zone 2 : read non-secure  write secure.
185                                              This parameter can be RTC_BKP_DRx where x can be from 0 to 31 to specify
186                                              the register.
187                                              Warning : this parameter is shared with RTC_PrivilegeStateTypeDef */
188 
189   uint32_t backupRegisterStartZone3;    /*!< Specifies the backup register start zone 3.
190                                              Zone 3 : read non-secure  write non-secure.
191                                              This parameter can be RTC_BKP_DRx where x can be from 0 to 31 to
192                                              specify the register.
193                                              Warning : this parameter is shared with RTC_PrivilegeStateTypeDef */
194 
195   uint32_t MonotonicCounterSecure;      /*!< Specifies If the monotonic counter is secure or not.
196                                              This parameter can be a value of
197                                              @ref RTCEx_TAMP_Monotonic_Counter_Secure */
198 } RTC_SecureStateTypeDef;
199 /**
200   * @}
201   */
202 
203 /** @defgroup RTCEx_Privilege_State_structure_definition RTCEx Privilege structure definition
204   * @{
205   */
206 typedef struct
207 {
208   uint32_t rtcPrivilegeFull;            /*!< Specifies If the RTC is fully privileged or not.
209                                              This parameter can be a value of @ref RTCEx_RTC_Privilege_Full */
210 
211   uint32_t rtcPrivilegeFeatures;        /*!< Specifies the privileged features.
212                                              This parameter is only relevant if RTC is not fully privileged
213                                              (rtcPrivilegeFull == RTC_PRIVILEGE_FULL_NO).
214                                              This parameter can be a combination of
215                                              @ref RTCEx_RTC_Privilege_Features */
216 
217   uint32_t tampPrivilegeFull;           /*!< Specifies If the TAMP is fully privileged or not execpt monotonic
218                                              counters and BackUp registers.
219                                              This parameter can be a value of @ref RTCEx_TAMP_Privilege_Full */
220 
221   uint32_t backupRegisterPrivZone;      /*!< Specifies backup register zone to be privileged.
222                                              This parameter can be a combination of
223                                              @ref RTCEx_Backup_Reg_Privilege_zone.
224                                              Warning : this parameter is writable in secure mode or if trustzone is
225                                              disabled */
226 
227   uint32_t backupRegisterStartZone2;    /*!< Specifies the backup register start zone 2.
228                                              Zone 1 : read secure write secure.
229                                              Zone 2 : read non-secure  write secure.
230                                              This parameter can be RTC_BKP_DRx where x can be from 0 to 31 to specify
231                                              the register .
232                                              Warning : this parameter is writable in secure mode or if trustzone is
233                                              disabled.
234                                              Warning : this parameter is shared with RTC_SecureStateTypeDef */
235 
236   uint32_t backupRegisterStartZone3;    /*!< Specifies the backup register start zone 3.
237                                              Zone 3 : read non-secure  write non-secure.
238                                              This parameter can be RTC_BKP_DRx where x can be from 0 to 31 to specify
239                                              the register.
240                                              Warning : this parameter is writable in secure mode or if trustzone is
241                                              disabled.
242                                              Warning : this parameter is shared with RTC_SecureStateTypeDef */
243 
244   uint32_t MonotonicCounterPrivilege;   /*!< Specifies If the monotonic counter is privileged or not.
245                                              This parameter can be a value of
246                                              @ref RTCEx_TAMP_Monotonic_Counter_Privilege */
247 } RTC_PrivilegeStateTypeDef;
248 /**
249   * @}
250   */
251 
252 /**
253   * @}
254   */
255 
256 /* Exported constants --------------------------------------------------------*/
257 /** @defgroup RTCEx_Exported_Constants RTCEx Exported Constants
258   * @{
259   */
260 
261 #if defined(RTC_CR_TSEDGE)
262 /** @defgroup RTCEx_Time_Stamp_Edges_definitions RTCEx Time Stamp Edges definition
263   * @{
264   */
265 #define RTC_TIMESTAMPEDGE_RISING           0U
266 #define RTC_TIMESTAMPEDGE_FALLING          RTC_CR_TSEDGE
267 /**
268   * @}
269   */
270 #endif /* RTC_CR_TSEDGE */
271 
272 /** @defgroup RTCEx_TimeStamp_Pin_Selections RTCEx TimeStamp Pin Selection
273   * @{
274   */
275 #define RTC_TIMESTAMPPIN_DEFAULT           0U
276 /**
277   * @}
278   */
279 
280 /** @defgroup RTCEx_Wakeup_Timer_Definitions RTCEx Wakeup Timer Definitions
281   * @{
282   */
283 #define RTC_WAKEUPCLOCK_RTCCLK_DIV16       0U
284 #define RTC_WAKEUPCLOCK_RTCCLK_DIV8        RTC_CR_WUCKSEL_0
285 #define RTC_WAKEUPCLOCK_RTCCLK_DIV4        RTC_CR_WUCKSEL_1
286 #define RTC_WAKEUPCLOCK_RTCCLK_DIV2        (RTC_CR_WUCKSEL_0 | RTC_CR_WUCKSEL_1)
287 #define RTC_WAKEUPCLOCK_CK_SPRE_16BITS     RTC_CR_WUCKSEL_2
288 #define RTC_WAKEUPCLOCK_CK_SPRE_17BITS     (RTC_CR_WUCKSEL_1 | RTC_CR_WUCKSEL_2)
289 /**
290   * @}
291   */
292 
293 /** @defgroup RTCEx_Smooth_calib_period_Definitions RTCEx Smooth calib period Definitions
294   * @{
295   */
296 #define RTC_SMOOTHCALIB_PERIOD_32SEC       0U                    /*!< If RTCCLK = 32768 Hz, Smooth calibration period
297                                                                       is 32s, else 2exp20 RTCCLK pulses */
298 #define RTC_SMOOTHCALIB_PERIOD_16SEC       RTC_CALR_CALW16       /*!< If RTCCLK = 32768 Hz, Smooth calibration period
299                                                                       is 16s, else 2exp19 RTCCLK pulses */
300 #define RTC_SMOOTHCALIB_PERIOD_8SEC        RTC_CALR_CALW8        /*!< If RTCCLK = 32768 Hz, Smooth calibration period
301                                                                       is 8s, else 2exp18 RTCCLK pulses  */
302 /**
303   * @}
304   */
305 
306 /** @defgroup RTCEx_Smooth_calib_Plus_pulses_Definitions RTCEx Smooth calib Plus pulses Definitions
307   * @{
308   */
309 #define RTC_SMOOTHCALIB_PLUSPULSES_SET     RTC_CALR_CALP         /*!< The number of RTCCLK pulses added
310                                                                       during a X -second window = Y - CALM[8:0]
311                                                                       with Y = 512, 256, 128 when X = 32, 16, 8 */
312 #define RTC_SMOOTHCALIB_PLUSPULSES_RESET   0U                    /*!< The number of RTCCLK pulses subbstited
313                                                                       during a 32-second window = CALM[8:0]     */
314 /**
315   * @}
316   */
317 
318 /** @defgroup RTCEx_Smooth_calib_low_power_Definitions RTCEx Smooth calib Low Power Definitions
319   * @{
320   */
321 #define RTC_LPCAL_SET                      RTC_CALR_LPCAL        /*!< Calibration window is 2exp20 ck_apre, which is the required configuration for ultra-low consumption mode. */
322 #define RTC_LPCAL_RESET                    0U                    /*!< Calibration window is 2exp20 RTCCLK, which is a high-consumption mode.
323                                                                       This mode should be set only when less
324                                                                       than 32s calibration window is required. */
325 /**
326   * @}
327   */
328 
329 #if defined(RTC_CR_COSEL)
330 /** @defgroup RTCEx_Calib_Output_selection_Definitions RTCEx Calib Output selection Definitions
331   * @{
332   */
333 #define RTC_CALIBOUTPUT_512HZ              0U
334 #define RTC_CALIBOUTPUT_1HZ                RTC_CR_COSEL
335 /**
336   * @}
337   */
338 #endif /* RTC_CR_COSEL */
339 
340 /** @defgroup RTCEx_Add_1_Second_Parameter_Definition RTCEx Add 1 Second Parameter Definitions
341   * @{
342   */
343 #define RTC_SHIFTADD1S_RESET               0U
344 #define RTC_SHIFTADD1S_SET                 RTC_SHIFTR_ADD1S
345 /**
346   * @}
347   */
348 
349 /** @defgroup RTCEx_Tamper_Pins  RTCEx Tamper Pins Definition
350   * @{
351   */
352 #define RTC_TAMPER_1                       TAMP_CR1_TAMP1E
353 #define RTC_TAMPER_2                       TAMP_CR1_TAMP2E
354 #define RTC_TAMPER_3                       TAMP_CR1_TAMP3E
355 #ifdef TAMP_CR1_TAMP4E
356 #define RTC_TAMPER_4                       TAMP_CR1_TAMP4E
357 #define RTC_TAMPER_5                       TAMP_CR1_TAMP5E
358 #define RTC_TAMPER_6                       TAMP_CR1_TAMP6E
359 #endif /* TAMP_CR1_TAMP4E */
360 
361 #ifdef TAMP_CR1_TAMP4E
362 #define RTC_TAMPER_ALL                     (RTC_TAMPER_1 | RTC_TAMPER_2 |\
363                                             RTC_TAMPER_3 | RTC_TAMPER_4 |\
364                                             RTC_TAMPER_5 | RTC_TAMPER_6)
365 #else
366 #define RTC_TAMPER_ALL                     (RTC_TAMPER_1 | RTC_TAMPER_2 |\
367                                             RTC_TAMPER_3)
368 #endif /* TAMP_CR1_TAMP4E */
369 /**
370   * @}
371   */
372 
373 /** @defgroup RTCEx_Internal_Tamper_Pins  RTCEx Internal Tamper Pins Definition
374   * @{
375   */
376 #define RTC_INT_TAMPER_3                   TAMP_CR1_ITAMP3E
377 #define RTC_INT_TAMPER_5                   TAMP_CR1_ITAMP5E
378 #define RTC_INT_TAMPER_6                   TAMP_CR1_ITAMP6E
379 #define RTC_INT_TAMPER_7                   TAMP_CR1_ITAMP7E
380 #define RTC_INT_TAMPER_8                   TAMP_CR1_ITAMP8E
381 #define RTC_INT_TAMPER_9                   TAMP_CR1_ITAMP9E
382 #define RTC_INT_TAMPER_11                  TAMP_CR1_ITAMP11E
383 #define RTC_INT_TAMPER_12                  TAMP_CR1_ITAMP12E
384 #define RTC_INT_TAMPER_13                  TAMP_CR1_ITAMP13E
385 
386 #define RTC_INT_TAMPER_ALL                 (RTC_INT_TAMPER_3 | RTC_INT_TAMPER_5 |\
387                                             RTC_INT_TAMPER_6 | RTC_INT_TAMPER_7 |\
388                                             RTC_INT_TAMPER_8 | RTC_INT_TAMPER_9 |\
389                                             RTC_INT_TAMPER_11| RTC_INT_TAMPER_12|\
390                                             RTC_INT_TAMPER_13)
391 /**
392   * @}
393   */
394 
395 /** @defgroup RTCEx_Tamper_Trigger  RTCEx Tamper Trigger
396   * @{
397   */
398 #define RTC_TAMPERTRIGGER_RISINGEDGE       0U                    /*!< Warning : Filter must be RTC_TAMPERFILTER_DISABLE */
399 #define RTC_TAMPERTRIGGER_FALLINGEDGE      1U                    /*!< Warning : Filter must be RTC_TAMPERFILTER_DISABLE */
400 #define RTC_TAMPERTRIGGER_LOWLEVEL         2U                    /*!< Warning : Filter must not be RTC_TAMPERFILTER_DISABLE */
401 #define RTC_TAMPERTRIGGER_HIGHLEVEL        3U                    /*!< Warning : Filter must not be RTC_TAMPERFILTER_DISABLE */
402 /**
403   * @}
404   */
405 
406 /** @defgroup RTCEx_Tamper_MaskFlag  RTCEx Tamper MaskFlag
407   * @{
408   */
409 #define RTC_TAMPERMASK_FLAG_DISABLE        0U
410 #define RTC_TAMPERMASK_FLAG_ENABLE         1U
411 /**
412   * @}
413   */
414 
415 /** @defgroup RTCEx_Tamper_Maskable_nb  RTCEx Tampers maskable number
416   * @{
417   */
418 #define RTC_TAMPER_MASKABLE_NB             3U
419 /**
420   * @}
421   */
422 
423 /** @defgroup RTCEx_Tamper_EraseBackUp  RTCEx Tamper EraseBackUp
424   * @{
425   */
426 #define RTC_TAMPER_ERASE_BACKUP_ENABLE     0U
427 #define RTC_TAMPER_ERASE_BACKUP_DISABLE    1U
428 /**
429   * @}
430   */
431 
432 /** @defgroup RTCEx_Tamper_Filter  RTCEx Tamper Filter
433   * @{
434   */
435 #define RTC_TAMPERFILTER_DISABLE           0U                    /*!< Tamper filter is disabled */
436 #define RTC_TAMPERFILTER_2SAMPLE           TAMP_FLTCR_TAMPFLT_0  /*!< Tamper is activated after 2 consecutive samples at the active level */
437 #define RTC_TAMPERFILTER_4SAMPLE           TAMP_FLTCR_TAMPFLT_1  /*!< Tamper is activated after 4 consecutive samples at the active level */
438 #define RTC_TAMPERFILTER_8SAMPLE           TAMP_FLTCR_TAMPFLT    /*!< Tamper is activated after 8 consecutive samples at the active level */
439 /**
440   * @}
441   */
442 
443 /** @defgroup RTCEx_Tamper_Sampling_Frequencies  RTCEx Tamper Sampling Frequencies
444   * @{
445   */
446 #define RTC_TAMPERSAMPLINGFREQ_RTCCLK_DIV32768  0U                                                  /*!< Each of the tamper inputs are sampled with a frequency =  RTCCLK / 32768 */
447 #define RTC_TAMPERSAMPLINGFREQ_RTCCLK_DIV16384  TAMP_FLTCR_TAMPFREQ_0                               /*!< Each of the tamper inputs are sampled with a frequency =  RTCCLK / 16384 */
448 #define RTC_TAMPERSAMPLINGFREQ_RTCCLK_DIV8192   TAMP_FLTCR_TAMPFREQ_1                               /*!< Each of the tamper inputs are sampled with a frequency =  RTCCLK / 8192  */
449 #define RTC_TAMPERSAMPLINGFREQ_RTCCLK_DIV4096   (TAMP_FLTCR_TAMPFREQ_0 | TAMP_FLTCR_TAMPFREQ_1)     /*!< Each of the tamper inputs are sampled with a frequency =  RTCCLK / 4096  */
450 #define RTC_TAMPERSAMPLINGFREQ_RTCCLK_DIV2048   TAMP_FLTCR_TAMPFREQ_2                               /*!< Each of the tamper inputs are sampled with a frequency =  RTCCLK / 2048  */
451 #define RTC_TAMPERSAMPLINGFREQ_RTCCLK_DIV1024   (TAMP_FLTCR_TAMPFREQ_0 | TAMP_FLTCR_TAMPFREQ_2)     /*!< Each of the tamper inputs are sampled with a frequency =  RTCCLK / 1024  */
452 #define RTC_TAMPERSAMPLINGFREQ_RTCCLK_DIV512    (TAMP_FLTCR_TAMPFREQ_1 | TAMP_FLTCR_TAMPFREQ_2)     /*!< Each of the tamper inputs are sampled with a frequency =  RTCCLK / 512   */
453 #define RTC_TAMPERSAMPLINGFREQ_RTCCLK_DIV256    (TAMP_FLTCR_TAMPFREQ_0 | TAMP_FLTCR_TAMPFREQ_1 | \
454                                                  TAMP_FLTCR_TAMPFREQ_2)                             /*!< Each of the tamper inputs are sampled with a frequency =  RTCCLK / 256   */
455 /**
456   * @}
457   */
458 
459 /** @defgroup RTCEx_Tamper_Pin_Precharge_Duration  RTCEx Tamper Pin Precharge Duration
460   * @{
461   */
462 #define RTC_TAMPERPRECHARGEDURATION_1RTCCLK  0U                                              /*!< Tamper pins are pre-charged before sampling during 1 RTCCLK cycle  */
463 #define RTC_TAMPERPRECHARGEDURATION_2RTCCLK  TAMP_FLTCR_TAMPPRCH_0                           /*!< Tamper pins are pre-charged before sampling during 2 RTCCLK cycles */
464 #define RTC_TAMPERPRECHARGEDURATION_4RTCCLK  TAMP_FLTCR_TAMPPRCH_1                           /*!< Tamper pins are pre-charged before sampling during 4 RTCCLK cycles */
465 #define RTC_TAMPERPRECHARGEDURATION_8RTCCLK  (TAMP_FLTCR_TAMPPRCH_0 | TAMP_FLTCR_TAMPPRCH_1) /*!< Tamper pins are pre-charged before sampling during 8 RTCCLK cycles */
466 /**
467   * @}
468   */
469 
470 /** @defgroup RTCEx_Tamper_Pull_UP  RTCEx Tamper Pull UP
471   * @{
472   */
473 #define RTC_TAMPER_PULLUP_ENABLE           0U                    /*!< Tamper pins are pre-charged before sampling */
474 #define RTC_TAMPER_PULLUP_DISABLE          TAMP_FLTCR_TAMPPUDIS  /*!< Tamper pins pre-charge is disabled          */
475 /**
476   * @}
477   */
478 
479 /** @defgroup RTCEx_Tamper_TimeStampOnTamperDetection RTCEx Tamper TimeStamp On Tamper Detection Definitions
480   * @{
481   */
482 #define RTC_TIMESTAMPONTAMPERDETECTION_DISABLE  0U               /*!< TimeStamp on Tamper Detection event is not saved */
483 #define RTC_TIMESTAMPONTAMPERDETECTION_ENABLE   RTC_CR_TAMPTS    /*!< TimeStamp on Tamper Detection event saved        */
484 /**
485   * @}
486   */
487 
488 /** @defgroup RTCEx_Tamper_Detection_Output RTCEx Tamper detection output Definitions
489   * @{
490   */
491 #if defined(RTC_CR_TAMPOE)
492 #define RTC_TAMPERDETECTIONOUTPUT_DISABLE  0U                    /*!< Tamper detection output disable on TAMPALRM */
493 #define RTC_TAMPERDETECTIONOUTPUT_ENABLE   RTC_CR_TAMPOE         /*!< Tamper detection output enable on TAMPALRM  */
494 #endif /* RTC_CR_TAMPOE */
495 /**
496   * @}
497   */
498 
499 
500 /** @defgroup RTCEx_Tamper_Interrupt  RTCEx Tamper Interrupt
501   * @{
502   */
503 #define RTC_IT_TAMP_1                      TAMP_IER_TAMP1IE      /*!< Tamper 1 Interrupt */
504 #define RTC_IT_TAMP_2                      TAMP_IER_TAMP2IE      /*!< Tamper 2 Interrupt */
505 #define RTC_IT_TAMP_3                      TAMP_IER_TAMP3IE      /*!< Tamper 3 Interrupt */
506 #ifdef TAMP_IER_TAMP4IE
507 #define RTC_IT_TAMP_4                      TAMP_IER_TAMP4IE      /*!< Tamper 4 Interrupt */
508 #define RTC_IT_TAMP_5                      TAMP_IER_TAMP5IE      /*!< Tamper 5 Interrupt */
509 #define RTC_IT_TAMP_6                      TAMP_IER_TAMP6IE      /*!< Tamper 6 Interrupt */
510 #define RTC_IT_TAMP_ALL                   (RTC_IT_TAMP_1 | RTC_IT_TAMP_2 |\
511                                            RTC_IT_TAMP_3 | RTC_IT_TAMP_4 |\
512                                            RTC_IT_TAMP_5 | RTC_IT_TAMP_6)
513 #else
514 #define RTC_IT_TAMP_ALL                   (RTC_IT_TAMP_1 | RTC_IT_TAMP_2 | RTC_IT_TAMP_3)
515 #endif /* TAMP_IER_TAMP4IE */
516 /**
517   * @}
518   */
519 
520 /** @defgroup RTCEx_Internal_Tamper_Interrupt  RTCEx Internal Tamper Interrupt
521   * @{
522   */
523 #define RTC_IT_INT_TAMP_3                  TAMP_IER_ITAMP3IE     /*!< Tamper 3 internal Interrupt  */
524 #define RTC_IT_INT_TAMP_5                  TAMP_IER_ITAMP5IE     /*!< Tamper 5 internal Interrupt  */
525 #define RTC_IT_INT_TAMP_6                  TAMP_IER_ITAMP6IE     /*!< Tamper 6 internal Interrupt  */
526 #define RTC_IT_INT_TAMP_7                  TAMP_IER_ITAMP7IE     /*!< Tamper 7 internal Interrupt  */
527 #define RTC_IT_INT_TAMP_8                  TAMP_IER_ITAMP8IE     /*!< Tamper 8 internal Interrupt  */
528 #define RTC_IT_INT_TAMP_9                  TAMP_IER_ITAMP9IE     /*!< Tamper 9 internal Interrupt  */
529 #define RTC_IT_INT_TAMP_11                 TAMP_IER_ITAMP11IE    /*!< Tamper 11 internal Interrupt */
530 #define RTC_IT_INT_TAMP_12                 TAMP_IER_ITAMP12IE    /*!< Tamper 12 internal Interrupt */
531 #define RTC_IT_INT_TAMP_13                 TAMP_IER_ITAMP13IE    /*!< Tamper 13 internal Interrupt */
532 #define RTC_IT_INT_TAMP_ALL                (RTC_IT_INT_TAMP_3 | RTC_IT_INT_TAMP_5 |\
533                                             RTC_IT_INT_TAMP_6 | RTC_IT_INT_TAMP_7 |\
534                                             RTC_IT_INT_TAMP_8 | RTC_IT_INT_TAMP_9 |\
535                                             RTC_IT_INT_TAMP_11| RTC_IT_INT_TAMP_12|\
536                                             RTC_IT_INT_TAMP_13)
537 /**
538   * @}
539   */
540 
541 /** @defgroup RTCEx_Flags  RTCEx Flags
542   * @{
543   */
544 #define RTC_FLAG_TAMP_1                    TAMP_SR_TAMP1F
545 #define RTC_FLAG_TAMP_2                    TAMP_SR_TAMP2F
546 #define RTC_FLAG_TAMP_3                    TAMP_SR_TAMP3F
547 #ifdef TAMP_SR_TAMP4F
548 #define RTC_FLAG_TAMP_4                    TAMP_SR_TAMP4F
549 #define RTC_FLAG_TAMP_5                    TAMP_SR_TAMP5F
550 #define RTC_FLAG_TAMP_6                    TAMP_SR_TAMP6F
551 #define RTC_FLAG_TAMP_ALL                  (RTC_FLAG_TAMP_1 | RTC_FLAG_TAMP_2 | RTC_FLAG_TAMP_3 |\
552                                             RTC_FLAG_TAMP_4 | RTC_FLAG_TAMP_5 | RTC_FLAG_TAMP_6)
553 #else
554 #define RTC_FLAG_TAMP_ALL                  (RTC_FLAG_TAMP_1 | RTC_FLAG_TAMP_2 | RTC_FLAG_TAMP_3)
555 #endif /* TAMP_SR_TAMP4F */
556 
557 
558 #define RTC_FLAG_INT_TAMP_3                TAMP_SR_ITAMP3F
559 #define RTC_FLAG_INT_TAMP_5                TAMP_SR_ITAMP5F
560 #define RTC_FLAG_INT_TAMP_6                TAMP_SR_ITAMP6F
561 #define RTC_FLAG_INT_TAMP_7                TAMP_SR_ITAMP7F
562 #define RTC_FLAG_INT_TAMP_8                TAMP_SR_ITAMP8F
563 #define RTC_FLAG_INT_TAMP_9                TAMP_SR_ITAMP9F
564 #define RTC_FLAG_INT_TAMP_11               TAMP_SR_ITAMP11F
565 #define RTC_FLAG_INT_TAMP_12               TAMP_SR_ITAMP12F
566 #define RTC_FLAG_INT_TAMP_13               TAMP_SR_ITAMP13F
567 #define RTC_FLAG_INT_TAMP_ALL              (RTC_FLAG_INT_TAMP_3 | RTC_FLAG_INT_TAMP_5 |\
568                                             RTC_FLAG_INT_TAMP_6 | RTC_FLAG_INT_TAMP_7 |\
569                                             RTC_FLAG_INT_TAMP_8 | RTC_FLAG_INT_TAMP_9 |\
570                                             RTC_FLAG_INT_TAMP_11| RTC_FLAG_INT_TAMP_12|\
571                                             RTC_FLAG_INT_TAMP_13)
572 /**
573   * @}
574   */
575 
576 
577 /** @defgroup RTCEx_ActiveTamper_Enable RTCEx_ActiveTamper_Enable Definitions
578   * @{
579   */
580 #define RTC_ATAMP_ENABLE                   1U
581 #define RTC_ATAMP_DISABLE                  0U
582 /**
583   * @}
584   */
585 
586 /** @defgroup RTCEx_ActiveTamper_Interrupt RTCEx_ActiveTamper_Interrupt Definitions
587   * @{
588   */
589 #define RTC_ATAMP_INTERRUPT_ENABLE         1U
590 #define RTC_ATAMP_INTERRUPT_DISABLE        0U
591 /**
592   * @}
593   */
594 
595 /** @defgroup RTCEx_ActiveTamper_Filter RTCEx_ActiveTamper_Filter Definitions
596   * @{
597   */
598 #define RTC_ATAMP_FILTER_ENABLE            TAMP_ATCR1_FLTEN
599 #define RTC_ATAMP_FILTER_DISABLE           0U
600 /**
601   * @}
602   */
603 
604 /** @defgroup RTCEx_ActiveTamper_Async_prescaler RTCEx Active_Tamper_Asynchronous_Prescaler clock Definitions
605   * @{
606   */
607 #define RTC_ATAMP_ASYNCPRES_RTCCLK         0U                                                                   /*!< RTCCLK     */
608 #define RTC_ATAMP_ASYNCPRES_RTCCLK_2       TAMP_ATCR1_ATCKSEL_0                                                 /*!< RTCCLK/2   */
609 #define RTC_ATAMP_ASYNCPRES_RTCCLK_4       TAMP_ATCR1_ATCKSEL_1                                                 /*!< RTCCLK/4   */
610 #define RTC_ATAMP_ASYNCPRES_RTCCLK_8       (TAMP_ATCR1_ATCKSEL_1 | TAMP_ATCR1_ATCKSEL_0)                        /*!< RTCCLK/8   */
611 #define RTC_ATAMP_ASYNCPRES_RTCCLK_16      TAMP_ATCR1_ATCKSEL_2                                                 /*!< RTCCLK/16  */
612 #define RTC_ATAMP_ASYNCPRES_RTCCLK_32      (TAMP_ATCR1_ATCKSEL_2 | TAMP_ATCR1_ATCKSEL_0)                        /*!< RTCCLK/32  */
613 #define RTC_ATAMP_ASYNCPRES_RTCCLK_64      (TAMP_ATCR1_ATCKSEL_2 | TAMP_ATCR1_ATCKSEL_1)                        /*!< RTCCLK/64  */
614 #define RTC_ATAMP_ASYNCPRES_RTCCLK_128     (TAMP_ATCR1_ATCKSEL_2 | TAMP_ATCR1_ATCKSEL_1 | TAMP_ATCR1_ATCKSEL_0) /*!< RTCCLK/128 */
615 /**
616   * @}
617   */
618 
619 /** @defgroup RTCEx_ActiveTamper_Sel  RTCEx Active Tamper selection Definition
620   * @{
621   */
622 #define RTC_ATAMP_1                        0U                    /*!< Tamper 1 */
623 #define RTC_ATAMP_2                        1U                    /*!< Tamper 2 */
624 #define RTC_ATAMP_3                        2U                    /*!< Tamper 3 */
625 #define RTC_ATAMP_4                        3U                    /*!< Tamper 4 */
626 #define RTC_ATAMP_5                        4U                    /*!< Tamper 5 */
627 #define RTC_ATAMP_6                        5U                    /*!< Tamper 6 */
628 /**
629   * @}
630   */
631 
632 /** @defgroup RTCEx_MonotonicCounter_Instance  RTCEx Monotonic Counter Instance Definition
633   * @{
634   */
635 #define RTC_MONOTONIC_COUNTER_1            0U                    /*!< Monotonic counter 1 */
636 /**
637   * @}
638   */
639 
640 
641 /** @defgroup RTCEx_Backup_Registers  RTCEx Backup Registers Definition
642   * @{
643   */
644 #define RTC_BKP_NUMBER                     RTC_BKP_NB
645 #define RTC_BKP_DR0                        0x00U
646 #define RTC_BKP_DR1                        0x01U
647 #define RTC_BKP_DR2                        0x02U
648 #define RTC_BKP_DR3                        0x03U
649 #define RTC_BKP_DR4                        0x04U
650 #define RTC_BKP_DR5                        0x05U
651 #define RTC_BKP_DR6                        0x06U
652 #define RTC_BKP_DR7                        0x07U
653 #define RTC_BKP_DR8                        0x08U
654 #define RTC_BKP_DR9                        0x09U
655 #define RTC_BKP_DR10                       0x0AU
656 #define RTC_BKP_DR11                       0x0BU
657 #define RTC_BKP_DR12                       0x0CU
658 #define RTC_BKP_DR13                       0x0DU
659 #define RTC_BKP_DR14                       0x0EU
660 #define RTC_BKP_DR15                       0x0FU
661 #define RTC_BKP_DR16                       0x10U
662 #define RTC_BKP_DR17                       0x11U
663 #define RTC_BKP_DR18                       0x12U
664 #define RTC_BKP_DR19                       0x13U
665 #define RTC_BKP_DR20                       0x14U
666 #define RTC_BKP_DR21                       0x15U
667 #define RTC_BKP_DR22                       0x16U
668 #define RTC_BKP_DR23                       0x17U
669 #define RTC_BKP_DR24                       0x18U
670 #define RTC_BKP_DR25                       0x19U
671 #define RTC_BKP_DR26                       0x1AU
672 #define RTC_BKP_DR27                       0x1BU
673 #define RTC_BKP_DR28                       0x1CU
674 #define RTC_BKP_DR29                       0x1DU
675 #define RTC_BKP_DR30                       0x1EU
676 #define RTC_BKP_DR31                       0x1FU
677 /**
678   * @}
679   */
680 
681 /** @defgroup RTCEx_Binary_Mode RTC Binary Mode (32-bit free-running counter configuration).
682   *           Warning : It Should not be confused with the Binary format @ref RTC_Input_parameter_format_definitions.
683   * @{
684   */
685 #define RTC_BINARY_NONE                    0U                    /*!< Free running BCD calendar mode (Binary mode disabled) */
686 #define RTC_BINARY_ONLY                    RTC_ICSR_BIN_0        /*!< Free running Binary mode (BCD mode disabled)          */
687 #define RTC_BINARY_MIX                     RTC_ICSR_BIN_1        /*!< Free running BCD calendar and Binary modes            */
688 /**
689   * @}
690   */
691 
692 /** @defgroup RTCEx_Binary_mix_BCDU If Binary mode is RTC_BINARY_MIX, the BCD calendar second is incremented
693   *           using the SSR Least Significant Bits.
694   * @{
695   */
696 #define RTC_BINARY_MIX_BCDU_0              0U                           /*!<  The 1s BCD calendar increment is generated each time SS[7:0] = 0  */
697 #define RTC_BINARY_MIX_BCDU_1              (0x1UL << RTC_ICSR_BCDU_Pos) /*!<  The 1s BCD calendar increment is generated each time SS[8:0] = 0  */
698 #define RTC_BINARY_MIX_BCDU_2              (0x2UL << RTC_ICSR_BCDU_Pos) /*!<  The 1s BCD calendar increment is generated each time SS[9:0] = 0  */
699 #define RTC_BINARY_MIX_BCDU_3              (0x3UL << RTC_ICSR_BCDU_Pos) /*!<  The 1s BCD calendar increment is generated each time SS[10:0] = 0 */
700 #define RTC_BINARY_MIX_BCDU_4              (0x4UL << RTC_ICSR_BCDU_Pos) /*!<  The 1s BCD calendar increment is generated each time SS[11:0] = 0 */
701 #define RTC_BINARY_MIX_BCDU_5              (0x5UL << RTC_ICSR_BCDU_Pos) /*!<  The 1s BCD calendar increment is generated each time SS[12:0] = 0 */
702 #define RTC_BINARY_MIX_BCDU_6              (0x6UL << RTC_ICSR_BCDU_Pos) /*!<  The 1s BCD calendar increment is generated each time SS[13:0] = 0 */
703 #define RTC_BINARY_MIX_BCDU_7              (0x7UL << RTC_ICSR_BCDU_Pos) /*!<  The 1s BCD calendar increment is generated each time SS[14:0] = 0 */
704 /**
705   * @}
706   */
707 
708 /** @defgroup RTCEx_Alarm_Sub_Seconds_binary_Masks_Definitions RTC Alarm Sub Seconds with binary or mix mode
709   *           Masks Definitions.
710   * @{
711   */
712 #define RTC_ALARMSUBSECONDBINMASK_ALL      0U                                /*!< All Alarm SS fields are masked.There is no comparison on sub seconds for Alarm */
713 #define RTC_ALARMSUBSECONDBINMASK_SS31_1   (1UL << RTC_ALRMASSR_MASKSS_Pos)  /*!< SS[31:1] are don't care in Alarm comparison. Only SS[0] is compared            */
714 #define RTC_ALARMSUBSECONDBINMASK_SS31_2   (2UL << RTC_ALRMASSR_MASKSS_Pos)  /*!< SS[31:2] are don't care in Alarm comparison. Only SS[1:0] are compared         */
715 #define RTC_ALARMSUBSECONDBINMASK_SS31_3   (3UL << RTC_ALRMASSR_MASKSS_Pos)  /*!< SS[31:3] are don't care in Alarm comparison. Only SS[2:0] are compared         */
716 #define RTC_ALARMSUBSECONDBINMASK_SS31_4   (4UL << RTC_ALRMASSR_MASKSS_Pos)  /*!< SS[31:4] are don't care in Alarm comparison. Only SS[3:0] are compared         */
717 #define RTC_ALARMSUBSECONDBINMASK_SS31_5   (5UL << RTC_ALRMASSR_MASKSS_Pos)  /*!< SS[31:5] are don't care in Alarm comparison. Only SS[4:0] are compared         */
718 #define RTC_ALARMSUBSECONDBINMASK_SS31_6   (6UL << RTC_ALRMASSR_MASKSS_Pos)  /*!< SS[31:6] are don't care in Alarm comparison. Only SS[5:0] are compared         */
719 #define RTC_ALARMSUBSECONDBINMASK_SS31_7   (7UL << RTC_ALRMASSR_MASKSS_Pos)  /*!< SS[31:7] are don't care in Alarm comparison. Only SS[6:0] are compared         */
720 #define RTC_ALARMSUBSECONDBINMASK_SS31_8   (8UL << RTC_ALRMASSR_MASKSS_Pos)  /*!< SS[31:8] are don't care in Alarm comparison. Only SS[7:0] are compared         */
721 #define RTC_ALARMSUBSECONDBINMASK_SS31_9   (9UL << RTC_ALRMASSR_MASKSS_Pos)  /*!< SS[31:9] are don't care in Alarm comparison. Only SS[8:0] are compared         */
722 #define RTC_ALARMSUBSECONDBINMASK_SS31_10  (10UL << RTC_ALRMASSR_MASKSS_Pos) /*!< SS[31:10] are don't care in Alarm comparison. Only SS[9:0] are compared        */
723 #define RTC_ALARMSUBSECONDBINMASK_SS31_11  (11UL << RTC_ALRMASSR_MASKSS_Pos) /*!< SS[31:11] are don't care in Alarm comparison. Only SS[10:0] are compared       */
724 #define RTC_ALARMSUBSECONDBINMASK_SS31_12  (12UL << RTC_ALRMASSR_MASKSS_Pos) /*!< SS[31:12] are don't care in Alarm comparison.Only SS[11:0] are compared        */
725 #define RTC_ALARMSUBSECONDBINMASK_SS31_13  (13UL << RTC_ALRMASSR_MASKSS_Pos) /*!< SS[31:13] are don't care in Alarm comparison. Only SS[12:0] are compared       */
726 #define RTC_ALARMSUBSECONDBINMASK_SS31_14  (14UL << RTC_ALRMASSR_MASKSS_Pos) /*!< SS[31:14] are don't care in Alarm comparison. Only SS[13:0] are compared       */
727 #define RTC_ALARMSUBSECONDBINMASK_SS31_15  (15UL << RTC_ALRMASSR_MASKSS_Pos) /*!< SS[31:15] are don't care in Alarm comparison. Only SS[14:0] are compared       */
728 #define RTC_ALARMSUBSECONDBINMASK_SS31_16  (16UL << RTC_ALRMASSR_MASKSS_Pos) /*!< SS[31:16] are don't care in Alarm comparison. Only SS[15:0] are compared       */
729 #define RTC_ALARMSUBSECONDBINMASK_SS31_17  (17UL << RTC_ALRMASSR_MASKSS_Pos) /*!< SS[31:17] are don't care in Alarm comparison. Only SS[16:0] are compared       */
730 #define RTC_ALARMSUBSECONDBINMASK_SS31_18  (18UL << RTC_ALRMASSR_MASKSS_Pos) /*!< SS[31:18] are don't care in Alarm comparison. Only SS[17:0] are compared       */
731 #define RTC_ALARMSUBSECONDBINMASK_SS31_19  (19UL << RTC_ALRMASSR_MASKSS_Pos) /*!< SS[31:19] are don't care in Alarm comparison. Only SS[18:0] are compared       */
732 #define RTC_ALARMSUBSECONDBINMASK_SS31_20  (20UL << RTC_ALRMASSR_MASKSS_Pos) /*!< SS[31:20] are don't care in Alarm comparison. Only SS[19:0] are compared       */
733 #define RTC_ALARMSUBSECONDBINMASK_SS31_21  (21UL << RTC_ALRMASSR_MASKSS_Pos) /*!< SS[31:21] are don't care in Alarm comparison. Only SS[20:0] are compared       */
734 #define RTC_ALARMSUBSECONDBINMASK_SS31_22  (22UL << RTC_ALRMASSR_MASKSS_Pos) /*!< SS[31:22] are don't care in Alarm comparison. Only SS[21:0] are compared       */
735 #define RTC_ALARMSUBSECONDBINMASK_SS31_23  (23UL << RTC_ALRMASSR_MASKSS_Pos) /*!< SS[31:23] are don't care in Alarm comparison. Only SS[22:0] are compared       */
736 #define RTC_ALARMSUBSECONDBINMASK_SS31_24  (24UL << RTC_ALRMASSR_MASKSS_Pos) /*!< SS[31:24] are don't care in Alarm comparison. Only SS[23:0] are compared       */
737 #define RTC_ALARMSUBSECONDBINMASK_SS31_25  (25UL << RTC_ALRMASSR_MASKSS_Pos) /*!< SS[31:25] are don't care in Alarm comparison. Only SS[24:0] are compared       */
738 #define RTC_ALARMSUBSECONDBINMASK_SS31_26  (26UL << RTC_ALRMASSR_MASKSS_Pos) /*!< SS[31:26] are don't care in Alarm comparison. Only SS[25:0] are compared       */
739 #define RTC_ALARMSUBSECONDBINMASK_SS31_27  (27UL << RTC_ALRMASSR_MASKSS_Pos) /*!< SS[31:27] are don't care in Alarm comparison. Only SS[26:0] are compared       */
740 #define RTC_ALARMSUBSECONDBINMASK_SS31_28  (28UL << RTC_ALRMASSR_MASKSS_Pos) /*!< SS[31:28] are don't care in Alarm comparison. Only SS[27:0] are compared       */
741 #define RTC_ALARMSUBSECONDBINMASK_SS31_29  (29UL << RTC_ALRMASSR_MASKSS_Pos) /*!< SS[31:29] are don't care in Alarm comparison. Only SS[28:0] are compared       */
742 #define RTC_ALARMSUBSECONDBINMASK_SS31_30  (30UL << RTC_ALRMASSR_MASKSS_Pos) /*!< SS[31:30] are don't care in Alarm comparison. Only SS[29:0] are compared       */
743 #define RTC_ALARMSUBSECONDBINMASK_SS31     (31UL << RTC_ALRMASSR_MASKSS_Pos) /*!< SS[31] is don't care in Alarm comparison. Only SS[30:0] are compared           */
744 #define RTC_ALARMSUBSECONDBINMASK_NONE     RTC_ALRMASSR_MASKSS               /*!< SS[31:0] are compared and must match to activate alarm                         */
745 /**
746   * @}
747   */
748 
749 /** @defgroup RTCEx_Alarm_Sub_Seconds_binary_Clear_Definitions RTC Alarm Sub Seconds
750   *           with binary mode auto clear Definitions
751   * @{
752   */
753 #define RTC_ALARMSUBSECONDBIN_AUTOCLR_NO   0UL                   /*!< The synchronous Binary counter(SS[31:0] in RTC_SSR) is free-running */
754 #define RTC_ALARMSUBSECONDBIN_AUTOCLR_YES  RTC_ALRMASSR_SSCLR
755 /*!< The synchronous Binary counter (SS[31:0] in RTC_SSR) is running from 0xFFFF FFFF to RTC_ALRMABINR -> SS[31:0]
756      value and is automatically reloaded with 0xFFFF FFFF whenreaching RTC_ALRMABINR -> SS[31:0]. */
757 /**
758   * @}
759   */
760 
761 #ifdef RTC_SECCFGR_SEC
762 /** @defgroup RTCEx_RTC_Secure_Full  RTCEx Secure Definition
763   * @{
764   */
765 #define RTC_SECURE_FULL_YES                RTC_SECCFGR_SEC       /*!< RTC full secure */
766 #define RTC_SECURE_FULL_NO                 0U                    /*!< RTC is not full secure, features can be unsecure. See RTCEx_RTC_NonSecure_Features */
767 /**
768   * @}
769   */
770 
771 /** @defgroup RTCEx_RTC_NonSecure_Features  RTCEx Secure Features Definition
772   * @{
773   */
774 #define RTC_NONSECURE_FEATURE_NONE         0U
775 #define RTC_NONSECURE_FEATURE_INIT         RTC_SECCFGR_INITSEC   /*!< Initialization */
776 #define RTC_NONSECURE_FEATURE_CAL          RTC_SECCFGR_CALSEC    /*!< Calibration    */
777 #define RTC_NONSECURE_FEATURE_TS           RTC_SECCFGR_TSSEC     /*!< Time stamp     */
778 #define RTC_NONSECURE_FEATURE_WUT          RTC_SECCFGR_WUTSEC    /*!< Wake up timer  */
779 #define RTC_NONSECURE_FEATURE_ALRA         RTC_SECCFGR_ALRASEC   /*!< Alarm A        */
780 #define RTC_NONSECURE_FEATURE_ALRB         RTC_SECCFGR_ALRBSEC   /*!< Alarm B        */
781 
782 #define RTC_NONSECURE_FEATURE_ALL          (RTC_SECCFGR_INITSEC |  RTC_SECCFGR_CALSEC | \
783                                             RTC_SECCFGR_TSSEC | RTC_SECCFGR_WUTSEC | \
784                                             RTC_SECCFGR_ALRASEC | RTC_SECCFGR_ALRBSEC)
785 /**
786   * @}
787   */
788 #endif /* RTC_SECCFGR_SEC */
789 
790 #ifdef TAMP_SECCFGR_TAMPSEC
791 /** @defgroup RTCEx_TAMP_Secure_Full  RTCEx TAMP Secure Definition
792   * @{
793   */
794 #define TAMP_SECURE_FULL_YES               TAMP_SECCFGR_TAMPSEC  /*!< TAMPER full secure   */
795 #define TAMP_SECURE_FULL_NO                0U                    /*!< TAMPER is not secure */
796 /**
797   * @}
798   */
799 #endif /* TAMP_SECCFGR_TAMPSEC*/
800 
801 #ifdef TAMP_SECCFGR_CNT1SEC
802 /** @defgroup RTCEx_TAMP_Monotonic_Counter_Secure  RTCEx TAMP Monotonic Counter Secure Definition
803   * @{
804   */
805 #define TAMP_MONOTONIC_CNT_SECURE_YES      TAMP_SECCFGR_CNT1SEC  /*!< TAMPER Monotonic Counter secure        */
806 #define TAMP_MONOTONIC_CNT_SECURE_NO       0U                    /*!< TAMPER Monotonic Counter is not secure */
807 /**
808   * @}
809   */
810 #endif /* TAMP_SECCFGR_CNT1SEC */
811 
812 /** @defgroup RTCEx_RTC_Privilege_Full  RTCEx Privilege Full Definition
813   * @{
814   */
815 #define RTC_PRIVILEGE_FULL_YES             RTC_PRIVCFGR_PRIV
816 #define RTC_PRIVILEGE_FULL_NO              0U
817 /**
818   * @}
819   */
820 
821 /** @defgroup RTCEx_RTC_Privilege_Features  RTCEx Privilege Features Definition
822   * @{
823   */
824 #define RTC_PRIVILEGE_FEATURE_NONE         0U
825 #define RTC_PRIVILEGE_FEATURE_INIT         RTC_PRIVCFGR_INITPRIV /*!< Initialization */
826 #define RTC_PRIVILEGE_FEATURE_CAL          RTC_PRIVCFGR_CALPRIV  /*!< Calibration    */
827 #define RTC_PRIVILEGE_FEATURE_TS           RTC_PRIVCFGR_TSPRIV   /*!< Time stamp     */
828 #define RTC_PRIVILEGE_FEATURE_WUT          RTC_PRIVCFGR_WUTPRIV  /*!< Wake up timer  */
829 #define RTC_PRIVILEGE_FEATURE_ALRA         RTC_PRIVCFGR_ALRAPRIV /*!< Alarm A        */
830 #define RTC_PRIVILEGE_FEATURE_ALRB         RTC_PRIVCFGR_ALRBPRIV /*!< Alarm B        */
831 
832 #define RTC_PRIVILEGE_FEATURE_ALL          (RTC_PRIVCFGR_INITPRIV |  RTC_PRIVCFGR_CALPRIV | \
833                                             RTC_PRIVCFGR_TSPRIV | RTC_PRIVCFGR_WUTPRIV | \
834                                             RTC_PRIVCFGR_ALRAPRIV | RTC_PRIVCFGR_ALRBPRIV)
835 /**
836   * @}
837   */
838 
839 /** @defgroup RTCEx_TAMP_Privilege_Full  RTCEx TAMP security Definition
840   * @{
841   */
842 #define TAMP_PRIVILEGE_FULL_YES            TAMP_PRIVCFGR_TAMPPRIV
843 #define TAMP_PRIVILEGE_FULL_NO             0U
844 /**
845   * @}
846   */
847 
848 /** @defgroup RTCEx_TAMP_Device_Secrets_Erase_Conf  RTCEx TAMP Device Secrets Erase Configuration Definition
849   * @{
850   */
851 #define TAMP_DEVICESECRETS_ERASE_NONE          0U                   /*! < No Erase          */
852 #define TAMP_DEVICESECRETS_ERASE_SRAM2         TAMP_RPCFGR_RPCFG_1  /*!< SRAM2              */
853 #define TAMP_DEVICESECRETS_ERASE_RHUK          TAMP_RPCFGR_RPCFG_2  /*!< RHUK               */
854 #define TAMP_DEVICESECRETS_ERASE_ICACHE        TAMP_RPCFGR_RPCFG_3  /*!< ICACHE             */
855 #define TAMP_DEVICESECRETS_ERASE_SAES_AES_HASH TAMP_RPCFGR_RPCFG_4  /*!< SAES, AES and HASH */
856 #define TAMP_DEVICESECRETS_ERASE_PKA_SRAM      TAMP_RPCFGR_RPCFG_5  /*!< Initialization     */
857 #define TAMP_DEVICESECRETS_ERASE_ALL           TAMP_RPCFGR_RPCFG    /*!< All                */
858 /**
859   * @}
860   */
861 
862 /** @defgroup RTCEx_TAMP_Monotonic_Counter_Privilege  RTCEx TAMP Monotonic Counter Privilege Definition
863   * @{
864   */
865 #define TAMP_MONOTONIC_CNT_PRIVILEGE_YES   TAMP_PRIVCFGR_CNT1PRIV
866 #define TAMP_MONOTONIC_CNT_PRIVILEGE_NO    0U
867 /**
868   * @}
869   */
870 
871 /** @defgroup RTCEx_Backup_Reg_Privilege_zone  RTCEx Privilege Backup register privilege zone Definition
872   * @{
873   */
874 #define RTC_PRIVILEGE_BKUP_ZONE_NONE       0U
875 #define RTC_PRIVILEGE_BKUP_ZONE_1          TAMP_PRIVCFGR_BKPRWPRIV
876 #define RTC_PRIVILEGE_BKUP_ZONE_2          TAMP_PRIVCFGR_BKPWPRIV
877 #define RTC_PRIVILEGE_BKUP_ZONE_ALL        (RTC_PRIVILEGE_BKUP_ZONE_1 | RTC_PRIVILEGE_BKUP_ZONE_2)
878 /**
879   * @}
880   */
881 
882 /**
883   * @}
884   */
885 
886 /* Exported macros -----------------------------------------------------------*/
887 /** @defgroup RTCEx_Exported_Macros RTCEx Exported Macros
888   * @{
889   */
890 
891 /** @brief  Clear the specified RTC pending flag.
892   * @param  __HANDLE__ specifies the RTC Handle.
893   * @param  __FLAG__ specifies the flag to check.
894   *          This parameter can be any combination of the following values:
895   *            @arg @ref RTC_CLEAR_SSRUF              Clear SSR underflow flag
896   *            @arg @ref RTC_CLEAR_TSOVF              Clear Time-stamp overflow flag
897   *            @arg @ref RTC_CLEAR_TSF                Clear Time-stamp flag
898   *            @arg @ref RTC_CLEAR_WUTF               Clear Wakeup timer flag
899   *            @arg @ref RTC_CLEAR_ALRBF              Clear Alarm B flag
900   *            @arg @ref RTC_CLEAR_ALRAF              Clear Alarm A flag
901   * @retval None
902   */
903 #define __HAL_RTC_CLEAR_FLAG(__HANDLE__, __FLAG__)   (RTC->SCR = (__FLAG__))
904 
905 /** @brief  Check whether the specified RTC flag is set or not.
906   * @param  __HANDLE__ specifies the RTC Handle.
907   * @param  __FLAG__ specifies the flag to check.
908   *          This parameter can be any combination of the following values:
909   *            @arg @ref RTC_FLAG_RECALPF             Recalibration pending Flag
910   *            @arg @ref RTC_FLAG_INITF               Initialization flag
911   *            @arg @ref RTC_FLAG_RSF                 Registers synchronization flag
912   *            @arg @ref RTC_FLAG_INITS               Initialization status flag
913   *            @arg @ref RTC_FLAG_SHPF                Shift operation pending flag
914   *            @arg @ref RTC_FLAG_WUTWF               Wakeup timer write flag
915   *            @arg @ref RTC_FLAG_TSOVF               Time-stamp overflow flag
916   *            @arg @ref RTC_FLAG_TSF                 Time-stamp flag
917   *            @arg @ref RTC_FLAG_WUTF                Wakeup timer flag
918   *            @arg @ref RTC_FLAG_ALRBF               Alarm B flag
919   *            @arg @ref RTC_FLAG_ALRAF               Alarm A flag
920   * @retval The state of __FLAG__ (TRUE or FALSE).
921   */
922 #define __HAL_RTC_GET_FLAG(__HANDLE__, __FLAG__)( \
923                                ((__FLAG__) == RTC_FLAG_RECALPF) ? (READ_BIT(RTC->ICSR, RTC_ICSR_RECALPF) == \
924                                                                 RTC_ICSR_RECALPF) : \
925                                ((__FLAG__) == RTC_FLAG_INITF)   ? (READ_BIT(RTC->ICSR, RTC_ICSR_INITF) == \
926                                                                 RTC_ICSR_INITF) : \
927                                ((__FLAG__) == RTC_FLAG_RSF)     ? (READ_BIT(RTC->ICSR, RTC_ICSR_RSF) == \
928                                                                 RTC_ICSR_RSF) : \
929                                ((__FLAG__) == RTC_FLAG_INITS)   ? (READ_BIT(RTC->ICSR, RTC_ICSR_INITS) == \
930                                                                 RTC_ICSR_INITS) : \
931                                ((__FLAG__) == RTC_FLAG_SHPF)    ? (READ_BIT(RTC->ICSR, RTC_ICSR_SHPF) == \
932                                                                 RTC_ICSR_SHPF) : \
933                                ((__FLAG__) == RTC_FLAG_WUTWF)   ? (READ_BIT(RTC->ICSR, RTC_ICSR_WUTWF) == \
934                                                                 RTC_ICSR_WUTWF) : \
935                                ((__FLAG__) == RTC_FLAG_SSRUF)   ? (READ_BIT(RTC->SR, RTC_SR_SSRUF) == \
936                                                                 RTC_SR_SSRUF) : \
937                                ((__FLAG__) == RTC_FLAG_TSOVF)   ? (READ_BIT(RTC->SR, RTC_SR_TSOVF) == \
938                                                                 RTC_SR_TSOVF) : \
939                                ((__FLAG__) == RTC_FLAG_TSF)     ? (READ_BIT(RTC->SR, RTC_SR_TSF) == \
940                                                                 RTC_SR_TSF): \
941                                ((__FLAG__) == RTC_FLAG_WUTF)    ? (READ_BIT(RTC->SR, RTC_SR_WUTF) == \
942                                                                 RTC_SR_WUTF): \
943                                ((__FLAG__) == RTC_FLAG_ALRBF)   ? (READ_BIT(RTC->SR, RTC_SR_ALRBF) == \
944                                                                 RTC_SR_ALRBF) : \
945                                ((__FLAG__) == RTC_FLAG_ALRAF)   ? (READ_BIT(RTC->SR, RTC_SR_ALRAF) == \
946                                                                 RTC_SR_ALRAF) : \
947                                (0U)) /* Return 0 because it is an invalid parameter value */
948 
949 /* ---------------------------------WAKEUPTIMER---------------------------------*/
950 /** @defgroup RTCEx_WakeUp_Timer RTC WakeUp Timer
951   * @{
952   */
953 
954 /**
955   * @brief  Enable the RTC WakeUp Timer peripheral.
956   * @param  __HANDLE__ specifies the RTC handle.
957   * @retval None
958   */
959 #define __HAL_RTC_WAKEUPTIMER_ENABLE(__HANDLE__)                      (RTC->CR |= (RTC_CR_WUTE))
960 
961 /**
962   * @brief  Disable the RTC WakeUp Timer peripheral.
963   * @param  __HANDLE__ specifies the RTC handle.
964   * @retval None
965   */
966 #define __HAL_RTC_WAKEUPTIMER_DISABLE(__HANDLE__)                     (RTC->CR &= ~(RTC_CR_WUTE))
967 
968 /**
969   * @brief  Enable the RTC WakeUpTimer interrupt.
970   * @param  __HANDLE__ specifies the RTC handle.
971   * @param  __INTERRUPT__ specifies the RTC WakeUpTimer interrupt sources to be enabled.
972   *         This parameter can be:
973   *            @arg @ref RTC_IT_WUT WakeUpTimer interrupt
974   * @retval None
975   */
976 #define __HAL_RTC_WAKEUPTIMER_ENABLE_IT(__HANDLE__, __INTERRUPT__)    (RTC->CR |= (RTC_CR_WUTIE))
977 
978 /**
979   * @brief  Disable the RTC WakeUpTimer interrupt.
980   * @param  __HANDLE__ specifies the RTC handle.
981   * @param  __INTERRUPT__ specifies the RTC WakeUpTimer interrupt sources to be disabled.
982   *         This parameter can be:
983   *            @arg @ref RTC_IT_WUT WakeUpTimer interrupt
984   * @retval None
985   */
986 #define __HAL_RTC_WAKEUPTIMER_DISABLE_IT(__HANDLE__, __INTERRUPT__)   (RTC->CR &= ~(RTC_CR_WUTIE))
987 
988 /**
989   * @brief  Check whether the specified RTC WakeUpTimer interrupt has occurred or not.
990   * @param  __HANDLE__ specifies the RTC handle.
991   * @param  __INTERRUPT__ specifies the RTC WakeUpTimer interrupt to check.
992   *         This parameter can be:
993   *            @arg @ref RTC_IT_WUT  WakeUpTimer interrupt
994   * @retval The state of __INTERRUPT__ (TRUE or FALSE).
995   */
996 #define __HAL_RTC_WAKEUPTIMER_GET_IT(__HANDLE__, __INTERRUPT__)       (((RTC->MISR) & (RTC_MISR_WUTMF)) != 0U)
997 
998 /**
999   * @brief  Check whether the specified RTC Wake Up timer interrupt has been enabled or not.
1000   * @param  __HANDLE__ specifies the RTC handle.
1001   * @param  __INTERRUPT__ specifies the RTC Wake Up timer interrupt sources to check.
1002   *         This parameter can be:
1003   *            @arg @ref RTC_IT_WUT  WakeUpTimer interrupt
1004   * @retval The state of __INTERRUPT__ (TRUE or FALSE).
1005   */
1006 #define __HAL_RTC_WAKEUPTIMER_GET_IT_SOURCE(__HANDLE__, __INTERRUPT__)   (((RTC->CR) & (RTC_CR_WUTIE)) != 0U)
1007 
1008 /**
1009   * @brief  Get the selected RTC WakeUpTimers flag status.
1010   * @param  __HANDLE__ specifies the RTC handle.
1011   * @param  __FLAG__ specifies the RTC WakeUpTimer Flag is pending or not.
1012   *          This parameter can be:
1013   *             @arg @ref RTC_FLAG_WUTF
1014   *             @arg @ref RTC_FLAG_WUTWF
1015   * @retval The state of __FLAG__ (TRUE or FALSE).
1016   */
1017 #define __HAL_RTC_WAKEUPTIMER_GET_FLAG(__HANDLE__, __FLAG__)( \
1018                             ((__FLAG__) == RTC_FLAG_WUTF)  ? (READ_BIT(RTC->SR, RTC_SR_WUTF) == RTC_SR_WUTF):\
1019                             ((__FLAG__) == RTC_FLAG_WUTWF) ? (READ_BIT(RTC->ICSR, RTC_ICSR_WUTWF) == RTC_ICSR_WUTWF):\
1020                             (0U)) /* Return 0 because it is an invalid parameter value */
1021 
1022 /**
1023   * @brief  Clear the RTC Wake Up timers pending flags.
1024   * @param  __HANDLE__ specifies the RTC handle.
1025   * @param  __FLAG__ specifies the RTC WakeUpTimer Flag to clear.
1026   *         This parameter can be:
1027   *            @arg @ref RTC_FLAG_WUTF
1028   * @retval None
1029   */
1030 #define __HAL_RTC_WAKEUPTIMER_CLEAR_FLAG(__HANDLE__, __FLAG__)  (SET_BIT(RTC->SCR, RTC_SCR_CWUTF))
1031 
1032 /**
1033   * @}
1034   */
1035 
1036 /* ---------------------------------TIMESTAMP---------------------------------*/
1037 /** @defgroup RTCEx_Timestamp RTC Timestamp
1038   * @{
1039   */
1040 
1041 /**
1042   * @brief  Enable the RTC TimeStamp peripheral.
1043   * @param  __HANDLE__ specifies the RTC handle.
1044   * @retval None
1045   */
1046 #define __HAL_RTC_TIMESTAMP_ENABLE(__HANDLE__)                       (RTC->CR |= (RTC_CR_TSE))
1047 
1048 /**
1049   * @brief  Disable the RTC TimeStamp peripheral.
1050   * @param  __HANDLE__ specifies the RTC handle.
1051   * @retval None
1052   */
1053 #define __HAL_RTC_TIMESTAMP_DISABLE(__HANDLE__)                      (RTC->CR &= ~(RTC_CR_TSE))
1054 
1055 /**
1056   * @brief  Enable the RTC TimeStamp interrupt.
1057   * @param  __HANDLE__ specifies the RTC handle.
1058   * @param  __INTERRUPT__ specifies the RTC TimeStamp interrupt source to be enabled.
1059   *         This parameter can be:
1060   *            @arg @ref RTC_IT_TS TimeStamp interrupt
1061   * @retval None
1062   */
1063 #define __HAL_RTC_TIMESTAMP_ENABLE_IT(__HANDLE__, __INTERRUPT__)     (RTC->CR |= (RTC_CR_TSIE))
1064 
1065 /**
1066   * @brief  Disable the RTC TimeStamp interrupt.
1067   * @param  __HANDLE__ specifies the RTC handle.
1068   * @param  __INTERRUPT__ specifies the RTC TimeStamp interrupt source to be disabled.
1069   *         This parameter can be:
1070   *            @arg @ref RTC_IT_TS TimeStamp interrupt
1071   * @retval None
1072   */
1073 #define __HAL_RTC_TIMESTAMP_DISABLE_IT(__HANDLE__, __INTERRUPT__)    (RTC->CR &= ~(RTC_CR_TSIE))
1074 
1075 /**
1076   * @brief  Check whether the specified RTC TimeStamp interrupt has occurred or not.
1077   * @param  __HANDLE__ specifies the RTC handle.
1078   * @param  __INTERRUPT__ specifies the RTC TimeStamp interrupt to check.
1079   *         This parameter can be:
1080   *            @arg @ref RTC_IT_TS TimeStamp interrupt
1081   * @retval The state of __INTERRUPT__ (TRUE or FALSE).
1082   */
1083 #define __HAL_RTC_TIMESTAMP_GET_IT(__HANDLE__, __INTERRUPT__)        (((RTC->MISR) & (RTC_MISR_TSMF)) != 0U)
1084 
1085 /**
1086   * @brief  Check whether the specified RTC Time Stamp interrupt has been enabled or not.
1087   * @param  __HANDLE__ specifies the RTC handle.
1088   * @param  __INTERRUPT__ specifies the RTC Time Stamp interrupt source to check.
1089   *         This parameter can be:
1090   *            @arg @ref RTC_IT_TS TimeStamp interrupt
1091   * @retval The state of __INTERRUPT__ (TRUE or FALSE).
1092   */
1093 #define __HAL_RTC_TIMESTAMP_GET_IT_SOURCE(__HANDLE__, __INTERRUPT__)  (((RTC->CR) & (RTC_CR_TSIE)) != 0U)
1094 
1095 /**
1096   * @brief  Get the selected RTC TimeStamps flag status.
1097   * @param  __HANDLE__ specifies the RTC handle.
1098   * @param  __FLAG__ specifies the RTC TimeStamp Flag is pending or not.
1099   *         This parameter can be:
1100   *            @arg @ref RTC_FLAG_TSF
1101   *            @arg @ref RTC_FLAG_TSOVF
1102   * @retval The state of __FLAG__ (TRUE or FALSE) or 255 if invalid parameter.
1103   */
1104 #define __HAL_RTC_TIMESTAMP_GET_FLAG(__HANDLE__, __FLAG__)( \
1105                                 ((__FLAG__) == RTC_FLAG_TSF)   ? (READ_BIT(RTC->SR, RTC_SR_TSF) == RTC_SR_TSF):\
1106                                 ((__FLAG__) == RTC_FLAG_TSOVF) ? (READ_BIT(RTC->SR, RTC_SR_TSOVF) == RTC_SR_TSOVF):\
1107                                 (0U)) /* Return 0 because it is an invalid parameter value */
1108 
1109 /**
1110   * @brief  Clear the RTC Time Stamps pending flags.
1111   * @param  __HANDLE__ specifies the RTC handle.
1112   * @param  __FLAG__ specifies the RTC TimeStamp Flag to clear.
1113   *          This parameter can be:
1114   *             @arg @ref RTC_FLAG_TSF
1115   *             @arg @ref RTC_FLAG_TSOVF
1116   * @retval None
1117   */
1118 #define __HAL_RTC_TIMESTAMP_CLEAR_FLAG(__HANDLE__, __FLAG__)( \
1119                                 ((__FLAG__) == RTC_FLAG_TSF)   ? (SET_BIT(RTC->SCR, RTC_SCR_CTSF)):\
1120                                 ((__FLAG__) == RTC_FLAG_TSOVF) ? (SET_BIT(RTC->SCR, RTC_SCR_CTSOVF)):\
1121                                 (0U)) /* Dummy action because is an invalid parameter value */
1122 
1123 /**
1124   * @brief  Enable the RTC TimeStamp on Tamper detection.
1125   * @param  __HANDLE__ specifies the RTC handle.
1126   * @retval None
1127   */
1128 #define __HAL_RTC_TAMPTS_ENABLE(__HANDLE__)                       (RTC->CR |= (RTC_CR_TAMPTS))
1129 
1130 /**
1131   * @brief  Disable the RTC TimeStamp on Tamper detection.
1132   * @param  __HANDLE__ specifies the RTC handle.
1133   * @retval None
1134   */
1135 #define __HAL_RTC_TAMPTS_DISABLE(__HANDLE__)                      (RTC->CR &= ~(RTC_CR_TAMPTS))
1136 
1137 #if defined(RTC_CR_TAMPOE)
1138 /**
1139   * @brief  Enable the RTC Tamper detection output.
1140   * @param  __HANDLE__ specifies the RTC handle.
1141   * @retval None
1142   */
1143 #define __HAL_RTC_TAMPOE_ENABLE(__HANDLE__)                       (RTC->CR |= (RTC_CR_TAMPOE))
1144 
1145 /**
1146   * @brief  Disable the RTC Tamper detection output.
1147   * @param  __HANDLE__ specifies the RTC handle.
1148   * @retval None
1149   */
1150 #define __HAL_RTC_TAMPOE_DISABLE(__HANDLE__)                      (RTC->CR &= ~(RTC_CR_TAMPOE))
1151 
1152 #endif /* RTC_CR_TAMPOE */
1153 
1154 /**
1155   * @}
1156   */
1157 
1158 
1159 /* ------------------------------Calibration----------------------------------*/
1160 /** @defgroup RTCEx_Calibration RTC Calibration
1161   * @{
1162   */
1163 
1164 /**
1165   * @brief  Enable the RTC calibration output.
1166   * @param  __HANDLE__ specifies the RTC handle.
1167   * @retval None
1168   */
1169 #define __HAL_RTC_CALIBRATION_OUTPUT_ENABLE(__HANDLE__)               (RTC->CR |= (RTC_CR_COE))
1170 
1171 /**
1172   * @brief  Disable the calibration output.
1173   * @param  __HANDLE__ specifies the RTC handle.
1174   * @retval None
1175   */
1176 #define __HAL_RTC_CALIBRATION_OUTPUT_DISABLE(__HANDLE__)              (RTC->CR &= ~(RTC_CR_COE))
1177 
1178 /**
1179   * @brief  Enable the clock reference detection.
1180   * @param  __HANDLE__ specifies the RTC handle.
1181   * @retval None
1182   */
1183 #define __HAL_RTC_CLOCKREF_DETECTION_ENABLE(__HANDLE__)               (RTC->CR |= (RTC_CR_REFCKON))
1184 
1185 /**
1186   * @brief  Disable the clock reference detection.
1187   * @param  __HANDLE__ specifies the RTC handle.
1188   * @retval None
1189   */
1190 #define __HAL_RTC_CLOCKREF_DETECTION_DISABLE(__HANDLE__)              (RTC->CR &= ~(RTC_CR_REFCKON))
1191 
1192 /**
1193   * @brief  Get the selected RTC shift operations flag status.
1194   * @param  __HANDLE__ specifies the RTC handle.
1195   * @param  __FLAG__ specifies the RTC shift operation Flag is pending or not.
1196   *          This parameter can be:
1197   *             @arg @ref RTC_FLAG_SHPF
1198   * @retval The state of __FLAG__ (TRUE or FALSE)
1199   */
1200 #define __HAL_RTC_SHIFT_GET_FLAG(__HANDLE__, __FLAG__)  ((READ_BIT(RTC->ICSR, RTC_ICSR_SHPF) == RTC_ICSR_SHPF))
1201 /**
1202   * @}
1203   */
1204 
1205 /* ------------------------------Tamper----------------------------------*/
1206 /** @defgroup RTCEx_Tamper RTCEx tamper
1207   * @{
1208   */
1209 
1210 /**
1211   * @brief  Enable the TAMP Tamper input detection.
1212   * @param  __HANDLE__ specifies the RTC handle.
1213   * @param  __TAMPER__ specifies the RTC Tamper source to be enabled.
1214   *         This parameter can be any combination of the following values:
1215   *            @arg  RTC_TAMPER_ALL: All tampers
1216   *            @arg  RTC_TAMPER_1: Tamper1
1217   *            @arg  RTC_TAMPER_2: Tamper2
1218   *            @arg  RTC_TAMPER_3: Tamper3
1219   *            @arg  RTC_TAMPER_4: Tamper4
1220   *            @arg  RTC_TAMPER_5: Tamper5
1221   *            @arg  RTC_TAMPER_6: Tamper6
1222   * @retval None
1223   */
1224 #define __HAL_RTC_TAMPER_ENABLE(__HANDLE__, __TAMPER__)           (TAMP->CR1 |= (__TAMPER__))
1225 
1226 /**
1227   * @brief  Disable the TAMP Tamper input detection.
1228   * @param  __HANDLE__ specifies the RTC handle.
1229   * @param  __TAMPER__ specifies the RTC Tamper sources to be enabled.
1230   *         This parameter can be any combination of the following values:
1231   *            @arg  RTC_TAMPER_ALL: All tampers
1232   *            @arg  RTC_TAMPER_1: Tamper1
1233   *            @arg  RTC_TAMPER_2: Tamper2
1234   *            @arg  RTC_TAMPER_3: Tamper3
1235   *            @arg  RTC_TAMPER_4: Tamper4
1236   *            @arg  RTC_TAMPER_5: Tamper5
1237   *            @arg  RTC_TAMPER_6: Tamper6
1238   */
1239 #define __HAL_RTC_TAMPER_DISABLE(__HANDLE__, __TAMPER__)           (TAMP->CR1 &= ~(__TAMPER__))
1240 
1241 
1242 /**************************************************************************************************/
1243 /**
1244   * @brief  Enable the TAMP Tamper interrupt.
1245   * @param  __HANDLE__ specifies the RTC handle.
1246   * @param  __INTERRUPT__ specifies the RTC Tamper interrupt sources to be enabled.
1247   *          This parameter can be any combination of the following values:
1248   *            @arg  RTC_IT_TAMP_ALL: All tampers interrupts
1249   *            @arg  RTC_IT_TAMP_1: Tamper1 interrupt
1250   *            @arg  RTC_IT_TAMP_2: Tamper2 interrupt
1251   *            @arg  RTC_IT_TAMP_3: Tamper3 interrupt
1252   *            @arg  RTC_IT_TAMP_4: Tamper4 interrupt
1253   *            @arg  RTC_IT_TAMP_5: Tamper5 interrupt
1254   *            @arg  RTC_IT_TAMP_6: Tamper6 interrupt
1255   *            @arg  RTC_IT_INT_TAMP_ALL: All Internal Tamper interrupts
1256   *            @arg  RTC_IT_INT_TAMP_3: Internal Tamper3 interrupt
1257   *            @arg  RTC_IT_INT_TAMP_5: Internal Tamper5 interrupt
1258   *            @arg  RTC_IT_INT_TAMP_6: Internal Tamper6 interrupt
1259   *            @arg  RTC_IT_INT_TAMP_7: Internal Tamper7 interrupt
1260   *            @arg  RTC_IT_INT_TAMP_8: Internal Tamper8 interrupt
1261   *            @arg  RTC_IT_INT_TAMP_9: Internal Tamper9 interrupt
1262   *            @arg  RTC_IT_INT_TAMP_11: Internal Tamper11 interrupt
1263   *            @arg  RTC_IT_INT_TAMP_12: Internal Tamper12 interrupt
1264   *            @arg  RTC_IT_INT_TAMP_13: Internal Tamper13 interrupt
1265   * @retval None
1266   */
1267 #define __HAL_RTC_TAMPER_ENABLE_IT(__HANDLE__, __INTERRUPT__)        (TAMP->IER |= (__INTERRUPT__))
1268 
1269 /**
1270   * @brief  Disable the TAMP Tamper interrupt.
1271   * @param  __HANDLE__ specifies the RTC handle.
1272   * @param  __INTERRUPT__ specifies the RTC Tamper interrupt sources to be disabled.
1273   *         This parameter can be any combination of the following values:
1274   *            @arg  RTC_IT_TAMP_ALL: All tampers interrupts
1275   *            @arg  RTC_IT_TAMP_1: Tamper1 interrupt
1276   *            @arg  RTC_IT_TAMP_2: Tamper2 interrupt
1277   *            @arg  RTC_IT_TAMP_3: Tamper3 interrupt
1278   *            @arg  RTC_IT_TAMP_4: Tamper4 interrupt
1279   *            @arg  RTC_IT_TAMP_5: Tamper5 interrupt
1280   *            @arg  RTC_IT_TAMP_6: Tamper6 interrupt
1281   *            @arg  RTC_IT_INT_TAMP_ALL: All Internal Tamper interrupts
1282   *            @arg  RTC_IT_INT_TAMP_3: Internal Tamper3 interrupt
1283   *            @arg  RTC_IT_INT_TAMP_5: Internal Tamper5 interrupt
1284   *            @arg  RTC_IT_INT_TAMP_6: Internal Tamper6 interrupt
1285   *            @arg  RTC_IT_INT_TAMP_7: Internal Tamper7 interrupt
1286   *            @arg  RTC_IT_INT_TAMP_8: Internal Tamper8 interrupt
1287   *            @arg  RTC_IT_INT_TAMP_9: Internal Tamper9 interrupt
1288   *            @arg  RTC_IT_INT_TAMP_11: Internal Tamper11 interrupt
1289   *            @arg  RTC_IT_INT_TAMP_12: Internal Tamper12 interrupt
1290   *            @arg  RTC_IT_INT_TAMP_13: Internal Tamper13 interrupt
1291   * @retval None
1292   */
1293 #define __HAL_RTC_TAMPER_DISABLE_IT(__HANDLE__, __INTERRUPT__)       (TAMP->IER &= ~(__INTERRUPT__))
1294 
1295 
1296 /**************************************************************************************************/
1297 /**
1298   * @brief  Check whether the specified RTC Tamper interrupt has occurred or not.
1299   * @param  __HANDLE__ specifies the RTC handle.
1300   * @param  __INTERRUPT__ specifies the RTC Tamper interrupt to check.
1301   *         This parameter can be:
1302   *            @arg  RTC_IT_TAMP_ALL: All tampers interrupts
1303   *            @arg  RTC_IT_TAMP_1: Tamper1 interrupt
1304   *            @arg  RTC_IT_TAMP_2: Tamper2 interrupt
1305   *            @arg  RTC_IT_TAMP_3: Tamper3 interrupt
1306   *            @arg  RTC_IT_TAMP_4: Tamper4 interrupt
1307   *            @arg  RTC_IT_TAMP_5: Tamper5 interrupt
1308   *            @arg  RTC_IT_TAMP_6: Tamper6 interrupt
1309   *            @arg  RTC_IT_INT_TAMP_ALL: All Internal Tamper interrupts
1310   *            @arg  RTC_IT_INT_TAMP_3: Internal Tamper3 interrupt
1311   *            @arg  RTC_IT_INT_TAMP_5: Internal Tamper5 interrupt
1312   *            @arg  RTC_IT_INT_TAMP_6: Internal Tamper6 interrupt
1313   *            @arg  RTC_IT_INT_TAMP_7: Internal Tamper7 interrupt
1314   *            @arg  RTC_IT_INT_TAMP_8: Internal Tamper8 interrupt
1315   *            @arg  RTC_IT_INT_TAMP_9: Internal Tamper9 interrupt
1316   *            @arg  RTC_IT_INT_TAMP_11: Internal Tamper11 interrupt
1317   *            @arg  RTC_IT_INT_TAMP_12: Internal Tamper12 interrupt
1318   *            @arg  RTC_IT_INT_TAMP_13: Internal Tamper13 interrupt
1319   * @retval The state of __INTERRUPT__ (TRUE or FALSE)
1320   */
1321 #define __HAL_RTC_TAMPER_GET_IT(__HANDLE__, __INTERRUPT__)    (((TAMP->MISR) & (__INTERRUPT__)) != 0U)
1322 
1323 /**
1324   * @brief  Check whether the specified RTC Tamper interrupt has been enabled or not.
1325   * @param  __HANDLE__ specifies the RTC handle.
1326   * @param  __INTERRUPT__ specifies the RTC Tamper interrupt source to check.
1327   *         This parameter can be:
1328   *            @arg  RTC_IT_TAMP_ALL: All tampers interrupts
1329   *            @arg  RTC_IT_TAMP_1: Tamper1 interrupt
1330   *            @arg  RTC_IT_TAMP_2: Tamper2 interrupt
1331   *            @arg  RTC_IT_TAMP_3: Tamper3 interrupt
1332   *            @arg  RTC_IT_TAMP_4: Tamper4 interrupt
1333   *            @arg  RTC_IT_TAMP_5: Tamper5 interrupt
1334   *            @arg  RTC_IT_TAMP_6: Tamper6 interrupt
1335   *            @arg  RTC_IT_INT_TAMP_ALL: All internal tampers interrupts
1336   *            @arg  RTC_IT_INT_TAMP_3: Internal Tamper3 interrupt
1337   *            @arg  RTC_IT_INT_TAMP_5: Internal Tamper5 interrupt
1338   *            @arg  RTC_IT_INT_TAMP_6: Internal Tamper6 interrupt
1339   *            @arg  RTC_IT_INT_TAMP_7: Internal Tamper7 interrupt
1340   *            @arg  RTC_IT_INT_TAMP_8: Internal Tamper8 interrupt
1341   *            @arg  RTC_IT_INT_TAMP_9: Internal Tamper9 interrupt
1342   *            @arg  RTC_IT_INT_TAMP_11: Internal Tamper11 interrupt
1343   *            @arg  RTC_IT_INT_TAMP_12: Internal Tamper12 interrupt
1344   *            @arg  RTC_IT_INT_TAMP_13: Internal Tamper13 interrupt
1345   * @retval The state of __INTERRUPT__ (TRUE or FALSE)
1346   */
1347 #define __HAL_RTC_TAMPER_GET_IT_SOURCE(__HANDLE__, __INTERRUPT__)   (((TAMP->IER) & (__INTERRUPT__)) != 0U)
1348 
1349 /**
1350   * @brief  Get the selected RTC Tampers flag status.
1351   * @param  __HANDLE__ specifies the RTC handle.
1352   * @param  __FLAG__ specifies the RTC Tamper Flag is pending or not.
1353   *          This parameter can be:
1354   *             @arg RTC_FLAG_TAMP_ALL: All tampers flag
1355   *             @arg RTC_FLAG_TAMP_1: Tamper1 flag
1356   *             @arg RTC_FLAG_TAMP_2: Tamper2 flag
1357   *             @arg RTC_FLAG_TAMP_3: Tamper3 flag
1358   *             @arg RTC_FLAG_TAMP_4: Tamper4 flag
1359   *             @arg RTC_FLAG_TAMP_5: Tamper5 flag
1360   *             @arg RTC_FLAG_TAMP_6: Tamper6 flag
1361   *             @arg RTC_FLAG_INT_TAMP_ALL: All Internal Tamper flags
1362   *             @arg RTC_FLAG_INT_TAMP_3: Internal Tamper3 flag
1363   *             @arg RTC_FLAG_INT_TAMP_5: Internal Tamper5 flag
1364   *             @arg RTC_FLAG_INT_TAMP_6: Internal Tamper6 flag
1365   *             @arg RTC_FLAG_INT_TAMP_7: Internal Tamper7 flag
1366   *             @arg RTC_FLAG_INT_TAMP_8: Internal Tamper8 flag
1367   *             @arg RTC_FLAG_INT_TAMP_9: Internal Tamper9 flag
1368   *             @arg RTC_FLAG_INT_TAMP_11: Internal Tamper11 flag
1369   *             @arg RTC_FLAG_INT_TAMP_12: Internal Tamper12 flag
1370   *             @arg RTC_FLAG_INT_TAMP_13: Internal Tamper13 flag
1371   * @retval The state of __FLAG__ (TRUE or FALSE)
1372   */
1373 #define __HAL_RTC_TAMPER_GET_FLAG(__HANDLE__, __FLAG__)        (((TAMP->SR) & (__FLAG__)) != 0U)
1374 
1375 /**
1376   * @brief  Clear the RTC Tamper's pending flags.
1377   * @param  __HANDLE__ specifies the RTC handle.
1378   * @param  __FLAG__ specifies the RTC Tamper Flag to clear.
1379   *          This parameter can be:
1380   *             @arg RTC_FLAG_TAMP_ALL: All tampers flag
1381   *             @arg RTC_FLAG_TAMP_1: Tamper1 flag
1382   *             @arg RTC_FLAG_TAMP_2: Tamper2 flag
1383   *             @arg RTC_FLAG_TAMP_3: Tamper3 flag
1384   *             @arg RTC_FLAG_TAMP_4: Tamper4 flag
1385   *             @arg RTC_FLAG_TAMP_5: Tamper5 flag
1386   *             @arg RTC_FLAG_TAMP_6: Tamper6 flag
1387   *             @arg RTC_FLAG_INT_TAMP_ALL: All Internal Tamper flags
1388   *             @arg RTC_FLAG_INT_TAMP_3: Internal Tamper3 flag
1389   *             @arg RTC_FLAG_INT_TAMP_5: Internal Tamper5 flag
1390   *             @arg RTC_FLAG_INT_TAMP_6: Internal Tamper6 flag
1391   *             @arg RTC_FLAG_INT_TAMP_7: Internal Tamper7 flag
1392   *             @arg RTC_FLAG_INT_TAMP_8: Internal Tamper8 flag
1393   *             @arg RTC_FLAG_INT_TAMP_9: Internal Tamper9 flag
1394   *             @arg RTC_FLAG_INT_TAMP_11: Internal Tamper11 flag
1395   *             @arg RTC_FLAG_INT_TAMP_12: Internal Tamper12 flag
1396   *             @arg RTC_FLAG_INT_TAMP_13: Internal Tamper13 flag
1397   * @retval None
1398   */
1399 #define __HAL_RTC_TAMPER_CLEAR_FLAG(__HANDLE__, __FLAG__)      ((TAMP->SCR) = (__FLAG__))
1400 /**
1401   * @}
1402   */
1403 
1404 /* --------------------------------- SSR Underflow ---------------------------------*/
1405 /** @defgroup RTCEx_SSR_Underflow RTC SSR Underflow
1406   * @{
1407   */
1408 
1409 /**
1410   * @brief  Enable the RTC SSRU interrupt.
1411   * @param  __HANDLE__ specifies the RTC handle.
1412   * @param  __INTERRUPT__ specifies the RTC SSRU interrupt sources to be enabled.
1413   *         This parameter can be:
1414   *            @arg @ref RTC_IT_SSRU SSRU interrupt
1415   * @retval None
1416   */
1417 #define __HAL_RTC_SSRU_ENABLE_IT(__HANDLE__, __INTERRUPT__)    (RTC->CR |= (RTC_CR_SSRUIE))
1418 
1419 /**
1420   * @brief  Disable the RTC SSRU interrupt.
1421   * @param  __HANDLE__ specifies the RTC handle.
1422   * @param  __INTERRUPT__ specifies the RTC SSRU interrupt sources to be disabled.
1423   *         This parameter can be:
1424   *            @arg @ref RTC_IT_SSRU SSRU interrupt
1425   * @retval None
1426   */
1427 #define __HAL_RTC_SSRU_DISABLE_IT(__HANDLE__, __INTERRUPT__)   (RTC->CR &= ~(RTC_CR_SSRUIE))
1428 
1429 
1430 /**
1431   * @brief  Check whether the specified RTC SSRU interrupt has occurred or not.
1432   * @param  __HANDLE__ specifies the RTC handle.
1433   * @param  __INTERRUPT__ specifies the RTC SSRU interrupt to check.
1434   *         This parameter can be:
1435   *            @arg @ref RTC_IT_SSRU  SSRU interrupt
1436   * @retval The state of __INTERRUPT__ (TRUE or FALSE)
1437   */
1438 #define __HAL_RTC_SSRU_GET_IT(__HANDLE__, __INTERRUPT__)       (((RTC->MISR) & (RTC_MISR_SSRUMF)) != 0U)
1439 /**
1440   * @brief  Check whether the specified RTC Wake Up timer interrupt has been enabled or not.
1441   * @param  __HANDLE__ specifies the RTC handle.
1442   * @param  __INTERRUPT__ specifies the RTC Wake Up timer interrupt sources to check.
1443   *         This parameter can be:
1444   *            @arg @ref RTC_IT_SSRU  SSRU interrupt
1445   * @retval The state of __INTERRUPT__ (TRUE or FALSE)
1446   */
1447 #define __HAL_RTC_SSRU_GET_IT_SOURCE(__HANDLE__, __INTERRUPT__)   (((RTC->CR) & (RTC_CR_SSRUIE)) != 0U)
1448 
1449 /**
1450   * @brief  Get the selected RTC SSRU's flag status.
1451   * @param  __HANDLE__ specifies the RTC handle.
1452   * @param  __FLAG__ specifies the RTC SSRU Flag is pending or not.
1453   *          This parameter can be:
1454   *             @arg @ref RTC_FLAG_SSRUF
1455   * @retval The state of __FLAG__ (TRUE or FALSE)
1456   */
1457 #define __HAL_RTC_SSRU_GET_FLAG(__HANDLE__, __FLAG__)       ((READ_BIT(RTC->SR, RTC_SR_SSRUF) == RTC_SR_SSRUF))
1458 
1459 /**
1460   * @brief  Clear the RTC Wake Up timer's pending flags.
1461   * @param  __HANDLE__ specifies the RTC handle.
1462   * @param  __FLAG__ specifies the RTC SSRU Flag to clear.
1463   *         This parameter can be:
1464   *            @arg @ref RTC_FLAG_SSRUF
1465   * @retval None
1466   */
1467 #define __HAL_RTC_SSRU_CLEAR_FLAG(__HANDLE__, __FLAG__)     (SET_BIT(RTC->SCR, RTC_SCR_CSSRUF))
1468 /**
1469   * @}
1470   */
1471 
1472 /**
1473   * @}
1474   */
1475 
1476 /* Exported functions --------------------------------------------------------*/
1477 /** @defgroup RTCEx_Exported_Functions RTCEx Exported Functions
1478   * @{
1479   */
1480 
1481 /* RTC TimeStamp functions *****************************************/
1482 /** @defgroup RTCEx_Exported_Functions_Group1 Extended RTC TimeStamp functions
1483   * @{
1484   */
1485 
1486 #ifdef RTC_CR_TSE
1487 HAL_StatusTypeDef HAL_RTCEx_SetTimeStamp(RTC_HandleTypeDef *hrtc, uint32_t TimeStampEdge, uint32_t RTC_TimeStampPin);
1488 HAL_StatusTypeDef HAL_RTCEx_SetTimeStamp_IT(RTC_HandleTypeDef *hrtc, uint32_t TimeStampEdge, uint32_t RTC_TimeStampPin);
1489 HAL_StatusTypeDef HAL_RTCEx_DeactivateTimeStamp(RTC_HandleTypeDef *hrtc);
1490 #endif /* RTC_CR_TSE */
1491 HAL_StatusTypeDef HAL_RTCEx_GetTimeStamp(const RTC_HandleTypeDef *hrtc, RTC_TimeTypeDef *sTimeStamp,
1492                                          RTC_DateTypeDef *sTimeStampDate, uint32_t Format);
1493 void              HAL_RTCEx_TimeStampIRQHandler(RTC_HandleTypeDef *hrtc);
1494 HAL_StatusTypeDef HAL_RTCEx_PollForTimeStampEvent(const RTC_HandleTypeDef *hrtc, uint32_t Timeout);
1495 void              HAL_RTCEx_TimeStampEventCallback(RTC_HandleTypeDef *hrtc);
1496 /**
1497   * @}
1498   */
1499 
1500 
1501 /* RTC Wake-up functions ******************************************************/
1502 /** @defgroup RTCEx_Exported_Functions_Group2 Extended RTC Wake-up functions
1503   * @{
1504   */
1505 
1506 HAL_StatusTypeDef HAL_RTCEx_SetWakeUpTimer(RTC_HandleTypeDef *hrtc, uint32_t WakeUpCounter, uint32_t WakeUpClock);
1507 HAL_StatusTypeDef HAL_RTCEx_SetWakeUpTimer_IT(RTC_HandleTypeDef *hrtc, uint32_t WakeUpCounter, uint32_t WakeUpClock,
1508                                               uint32_t WakeUpAutoClr);
1509 HAL_StatusTypeDef HAL_RTCEx_DeactivateWakeUpTimer(RTC_HandleTypeDef *hrtc);
1510 uint32_t          HAL_RTCEx_GetWakeUpTimer(const RTC_HandleTypeDef *hrtc);
1511 void              HAL_RTCEx_WakeUpTimerIRQHandler(RTC_HandleTypeDef *hrtc);
1512 void              HAL_RTCEx_WakeUpTimerEventCallback(RTC_HandleTypeDef *hrtc);
1513 HAL_StatusTypeDef HAL_RTCEx_PollForWakeUpTimerEvent(const RTC_HandleTypeDef *hrtc, uint32_t Timeout);
1514 /**
1515   * @}
1516   */
1517 
1518 /* Extended Control functions ************************************************/
1519 /** @defgroup RTCEx_Exported_Functions_Group3 Extended Peripheral Control functions
1520   * @{
1521   */
1522 
1523 HAL_StatusTypeDef HAL_RTCEx_SetSmoothCalib(RTC_HandleTypeDef *hrtc, uint32_t SmoothCalibPeriod,
1524                                            uint32_t SmoothCalibPlusPulses, uint32_t SmoothCalibMinusPulsesValue);
1525 HAL_StatusTypeDef HAL_RTCEx_SetLowPowerCalib(RTC_HandleTypeDef *hrtc, uint32_t LowPowerCalib);
1526 HAL_StatusTypeDef HAL_RTCEx_SetSynchroShift(RTC_HandleTypeDef *hrtc, uint32_t ShiftAdd1S, uint32_t ShiftSubFS);
1527 #if defined(RTC_CR_COSEL)
1528 HAL_StatusTypeDef HAL_RTCEx_SetCalibrationOutPut(RTC_HandleTypeDef *hrtc, uint32_t CalibOutput);
1529 HAL_StatusTypeDef HAL_RTCEx_DeactivateCalibrationOutPut(RTC_HandleTypeDef *hrtc);
1530 #endif /* RTC_CR_COSEL */
1531 #if defined(RTC_CR_REFCKON)
1532 HAL_StatusTypeDef HAL_RTCEx_SetRefClock(RTC_HandleTypeDef *hrtc);
1533 HAL_StatusTypeDef HAL_RTCEx_DeactivateRefClock(RTC_HandleTypeDef *hrtc);
1534 #endif /* RTC_CR_REFCKON */
1535 HAL_StatusTypeDef HAL_RTCEx_EnableBypassShadow(RTC_HandleTypeDef *hrtc);
1536 HAL_StatusTypeDef HAL_RTCEx_DisableBypassShadow(RTC_HandleTypeDef *hrtc);
1537 HAL_StatusTypeDef HAL_RTCEx_MonotonicCounterIncrement(const RTC_HandleTypeDef *hrtc, uint32_t Instance);
1538 HAL_StatusTypeDef HAL_RTCEx_MonotonicCounterGet(const RTC_HandleTypeDef *hrtc, uint32_t Instance, uint32_t *pValue);
1539 HAL_StatusTypeDef HAL_RTCEx_SetSSRU_IT(RTC_HandleTypeDef *hrtc);
1540 HAL_StatusTypeDef HAL_RTCEx_DeactivateSSRU(RTC_HandleTypeDef *hrtc);
1541 void              HAL_RTCEx_SSRUIRQHandler(RTC_HandleTypeDef *hrtc);
1542 void              HAL_RTCEx_SSRUEventCallback(RTC_HandleTypeDef *hrtc);
1543 
1544 /**
1545   * @}
1546   */
1547 
1548 /* Extended RTC features functions *******************************************/
1549 /** @defgroup RTCEx_Exported_Functions_Group4 Extended features functions
1550   * @{
1551   */
1552 
1553 void              HAL_RTCEx_AlarmBEventCallback(RTC_HandleTypeDef *hrtc);
1554 HAL_StatusTypeDef HAL_RTCEx_PollForAlarmBEvent(const RTC_HandleTypeDef *hrtc, uint32_t Timeout);
1555 /**
1556   * @}
1557   */
1558 
1559 /** @defgroup RTCEx_Exported_Functions_Group5 Extended RTC Tamper functions
1560   * @{
1561   */
1562 HAL_StatusTypeDef HAL_RTCEx_SetTamper(const RTC_HandleTypeDef *hrtc, const RTC_TamperTypeDef *sTamper);
1563 HAL_StatusTypeDef HAL_RTCEx_SetActiveTampers(RTC_HandleTypeDef *hrtc, const RTC_ActiveTampersTypeDef *sAllTamper);
1564 HAL_StatusTypeDef HAL_RTCEx_SetActiveSeed(RTC_HandleTypeDef *hrtc, const uint32_t *pSeed);
1565 HAL_StatusTypeDef HAL_RTCEx_SetTamper_IT(const RTC_HandleTypeDef *hrtc, const RTC_TamperTypeDef *sTamper);
1566 HAL_StatusTypeDef HAL_RTCEx_DeactivateTamper(const RTC_HandleTypeDef *hrtc, uint32_t Tamper);
1567 HAL_StatusTypeDef HAL_RTCEx_DeactivateActiveTampers(const RTC_HandleTypeDef *hrtc);
1568 HAL_StatusTypeDef HAL_RTCEx_PollForTamperEvent(const RTC_HandleTypeDef *hrtc, uint32_t Tamper, uint32_t Timeout);
1569 HAL_StatusTypeDef HAL_RTCEx_SetInternalTamper(const RTC_HandleTypeDef *hrtc,
1570                                               const RTC_InternalTamperTypeDef *sIntTamper);
1571 HAL_StatusTypeDef HAL_RTCEx_SetInternalTamper_IT(const RTC_HandleTypeDef *hrtc,
1572                                                  const RTC_InternalTamperTypeDef *sIntTamper);
1573 HAL_StatusTypeDef HAL_RTCEx_DeactivateInternalTamper(const RTC_HandleTypeDef *hrtc, uint32_t IntTamper);
1574 HAL_StatusTypeDef HAL_RTCEx_PollForInternalTamperEvent(const RTC_HandleTypeDef *hrtc, uint32_t IntTamper,
1575                                                        uint32_t Timeout);
1576 #if defined(TAMP_SECCFGR_BHKLOCK)
1577 HAL_StatusTypeDef HAL_RTCEx_LockBootHardwareKey(const RTC_HandleTypeDef *hrtc);
1578 #endif /* TAMP_SECCFGR_BHKLOCK */
1579 void              HAL_RTCEx_TamperIRQHandler(RTC_HandleTypeDef *hrtc);
1580 void              HAL_RTCEx_Tamper1EventCallback(RTC_HandleTypeDef *hrtc);
1581 void              HAL_RTCEx_Tamper2EventCallback(RTC_HandleTypeDef *hrtc);
1582 void              HAL_RTCEx_Tamper3EventCallback(RTC_HandleTypeDef *hrtc);
1583 void              HAL_RTCEx_Tamper4EventCallback(RTC_HandleTypeDef *hrtc);
1584 void              HAL_RTCEx_Tamper5EventCallback(RTC_HandleTypeDef *hrtc);
1585 void              HAL_RTCEx_Tamper6EventCallback(RTC_HandleTypeDef *hrtc);
1586 void              HAL_RTCEx_InternalTamper3EventCallback(RTC_HandleTypeDef *hrtc);
1587 void              HAL_RTCEx_InternalTamper5EventCallback(RTC_HandleTypeDef *hrtc);
1588 void              HAL_RTCEx_InternalTamper6EventCallback(RTC_HandleTypeDef *hrtc);
1589 void              HAL_RTCEx_InternalTamper7EventCallback(RTC_HandleTypeDef *hrtc);
1590 void              HAL_RTCEx_InternalTamper8EventCallback(RTC_HandleTypeDef *hrtc);
1591 void              HAL_RTCEx_InternalTamper9EventCallback(RTC_HandleTypeDef *hrtc);
1592 void              HAL_RTCEx_InternalTamper11EventCallback(RTC_HandleTypeDef *hrtc);
1593 void              HAL_RTCEx_InternalTamper12EventCallback(RTC_HandleTypeDef *hrtc);
1594 void              HAL_RTCEx_InternalTamper13EventCallback(RTC_HandleTypeDef *hrtc);
1595 
1596 /**
1597   * @}
1598   */
1599 
1600 /** @defgroup RTCEx_Exported_Functions_Group6 Extended RTC Backup register functions
1601   * @{
1602   */
1603 void              HAL_RTCEx_BKUPWrite(const RTC_HandleTypeDef *hrtc, uint32_t BackupRegister, uint32_t Data);
1604 uint32_t          HAL_RTCEx_BKUPRead(const RTC_HandleTypeDef *hrtc, uint32_t BackupRegister);
1605 void              HAL_RTCEx_BKUPErase(const RTC_HandleTypeDef *hrtc);
1606 void              HAL_RTCEx_BKUPBlock(const RTC_HandleTypeDef *hrtc);
1607 void              HAL_RTCEx_BKUPUnblock(const RTC_HandleTypeDef *hrtc);
1608 #ifdef TAMP_RPCFGR_RPCFG
1609 void              HAL_RTCEx_ConfigEraseDeviceSecrets(const RTC_HandleTypeDef *hrtc, uint32_t DeviceSecretConf);
1610 #endif /* TAMP_RPCFGR_RPCFG */
1611 /**
1612   * @}
1613   */
1614 
1615 #if defined(RTC_SECCFGR_SEC)
1616 /** @defgroup RTCEx_Exported_Functions_Group7 Extended RTC secure functions
1617   * @{
1618   */
1619 HAL_StatusTypeDef HAL_RTCEx_SecureModeGet(const RTC_HandleTypeDef *hrtc, RTC_SecureStateTypeDef  *secureState);
1620 #if defined (__ARM_FEATURE_CMSE) && (__ARM_FEATURE_CMSE == 3U)
1621 HAL_StatusTypeDef HAL_RTCEx_SecureModeSet(const RTC_HandleTypeDef *hrtc, const RTC_SecureStateTypeDef  *secureState);
1622 #endif /* #if defined (__ARM_FEATURE_CMSE) && (__ARM_FEATURE_CMSE == 3U) */
1623 /**
1624   * @}
1625   */
1626 #endif /* RTC_SECCFGR_SEC */
1627 
1628 #if defined(TAMP_PRIVCFGR_TAMPPRIV)
1629 /** @defgroup RTCEx_Exported_Functions_Group8 Extended RTC privilege functions
1630   * @{
1631   */
1632 HAL_StatusTypeDef HAL_RTCEx_PrivilegeModeSet(const RTC_HandleTypeDef *hrtc,
1633                                              const RTC_PrivilegeStateTypeDef *privilegeState);
1634 HAL_StatusTypeDef HAL_RTCEx_PrivilegeModeGet(const RTC_HandleTypeDef *hrtc, RTC_PrivilegeStateTypeDef *privilegeState);
1635 /**
1636   * @}
1637   */
1638 #endif /* TAMP_PRIVCFGR_TAMPPRIV */
1639 
1640 /**
1641   * @}
1642   */
1643 
1644 /* Private types -------------------------------------------------------------*/
1645 /* Private variables ---------------------------------------------------------*/
1646 /* Private constants ---------------------------------------------------------*/
1647 /* Private macros ------------------------------------------------------------*/
1648 /** @defgroup RTCEx_Private_Macros RTCEx Private Macros
1649   * @{
1650   */
1651 
1652 /** @defgroup RTCEx_IS_RTC_Definitions Private macros to check input parameters
1653   * @{
1654   */
1655 #if defined(RTC_CR_TSEDGE)
1656 #define IS_TIMESTAMP_EDGE(EDGE) (((EDGE) == RTC_TIMESTAMPEDGE_RISING) || \
1657                                  ((EDGE) == RTC_TIMESTAMPEDGE_FALLING))
1658 #endif /* RTC_CR_TSEDGE */
1659 
1660 #define IS_RTC_TIMESTAMP_PIN(PIN)  (((PIN) == RTC_TIMESTAMPPIN_DEFAULT))
1661 
1662 #define IS_RTC_TIMESTAMPONTAMPER_DETECTION(DETECTION) (((DETECTION) == RTC_TIMESTAMPONTAMPERDETECTION_ENABLE) || \
1663                                                        ((DETECTION) == RTC_TIMESTAMPONTAMPERDETECTION_DISABLE))
1664 
1665 #if defined(RTC_CR_TAMPOE)
1666 #define IS_RTC_TAMPER_TAMPERDETECTIONOUTPUT(MODE)    (((MODE) == RTC_TAMPERDETECTIONOUTPUT_ENABLE) || \
1667                                                       ((MODE) == RTC_TAMPERDETECTIONOUTPUT_DISABLE))
1668 #endif /* RTC_CR_TAMPOE */
1669 
1670 #define IS_RTC_WAKEUP_CLOCK(CLOCK) (((CLOCK) == RTC_WAKEUPCLOCK_RTCCLK_DIV16)   || \
1671                                     ((CLOCK) == RTC_WAKEUPCLOCK_RTCCLK_DIV8)    || \
1672                                     ((CLOCK) == RTC_WAKEUPCLOCK_RTCCLK_DIV4)    || \
1673                                     ((CLOCK) == RTC_WAKEUPCLOCK_RTCCLK_DIV2)    || \
1674                                     ((CLOCK) == RTC_WAKEUPCLOCK_CK_SPRE_16BITS) || \
1675                                     ((CLOCK) == RTC_WAKEUPCLOCK_CK_SPRE_17BITS))
1676 
1677 #define IS_RTC_WAKEUP_COUNTER(COUNTER)  ((COUNTER) <= RTC_WUTR_WUT)
1678 
1679 #define IS_RTC_SMOOTH_CALIB_PERIOD(PERIOD) (((PERIOD) == RTC_SMOOTHCALIB_PERIOD_32SEC) || \
1680                                             ((PERIOD) == RTC_SMOOTHCALIB_PERIOD_16SEC) || \
1681                                             ((PERIOD) == RTC_SMOOTHCALIB_PERIOD_8SEC))
1682 
1683 #define IS_RTC_SMOOTH_CALIB_PLUS(PLUS) (((PLUS) == RTC_SMOOTHCALIB_PLUSPULSES_SET) || \
1684                                         ((PLUS) == RTC_SMOOTHCALIB_PLUSPULSES_RESET))
1685 
1686 #define IS_RTC_SMOOTH_CALIB_MINUS(VALUE) ((VALUE) <= RTC_CALR_CALM)
1687 
1688 #define IS_RTC_LOW_POWER_CALIB(LPCAL) (((LPCAL) == RTC_LPCAL_SET) || \
1689                                        ((LPCAL) == RTC_LPCAL_RESET))
1690 
1691 
1692 #define IS_RTC_TAMPER(__TAMPER__)                ((((__TAMPER__) & RTC_TAMPER_ALL) != 0U) && \
1693                                                   (((__TAMPER__) & ~RTC_TAMPER_ALL) == 0U))
1694 
1695 #define IS_RTC_INTERNAL_TAMPER(__INT_TAMPER__)   ((((__INT_TAMPER__) & RTC_INT_TAMPER_ALL) != 0U) && \
1696                                                   (((__INT_TAMPER__) & ~RTC_INT_TAMPER_ALL) == 0U))
1697 
1698 #define IS_RTC_TAMPER_TRIGGER(__TRIGGER__)       (((__TRIGGER__) == RTC_TAMPERTRIGGER_RISINGEDGE)  || \
1699                                                   ((__TRIGGER__) == RTC_TAMPERTRIGGER_FALLINGEDGE) || \
1700                                                   ((__TRIGGER__) == RTC_TAMPERTRIGGER_LOWLEVEL)    || \
1701                                                   ((__TRIGGER__) == RTC_TAMPERTRIGGER_HIGHLEVEL))
1702 
1703 #define IS_RTC_TAMPER_ERASE_MODE(__MODE__)       (((__MODE__) == RTC_TAMPER_ERASE_BACKUP_ENABLE) || \
1704                                                   ((__MODE__) == RTC_TAMPER_ERASE_BACKUP_DISABLE))
1705 
1706 #define IS_RTC_TAMPER_MASKFLAG_STATE(__STATE__)  (((__STATE__) == RTC_TAMPERMASK_FLAG_ENABLE) || \
1707                                                   ((__STATE__) == RTC_TAMPERMASK_FLAG_DISABLE))
1708 
1709 #define IS_RTC_TAMPER_FILTER(__FILTER__)         (((__FILTER__) == RTC_TAMPERFILTER_DISABLE)  || \
1710                                                   ((__FILTER__) == RTC_TAMPERFILTER_2SAMPLE) || \
1711                                                   ((__FILTER__) == RTC_TAMPERFILTER_4SAMPLE) || \
1712                                                   ((__FILTER__) == RTC_TAMPERFILTER_8SAMPLE))
1713 
1714 #define IS_RTC_TAMPER_SAMPLING_FREQ(__FREQ__)    (((__FREQ__) == RTC_TAMPERSAMPLINGFREQ_RTCCLK_DIV32768)|| \
1715                                                   ((__FREQ__) == RTC_TAMPERSAMPLINGFREQ_RTCCLK_DIV16384)|| \
1716                                                   ((__FREQ__) == RTC_TAMPERSAMPLINGFREQ_RTCCLK_DIV8192) || \
1717                                                   ((__FREQ__) == RTC_TAMPERSAMPLINGFREQ_RTCCLK_DIV4096) || \
1718                                                   ((__FREQ__) == RTC_TAMPERSAMPLINGFREQ_RTCCLK_DIV2048) || \
1719                                                   ((__FREQ__) == RTC_TAMPERSAMPLINGFREQ_RTCCLK_DIV1024) || \
1720                                                   ((__FREQ__) == RTC_TAMPERSAMPLINGFREQ_RTCCLK_DIV512)  || \
1721                                                   ((__FREQ__) == RTC_TAMPERSAMPLINGFREQ_RTCCLK_DIV256))
1722 
1723 #define IS_RTC_TAMPER_PRECHARGE_DURATION(__DURATION__)   (((__DURATION__) == RTC_TAMPERPRECHARGEDURATION_1RTCCLK) || \
1724                                                           ((__DURATION__) == RTC_TAMPERPRECHARGEDURATION_2RTCCLK) || \
1725                                                           ((__DURATION__) == RTC_TAMPERPRECHARGEDURATION_4RTCCLK) || \
1726                                                           ((__DURATION__) == RTC_TAMPERPRECHARGEDURATION_8RTCCLK))
1727 
1728 #define IS_RTC_TAMPER_PULLUP_STATE(__STATE__)    (((__STATE__) == RTC_TAMPER_PULLUP_ENABLE) || \
1729                                                   ((__STATE__) == RTC_TAMPER_PULLUP_DISABLE))
1730 
1731 #define IS_RTC_TAMPER_TIMESTAMPONTAMPER_DETECTION(DETECTION)  \
1732   (((DETECTION) == RTC_TIMESTAMPONTAMPERDETECTION_ENABLE) || \
1733    ((DETECTION) == RTC_TIMESTAMPONTAMPERDETECTION_DISABLE))
1734 
1735 #define IS_RTC_ATAMPER_FILTER(__FILTER__)                    (((__FILTER__) == RTC_ATAMP_FILTER_ENABLE) || \
1736                                                               ((__FILTER__) == RTC_ATAMP_FILTER_DISABLE))
1737 
1738 #define IS_RTC_ATAMPER_OUTPUT_CHANGE_PERIOD(__PERIOD__)      ((__PERIOD__) <= 7U)
1739 
1740 #define IS_RTC_ATAMPER_ASYNCPRES_RTCCLK(__PRESCALER__)       (((__PRESCALER__) == RTC_ATAMP_ASYNCPRES_RTCCLK)     || \
1741                                                               ((__PRESCALER__) == RTC_ATAMP_ASYNCPRES_RTCCLK_2)   || \
1742                                                               ((__PRESCALER__) == RTC_ATAMP_ASYNCPRES_RTCCLK_4)   || \
1743                                                               ((__PRESCALER__) == RTC_ATAMP_ASYNCPRES_RTCCLK_8)   || \
1744                                                               ((__PRESCALER__) == RTC_ATAMP_ASYNCPRES_RTCCLK_16)  || \
1745                                                               ((__PRESCALER__) == RTC_ATAMP_ASYNCPRES_RTCCLK_32)  || \
1746                                                               ((__PRESCALER__) == RTC_ATAMP_ASYNCPRES_RTCCLK_64)  || \
1747                                                               ((__PRESCALER__) == RTC_ATAMP_ASYNCPRES_RTCCLK_128))
1748 
1749 
1750 #define IS_RTC_BKP(__BKP__)   ((__BKP__) < RTC_BKP_NUMBER)
1751 
1752 #define IS_RTC_SHIFT_ADD1S(SEL) (((SEL) == RTC_SHIFTADD1S_RESET) || \
1753                                  ((SEL) == RTC_SHIFTADD1S_SET))
1754 
1755 #define IS_RTC_SHIFT_SUBFS(FS) ((FS) <= RTC_SHIFTR_SUBFS)
1756 
1757 #if defined(RTC_CR_COSEL)
1758 #define IS_RTC_CALIB_OUTPUT(OUTPUT)  (((OUTPUT) == RTC_CALIBOUTPUT_512HZ) || \
1759                                       ((OUTPUT) == RTC_CALIBOUTPUT_1HZ))
1760 #endif /* RTC_CR_COSEL */
1761 
1762 #define IS_RTC_SECURE_FULL(__STATE__) (((__STATE__) == RTC_SECURE_FULL_YES) || \
1763                                        ((__STATE__) == RTC_SECURE_FULL_NO))
1764 
1765 #define IS_RTC_NONSECURE_FEATURES(__FEATURES__) (((__FEATURES__) & ~RTC_NONSECURE_FEATURE_ALL) == 0U)
1766 
1767 #define IS_TAMP_SECURE_FULL(__STATE__) (((__STATE__) == TAMP_SECURE_FULL_YES) || \
1768                                         ((__STATE__) == TAMP_SECURE_FULL_NO))
1769 
1770 #define IS_TAMP_MONOTONIC_CNT_SECURE(__STATE__) (((__STATE__) == TAMP_MONOTONIC_CNT_SECURE_YES) || \
1771                                                  ((__STATE__) == TAMP_MONOTONIC_CNT_SECURE_NO))
1772 
1773 #define IS_RTC_PRIVILEGE_FULL(__STATE__) (((__STATE__) == RTC_PRIVILEGE_FULL_YES) || \
1774                                           ((__STATE__) == RTC_PRIVILEGE_FULL_NO))
1775 
1776 #define IS_RTC_PRIVILEGE_FEATURES(__FEATURES__) (((__FEATURES__) & ~RTC_PRIVILEGE_FEATURE_ALL) == 0U)
1777 
1778 #define IS_TAMP_PRIVILEGE_FULL(__STATE__) (((__STATE__) == TAMP_PRIVILEGE_FULL_YES) || \
1779                                            ((__STATE__) == TAMP_PRIVILEGE_FULL_NO))
1780 
1781 #define IS_TAMP_MONOTONIC_CNT_PRIVILEGE(__STATE__) (((__STATE__) == TAMP_MONOTONIC_CNT_PRIVILEGE_YES) || \
1782                                                     ((__STATE__) == TAMP_MONOTONIC_CNT_PRIVILEGE_NO))
1783 
1784 #define IS_RTC_PRIVILEGE_BKUP_ZONE(__ZONES__) (((__ZONES__) & ~RTC_PRIVILEGE_BKUP_ZONE_ALL) == 0U)
1785 
1786 #define IS_RTC_BINARY_MODE(MODE) (((MODE) == RTC_BINARY_NONE) || \
1787                                   ((MODE) == RTC_BINARY_ONLY) || \
1788                                   ((MODE) == RTC_BINARY_MIX ))
1789 
1790 #define IS_RTC_BINARY_MIX_BCDU(BDCU) (((BDCU) == RTC_BINARY_MIX_BCDU_0) || \
1791                                       ((BDCU) == RTC_BINARY_MIX_BCDU_1) || \
1792                                       ((BDCU) == RTC_BINARY_MIX_BCDU_2) || \
1793                                       ((BDCU) == RTC_BINARY_MIX_BCDU_3) || \
1794                                       ((BDCU) == RTC_BINARY_MIX_BCDU_4) || \
1795                                       ((BDCU) == RTC_BINARY_MIX_BCDU_5) || \
1796                                       ((BDCU) == RTC_BINARY_MIX_BCDU_6) || \
1797                                       ((BDCU) == RTC_BINARY_MIX_BCDU_7))
1798 
1799 #define IS_RTC_ALARM_SUB_SECOND_BINARY_MASK(MASK)   (((MASK) == 0U) || \
1800                                                      (((MASK) >= RTC_ALARMSUBSECONDBINMASK_SS31_1) &&\
1801                                                       ((MASK) <= RTC_ALARMSUBSECONDBINMASK_NONE)))
1802 
1803 #define IS_RTC_ALARMSUBSECONDBIN_AUTOCLR(SEL) (((SEL) == RTC_ALARMSUBSECONDBIN_AUTOCLR_NO) || \
1804                                                ((SEL) == RTC_ALARMSUBSECONDBIN_AUTOCLR_YES))
1805 /**
1806   * @}
1807   */
1808 
1809 /**
1810   * @}
1811   */
1812 
1813 /**
1814   * @}
1815   */
1816 
1817 /**
1818   * @}
1819   */
1820 
1821 /**
1822   * @}
1823   */
1824 
1825 /**
1826   * @}
1827   */
1828 
1829 #ifdef __cplusplus
1830 }
1831 #endif
1832 
1833 #endif /* STM32WBAxx_HAL_RTC_EX_H */
1834 
1835