STAR
Cal STAR — firmware, DAQ server, and engine design
Loading...
Searching...
No Matches
stm32h7xx_hal_rtc_ex.c
Go to the documentation of this file.
1/**
2 ******************************************************************************
3 * @file stm32h7xx_hal_rtc_ex.c
4 * @author MCD Application Team
5 * @brief Extended RTC HAL module driver.
6 * This file provides firmware functions to manage the following
7 * functionalities of the Real Time Clock (RTC) Extended peripheral:
8 * + RTC Time Stamp functions
9 * + RTC Tamper functions
10 * + RTC Wake-up functions
11 * + Extended Control functions
12 * + Extended RTC features functions
13 *
14 ******************************************************************************
15 * @attention
16 *
17 * Copyright (c) 2017 STMicroelectronics.
18 * All rights reserved.
19 *
20 * This software is licensed under terms that can be found in the LICENSE file
21 * in the root directory of this software component.
22 * If no LICENSE file comes with this software, it is provided AS-IS.
23 *
24 ******************************************************************************
25 @verbatim
26 ==============================================================================
27 ##### How to use this driver #####
28 ==============================================================================
29 [..]
30 (+) Enable the RTC domain access.
31 (+) Configure the RTC Prescaler (Asynchronous and Synchronous) and RTC hour
32 format using the HAL_RTC_Init() function.
33
34 *** RTC Wakeup configuration ***
35 ================================
36 [..]
37 (+) To configure the RTC Wakeup Clock source and Counter use the HAL_RTCEx_SetWakeUpTimer()
38 function. You can also configure the RTC Wakeup timer with interrupt mode
39 using the HAL_RTCEx_SetWakeUpTimer_IT() function.
40 (+) To read the RTC WakeUp Counter register, use the HAL_RTCEx_GetWakeUpTimer()
41 function.
42
43 *** Outputs configuration ***
44 =============================
45 [..] The RTC has 2 different outputs:
46 (+) RTC_ALARM: this output is used to manage the RTC Alarm A, Alarm B
47 and WaKeUp signals.
48 To output the selected RTC signal, use the HAL_RTC_Init() function.
49 (+) RTC_CALIB: this output is 512Hz signal or 1Hz.
50 To enable the RTC_CALIB, use the HAL_RTCEx_SetCalibrationOutPut() function.
51 (+) Two pins can be used as RTC_ALARM or RTC_CALIB (PC13, PB2) managed on
52 the RTC_OR register.
53 (+) When the RTC_CALIB or RTC_ALARM output is selected, the RTC_OUT pin is
54 automatically configured in output alternate function.
55
56 *** Smooth digital Calibration configuration ***
57 ================================================
58 [..]
59 (+) Configure the RTC Original Digital Calibration Value and the corresponding
60 calibration cycle period (32s,16s and 8s) using the HAL_RTCEx_SetSmoothCalib()
61 function.
62
63 *** TimeStamp configuration ***
64 ===============================
65 [..]
66 (+) Enable the RTC TimeStamp using the HAL_RTCEx_SetTimeStamp() function.
67 You can also configure the RTC TimeStamp with interrupt mode using the
68 HAL_RTCEx_SetTimeStamp_IT() function.
69 (+) To read the RTC TimeStamp Time and Date register, use the HAL_RTCEx_GetTimeStamp()
70 function.
71
72 *** Internal TimeStamp configuration ***
73 ===============================
74 [..]
75 (+) Enable the RTC internal TimeStamp using the HAL_RTCEx_SetInternalTimeStamp() function.
76 User has to check internal timestamp occurrence using __HAL_RTC_INTERNAL_TIMESTAMP_GET_FLAG.
77 (+) To read the RTC TimeStamp Time and Date register, use the HAL_RTCEx_GetTimeStamp()
78 function.
79
80 *** Tamper configuration ***
81 ============================
82 [..]
83 (+) Enable the RTC Tamper and configure the Tamper filter count, trigger Edge
84 or Level according to the Tamper filter (if equal to 0 Edge else Level)
85 value, sampling frequency, NoErase, MaskFlag, precharge or discharge and
86 Pull-UP using the HAL_RTCEx_SetTamper() function. You can configure RTC Tamper
87 with interrupt mode using HAL_RTCEx_SetTamper_IT() function.
88 (+) The default configuration of the Tamper erases the backup registers. To avoid
89 erase, enable the NoErase field on the RTC_TAMPCR register.
90
91 *** Backup Data Registers configuration ***
92 ===========================================
93 [..]
94 (+) To write to the RTC Backup Data registers, use the HAL_RTCEx_BKUPWrite()
95 function.
96 (+) To read the RTC Backup Data registers, use the HAL_RTCEx_BKUPRead()
97 function.
98
99 @endverbatim
100 */
101
102/* Includes ------------------------------------------------------------------*/
103#include "stm32h7xx_hal.h"
104
105/** @addtogroup STM32H7xx_HAL_Driver
106 * @{
107 */
108
109/** @addtogroup RTCEx
110 * @brief RTC Extended HAL module driver
111 * @{
112 */
113
114#ifdef HAL_RTC_MODULE_ENABLED
115
116/* Private typedef -----------------------------------------------------------*/
117/* Private define ------------------------------------------------------------*/
118#if defined(TAMP)
119#define TAMP_ALL (TAMP_CR1_TAMP1E | TAMP_CR1_TAMP2E | TAMP_CR1_TAMP3E)
120#endif /* TAMP */
121
122/* Private macro -------------------------------------------------------------*/
123/* Private variables ---------------------------------------------------------*/
124/* Private function prototypes -----------------------------------------------*/
125/* Exported functions --------------------------------------------------------*/
126
127/** @addtogroup RTCEx_Exported_Functions
128 * @{
129 */
130
131
132/** @addtogroup RTCEx_Exported_Functions_Group1
133 * @brief RTC TimeStamp and Tamper functions
134 *
135@verbatim
136 ===============================================================================
137 ##### RTC TimeStamp and Tamper functions #####
138 ===============================================================================
139
140 [..] This section provides functions allowing to configure TimeStamp feature
141
142@endverbatim
143 * @{
144 */
145
146/**
147 * @brief Set TimeStamp.
148 * @note This API must be called before enabling the TimeStamp feature.
149 * @param hrtc RTC handle
150 * @param TimeStampEdge Specifies the pin edge on which the TimeStamp is
151 * activated.
152 * This parameter can be one of the following values:
153 * @arg RTC_TIMESTAMPEDGE_RISING: the Time stamp event occurs on the
154 * rising edge of the related pin.
155 * @arg RTC_TIMESTAMPEDGE_FALLING: the Time stamp event occurs on the
156 * falling edge of the related pin.
157 * @param RTC_TimeStampPin specifies the RTC TimeStamp Pin.
158 * This parameter can be one of the following values:
159 * @arg RTC_TIMESTAMPPIN_DEFAULT: PC13 is selected as RTC TimeStamp Pin.
160 * The RTC TimeStamp Pin is per default PC13, but for reasons of
161 * compatibility, this parameter is required.
162 * @retval HAL status
163 */
164HAL_StatusTypeDef HAL_RTCEx_SetTimeStamp(RTC_HandleTypeDef *hrtc, uint32_t TimeStampEdge, uint32_t RTC_TimeStampPin)
165{
166 uint32_t tmpreg;
167
168 /* Check the parameters */
169 assert_param(IS_TIMESTAMP_EDGE(TimeStampEdge));
170 assert_param(IS_RTC_TIMESTAMP_PIN(RTC_TimeStampPin));
171
172 /* Prevent unused argument(s) compilation warning if no assert_param check */
173 UNUSED(RTC_TimeStampPin);
174
175 /* Process Locked */
177
178 hrtc->State = HAL_RTC_STATE_BUSY;
179
180 /* Get the RTC_CR register and clear the bits to be configured */
181 tmpreg = (uint32_t)(hrtc->Instance->CR & (uint32_t)~(RTC_CR_TSEDGE | RTC_CR_TSE));
182
183 tmpreg |= TimeStampEdge;
184
185 /* Disable the write protection for RTC registers */
187
188 /* Configure the Time Stamp TSEDGE and Enable bits */
189 hrtc->Instance->CR = (uint32_t)tmpreg;
190
192
193 /* Enable the write protection for RTC registers */
195
196 /* Change RTC state */
197 hrtc->State = HAL_RTC_STATE_READY;
198
199 /* Process Unlocked */
201
202 return HAL_OK;
203}
204
205/**
206 * @brief Set TimeStamp with Interrupt.
207 * @note This API must be called before enabling the TimeStamp feature.
208 * @param hrtc RTC handle
209 * @param TimeStampEdge Specifies the pin edge on which the TimeStamp is
210 * activated.
211 * This parameter can be one of the following values:
212 * @arg RTC_TIMESTAMPEDGE_RISING: the Time stamp event occurs on the
213 * rising edge of the related pin.
214 * @arg RTC_TIMESTAMPEDGE_FALLING: the Time stamp event occurs on the
215 * falling edge of the related pin.
216 * @param RTC_TimeStampPin Specifies the RTC TimeStamp Pin.
217 * This parameter can be one of the following values:
218 * @arg RTC_TIMESTAMPPIN_DEFAULT: PC13 is selected as RTC TimeStamp Pin.
219 * The RTC TimeStamp Pin is per default PC13, but for reasons of
220 * compatibility, this parameter is required.
221 * @retval HAL status
222 */
223HAL_StatusTypeDef HAL_RTCEx_SetTimeStamp_IT(RTC_HandleTypeDef *hrtc, uint32_t TimeStampEdge, uint32_t RTC_TimeStampPin)
224{
225 uint32_t tmpreg;
226
227 /* Check the parameters */
228 assert_param(IS_TIMESTAMP_EDGE(TimeStampEdge));
229 assert_param(IS_RTC_TIMESTAMP_PIN(RTC_TimeStampPin));
230
231 /* Prevent unused argument(s) compilation warning if no assert_param check */
232 UNUSED(RTC_TimeStampPin);
233
234 /* Process Locked */
236
237 hrtc->State = HAL_RTC_STATE_BUSY;
238
239 /* Get the RTC_CR register and clear the bits to be configured */
240 tmpreg = (uint32_t)(hrtc->Instance->CR & (uint32_t)~(RTC_CR_TSEDGE | RTC_CR_TSE));
241
242 tmpreg |= TimeStampEdge;
243
244 /* Disable the write protection for RTC registers */
246
247 /* Configure the Time Stamp TSEDGE and Enable bits */
248 hrtc->Instance->CR = (uint32_t)tmpreg;
249
251
252 /* Enable IT timestamp */
254
255 /* RTC timestamp Interrupt Configuration: EXTI configuration */
256#if defined(DUAL_CORE)
258 {
260 }
261 else
262 {
263 __HAL_RTC_TAMPER_TIMESTAMP_EXTID2_ENABLE_IT();
264 }
265#else /* SINGLE_CORE */
267#endif /* DUAL_CORE */
268
270
271 /* Enable the write protection for RTC registers */
273
274 hrtc->State = HAL_RTC_STATE_READY;
275
276 /* Process Unlocked */
278
279 return HAL_OK;
280}
281
282/**
283 * @brief Deactivate TimeStamp.
284 * @param hrtc RTC handle
285 * @retval HAL status
286 */
288{
289 uint32_t tmpreg;
290
291 /* Process Locked */
293
294 hrtc->State = HAL_RTC_STATE_BUSY;
295
296 /* Disable the write protection for RTC registers */
298
299 /* In case of interrupt mode is used, the interrupt source must disabled */
301
302 /* Get the RTC_CR register and clear the bits to be configured */
303 tmpreg = (uint32_t)(hrtc->Instance->CR & (uint32_t)~(RTC_CR_TSEDGE | RTC_CR_TSE));
304
305 /* Configure the Time Stamp TSEDGE and Enable bits */
306 hrtc->Instance->CR = (uint32_t)tmpreg;
307
308 /* Enable the write protection for RTC registers */
310
311 hrtc->State = HAL_RTC_STATE_READY;
312
313 /* Process Unlocked */
315
316 return HAL_OK;
317}
318
319/**
320 * @brief Set Internal TimeStamp.
321 * @note This API must be called before enabling the internal TimeStamp feature.
322 * @param hrtc RTC handle
323 * @retval HAL status
324 */
326{
327 /* Process Locked */
329
330 hrtc->State = HAL_RTC_STATE_BUSY;
331
332 /* Disable the write protection for RTC registers */
334
335 /* Configure the internal Time Stamp Enable bits */
337
338 /* Enable the write protection for RTC registers */
340
341 /* Change RTC state */
342 hrtc->State = HAL_RTC_STATE_READY;
343
344 /* Process Unlocked */
346
347 return HAL_OK;
348}
349
350/**
351 * @brief Deactivate Internal TimeStamp.
352 * @param hrtc RTC handle
353 * @retval HAL status
354 */
356{
357 /* Process Locked */
359
360 hrtc->State = HAL_RTC_STATE_BUSY;
361
362 /* Disable the write protection for RTC registers */
364
365 /* Configure the internal Time Stamp Enable bits */
367
368 /* Enable the write protection for RTC registers */
370
371 hrtc->State = HAL_RTC_STATE_READY;
372
373 /* Process Unlocked */
375
376 return HAL_OK;
377}
378
379/**
380 * @brief Get the RTC TimeStamp value.
381 * @param hrtc RTC handle
382 * @param sTimeStamp Pointer to Time structure
383 * @param sTimeStampDate Pointer to Date structure
384 * @param Format specifies the format of the entered parameters.
385 * This parameter can be one of the following values:
386 * @arg RTC_FORMAT_BIN: Binary data format
387 * @arg RTC_FORMAT_BCD: BCD data format
388 * @retval HAL status
389 */
391{
392 uint32_t tmptime;
393 uint32_t tmpdate;
394
395 /* Check the parameters */
397
398 /* Get the TimeStamp time and date registers values */
399 tmptime = (uint32_t)(hrtc->Instance->TSTR & RTC_TR_RESERVED_MASK);
400 tmpdate = (uint32_t)(hrtc->Instance->TSDR & RTC_DR_RESERVED_MASK);
401
402 /* Fill the Time structure fields with the read parameters */
403 sTimeStamp->Hours = (uint8_t)((tmptime & (RTC_TSTR_HT | RTC_TSTR_HU)) >> RTC_TSTR_HU_Pos);
404 sTimeStamp->Minutes = (uint8_t)((tmptime & (RTC_TSTR_MNT | RTC_TSTR_MNU)) >> RTC_TSTR_MNU_Pos);
405 sTimeStamp->Seconds = (uint8_t)((tmptime & (RTC_TSTR_ST | RTC_TSTR_SU)) >> RTC_TSTR_SU_Pos);
406 sTimeStamp->TimeFormat = (uint8_t)((tmptime & (RTC_TSTR_PM)) >> RTC_TSTR_PM_Pos);
407 sTimeStamp->SubSeconds = (uint32_t) hrtc->Instance->TSSSR;
408
409 /* Fill the Date structure fields with the read parameters */
410 sTimeStampDate->Year = 0U;
411 sTimeStampDate->Month = (uint8_t)((tmpdate & (RTC_TSDR_MT | RTC_TSDR_MU)) >> RTC_TSDR_MU_Pos);
412 sTimeStampDate->Date = (uint8_t)((tmpdate & (RTC_TSDR_DT | RTC_TSDR_DU)) >> RTC_TSDR_DU_Pos);
413 sTimeStampDate->WeekDay = (uint8_t)((tmpdate & (RTC_TSDR_WDU)) >> RTC_TSDR_WDU_Pos);
414
415 /* Check the input parameters format */
416 if (Format == RTC_FORMAT_BIN)
417 {
418 /* Convert the TimeStamp structure parameters to Binary format */
419 sTimeStamp->Hours = (uint8_t)RTC_Bcd2ToByte(sTimeStamp->Hours);
420 sTimeStamp->Minutes = (uint8_t)RTC_Bcd2ToByte(sTimeStamp->Minutes);
421 sTimeStamp->Seconds = (uint8_t)RTC_Bcd2ToByte(sTimeStamp->Seconds);
422
423 /* Convert the DateTimeStamp structure parameters to Binary format */
424 sTimeStampDate->Month = (uint8_t)RTC_Bcd2ToByte(sTimeStampDate->Month);
425 sTimeStampDate->Date = (uint8_t)RTC_Bcd2ToByte(sTimeStampDate->Date);
426 sTimeStampDate->WeekDay = (uint8_t)RTC_Bcd2ToByte(sTimeStampDate->WeekDay);
427 }
428
429 /* Clear the TIMESTAMP Flags */
432
433 return HAL_OK;
434}
435
436/**
437 * @}
438 */
439
440/** @addtogroup RTCEx_Exported_Functions_Group5
441 * @brief Extended RTC Tamper functions
442 *
443@verbatim
444 ==============================================================================
445 ##### Tamper functions #####
446 ==============================================================================
447 [..]
448 (+) Before calling any tamper or internal tamper function, you have to call first
449 HAL_RTC_Init() function.
450 (+) In that ine you can select to output tamper event on RTC pin.
451 [..]
452 (+) Enable the Tamper and configure the Tamper filter count, trigger Edge
453 or Level according to the Tamper filter (if equal to 0 Edge else Level)
454 value, sampling frequency, NoErase, MaskFlag, precharge or discharge and
455 Pull-UP, timestamp using the HAL_RTCEx_SetTamper() function.
456 You can configure Tamper with interrupt mode using HAL_RTCEx_SetTamper_IT() function.
457 (+) The default configuration of the Tamper erases the backup registers. To avoid
458 erase, enable the NoErase field on the TAMP_TAMPCR register.
459 [..]
460 (+) Enable Internal Tamper and configure it with interrupt, timestamp using
461 the HAL_RTCEx_SetInternalTamper() function.
462
463@endverbatim
464* @{
465*/
466
467#if defined(TAMP)
468/**
469 * @brief Set Tamper
470 * @param hrtc RTC handle
471 * @param sTamper Pointer to Tamper Structure.
472 * @retval HAL status
473 */
475{
476 uint32_t tmpreg;
477
478 /* Point on TAMPER registers base address */
479 TAMP_TypeDef *tamp = (TAMP_TypeDef *)((uint32_t)hrtc->Instance + TAMP_OFFSET);
480
481 /* Check the parameters */
492
493 /* Configuration register 2 */
494 tmpreg = tamp->CR2;
495 tmpreg &= ~((sTamper->Tamper << TAMP_CR2_TAMP1TRG_Pos) | (sTamper->Tamper << TAMP_CR2_TAMP1MSK_Pos) | (sTamper->Tamper << TAMP_CR2_TAMP1NOERASE_Pos));
496
497 /* Configure the tamper trigger bit */
499 {
500 tmpreg |= (sTamper->Tamper << TAMP_CR2_TAMP1TRG_Pos);
501 }
502
503 /* Configure the tamper flags masking bit */
505 {
506 tmpreg |= (sTamper->Tamper << TAMP_CR2_TAMP1MSK_Pos);
507 }
508
509 /* Configure the tamper backup registers erasure bit */
511 {
512 tmpreg |= (sTamper->Tamper << TAMP_CR2_TAMP1NOERASE_Pos);
513 }
514 tamp->CR2 = tmpreg;
515
516 /* Configure filtering parameters */
517 tamp->FLTCR = (sTamper->Filter) | (sTamper->SamplingFrequency) | \
518 (sTamper->PrechargeDuration) | (sTamper->TamperPullUp);
519
520 /* Configure Timestamp saving on tamper detection */
521 if ((hrtc->Instance->CR & RTC_CR_TAMPTS) != (sTamper->TimeStampOnTamperDetection))
522 {
524 tmpreg = (hrtc->Instance->CR & ~RTC_CR_TAMPTS);
525 hrtc->Instance->CR = (tmpreg | (sTamper->TimeStampOnTamperDetection));
527 }
528
529 /* Enable selected tamper */
530 tamp->CR1 |= (sTamper->Tamper);
531
532 return HAL_OK;
533}
534#else
535/**
536 * @brief Set Tamper.
537 * @note By calling this API we disable the tamper interrupt for all tampers.
538 * @param hrtc RTC handle
539 * @param sTamper Pointer to Tamper Structure.
540 * @retval HAL status
541 */
543{
544 uint32_t tmpreg;
545
546 /* Check the parameters */
557
558 /* Process Locked */
560
561 hrtc->State = HAL_RTC_STATE_BUSY;
562
563 /* Copy control register into temporary variable */
564 tmpreg = hrtc->Instance->TAMPCR;
565
566 /* Enable selected tamper */
567 tmpreg |= (sTamper->Tamper);
568
569 /* Configure the bit (located just next to the tamper enable bit) */
571 {
572 /* Set the tamper trigger bit */
573 tmpreg |= (uint32_t)(sTamper->Tamper << 1U);
574 }
575 else
576 {
577 /* Clear the tamper trigger bit */
578 tmpreg &= (uint32_t)~(sTamper->Tamper << 1U);
579 }
580
581#if defined(RTC_TAMPNOERASE_SUPPORT)
582 /* Configure the tamper backup registers erasure bit */
584 {
585 if ((sTamper->Tamper & RTC_TAMPER_1) != 0U)
586 {
587 tmpreg |= (uint32_t)(RTC_TAMPCR_TAMP1NOERASE);
588 }
589 if ((sTamper->Tamper & RTC_TAMPER_2) != 0U)
590 {
591 tmpreg |= (uint32_t)(RTC_TAMPCR_TAMP2NOERASE);
592 }
593 if ((sTamper->Tamper & RTC_TAMPER_3) != 0U)
594 {
595 tmpreg |= (uint32_t)(RTC_TAMPCR_TAMP3NOERASE);
596 }
597 }
598 else
599 {
600 if ((sTamper->Tamper & RTC_TAMPER_1) != 0U)
601 {
602 tmpreg &= (uint32_t)~(RTC_TAMPCR_TAMP1NOERASE);
603 }
604 if ((sTamper->Tamper & RTC_TAMPER_2) != 0U)
605 {
606 tmpreg &= (uint32_t)~(RTC_TAMPCR_TAMP2NOERASE);
607 }
608 if ((sTamper->Tamper & RTC_TAMPER_3) != 0U)
609 {
610 tmpreg &= (uint32_t)~(RTC_TAMPCR_TAMP3NOERASE);
611 }
612 }
613#endif /* RTC_TAMPNOERASE_SUPPORT */
614
615#if defined(RTC_TAMPMASKFLAG_SUPPORT)
616 /* Configure the tamper flags masking bit */
618 {
619 if ((sTamper->Tamper & RTC_TAMPER_1) != 0U)
620 {
621 tmpreg |= (uint32_t)(RTC_TAMPCR_TAMP1MF);
622 }
623 if ((sTamper->Tamper & RTC_TAMPER_2) != 0U)
624 {
625 tmpreg |= (uint32_t)(RTC_TAMPCR_TAMP2MF);
626 }
627 if ((sTamper->Tamper & RTC_TAMPER_3) != 0U)
628 {
629 tmpreg |= (uint32_t)(RTC_TAMPCR_TAMP3MF);
630 }
631 }
632 else
633 {
634 if ((sTamper->Tamper & RTC_TAMPER_1) != 0U)
635 {
636 tmpreg &= (uint32_t)~(RTC_TAMPCR_TAMP1MF);
637 }
638 if ((sTamper->Tamper & RTC_TAMPER_2) != 0U)
639 {
640 tmpreg &= (uint32_t)~(RTC_TAMPCR_TAMP2MF);
641 }
642 if ((sTamper->Tamper & RTC_TAMPER_3) != 0U)
643 {
644 tmpreg &= (uint32_t)~(RTC_TAMPCR_TAMP3MF);
645 }
646 }
647#endif /* RTC_TAMPMASKFLAG_SUPPORT */
648
649 /* Clearing remaining fields before setting them */
653
654 /* Set remaining parameters of desired configuration into temporary variable */
655 tmpreg |= ((uint32_t)sTamper->Filter | \
656 (uint32_t)sTamper->SamplingFrequency | \
657 (uint32_t)sTamper->PrechargeDuration | \
658 (uint32_t)sTamper->TamperPullUp | \
659 (uint32_t)sTamper->TimeStampOnTamperDetection);
660
661 /* Copy desired configuration into configuration register */
662 hrtc->Instance->TAMPCR = tmpreg;
663
664 hrtc->State = HAL_RTC_STATE_READY;
665
666 /* Process Unlocked */
668
669 return HAL_OK;
670}
671#endif /* TAMP */
672
673#if defined(TAMP)
674/**
675 * @brief Set Tamper with interrupt.
676 * @param hrtc RTC handle
677 * @param sTamper Pointer to Tamper Structure.
678 * @retval HAL status
679 */
681{
682 uint32_t tmpreg;
683
684 /* Point on TAMPER registers base address */
685 TAMP_TypeDef *tamp = (TAMP_TypeDef *)((uint32_t)hrtc->Instance + TAMP_OFFSET);
686
687 /* Check the parameters */
698
699 /* Copy configuration register into temporary variable */
700 tmpreg = tamp->CR2;
701
702 /* Clear the bits that are going to be configured and leave the others unchanged */
703 tmpreg &= ~((sTamper->Tamper << TAMP_CR2_TAMP1TRG_Pos) | (sTamper->Tamper << TAMP_CR2_TAMP1MSK_Pos) | (sTamper->Tamper << TAMP_CR2_TAMP1NOERASE_Pos));
704
705 /* Configure the tamper trigger bit */
707 {
708 tmpreg |= (sTamper->Tamper << TAMP_CR2_TAMP1TRG_Pos);
709 }
710
711 /* Configure the tamper flags masking bit */
713 {
714 tmpreg |= (sTamper->Tamper << TAMP_CR2_TAMP1MSK_Pos);
715 }
716
717 /* Configure the tamper backup registers erasure bit */
719 {
720 tmpreg |= (sTamper->Tamper << TAMP_CR2_TAMP1NOERASE_Pos);
721 }
722 tamp->CR2 = tmpreg;
723
724 /* Configure filtering parameters */
725 tamp->FLTCR = (sTamper->Filter) | (sTamper->SamplingFrequency) | \
726 (sTamper->PrechargeDuration) | (sTamper->TamperPullUp);
727
728 /* Configure Timestamp saving on tamper detection */
729 if ((hrtc->Instance->CR & RTC_CR_TAMPTS) != (sTamper->TimeStampOnTamperDetection))
730 {
732 tmpreg = (hrtc->Instance->CR & ~RTC_CR_TAMPTS);
733 hrtc->Instance->CR = (tmpreg | (sTamper->TimeStampOnTamperDetection));
735 }
736
737 /* Configure RTC Tamper Interrupt: EXTI configuration */
740
741 /* Enable interrupt on selected tamper */
742 tamp->IER |= sTamper->Tamper;
743
744 /* Enable selected tamper */
745 tamp->CR1 |= sTamper->Tamper;
746
747 return HAL_OK;
748}
749#else
750/**
751 * @brief Set Tamper with interrupt.
752 * @note By calling this API we force the tamper interrupt for all tampers.
753 * @param hrtc RTC handle
754 * @param sTamper Pointer to Tamper Structure.
755 * @retval HAL status
756 */
758{
759 uint32_t tmpreg;
760
761 /* Check the parameters */
773
774 /* Process Locked */
776
777 hrtc->State = HAL_RTC_STATE_BUSY;
778
779 /* Copy control register into temporary variable */
780 tmpreg = hrtc->Instance->TAMPCR;
781
782 /* Enable selected tamper */
783 tmpreg |= (sTamper->Tamper);
784
785 /* Configure the tamper trigger bit (located just next to the tamper enable bit) */
787 {
788 /* Set the tamper trigger bit */
789 tmpreg |= (uint32_t)(sTamper->Tamper << 1U);
790 }
791 else
792 {
793 /* Clear the tamper trigger bit */
794 tmpreg &= (uint32_t)~(sTamper->Tamper << 1U);
795 }
796
797#if defined(RTC_TAMPNOERASE_SUPPORT)
798 /* Configure the tamper backup registers erasure bit */
800 {
801 if ((sTamper->Tamper & RTC_TAMPER_1) != 0U)
802 {
803 tmpreg |= (uint32_t)(RTC_TAMPCR_TAMP1NOERASE);
804 }
805 if ((sTamper->Tamper & RTC_TAMPER_2) != 0U)
806 {
807 tmpreg |= (uint32_t)(RTC_TAMPCR_TAMP2NOERASE);
808 }
809 if ((sTamper->Tamper & RTC_TAMPER_3) != 0U)
810 {
811 tmpreg |= (uint32_t)(RTC_TAMPCR_TAMP3NOERASE);
812 }
813 }
814 else
815 {
816 if ((sTamper->Tamper & RTC_TAMPER_1) != 0U)
817 {
818 tmpreg &= (uint32_t)~(RTC_TAMPCR_TAMP1NOERASE);
819 }
820 if ((sTamper->Tamper & RTC_TAMPER_2) != 0U)
821 {
822 tmpreg &= (uint32_t)~(RTC_TAMPCR_TAMP2NOERASE);
823 }
824 if ((sTamper->Tamper & RTC_TAMPER_3) != 0U)
825 {
826 tmpreg &= (uint32_t)~(RTC_TAMPCR_TAMP3NOERASE);
827 }
828 }
829#endif /* RTC_TAMPNOERASE_SUPPORT */
830
831#if defined(RTC_TAMPMASKFLAG_SUPPORT)
832 /* Configure the tamper flags masking bit */
834 {
835 if ((sTamper->Tamper & RTC_TAMPER_1) != 0U)
836 {
837 tmpreg |= (uint32_t)(RTC_TAMPCR_TAMP1MF);
838 }
839 if ((sTamper->Tamper & RTC_TAMPER_2) != 0U)
840 {
841 tmpreg |= (uint32_t)(RTC_TAMPCR_TAMP2MF);
842 }
843 if ((sTamper->Tamper & RTC_TAMPER_3) != 0U)
844 {
845 tmpreg |= (uint32_t)(RTC_TAMPCR_TAMP3MF);
846 }
847 }
848 else
849 {
850 if ((sTamper->Tamper & RTC_TAMPER_1) != 0U)
851 {
852 tmpreg &= (uint32_t)~(RTC_TAMPCR_TAMP1MF);
853 }
854 if ((sTamper->Tamper & RTC_TAMPER_2) != 0U)
855 {
856 tmpreg &= (uint32_t)~(RTC_TAMPCR_TAMP2MF);
857 }
858 if ((sTamper->Tamper & RTC_TAMPER_3) != 0U)
859 {
860 tmpreg &= (uint32_t)~(RTC_TAMPCR_TAMP3MF);
861 }
862 }
863#endif /* RTC_TAMPMASKFLAG_SUPPORT */
864
865 /* Clearing remaining fields before setting them */
869
870 /* Set remaining parameters of desired configuration into temporary variable */
871 tmpreg |= ((uint32_t)sTamper->Filter | \
872 (uint32_t)sTamper->SamplingFrequency | \
873 (uint32_t)sTamper->PrechargeDuration | \
874 (uint32_t)sTamper->TamperPullUp | \
875 (uint32_t)sTamper->TimeStampOnTamperDetection);
876
877 /* Enable interrupt on selected tamper */
878 tmpreg |= (uint32_t)sTamper->Interrupt;
879
880 /* Copy desired configuration into configuration register */
881 hrtc->Instance->TAMPCR = tmpreg;
882
883 /* RTC Tamper Interrupt Configuration: EXTI configuration */
884#if defined(DUAL_CORE)
886 {
888 }
889 else
890 {
891 __HAL_RTC_TAMPER_TIMESTAMP_EXTID2_ENABLE_IT();
892 }
893#else /* SINGLE_CORE */
895#endif /* DUAL_CORE */
896
898
899 hrtc->State = HAL_RTC_STATE_READY;
900
901 /* Process Unlocked */
903
904 return HAL_OK;
905}
906#endif /* TAMP */
907
908#if defined(TAMP)
909/**
910 * @brief Deactivate Tamper.
911 * @param hrtc RTC handle
912 * @param Tamper Selected tamper pin.
913 * This parameter can be a combination of the following values:
914 * @arg RTC_TAMPER_1
915 * @arg RTC_TAMPER_2
916 * @retval HAL status
917 */
919{
920 /* Point on TAMPER registers base address */
921 TAMP_TypeDef *tamp = (TAMP_TypeDef *)((uint32_t)hrtc->Instance + TAMP_OFFSET);
922
924
925 /* Disable the selected Tamper pin */
926 tamp->CR1 &= ~Tamper;
927
928 /* Disable the selected Tamper interrupt */
929 tamp->IER &= ~Tamper;
930
931 /* Clear the selected tamper flags in SR register by setting corresponding bits in SCR register */
932 tamp->SCR = Tamper;
933
934 /* Clear the selected tamper configuration (trigger, mask flag, and no-erase) */
935 tamp->CR2 &= ~((Tamper << TAMP_CR2_TAMP1TRG_Pos) | (Tamper << TAMP_CR2_TAMP1MSK_Pos) | (Tamper << TAMP_CR2_TAMP1NOERASE_Pos));
936
937 return HAL_OK;
938}
939#else
940/**
941 * @brief Deactivate Tamper.
942 * @param hrtc RTC handle
943 * @param Tamper Selected tamper pin.
944 * This parameter can be any combination of the following values:
945 * @arg RTC_TAMPER_1
946 * @arg RTC_TAMPER_2 (*)
947 * @arg RTC_TAMPER_3
948 * (*) Not applicable to all devices.
949 * @retval HAL status
950 */
952{
954
955 /* Process Locked */
957
958 hrtc->State = HAL_RTC_STATE_BUSY;
959
960 /* Disable the selected Tamper pin */
961 hrtc->Instance->TAMPCR &= ((uint32_t)~Tamper);
962
963#if defined(RTC_TAMPxIE_SUPPORT)
964 /* Disable the selected Tamper interrupt */
965 if ((Tamper & RTC_TAMPER_1) != 0U)
966 {
967 hrtc->Instance->TAMPCR &= ((uint32_t)~(RTC_IT_TAMP | RTC_IT_TAMP1));
968 }
969
970#if defined(RTC_TAMPER2_SUPPORT)
971 if ((Tamper & RTC_TAMPER_2) != 0U)
972 {
973 hrtc->Instance->TAMPCR &= ((uint32_t)~(RTC_IT_TAMP | RTC_IT_TAMP2));
974 }
975#endif /* RTC_TAMPER2_SUPPORT */
976
977 if ((Tamper & RTC_TAMPER_3) != 0U)
978 {
979 hrtc->Instance->TAMPCR &= ((uint32_t)~(RTC_IT_TAMP | RTC_IT_TAMP3));
980 }
981#else
982 /* Disable the Tamper interrupt */
983 hrtc->Instance->TAMPCR &= (uint32_t)~(RTC_IT_TAMP);
984#endif /* RTC_TAMPxIE_SUPPORT */
985
986 hrtc->State = HAL_RTC_STATE_READY;
987
988 /* Process Unlocked */
990
991 return HAL_OK;
992}
993#endif /* TAMP */
994
995#if defined(TAMP)
996/**
997 * @brief Set Internal Tamper
998 * @param hrtc RTC handle
999 * @param sIntTamper Pointer to Internal Tamper Structure.
1000 * @retval HAL status
1001 */
1002HAL_StatusTypeDef HAL_RTCEx_SetInternalTamper(RTC_HandleTypeDef *hrtc, const RTC_InternalTamperTypeDef *sIntTamper)
1003{
1004 /* Check the parameters */
1005 assert_param(IS_RTC_INTERNAL_TAMPER(sIntTamper->IntTamper));
1006 assert_param(IS_RTC_TAMPER_TIMESTAMPONTAMPER_DETECTION(sIntTamper->TimeStampOnTamperDetection));
1007
1008 /* Time-Stamp on internal tamper */
1009 if (READ_BIT(RTC->CR, RTC_CR_TAMPTS) != sIntTamper->TimeStampOnTamperDetection)
1010 {
1012 MODIFY_REG(RTC->CR, RTC_CR_TAMPTS, sIntTamper->TimeStampOnTamperDetection);
1014 }
1015
1016 /* Control register 1 */
1017 SET_BIT(TAMP->CR1, sIntTamper->IntTamper);
1018
1019 return HAL_OK;
1020}
1021
1022/**
1023 * @brief Set Internal Tamper in interrupt mode
1024 * @param hrtc RTC handle
1025 * @param sIntTamper Pointer to Internal Tamper Structure.
1026 * @retval HAL status
1027 */
1028HAL_StatusTypeDef HAL_RTCEx_SetInternalTamper_IT(RTC_HandleTypeDef *hrtc, const RTC_InternalTamperTypeDef *sIntTamper)
1029{
1030 /* Check the parameters */
1031 assert_param(IS_RTC_INTERNAL_TAMPER(sIntTamper->IntTamper));
1032 assert_param(IS_RTC_TAMPER_TIMESTAMPONTAMPER_DETECTION(sIntTamper->TimeStampOnTamperDetection));
1033
1034 /* Time-stamp on internal tamper */
1035 if (READ_BIT(RTC->CR, RTC_CR_TAMPTS) != sIntTamper->TimeStampOnTamperDetection)
1036 {
1038 MODIFY_REG(RTC->CR, RTC_CR_TAMPTS, sIntTamper->TimeStampOnTamperDetection);
1040 }
1041
1042 /* RTC Tamper Interrupt Configuration: EXTI configuration */
1045 /* Interrupt enable register */
1046 SET_BIT(TAMP->IER, sIntTamper->IntTamper);
1047
1048 /* Control register 1 */
1049 SET_BIT(TAMP->CR1, sIntTamper->IntTamper);
1050
1051 return HAL_OK;
1052}
1053
1054/**
1055 * @brief Deactivate Internal Tamper.
1056 * @param hrtc RTC handle
1057 * @param IntTamper Selected internal tamper event.
1058 * This parameter can be any combination of existing internal tampers.
1059 * @retval HAL status
1060 */
1061HAL_StatusTypeDef HAL_RTCEx_DeactivateInternalTamper(RTC_HandleTypeDef *hrtc, uint32_t IntTamper)
1062{
1063 UNUSED(hrtc);
1065
1066 /* Disable the selected Tamper pin */
1067 CLEAR_BIT(TAMP->CR1, IntTamper);
1068
1069 /* Clear internal tamper interrupt mode configuration */
1070 CLEAR_BIT(TAMP->IER, IntTamper);
1071
1072 /* Clear internal tamper interrupt */
1073 WRITE_REG(TAMP->SCR, IntTamper);
1074
1075 return HAL_OK;
1076}
1077
1078/**
1079 * @brief Set all active Tampers at the same time.
1080 * @param hrtc RTC handle
1081 * @param sAllTamper Pointer to active Tamper Structure.
1082 * @retval HAL status
1083 */
1084HAL_StatusTypeDef HAL_RTCEx_SetActiveTampers(RTC_HandleTypeDef *hrtc, const RTC_ActiveTampersTypeDef *sAllTamper)
1085{
1086 uint32_t IER, CR1, CR2, ATCR1, CR, i, tickstart;
1087
1088#ifdef USE_FULL_ASSERT
1089 for (i = 0; i < RTC_TAMP_NB; i++)
1090 {
1091 assert_param(IS_RTC_TAMPER_ERASE_MODE(sAllTamper->TampInput[i].NoErase));
1092 assert_param(IS_RTC_TAMPER_MASKFLAG_STATE(sAllTamper->TampInput[i].MaskFlag));
1093 /* Mask flag only supported by TAMPER 1, 2, and 3 */
1094 assert_param(!((sAllTamper->TampInput[i].MaskFlag != RTC_TAMPERMASK_FLAG_DISABLE) && (i > RTC_TAMPER_3)));
1095 }
1096
1097 assert_param(IS_RTC_TAMPER_TIMESTAMPONTAMPER_DETECTION(sAllTamper->TimeStampOnTamperDetection));
1098#endif /* USE_FULL_ASSERT */
1099
1100 /* Active Tampers must not be already enabled */
1101 if (READ_BIT(TAMP->ATOR, TAMP_ATOR_INITS) != 0U)
1102 {
1103 /* Disable all active tampers with HAL_RTCEx_DeactivateActiveTampers */
1104 if (HAL_RTCEx_DeactivateActiveTampers(hrtc) != HAL_OK)
1105 {
1106 return HAL_ERROR;
1107 }
1108 }
1109
1110 /* Set TimeStamp on tamper detection */
1111 CR = READ_REG(RTC->CR);
1112 if ((CR & RTC_CR_TAMPTS) != (sAllTamper->TimeStampOnTamperDetection))
1113 {
1115 MODIFY_REG(RTC->CR, RTC_CR_TAMPTS, sAllTamper->TimeStampOnTamperDetection);
1117 }
1118
1119 CR1 = READ_REG(TAMP->CR1);
1120 CR2 = READ_REG(TAMP->CR2);
1121 IER = READ_REG(TAMP->IER);
1122
1123 /* Set common parameters */
1124 ATCR1 = (sAllTamper->ActiveFilter | (sAllTamper->ActiveOutputChangePeriod << TAMP_ATCR1_ATPER_Pos) | sAllTamper->ActiveAsyncPrescaler);
1125
1126 /* Set specific parameters for each active tamper inputs if enable */
1127 for (i = 0; i < RTC_TAMP_NB; i++)
1128 {
1129 if (sAllTamper->TampInput[i].Enable != RTC_ATAMP_DISABLE)
1130 {
1131 CR1 |= (TAMP_CR1_TAMP1E << i);
1132 ATCR1 |= (TAMP_ATCR1_TAMP1AM << i);
1133
1134 if (sAllTamper->TampInput[i].Interrupt != RTC_ATAMP_INTERRUPT_DISABLE)
1135 {
1136 /* RTC Tamper Interrupt Configuration: EXTI configuration */
1139
1140 /* Interrupt enable register */
1141 IER |= (TAMP_IER_TAMP1IE << i);
1142 }
1143
1144 if (sAllTamper->TampInput[i].MaskFlag != RTC_TAMPERMASK_FLAG_DISABLE)
1145 {
1146 CR2 |= (TAMP_CR2_TAMP1MSK << i);
1147 }
1148
1149 if (sAllTamper->TampInput[i].NoErase != RTC_TAMPER_ERASE_BACKUP_ENABLE)
1150 {
1151 CR2 |= (TAMP_CR2_TAMP1NOERASE << i);
1152 }
1153
1154 /* Set ATOSHARE and configure ATOSELx[] in case of output sharing */
1155 if (sAllTamper->TampInput[i].Output != i)
1156 {
1157 ATCR1 |= TAMP_ATCR1_ATOSHARE;
1158 ATCR1 |= sAllTamper->TampInput[i].Output << ((2u * i) + TAMP_ATCR1_ATOSEL1_Pos);
1159 }
1160 }
1161 }
1162
1163 WRITE_REG(TAMP->IER, IER);
1164 WRITE_REG(TAMP->ATCR1, ATCR1);
1165#if defined(TAMP_ATCR2_ATOSEL1)
1166 WRITE_REG(TAMP->ATCR2, ATCR2);
1167#endif /* TAMP_ATCR2_ATOSEL1 */
1168 WRITE_REG(TAMP->CR2, CR2);
1169 WRITE_REG(TAMP->CR1, CR1);
1170
1171 /* Write seed */
1172 for (i = 0; i < RTC_ATAMP_SEED_NB_UINT32; i++)
1173 {
1174 WRITE_REG(TAMP->ATSEEDR, sAllTamper->Seed[i]);
1175 }
1176
1177 /* Wait till RTC SEEDF flag is set and if timeout is reached exit */
1178 tickstart = HAL_GetTick();
1179 while (READ_BIT(TAMP->ATOR, TAMP_ATOR_SEEDF) != 0u)
1180 {
1181 if ((HAL_GetTick() - tickstart) > RTC_TIMEOUT_VALUE)
1182 {
1183 hrtc->State = HAL_RTC_STATE_TIMEOUT;
1184 return HAL_TIMEOUT;
1185 }
1186 }
1187
1188 return HAL_OK;
1189}
1190
1191/**
1192 * @brief Write a new seed. Active tamper must be enabled.
1193 * @param hrtc RTC handle
1194 * @param pSeed Pointer to active tamper seed values.
1195 * @retval HAL status
1196 */
1197HAL_StatusTypeDef HAL_RTCEx_SetActiveSeed(RTC_HandleTypeDef *hrtc, const uint32_t *pSeed)
1198{
1199 uint32_t i, tickstart;
1200
1201 /* Active Tampers must be enabled */
1202 if (READ_BIT(TAMP->ATOR, TAMP_ATOR_INITS) == 0U)
1203 {
1204 return HAL_ERROR;
1205 }
1206
1207 for (i = 0; i < RTC_ATAMP_SEED_NB_UINT32; i++)
1208 {
1209 WRITE_REG(TAMP->ATSEEDR, pSeed[i]);
1210 }
1211
1212 /* Wait till RTC SEEDF flag is set and if timeout is reached exit */
1213 tickstart = HAL_GetTick();
1214 while (READ_BIT(TAMP->ATOR, TAMP_ATOR_SEEDF) != 0U)
1215 {
1216 if ((HAL_GetTick() - tickstart) > RTC_TIMEOUT_VALUE)
1217 {
1218 hrtc->State = HAL_RTC_STATE_TIMEOUT;
1219 return HAL_TIMEOUT;
1220 }
1221 }
1222
1223 return HAL_OK;
1224}
1225
1226/**
1227 * @brief Deactivate all Active Tampers at the same time.
1228 * @param hrtc RTC handle
1229 * @retval HAL status
1230 */
1231HAL_StatusTypeDef HAL_RTCEx_DeactivateActiveTampers(RTC_HandleTypeDef *hrtc)
1232{
1233 /* Get Active tampers */
1234 uint32_t ATamp_mask = READ_BIT(TAMP->ATCR1, TAMP_ALL);
1235
1236 UNUSED(hrtc);
1237 /* Disable all actives tampers but not passives tampers */
1238 CLEAR_BIT(TAMP->CR1, ATamp_mask);
1239 /* Disable no erase and mask */
1240 CLEAR_BIT(TAMP->CR2, (ATamp_mask | ((ATamp_mask & (TAMP_ATCR1_TAMP1AM | TAMP_ATCR1_TAMP2AM | TAMP_ATCR1_TAMP3AM)) << TAMP_CR2_TAMP1MSK_Pos)));
1241
1242 /* Clear tamper interrupt and event flags (WO register) of all actives tampers but not passives tampers */
1243 WRITE_REG(TAMP->SCR, ATamp_mask);
1244
1245 /* Clear all active tampers interrupt mode configuration but not passives tampers */
1246 CLEAR_BIT(TAMP->IER, ATamp_mask);
1247
1248 CLEAR_BIT(TAMP->ATCR1, TAMP_ALL | TAMP_ATCR1_ATCKSEL | TAMP_ATCR1_ATPER | \
1249 TAMP_ATCR1_ATOSHARE | TAMP_ATCR1_FLTEN);
1250
1251#if defined(TAMP_ATCR2_ATOSEL1)
1252 CLEAR_BIT(TAMP->ATCR2, TAMP_ATCR2_ATOSEL1 | TAMP_ATCR2_ATOSEL2 | TAMP_ATCR2_ATOSEL3 | TAMP_ATCR2_ATOSEL4 |
1253 TAMP_ATCR2_ATOSEL5 | TAMP_ATCR2_ATOSEL6 | TAMP_ATCR2_ATOSEL7 | TAMP_ATCR2_ATOSEL8);
1254#endif /* TAMP_ATCR2_ATOSEL1 */
1255
1256 return HAL_OK;
1257}
1258#endif /* TAMP */
1259
1260/**
1261 * @}
1262 */
1263
1264/** @addtogroup RTCEx_Exported_Functions_Group1
1265 * @brief RTC TimeStamp and Tamper functions
1266 *
1267* @{
1268*/
1269
1270/**
1271 * @brief Handle Tamper and TimeStamp interrupt request.
1272 * @param hrtc RTC handle
1273 * @retval None
1274 */
1275#if defined(TAMP)
1277{
1278
1279 /* Point on TAMPER registers base address */
1280 TAMP_TypeDef *tamp = (TAMP_TypeDef *)((uint32_t)hrtc->Instance + TAMP_OFFSET);
1281
1282 /* Clear the EXTI's Flag for RTC TimeStamp and Tamper */
1284
1285 if ((hrtc->Instance->MISR & RTC_MISR_TSMF) != 0u)
1286 {
1287#if (USE_HAL_RTC_REGISTER_CALLBACKS == 1)
1288 /* Call TimeStampEvent registered Callback */
1289 hrtc->TimeStampEventCallback(hrtc);
1290#else
1292#endif /* USE_HAL_RTC_REGISTER_CALLBACKS */
1293 /* Not immediately clear flags because the content of RTC_TSTR and RTC_TSDR are cleared when TSF bit is reset.*/
1294 hrtc->Instance->SCR = RTC_SCR_CTSF;
1295 }
1296
1297 /* Get interrupt status */
1298 uint32_t tmp = tamp->MISR;
1299
1300 /* Immediately clear flags */
1301 tamp->SCR = tmp;
1302
1303 /* Check Tamper 1 status */
1304 if ((tmp & RTC_TAMPER_1) == RTC_TAMPER_1)
1305 {
1306#if (USE_HAL_RTC_REGISTER_CALLBACKS == 1)
1307 /* Call Tamper 1 Event registered Callback */
1308 hrtc->Tamper1EventCallback(hrtc);
1309#else
1310 /* Tamper 1 callback */
1312#endif /* USE_HAL_RTC_REGISTER_CALLBACKS */
1313 }
1314
1315#if defined(RTC_TAMPER2_SUPPORT)
1316 /* Check Tamper 2 status */
1317 if ((tmp & RTC_TAMPER_2) == RTC_TAMPER_2)
1318 {
1319#if (USE_HAL_RTC_REGISTER_CALLBACKS == 1)
1320 /* Call Tamper 2 Event registered Callback */
1321 hrtc->Tamper2EventCallback(hrtc);
1322#else
1323 /* Tamper 2 callback */
1324 HAL_RTCEx_Tamper2EventCallback(hrtc);
1325#endif /* USE_HAL_RTC_REGISTER_CALLBACKS */
1326 }
1327#endif /* RTC_TAMPER2_SUPPORT */
1328
1329 /* Check Tamper 3 status */
1330 if ((tmp & RTC_TAMPER_3) == RTC_TAMPER_3)
1331 {
1332#if (USE_HAL_RTC_REGISTER_CALLBACKS == 1)
1333 /* Call Tamper 3 Event registered Callback */
1334 hrtc->Tamper3EventCallback(hrtc);
1335#else
1336 /* Tamper 3 callback */
1338#endif /* USE_HAL_RTC_REGISTER_CALLBACKS */
1339 }
1340
1341 /* Check Internal Tamper 1 status */
1342 if ((tmp & RTC_INT_TAMPER_1) == RTC_INT_TAMPER_1)
1343 {
1344#if (USE_HAL_RTC_REGISTER_CALLBACKS == 1)
1345 /* Call Internal Tamper 1 Event registered callback */
1346 hrtc->InternalTamper1EventCallback(hrtc);
1347#else
1348 /* Call Internal Tamper 1 Event by-default callback */
1349 HAL_RTCEx_InternalTamper1EventCallback(hrtc);
1350#endif /* USE_HAL_RTC_REGISTER_CALLBACKS */
1351 }
1352
1353 /* Check Internal Tamper 2 status */
1354 if ((tmp & RTC_INT_TAMPER_2) == RTC_INT_TAMPER_2)
1355 {
1356#if (USE_HAL_RTC_REGISTER_CALLBACKS == 1)
1357 /* Call Internal Tamper 2 Event registered callback */
1358 hrtc->InternalTamper2EventCallback(hrtc);
1359#else
1360 /* Call Internal Tamper 2 Event by-default callback */
1361 HAL_RTCEx_InternalTamper2EventCallback(hrtc);
1362#endif /* USE_HAL_RTC_REGISTER_CALLBACKS */
1363 }
1364
1365 /* Check Internal Tamper 3 status */
1366 if ((tmp & RTC_INT_TAMPER_3) == RTC_INT_TAMPER_3)
1367 {
1368#if (USE_HAL_RTC_REGISTER_CALLBACKS == 1)
1369 /* Call Internal Tamper 3 Event registered callback */
1370 hrtc->InternalTamper3EventCallback(hrtc);
1371#else
1372 /* Call Internal Tamper 3 Event by-default callback */
1373 HAL_RTCEx_InternalTamper3EventCallback(hrtc);
1374#endif /* USE_HAL_RTC_REGISTER_CALLBACKS */
1375 }
1376
1377 /* Check Internal Tamper 4 status */
1378 if ((tmp & RTC_INT_TAMPER_4) == RTC_INT_TAMPER_4)
1379 {
1380#if (USE_HAL_RTC_REGISTER_CALLBACKS == 1)
1381 /* Call Internal Tamper 4 Event registered callback */
1382 hrtc->InternalTamper4EventCallback(hrtc);
1383#else
1384 /* Call Internal Tamper 4 Event by-default callback */
1385 HAL_RTCEx_InternalTamper4EventCallback(hrtc);
1386#endif /* USE_HAL_RTC_REGISTER_CALLBACKS */
1387 }
1388
1389 /* Check Internal Tamper 5 status */
1390 if ((tmp & RTC_INT_TAMPER_5) == RTC_INT_TAMPER_5)
1391 {
1392#if (USE_HAL_RTC_REGISTER_CALLBACKS == 1)
1393 /* Call Internal Tamper 5 Event registered callback */
1394 hrtc->InternalTamper5EventCallback(hrtc);
1395#else
1396 /* Call Internal Tamper 5 Event by-default callback */
1397 HAL_RTCEx_InternalTamper5EventCallback(hrtc);
1398#endif /* USE_HAL_RTC_REGISTER_CALLBACKS */
1399 }
1400
1401 /* Check Internal Tamper 6 status */
1402 if ((tmp & RTC_INT_TAMPER_6) == RTC_INT_TAMPER_6)
1403 {
1404#if (USE_HAL_RTC_REGISTER_CALLBACKS == 1)
1405 /* Call Internal Tamper 6 Event registered callback */
1406 hrtc->InternalTamper6EventCallback(hrtc);
1407#else
1408 /* Call Internal Tamper 6 Event by-default callback */
1409 HAL_RTCEx_InternalTamper6EventCallback(hrtc);
1410#endif /* USE_HAL_RTC_REGISTER_CALLBACKS */
1411 }
1412
1413 /* Check Internal Tamper 8 status */
1414 if ((tmp & RTC_INT_TAMPER_8) == RTC_INT_TAMPER_8)
1415 {
1416#if (USE_HAL_RTC_REGISTER_CALLBACKS == 1)
1417 /* Call Internal Tamper 8 Event registered callback */
1418 hrtc->InternalTamper8EventCallback(hrtc);
1419#else
1420 /* Call Internal Tamper 8 Event by-default callback */
1421 HAL_RTCEx_InternalTamper8EventCallback(hrtc);
1422#endif /* USE_HAL_RTC_REGISTER_CALLBACKS */
1423 }
1424
1425 /* Change RTC state */
1426 hrtc->State = HAL_RTC_STATE_READY;
1427}
1428#else
1430{
1431 /* Clear the EXTI's Flag for RTC TimeStamp and Tamper */
1432#if defined(DUAL_CORE)
1434 {
1436 }
1437 else
1438 {
1439 __HAL_RTC_TAMPER_TIMESTAMP_EXTID2_CLEAR_FLAG();
1440 }
1441#else /* SINGLE_CORE */
1443#endif /* DUAL_CORE */
1444
1445 /* Get the TimeStamp interrupt source enable status */
1447 {
1448 /* Get the pending status of the TIMESTAMP Interrupt */
1450 {
1451 /* TIMESTAMP callback */
1452#if (USE_HAL_RTC_REGISTER_CALLBACKS == 1)
1453 hrtc->TimeStampEventCallback(hrtc);
1454#else /* (USE_HAL_RTC_REGISTER_CALLBACKS == 1) */
1456#endif /* (USE_HAL_RTC_REGISTER_CALLBACKS == 1) */
1457
1458 /* Clear the TIMESTAMP interrupt pending bit (this will clear timestamp time and date registers) */
1460 }
1461 }
1462
1463 /* Get the Tamper 1 interrupt source enable status */
1464#if defined(RTC_TAMPxIE_SUPPORT)
1466#else
1468#endif /* RTC_TAMPxIE_SUPPORT */
1469 {
1470 /* Get the pending status of the Tamper 1 Interrupt */
1472 {
1473 /* Clear the Tamper 1 interrupt pending bit */
1475
1476 /* Tamper 1 callback */
1477#if (USE_HAL_RTC_REGISTER_CALLBACKS == 1)
1478 hrtc->Tamper1EventCallback(hrtc);
1479#else /* (USE_HAL_RTC_REGISTER_CALLBACKS == 1) */
1481#endif /* (USE_HAL_RTC_REGISTER_CALLBACKS == 1) */
1482 }
1483 }
1484
1485 /* Get the Tamper 2 interrupt source enable status */
1486#if defined(RTC_TAMPER2_SUPPORT)
1487#if defined(RTC_TAMPxIE_SUPPORT)
1488 if (__HAL_RTC_TAMPER_GET_IT_SOURCE(hrtc, RTC_IT_TAMP | RTC_IT_TAMP2) != 0U)
1489#else
1491#endif /* RTC_TAMPxIE_SUPPORT */
1492 {
1493 /* Get the pending status of the Tamper 2 Interrupt */
1494 if (__HAL_RTC_TAMPER_GET_FLAG(hrtc, RTC_FLAG_TAMP2F) != 0U)
1495 {
1496 /* Clear the Tamper 2 interrupt pending bit */
1497 __HAL_RTC_TAMPER_CLEAR_FLAG(hrtc, RTC_FLAG_TAMP2F);
1498
1499 /* Tamper 2 callback */
1500#if (USE_HAL_RTC_REGISTER_CALLBACKS == 1)
1501 hrtc->Tamper2EventCallback(hrtc);
1502#else /* (USE_HAL_RTC_REGISTER_CALLBACKS == 1) */
1503 HAL_RTCEx_Tamper2EventCallback(hrtc);
1504#endif /* (USE_HAL_RTC_REGISTER_CALLBACKS == 1) */
1505 }
1506 }
1507#endif /* RTC_TAMPER2_SUPPORT */
1508
1509 /* Get the Tamper 3 interrupts source enable status */
1510#if defined(RTC_TAMPxIE_SUPPORT)
1511 if (__HAL_RTC_TAMPER_GET_IT_SOURCE(hrtc, RTC_IT_TAMP | RTC_IT_TAMP3) != 0U)
1512#else
1514#endif /* RTC_TAMPxIE_SUPPORT */
1515 {
1516 /* Get the pending status of the Tamper 3 Interrupt */
1518 {
1519 /* Clear the Tamper 3 interrupt pending bit */
1521
1522 /* Tamper 3 callback */
1523#if (USE_HAL_RTC_REGISTER_CALLBACKS == 1)
1524 hrtc->Tamper3EventCallback(hrtc);
1525#else /* (USE_HAL_RTC_REGISTER_CALLBACKS == 1) */
1527#endif /* (USE_HAL_RTC_REGISTER_CALLBACKS == 1) */
1528 }
1529 }
1530
1531 /* Change RTC state */
1532 hrtc->State = HAL_RTC_STATE_READY;
1533}
1534#endif /* TAMP */
1535
1536/**
1537 * @brief TimeStamp callback.
1538 * @param hrtc RTC handle
1539 * @retval None
1540 */
1542{
1543 /* Prevent unused argument(s) compilation warning */
1544 UNUSED(hrtc);
1545
1546 /* NOTE : This function should not be modified, when the callback is needed,
1547 the HAL_RTCEx_TimeStampEventCallback could be implemented in the user file
1548 */
1549}
1550
1551/**
1552 * @}
1553 */
1554
1555/** @addtogroup RTCEx_Exported_Functions_Group5
1556 * @brief Extended RTC Tamper functions
1557 *
1558* @{
1559*/
1560
1561/**
1562 * @brief Tamper 1 callback.
1563 * @param hrtc RTC handle
1564 * @retval None
1565 */
1567{
1568 /* Prevent unused argument(s) compilation warning */
1569 UNUSED(hrtc);
1570
1571 /* NOTE : This function should not be modified, when the callback is needed,
1572 the HAL_RTCEx_Tamper1EventCallback could be implemented in the user file
1573 */
1574}
1575
1576#if defined(RTC_TAMPER2_SUPPORT)
1577/**
1578 * @brief Tamper 2 callback.
1579 * @param hrtc RTC handle
1580 * @retval None
1581 */
1582__weak void HAL_RTCEx_Tamper2EventCallback(RTC_HandleTypeDef * hrtc)
1583{
1584 /* Prevent unused argument(s) compilation warning */
1585 UNUSED(hrtc);
1586
1587 /* NOTE : This function should not be modified, when the callback is needed,
1588 the HAL_RTCEx_Tamper2EventCallback could be implemented in the user file
1589 */
1590}
1591#endif /* RTC_TAMPER2_SUPPORT */
1592
1593/**
1594 * @brief Tamper 3 callback.
1595 * @param hrtc RTC handle
1596 * @retval None
1597 */
1599{
1600 /* Prevent unused argument(s) compilation warning */
1601 UNUSED(hrtc);
1602
1603 /* NOTE : This function should not be modified, when the callback is needed,
1604 the HAL_RTCEx_Tamper3EventCallback could be implemented in the user file
1605 */
1606}
1607
1608#if defined(TAMP)
1609/**
1610 * @brief Internal Tamper 1 callback.
1611 * @param hrtc RTC handle
1612 * @retval None
1613 */
1614__weak void HAL_RTCEx_InternalTamper1EventCallback(RTC_HandleTypeDef *hrtc)
1615{
1616 /* Prevent unused argument(s) compilation warning */
1617 UNUSED(hrtc);
1618
1619 /* NOTE : This function should not be modified, when the callback is needed,
1620 the HAL_RTCEx_InternalTamper1EventCallback could be implemented in the user file
1621 */
1622}
1623
1624/**
1625 * @brief Internal Tamper 2 callback.
1626 * @param hrtc RTC handle
1627 * @retval None
1628 */
1629__weak void HAL_RTCEx_InternalTamper2EventCallback(RTC_HandleTypeDef *hrtc)
1630{
1631 /* Prevent unused argument(s) compilation warning */
1632 UNUSED(hrtc);
1633
1634 /* NOTE : This function should not be modified, when the callback is needed,
1635 the HAL_RTCEx_InternalTamper2EventCallback could be implemented in the user file
1636 */
1637}
1638
1639/**
1640 * @brief Internal Tamper 3 callback.
1641 * @param hrtc RTC handle
1642 * @retval None
1643 */
1644__weak void HAL_RTCEx_InternalTamper3EventCallback(RTC_HandleTypeDef *hrtc)
1645{
1646 /* Prevent unused argument(s) compilation warning */
1647 UNUSED(hrtc);
1648
1649 /* NOTE : This function should not be modified, when the callback is needed,
1650 the HAL_RTCEx_InternalTamper3EventCallback could be implemented in the user file
1651 */
1652}
1653
1654/**
1655 * @brief Internal Tamper 4 callback.
1656 * @param hrtc RTC handle
1657 * @retval None
1658 */
1659__weak void HAL_RTCEx_InternalTamper4EventCallback(RTC_HandleTypeDef *hrtc)
1660{
1661 /* Prevent unused argument(s) compilation warning */
1662 UNUSED(hrtc);
1663
1664 /* NOTE : This function should not be modified, when the callback is needed,
1665 the HAL_RTCEx_InternalTamper4EventCallback could be implemented in the user file
1666 */
1667}
1668
1669/**
1670 * @brief Internal Tamper 5 callback.
1671 * @param hrtc RTC handle
1672 * @retval None
1673 */
1674__weak void HAL_RTCEx_InternalTamper5EventCallback(RTC_HandleTypeDef *hrtc)
1675{
1676 /* Prevent unused argument(s) compilation warning */
1677 UNUSED(hrtc);
1678
1679 /* NOTE : This function should not be modified, when the callback is needed,
1680 the HAL_RTCEx_InternalTamper5EventCallback could be implemented in the user file
1681 */
1682}
1683
1684/**
1685 * @brief Internal Tamper 6 callback.
1686 * @param hrtc RTC handle
1687 * @retval None
1688 */
1689__weak void HAL_RTCEx_InternalTamper6EventCallback(RTC_HandleTypeDef *hrtc)
1690{
1691 /* Prevent unused argument(s) compilation warning */
1692 UNUSED(hrtc);
1693
1694 /* NOTE : This function should not be modified, when the callback is needed,
1695 the HAL_RTCEx_InternalTamper6EventCallback could be implemented in the user file
1696 */
1697}
1698
1699/**
1700 * @brief Internal Tamper 8 callback.
1701 * @param hrtc RTC handle
1702 * @retval None
1703 */
1704__weak void HAL_RTCEx_InternalTamper8EventCallback(RTC_HandleTypeDef *hrtc)
1705{
1706 /* Prevent unused argument(s) compilation warning */
1707 UNUSED(hrtc);
1708
1709 /* NOTE : This function should not be modified, when the callback is needed,
1710 the HAL_RTCEx_InternalTamper8EventCallback could be implemented in the user file
1711 */
1712}
1713#endif /* TAMP */
1714
1715/**
1716 * @}
1717 */
1718
1719/** @addtogroup RTCEx_Exported_Functions_Group1
1720 * @brief RTC TimeStamp and Tamper functions
1721 *
1722* @{
1723*/
1724
1725/**
1726 * @brief Handle TimeStamp polling request.
1727 * @param hrtc RTC handle
1728 * @param Timeout Timeout duration
1729 * @retval HAL status
1730 */
1732{
1733 uint32_t tickstart = HAL_GetTick();
1734
1736 {
1738 {
1739 /* Clear the TIMESTAMP OverRun Flag */
1741
1742 /* Change TIMESTAMP state */
1743 hrtc->State = HAL_RTC_STATE_ERROR;
1744
1745 return HAL_ERROR;
1746 }
1747
1748 if (Timeout != HAL_MAX_DELAY)
1749 {
1750 if (((HAL_GetTick() - tickstart) > Timeout) || (Timeout == 0U))
1751 {
1752 hrtc->State = HAL_RTC_STATE_TIMEOUT;
1753 return HAL_TIMEOUT;
1754 }
1755 }
1756 }
1757
1758 /* Change RTC state */
1759 hrtc->State = HAL_RTC_STATE_READY;
1760
1761 return HAL_OK;
1762}
1763
1764/**
1765 * @}
1766 */
1767
1768/** @addtogroup RTCEx_Exported_Functions_Group5
1769 * @brief Extended RTC Tamper functions
1770 *
1771* @{
1772*/
1773
1774/**
1775 * @brief Handle Tamper1 Polling.
1776 * @param hrtc RTC handle
1777 * @param Timeout Timeout duration
1778 * @retval HAL status
1779 */
1781{
1782 uint32_t tickstart = HAL_GetTick();
1783
1784 /* Get the status of the Interrupt */
1786 {
1787 if (Timeout != HAL_MAX_DELAY)
1788 {
1789 if (((HAL_GetTick() - tickstart) > Timeout) || (Timeout == 0U))
1790 {
1791 hrtc->State = HAL_RTC_STATE_TIMEOUT;
1792 return HAL_TIMEOUT;
1793 }
1794 }
1795 }
1796
1797 /* Clear the Tamper Flag */
1799
1800 /* Change RTC state */
1801 hrtc->State = HAL_RTC_STATE_READY;
1802
1803 return HAL_OK;
1804}
1805
1806#if defined(RTC_TAMPER2_SUPPORT)
1807/**
1808 * @brief Handle Tamper2 Polling.
1809 * @param hrtc RTC handle
1810 * @param Timeout Timeout duration
1811 * @retval HAL status
1812 */
1813HAL_StatusTypeDef HAL_RTCEx_PollForTamper2Event(RTC_HandleTypeDef * hrtc, uint32_t Timeout)
1814{
1815 uint32_t tickstart = HAL_GetTick();
1816
1817 /* Get the status of the Interrupt */
1818 while (__HAL_RTC_TAMPER_GET_FLAG(hrtc, RTC_FLAG_TAMP2F) == 0U)
1819 {
1820 if (Timeout != HAL_MAX_DELAY)
1821 {
1822 if (((HAL_GetTick() - tickstart) > Timeout) || (Timeout == 0U))
1823 {
1824 hrtc->State = HAL_RTC_STATE_TIMEOUT;
1825 return HAL_TIMEOUT;
1826 }
1827 }
1828 }
1829
1830 /* Clear the Tamper Flag */
1831 __HAL_RTC_TAMPER_CLEAR_FLAG(hrtc, RTC_FLAG_TAMP2F);
1832
1833 /* Change RTC state */
1834 hrtc->State = HAL_RTC_STATE_READY;
1835
1836 return HAL_OK;
1837}
1838#endif /* RTC_TAMPER2_SUPPORT */
1839
1840/**
1841 * @brief Handle Tamper3 Polling.
1842 * @param hrtc RTC handle
1843 * @param Timeout Timeout duration
1844 * @retval HAL status
1845 */
1847{
1848 uint32_t tickstart = HAL_GetTick();
1849
1850 /* Get the status of the Interrupt */
1852 {
1853 if (Timeout != HAL_MAX_DELAY)
1854 {
1855 if (((HAL_GetTick() - tickstart) > Timeout) || (Timeout == 0U))
1856 {
1857 hrtc->State = HAL_RTC_STATE_TIMEOUT;
1858 return HAL_TIMEOUT;
1859 }
1860 }
1861 }
1862
1863 /* Clear the Tamper Flag */
1865
1866 /* Change RTC state */
1867 hrtc->State = HAL_RTC_STATE_READY;
1868
1869 return HAL_OK;
1870}
1871
1872#if defined(TAMP)
1873/**
1874 * @brief Internal Tamper event polling.
1875 * @param hrtc RTC handle
1876 * @param IntTamper selected tamper.
1877 * This parameter can be any combination of existing internal tampers.
1878 * @param Timeout Timeout duration
1879 * @retval HAL status
1880 */
1881HAL_StatusTypeDef HAL_RTCEx_PollForInternalTamperEvent(RTC_HandleTypeDef *hrtc, uint32_t IntTamper, uint32_t Timeout)
1882{
1883 UNUSED(hrtc);
1885
1886 uint32_t tickstart = HAL_GetTick();
1887
1888 /* Get the status of the Interrupt */
1889 while (READ_BIT(TAMP->SR, IntTamper) != IntTamper)
1890 {
1891 if (Timeout != HAL_MAX_DELAY)
1892 {
1893 if (((HAL_GetTick() - tickstart) > Timeout) || (Timeout == 0U))
1894 {
1895 return HAL_TIMEOUT;
1896 }
1897 }
1898 }
1899
1900 /* Clear the Tamper Flag */
1901 WRITE_REG(TAMP->SCR, IntTamper);
1902
1903 return HAL_OK;
1904}
1905#endif /* TAMP */
1906
1907/**
1908 * @}
1909 */
1910
1911/** @addtogroup RTCEx_Exported_Functions_Group2
1912 * @brief RTC Wake-up functions
1913 *
1914@verbatim
1915 ===============================================================================
1916 ##### RTC Wake-up functions #####
1917 ===============================================================================
1918
1919 [..] This section provides functions allowing to configure Wake-up feature
1920
1921@endverbatim
1922 * @{
1923 */
1924
1925/**
1926 * @brief Set wake up timer.
1927 * @param hrtc RTC handle
1928 * @param WakeUpCounter Wake up counter
1929 * @param WakeUpClock Wake up clock
1930 * @retval HAL status
1931 */
1932HAL_StatusTypeDef HAL_RTCEx_SetWakeUpTimer(RTC_HandleTypeDef *hrtc, uint32_t WakeUpCounter, uint32_t WakeUpClock)
1933{
1934 uint32_t tickstart;
1935
1936 /* Check the parameters */
1937 assert_param(IS_RTC_WAKEUP_CLOCK(WakeUpClock));
1938 assert_param(IS_RTC_WAKEUP_COUNTER(WakeUpCounter));
1939
1940 /* Process Locked */
1942
1943 hrtc->State = HAL_RTC_STATE_BUSY;
1944
1945 /* Disable the write protection for RTC registers */
1947
1948 /* Clear WUTE in RTC_CR to disable the wakeup timer */
1950
1951 /* Poll WUTWF until it is set in RTC_ICSR / RTC_ISR to make sure the access to wakeup autoreload
1952 counter and to WUCKSEL[2:0] bits is allowed. This step must be skipped in
1953 calendar initialization mode. */
1954#if defined(TAMP)
1955 if (READ_BIT(RTC->ICSR, RTC_ICSR_INITF) == 0U)
1956 {
1957 tickstart = HAL_GetTick();
1958
1959 while (READ_BIT(hrtc->Instance->ICSR, RTC_FLAG_WUTWF) == 0U)
1960#else
1961 if (READ_BIT(RTC->ISR, RTC_ISR_INITF) == 0U)
1962 {
1963 tickstart = HAL_GetTick();
1964
1966#endif /* TAMP */
1967 {
1968 if ((HAL_GetTick() - tickstart) > RTC_TIMEOUT_VALUE)
1969 {
1970 /* Enable the write protection for RTC registers */
1972
1973 hrtc->State = HAL_RTC_STATE_TIMEOUT;
1974
1975 /* Process Unlocked */
1977
1978 return HAL_TIMEOUT;
1979 }
1980 }
1981 }
1982
1983 /* Clear the Wakeup Timer clock source bits and configure the clock source in CR register */
1984 uint32_t CR_tmp = hrtc->Instance->CR;
1985 CR_tmp &= (uint32_t)~RTC_CR_WUCKSEL;
1986 CR_tmp |= (uint32_t)WakeUpClock;
1987 hrtc->Instance->CR = CR_tmp;
1988
1989 /* Configure the Wakeup Timer counter */
1990 hrtc->Instance->WUTR = (uint32_t)WakeUpCounter;
1991
1992 /* Enable the Wakeup Timer */
1994
1995 /* Enable the write protection for RTC registers */
1997
1998 hrtc->State = HAL_RTC_STATE_READY;
1999
2000 /* Process Unlocked */
2002
2003 return HAL_OK;
2004}
2005
2006/**
2007 * @brief Set wake up timer with interrupt.
2008 * @param hrtc RTC handle
2009 * @param WakeUpCounter Wake up counter
2010 * @param WakeUpClock Wake up clock
2011 * @retval HAL status
2012 */
2013HAL_StatusTypeDef HAL_RTCEx_SetWakeUpTimer_IT(RTC_HandleTypeDef *hrtc, uint32_t WakeUpCounter, uint32_t WakeUpClock)
2014{
2015 uint32_t tickstart;
2016
2017 /* Check the parameters */
2018 assert_param(IS_RTC_WAKEUP_CLOCK(WakeUpClock));
2019 assert_param(IS_RTC_WAKEUP_COUNTER(WakeUpCounter));
2020
2021 /* Process Locked */
2023
2024 hrtc->State = HAL_RTC_STATE_BUSY;
2025
2026 /* Disable the write protection for RTC registers */
2028
2029 /* Clear WUTE in RTC_CR to disable the wakeup timer */
2031
2032 /* Poll WUTWF until it is set in RTC_ICSR to make sure the access to wakeup autoreload
2033 counter and to WUCKSEL[2:0] bits is allowed. This step must be skipped in
2034 calendar initialization mode. */
2035#if defined(TAMP)
2036 if (READ_BIT(RTC->ICSR, RTC_ICSR_INITF) == 0U)
2037 {
2038 tickstart = HAL_GetTick();
2039
2040 while (READ_BIT(hrtc->Instance->ICSR, RTC_FLAG_WUTWF) == 0U)
2041#else
2042 if (READ_BIT(RTC->ISR, RTC_ISR_INITF) == 0U)
2043 {
2044 tickstart = HAL_GetTick();
2045
2047#endif /* TAMP */
2048 {
2049 if ((HAL_GetTick() - tickstart) > RTC_TIMEOUT_VALUE)
2050 {
2051 /* Enable the write protection for RTC registers */
2053
2054 hrtc->State = HAL_RTC_STATE_TIMEOUT;
2055
2056 /* Process Unlocked */
2058
2059 return HAL_TIMEOUT;
2060 }
2061 }
2062 }
2063
2064 /* Configure the Wakeup Timer counter */
2065 hrtc->Instance->WUTR = (uint32_t)WakeUpCounter;
2066
2067 /* Clear the Wakeup Timer clock source bits and configure the clock source in CR register */
2068 {
2069 uint32_t CR_tmp = hrtc->Instance->CR;
2070 CR_tmp &= (uint32_t)~RTC_CR_WUCKSEL;
2071 CR_tmp |= (uint32_t)WakeUpClock;
2072 hrtc->Instance->CR = CR_tmp;
2073 }
2074
2075 /* RTC WakeUpTimer Interrupt Configuration: EXTI configuration */
2076#if defined(DUAL_CORE)
2078 {
2080 }
2081 else
2082 {
2083 __HAL_RTC_WAKEUPTIMER_EXTID2_ENABLE_IT();
2084 }
2085#else /* SINGLE_CORE */
2087#endif /* DUAL_CORE */
2088
2090
2091 /* Configure the Interrupt in the RTC_CR register */
2093
2094 /* Enable the Wakeup Timer */
2096
2097 /* Enable the write protection for RTC registers */
2099
2100 hrtc->State = HAL_RTC_STATE_READY;
2101
2102 /* Process Unlocked */
2104
2105 return HAL_OK;
2106}
2107
2108/**
2109 * @brief Deactivate wake up timer counter.
2110 * @param hrtc RTC handle
2111 * @retval HAL status
2112 */
2114{
2115 uint32_t tickstart;
2116
2117 /* Process Locked */
2119
2120 hrtc->State = HAL_RTC_STATE_BUSY;
2121
2122 /* Disable the write protection for RTC registers */
2124
2125 /* Disable the Wakeup Timer */
2127
2128 /* In case of interrupt mode is used, the interrupt source must disabled */
2130
2131 tickstart = HAL_GetTick();
2132 /* Wait till RTC WUTWF flag is set and if timeout is reached exit */
2133#if defined(TAMP)
2134 while (READ_BIT(hrtc->Instance->ICSR, RTC_FLAG_WUTWF) == 0U)
2135#else
2137#endif /* TAMP */
2138 {
2139 if ((HAL_GetTick() - tickstart) > RTC_TIMEOUT_VALUE)
2140 {
2141 /* Enable the write protection for RTC registers */
2143
2144 hrtc->State = HAL_RTC_STATE_TIMEOUT;
2145
2146 /* Process Unlocked */
2148
2149 return HAL_TIMEOUT;
2150 }
2151 }
2152
2153 /* Enable the write protection for RTC registers */
2155
2156 hrtc->State = HAL_RTC_STATE_READY;
2157
2158 /* Process Unlocked */
2160
2161 return HAL_OK;
2162}
2163
2164/**
2165 * @brief Get wake up timer counter.
2166 * @param hrtc RTC handle
2167 * @retval Counter value
2168 */
2170{
2171 /* Get the counter value */
2172 return ((uint32_t)(hrtc->Instance->WUTR & RTC_WUTR_WUT));
2173}
2174
2175/**
2176 * @brief Handle Wake Up Timer interrupt request.
2177 * @param hrtc RTC handle
2178 * @retval None
2179 */
2181{
2182 /* Clear the EXTI's line Flag for RTC WakeUpTimer */
2183#if defined(DUAL_CORE)
2185 {
2187 }
2188 else
2189 {
2190 __HAL_RTC_WAKEUPTIMER_EXTID2_CLEAR_FLAG();
2191 }
2192#else /* SINGLE_CORE */
2194#endif /* DUAL_CORE */
2195
2196#if defined(TAMP)
2197 /* Get the pending status of the WAKEUPTIMER Interrupt */
2198 if ((hrtc->Instance->MISR & RTC_MISR_WUTMF) != 0u)
2199 {
2200 /* Immediately clear flags */
2201 hrtc->Instance->SCR = RTC_SCR_CWUTF;
2202
2203 /* WAKEUPTIMER callback */
2204 #if (USE_HAL_RTC_REGISTER_CALLBACKS == 1)
2205 /* Call WakeUpTimerEvent registered Callback */
2206 hrtc->WakeUpTimerEventCallback(hrtc);
2207 #else
2209 #endif /* USE_HAL_RTC_REGISTER_CALLBACKS */
2210 }
2211#else
2212 /* Get the pending status of the WAKEUPTIMER Interrupt */
2214 {
2215 /* Clear the WAKEUPTIMER interrupt pending bit */
2217
2218 /* WAKEUPTIMER callback */
2219 #if (USE_HAL_RTC_REGISTER_CALLBACKS == 1)
2220 /* Call WakeUpTimerEvent registered Callback */
2221 hrtc->WakeUpTimerEventCallback(hrtc);
2222 #else
2224 #endif /* USE_HAL_RTC_REGISTER_CALLBACKS */
2225 }
2226#endif /* TAMP */
2227
2228 /* Change RTC state */
2229 hrtc->State = HAL_RTC_STATE_READY;
2230}
2231
2232/**
2233 * @brief Wake Up Timer callback.
2234 * @param hrtc RTC handle
2235 * @retval None
2236 */
2238{
2239 /* Prevent unused argument(s) compilation warning */
2240 UNUSED(hrtc);
2241
2242 /* NOTE : This function should not be modified, when the callback is needed,
2243 the HAL_RTCEx_WakeUpTimerEventCallback could be implemented in the user file
2244 */
2245}
2246
2247
2248/**
2249 * @brief Handle Wake Up Timer Polling.
2250 * @param hrtc RTC handle
2251 * @param Timeout Timeout duration
2252 * @retval HAL status
2253 */
2255{
2256 uint32_t tickstart = HAL_GetTick();
2257
2259 {
2260 if (Timeout != HAL_MAX_DELAY)
2261 {
2262 if (((HAL_GetTick() - tickstart) > Timeout) || (Timeout == 0U))
2263 {
2264 hrtc->State = HAL_RTC_STATE_TIMEOUT;
2265 return HAL_TIMEOUT;
2266 }
2267 }
2268 }
2269
2270 /* Clear the WAKEUPTIMER Flag */
2272
2273 /* Change RTC state */
2274 hrtc->State = HAL_RTC_STATE_READY;
2275
2276 return HAL_OK;
2277}
2278
2279/**
2280 * @}
2281 */
2282
2283
2284/** @addtogroup RTCEx_Exported_Functions_Group6
2285 * @brief Extended RTC Backup register functions
2286 *
2287@verbatim
2288 ===============================================================================
2289 ##### Extended RTC Backup register functions #####
2290 ===============================================================================
2291 [..]
2292 (+) Before calling any tamper or internal tamper function, you have to call first
2293 HAL_RTC_Init() function.
2294 (+) In that ine you can select to output tamper event on RTC pin.
2295 [..]
2296 This subsection provides functions allowing to
2297 (+) Write a data in a specified RTC Backup data register
2298 (+) Read a data in a specified RTC Backup data register
2299@endverbatim
2300 * @{
2301 */
2302
2303
2304/**
2305 * @brief Write a data in a specified RTC Backup data register.
2306 * @param hrtc RTC handle
2307 * @param BackupRegister RTC Backup data Register number.
2308 * This parameter can be: RTC_BKP_DRx where x can be from 0 to 31 to
2309 * specify the register.
2310 * @param Data Data to be written in the specified Backup data register.
2311 * @retval None
2312 */
2313void HAL_RTCEx_BKUPWrite(const RTC_HandleTypeDef * hrtc, uint32_t BackupRegister, uint32_t Data)
2314{
2315 uint32_t tmp;
2316
2317 /* Check the parameters */
2318 assert_param(IS_RTC_BKP(BackupRegister));
2319
2320 /* Point on address of first backup register */
2321#if defined(TAMP)
2322 tmp = (uint32_t) &(((TAMP_TypeDef *)((uint32_t)hrtc->Instance + TAMP_OFFSET))->BKP0R);
2323#else
2324 tmp = (uint32_t) &(hrtc->Instance->BKP0R);
2325#endif /* TAMP */
2326
2327 tmp += (BackupRegister * 4U);
2328
2329 /* Write the specified register */
2330 *(__IO uint32_t *)tmp = (uint32_t)Data;
2331}
2332
2333
2334/**
2335 * @brief Read data from the specified RTC Backup data Register.
2336 * @param hrtc RTC handle
2337 * @param BackupRegister RTC Backup data Register number.
2338 * This parameter can be: RTC_BKP_DRx where x can be from 0 to 31 to
2339 * specify the register.
2340 * @retval Read value
2341 */
2342uint32_t HAL_RTCEx_BKUPRead(const RTC_HandleTypeDef * hrtc, uint32_t BackupRegister)
2343{
2344 uint32_t tmp;
2345
2346 /* Check the parameters */
2347 assert_param(IS_RTC_BKP(BackupRegister));
2348
2349 /* Point on address of first backup register */
2350#if defined(TAMP)
2351 tmp = (uint32_t) &(((TAMP_TypeDef *)((uint32_t)hrtc->Instance + TAMP_OFFSET))->BKP0R);
2352#else
2353 tmp = (uint32_t) &(hrtc->Instance->BKP0R);
2354#endif /* TAMP */
2355
2356 tmp += (BackupRegister * 4U);
2357
2358 /* Read the specified register */
2359 return (*(__IO uint32_t *)tmp);
2360}
2361
2362
2363/**
2364 * @}
2365 */
2366
2367
2368/** @addtogroup RTCEx_Exported_Functions_Group3
2369 * @brief Extended Peripheral Control functions
2370 *
2371@verbatim
2372 ===============================================================================
2373 ##### Extended Peripheral Control functions #####
2374 ===============================================================================
2375 [..]
2376 This subsection provides functions allowing to
2377 (+) Write a data in a specified RTC Backup data register
2378 (+) Read a data in a specified RTC Backup data register
2379 (+) Set the Smooth calibration parameters.
2380 (+) Set Low Power calibration parameter (if feature supported).
2381 (+) Configure the Synchronization Shift Control Settings.
2382 (+) Configure the Calibration Pinout (RTC_CALIB) Selection (1Hz or 512Hz).
2383 (+) Deactivate the Calibration Pinout (RTC_CALIB) Selection (1Hz or 512Hz).
2384 (+) Enable the RTC reference clock detection.
2385 (+) Disable the RTC reference clock detection.
2386 (+) Enable the Bypass Shadow feature.
2387 (+) Disable the Bypass Shadow feature.
2388
2389@endverbatim
2390 * @{
2391 */
2392
2393
2394/**
2395 * @brief Set the Smooth calibration parameters.
2396 * @param hrtc RTC handle
2397 * @param SmoothCalibPeriod Select the Smooth Calibration Period.
2398 * This parameter can be can be one of the following values :
2399 * @arg RTC_SMOOTHCALIB_PERIOD_32SEC: The smooth calibration period is 32s.
2400 * @arg RTC_SMOOTHCALIB_PERIOD_16SEC: The smooth calibration period is 16s.
2401 * @arg RTC_SMOOTHCALIB_PERIOD_8SEC: The smooth calibration period is 8s.
2402 * @param SmoothCalibPlusPulses Select to Set or reset the CALP bit.
2403 * This parameter can be one of the following values:
2404 * @arg RTC_SMOOTHCALIB_PLUSPULSES_SET: Add one RTCCLK pulse every 2*11 pulses.
2405 * @arg RTC_SMOOTHCALIB_PLUSPULSES_RESET: No RTCCLK pulses are added.
2406 * @param SmoothCalibMinusPulsesValue Select the value of CALM[8:0] bits.
2407 * This parameter can be one any value from 0 to 0x000001FF.
2408 * @note To deactivate the smooth calibration, the field SmoothCalibPlusPulses
2409 * must be equal to SMOOTHCALIB_PLUSPULSES_RESET and the field
2410 * SmoothCalibMinusPulsesValue must be equal to 0.
2411 * @retval HAL status
2412 */
2413HAL_StatusTypeDef HAL_RTCEx_SetSmoothCalib(RTC_HandleTypeDef * hrtc, uint32_t SmoothCalibPeriod, uint32_t SmoothCalibPlusPulses, uint32_t SmoothCalibMinusPulsesValue)
2414{
2415 uint32_t tickstart;
2416
2417 /* Check the parameters */
2418 assert_param(IS_RTC_SMOOTH_CALIB_PERIOD(SmoothCalibPeriod));
2419 assert_param(IS_RTC_SMOOTH_CALIB_PLUS(SmoothCalibPlusPulses));
2420 assert_param(IS_RTC_SMOOTH_CALIB_MINUS(SmoothCalibMinusPulsesValue));
2421
2422 /* Process Locked */
2424
2425 hrtc->State = HAL_RTC_STATE_BUSY;
2426
2427 /* Disable the write protection for RTC registers */
2429
2430#if defined(TAMP)
2431 /* check if a calibration operation is pending */
2432 if ((hrtc->Instance->ICSR & RTC_ICSR_RECALPF) != 0U)
2433 {
2434 tickstart = HAL_GetTick();
2435
2436 /* Wait for pending calibration operation to finish */
2437 while ((hrtc->Instance->ICSR & RTC_ICSR_RECALPF) != 0U)
2438#else
2439 /* check if a calibration operation is pending */
2440 if ((hrtc->Instance->ISR & RTC_ISR_RECALPF) != 0U)
2441 {
2442 tickstart = HAL_GetTick();
2443
2444 /* Wait for pending calibration operation to finish */
2445 while ((hrtc->Instance->ISR & RTC_ISR_RECALPF) != 0U)
2446#endif /* TAMP */
2447 {
2448 if ((HAL_GetTick() - tickstart) > RTC_TIMEOUT_VALUE)
2449 {
2450 /* Enable the write protection for RTC registers */
2452
2453 /* Change RTC state */
2454 hrtc->State = HAL_RTC_STATE_TIMEOUT;
2455
2456 /* Process Unlocked */
2458
2459 return HAL_TIMEOUT;
2460 }
2461 }
2462 }
2463
2464 /* Configure the Smooth calibration settings */
2465 MODIFY_REG(hrtc->Instance->CALR, (RTC_CALR_CALP | RTC_CALR_CALW8 | RTC_CALR_CALW16 | RTC_CALR_CALM), (uint32_t)(SmoothCalibPeriod | SmoothCalibPlusPulses | SmoothCalibMinusPulsesValue));
2466
2467 /* Enable the write protection for RTC registers */
2469
2470 /* Change RTC state */
2471 hrtc->State = HAL_RTC_STATE_READY;
2472
2473 /* Process Unlocked */
2475
2476 return HAL_OK;
2477}
2478
2479/**
2480 * @brief Configure the Synchronization Shift Control Settings.
2481 * @note When REFCKON is set, firmware must not write to Shift control register.
2482 * @param hrtc RTC handle
2483 * @param ShiftAdd1S Select to add or not 1 second to the time calendar.
2484 * This parameter can be one of the following values:
2485 * @arg RTC_SHIFTADD1S_SET: Add one second to the clock calendar.
2486 * @arg RTC_SHIFTADD1S_RESET: No effect.
2487 * @param ShiftSubFS Select the number of Second Fractions to substitute.
2488 * This parameter can be one any value from 0 to 0x7FFF.
2489 * @retval HAL status
2490 */
2491HAL_StatusTypeDef HAL_RTCEx_SetSynchroShift(RTC_HandleTypeDef * hrtc, uint32_t ShiftAdd1S, uint32_t ShiftSubFS)
2492{
2493 uint32_t tickstart;
2494
2495 /* Check the parameters */
2496 assert_param(IS_RTC_SHIFT_ADD1S(ShiftAdd1S));
2497 assert_param(IS_RTC_SHIFT_SUBFS(ShiftSubFS));
2498
2499 /* Process Locked */
2501
2502 hrtc->State = HAL_RTC_STATE_BUSY;
2503
2504 /* Disable the write protection for RTC registers */
2506
2507 tickstart = HAL_GetTick();
2508
2509 /* Wait until the shift is completed */
2510#if defined(TAMP)
2511 while ((hrtc->Instance->ICSR & RTC_ICSR_SHPF) != 0U)
2512#else
2513 while ((hrtc->Instance->ISR & RTC_ISR_SHPF) != 0U)
2514#endif /* TAMP */
2515 {
2516 if ((HAL_GetTick() - tickstart) > RTC_TIMEOUT_VALUE)
2517 {
2518 /* Enable the write protection for RTC registers */
2520
2521 hrtc->State = HAL_RTC_STATE_TIMEOUT;
2522
2523 /* Process Unlocked */
2525
2526 return HAL_TIMEOUT;
2527 }
2528 }
2529
2530 /* Check if the reference clock detection is disabled */
2531 if ((hrtc->Instance->CR & RTC_CR_REFCKON) == 0U)
2532 {
2533 /* Configure the Shift settings */
2534 hrtc->Instance->SHIFTR = (uint32_t)(uint32_t)(ShiftSubFS) | (uint32_t)(ShiftAdd1S);
2535
2536 /* If RTC_CR_BYPSHAD bit = 0, wait for synchro else this check is not needed */
2537 if ((hrtc->Instance->CR & RTC_CR_BYPSHAD) == 0U)
2538 {
2540 {
2541 /* Enable the write protection for RTC registers */
2543
2544 hrtc->State = HAL_RTC_STATE_ERROR;
2545
2546 /* Process Unlocked */
2548
2549 return HAL_ERROR;
2550 }
2551 }
2552 }
2553 else
2554 {
2555 /* Enable the write protection for RTC registers */
2557
2558 /* Change RTC state */
2559 hrtc->State = HAL_RTC_STATE_ERROR;
2560
2561 /* Process Unlocked */
2563
2564 return HAL_ERROR;
2565 }
2566
2567 /* Enable the write protection for RTC registers */
2569
2570 /* Change RTC state */
2571 hrtc->State = HAL_RTC_STATE_READY;
2572
2573 /* Process Unlocked */
2575
2576 return HAL_OK;
2577}
2578
2579/**
2580 * @brief Configure the Calibration Pinout (RTC_CALIB) Selection (1Hz or 512Hz).
2581 * @param hrtc RTC handle
2582 * @param CalibOutput Select the Calibration output Selection.
2583 * This parameter can be one of the following values:
2584 * @arg RTC_CALIBOUTPUT_512HZ: A signal has a regular waveform at 512Hz.
2585 * @arg RTC_CALIBOUTPUT_1HZ: A signal has a regular waveform at 1Hz.
2586 * @retval HAL status
2587 */
2589{
2590 /* Check the parameters */
2591 assert_param(IS_RTC_CALIB_OUTPUT(CalibOutput));
2592
2593 /* Process Locked */
2595
2596 hrtc->State = HAL_RTC_STATE_BUSY;
2597
2598 /* Disable the write protection for RTC registers */
2600
2601 /* Clear flags before config */
2602 hrtc->Instance->CR &= (uint32_t)~RTC_CR_COSEL;
2603
2604 /* Configure the RTC_CR register */
2605 hrtc->Instance->CR |= (uint32_t)CalibOutput;
2606
2608
2609 /* Enable the write protection for RTC registers */
2611
2612 /* Change RTC state */
2613 hrtc->State = HAL_RTC_STATE_READY;
2614
2615 /* Process Unlocked */
2617
2618 return HAL_OK;
2619}
2620
2621/**
2622 * @brief Deactivate the Calibration Pinout (RTC_CALIB) Selection (1Hz or 512Hz).
2623 * @param hrtc RTC handle
2624 * @retval HAL status
2625 */
2627{
2628 /* Process Locked */
2630
2631 hrtc->State = HAL_RTC_STATE_BUSY;
2632
2633 /* Disable the write protection for RTC registers */
2635
2637
2638 /* Enable the write protection for RTC registers */
2640
2641 /* Change RTC state */
2642 hrtc->State = HAL_RTC_STATE_READY;
2643
2644 /* Process Unlocked */
2646
2647 return HAL_OK;
2648}
2649
2650/**
2651 * @brief Enable the RTC reference clock detection.
2652 * @param hrtc RTC handle
2653 * @retval HAL status
2654 */
2656{
2658 /* Process Locked */
2660
2661 hrtc->State = HAL_RTC_STATE_BUSY;
2662
2663 /* Disable the write protection for RTC registers */
2665
2666 /* Enter Initialization mode */
2668 if (status == HAL_OK)
2669 {
2671
2672 /* Exit Initialization mode */
2674 }
2675
2676 /* Enable the write protection for RTC registers */
2678 if (status == HAL_OK)
2679 {
2680 /* Change RTC state */
2681 hrtc->State = HAL_RTC_STATE_READY;
2682 }
2683 /* Process Unlocked */
2685
2686 return HAL_OK;
2687}
2688
2689/**
2690 * @brief Disable the RTC reference clock detection.
2691 * @param hrtc RTC handle
2692 * @retval HAL status
2693 */
2695{
2697 /* Process Locked */
2699
2700 hrtc->State = HAL_RTC_STATE_BUSY;
2701
2702 /* Disable the write protection for RTC registers */
2704
2705 /* Enter Initialization mode */
2707 if (status == HAL_OK)
2708 {
2710
2711 /* Exit Initialization mode */
2713 }
2714
2715 /* Enable the write protection for RTC registers */
2717
2718 if (status == HAL_OK)
2719 {
2720 /* Change RTC state */
2721 hrtc->State = HAL_RTC_STATE_READY;
2722
2723 }
2724
2725 /* Process Unlocked */
2727
2728 return HAL_OK;
2729}
2730
2731/**
2732 * @brief Enable the Bypass Shadow feature.
2733 * @note When the Bypass Shadow is enabled the calendar value are taken
2734 * directly from the Calendar counter.
2735 * @param hrtc RTC handle
2736 * @retval HAL status
2737 */
2739{
2740 /* Process Locked */
2742
2743 hrtc->State = HAL_RTC_STATE_BUSY;
2744
2745 /* Disable the write protection for RTC registers */
2747
2748 /* Set the BYPSHAD bit */
2749 hrtc->Instance->CR |= (uint32_t)RTC_CR_BYPSHAD;
2750
2751 /* Enable the write protection for RTC registers */
2753
2754 /* Change RTC state */
2755 hrtc->State = HAL_RTC_STATE_READY;
2756
2757 /* Process Unlocked */
2759
2760 return HAL_OK;
2761}
2762
2763/**
2764 * @brief Disable the Bypass Shadow feature.
2765 * @note When the Bypass Shadow is enabled the calendar value are taken
2766 * directly from the Calendar counter.
2767 * @param hrtc RTC handle
2768 * @retval HAL status
2769 */
2771{
2772 /* Process Locked */
2774
2775 hrtc->State = HAL_RTC_STATE_BUSY;
2776
2777 /* Disable the write protection for RTC registers */
2779
2780 /* Reset the BYPSHAD bit */
2781 hrtc->Instance->CR &= ((uint32_t)~RTC_CR_BYPSHAD);
2782
2783 /* Enable the write protection for RTC registers */
2785
2786 /* Change RTC state */
2787 hrtc->State = HAL_RTC_STATE_READY;
2788
2789 /* Process Unlocked */
2791
2792 return HAL_OK;
2793}
2794
2795#if defined(TAMP)
2796/**
2797 * @brief Increment Monotonic counter.
2798 * @param hrtc RTC handle
2799 * @param Instance Monotonic counter Instance
2800 * This parameter can be can be one of the following values :
2801 * @arg RTC_MONOTONIC_COUNTER_1
2802 * @retval HAL status
2803 */
2804HAL_StatusTypeDef HAL_RTCEx_MonotonicCounterIncrement(RTC_HandleTypeDef *hrtc, uint32_t Instance)
2805{
2806 UNUSED(hrtc);
2807 UNUSED(Instance);
2808 /* This register is read-only only and is incremented by one when a write access is done to this
2809 register. This register cannot roll-over and is frozen when reaching the maximum value. */
2810 CLEAR_REG(TAMP->COUNTR);
2811
2812 return HAL_OK;
2813}
2814
2815/**
2816 * @brief Monotonic counter incrementation.
2817 * @param hrtc RTC handle
2818 * @param Instance Monotonic counter Instance
2819 * This parameter can be can be one of the following values :
2820 * @arg RTC_MONOTONIC_COUNTER_1
2821 * @param Counter monotonic counter value
2822 * @retval HAL status
2823 */
2824HAL_StatusTypeDef HAL_RTCEx_MonotonicCounterGet(const RTC_HandleTypeDef *hrtc, uint32_t *Counter, uint32_t Instance)
2825{
2826 UNUSED(hrtc);
2827 UNUSED(Instance);
2828 /* This register is read-only only and is incremented by one when a write access is done to this
2829 register. This register cannot roll-over and is frozen when reaching the maximum value. */
2830 *Counter = READ_REG(TAMP->COUNTR);
2831
2832 return HAL_OK;
2833}
2834#endif /* TAMP */
2835
2836/**
2837 * @}
2838 */
2839
2840/** @addtogroup RTCEx_Exported_Functions_Group4
2841 * @brief Extended features functions
2842 *
2843@verbatim
2844 ===============================================================================
2845 ##### Extended features functions #####
2846 ===============================================================================
2847 [..] This section provides functions allowing to:
2848 (+) RTC Alarm B callback
2849 (+) RTC Poll for Alarm B request
2850
2851@endverbatim
2852 * @{
2853 */
2854
2855/**
2856 * @brief Alarm B callback.
2857 * @param hrtc RTC handle
2858 * @retval None
2859 */
2861{
2862 /* Prevent unused argument(s) compilation warning */
2863 UNUSED(hrtc);
2864
2865 /* NOTE : This function should not be modified, when the callback is needed,
2866 the HAL_RTCEx_AlarmBEventCallback could be implemented in the user file
2867 */
2868}
2869
2870/**
2871 * @brief Handle Alarm B Polling request.
2872 * @param hrtc RTC handle
2873 * @param Timeout Timeout duration
2874 * @retval HAL status
2875 */
2877{
2878 uint32_t tickstart = HAL_GetTick();
2879
2881 {
2882 if (Timeout != HAL_MAX_DELAY)
2883 {
2884 if (((HAL_GetTick() - tickstart) > Timeout) || (Timeout == 0U))
2885 {
2886 hrtc->State = HAL_RTC_STATE_TIMEOUT;
2887 return HAL_TIMEOUT;
2888 }
2889 }
2890 }
2891
2892 /* Clear the Alarm Flag */
2894
2895 /* Change RTC state */
2896 hrtc->State = HAL_RTC_STATE_READY;
2897
2898 return HAL_OK;
2899}
2900
2901/**
2902 * @}
2903 */
2904
2905
2906/**
2907 * @}
2908 */
2909
2910#endif /* HAL_RTC_MODULE_ENABLED */
2911
2912/**
2913 * @}
2914 */
2915
2916/**
2917 * @}
2918 */
2919
#define __IO
Defines 'read / write' permissions.
#define CM7_CPUID
uint32_t HAL_GetCurrentCPUID(void)
#define CLEAR_BIT(REG, BIT)
Definition stm32h7xx.h:209
#define CLEAR_REG(REG)
Definition stm32h7xx.h:213
#define SET_BIT(REG, BIT)
Definition stm32h7xx.h:207
#define WRITE_REG(REG, VAL)
Definition stm32h7xx.h:215
#define MODIFY_REG(REG, CLEARMASK, SETMASK)
Definition stm32h7xx.h:219
#define READ_BIT(REG, BIT)
Definition stm32h7xx.h:211
#define READ_REG(REG)
Definition stm32h7xx.h:217
uint32_t HAL_GetTick(void)
Provides a tick value in millisecond.
#define RTC_TSDR_DU_Pos
#define RTC_ISR_RECALPF
#define RTC_CR_WUTE
#define RTC_TAMPCR_TAMP2NOERASE
#define RTC_CR_COSEL
#define RTC_ISR_SHPF
#define RTC_TSTR_SU_Pos
#define RTC_CALR_CALW8
#define RTC_TSDR_MU
#define RTC_WUTR_WUT
#define RTC_TSDR_MU_Pos
#define RTC_CR_BYPSHAD
#define RTC_TSDR_DT
#define RTC_CALR_CALM
#define RTC_TAMPCR_TAMP3MF
#define RTC_TSDR_WDU
#define RTC_CR_WUCKSEL
#define RTC_TSTR_HT
#define RTC_CR_REFCKON
#define RTC_TSTR_MNU
#define RTC_CALR_CALW16
#define RTC_TSDR_MT
#define RTC_TSTR_PM
#define RTC_TAMPCR_TAMP2MF
#define RTC_CR_TSE
#define RTC_TSTR_MNT
#define RTC_CALR_CALP
#define RTC_TSTR_PM_Pos
#define RTC_TSTR_ST
#define RTC_TAMPCR_TAMP3NOERASE
#define RTC_ISR_INITF
#define RTC_TSTR_HU_Pos
#define RTC_TSTR_SU
#define RTC_TSDR_WDU_Pos
#define RTC_TSDR_DU
#define RTC_CR_TSEDGE
#define RTC_TSTR_MNU_Pos
#define RTC_TAMPCR_TAMP1MF
#define RTC_TAMPCR_TAMP1NOERASE
#define RTC_TSTR_HU
#define RTC
#define RTC_ATAMP_DISABLE
#define RTC_ATAMP_INTERRUPT_DISABLE
HAL_StatusTypeDef HAL_RTCEx_DeactivateTimeStamp(RTC_HandleTypeDef *hrtc)
HAL_StatusTypeDef HAL_RTCEx_DeactivateInternalTimeStamp(RTC_HandleTypeDef *hrtc)
HAL_StatusTypeDef HAL_RTCEx_SetInternalTimeStamp(RTC_HandleTypeDef *hrtc)
HAL_StatusTypeDef HAL_RTCEx_GetTimeStamp(RTC_HandleTypeDef *hrtc, RTC_TimeTypeDef *sTimeStamp, RTC_DateTypeDef *sTimeStampDate, uint32_t Format)
void HAL_RTCEx_TamperTimeStampIRQHandler(RTC_HandleTypeDef *hrtc)
HAL_StatusTypeDef HAL_RTCEx_SetTimeStamp(RTC_HandleTypeDef *hrtc, uint32_t TimeStampEdge, uint32_t RTC_TimeStampPin)
HAL_StatusTypeDef HAL_RTCEx_SetTimeStamp_IT(RTC_HandleTypeDef *hrtc, uint32_t TimeStampEdge, uint32_t RTC_TimeStampPin)
void HAL_RTCEx_TimeStampEventCallback(RTC_HandleTypeDef *hrtc)
HAL_StatusTypeDef HAL_RTCEx_PollForTimeStampEvent(RTC_HandleTypeDef *hrtc, uint32_t Timeout)
HAL_StatusTypeDef HAL_RTCEx_PollForWakeUpTimerEvent(RTC_HandleTypeDef *hrtc, uint32_t Timeout)
HAL_StatusTypeDef HAL_RTCEx_DeactivateWakeUpTimer(RTC_HandleTypeDef *hrtc)
void HAL_RTCEx_WakeUpTimerIRQHandler(RTC_HandleTypeDef *hrtc)
uint32_t HAL_RTCEx_GetWakeUpTimer(const RTC_HandleTypeDef *hrtc)
HAL_StatusTypeDef HAL_RTCEx_SetWakeUpTimer_IT(RTC_HandleTypeDef *hrtc, uint32_t WakeUpCounter, uint32_t WakeUpClock)
HAL_StatusTypeDef HAL_RTCEx_SetWakeUpTimer(RTC_HandleTypeDef *hrtc, uint32_t WakeUpCounter, uint32_t WakeUpClock)
void HAL_RTCEx_WakeUpTimerEventCallback(RTC_HandleTypeDef *hrtc)
Definition board_sleep.c:18
HAL_StatusTypeDef HAL_RTCEx_SetSynchroShift(RTC_HandleTypeDef *hrtc, uint32_t ShiftAdd1S, uint32_t ShiftSubFS)
HAL_StatusTypeDef HAL_RTCEx_SetSmoothCalib(RTC_HandleTypeDef *hrtc, uint32_t SmoothCalibPeriod, uint32_t SmoothCalibPlusPulses, uint32_t SmoothCalibMinusPulsesValue)
HAL_StatusTypeDef HAL_RTCEx_DeactivateCalibrationOutPut(RTC_HandleTypeDef *hrtc)
HAL_StatusTypeDef HAL_RTCEx_EnableBypassShadow(RTC_HandleTypeDef *hrtc)
HAL_StatusTypeDef HAL_RTCEx_DeactivateRefClock(RTC_HandleTypeDef *hrtc)
HAL_StatusTypeDef HAL_RTCEx_DisableBypassShadow(RTC_HandleTypeDef *hrtc)
HAL_StatusTypeDef HAL_RTCEx_SetRefClock(RTC_HandleTypeDef *hrtc)
HAL_StatusTypeDef HAL_RTCEx_SetCalibrationOutPut(RTC_HandleTypeDef *hrtc, uint32_t CalibOutput)
void HAL_RTCEx_AlarmBEventCallback(RTC_HandleTypeDef *hrtc)
HAL_StatusTypeDef HAL_RTCEx_PollForAlarmBEvent(RTC_HandleTypeDef *hrtc, uint32_t Timeout)
HAL_StatusTypeDef HAL_RTCEx_PollForTamper3Event(RTC_HandleTypeDef *hrtc, uint32_t Timeout)
HAL_StatusTypeDef HAL_RTCEx_SetTamper_IT(RTC_HandleTypeDef *hrtc, const RTC_TamperTypeDef *sTamper)
void HAL_RTCEx_Tamper3EventCallback(RTC_HandleTypeDef *hrtc)
HAL_StatusTypeDef HAL_RTCEx_SetTamper(RTC_HandleTypeDef *hrtc, const RTC_TamperTypeDef *sTamper)
void HAL_RTCEx_Tamper1EventCallback(RTC_HandleTypeDef *hrtc)
HAL_StatusTypeDef HAL_RTCEx_PollForTamper1Event(RTC_HandleTypeDef *hrtc, uint32_t Timeout)
HAL_StatusTypeDef HAL_RTCEx_DeactivateTamper(RTC_HandleTypeDef *hrtc, uint32_t Tamper)
void HAL_RTCEx_BKUPWrite(const RTC_HandleTypeDef *hrtc, uint32_t BackupRegister, uint32_t Data)
uint32_t HAL_RTCEx_BKUPRead(const RTC_HandleTypeDef *hrtc, uint32_t BackupRegister)
#define __HAL_RTC_TIMESTAMP_ENABLE_IT(__HANDLE__, __INTERRUPT__)
Enable the RTC TimeStamp interrupt.
#define __HAL_RTC_WAKEUPTIMER_DISABLE(__HANDLE__)
Disable the RTC WakeUp Timer peripheral.
#define __HAL_RTC_WAKEUPTIMER_GET_FLAG(__HANDLE__, __FLAG__)
Get the selected RTC WakeUpTimer's flag status.
#define __HAL_RTC_CALIBRATION_OUTPUT_ENABLE(__HANDLE__)
Enable the RTC calibration output.
#define __HAL_RTC_WAKEUPTIMER_EXTI_CLEAR_FLAG()
Clear the RTC WakeUp Timer associated Exti line flag.
#define __HAL_RTC_CLOCKREF_DETECTION_ENABLE(__HANDLE__)
Enable the clock reference detection.
#define __HAL_RTC_INTERNAL_TIMESTAMP_CLEAR_FLAG(__HANDLE__, __FLAG__)
Clear the RTC Internal Time Stamp's pending flags.
#define __HAL_RTC_TIMESTAMP_GET_IT_SOURCE(__HANDLE__, __INTERRUPT__)
Check whether the specified RTC Time Stamp interrupt has been enabled or not.
#define __HAL_RTC_TAMPER_TIMESTAMP_EXTI_ENABLE_RISING_EDGE()
Enable rising edge trigger on the RTC Tamper and Timestamp associated Exti line.
#define __HAL_RTC_TAMPER_TIMESTAMP_EXTI_ENABLE_RISING_FALLING_EDGE()
Enable rising & falling edge trigger on the RTC Tamper and Timestamp associated Exti line.
#define __HAL_RTC_WAKEUPTIMER_DISABLE_IT(__HANDLE__, __INTERRUPT__)
Disable the RTC WakeUpTimer interrupt.
#define __HAL_RTC_TIMESTAMP_GET_FLAG(__HANDLE__, __FLAG__)
Get the selected RTC TimeStamp's flag status.
#define __HAL_RTC_CLOCKREF_DETECTION_DISABLE(__HANDLE__)
Disable the clock reference detection.
#define __HAL_RTC_WAKEUPTIMER_ENABLE(__HANDLE__)
Enable the RTC WakeUp Timer peripheral.
#define __HAL_RTC_WAKEUPTIMER_ENABLE_IT(__HANDLE__, __INTERRUPT__)
Enable the RTC WakeUpTimer interrupt.
#define __HAL_RTC_TAMPER_TIMESTAMP_EXTI_ENABLE_IT()
Enable interrupt on the RTC Tamper and Timestamp associated Exti line.
#define __HAL_RTC_TIMESTAMP_DISABLE_IT(__HANDLE__, __INTERRUPT__)
Disable the RTC TimeStamp interrupt.
#define __HAL_RTC_CALIBRATION_OUTPUT_DISABLE(__HANDLE__)
Disable the calibration output.
#define __HAL_RTC_INTERNAL_TIMESTAMP_DISABLE(__HANDLE__)
Disable the RTC internal TimeStamp peripheral.
#define __HAL_RTC_WAKEUPTIMER_CLEAR_FLAG(__HANDLE__, __FLAG__)
Clear the RTC Wake Up timer's pending flags.
#define __HAL_RTC_WAKEUPTIMER_EXTI_ENABLE_RISING_EDGE()
Enable rising edge trigger on the RTC WakeUp Timer associated Exti line.
#define __HAL_RTC_TIMESTAMP_CLEAR_FLAG(__HANDLE__, __FLAG__)
Clear the RTC Time Stamp's pending flags.
#define __HAL_RTC_TIMESTAMP_ENABLE(__HANDLE__)
Enable the RTC TimeStamp peripheral.
#define __HAL_RTC_TAMPER_CLEAR_FLAG(__HANDLE__, __FLAG__)
Clear the RTC Tamper's pending flags.
#define __HAL_RTC_TAMPER_TIMESTAMP_EXTI_CLEAR_FLAG()
Clear the RTC Tamper and Timestamp associated Exti line flag.
#define __HAL_RTC_TAMPER_GET_IT_SOURCE(__HANDLE__, __INTERRUPT__)
Check whether the specified RTC Tamper interrupt has been enabled or not.
#define __HAL_RTC_WAKEUPTIMER_EXTI_ENABLE_IT()
Enable interrupt on the RTC WakeUp Timer associated Exti line.
#define __HAL_RTC_INTERNAL_TIMESTAMP_ENABLE(__HANDLE__)
Enable the RTC internal TimeStamp peripheral.
#define __HAL_RTC_TAMPER_GET_FLAG(__HANDLE__, __FLAG__)
Get the selected RTC Tamper's flag status.
#define IS_RTC_TAMPER(__TAMPER__)
#define IS_RTC_TAMPER_ERASE_MODE(__MODE__)
#define IS_RTC_SMOOTH_CALIB_MINUS(VALUE)
#define IS_RTC_SHIFT_ADD1S(SEL)
#define IS_RTC_TAMPER_SAMPLING_FREQ(__FREQ__)
#define IS_TIMESTAMP_EDGE(EDGE)
#define IS_RTC_TIMESTAMP_PIN(PIN)
#define IS_RTC_TAMPER_PRECHARGE_DURATION(__DURATION__)
#define IS_RTC_WAKEUP_COUNTER(COUNTER)
#define IS_RTC_SMOOTH_CALIB_PERIOD(PERIOD)
#define IS_RTC_TAMPER_INTERRUPT(__INTERRUPT__)
#define IS_RTC_TAMPER_FILTER(__FILTER__)
#define IS_RTC_BKP(__BKP__)
#define IS_RTC_SHIFT_SUBFS(FS)
#define IS_RTC_TAMPER_TIMESTAMPONTAMPER_DETECTION(__DETECTION__)
#define IS_RTC_TAMPER_TRIGGER(__TRIGGER__)
#define IS_RTC_WAKEUP_CLOCK(CLOCK)
#define IS_RTC_TAMPER_MASKFLAG_STATE(__STATE__)
#define IS_RTC_SMOOTH_CALIB_PLUS(PLUS)
#define IS_RTC_TAMPER_FILTER_CONFIG_CORRECT(FILTER, TRIGGER)
#define IS_RTC_CALIB_OUTPUT(OUTPUT)
#define IS_RTC_TAMPER_PULLUP_STATE(__STATE__)
#define IS_RTC_INTERNAL_TAMPER(__INT_TAMPER__)
#define RTC_TAMPER_ERASE_BACKUP_ENABLE
< These values are not applicable to the STM32H723/33, STM32H725/35 and STM32H730 devices,...
#define RTC_TAMPERFILTER_MASK
Masking all bits except those of field TAMPFLT[1:0].
#define RTC_IT_TAMP1
Enable Tamper Interrupt.
#define RTC_IT_TAMP
Enable all Tamper Interrupts.
#define RTC_TAMPERMASK_FLAG_DISABLE
< These values are not applicable to the STM32H723/33, STM32H725/35 and STM32H730 devices,...
#define RTC_TAMPERPRECHARGEDURATION_MASK
Masking all bits except those of field TAMPPRCH[1:0].
#define RTC_TAMPER_3
#define RTC_TAMPER_1
#define RTC_TAMPER_PULLUP_MASK
Maskin all bits except bit TAMPPUDIS.
#define RTC_TAMPERSAMPLINGFREQ_RTCCLK_MASK
Masking all bits except those of field TAMPFREQ[2:0].
#define RTC_TIMESTAMPONTAMPERDETECTION_MASK
Masking all bits except bit TAMPTS.
#define RTC_TAMPERTRIGGER_HIGHLEVEL
Warning : Filter must not be RTC_TAMPERFILTER_DISABLE.
#define RTC_TAMPERTRIGGER_FALLINGEDGE
Warning : Filter must be RTC_TAMPERFILTER_DISABLE.
HAL_StatusTypeDef HAL_RTC_WaitForSynchro(RTC_HandleTypeDef *hrtc)
#define __HAL_RTC_ALARM_CLEAR_FLAG(__HANDLE__, __FLAG__)
Clear the RTC Alarm's pending flags.
#define __HAL_RTC_WRITEPROTECTION_ENABLE(__HANDLE__)
Enable the write protection for RTC registers.
#define __HAL_RTC_ALARM_GET_FLAG(__HANDLE__, __FLAG__)
Get the selected RTC Alarm's flag status.
#define __HAL_RTC_WRITEPROTECTION_DISABLE(__HANDLE__)
Disable the write protection for RTC registers.
@ HAL_RTC_STATE_TIMEOUT
RTC timeout state.
@ HAL_RTC_STATE_ERROR
RTC error state.
@ HAL_RTC_STATE_READY
RTC initialized and ready for use.
@ HAL_RTC_STATE_BUSY
RTC process is ongoing.
#define RTC_FLAG_WUTWF
#define RTC_FLAG_TSOVF
#define RTC_FLAG_TSF
#define RTC_FLAG_ALRBF
#define RTC_FLAG_ITSF
#define RTC_FLAG_WUTF
#define IS_RTC_FORMAT(FORMAT)
#define RTC_FORMAT_BIN
#define RTC_IT_TS
Enable Timestamp Interrupt.
#define RTC_IT_WUT
Enable Wakeup timer Interrupt.
#define RTC_DR_RESERVED_MASK
#define RTC_TIMEOUT_VALUE
#define RTC_TR_RESERVED_MASK
HAL_StatusTypeDef RTC_ExitInitMode(RTC_HandleTypeDef *hrtc)
HAL_StatusTypeDef RTC_EnterInitMode(RTC_HandleTypeDef *hrtc)
uint8_t RTC_Bcd2ToByte(uint8_t Value)
#define RTC_FLAG_TAMP1F
#define RTC_FLAG_TAMP3F
RTC_HandleTypeDef hrtc
Definition main.c:52
This file contains all the functions prototypes for the HAL module driver.
#define assert_param(expr)
Uncomment the line below to expanse the "assert_param" macro in the HAL drivers code.
HAL_StatusTypeDef
HAL Status structures definition.
@ HAL_TIMEOUT
@ HAL_ERROR
@ HAL_OK
#define __HAL_UNLOCK(__HANDLE__)
#define UNUSED(x)
#define HAL_MAX_DELAY
#define __HAL_LOCK(__HANDLE__)
RTC Date structure definition.
uint8_t Year
Specifies the RTC Date Year.
uint8_t Month
Specifies the RTC Date Month (in BCD format).
uint8_t Date
Specifies the RTC Date.
uint8_t WeekDay
Specifies the RTC Date WeekDay.
RTC Handle Structure definition.
uint32_t Trigger
Specifies the Tamper Trigger.
uint32_t SamplingFrequency
Specifies the sampling frequency.
uint32_t Filter
Specifies the TAMP Filter Tamper.
uint32_t TamperPullUp
Specifies the Tamper PullUp .
uint32_t Tamper
Specifies the Tamper Pin.
uint32_t NoErase
Specifies the Tamper no erase mode.
uint32_t PrechargeDuration
Specifies the Precharge Duration .
uint32_t Interrupt
Specifies the Tamper Interrupt.
uint32_t TimeStampOnTamperDetection
Specifies the TimeStampOnTamperDetection.
uint32_t MaskFlag
Specifies the Tamper Flag masking.
RTC Time structure definition.
uint8_t Seconds
Specifies the RTC Time Seconds.
uint8_t Minutes
Specifies the RTC Time Minutes.
uint8_t TimeFormat
Specifies the RTC AM/PM Time.
uint32_t SubSeconds
Specifies the RTC_SSR RTC Sub Second register content.
uint8_t Hours
Specifies the RTC Time Hour.