2 ******************************************************************************
3 * @file stm32f7xx_hal_rtc_ex.c
4 * @author MCD Application Team
7 * @brief RTC HAL module driver.
8 * This file provides firmware functions to manage the following
9 * functionalities of the Real Time Clock (RTC) Extension peripheral:
10 * + RTC Time Stamp functions
11 * + RTC Tamper functions
12 * + RTC Wake-up functions
13 * + Extension Control functions
14 * + Extension RTC features functions
17 ==============================================================================
18 ##### How to use this driver #####
19 ==============================================================================
21 (+) Enable the RTC domain access.
22 (+) Configure the RTC Prescaler (Asynchronous and Synchronous) and RTC hour
23 format using the HAL_RTC_Init() function.
25 *** RTC Wakeup configuration ***
26 ================================
28 (+) To configure the RTC Wakeup Clock source and Counter use the HAL_RTC_SetWakeUpTimer()
29 function. You can also configure the RTC Wakeup timer in interrupt mode
30 using the HAL_RTC_SetWakeUpTimer_IT() function.
31 (+) To read the RTC WakeUp Counter register, use the HAL_RTC_GetWakeUpTimer()
34 *** TimeStamp configuration ***
35 ===============================
37 (+) Enables the RTC TimeStamp using the HAL_RTC_SetTimeStamp() function.
38 You can also configure the RTC TimeStamp with interrupt mode using the
39 HAL_RTC_SetTimeStamp_IT() function.
40 (+) To read the RTC TimeStamp Time and Date register, use the HAL_RTC_GetTimeStamp()
43 *** Internal TimeStamp configuration ***
44 ===============================
46 (+) Enables the RTC internal TimeStamp using the HAL_RTC_SetInternalTimeStamp() function.
47 (+) To read the RTC TimeStamp Time and Date register, use the HAL_RTC_GetTimeStamp()
50 *** Tamper configuration ***
51 ============================
53 (+) Enable the RTC Tamper and Configure the Tamper filter count, trigger Edge
54 or Level according to the Tamper filter (if equal to 0 Edge else Level)
55 value, sampling frequency, NoErase, MaskFlag, precharge or discharge and
56 Pull-UP using the HAL_RTC_SetTamper() function. You can configure RTC Tamper
57 with interrupt mode using HAL_RTC_SetTamper_IT() function.
58 (+) The default configuration of the Tamper erases the backup registers. To avoid
59 erase, enable the NoErase field on the RTC_TAMPCR register.
61 *** Backup Data Registers configuration ***
62 ===========================================
64 (+) To write to the RTC Backup Data registers, use the HAL_RTC_BKUPWrite()
66 (+) To read the RTC Backup Data registers, use the HAL_RTC_BKUPRead()
70 ******************************************************************************
73 * <h2><center>© COPYRIGHT(c) 2016 STMicroelectronics</center></h2>
75 * Redistribution and use in source and binary forms, with or without modification,
76 * are permitted provided that the following conditions are met:
77 * 1. Redistributions of source code must retain the above copyright notice,
78 * this list of conditions and the following disclaimer.
79 * 2. Redistributions in binary form must reproduce the above copyright notice,
80 * this list of conditions and the following disclaimer in the documentation
81 * and/or other materials provided with the distribution.
82 * 3. Neither the name of STMicroelectronics nor the names of its contributors
83 * may be used to endorse or promote products derived from this software
84 * without specific prior written permission.
86 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
87 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
88 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
89 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
90 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
91 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
92 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
93 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
94 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
95 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
97 ******************************************************************************
100 /* Includes ------------------------------------------------------------------*/
101 #include "stm32f7xx_hal.h"
103 /** @addtogroup STM32F7xx_HAL_Driver
107 /** @defgroup RTCEx RTCEx
108 * @brief RTC Extended HAL module driver
112 #ifdef HAL_RTC_MODULE_ENABLED
114 /* Private typedef -----------------------------------------------------------*/
115 /* Private define ------------------------------------------------------------*/
116 /* Private macro -------------------------------------------------------------*/
117 /* Private variables ---------------------------------------------------------*/
118 /* Private function prototypes -----------------------------------------------*/
119 /* Private functions ---------------------------------------------------------*/
121 /** @defgroup RTCEx_Exported_Functions RTCEx Exported Functions
126 /** @defgroup RTCEx_Group1 RTC TimeStamp and Tamper functions
127 * @brief RTC TimeStamp and Tamper functions
130 ===============================================================================
131 ##### RTC TimeStamp and Tamper functions #####
132 ===============================================================================
134 [..] This section provides functions allowing to configure TimeStamp feature
141 * @brief Sets TimeStamp.
142 * @note This API must be called before enabling the TimeStamp feature.
143 * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains
144 * the configuration information for RTC.
145 * @param TimeStampEdge: Specifies the pin edge on which the TimeStamp is
147 * This parameter can be one of the following values:
148 * @arg RTC_TIMESTAMPEDGE_RISING: the Time stamp event occurs on the
149 * rising edge of the related pin.
150 * @arg RTC_TIMESTAMPEDGE_FALLING: the Time stamp event occurs on the
151 * falling edge of the related pin.
152 * @param RTC_TimeStampPin: specifies the RTC TimeStamp Pin.
153 * This parameter can be one of the following values:
154 * @arg RTC_TIMESTAMPPIN_PC13: PC13 is selected as RTC TimeStamp Pin.
155 * @arg RTC_TIMESTAMPPIN_PI8: PI8 is selected as RTC TimeStamp Pin.
156 * @arg RTC_TIMESTAMPPIN_PC1: PC1 is selected as RTC TimeStamp Pin.
159 HAL_StatusTypeDef
HAL_RTCEx_SetTimeStamp(RTC_HandleTypeDef
*hrtc
, uint32_t TimeStampEdge
, uint32_t RTC_TimeStampPin
)
163 /* Check the parameters */
164 assert_param(IS_TIMESTAMP_EDGE(TimeStampEdge
));
165 assert_param(IS_RTC_TIMESTAMP_PIN(RTC_TimeStampPin
));
170 hrtc
->State
= HAL_RTC_STATE_BUSY
;
172 /* Get the RTC_CR register and clear the bits to be configured */
173 tmpreg
= (uint32_t)(hrtc
->Instance
->CR
& (uint32_t)~(RTC_CR_TSEDGE
| RTC_CR_TSE
));
175 tmpreg
|= TimeStampEdge
;
177 /* Disable the write protection for RTC registers */
178 __HAL_RTC_WRITEPROTECTION_DISABLE(hrtc
);
180 hrtc
->Instance
->OR
&= (uint32_t)~RTC_OR_TSINSEL
;
181 hrtc
->Instance
->OR
|= (uint32_t)(RTC_TimeStampPin
);
183 /* Configure the Time Stamp TSEDGE and Enable bits */
184 hrtc
->Instance
->CR
= (uint32_t)tmpreg
;
186 __HAL_RTC_TIMESTAMP_ENABLE(hrtc
);
188 /* Enable the write protection for RTC registers */
189 __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc
);
191 /* Change RTC state */
192 hrtc
->State
= HAL_RTC_STATE_READY
;
194 /* Process Unlocked */
201 * @brief Sets TimeStamp with Interrupt.
202 * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains
203 * the configuration information for RTC.
204 * @note This API must be called before enabling the TimeStamp feature.
205 * @param TimeStampEdge: Specifies the pin edge on which the TimeStamp is
207 * This parameter can be one of the following values:
208 * @arg RTC_TIMESTAMPEDGE_RISING: the Time stamp event occurs on the
209 * rising edge of the related pin.
210 * @arg RTC_TIMESTAMPEDGE_FALLING: the Time stamp event occurs on the
211 * falling edge of the related pin.
212 * @param RTC_TimeStampPin: Specifies the RTC TimeStamp Pin.
213 * This parameter can be one of the following values:
214 * @arg RTC_TIMESTAMPPIN_PC13: PC13 is selected as RTC TimeStamp Pin.
215 * @arg RTC_TIMESTAMPPIN_PI8: PI8 is selected as RTC TimeStamp Pin.
216 * @arg RTC_TIMESTAMPPIN_PC1: PC1 is selected as RTC TimeStamp Pin.
219 HAL_StatusTypeDef
HAL_RTCEx_SetTimeStamp_IT(RTC_HandleTypeDef
*hrtc
, uint32_t TimeStampEdge
, uint32_t RTC_TimeStampPin
)
223 /* Check the parameters */
224 assert_param(IS_TIMESTAMP_EDGE(TimeStampEdge
));
225 assert_param(IS_RTC_TIMESTAMP_PIN(RTC_TimeStampPin
));
230 hrtc
->State
= HAL_RTC_STATE_BUSY
;
232 /* Get the RTC_CR register and clear the bits to be configured */
233 tmpreg
= (uint32_t)(hrtc
->Instance
->CR
& (uint32_t)~(RTC_CR_TSEDGE
| RTC_CR_TSE
));
235 tmpreg
|= TimeStampEdge
;
237 /* Disable the write protection for RTC registers */
238 __HAL_RTC_WRITEPROTECTION_DISABLE(hrtc
);
240 /* Configure the Time Stamp TSEDGE and Enable bits */
241 hrtc
->Instance
->CR
= (uint32_t)tmpreg
;
243 hrtc
->Instance
->OR
&= (uint32_t)~RTC_OR_TSINSEL
;
244 hrtc
->Instance
->OR
|= (uint32_t)(RTC_TimeStampPin
);
246 __HAL_RTC_TIMESTAMP_ENABLE(hrtc
);
248 /* Enable IT timestamp */
249 __HAL_RTC_TIMESTAMP_ENABLE_IT(hrtc
,RTC_IT_TS
);
251 /* RTC timestamp Interrupt Configuration: EXTI configuration */
252 __HAL_RTC_TAMPER_TIMESTAMP_EXTI_ENABLE_IT();
254 EXTI
->RTSR
|= RTC_EXTI_LINE_TAMPER_TIMESTAMP_EVENT
;
256 /* Enable the write protection for RTC registers */
257 __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc
);
259 hrtc
->State
= HAL_RTC_STATE_READY
;
261 /* Process Unlocked */
268 * @brief Deactivates TimeStamp.
269 * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains
270 * the configuration information for RTC.
273 HAL_StatusTypeDef
HAL_RTCEx_DeactivateTimeStamp(RTC_HandleTypeDef
*hrtc
)
280 hrtc
->State
= HAL_RTC_STATE_BUSY
;
282 /* Disable the write protection for RTC registers */
283 __HAL_RTC_WRITEPROTECTION_DISABLE(hrtc
);
285 /* In case of interrupt mode is used, the interrupt source must disabled */
286 __HAL_RTC_TIMESTAMP_DISABLE_IT(hrtc
, RTC_IT_TS
);
288 /* Get the RTC_CR register and clear the bits to be configured */
289 tmpreg
= (uint32_t)(hrtc
->Instance
->CR
& (uint32_t)~(RTC_CR_TSEDGE
| RTC_CR_TSE
));
291 /* Configure the Time Stamp TSEDGE and Enable bits */
292 hrtc
->Instance
->CR
= (uint32_t)tmpreg
;
294 /* Enable the write protection for RTC registers */
295 __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc
);
297 hrtc
->State
= HAL_RTC_STATE_READY
;
299 /* Process Unlocked */
306 * @brief Sets Internal TimeStamp.
307 * @note This API must be called before enabling the internal TimeStamp feature.
308 * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains
309 * the configuration information for RTC.
312 HAL_StatusTypeDef
HAL_RTCEx_SetInternalTimeStamp(RTC_HandleTypeDef
*hrtc
)
317 hrtc
->State
= HAL_RTC_STATE_BUSY
;
319 /* Disable the write protection for RTC registers */
320 __HAL_RTC_WRITEPROTECTION_DISABLE(hrtc
);
322 /* Configure the internal Time Stamp Enable bits */
323 __HAL_RTC_INTERNAL_TIMESTAMP_ENABLE(hrtc
);
325 /* Enable the write protection for RTC registers */
326 __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc
);
328 /* Change RTC state */
329 hrtc
->State
= HAL_RTC_STATE_READY
;
331 /* Process Unlocked */
338 * @brief Deactivates internal TimeStamp.
339 * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains
340 * the configuration information for RTC.
343 HAL_StatusTypeDef
HAL_RTCEx_DeactivateInternalTimeStamp(RTC_HandleTypeDef
*hrtc
)
348 hrtc
->State
= HAL_RTC_STATE_BUSY
;
350 /* Disable the write protection for RTC registers */
351 __HAL_RTC_WRITEPROTECTION_DISABLE(hrtc
);
353 /* Configure the internal Time Stamp Enable bits */
354 __HAL_RTC_INTERNAL_TIMESTAMP_DISABLE(hrtc
);
356 /* Enable the write protection for RTC registers */
357 __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc
);
359 hrtc
->State
= HAL_RTC_STATE_READY
;
361 /* Process Unlocked */
368 * @brief Gets the RTC TimeStamp value.
369 * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains
370 * the configuration information for RTC.
371 * @param sTimeStamp: Pointer to Time structure
372 * @param sTimeStampDate: Pointer to Date structure
373 * @param Format: specifies the format of the entered parameters.
374 * This parameter can be one of the following values:
375 * FORMAT_BIN: Binary data format
376 * FORMAT_BCD: BCD data format
379 HAL_StatusTypeDef
HAL_RTCEx_GetTimeStamp(RTC_HandleTypeDef
*hrtc
, RTC_TimeTypeDef
* sTimeStamp
, RTC_DateTypeDef
* sTimeStampDate
, uint32_t Format
)
381 uint32_t tmptime
= 0, tmpdate
= 0;
383 /* Check the parameters */
384 assert_param(IS_RTC_FORMAT(Format
));
386 /* Get the TimeStamp time and date registers values */
387 tmptime
= (uint32_t)(hrtc
->Instance
->TSTR
& RTC_TR_RESERVED_MASK
);
388 tmpdate
= (uint32_t)(hrtc
->Instance
->TSDR
& RTC_DR_RESERVED_MASK
);
390 /* Fill the Time structure fields with the read parameters */
391 sTimeStamp
->Hours
= (uint8_t)((tmptime
& (RTC_TR_HT
| RTC_TR_HU
)) >> 16);
392 sTimeStamp
->Minutes
= (uint8_t)((tmptime
& (RTC_TR_MNT
| RTC_TR_MNU
)) >> 8);
393 sTimeStamp
->Seconds
= (uint8_t)(tmptime
& (RTC_TR_ST
| RTC_TR_SU
));
394 sTimeStamp
->TimeFormat
= (uint8_t)((tmptime
& (RTC_TR_PM
)) >> 16);
395 sTimeStamp
->SubSeconds
= (uint32_t) hrtc
->Instance
->TSSSR
;
397 /* Fill the Date structure fields with the read parameters */
398 sTimeStampDate
->Year
= 0;
399 sTimeStampDate
->Month
= (uint8_t)((tmpdate
& (RTC_DR_MT
| RTC_DR_MU
)) >> 8);
400 sTimeStampDate
->Date
= (uint8_t)(tmpdate
& (RTC_DR_DT
| RTC_DR_DU
));
401 sTimeStampDate
->WeekDay
= (uint8_t)((tmpdate
& (RTC_DR_WDU
)) >> 13);
403 /* Check the input parameters format */
404 if(Format
== RTC_FORMAT_BIN
)
406 /* Convert the TimeStamp structure parameters to Binary format */
407 sTimeStamp
->Hours
= (uint8_t)RTC_Bcd2ToByte(sTimeStamp
->Hours
);
408 sTimeStamp
->Minutes
= (uint8_t)RTC_Bcd2ToByte(sTimeStamp
->Minutes
);
409 sTimeStamp
->Seconds
= (uint8_t)RTC_Bcd2ToByte(sTimeStamp
->Seconds
);
411 /* Convert the DateTimeStamp structure parameters to Binary format */
412 sTimeStampDate
->Month
= (uint8_t)RTC_Bcd2ToByte(sTimeStampDate
->Month
);
413 sTimeStampDate
->Date
= (uint8_t)RTC_Bcd2ToByte(sTimeStampDate
->Date
);
414 sTimeStampDate
->WeekDay
= (uint8_t)RTC_Bcd2ToByte(sTimeStampDate
->WeekDay
);
417 /* Clear the TIMESTAMP Flag */
418 __HAL_RTC_TIMESTAMP_CLEAR_FLAG(hrtc
, RTC_FLAG_TSF
);
425 * @note By calling this API we disable the tamper interrupt for all tampers.
426 * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains
427 * the configuration information for RTC.
428 * @param sTamper: Pointer to Tamper Structure.
431 HAL_StatusTypeDef
HAL_RTCEx_SetTamper(RTC_HandleTypeDef
*hrtc
, RTC_TamperTypeDef
* sTamper
)
435 /* Check the parameters */
436 assert_param(IS_RTC_TAMPER(sTamper
->Tamper
));
437 assert_param(IS_RTC_TAMPER_TRIGGER(sTamper
->Trigger
));
438 assert_param(IS_RTC_TAMPER_ERASE_MODE(sTamper
->NoErase
));
439 assert_param(IS_RTC_TAMPER_MASKFLAG_STATE(sTamper
->MaskFlag
));
440 assert_param(IS_RTC_TAMPER_FILTER(sTamper
->Filter
));
441 assert_param(IS_RTC_TAMPER_SAMPLING_FREQ(sTamper
->SamplingFrequency
));
442 assert_param(IS_RTC_TAMPER_PRECHARGE_DURATION(sTamper
->PrechargeDuration
));
443 assert_param(IS_RTC_TAMPER_PULLUP_STATE(sTamper
->TamperPullUp
));
444 assert_param(IS_RTC_TAMPER_TIMESTAMPONTAMPER_DETECTION(sTamper
->TimeStampOnTamperDetection
));
449 hrtc
->State
= HAL_RTC_STATE_BUSY
;
451 if(sTamper
->Trigger
!= RTC_TAMPERTRIGGER_RISINGEDGE
)
453 sTamper
->Trigger
= (uint32_t)(sTamper
->Tamper
<< 1);
456 if(sTamper
->NoErase
!= RTC_TAMPER_ERASE_BACKUP_ENABLE
)
458 sTamper
->NoErase
= 0;
459 if((sTamper
->Tamper
& RTC_TAMPER_1
) != 0)
461 sTamper
->NoErase
|= RTC_TAMPCR_TAMP1NOERASE
;
463 if((sTamper
->Tamper
& RTC_TAMPER_2
) != 0)
465 sTamper
->NoErase
|= RTC_TAMPCR_TAMP2NOERASE
;
467 if((sTamper
->Tamper
& RTC_TAMPER_3
) != 0)
469 sTamper
->NoErase
|= RTC_TAMPCR_TAMP3NOERASE
;
473 if(sTamper
->MaskFlag
!= RTC_TAMPERMASK_FLAG_DISABLE
)
475 sTamper
->MaskFlag
= 0;
476 if((sTamper
->Tamper
& RTC_TAMPER_1
) != 0)
478 sTamper
->MaskFlag
|= RTC_TAMPCR_TAMP1MF
;
480 if((sTamper
->Tamper
& RTC_TAMPER_2
) != 0)
482 sTamper
->MaskFlag
|= RTC_TAMPCR_TAMP2MF
;
484 if((sTamper
->Tamper
& RTC_TAMPER_3
) != 0)
486 sTamper
->MaskFlag
|= RTC_TAMPCR_TAMP3MF
;
490 tmpreg
= ((uint32_t)sTamper
->Tamper
| (uint32_t)sTamper
->Trigger
| (uint32_t)sTamper
->NoErase
|\
491 (uint32_t)sTamper
->MaskFlag
| (uint32_t)sTamper
->Filter
| (uint32_t)sTamper
->SamplingFrequency
|\
492 (uint32_t)sTamper
->PrechargeDuration
| (uint32_t)sTamper
->TamperPullUp
| sTamper
->TimeStampOnTamperDetection
);
494 hrtc
->Instance
->TAMPCR
&= (uint32_t)~((uint32_t)sTamper
->Tamper
| (uint32_t)(sTamper
->Tamper
<< 1) | (uint32_t)RTC_TAMPCR_TAMPTS
|\
495 (uint32_t)RTC_TAMPCR_TAMPFREQ
| (uint32_t)RTC_TAMPCR_TAMPFLT
| (uint32_t)RTC_TAMPCR_TAMPPRCH
|\
496 (uint32_t)RTC_TAMPCR_TAMPPUDIS
| (uint32_t)RTC_TAMPCR_TAMPIE
| (uint32_t)RTC_TAMPCR_TAMP1IE
|\
497 (uint32_t)RTC_TAMPCR_TAMP2IE
| (uint32_t)RTC_TAMPCR_TAMP3IE
| (uint32_t)RTC_TAMPCR_TAMP1NOERASE
|\
498 (uint32_t)RTC_TAMPCR_TAMP2NOERASE
| (uint32_t)RTC_TAMPCR_TAMP3NOERASE
| (uint32_t)RTC_TAMPCR_TAMP1MF
|\
499 (uint32_t)RTC_TAMPCR_TAMP2MF
| (uint32_t)RTC_TAMPCR_TAMP3MF
);
501 hrtc
->Instance
->TAMPCR
|= tmpreg
;
503 hrtc
->State
= HAL_RTC_STATE_READY
;
505 /* Process Unlocked */
512 * @brief Sets Tamper with interrupt.
513 * @note By calling this API we force the tamper interrupt for all tampers.
514 * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains
515 * the configuration information for RTC.
516 * @param sTamper: Pointer to RTC Tamper.
519 HAL_StatusTypeDef
HAL_RTCEx_SetTamper_IT(RTC_HandleTypeDef
*hrtc
, RTC_TamperTypeDef
* sTamper
)
523 /* Check the parameters */
524 assert_param(IS_RTC_TAMPER(sTamper
->Tamper
));
525 assert_param(IS_RTC_TAMPER_INTERRUPT(sTamper
->Interrupt
));
526 assert_param(IS_RTC_TAMPER_TRIGGER(sTamper
->Trigger
));
527 assert_param(IS_RTC_TAMPER_ERASE_MODE(sTamper
->NoErase
));
528 assert_param(IS_RTC_TAMPER_MASKFLAG_STATE(sTamper
->MaskFlag
));
529 assert_param(IS_RTC_TAMPER_FILTER(sTamper
->Filter
));
530 assert_param(IS_RTC_TAMPER_SAMPLING_FREQ(sTamper
->SamplingFrequency
));
531 assert_param(IS_RTC_TAMPER_PRECHARGE_DURATION(sTamper
->PrechargeDuration
));
532 assert_param(IS_RTC_TAMPER_PULLUP_STATE(sTamper
->TamperPullUp
));
533 assert_param(IS_RTC_TAMPER_TIMESTAMPONTAMPER_DETECTION(sTamper
->TimeStampOnTamperDetection
));
538 hrtc
->State
= HAL_RTC_STATE_BUSY
;
540 /* Configure the tamper trigger */
541 if(sTamper
->Trigger
!= RTC_TAMPERTRIGGER_RISINGEDGE
)
543 sTamper
->Trigger
= (uint32_t)(sTamper
->Tamper
<< 1);
546 if(sTamper
->NoErase
!= RTC_TAMPER_ERASE_BACKUP_ENABLE
)
548 sTamper
->NoErase
= 0;
549 if((sTamper
->Tamper
& RTC_TAMPER_1
) != 0)
551 sTamper
->NoErase
|= RTC_TAMPCR_TAMP1NOERASE
;
553 if((sTamper
->Tamper
& RTC_TAMPER_2
) != 0)
555 sTamper
->NoErase
|= RTC_TAMPCR_TAMP2NOERASE
;
557 if((sTamper
->Tamper
& RTC_TAMPER_3
) != 0)
559 sTamper
->NoErase
|= RTC_TAMPCR_TAMP3NOERASE
;
563 if(sTamper
->MaskFlag
!= RTC_TAMPERMASK_FLAG_DISABLE
)
565 sTamper
->MaskFlag
= 0;
566 if((sTamper
->Tamper
& RTC_TAMPER_1
) != 0)
568 sTamper
->MaskFlag
|= RTC_TAMPCR_TAMP1MF
;
570 if((sTamper
->Tamper
& RTC_TAMPER_2
) != 0)
572 sTamper
->MaskFlag
|= RTC_TAMPCR_TAMP2MF
;
574 if((sTamper
->Tamper
& RTC_TAMPER_3
) != 0)
576 sTamper
->MaskFlag
|= RTC_TAMPCR_TAMP3MF
;
580 tmpreg
= ((uint32_t)sTamper
->Tamper
| (uint32_t)sTamper
->Interrupt
| (uint32_t)sTamper
->Trigger
| (uint32_t)sTamper
->NoErase
|\
581 (uint32_t)sTamper
->MaskFlag
| (uint32_t)sTamper
->Filter
| (uint32_t)sTamper
->SamplingFrequency
|\
582 (uint32_t)sTamper
->PrechargeDuration
| (uint32_t)sTamper
->TamperPullUp
| sTamper
->TimeStampOnTamperDetection
);
584 hrtc
->Instance
->TAMPCR
&= (uint32_t)~((uint32_t)sTamper
->Tamper
| (uint32_t)(sTamper
->Tamper
<< 1) | (uint32_t)RTC_TAMPCR_TAMPTS
|\
585 (uint32_t)RTC_TAMPCR_TAMPFREQ
| (uint32_t)RTC_TAMPCR_TAMPFLT
| (uint32_t)RTC_TAMPCR_TAMPPRCH
|\
586 (uint32_t)RTC_TAMPCR_TAMPPUDIS
| (uint32_t)RTC_TAMPCR_TAMPIE
| (uint32_t)RTC_TAMPCR_TAMP1IE
|\
587 (uint32_t)RTC_TAMPCR_TAMP2IE
| (uint32_t)RTC_TAMPCR_TAMP3IE
| (uint32_t)RTC_TAMPCR_TAMP1NOERASE
|\
588 (uint32_t)RTC_TAMPCR_TAMP2NOERASE
| (uint32_t)RTC_TAMPCR_TAMP3NOERASE
| (uint32_t)RTC_TAMPCR_TAMP1MF
|\
589 (uint32_t)RTC_TAMPCR_TAMP2MF
| (uint32_t)RTC_TAMPCR_TAMP3MF
);
591 hrtc
->Instance
->TAMPCR
|= tmpreg
;
593 /* RTC Tamper Interrupt Configuration: EXTI configuration */
594 __HAL_RTC_TAMPER_TIMESTAMP_EXTI_ENABLE_IT();
596 EXTI
->RTSR
|= RTC_EXTI_LINE_TAMPER_TIMESTAMP_EVENT
;
598 hrtc
->State
= HAL_RTC_STATE_READY
;
600 /* Process Unlocked */
607 * @brief Deactivates Tamper.
608 * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains
609 * the configuration information for RTC.
610 * @param Tamper: Selected tamper pin.
611 * This parameter can be RTC_Tamper_1 and/or RTC_TAMPER_2.
614 HAL_StatusTypeDef
HAL_RTCEx_DeactivateTamper(RTC_HandleTypeDef
*hrtc
, uint32_t Tamper
)
616 assert_param(IS_RTC_TAMPER(Tamper
));
621 hrtc
->State
= HAL_RTC_STATE_BUSY
;
623 /* Disable the selected Tamper pin */
624 hrtc
->Instance
->TAMPCR
&= (uint32_t)~Tamper
;
626 if ((Tamper
& RTC_TAMPER_1
) != 0)
628 /* Disable the Tamper1 interrupt */
629 hrtc
->Instance
->TAMPCR
&= (uint32_t)~(RTC_IT_TAMP
| RTC_IT_TAMP1
);
631 if ((Tamper
& RTC_TAMPER_2
) != 0)
633 /* Disable the Tamper2 interrupt */
634 hrtc
->Instance
->TAMPCR
&= (uint32_t)~(RTC_IT_TAMP
| RTC_IT_TAMP2
);
636 if ((Tamper
& RTC_TAMPER_3
) != 0)
638 /* Disable the Tamper2 interrupt */
639 hrtc
->Instance
->TAMPCR
&= (uint32_t)~(RTC_IT_TAMP
| RTC_IT_TAMP3
);
642 hrtc
->State
= HAL_RTC_STATE_READY
;
644 /* Process Unlocked */
651 * @brief This function handles TimeStamp interrupt request.
652 * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains
653 * the configuration information for RTC.
656 void HAL_RTCEx_TamperTimeStampIRQHandler(RTC_HandleTypeDef
*hrtc
)
658 if(__HAL_RTC_TIMESTAMP_GET_IT(hrtc
, RTC_IT_TS
))
660 /* Get the status of the Interrupt */
661 if((uint32_t)(hrtc
->Instance
->CR
& RTC_IT_TS
) != (uint32_t)RESET
)
663 /* TIMESTAMP callback */
664 HAL_RTCEx_TimeStampEventCallback(hrtc
);
666 /* Clear the TIMESTAMP interrupt pending bit */
667 __HAL_RTC_TIMESTAMP_CLEAR_FLAG(hrtc
,RTC_FLAG_TSF
);
671 /* Get the status of the Interrupt */
672 if(__HAL_RTC_TAMPER_GET_FLAG(hrtc
, RTC_FLAG_TAMP1F
)== SET
)
674 /* Get the TAMPER Interrupt enable bit and pending bit */
675 if((((hrtc
->Instance
->TAMPCR
& RTC_TAMPCR_TAMPIE
)) != (uint32_t)RESET
) || \
676 (((hrtc
->Instance
->TAMPCR
& RTC_TAMPCR_TAMP1IE
)) != (uint32_t)RESET
))
678 /* Tamper callback */
679 HAL_RTCEx_Tamper1EventCallback(hrtc
);
681 /* Clear the Tamper interrupt pending bit */
682 __HAL_RTC_TAMPER_CLEAR_FLAG(hrtc
,RTC_FLAG_TAMP1F
);
686 /* Get the status of the Interrupt */
687 if(__HAL_RTC_TAMPER_GET_FLAG(hrtc
, RTC_FLAG_TAMP2F
)== SET
)
689 /* Get the TAMPER Interrupt enable bit and pending bit */
690 if((((hrtc
->Instance
->TAMPCR
& RTC_TAMPCR_TAMPIE
)) != (uint32_t)RESET
) || \
691 (((hrtc
->Instance
->TAMPCR
& RTC_TAMPCR_TAMP2IE
)) != (uint32_t)RESET
))
693 /* Tamper callback */
694 HAL_RTCEx_Tamper2EventCallback(hrtc
);
696 /* Clear the Tamper interrupt pending bit */
697 __HAL_RTC_TAMPER_CLEAR_FLAG(hrtc
, RTC_FLAG_TAMP2F
);
701 /* Get the status of the Interrupt */
702 if(__HAL_RTC_TAMPER_GET_FLAG(hrtc
, RTC_FLAG_TAMP3F
)== SET
)
704 /* Get the TAMPER Interrupt enable bit and pending bit */
705 if((((hrtc
->Instance
->TAMPCR
& RTC_TAMPCR_TAMPIE
)) != (uint32_t)RESET
) || \
706 (((hrtc
->Instance
->TAMPCR
& RTC_TAMPCR_TAMP3IE
)) != (uint32_t)RESET
))
708 /* Tamper callback */
709 HAL_RTCEx_Tamper3EventCallback(hrtc
);
711 /* Clear the Tamper interrupt pending bit */
712 __HAL_RTC_TAMPER_CLEAR_FLAG(hrtc
, RTC_FLAG_TAMP3F
);
716 /* Clear the EXTI's Flag for RTC TimeStamp and Tamper */
717 __HAL_RTC_TAMPER_TIMESTAMP_EXTI_CLEAR_FLAG();
719 /* Change RTC state */
720 hrtc
->State
= HAL_RTC_STATE_READY
;
724 * @brief TimeStamp callback.
725 * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains
726 * the configuration information for RTC.
729 __weak
void HAL_RTCEx_TimeStampEventCallback(RTC_HandleTypeDef
*hrtc
)
731 /* Prevent unused argument(s) compilation warning */
734 /* NOTE : This function Should not be modified, when the callback is needed,
735 the HAL_RTC_TimeStampEventCallback could be implemented in the user file
740 * @brief Tamper 1 callback.
741 * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains
742 * the configuration information for RTC.
745 __weak
void HAL_RTCEx_Tamper1EventCallback(RTC_HandleTypeDef
*hrtc
)
747 /* Prevent unused argument(s) compilation warning */
750 /* NOTE : This function Should not be modified, when the callback is needed,
751 the HAL_RTC_Tamper1EventCallback could be implemented in the user file
756 * @brief Tamper 2 callback.
757 * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains
758 * the configuration information for RTC.
761 __weak
void HAL_RTCEx_Tamper2EventCallback(RTC_HandleTypeDef
*hrtc
)
763 /* Prevent unused argument(s) compilation warning */
766 /* NOTE : This function Should not be modified, when the callback is needed,
767 the HAL_RTC_Tamper2EventCallback could be implemented in the user file
772 * @brief Tamper 3 callback.
773 * @param hrtc: RTC handle
776 __weak
void HAL_RTCEx_Tamper3EventCallback(RTC_HandleTypeDef
*hrtc
)
778 /* Prevent unused argument(s) compilation warning */
781 /* NOTE : This function Should not be modified, when the callback is needed,
782 the HAL_RTCEx_Tamper3EventCallback could be implemented in the user file
787 * @brief This function handles TimeStamp polling request.
788 * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains
789 * the configuration information for RTC.
790 * @param Timeout: Timeout duration
793 HAL_StatusTypeDef
HAL_RTCEx_PollForTimeStampEvent(RTC_HandleTypeDef
*hrtc
, uint32_t Timeout
)
795 uint32_t tickstart
= 0;
798 tickstart
= HAL_GetTick();
800 while(__HAL_RTC_TIMESTAMP_GET_FLAG(hrtc
, RTC_FLAG_TSF
) == RESET
)
802 if(Timeout
!= HAL_MAX_DELAY
)
804 if((Timeout
== 0)||((HAL_GetTick() - tickstart
) > Timeout
))
806 hrtc
->State
= HAL_RTC_STATE_TIMEOUT
;
812 if(__HAL_RTC_TIMESTAMP_GET_FLAG(hrtc
, RTC_FLAG_TSOVF
) != RESET
)
814 /* Clear the TIMESTAMP OverRun Flag */
815 __HAL_RTC_TIMESTAMP_CLEAR_FLAG(hrtc
, RTC_FLAG_TSOVF
);
817 /* Change TIMESTAMP state */
818 hrtc
->State
= HAL_RTC_STATE_ERROR
;
823 /* Change RTC state */
824 hrtc
->State
= HAL_RTC_STATE_READY
;
830 * @brief This function handles Tamper1 Polling.
831 * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains
832 * the configuration information for RTC.
833 * @param Timeout: Timeout duration
836 HAL_StatusTypeDef
HAL_RTCEx_PollForTamper1Event(RTC_HandleTypeDef
*hrtc
, uint32_t Timeout
)
838 uint32_t tickstart
= 0;
841 tickstart
= HAL_GetTick();
843 /* Get the status of the Interrupt */
844 while(__HAL_RTC_TAMPER_GET_FLAG(hrtc
, RTC_FLAG_TAMP1F
)== RESET
)
846 if(Timeout
!= HAL_MAX_DELAY
)
848 if((Timeout
== 0)||((HAL_GetTick() - tickstart
) > Timeout
))
850 hrtc
->State
= HAL_RTC_STATE_TIMEOUT
;
856 /* Clear the Tamper Flag */
857 __HAL_RTC_TAMPER_CLEAR_FLAG(hrtc
,RTC_FLAG_TAMP1F
);
859 /* Change RTC state */
860 hrtc
->State
= HAL_RTC_STATE_READY
;
866 * @brief This function handles Tamper2 Polling.
867 * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains
868 * the configuration information for RTC.
869 * @param Timeout: Timeout duration
872 HAL_StatusTypeDef
HAL_RTCEx_PollForTamper2Event(RTC_HandleTypeDef
*hrtc
, uint32_t Timeout
)
874 uint32_t tickstart
= 0;
877 tickstart
= HAL_GetTick();
879 /* Get the status of the Interrupt */
880 while(__HAL_RTC_TAMPER_GET_FLAG(hrtc
, RTC_FLAG_TAMP2F
) == RESET
)
882 if(Timeout
!= HAL_MAX_DELAY
)
884 if((Timeout
== 0)||((HAL_GetTick() - tickstart
) > Timeout
))
886 hrtc
->State
= HAL_RTC_STATE_TIMEOUT
;
892 /* Clear the Tamper Flag */
893 __HAL_RTC_TAMPER_CLEAR_FLAG(hrtc
,RTC_FLAG_TAMP2F
);
895 /* Change RTC state */
896 hrtc
->State
= HAL_RTC_STATE_READY
;
902 * @brief This function handles Tamper3 Polling.
903 * @param hrtc: RTC handle
904 * @param Timeout: Timeout duration
907 HAL_StatusTypeDef
HAL_RTCEx_PollForTamper3Event(RTC_HandleTypeDef
*hrtc
, uint32_t Timeout
)
909 uint32_t tickstart
= HAL_GetTick();
911 /* Get the status of the Interrupt */
912 while(__HAL_RTC_TAMPER_GET_FLAG(hrtc
, RTC_FLAG_TAMP3F
) == RESET
)
914 if(Timeout
!= HAL_MAX_DELAY
)
916 if((Timeout
== 0)||((HAL_GetTick() - tickstart
) > Timeout
))
918 hrtc
->State
= HAL_RTC_STATE_TIMEOUT
;
924 /* Clear the Tamper Flag */
925 __HAL_RTC_TAMPER_CLEAR_FLAG(hrtc
,RTC_FLAG_TAMP3F
);
927 /* Change RTC state */
928 hrtc
->State
= HAL_RTC_STATE_READY
;
937 /** @defgroup RTCEx_Group2 RTC Wake-up functions
938 * @brief RTC Wake-up functions
941 ===============================================================================
942 ##### RTC Wake-up functions #####
943 ===============================================================================
945 [..] This section provides functions allowing to configure Wake-up feature
952 * @brief Sets wake up timer.
953 * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains
954 * the configuration information for RTC.
955 * @param WakeUpCounter: Wake up counter
956 * @param WakeUpClock: Wake up clock
959 HAL_StatusTypeDef
HAL_RTCEx_SetWakeUpTimer(RTC_HandleTypeDef
*hrtc
, uint32_t WakeUpCounter
, uint32_t WakeUpClock
)
961 uint32_t tickstart
= 0;
963 /* Check the parameters */
964 assert_param(IS_RTC_WAKEUP_CLOCK(WakeUpClock
));
965 assert_param(IS_RTC_WAKEUP_COUNTER(WakeUpCounter
));
970 hrtc
->State
= HAL_RTC_STATE_BUSY
;
972 /* Disable the write protection for RTC registers */
973 __HAL_RTC_WRITEPROTECTION_DISABLE(hrtc
);
975 __HAL_RTC_WAKEUPTIMER_DISABLE(hrtc
);
978 tickstart
= HAL_GetTick();
980 /*Check RTC WUTWF flag is reset only when wake up timer enabled*/
981 if((hrtc
->Instance
->CR
& RTC_CR_WUTE
) != RESET
)
983 /* Wait till RTC WUTWF flag is set and if Time out is reached exit */
984 while(__HAL_RTC_WAKEUPTIMER_GET_FLAG(hrtc
, RTC_FLAG_WUTWF
) == RESET
)
986 if((HAL_GetTick() - tickstart
) > RTC_TIMEOUT_VALUE
)
988 /* Enable the write protection for RTC registers */
989 __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc
);
991 hrtc
->State
= HAL_RTC_STATE_TIMEOUT
;
993 /* Process Unlocked */
1001 /* Clear the Wakeup Timer clock source bits in CR register */
1002 hrtc
->Instance
->CR
&= (uint32_t)~RTC_CR_WUCKSEL
;
1004 /* Configure the clock source */
1005 hrtc
->Instance
->CR
|= (uint32_t)WakeUpClock
;
1007 /* Configure the Wakeup Timer counter */
1008 hrtc
->Instance
->WUTR
= (uint32_t)WakeUpCounter
;
1010 /* Enable the Wakeup Timer */
1011 __HAL_RTC_WAKEUPTIMER_ENABLE(hrtc
);
1013 /* Enable the write protection for RTC registers */
1014 __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc
);
1016 hrtc
->State
= HAL_RTC_STATE_READY
;
1018 /* Process Unlocked */
1025 * @brief Sets wake up timer with interrupt
1026 * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains
1027 * the configuration information for RTC.
1028 * @param WakeUpCounter: Wake up counter
1029 * @param WakeUpClock: Wake up clock
1030 * @retval HAL status
1032 HAL_StatusTypeDef
HAL_RTCEx_SetWakeUpTimer_IT(RTC_HandleTypeDef
*hrtc
, uint32_t WakeUpCounter
, uint32_t WakeUpClock
)
1034 uint32_t tickstart
= 0;
1036 /* Check the parameters */
1037 assert_param(IS_RTC_WAKEUP_CLOCK(WakeUpClock
));
1038 assert_param(IS_RTC_WAKEUP_COUNTER(WakeUpCounter
));
1040 /* Process Locked */
1043 hrtc
->State
= HAL_RTC_STATE_BUSY
;
1045 /* Disable the write protection for RTC registers */
1046 __HAL_RTC_WRITEPROTECTION_DISABLE(hrtc
);
1048 __HAL_RTC_WAKEUPTIMER_DISABLE(hrtc
);
1051 tickstart
= HAL_GetTick();
1053 /*Check RTC WUTWF flag is reset only when wake up timer enabled*/
1054 if((hrtc
->Instance
->CR
& RTC_CR_WUTE
) != RESET
)
1056 /* Wait till RTC WUTWF flag is set and if Time out is reached exit */
1057 while(__HAL_RTC_WAKEUPTIMER_GET_FLAG(hrtc
, RTC_FLAG_WUTWF
) == RESET
)
1059 if((HAL_GetTick() - tickstart
) > RTC_TIMEOUT_VALUE
)
1061 /* Enable the write protection for RTC registers */
1062 __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc
);
1064 hrtc
->State
= HAL_RTC_STATE_TIMEOUT
;
1066 /* Process Unlocked */
1074 /* Configure the Wakeup Timer counter */
1075 hrtc
->Instance
->WUTR
= (uint32_t)WakeUpCounter
;
1077 /* Clear the Wakeup Timer clock source bits in CR register */
1078 hrtc
->Instance
->CR
&= (uint32_t)~RTC_CR_WUCKSEL
;
1080 /* Configure the clock source */
1081 hrtc
->Instance
->CR
|= (uint32_t)WakeUpClock
;
1083 /* RTC WakeUpTimer Interrupt Configuration: EXTI configuration */
1084 __HAL_RTC_WAKEUPTIMER_EXTI_ENABLE_IT();
1086 EXTI
->RTSR
|= RTC_EXTI_LINE_WAKEUPTIMER_EVENT
;
1088 /* Configure the Interrupt in the RTC_CR register */
1089 __HAL_RTC_WAKEUPTIMER_ENABLE_IT(hrtc
,RTC_IT_WUT
);
1091 /* Enable the Wakeup Timer */
1092 __HAL_RTC_WAKEUPTIMER_ENABLE(hrtc
);
1094 /* Enable the write protection for RTC registers */
1095 __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc
);
1097 hrtc
->State
= HAL_RTC_STATE_READY
;
1099 /* Process Unlocked */
1106 * @brief Deactivates wake up timer counter.
1107 * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains
1108 * the configuration information for RTC.
1109 * @retval HAL status
1111 uint32_t HAL_RTCEx_DeactivateWakeUpTimer(RTC_HandleTypeDef
*hrtc
)
1113 uint32_t tickstart
= 0;
1115 /* Process Locked */
1118 hrtc
->State
= HAL_RTC_STATE_BUSY
;
1120 /* Disable the write protection for RTC registers */
1121 __HAL_RTC_WRITEPROTECTION_DISABLE(hrtc
);
1123 /* Disable the Wakeup Timer */
1124 __HAL_RTC_WAKEUPTIMER_DISABLE(hrtc
);
1126 /* In case of interrupt mode is used, the interrupt source must disabled */
1127 __HAL_RTC_WAKEUPTIMER_DISABLE_IT(hrtc
,RTC_IT_WUT
);
1130 tickstart
= HAL_GetTick();
1132 /* Wait till RTC WUTWF flag is set and if Time out is reached exit */
1133 while(__HAL_RTC_WAKEUPTIMER_GET_FLAG(hrtc
, RTC_FLAG_WUTWF
) == RESET
)
1135 if((HAL_GetTick() - tickstart
) > RTC_TIMEOUT_VALUE
)
1137 /* Enable the write protection for RTC registers */
1138 __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc
);
1140 hrtc
->State
= HAL_RTC_STATE_TIMEOUT
;
1142 /* Process Unlocked */
1149 /* Enable the write protection for RTC registers */
1150 __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc
);
1152 hrtc
->State
= HAL_RTC_STATE_READY
;
1154 /* Process Unlocked */
1161 * @brief Gets wake up timer counter.
1162 * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains
1163 * the configuration information for RTC.
1164 * @retval Counter value
1166 uint32_t HAL_RTCEx_GetWakeUpTimer(RTC_HandleTypeDef
*hrtc
)
1168 /* Get the counter value */
1169 return ((uint32_t)(hrtc
->Instance
->WUTR
& RTC_WUTR_WUT
));
1173 * @brief This function handles Wake Up Timer interrupt request.
1174 * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains
1175 * the configuration information for RTC.
1178 void HAL_RTCEx_WakeUpTimerIRQHandler(RTC_HandleTypeDef
*hrtc
)
1180 if(__HAL_RTC_WAKEUPTIMER_GET_IT(hrtc
, RTC_IT_WUT
))
1182 /* Get the status of the Interrupt */
1183 if((uint32_t)(hrtc
->Instance
->CR
& RTC_IT_WUT
) != (uint32_t)RESET
)
1185 /* WAKEUPTIMER callback */
1186 HAL_RTCEx_WakeUpTimerEventCallback(hrtc
);
1188 /* Clear the WAKEUPTIMER interrupt pending bit */
1189 __HAL_RTC_WAKEUPTIMER_CLEAR_FLAG(hrtc
, RTC_FLAG_WUTF
);
1193 /* Clear the EXTI's line Flag for RTC WakeUpTimer */
1194 __HAL_RTC_WAKEUPTIMER_EXTI_CLEAR_FLAG();
1196 /* Change RTC state */
1197 hrtc
->State
= HAL_RTC_STATE_READY
;
1201 * @brief Wake Up Timer callback.
1202 * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains
1203 * the configuration information for RTC.
1206 __weak
void HAL_RTCEx_WakeUpTimerEventCallback(RTC_HandleTypeDef
*hrtc
)
1208 /* Prevent unused argument(s) compilation warning */
1211 /* NOTE : This function Should not be modified, when the callback is needed,
1212 the HAL_RTC_WakeUpTimerEventCallback could be implemented in the user file
1217 * @brief This function handles Wake Up Timer Polling.
1218 * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains
1219 * the configuration information for RTC.
1220 * @param Timeout: Timeout duration
1221 * @retval HAL status
1223 HAL_StatusTypeDef
HAL_RTCEx_PollForWakeUpTimerEvent(RTC_HandleTypeDef
*hrtc
, uint32_t Timeout
)
1225 uint32_t tickstart
= 0;
1228 tickstart
= HAL_GetTick();
1230 while(__HAL_RTC_WAKEUPTIMER_GET_FLAG(hrtc
, RTC_FLAG_WUTF
) == RESET
)
1232 if(Timeout
!= HAL_MAX_DELAY
)
1234 if((Timeout
== 0)||((HAL_GetTick() - tickstart
) > Timeout
))
1236 hrtc
->State
= HAL_RTC_STATE_TIMEOUT
;
1243 /* Clear the WAKEUPTIMER Flag */
1244 __HAL_RTC_WAKEUPTIMER_CLEAR_FLAG(hrtc
, RTC_FLAG_WUTF
);
1246 /* Change RTC state */
1247 hrtc
->State
= HAL_RTC_STATE_READY
;
1257 /** @defgroup RTCEx_Group3 Extension Peripheral Control functions
1258 * @brief Extension Peripheral Control functions
1261 ===============================================================================
1262 ##### Extension Peripheral Control functions #####
1263 ===============================================================================
1265 This subsection provides functions allowing to
1266 (+) Write a data in a specified RTC Backup data register
1267 (+) Read a data in a specified RTC Backup data register
1268 (+) Set the Coarse calibration parameters.
1269 (+) Deactivate the Coarse calibration parameters
1270 (+) Set the Smooth calibration parameters.
1271 (+) Configure the Synchronization Shift Control Settings.
1272 (+) Configure the Calibration Pinout (RTC_CALIB) Selection (1Hz or 512Hz).
1273 (+) Deactivate the Calibration Pinout (RTC_CALIB) Selection (1Hz or 512Hz).
1274 (+) Enable the RTC reference clock detection.
1275 (+) Disable the RTC reference clock detection.
1276 (+) Enable the Bypass Shadow feature.
1277 (+) Disable the Bypass Shadow feature.
1284 * @brief Writes a data in a specified RTC Backup data register.
1285 * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains
1286 * the configuration information for RTC.
1287 * @param BackupRegister: RTC Backup data Register number.
1288 * This parameter can be: RTC_BKP_DRx where x can be from 0 to 19 to
1289 * specify the register.
1290 * @param Data: Data to be written in the specified RTC Backup data register.
1293 void HAL_RTCEx_BKUPWrite(RTC_HandleTypeDef
*hrtc
, uint32_t BackupRegister
, uint32_t Data
)
1297 /* Check the parameters */
1298 assert_param(IS_RTC_BKP(BackupRegister
));
1300 tmp
= (uint32_t)&(hrtc
->Instance
->BKP0R
);
1301 tmp
+= (BackupRegister
* 4);
1303 /* Write the specified register */
1304 *(__IO
uint32_t *)tmp
= (uint32_t)Data
;
1308 * @brief Reads data from the specified RTC Backup data Register.
1309 * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains
1310 * the configuration information for RTC.
1311 * @param BackupRegister: RTC Backup data Register number.
1312 * This parameter can be: RTC_BKP_DRx where x can be from 0 to 19 to
1313 * specify the register.
1314 * @retval Read value
1316 uint32_t HAL_RTCEx_BKUPRead(RTC_HandleTypeDef
*hrtc
, uint32_t BackupRegister
)
1320 /* Check the parameters */
1321 assert_param(IS_RTC_BKP(BackupRegister
));
1323 tmp
= (uint32_t)&(hrtc
->Instance
->BKP0R
);
1324 tmp
+= (BackupRegister
* 4);
1326 /* Read the specified register */
1327 return (*(__IO
uint32_t *)tmp
);
1331 * @brief Sets the Smooth calibration parameters.
1332 * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains
1333 * the configuration information for RTC.
1334 * @param SmoothCalibPeriod: Select the Smooth Calibration Period.
1335 * This parameter can be can be one of the following values :
1336 * @arg RTC_SMOOTHCALIB_PERIOD_32SEC: The smooth calibration period is 32s.
1337 * @arg RTC_SMOOTHCALIB_PERIOD_16SEC: The smooth calibration period is 16s.
1338 * @arg RTC_SMOOTHCALIB_PERIOD_8SEC: The smooth calibration period is 8s.
1339 * @param SmoothCalibPlusPulses: Select to Set or reset the CALP bit.
1340 * This parameter can be one of the following values:
1341 * @arg RTC_SMOOTHCALIB_PLUSPULSES_SET: Add one RTCCLK pulses every 2*11 pulses.
1342 * @arg RTC_SMOOTHCALIB_PLUSPULSES_RESET: No RTCCLK pulses are added.
1343 * @param SmouthCalibMinusPulsesValue: Select the value of CALM[8:0] bits.
1344 * This parameter can be one any value from 0 to 0x000001FF.
1345 * @note To deactivate the smooth calibration, the field SmoothCalibPlusPulses
1346 * must be equal to SMOOTHCALIB_PLUSPULSES_RESET and the field
1347 * SmouthCalibMinusPulsesValue must be equal to 0.
1348 * @retval HAL status
1350 HAL_StatusTypeDef
HAL_RTCEx_SetSmoothCalib(RTC_HandleTypeDef
* hrtc
, uint32_t SmoothCalibPeriod
, uint32_t SmoothCalibPlusPulses
, uint32_t SmouthCalibMinusPulsesValue
)
1352 uint32_t tickstart
= 0;
1354 /* Check the parameters */
1355 assert_param(IS_RTC_SMOOTH_CALIB_PERIOD(SmoothCalibPeriod
));
1356 assert_param(IS_RTC_SMOOTH_CALIB_PLUS(SmoothCalibPlusPulses
));
1357 assert_param(IS_RTC_SMOOTH_CALIB_MINUS(SmouthCalibMinusPulsesValue
));
1359 /* Process Locked */
1362 hrtc
->State
= HAL_RTC_STATE_BUSY
;
1364 /* Disable the write protection for RTC registers */
1365 __HAL_RTC_WRITEPROTECTION_DISABLE(hrtc
);
1367 /* check if a calibration is pending*/
1368 if((hrtc
->Instance
->ISR
& RTC_ISR_RECALPF
) != RESET
)
1371 tickstart
= HAL_GetTick();
1373 /* check if a calibration is pending*/
1374 while((hrtc
->Instance
->ISR
& RTC_ISR_RECALPF
) != RESET
)
1376 if((HAL_GetTick() - tickstart
) > RTC_TIMEOUT_VALUE
)
1378 /* Enable the write protection for RTC registers */
1379 __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc
);
1381 /* Change RTC state */
1382 hrtc
->State
= HAL_RTC_STATE_TIMEOUT
;
1384 /* Process Unlocked */
1392 /* Configure the Smooth calibration settings */
1393 hrtc
->Instance
->CALR
= (uint32_t)((uint32_t)SmoothCalibPeriod
| (uint32_t)SmoothCalibPlusPulses
| (uint32_t)SmouthCalibMinusPulsesValue
);
1395 /* Enable the write protection for RTC registers */
1396 __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc
);
1398 /* Change RTC state */
1399 hrtc
->State
= HAL_RTC_STATE_READY
;
1401 /* Process Unlocked */
1408 * @brief Configures the Synchronization Shift Control Settings.
1409 * @note When REFCKON is set, firmware must not write to Shift control register.
1410 * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains
1411 * the configuration information for RTC.
1412 * @param ShiftAdd1S: Select to add or not 1 second to the time calendar.
1413 * This parameter can be one of the following values :
1414 * @arg RTC_SHIFTADD1S_SET: Add one second to the clock calendar.
1415 * @arg RTC_SHIFTADD1S_RESET: No effect.
1416 * @param ShiftSubFS: Select the number of Second Fractions to substitute.
1417 * This parameter can be one any value from 0 to 0x7FFF.
1418 * @retval HAL status
1420 HAL_StatusTypeDef
HAL_RTCEx_SetSynchroShift(RTC_HandleTypeDef
* hrtc
, uint32_t ShiftAdd1S
, uint32_t ShiftSubFS
)
1422 uint32_t tickstart
= 0;
1424 /* Check the parameters */
1425 assert_param(IS_RTC_SHIFT_ADD1S(ShiftAdd1S
));
1426 assert_param(IS_RTC_SHIFT_SUBFS(ShiftSubFS
));
1428 /* Process Locked */
1431 hrtc
->State
= HAL_RTC_STATE_BUSY
;
1433 /* Disable the write protection for RTC registers */
1434 __HAL_RTC_WRITEPROTECTION_DISABLE(hrtc
);
1437 tickstart
= HAL_GetTick();
1439 /* Wait until the shift is completed*/
1440 while((hrtc
->Instance
->ISR
& RTC_ISR_SHPF
) != RESET
)
1442 if((HAL_GetTick() - tickstart
) > RTC_TIMEOUT_VALUE
)
1444 /* Enable the write protection for RTC registers */
1445 __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc
);
1447 hrtc
->State
= HAL_RTC_STATE_TIMEOUT
;
1449 /* Process Unlocked */
1456 /* Check if the reference clock detection is disabled */
1457 if((hrtc
->Instance
->CR
& RTC_CR_REFCKON
) == RESET
)
1459 /* Configure the Shift settings */
1460 hrtc
->Instance
->SHIFTR
= (uint32_t)(uint32_t)(ShiftSubFS
) | (uint32_t)(ShiftAdd1S
);
1462 /* If RTC_CR_BYPSHAD bit = 0, wait for synchro else this check is not needed */
1463 if((hrtc
->Instance
->CR
& RTC_CR_BYPSHAD
) == RESET
)
1465 if(HAL_RTC_WaitForSynchro(hrtc
) != HAL_OK
)
1467 /* Enable the write protection for RTC registers */
1468 __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc
);
1470 hrtc
->State
= HAL_RTC_STATE_ERROR
;
1472 /* Process Unlocked */
1481 /* Enable the write protection for RTC registers */
1482 __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc
);
1484 /* Change RTC state */
1485 hrtc
->State
= HAL_RTC_STATE_ERROR
;
1487 /* Process Unlocked */
1493 /* Enable the write protection for RTC registers */
1494 __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc
);
1496 /* Change RTC state */
1497 hrtc
->State
= HAL_RTC_STATE_READY
;
1499 /* Process Unlocked */
1506 * @brief Configures the Calibration Pinout (RTC_CALIB) Selection (1Hz or 512Hz).
1507 * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains
1508 * the configuration information for RTC.
1509 * @param CalibOutput: Select the Calibration output Selection .
1510 * This parameter can be one of the following values:
1511 * @arg RTC_CALIBOUTPUT_512HZ: A signal has a regular waveform at 512Hz.
1512 * @arg RTC_CALIBOUTPUT_1HZ: A signal has a regular waveform at 1Hz.
1513 * @retval HAL status
1515 HAL_StatusTypeDef
HAL_RTCEx_SetCalibrationOutPut(RTC_HandleTypeDef
* hrtc
, uint32_t CalibOutput
)
1517 /* Check the parameters */
1518 assert_param(IS_RTC_CALIB_OUTPUT(CalibOutput
));
1520 /* Process Locked */
1523 hrtc
->State
= HAL_RTC_STATE_BUSY
;
1525 /* Disable the write protection for RTC registers */
1526 __HAL_RTC_WRITEPROTECTION_DISABLE(hrtc
);
1528 /* Clear flags before config */
1529 hrtc
->Instance
->CR
&= (uint32_t)~RTC_CR_COSEL
;
1531 /* Configure the RTC_CR register */
1532 hrtc
->Instance
->CR
|= (uint32_t)CalibOutput
;
1534 __HAL_RTC_CALIBRATION_OUTPUT_ENABLE(hrtc
);
1536 /* Enable the write protection for RTC registers */
1537 __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc
);
1539 /* Change RTC state */
1540 hrtc
->State
= HAL_RTC_STATE_READY
;
1542 /* Process Unlocked */
1549 * @brief Deactivates the Calibration Pinout (RTC_CALIB) Selection (1Hz or 512Hz).
1550 * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains
1551 * the configuration information for RTC.
1552 * @retval HAL status
1554 HAL_StatusTypeDef
HAL_RTCEx_DeactivateCalibrationOutPut(RTC_HandleTypeDef
* hrtc
)
1556 /* Process Locked */
1559 hrtc
->State
= HAL_RTC_STATE_BUSY
;
1561 /* Disable the write protection for RTC registers */
1562 __HAL_RTC_WRITEPROTECTION_DISABLE(hrtc
);
1564 __HAL_RTC_CALIBRATION_OUTPUT_DISABLE(hrtc
);
1566 /* Enable the write protection for RTC registers */
1567 __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc
);
1569 /* Change RTC state */
1570 hrtc
->State
= HAL_RTC_STATE_READY
;
1572 /* Process Unlocked */
1579 * @brief Enables the RTC reference clock detection.
1580 * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains
1581 * the configuration information for RTC.
1582 * @retval HAL status
1584 HAL_StatusTypeDef
HAL_RTCEx_SetRefClock(RTC_HandleTypeDef
* hrtc
)
1586 /* Process Locked */
1589 hrtc
->State
= HAL_RTC_STATE_BUSY
;
1591 /* Disable the write protection for RTC registers */
1592 __HAL_RTC_WRITEPROTECTION_DISABLE(hrtc
);
1594 /* Set Initialization mode */
1595 if(RTC_EnterInitMode(hrtc
) != HAL_OK
)
1597 /* Enable the write protection for RTC registers */
1598 __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc
);
1601 hrtc
->State
= HAL_RTC_STATE_ERROR
;
1603 /* Process Unlocked */
1610 __HAL_RTC_CLOCKREF_DETECTION_ENABLE(hrtc
);
1612 /* Exit Initialization mode */
1613 hrtc
->Instance
->ISR
&= (uint32_t)~RTC_ISR_INIT
;
1616 /* Enable the write protection for RTC registers */
1617 __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc
);
1619 /* Change RTC state */
1620 hrtc
->State
= HAL_RTC_STATE_READY
;
1622 /* Process Unlocked */
1629 * @brief Disable the RTC reference clock detection.
1630 * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains
1631 * the configuration information for RTC.
1632 * @retval HAL status
1634 HAL_StatusTypeDef
HAL_RTCEx_DeactivateRefClock(RTC_HandleTypeDef
* hrtc
)
1636 /* Process Locked */
1639 hrtc
->State
= HAL_RTC_STATE_BUSY
;
1641 /* Disable the write protection for RTC registers */
1642 __HAL_RTC_WRITEPROTECTION_DISABLE(hrtc
);
1644 /* Set Initialization mode */
1645 if(RTC_EnterInitMode(hrtc
) != HAL_OK
)
1647 /* Enable the write protection for RTC registers */
1648 __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc
);
1651 hrtc
->State
= HAL_RTC_STATE_ERROR
;
1653 /* Process Unlocked */
1660 __HAL_RTC_CLOCKREF_DETECTION_DISABLE(hrtc
);
1662 /* Exit Initialization mode */
1663 hrtc
->Instance
->ISR
&= (uint32_t)~RTC_ISR_INIT
;
1666 /* Enable the write protection for RTC registers */
1667 __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc
);
1669 /* Change RTC state */
1670 hrtc
->State
= HAL_RTC_STATE_READY
;
1672 /* Process Unlocked */
1679 * @brief Enables the Bypass Shadow feature.
1680 * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains
1681 * the configuration information for RTC.
1682 * @note When the Bypass Shadow is enabled the calendar value are taken
1683 * directly from the Calendar counter.
1684 * @retval HAL status
1686 HAL_StatusTypeDef
HAL_RTCEx_EnableBypassShadow(RTC_HandleTypeDef
* hrtc
)
1688 /* Process Locked */
1691 hrtc
->State
= HAL_RTC_STATE_BUSY
;
1693 /* Disable the write protection for RTC registers */
1694 __HAL_RTC_WRITEPROTECTION_DISABLE(hrtc
);
1696 /* Set the BYPSHAD bit */
1697 hrtc
->Instance
->CR
|= (uint8_t)RTC_CR_BYPSHAD
;
1699 /* Enable the write protection for RTC registers */
1700 __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc
);
1702 /* Change RTC state */
1703 hrtc
->State
= HAL_RTC_STATE_READY
;
1705 /* Process Unlocked */
1712 * @brief Disables the Bypass Shadow feature.
1713 * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains
1714 * the configuration information for RTC.
1715 * @note When the Bypass Shadow is enabled the calendar value are taken
1716 * directly from the Calendar counter.
1717 * @retval HAL status
1719 HAL_StatusTypeDef
HAL_RTCEx_DisableBypassShadow(RTC_HandleTypeDef
* hrtc
)
1721 /* Process Locked */
1724 hrtc
->State
= HAL_RTC_STATE_BUSY
;
1726 /* Disable the write protection for RTC registers */
1727 __HAL_RTC_WRITEPROTECTION_DISABLE(hrtc
);
1729 /* Reset the BYPSHAD bit */
1730 hrtc
->Instance
->CR
&= (uint8_t)~RTC_CR_BYPSHAD
;
1732 /* Enable the write protection for RTC registers */
1733 __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc
);
1735 /* Change RTC state */
1736 hrtc
->State
= HAL_RTC_STATE_READY
;
1738 /* Process Unlocked */
1748 /** @defgroup RTCEx_Group4 Extended features functions
1749 * @brief Extended features functions
1752 ===============================================================================
1753 ##### Extended features functions #####
1754 ===============================================================================
1755 [..] This section provides functions allowing to:
1756 (+) RTC Alram B callback
1757 (+) RTC Poll for Alarm B request
1764 * @brief Alarm B callback.
1765 * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains
1766 * the configuration information for RTC.
1769 __weak
void HAL_RTCEx_AlarmBEventCallback(RTC_HandleTypeDef
*hrtc
)
1771 /* Prevent unused argument(s) compilation warning */
1774 /* NOTE : This function Should not be modified, when the callback is needed,
1775 the HAL_RTC_AlarmBEventCallback could be implemented in the user file
1780 * @brief This function handles AlarmB Polling request.
1781 * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains
1782 * the configuration information for RTC.
1783 * @param Timeout: Timeout duration
1784 * @retval HAL status
1786 HAL_StatusTypeDef
HAL_RTCEx_PollForAlarmBEvent(RTC_HandleTypeDef
*hrtc
, uint32_t Timeout
)
1788 uint32_t tickstart
= 0;
1791 tickstart
= HAL_GetTick();
1793 while(__HAL_RTC_ALARM_GET_FLAG(hrtc
, RTC_FLAG_ALRBF
) == RESET
)
1795 if(Timeout
!= HAL_MAX_DELAY
)
1797 if((Timeout
== 0)||((HAL_GetTick() - tickstart
) > Timeout
))
1799 hrtc
->State
= HAL_RTC_STATE_TIMEOUT
;
1805 /* Clear the Alarm Flag */
1806 __HAL_RTC_ALARM_CLEAR_FLAG(hrtc
, RTC_FLAG_ALRBF
);
1808 /* Change RTC state */
1809 hrtc
->State
= HAL_RTC_STATE_READY
;
1822 #endif /* HAL_RTC_MODULE_ENABLED */
1831 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/