2 ******************************************************************************
3 * @file stm32f3xx_hal_rtc_ex.c
4 * @author MCD Application Team
7 * @brief Extended RTC HAL module driver.
8 * This file provides firmware functions to manage the following
9 * functionalities of the Real Time Clock (RTC) Extended peripheral:
10 * + RTC Time Stamp functions
11 * + RTC Tamper functions
12 * + RTC Wake-up functions
13 * + Extended Control functions
14 * + Extended 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_RTCEx_SetWakeUpTimer()
29 function. You can also configure the RTC Wakeup timer with interrupt mode
30 using the HAL_RTCEx_SetWakeUpTimer_IT() function.
31 (+) To read the RTC WakeUp Counter register, use the HAL_RTCEx_GetWakeUpTimer()
34 *** TimeStamp configuration ***
35 ===============================
37 (+) Configure the RTC_AFx trigger and enables the RTC TimeStamp using the
38 HAL_RTCEx_SetTimeStamp() function. You can also configure the RTC TimeStamp with
39 interrupt mode using the HAL_RTCEx_SetTimeStamp_IT() function.
40 (+) To read the RTC TimeStamp Time and Date register, use the HAL_RTCEx_GetTimeStamp()
42 (+) The TIMESTAMP alternate function is mapped to RTC_AF1 (PC13).
44 *** Tamper configuration ***
45 ============================
47 (+) Enable the RTC Tamper and Configure the Tamper filter count, trigger Edge
48 or Level according to the Tamper filter (if equal to 0 Edge else Level)
49 value, sampling frequency, precharge or discharge and Pull-UP using the
50 HAL_RTCEx_SetTamper() function. You can configure RTC Tamper with interrupt
51 mode using HAL_RTCEx_SetTamper_IT() function.
52 (+) The TAMPER1 alternate function is mapped to RTC_AF1 (PC13).
54 *** Backup Data Registers configuration ***
55 ===========================================
57 (+) To write to the RTC Backup Data registers, use the HAL_RTCEx_BKUPWrite()
59 (+) To read the RTC Backup Data registers, use the HAL_RTCEx_BKUPRead()
63 ******************************************************************************
66 * <h2><center>© COPYRIGHT(c) 2014 STMicroelectronics</center></h2>
68 * Redistribution and use in source and binary forms, with or without modification,
69 * are permitted provided that the following conditions are met:
70 * 1. Redistributions of source code must retain the above copyright notice,
71 * this list of conditions and the following disclaimer.
72 * 2. Redistributions in binary form must reproduce the above copyright notice,
73 * this list of conditions and the following disclaimer in the documentation
74 * and/or other materials provided with the distribution.
75 * 3. Neither the name of STMicroelectronics nor the names of its contributors
76 * may be used to endorse or promote products derived from this software
77 * without specific prior written permission.
79 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
80 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
81 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
82 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
83 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
84 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
85 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
86 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
87 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
88 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
90 ******************************************************************************
93 /* Includes ------------------------------------------------------------------*/
94 #include "stm32f3xx_hal.h"
96 /** @addtogroup STM32F3xx_HAL_Driver
100 /** @defgroup RTCEx RTC Extended HAL module driver
101 * @brief RTC Extended HAL module driver
105 #ifdef HAL_RTC_MODULE_ENABLED
107 /* Private typedef -----------------------------------------------------------*/
108 /* Private define ------------------------------------------------------------*/
109 /* Private macro -------------------------------------------------------------*/
110 /* Private variables ---------------------------------------------------------*/
111 /* Private function prototypes -----------------------------------------------*/
112 /* Exported functions ---------------------------------------------------------*/
114 /** @defgroup RTCEx_Exported_Functions RTC Extended Exported Functions
119 /** @defgroup RTCEx_Exported_Functions_Group1 RTC TimeStamp and Tamper functions
120 * @brief RTC TimeStamp and Tamper functions
123 ===============================================================================
124 ##### RTC TimeStamp and Tamper functions #####
125 ===============================================================================
127 [..] This section provide functions allowing to configure TimeStamp feature
134 * @brief Sets TimeStamp.
135 * @note This API must be called before enabling the TimeStamp feature.
136 * @param hrtc: RTC handle
137 * @param TimeStampEdge: Specifies the pin edge on which the TimeStamp is
139 * This parameter can be one of the following:
140 * @arg TimeStampEdge_Rising: the Time stamp event occurs on the
141 * rising edge of the related pin.
142 * @arg TimeStampEdge_Falling: the Time stamp event occurs on the
143 * falling edge of the related pin.
144 * @param RTC_TimeStampPin: specifies the RTC TimeStamp Pin.
145 * This parameter can be one of the following values:
146 * @arg RTC_TIMESTAMPPIN_PC13: PC13 is selected as RTC TimeStamp Pin.
149 HAL_StatusTypeDef HAL_RTCEx_SetTimeStamp(RTC_HandleTypeDef *hrtc, uint32_t TimeStampEdge, uint32_t RTC_TimeStampPin)
153 /* Check the parameters */
154 assert_param(IS_TIMESTAMP_EDGE(TimeStampEdge));
155 assert_param(IS_RTC_TIMESTAMP_PIN(RTC_TimeStampPin));
160 hrtc->State = HAL_RTC_STATE_BUSY;
162 /* Get the RTC_CR register and clear the bits to be configured */
163 tmpreg = (uint32_t)(hrtc->Instance->CR & (uint32_t)~(RTC_CR_TSEDGE | RTC_CR_TSE));
165 tmpreg|= TimeStampEdge;
167 /* Disable the write protection for RTC registers */
168 __HAL_RTC_WRITEPROTECTION_DISABLE(hrtc);
170 /* Configure the Time Stamp TSEDGE and Enable bits */
171 hrtc->Instance->CR = (uint32_t)tmpreg;
173 __HAL_RTC_TIMESTAMP_ENABLE(hrtc);
175 /* Enable the write protection for RTC registers */
176 __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc);
178 /* Change RTC state */
179 hrtc->State = HAL_RTC_STATE_READY;
181 /* Process Unlocked */
188 * @brief Sets TimeStamp with Interrupt.
189 * @param hrtc: RTC handle
190 * @note This API must be called before enabling the TimeStamp feature.
191 * @param TimeStampEdge: Specifies the pin edge on which the TimeStamp is
193 * This parameter can be one of the following:
194 * @arg TimeStampEdge_Rising: the Time stamp event occurs on the
195 * rising edge of the related pin.
196 * @arg TimeStampEdge_Falling: the Time stamp event occurs on the
197 * falling edge of the related pin.
198 * @param RTC_TimeStampPin: Specifies the RTC TimeStamp Pin.
199 * This parameter can be one of the following values:
200 * @arg RTC_TIMESTAMPPIN_PC13: PC13 is selected as RTC TimeStamp Pin.
203 HAL_StatusTypeDef HAL_RTCEx_SetTimeStamp_IT(RTC_HandleTypeDef *hrtc, uint32_t TimeStampEdge, uint32_t RTC_TimeStampPin)
207 /* Check the parameters */
208 assert_param(IS_TIMESTAMP_EDGE(TimeStampEdge));
209 assert_param(IS_RTC_TIMESTAMP_PIN(RTC_TimeStampPin));
214 hrtc->State = HAL_RTC_STATE_BUSY;
216 /* Get the RTC_CR register and clear the bits to be configured */
217 tmpreg = (uint32_t)(hrtc->Instance->CR & (uint32_t)~(RTC_CR_TSEDGE | RTC_CR_TSE));
219 tmpreg |= TimeStampEdge;
221 /* Disable the write protection for RTC registers */
222 __HAL_RTC_WRITEPROTECTION_DISABLE(hrtc);
224 /* Configure the Time Stamp TSEDGE and Enable bits */
225 hrtc->Instance->CR = (uint32_t)tmpreg;
227 __HAL_RTC_TIMESTAMP_ENABLE(hrtc);
229 /* Enable IT timestamp */
230 __HAL_RTC_TIMESTAMP_ENABLE_IT(hrtc,RTC_IT_TS);
232 /* RTC timestamp Interrupt Configuration: EXTI configuration */
233 __HAL_RTC_ENABLE_IT(RTC_EXTI_LINE_TAMPER_TIMESTAMP_EVENT);
235 EXTI->RTSR |= RTC_EXTI_LINE_TAMPER_TIMESTAMP_EVENT;
237 /* Enable the write protection for RTC registers */
238 __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc);
240 hrtc->State = HAL_RTC_STATE_READY;
242 /* Process Unlocked */
249 * @brief Deactivates TimeStamp.
250 * @param hrtc: RTC handle
253 HAL_StatusTypeDef HAL_RTCEx_DeactivateTimeStamp(RTC_HandleTypeDef *hrtc)
260 hrtc->State = HAL_RTC_STATE_BUSY;
262 /* Disable the write protection for RTC registers */
263 __HAL_RTC_WRITEPROTECTION_DISABLE(hrtc);
265 /* In case of interrupt mode is used, the interrupt source must disabled */
266 __HAL_RTC_TIMESTAMP_DISABLE_IT(hrtc, RTC_IT_TS);
268 /* Get the RTC_CR register and clear the bits to be configured */
269 tmpreg = (uint32_t)(hrtc->Instance->CR & (uint32_t)~(RTC_CR_TSEDGE | RTC_CR_TSE));
271 /* Configure the Time Stamp TSEDGE and Enable bits */
272 hrtc->Instance->CR = (uint32_t)tmpreg;
274 /* Enable the write protection for RTC registers */
275 __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc);
277 hrtc->State = HAL_RTC_STATE_READY;
279 /* Process Unlocked */
286 * @brief Gets the RTC TimeStamp value.
287 * @param hrtc: RTC handle
288 * @param sTimeStamp: Pointer to Time structure
289 * @param sTimeStampDate: Pointer to Date structure
290 * @param Format: specifies the format of the entered parameters.
291 * This parameter can be one of the following values:
292 * @arg Format_BIN: Binary data format
293 * @arg Format_BCD: BCD data format
296 HAL_StatusTypeDef HAL_RTCEx_GetTimeStamp(RTC_HandleTypeDef *hrtc, RTC_TimeTypeDef* sTimeStamp, RTC_DateTypeDef* sTimeStampDate, uint32_t Format)
298 uint32_t tmptime = 0, tmpdate = 0;
300 /* Check the parameters */
301 assert_param(IS_RTC_FORMAT(Format));
303 /* Get the TimeStamp time and date registers values */
304 tmptime = (uint32_t)(hrtc->Instance->TSTR & RTC_TR_RESERVED_MASK);
305 tmpdate = (uint32_t)(hrtc->Instance->TSDR & RTC_DR_RESERVED_MASK);
307 /* Fill the Time structure fields with the read parameters */
308 sTimeStamp->Hours = (uint8_t)((tmptime & (RTC_TR_HT | RTC_TR_HU)) >> 16);
309 sTimeStamp->Minutes = (uint8_t)((tmptime & (RTC_TR_MNT | RTC_TR_MNU)) >> 8);
310 sTimeStamp->Seconds = (uint8_t)(tmptime & (RTC_TR_ST | RTC_TR_SU));
311 sTimeStamp->TimeFormat = (uint8_t)((tmptime & (RTC_TR_PM)) >> 16);
312 sTimeStamp->SubSeconds = (uint32_t) hrtc->Instance->TSSSR;
314 /* Fill the Date structure fields with the read parameters */
315 sTimeStampDate->Year = 0;
316 sTimeStampDate->Month = (uint8_t)((tmpdate & (RTC_DR_MT | RTC_DR_MU)) >> 8);
317 sTimeStampDate->Date = (uint8_t)(tmpdate & (RTC_DR_DT | RTC_DR_DU));
318 sTimeStampDate->WeekDay = (uint8_t)((tmpdate & (RTC_DR_WDU)) >> 13);
320 /* Check the input parameters format */
321 if(Format == FORMAT_BIN)
323 /* Convert the TimeStamp structure parameters to Binary format */
324 sTimeStamp->Hours = (uint8_t)RTC_Bcd2ToByte(sTimeStamp->Hours);
325 sTimeStamp->Minutes = (uint8_t)RTC_Bcd2ToByte(sTimeStamp->Minutes);
326 sTimeStamp->Seconds = (uint8_t)RTC_Bcd2ToByte(sTimeStamp->Seconds);
328 /* Convert the DateTimeStamp structure parameters to Binary format */
329 sTimeStampDate->Month = (uint8_t)RTC_Bcd2ToByte(sTimeStampDate->Month);
330 sTimeStampDate->Date = (uint8_t)RTC_Bcd2ToByte(sTimeStampDate->Date);
331 sTimeStampDate->WeekDay = (uint8_t)RTC_Bcd2ToByte(sTimeStampDate->WeekDay);
334 /* Clear the TIMESTAMP Flag */
335 __HAL_RTC_TIMESTAMP_CLEAR_FLAG(hrtc, RTC_FLAG_TSF);
342 * @note By calling this API we disable the tamper interrupt for all tampers.
343 * @param hrtc: RTC handle
344 * @param sTamper: Pointer to Tamper Structure.
347 HAL_StatusTypeDef HAL_RTCEx_SetTamper(RTC_HandleTypeDef *hrtc, RTC_TamperTypeDef* sTamper)
351 /* Check the parameters */
352 assert_param(IS_TAMPER(sTamper->Tamper));
353 assert_param(IS_TAMPER_TRIGGER(sTamper->Trigger));
354 assert_param(IS_TAMPER_FILTER(sTamper->Filter));
355 assert_param(IS_TAMPER_SAMPLING_FREQ(sTamper->SamplingFrequency));
356 assert_param(IS_TAMPER_PRECHARGE_DURATION(sTamper->PrechargeDuration));
357 assert_param(IS_TAMPER_PULLUP_STATE(sTamper->TamperPullUp));
358 assert_param(IS_TAMPER_TIMESTAMPONTAMPER_DETECTION(sTamper->TimeStampOnTamperDetection));
363 hrtc->State = HAL_RTC_STATE_BUSY;
365 if(sTamper->Trigger != RTC_TAMPERTRIGGER_RISINGEDGE)
367 sTamper->Trigger = (uint32_t)(sTamper->Tamper << 1);
370 tmpreg = ((uint32_t)sTamper->Tamper | (uint32_t)sTamper->Trigger | (uint32_t)sTamper->Filter |\
371 (uint32_t)sTamper->SamplingFrequency | (uint32_t)sTamper->PrechargeDuration |\
372 (uint32_t)sTamper->TamperPullUp | sTamper->TimeStampOnTamperDetection);
374 hrtc->Instance->TAFCR &= (uint32_t)~((uint32_t)sTamper->Tamper | (uint32_t)(sTamper->Tamper << 1) | (uint32_t)RTC_TAFCR_TAMPTS |\
375 (uint32_t)RTC_TAFCR_TAMPFREQ | (uint32_t)RTC_TAFCR_TAMPFLT | (uint32_t)RTC_TAFCR_TAMPPRCH |\
376 (uint32_t)RTC_TAFCR_TAMPPUDIS | (uint32_t)RTC_TAFCR_TAMPIE);
378 hrtc->Instance->TAFCR |= tmpreg;
380 hrtc->State = HAL_RTC_STATE_READY;
382 /* Process Unlocked */
389 * @brief Sets Tamper with interrupt.
390 * @note By calling this API we force the tamper interrupt for all tampers.
391 * @param hrtc: RTC handle
392 * @param sTamper: Pointer to RTC Tamper.
395 HAL_StatusTypeDef HAL_RTCEx_SetTamper_IT(RTC_HandleTypeDef *hrtc, RTC_TamperTypeDef* sTamper)
399 /* Check the parameters */
400 assert_param(IS_TAMPER(sTamper->Tamper));
401 assert_param(IS_TAMPER_TRIGGER(sTamper->Trigger));
402 assert_param(IS_TAMPER_FILTER(sTamper->Filter));
403 assert_param(IS_TAMPER_SAMPLING_FREQ(sTamper->SamplingFrequency));
404 assert_param(IS_TAMPER_PRECHARGE_DURATION(sTamper->PrechargeDuration));
405 assert_param(IS_TAMPER_PULLUP_STATE(sTamper->TamperPullUp));
406 assert_param(IS_TAMPER_TIMESTAMPONTAMPER_DETECTION(sTamper->TimeStampOnTamperDetection));
411 hrtc->State = HAL_RTC_STATE_BUSY;
413 /* Configure the tamper trigger */
414 if(sTamper->Trigger != RTC_TAMPERTRIGGER_RISINGEDGE)
416 sTamper->Trigger = (uint32_t) (sTamper->Tamper<<1);
419 tmpreg = ((uint32_t)sTamper->Tamper | (uint32_t)sTamper->Trigger | (uint32_t)sTamper->Filter |\
420 (uint32_t)sTamper->SamplingFrequency | (uint32_t)sTamper->PrechargeDuration |\
421 (uint32_t)sTamper->TamperPullUp | sTamper->TimeStampOnTamperDetection);
423 hrtc->Instance->TAFCR &= (uint32_t)~((uint32_t)sTamper->Tamper | (uint32_t)(sTamper->Tamper << 1) | (uint32_t)RTC_TAFCR_TAMPTS |\
424 (uint32_t)RTC_TAFCR_TAMPFREQ | (uint32_t)RTC_TAFCR_TAMPFLT | (uint32_t)RTC_TAFCR_TAMPPRCH |\
425 (uint32_t)RTC_TAFCR_TAMPPUDIS);
427 hrtc->Instance->TAFCR |= tmpreg;
429 /* Configure the Tamper Interrupt in the RTC_TAFCR */
430 hrtc->Instance->TAFCR |= (uint32_t)RTC_TAFCR_TAMPIE;
432 /* RTC Tamper Interrupt Configuration: EXTI configuration */
433 __HAL_RTC_ENABLE_IT(RTC_EXTI_LINE_TAMPER_TIMESTAMP_EVENT);
435 EXTI->RTSR |= RTC_EXTI_LINE_TAMPER_TIMESTAMP_EVENT;
437 hrtc->State = HAL_RTC_STATE_READY;
439 /* Process Unlocked */
446 * @brief Deactivates Tamper.
447 * @param hrtc: RTC handle
448 * @param Tamper: Selected tamper pin.
449 * This parameter can be any combination of RTC_TAMPER_1, RTC_TAMPER_2 and RTC_TAMPER_3.
452 HAL_StatusTypeDef HAL_RTCEx_DeactivateTamper(RTC_HandleTypeDef *hrtc, uint32_t Tamper)
454 assert_param(IS_TAMPER(Tamper));
459 hrtc->State = HAL_RTC_STATE_BUSY;
461 /* Disable the selected Tamper pin */
462 hrtc->Instance->TAFCR &= (uint32_t)~Tamper;
464 hrtc->State = HAL_RTC_STATE_READY;
466 /* Process Unlocked */
473 * @brief This function handles TimeStamp interrupt request.
474 * @param hrtc: RTC handle
477 void HAL_RTCEx_TamperTimeStampIRQHandler(RTC_HandleTypeDef *hrtc)
479 if(__HAL_RTC_TIMESTAMP_GET_IT(hrtc, RTC_IT_TS))
481 /* Get the status of the Interrupt */
482 if((uint32_t)(hrtc->Instance->CR & RTC_IT_TS) != (uint32_t)RESET)
484 /* TIMESTAMP callback */
485 HAL_RTCEx_TimeStampEventCallback(hrtc);
487 /* Clear the TIMESTAMP interrupt pending bit */
488 __HAL_RTC_TIMESTAMP_CLEAR_FLAG(hrtc,RTC_FLAG_TSF);
492 /* Get the status of the Interrupt */
493 if(__HAL_RTC_TAMPER_GET_IT(hrtc,RTC_IT_TAMP1))
495 /* Get the TAMPER Interrupt enable bit and pending bit */
496 if(((hrtc->Instance->TAFCR & (RTC_TAFCR_TAMPIE))) != (uint32_t)RESET)
498 /* Tamper callback */
499 HAL_RTCEx_Tamper1EventCallback(hrtc);
501 /* Clear the Tamper interrupt pending bit */
502 __HAL_RTC_TAMPER_CLEAR_FLAG(hrtc,RTC_FLAG_TAMP1F);
506 /* Get the status of the Interrupt */
507 if(__HAL_RTC_TAMPER_GET_IT(hrtc, RTC_IT_TAMP2))
509 /* Get the TAMPER Interrupt enable bit and pending bit */
510 if(((hrtc->Instance->TAFCR & RTC_TAFCR_TAMPIE)) != (uint32_t)RESET)
512 /* Tamper callback */
513 HAL_RTCEx_Tamper2EventCallback(hrtc);
515 /* Clear the Tamper interrupt pending bit */
516 __HAL_RTC_TAMPER_CLEAR_FLAG(hrtc, RTC_FLAG_TAMP2F);
520 /* Get the status of the Interrupt */
521 if(__HAL_RTC_TAMPER_GET_IT(hrtc, RTC_IT_TAMP3))
523 /* Get the TAMPER Interrupt enable bit and pending bit */
524 if(((hrtc->Instance->TAFCR & RTC_TAFCR_TAMPIE)) != (uint32_t)RESET)
526 /* Tamper callback */
527 HAL_RTCEx_Tamper3EventCallback(hrtc);
529 /* Clear the Tamper interrupt pending bit */
530 __HAL_RTC_TAMPER_CLEAR_FLAG(hrtc, RTC_FLAG_TAMP3F);
534 /* Clear the EXTI's Flag for RTC TimeStamp and Tamper */
535 __HAL_RTC_CLEAR_FLAG(RTC_EXTI_LINE_TAMPER_TIMESTAMP_EVENT);
537 /* Change RTC state */
538 hrtc->State = HAL_RTC_STATE_READY;
542 * @brief TimeStamp callback.
543 * @param hrtc: RTC handle
546 __weak void HAL_RTCEx_TimeStampEventCallback(RTC_HandleTypeDef *hrtc)
548 /* NOTE : This function Should not be modified, when the callback is needed,
549 the HAL_RTCEx_TimeStampEventCallback could be implemented in the user file
554 * @brief Tamper 1 callback.
555 * @param hrtc: RTC handle
558 __weak void HAL_RTCEx_Tamper1EventCallback(RTC_HandleTypeDef *hrtc)
560 /* NOTE : This function Should not be modified, when the callback is needed,
561 the HAL_RTCEx_Tamper1EventCallback could be implemented in the user file
566 * @brief Tamper 2 callback.
567 * @param hrtc: RTC handle
570 __weak void HAL_RTCEx_Tamper2EventCallback(RTC_HandleTypeDef *hrtc)
572 /* NOTE : This function Should not be modified, when the callback is needed,
573 the HAL_RTCEx_Tamper2EventCallback could be implemented in the user file
578 * @brief Tamper 3 callback.
579 * @param hrtc: RTC handle
582 __weak void HAL_RTCEx_Tamper3EventCallback(RTC_HandleTypeDef *hrtc)
584 /* NOTE : This function Should not be modified, when the callback is needed,
585 the HAL_RTCEx_Tamper3EventCallback could be implemented in the user file
590 * @brief This function handles TimeStamp polling request.
591 * @param hrtc: RTC handle
592 * @param Timeout: Timeout duration
595 HAL_StatusTypeDef HAL_RTCEx_PollForTimeStampEvent(RTC_HandleTypeDef *hrtc, uint32_t Timeout)
597 uint32_t tickstart = HAL_GetTick();
599 while(__HAL_RTC_TIMESTAMP_GET_FLAG(hrtc, RTC_FLAG_TSF) == RESET)
601 if(__HAL_RTC_TIMESTAMP_GET_FLAG(hrtc, RTC_FLAG_TSOVF) != RESET)
603 /* Clear the TIMESTAMP OverRun Flag */
604 __HAL_RTC_TIMESTAMP_CLEAR_FLAG(hrtc, RTC_FLAG_TSOVF);
606 /* Change TIMESTAMP state */
607 hrtc->State = HAL_RTC_STATE_ERROR;
612 if(Timeout != HAL_MAX_DELAY)
614 if((Timeout == 0) || ((HAL_GetTick()-tickstart) > Timeout))
616 hrtc->State = HAL_RTC_STATE_TIMEOUT;
622 /* Change RTC state */
623 hrtc->State = HAL_RTC_STATE_READY;
629 * @brief This function handles Tamper1 Polling.
630 * @param hrtc: RTC handle
631 * @param Timeout: Timeout duration
634 HAL_StatusTypeDef HAL_RTCEx_PollForTamper1Event(RTC_HandleTypeDef *hrtc, uint32_t Timeout)
636 uint32_t tickstart = HAL_GetTick();
638 /* Get the status of the Interrupt */
639 while(__HAL_RTC_TAMPER_GET_FLAG(hrtc,RTC_FLAG_TAMP1F)== RESET)
641 if(Timeout != HAL_MAX_DELAY)
643 if((Timeout == 0) || ((HAL_GetTick()-tickstart) > Timeout))
645 hrtc->State = HAL_RTC_STATE_TIMEOUT;
651 /* Clear the Tamper Flag */
652 __HAL_RTC_TAMPER_CLEAR_FLAG(hrtc,RTC_FLAG_TAMP1F);
654 /* Change RTC state */
655 hrtc->State = HAL_RTC_STATE_READY;
661 * @brief This function handles Tamper2 Polling.
662 * @param hrtc: RTC handle
663 * @param Timeout: Timeout duration
666 HAL_StatusTypeDef HAL_RTCEx_PollForTamper2Event(RTC_HandleTypeDef *hrtc, uint32_t Timeout)
668 uint32_t tickstart = HAL_GetTick();
670 /* Get the status of the Interrupt */
671 while(__HAL_RTC_TAMPER_GET_FLAG(hrtc,RTC_FLAG_TAMP2F) == RESET)
673 if(Timeout != HAL_MAX_DELAY)
675 if((Timeout == 0) || ((HAL_GetTick()-tickstart) > Timeout))
677 hrtc->State = HAL_RTC_STATE_TIMEOUT;
683 /* Clear the Tamper Flag */
684 __HAL_RTC_TAMPER_CLEAR_FLAG(hrtc,RTC_FLAG_TAMP2F);
686 /* Change RTC state */
687 hrtc->State = HAL_RTC_STATE_READY;
693 * @brief This function handles Tamper3 Polling.
694 * @param hrtc: RTC handle
695 * @param Timeout: Timeout duration
698 HAL_StatusTypeDef HAL_RTCEx_PollForTamper3Event(RTC_HandleTypeDef *hrtc, uint32_t Timeout)
700 uint32_t tickstart = HAL_GetTick();
702 /* Get the status of the Interrupt */
703 while(__HAL_RTC_TAMPER_GET_FLAG(hrtc,RTC_FLAG_TAMP3F) == RESET)
705 if(Timeout != HAL_MAX_DELAY)
707 if((Timeout == 0) || ((HAL_GetTick()-tickstart) > Timeout))
709 hrtc->State = HAL_RTC_STATE_TIMEOUT;
715 /* Clear the Tamper Flag */
716 __HAL_RTC_TAMPER_CLEAR_FLAG(hrtc,RTC_FLAG_TAMP3F);
718 /* Change RTC state */
719 hrtc->State = HAL_RTC_STATE_READY;
728 /** @defgroup RTCEx_Exported_Functions_Group2 Extended Wake-up functions
729 * @brief RTC Wake-up functions
732 ===============================================================================
733 ##### RTC Wake-up functions #####
734 ===============================================================================
736 [..] This section provide functions allowing to configure Wake-up feature
743 * @brief Sets wake up timer.
744 * @param hrtc: RTC handle
745 * @param WakeUpCounter: Wake up counter
746 * @param WakeUpClock: Wake up clock
749 HAL_StatusTypeDef HAL_RTCEx_SetWakeUpTimer(RTC_HandleTypeDef *hrtc, uint32_t WakeUpCounter, uint32_t WakeUpClock)
751 uint32_t tickstart = 0;
753 /* Check the parameters */
754 assert_param(IS_WAKEUP_CLOCK(WakeUpClock));
755 assert_param(IS_WAKEUP_COUNTER(WakeUpCounter));
760 hrtc->State = HAL_RTC_STATE_BUSY;
762 /* Disable the write protection for RTC registers */
763 __HAL_RTC_WRITEPROTECTION_DISABLE(hrtc);
765 __HAL_RTC_WAKEUPTIMER_DISABLE(hrtc);
767 tickstart = HAL_GetTick();
769 /* Wait till RTC WUTWF flag is set and if Time out is reached exit */
770 while(__HAL_RTC_WAKEUPTIMER_GET_FLAG(hrtc, RTC_FLAG_WUTWF) == RESET)
772 if((HAL_GetTick()-tickstart) > RTC_TIMEOUT_VALUE)
774 /* Enable the write protection for RTC registers */
775 __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc);
777 hrtc->State = HAL_RTC_STATE_TIMEOUT;
779 /* Process Unlocked */
786 /* Clear the Wakeup Timer clock source bits in CR register */
787 hrtc->Instance->CR &= (uint32_t)~RTC_CR_WUCKSEL;
789 /* Configure the clock source */
790 hrtc->Instance->CR |= (uint32_t)WakeUpClock;
792 /* Configure the Wakeup Timer counter */
793 hrtc->Instance->WUTR = (uint32_t)WakeUpCounter;
795 /* Enable the Wakeup Timer */
796 __HAL_RTC_WAKEUPTIMER_ENABLE(hrtc);
798 /* Enable the write protection for RTC registers */
799 __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc);
801 hrtc->State = HAL_RTC_STATE_READY;
803 /* Process Unlocked */
810 * @brief Sets wake up timer with interrupt
811 * @param hrtc: RTC handle
812 * @param WakeUpCounter: wake up counter
813 * @param WakeUpClock: wake up clock
816 HAL_StatusTypeDef HAL_RTCEx_SetWakeUpTimer_IT(RTC_HandleTypeDef *hrtc, uint32_t WakeUpCounter, uint32_t WakeUpClock)
818 uint32_t tickstart = 0;
820 /* Check the parameters */
821 assert_param(IS_WAKEUP_CLOCK(WakeUpClock));
822 assert_param(IS_WAKEUP_COUNTER(WakeUpCounter));
827 hrtc->State = HAL_RTC_STATE_BUSY;
829 /* Disable the write protection for RTC registers */
830 __HAL_RTC_WRITEPROTECTION_DISABLE(hrtc);
832 __HAL_RTC_WAKEUPTIMER_DISABLE(hrtc);
834 tickstart = HAL_GetTick();
836 /* Wait till RTC WUTWF flag is set and if Time out is reached exit */
837 while(__HAL_RTC_WAKEUPTIMER_GET_FLAG(hrtc, RTC_FLAG_WUTWF) == RESET)
839 if((HAL_GetTick()-tickstart) > RTC_TIMEOUT_VALUE)
841 /* Enable the write protection for RTC registers */
842 __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc);
844 hrtc->State = HAL_RTC_STATE_TIMEOUT;
846 /* Process Unlocked */
853 /* Configure the Wakeup Timer counter */
854 hrtc->Instance->WUTR = (uint32_t)WakeUpCounter;
856 /* Clear the Wakeup Timer clock source bits in CR register */
857 hrtc->Instance->CR &= (uint32_t)~RTC_CR_WUCKSEL;
859 /* Configure the clock source */
860 hrtc->Instance->CR |= (uint32_t)WakeUpClock;
862 /* RTC WakeUpTimer Interrupt Configuration: EXTI configuration */
863 __HAL_RTC_ENABLE_IT(RTC_EXTI_LINE_WAKEUPTIMER_EVENT);
865 EXTI->RTSR |= RTC_EXTI_LINE_WAKEUPTIMER_EVENT;
867 /* Configure the Interrupt in the RTC_CR register */
868 __HAL_RTC_WAKEUPTIMER_ENABLE_IT(hrtc,RTC_IT_WUT);
870 /* Enable the Wakeup Timer */
871 __HAL_RTC_WAKEUPTIMER_ENABLE(hrtc);
873 /* Enable the write protection for RTC registers */
874 __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc);
876 hrtc->State = HAL_RTC_STATE_READY;
878 /* Process Unlocked */
885 * @brief Deactivates wake up timer counter.
886 * @param hrtc: RTC handle
889 uint32_t HAL_RTCEx_DeactivateWakeUpTimer(RTC_HandleTypeDef *hrtc)
891 uint32_t tickstart = 0;
896 hrtc->State = HAL_RTC_STATE_BUSY;
898 /* Disable the write protection for RTC registers */
899 __HAL_RTC_WRITEPROTECTION_DISABLE(hrtc);
901 /* Disable the Wakeup Timer */
902 __HAL_RTC_WAKEUPTIMER_DISABLE(hrtc);
904 /* In case of interrupt mode is used, the interrupt source must disabled */
905 __HAL_RTC_WAKEUPTIMER_DISABLE_IT(hrtc,RTC_IT_WUT);
907 tickstart = HAL_GetTick();
908 /* Wait till RTC WUTWF flag is set and if Time out is reached exit */
909 while(__HAL_RTC_WAKEUPTIMER_GET_FLAG(hrtc, RTC_FLAG_WUTWF) == RESET)
911 if((HAL_GetTick()-tickstart) > RTC_TIMEOUT_VALUE)
913 /* Enable the write protection for RTC registers */
914 __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc);
916 hrtc->State = HAL_RTC_STATE_TIMEOUT;
918 /* Process Unlocked */
925 /* Enable the write protection for RTC registers */
926 __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc);
928 hrtc->State = HAL_RTC_STATE_READY;
930 /* Process Unlocked */
937 * @brief Gets wake up timer counter.
938 * @param hrtc: RTC handle
939 * @retval Counter value
941 uint32_t HAL_RTCEx_GetWakeUpTimer(RTC_HandleTypeDef *hrtc)
943 /* Get the counter value */
944 return ((uint32_t)(hrtc->Instance->WUTR & RTC_WUTR_WUT));
948 * @brief This function handles Wake Up Timer interrupt request.
949 * @param hrtc: RTC handle
952 void HAL_RTCEx_WakeUpTimerIRQHandler(RTC_HandleTypeDef *hrtc)
954 if(__HAL_RTC_WAKEUPTIMER_GET_IT(hrtc, RTC_IT_WUT))
956 /* Get the status of the Interrupt */
957 if((uint32_t)(hrtc->Instance->CR & RTC_IT_WUT) != (uint32_t)RESET)
959 /* WAKEUPTIMER callback */
960 HAL_RTCEx_WakeUpTimerEventCallback(hrtc);
962 /* Clear the WAKEUPTIMER interrupt pending bit */
963 __HAL_RTC_WAKEUPTIMER_CLEAR_FLAG(hrtc, RTC_FLAG_WUTF);
967 /* Clear the EXTI's line Flag for RTC WakeUpTimer */
968 __HAL_RTC_CLEAR_FLAG(RTC_EXTI_LINE_WAKEUPTIMER_EVENT);
970 /* Change RTC state */
971 hrtc->State = HAL_RTC_STATE_READY;
975 * @brief Wake Up Timer callback.
976 * @param hrtc: RTC handle
979 __weak void HAL_RTCEx_WakeUpTimerEventCallback(RTC_HandleTypeDef *hrtc)
981 /* NOTE : This function Should not be modified, when the callback is needed,
982 the HAL_RTCEx_WakeUpTimerEventCallback could be implemented in the user file
987 * @brief This function handles Wake Up Timer Polling.
988 * @param hrtc: RTC handle
989 * @param Timeout: Timeout duration
992 HAL_StatusTypeDef HAL_RTCEx_PollForWakeUpTimerEvent(RTC_HandleTypeDef *hrtc, uint32_t Timeout)
994 uint32_t tickstart = HAL_GetTick();
996 while(__HAL_RTC_WAKEUPTIMER_GET_FLAG(hrtc, RTC_FLAG_WUTF) == RESET)
998 if(Timeout != HAL_MAX_DELAY)
1000 if((Timeout == 0) || ((HAL_GetTick()-tickstart) > Timeout))
1002 hrtc->State = HAL_RTC_STATE_TIMEOUT;
1009 /* Clear the WAKEUPTIMER Flag */
1010 __HAL_RTC_WAKEUPTIMER_CLEAR_FLAG(hrtc, RTC_FLAG_WUTF);
1012 /* Change RTC state */
1013 hrtc->State = HAL_RTC_STATE_READY;
1023 /** @defgroup RTCEx_Exported_Functions_Group3 Extended Peripheral Control functions
1024 * @brief Extended Peripheral Control functions
1027 ===============================================================================
1028 ##### Extended Peripheral Control functions #####
1029 ===============================================================================
1031 This subsection provides functions allowing to
1032 (+) Writes a data in a specified RTC Backup data register
1033 (+) Read a data in a specified RTC Backup data register
1034 (+) Sets the Coarse calibration parameters.
1035 (+) Deactivates the Coarse calibration parameters
1036 (+) Sets the Smooth calibration parameters.
1037 (+) Configures the Synchronization Shift Control Settings.
1038 (+) Configures the Calibration Pinout (RTC_CALIB) Selection (1Hz or 512Hz).
1039 (+) Deactivates the Calibration Pinout (RTC_CALIB) Selection (1Hz or 512Hz).
1040 (+) Enables the RTC reference clock detection.
1041 (+) Disable the RTC reference clock detection.
1042 (+) Enables the Bypass Shadow feature.
1043 (+) Disables the Bypass Shadow feature.
1050 * @brief Writes a data in a specified RTC Backup data register.
1051 * @param hrtc: RTC handle
1052 * @param BackupRegister: RTC Backup data Register number.
1053 * This parameter can be: RTC_BKP_DRx where x can be from 0 to 19 to
1054 * specify the register.
1055 * @param Data: Data to be written in the specified RTC Backup data register.
1058 void HAL_RTCEx_BKUPWrite(RTC_HandleTypeDef *hrtc, uint32_t BackupRegister, uint32_t Data)
1062 /* Check the parameters */
1063 assert_param(IS_RTC_BKP(BackupRegister));
1065 tmp = (uint32_t)&(hrtc->Instance->BKP0R);
1066 tmp += (BackupRegister * 4);
1068 /* Write the specified register */
1069 *(__IO uint32_t *)tmp = (uint32_t)Data;
1073 * @brief Reads data from the specified RTC Backup data Register.
1074 * @param hrtc: RTC handle
1075 * @param BackupRegister: RTC Backup data Register number.
1076 * This parameter can be: RTC_BKP_DRx where x can be from 0 to 19 to
1077 * specify the register.
1078 * @retval Read value
1080 uint32_t HAL_RTCEx_BKUPRead(RTC_HandleTypeDef *hrtc, uint32_t BackupRegister)
1084 /* Check the parameters */
1085 assert_param(IS_RTC_BKP(BackupRegister));
1087 tmp = (uint32_t)&(hrtc->Instance->BKP0R);
1088 tmp += (BackupRegister * 4);
1090 /* Read the specified register */
1091 return (*(__IO uint32_t *)tmp);
1095 * @brief Sets the Smooth calibration parameters.
1096 * @param hrtc: RTC handle
1097 * @param SmoothCalibPeriod: Select the Smooth Calibration Period.
1098 * This parameter can be can be one of the following values :
1099 * @arg RTC_SMOOTHCALIB_PERIOD_32SEC: The smooth calibration periode is 32s.
1100 * @arg RTC_SMOOTHCALIB_PERIOD_16SEC: The smooth calibration periode is 16s.
1101 * @arg RTC_SMOOTHCALIB_PERIOD_8SEC: The smooth calibartion periode is 8s.
1102 * @param SmoothCalibPlusPulses: Select to Set or reset the CALP bit.
1103 * This parameter can be one of the following values:
1104 * @arg RTC_SMOOTHCALIB_PLUSPULSES_SET: Add one RTCCLK puls every 2*11 pulses.
1105 * @arg RTC_SMOOTHCALIB_PLUSPULSES_RESET: No RTCCLK pulses are added.
1106 * @param SmouthCalibMinusPulsesValue: Select the value of CALM[8:0] bits.
1107 * This parameter can be one any value from 0 to 0x000001FF.
1108 * @note To deactivate the smooth calibration, the field SmoothCalibPlusPulses
1109 * must be equal to SMOOTHCALIB_PLUSPULSES_RESET and the field
1110 * SmouthCalibMinusPulsesValue mut be equal to 0.
1111 * @retval HAL status
1113 HAL_StatusTypeDef HAL_RTCEx_SetSmoothCalib(RTC_HandleTypeDef* hrtc, uint32_t SmoothCalibPeriod, uint32_t SmoothCalibPlusPulses, uint32_t SmouthCalibMinusPulsesValue)
1115 uint32_t tickstart = 0;
1117 /* Check the parameters */
1118 assert_param(IS_RTC_SMOOTH_CALIB_PERIOD(SmoothCalibPeriod));
1119 assert_param(IS_RTC_SMOOTH_CALIB_PLUS(SmoothCalibPlusPulses));
1120 assert_param(IS_RTC_SMOOTH_CALIB_MINUS(SmouthCalibMinusPulsesValue));
1122 /* Process Locked */
1125 hrtc->State = HAL_RTC_STATE_BUSY;
1127 /* Disable the write protection for RTC registers */
1128 __HAL_RTC_WRITEPROTECTION_DISABLE(hrtc);
1130 /* check if a calibration is pending*/
1131 if((hrtc->Instance->ISR & RTC_ISR_RECALPF) != RESET)
1133 tickstart = HAL_GetTick();
1135 /* check if a calibration is pending*/
1136 while((hrtc->Instance->ISR & RTC_ISR_RECALPF) != RESET)
1138 if((HAL_GetTick()-tickstart) > RTC_TIMEOUT_VALUE)
1140 /* Enable the write protection for RTC registers */
1141 __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc);
1143 /* Change RTC state */
1144 hrtc->State = HAL_RTC_STATE_TIMEOUT;
1146 /* Process Unlocked */
1154 /* Configure the Smooth calibration settings */
1155 hrtc->Instance->CALR = (uint32_t)((uint32_t)SmoothCalibPeriod | (uint32_t)SmoothCalibPlusPulses | (uint32_t)SmouthCalibMinusPulsesValue);
1157 /* Enable the write protection for RTC registers */
1158 __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc);
1160 /* Change RTC state */
1161 hrtc->State = HAL_RTC_STATE_READY;
1163 /* Process Unlocked */
1170 * @brief Configures the Synchronization Shift Control Settings.
1171 * @note When REFCKON is set, firmware must not write to Shift control register.
1172 * @param hrtc: RTC handle
1173 * @param ShiftAdd1S: Select to add or not 1 second to the time calendar.
1174 * This parameter can be one of the following values :
1175 * @arg RTC_SHIFTADD1S_SET: Add one second to the clock calendar.
1176 * @arg RTC_SHIFTADD1S_RESET: No effect.
1177 * @param ShiftSubFS: Select the number of Second Fractions to substitute.
1178 * This parameter can be one any value from 0 to 0x7FFF.
1179 * @retval HAL status
1181 HAL_StatusTypeDef HAL_RTCEx_SetSynchroShift(RTC_HandleTypeDef* hrtc, uint32_t ShiftAdd1S, uint32_t ShiftSubFS)
1183 uint32_t tickstart = 0;
1185 /* Check the parameters */
1186 assert_param(IS_RTC_SHIFT_ADD1S(ShiftAdd1S));
1187 assert_param(IS_RTC_SHIFT_SUBFS(ShiftSubFS));
1189 /* Process Locked */
1192 hrtc->State = HAL_RTC_STATE_BUSY;
1194 /* Disable the write protection for RTC registers */
1195 __HAL_RTC_WRITEPROTECTION_DISABLE(hrtc);
1197 tickstart = HAL_GetTick();
1199 /* Wait until the shift is completed*/
1200 while((hrtc->Instance->ISR & RTC_ISR_SHPF) != RESET)
1202 if((HAL_GetTick()-tickstart) > RTC_TIMEOUT_VALUE)
1204 /* Enable the write protection for RTC registers */
1205 __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc);
1207 hrtc->State = HAL_RTC_STATE_TIMEOUT;
1209 /* Process Unlocked */
1216 /* Check if the reference clock detection is disabled */
1217 if((hrtc->Instance->CR & RTC_CR_REFCKON) == RESET)
1219 /* Configure the Shift settings */
1220 hrtc->Instance->SHIFTR = (uint32_t)(uint32_t)(ShiftSubFS) | (uint32_t)(ShiftAdd1S);
1222 /* If RTC_CR_BYPSHAD bit = 0, wait for synchro else this check is not needed */
1223 if((hrtc->Instance->CR & RTC_CR_BYPSHAD) == RESET)
1225 if(HAL_RTC_WaitForSynchro(hrtc) != HAL_OK)
1227 /* Enable the write protection for RTC registers */
1228 __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc);
1230 hrtc->State = HAL_RTC_STATE_ERROR;
1232 /* Process Unlocked */
1241 /* Enable the write protection for RTC registers */
1242 __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc);
1244 /* Change RTC state */
1245 hrtc->State = HAL_RTC_STATE_ERROR;
1247 /* Process Unlocked */
1253 /* Enable the write protection for RTC registers */
1254 __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc);
1256 /* Change RTC state */
1257 hrtc->State = HAL_RTC_STATE_READY;
1259 /* Process Unlocked */
1266 * @brief Configures the Calibration Pinout (RTC_CALIB) Selection (1Hz or 512Hz).
1267 * @param hrtc: RTC handle
1268 * @param CalibOutput : Select the Calibration output Selection .
1269 * This parameter can be one of the following values:
1270 * @arg RTC_CALIBOUTPUT_512HZ: A signal has a regular waveform at 512Hz.
1271 * @arg RTC_CALIBOUTPUT_1HZ: A signal has a regular waveform at 1Hz.
1272 * @retval HAL status
1274 HAL_StatusTypeDef HAL_RTCEx_SetCalibrationOutPut(RTC_HandleTypeDef* hrtc, uint32_t CalibOutput)
1276 /* Check the parameters */
1277 assert_param(IS_RTC_CALIB_OUTPUT(CalibOutput));
1279 /* Process Locked */
1282 hrtc->State = HAL_RTC_STATE_BUSY;
1284 /* Disable the write protection for RTC registers */
1285 __HAL_RTC_WRITEPROTECTION_DISABLE(hrtc);
1287 /* Clear flags before config */
1288 hrtc->Instance->CR &= (uint32_t)~RTC_CR_COSEL;
1290 /* Configure the RTC_CR register */
1291 hrtc->Instance->CR |= (uint32_t)CalibOutput;
1293 __HAL_RTC_CALIBRATION_OUTPUT_ENABLE(hrtc);
1295 /* Enable the write protection for RTC registers */
1296 __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc);
1298 /* Change RTC state */
1299 hrtc->State = HAL_RTC_STATE_READY;
1301 /* Process Unlocked */
1308 * @brief Deactivates the Calibration Pinout (RTC_CALIB) Selection (1Hz or 512Hz).
1309 * @param hrtc: RTC handle
1310 * @retval HAL status
1312 HAL_StatusTypeDef HAL_RTCEx_DeactivateCalibrationOutPut(RTC_HandleTypeDef* hrtc)
1314 /* Process Locked */
1317 hrtc->State = HAL_RTC_STATE_BUSY;
1319 /* Disable the write protection for RTC registers */
1320 __HAL_RTC_WRITEPROTECTION_DISABLE(hrtc);
1322 __HAL_RTC_CALIBRATION_OUTPUT_DISABLE(hrtc);
1324 /* Enable the write protection for RTC registers */
1325 __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc);
1327 /* Change RTC state */
1328 hrtc->State = HAL_RTC_STATE_READY;
1330 /* Process Unlocked */
1337 * @brief Enables the RTC reference clock detection.
1338 * @param hrtc: RTC handle
1339 * @retval HAL status
1341 HAL_StatusTypeDef HAL_RTCEx_SetRefClock(RTC_HandleTypeDef* hrtc)
1343 /* Process Locked */
1346 hrtc->State = HAL_RTC_STATE_BUSY;
1348 /* Disable the write protection for RTC registers */
1349 __HAL_RTC_WRITEPROTECTION_DISABLE(hrtc);
1351 /* Set Initialization mode */
1352 if(RTC_EnterInitMode(hrtc) != HAL_OK)
1354 /* Enable the write protection for RTC registers */
1355 __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc);
1358 hrtc->State = HAL_RTC_STATE_ERROR;
1360 /* Process Unlocked */
1367 __HAL_RTC_CLOCKREF_DETECTION_ENABLE(hrtc);
1369 /* Exit Initialization mode */
1370 hrtc->Instance->ISR &= (uint32_t)~RTC_ISR_INIT;
1373 /* Enable the write protection for RTC registers */
1374 __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc);
1376 /* Change RTC state */
1377 hrtc->State = HAL_RTC_STATE_READY;
1379 /* Process Unlocked */
1386 * @brief Disable the RTC reference clock detection.
1387 * @param hrtc: RTC handle
1388 * @retval HAL status
1390 HAL_StatusTypeDef HAL_RTCEx_DeactivateRefClock(RTC_HandleTypeDef* hrtc)
1392 /* Process Locked */
1395 hrtc->State = HAL_RTC_STATE_BUSY;
1397 /* Disable the write protection for RTC registers */
1398 __HAL_RTC_WRITEPROTECTION_DISABLE(hrtc);
1400 /* Set Initialization mode */
1401 if(RTC_EnterInitMode(hrtc) != HAL_OK)
1403 /* Enable the write protection for RTC registers */
1404 __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc);
1407 hrtc->State = HAL_RTC_STATE_ERROR;
1409 /* Process Unlocked */
1416 __HAL_RTC_CLOCKREF_DETECTION_DISABLE(hrtc);
1418 /* Exit Initialization mode */
1419 hrtc->Instance->ISR &= (uint32_t)~RTC_ISR_INIT;
1422 /* Enable the write protection for RTC registers */
1423 __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc);
1425 /* Change RTC state */
1426 hrtc->State = HAL_RTC_STATE_READY;
1428 /* Process Unlocked */
1435 * @brief Enables the Bypass Shadow feature.
1436 * @param hrtc: RTC handle
1437 * @note When the Bypass Shadow is enabled the calendar value are taken
1438 * directly from the Calendar counter.
1439 * @retval HAL status
1441 HAL_StatusTypeDef HAL_RTCEx_EnableBypassShadow(RTC_HandleTypeDef* hrtc)
1443 /* Process Locked */
1446 hrtc->State = HAL_RTC_STATE_BUSY;
1448 /* Disable the write protection for RTC registers */
1449 __HAL_RTC_WRITEPROTECTION_DISABLE(hrtc);
1451 /* Set the BYPSHAD bit */
1452 hrtc->Instance->CR |= (uint8_t)RTC_CR_BYPSHAD;
1454 /* Enable the write protection for RTC registers */
1455 __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc);
1457 /* Change RTC state */
1458 hrtc->State = HAL_RTC_STATE_READY;
1460 /* Process Unlocked */
1467 * @brief Disables the Bypass Shadow feature.
1468 * @param hrtc: RTC handle
1469 * @note When the Bypass Shadow is enabled the calendar value are taken
1470 * directly from the Calendar counter.
1471 * @retval HAL status
1473 HAL_StatusTypeDef HAL_RTCEx_DisableBypassShadow(RTC_HandleTypeDef* hrtc)
1475 /* Process Locked */
1478 hrtc->State = HAL_RTC_STATE_BUSY;
1480 /* Disable the write protection for RTC registers */
1481 __HAL_RTC_WRITEPROTECTION_DISABLE(hrtc);
1483 /* Reset the BYPSHAD bit */
1484 hrtc->Instance->CR &= (uint8_t)~RTC_CR_BYPSHAD;
1486 /* Enable the write protection for RTC registers */
1487 __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc);
1489 /* Change RTC state */
1490 hrtc->State = HAL_RTC_STATE_READY;
1492 /* Process Unlocked */
1502 /** @defgroup RTCEx_Exported_Functions_Group4 Extended features functions
1503 * @brief Extended features functions
1506 ===============================================================================
1507 ##### Extended features functions #####
1508 ===============================================================================
1509 [..] This section provides functions allowing to:
1510 (+) RTC Alram B callback
1511 (+) RTC Poll for Alarm B request
1518 * @brief Alarm B callback.
1519 * @param hrtc: RTC handle
1522 __weak void HAL_RTCEx_AlarmBEventCallback(RTC_HandleTypeDef *hrtc)
1524 /* NOTE : This function Should not be modified, when the callback is needed,
1525 the HAL_RTCEx_AlarmBEventCallback could be implemented in the user file
1530 * @brief This function handles AlarmB Polling request.
1531 * @param hrtc: RTC handle
1532 * @param Timeout: Timeout duration
1533 * @retval HAL status
1535 HAL_StatusTypeDef HAL_RTCEx_PollForAlarmBEvent(RTC_HandleTypeDef *hrtc, uint32_t Timeout)
1537 uint32_t tickstart = HAL_GetTick();
1539 while(__HAL_RTC_ALARM_GET_FLAG(hrtc, RTC_FLAG_ALRBF) == RESET)
1541 if(Timeout != HAL_MAX_DELAY)
1543 if((Timeout == 0) || ((HAL_GetTick()-tickstart) > Timeout))
1545 hrtc->State = HAL_RTC_STATE_TIMEOUT;
1551 /* Clear the Alarm Flag */
1552 __HAL_RTC_ALARM_CLEAR_FLAG(hrtc, RTC_FLAG_ALRBF);
1554 /* Change RTC state */
1555 hrtc->State = HAL_RTC_STATE_READY;
1568 #endif /* HAL_RTC_MODULE_ENABLED */
1577 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/