2 ******************************************************************************
3 * @file stm32f0xx_hal_rtc_ex.c
4 * @author MCD Application Team
6 * @date 11-December-2014
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) Extension peripheral:
10 * + RTC TimeStamp 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 (see description in the section above).
22 (+) Configure the RTC Prescaler (Asynchronous and Synchronous) and RTC hour
23 format using the HAL_RTC_Init() function.
25 *** RTC Wake-up configuration ***
26 ================================
28 (+) To configure the RTC Wake-up Clock source and Counter use the HAL_RTCEx_SetWakeUpTimer()
29 function. You can also configure the RTC Wake-up timer in interrupt mode
30 using the HAL_RTCEx_SetWakeUpTimer_IT() function.
31 (+) To read the RTC Wake-up Counter register, use the HAL_RTCEx_GetWakeUpTimer()
33 (@) Not available on F030x6/x8/xC and F070x6/xB
35 *** TimeStamp configuration ***
36 ===============================
38 (+) Configure the RTC_AF trigger and enable the RTC TimeStamp using the
39 HAL_RTCEx_SetTimeStamp() function. You can also configure the RTC TimeStamp with
40 interrupt mode using the HAL_RTCEx_SetTimeStamp_IT() function.
41 (+) To read the RTC TimeStamp Time and Date register, use the HAL_RTCEx_GetTimeStamp()
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 in interrupt
51 mode using HAL_RTCEx_SetTamper_IT() function.
53 *** Backup Data Registers configuration ***
54 ===========================================
56 (+) To write to the RTC Backup Data registers, use the HAL_RTCEx_BKUPWrite()
58 (+) To read the RTC Backup Data registers, use the HAL_RTCEx_BKUPRead()
60 (@) Not available on F030x6/x8/xC and F070x6/xB
64 ******************************************************************************
67 * <h2><center>© COPYRIGHT(c) 2014 STMicroelectronics</center></h2>
69 * Redistribution and use in source and binary forms, with or without modification,
70 * are permitted provided that the following conditions are met:
71 * 1. Redistributions of source code must retain the above copyright notice,
72 * this list of conditions and the following disclaimer.
73 * 2. Redistributions in binary form must reproduce the above copyright notice,
74 * this list of conditions and the following disclaimer in the documentation
75 * and/or other materials provided with the distribution.
76 * 3. Neither the name of STMicroelectronics nor the names of its contributors
77 * may be used to endorse or promote products derived from this software
78 * without specific prior written permission.
80 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
81 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
82 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
83 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
84 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
85 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
86 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
87 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
88 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
89 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
91 ******************************************************************************
94 /* Includes ------------------------------------------------------------------*/
95 #include "stm32f0xx_hal.h"
97 /** @addtogroup STM32F0xx_HAL_Driver
101 /** @defgroup RTCEx RTCEx Extended HAL module driver
102 * @brief RTCEx Extended HAL module driver
106 #ifdef HAL_RTC_MODULE_ENABLED
108 /* Private typedef -----------------------------------------------------------*/
109 /* Private define ------------------------------------------------------------*/
110 /* Private macro -------------------------------------------------------------*/
111 /* Private variables ---------------------------------------------------------*/
112 /* Private function prototypes -----------------------------------------------*/
113 /* Exported functions ---------------------------------------------------------*/
115 /** @defgroup RTCEx_Exported_Functions RTCEx 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 provides 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: pointer to a RTC_HandleTypeDef structure that contains
137 * the configuration information for RTC.
138 * @param TimeStampEdge: Specifies the pin edge on which the TimeStamp is
140 * This parameter can be one of the following values:
141 * @arg RTC_TIMESTAMPEDGE_RISING: the Time stamp event occurs on the
142 * rising edge of the related pin.
143 * @arg RTC_TIMESTAMPEDGE_FALLING: the Time stamp event occurs on the
144 * falling edge of the related pin.
145 * @param RTC_TimeStampPin: specifies the RTC TimeStamp Pin.
146 * This parameter can be one of the following values:
147 * @arg RTC_TIMESTAMPPIN_PC13: PC13 is selected as RTC TimeStamp Pin.
150 HAL_StatusTypeDef
HAL_RTCEx_SetTimeStamp(RTC_HandleTypeDef
*hrtc
, uint32_t TimeStampEdge
, uint32_t RTC_TimeStampPin
)
154 /* Check the parameters */
155 assert_param(IS_TIMESTAMP_EDGE(TimeStampEdge
));
156 assert_param(IS_RTC_TIMESTAMP_PIN(RTC_TimeStampPin
));
161 hrtc
->State
= HAL_RTC_STATE_BUSY
;
163 /* Get the RTC_CR register and clear the bits to be configured */
164 tmpreg
= (uint32_t)(hrtc
->Instance
->CR
& (uint32_t)~(RTC_CR_TSEDGE
| RTC_CR_TSE
));
166 tmpreg
|= TimeStampEdge
;
168 /* Disable the write protection for RTC registers */
169 __HAL_RTC_WRITEPROTECTION_DISABLE(hrtc
);
171 /* Configure the Time Stamp TSEDGE and Enable bits */
172 hrtc
->Instance
->CR
= (uint32_t)tmpreg
;
174 __HAL_RTC_TIMESTAMP_ENABLE(hrtc
);
176 /* Enable the write protection for RTC registers */
177 __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc
);
179 /* Change RTC state */
180 hrtc
->State
= HAL_RTC_STATE_READY
;
182 /* Process Unlocked */
189 * @brief Sets TimeStamp with Interrupt.
190 * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains
191 * the configuration information for RTC.
192 * @note This API must be called before enabling the TimeStamp feature.
193 * @param TimeStampEdge: Specifies the pin edge on which the TimeStamp is
195 * This parameter can be one of the following values:
196 * @arg RTC_TIMESTAMPEDGE_RISING: the Time stamp event occurs on the
197 * rising edge of the related pin.
198 * @arg RTC_TIMESTAMPEDGE_FALLING: the Time stamp event occurs on the
199 * falling edge of the related pin.
200 * @param RTC_TimeStampPin: Specifies the RTC TimeStamp Pin.
201 * This parameter can be one of the following values:
202 * @arg RTC_TIMESTAMPPIN_PC13: PC13 is selected as RTC TimeStamp Pin.
205 HAL_StatusTypeDef
HAL_RTCEx_SetTimeStamp_IT(RTC_HandleTypeDef
*hrtc
, uint32_t TimeStampEdge
, uint32_t RTC_TimeStampPin
)
209 /* Check the parameters */
210 assert_param(IS_TIMESTAMP_EDGE(TimeStampEdge
));
211 assert_param(IS_RTC_TIMESTAMP_PIN(RTC_TimeStampPin
));
216 hrtc
->State
= HAL_RTC_STATE_BUSY
;
218 /* Get the RTC_CR register and clear the bits to be configured */
219 tmpreg
= (uint32_t)(hrtc
->Instance
->CR
& (uint32_t)~(RTC_CR_TSEDGE
| RTC_CR_TSE
));
221 tmpreg
|= TimeStampEdge
;
223 /* Disable the write protection for RTC registers */
224 __HAL_RTC_WRITEPROTECTION_DISABLE(hrtc
);
226 /* Configure the Time Stamp TSEDGE and Enable bits */
227 hrtc
->Instance
->CR
= (uint32_t)tmpreg
;
229 __HAL_RTC_TIMESTAMP_ENABLE(hrtc
);
231 /* Enable IT timestamp */
232 __HAL_RTC_TIMESTAMP_ENABLE_IT(hrtc
,RTC_IT_TS
);
234 /* RTC timestamp Interrupt Configuration: EXTI configuration */
235 __HAL_RTC_EXTI_ENABLE_IT(RTC_EXTI_LINE_TAMPER_TIMESTAMP_EVENT
);
237 EXTI
->RTSR
|= RTC_EXTI_LINE_TAMPER_TIMESTAMP_EVENT
;
239 /* Enable the write protection for RTC registers */
240 __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc
);
242 hrtc
->State
= HAL_RTC_STATE_READY
;
244 /* Process Unlocked */
251 * @brief Deactivates TimeStamp.
252 * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains
253 * the configuration information for RTC.
256 HAL_StatusTypeDef
HAL_RTCEx_DeactivateTimeStamp(RTC_HandleTypeDef
*hrtc
)
263 hrtc
->State
= HAL_RTC_STATE_BUSY
;
265 /* Disable the write protection for RTC registers */
266 __HAL_RTC_WRITEPROTECTION_DISABLE(hrtc
);
268 /* In case of interrupt mode is used, the interrupt source must disabled */
269 __HAL_RTC_TIMESTAMP_DISABLE_IT(hrtc
, RTC_IT_TS
);
271 /* Get the RTC_CR register and clear the bits to be configured */
272 tmpreg
= (uint32_t)(hrtc
->Instance
->CR
& (uint32_t)~(RTC_CR_TSEDGE
| RTC_CR_TSE
));
274 /* Configure the Time Stamp TSEDGE and Enable bits */
275 hrtc
->Instance
->CR
= (uint32_t)tmpreg
;
277 /* Enable the write protection for RTC registers */
278 __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc
);
280 hrtc
->State
= HAL_RTC_STATE_READY
;
282 /* Process Unlocked */
289 * @brief Gets the RTC TimeStamp value.
290 * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains
291 * the configuration information for RTC.
292 * @param sTimeStamp: Pointer to Time structure
293 * @param sTimeStampDate: Pointer to Date structure
294 * @param Format: specifies the format of the entered parameters.
295 * This parameter can be one of the following values:
296 * @arg FORMAT_BIN: Binary data format
297 * @arg FORMAT_BCD: BCD data format
300 HAL_StatusTypeDef
HAL_RTCEx_GetTimeStamp(RTC_HandleTypeDef
*hrtc
, RTC_TimeTypeDef
* sTimeStamp
, RTC_DateTypeDef
* sTimeStampDate
, uint32_t Format
)
302 uint32_t tmptime
= 0, tmpdate
= 0;
304 /* Check the parameters */
305 assert_param(IS_RTC_FORMAT(Format
));
307 /* Get the TimeStamp time and date registers values */
308 tmptime
= (uint32_t)(hrtc
->Instance
->TSTR
& RTC_TR_RESERVED_MASK
);
309 tmpdate
= (uint32_t)(hrtc
->Instance
->TSDR
& RTC_DR_RESERVED_MASK
);
311 /* Fill the Time structure fields with the read parameters */
312 sTimeStamp
->Hours
= (uint8_t)((tmptime
& (RTC_TR_HT
| RTC_TR_HU
)) >> 16);
313 sTimeStamp
->Minutes
= (uint8_t)((tmptime
& (RTC_TR_MNT
| RTC_TR_MNU
)) >> 8);
314 sTimeStamp
->Seconds
= (uint8_t)(tmptime
& (RTC_TR_ST
| RTC_TR_SU
));
315 sTimeStamp
->TimeFormat
= (uint8_t)((tmptime
& (RTC_TR_PM
)) >> 16);
316 sTimeStamp
->SubSeconds
= (uint32_t) hrtc
->Instance
->TSSSR
;
318 /* Fill the Date structure fields with the read parameters */
319 sTimeStampDate
->Year
= 0;
320 sTimeStampDate
->Month
= (uint8_t)((tmpdate
& (RTC_DR_MT
| RTC_DR_MU
)) >> 8);
321 sTimeStampDate
->Date
= (uint8_t)(tmpdate
& (RTC_DR_DT
| RTC_DR_DU
));
322 sTimeStampDate
->WeekDay
= (uint8_t)((tmpdate
& (RTC_DR_WDU
)) >> 13);
324 /* Check the input parameters format */
325 if(Format
== FORMAT_BIN
)
327 /* Convert the TimeStamp structure parameters to Binary format */
328 sTimeStamp
->Hours
= (uint8_t)RTC_Bcd2ToByte(sTimeStamp
->Hours
);
329 sTimeStamp
->Minutes
= (uint8_t)RTC_Bcd2ToByte(sTimeStamp
->Minutes
);
330 sTimeStamp
->Seconds
= (uint8_t)RTC_Bcd2ToByte(sTimeStamp
->Seconds
);
332 /* Convert the DateTimeStamp structure parameters to Binary format */
333 sTimeStampDate
->Month
= (uint8_t)RTC_Bcd2ToByte(sTimeStampDate
->Month
);
334 sTimeStampDate
->Date
= (uint8_t)RTC_Bcd2ToByte(sTimeStampDate
->Date
);
335 sTimeStampDate
->WeekDay
= (uint8_t)RTC_Bcd2ToByte(sTimeStampDate
->WeekDay
);
338 /* Clear the TIMESTAMP Flag */
339 __HAL_RTC_TIMESTAMP_CLEAR_FLAG(hrtc
, RTC_FLAG_TSF
);
346 * @note By calling this API we disable the tamper interrupt for all tampers.
347 * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains
348 * the configuration information for RTC.
349 * @param sTamper: Pointer to Tamper Structure.
352 HAL_StatusTypeDef
HAL_RTCEx_SetTamper(RTC_HandleTypeDef
*hrtc
, RTC_TamperTypeDef
* sTamper
)
356 /* Check the parameters */
357 assert_param(IS_TAMPER(sTamper
->Tamper
));
358 assert_param(IS_TAMPER_TRIGGER(sTamper
->Trigger
));
359 assert_param(IS_TAMPER_FILTER(sTamper
->Filter
));
360 assert_param(IS_TAMPER_SAMPLING_FREQ(sTamper
->SamplingFrequency
));
361 assert_param(IS_TAMPER_PRECHARGE_DURATION(sTamper
->PrechargeDuration
));
362 assert_param(IS_TAMPER_PULLUP_STATE(sTamper
->TamperPullUp
));
363 assert_param(IS_TAMPER_TIMESTAMPONTAMPER_DETECTION(sTamper
->TimeStampOnTamperDetection
));
368 hrtc
->State
= HAL_RTC_STATE_BUSY
;
370 if(sTamper
->Trigger
!= RTC_TAMPERTRIGGER_RISINGEDGE
)
372 sTamper
->Trigger
= (uint32_t)(sTamper
->Tamper
<< 1);
375 tmpreg
= ((uint32_t)sTamper
->Tamper
| (uint32_t)sTamper
->Trigger
| (uint32_t)sTamper
->Filter
|\
376 (uint32_t)sTamper
->SamplingFrequency
| (uint32_t)sTamper
->PrechargeDuration
|\
377 (uint32_t)sTamper
->TamperPullUp
| sTamper
->TimeStampOnTamperDetection
);
379 hrtc
->Instance
->TAFCR
&= (uint32_t)~((uint32_t)sTamper
->Tamper
| (uint32_t)(sTamper
->Tamper
<< 1) | (uint32_t)RTC_TAFCR_TAMPTS
|\
380 (uint32_t)RTC_TAFCR_TAMPFREQ
| (uint32_t)RTC_TAFCR_TAMPFLT
| (uint32_t)RTC_TAFCR_TAMPPRCH
|\
381 (uint32_t)RTC_TAFCR_TAMPPUDIS
| (uint32_t)RTC_TAFCR_TAMPIE
);
383 hrtc
->Instance
->TAFCR
|= tmpreg
;
385 hrtc
->State
= HAL_RTC_STATE_READY
;
387 /* Process Unlocked */
394 * @brief Sets Tamper with interrupt.
395 * @note By calling this API we force the tamper interrupt for all tampers.
396 * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains
397 * the configuration information for RTC.
398 * @param sTamper: Pointer to RTC Tamper.
401 HAL_StatusTypeDef
HAL_RTCEx_SetTamper_IT(RTC_HandleTypeDef
*hrtc
, RTC_TamperTypeDef
* sTamper
)
405 /* Check the parameters */
406 assert_param(IS_TAMPER(sTamper
->Tamper
));
407 assert_param(IS_TAMPER_TRIGGER(sTamper
->Trigger
));
408 assert_param(IS_TAMPER_FILTER(sTamper
->Filter
));
409 assert_param(IS_TAMPER_SAMPLING_FREQ(sTamper
->SamplingFrequency
));
410 assert_param(IS_TAMPER_PRECHARGE_DURATION(sTamper
->PrechargeDuration
));
411 assert_param(IS_TAMPER_PULLUP_STATE(sTamper
->TamperPullUp
));
412 assert_param(IS_TAMPER_TIMESTAMPONTAMPER_DETECTION(sTamper
->TimeStampOnTamperDetection
));
417 hrtc
->State
= HAL_RTC_STATE_BUSY
;
419 /* Configure the tamper trigger */
420 if(sTamper
->Trigger
!= RTC_TAMPERTRIGGER_RISINGEDGE
)
422 sTamper
->Trigger
= (uint32_t)(sTamper
->Tamper
<< 1);
425 tmpreg
= ((uint32_t)sTamper
->Tamper
| (uint32_t)sTamper
->Trigger
| (uint32_t)sTamper
->Filter
|\
426 (uint32_t)sTamper
->SamplingFrequency
| (uint32_t)sTamper
->PrechargeDuration
|\
427 (uint32_t)sTamper
->TamperPullUp
| sTamper
->TimeStampOnTamperDetection
);
429 hrtc
->Instance
->TAFCR
&= (uint32_t)~((uint32_t)sTamper
->Tamper
| (uint32_t)(sTamper
->Tamper
<< 1) | (uint32_t)RTC_TAFCR_TAMPTS
|\
430 (uint32_t)RTC_TAFCR_TAMPFREQ
| (uint32_t)RTC_TAFCR_TAMPFLT
| (uint32_t)RTC_TAFCR_TAMPPRCH
|\
431 (uint32_t)RTC_TAFCR_TAMPPUDIS
);
433 hrtc
->Instance
->TAFCR
|= tmpreg
;
435 /* Configure the Tamper Interrupt in the RTC_TAFCR */
436 hrtc
->Instance
->TAFCR
|= (uint32_t)RTC_TAFCR_TAMPIE
;
438 /* RTC Tamper Interrupt Configuration: EXTI configuration */
439 __HAL_RTC_EXTI_ENABLE_IT(RTC_EXTI_LINE_TAMPER_TIMESTAMP_EVENT
);
441 EXTI
->RTSR
|= RTC_EXTI_LINE_TAMPER_TIMESTAMP_EVENT
;
443 hrtc
->State
= HAL_RTC_STATE_READY
;
445 /* Process Unlocked */
452 * @brief Deactivates Tamper.
453 * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains
454 * the configuration information for RTC.
455 * @param Tamper: Selected tamper pin.
456 * This parameter can be any combination of RTC_TAMPER_1, RTC_TAMPER_2 and RTC_TAMPER_3.
459 HAL_StatusTypeDef
HAL_RTCEx_DeactivateTamper(RTC_HandleTypeDef
*hrtc
, uint32_t Tamper
)
461 assert_param(IS_TAMPER(Tamper
));
466 hrtc
->State
= HAL_RTC_STATE_BUSY
;
468 /* Disable the selected Tamper pin */
469 hrtc
->Instance
->TAFCR
&= (uint32_t)~Tamper
;
471 hrtc
->State
= HAL_RTC_STATE_READY
;
473 /* Process Unlocked */
480 * @brief This function handles TimeStamp interrupt request.
481 * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains
482 * the configuration information for RTC.
485 void HAL_RTCEx_TamperTimeStampIRQHandler(RTC_HandleTypeDef
*hrtc
)
487 if(__HAL_RTC_TIMESTAMP_GET_IT(hrtc
, RTC_IT_TS
))
489 /* Get the status of the Interrupt */
490 if((uint32_t)(hrtc
->Instance
->CR
& RTC_IT_TS
) != (uint32_t)RESET
)
492 /* TIMESTAMP callback */
493 HAL_RTCEx_TimeStampEventCallback(hrtc
);
495 /* Clear the TIMESTAMP interrupt pending bit */
496 __HAL_RTC_TIMESTAMP_CLEAR_FLAG(hrtc
,RTC_FLAG_TSF
);
500 /* Get the status of the Interrupt */
501 if(__HAL_RTC_TAMPER_GET_IT(hrtc
,RTC_IT_TAMP1
))
503 /* Get the TAMPER Interrupt enable bit and pending bit */
504 if(((hrtc
->Instance
->TAFCR
& (RTC_TAFCR_TAMPIE
))) != (uint32_t)RESET
)
506 /* Tamper callback */
507 HAL_RTCEx_Tamper1EventCallback(hrtc
);
509 /* Clear the Tamper interrupt pending bit */
510 __HAL_RTC_TAMPER_CLEAR_FLAG(hrtc
,RTC_FLAG_TAMP1F
);
514 /* Get the status of the Interrupt */
515 if(__HAL_RTC_TAMPER_GET_IT(hrtc
, RTC_IT_TAMP2
))
517 /* Get the TAMPER Interrupt enable bit and pending bit */
518 if(((hrtc
->Instance
->TAFCR
& RTC_TAFCR_TAMPIE
)) != (uint32_t)RESET
)
520 /* Tamper callback */
521 HAL_RTCEx_Tamper2EventCallback(hrtc
);
523 /* Clear the Tamper interrupt pending bit */
524 __HAL_RTC_TAMPER_CLEAR_FLAG(hrtc
, RTC_FLAG_TAMP2F
);
528 #if defined(STM32F071xB) || defined(STM32F072xB) || defined(STM32F078xx) || defined(STM32F091xC) || defined(STM32F098xx)
529 /* Get the status of the Interrupt */
530 if(__HAL_RTC_TAMPER_GET_IT(hrtc
, RTC_IT_TAMP3
))
532 /* Get the TAMPER Interrupt enable bit and pending bit */
533 if(((hrtc
->Instance
->TAFCR
& RTC_TAFCR_TAMPIE
)) != (uint32_t)RESET
)
535 /* Tamper callback */
536 HAL_RTCEx_Tamper3EventCallback(hrtc
);
538 /* Clear the Tamper interrupt pending bit */
539 __HAL_RTC_TAMPER_CLEAR_FLAG(hrtc
, RTC_FLAG_TAMP3F
);
544 /* Clear the EXTI's Flag for RTC TimeStamp and Tamper */
545 __HAL_RTC_EXTI_CLEAR_FLAG(RTC_EXTI_LINE_TAMPER_TIMESTAMP_EVENT
);
547 /* Change RTC state */
548 hrtc
->State
= HAL_RTC_STATE_READY
;
552 * @brief TimeStamp callback.
553 * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains
554 * the configuration information for RTC.
557 __weak
void HAL_RTCEx_TimeStampEventCallback(RTC_HandleTypeDef
*hrtc
)
559 /* NOTE : This function Should not be modified, when the callback is needed,
560 the HAL_RTCEx_TimeStampEventCallback could be implemented in the user file
565 * @brief Tamper 1 callback.
566 * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains
567 * the configuration information for RTC.
570 __weak
void HAL_RTCEx_Tamper1EventCallback(RTC_HandleTypeDef
*hrtc
)
572 /* NOTE : This function Should not be modified, when the callback is needed,
573 the HAL_RTCEx_Tamper1EventCallback could be implemented in the user file
578 * @brief Tamper 2 callback.
579 * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains
580 * the configuration information for RTC.
583 __weak
void HAL_RTCEx_Tamper2EventCallback(RTC_HandleTypeDef
*hrtc
)
585 /* NOTE : This function Should not be modified, when the callback is needed,
586 the HAL_RTCEx_Tamper2EventCallback could be implemented in the user file
590 #if defined(STM32F071xB) || defined(STM32F072xB) || defined(STM32F078xx) || defined(STM32F091xC) || defined(STM32F098xx) || defined(STM32F070xB) || defined(STM32F030xC)
592 * @brief Tamper 3 callback.
593 * @param hrtc: RTC handle
596 __weak
void HAL_RTCEx_Tamper3EventCallback(RTC_HandleTypeDef
*hrtc
)
598 /* NOTE : This function Should not be modified, when the callback is needed,
599 the HAL_RTCEx_Tamper3EventCallback could be implemented in the user file
605 * @brief This function handles TimeStamp polling request.
606 * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains
607 * the configuration information for RTC.
608 * @param Timeout: Timeout duration
611 HAL_StatusTypeDef
HAL_RTCEx_PollForTimeStampEvent(RTC_HandleTypeDef
*hrtc
, uint32_t Timeout
)
613 uint32_t tickstart
= 0;
616 tickstart
= HAL_GetTick();
618 while(__HAL_RTC_TIMESTAMP_GET_FLAG(hrtc
, RTC_FLAG_TSF
) == RESET
)
620 if(__HAL_RTC_TIMESTAMP_GET_FLAG(hrtc
, RTC_FLAG_TSOVF
) != RESET
)
622 /* Clear the TIMESTAMP Overrun Flag */
623 __HAL_RTC_TIMESTAMP_CLEAR_FLAG(hrtc
, RTC_FLAG_TSOVF
);
625 /* Change TIMESTAMP state */
626 hrtc
->State
= HAL_RTC_STATE_ERROR
;
631 if(Timeout
!= HAL_MAX_DELAY
)
633 if((Timeout
== 0) || ((HAL_GetTick() - tickstart
) > Timeout
))
635 hrtc
->State
= HAL_RTC_STATE_TIMEOUT
;
641 /* Change RTC state */
642 hrtc
->State
= HAL_RTC_STATE_READY
;
648 * @brief This function handles Tamper1 Polling.
649 * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains
650 * the configuration information for RTC.
651 * @param Timeout: Timeout duration
654 HAL_StatusTypeDef
HAL_RTCEx_PollForTamper1Event(RTC_HandleTypeDef
*hrtc
, uint32_t Timeout
)
656 uint32_t tickstart
= 0;
659 tickstart
= HAL_GetTick();
661 /* Get the status of the Interrupt */
662 while(__HAL_RTC_TAMPER_GET_FLAG(hrtc
,RTC_FLAG_TAMP1F
)== RESET
)
664 if(Timeout
!= HAL_MAX_DELAY
)
666 if((Timeout
== 0) || ((HAL_GetTick() - tickstart
) > Timeout
))
668 hrtc
->State
= HAL_RTC_STATE_TIMEOUT
;
674 /* Clear the Tamper Flag */
675 __HAL_RTC_TAMPER_CLEAR_FLAG(hrtc
,RTC_FLAG_TAMP1F
);
677 /* Change RTC state */
678 hrtc
->State
= HAL_RTC_STATE_READY
;
684 * @brief This function handles Tamper2 Polling.
685 * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains
686 * the configuration information for RTC.
687 * @param Timeout: Timeout duration
690 HAL_StatusTypeDef
HAL_RTCEx_PollForTamper2Event(RTC_HandleTypeDef
*hrtc
, uint32_t Timeout
)
692 uint32_t tickstart
= 0;
695 tickstart
= HAL_GetTick();
697 /* Get the status of the Interrupt */
698 while(__HAL_RTC_TAMPER_GET_FLAG(hrtc
,RTC_FLAG_TAMP2F
) == RESET
)
700 if(Timeout
!= HAL_MAX_DELAY
)
702 if((Timeout
== 0) || ((HAL_GetTick() - tickstart
) > Timeout
))
704 hrtc
->State
= HAL_RTC_STATE_TIMEOUT
;
710 /* Clear the Tamper Flag */
711 __HAL_RTC_TAMPER_CLEAR_FLAG(hrtc
,RTC_FLAG_TAMP2F
);
713 /* Change RTC state */
714 hrtc
->State
= HAL_RTC_STATE_READY
;
719 #if defined(STM32F071xB) || defined(STM32F072xB) || defined(STM32F078xx) || defined(STM32F091xC) || defined(STM32F098xx)
721 * @brief This function handles Tamper3 Polling.
722 * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains
723 * the configuration information for RTC.
724 * @param Timeout: Timeout duration
727 HAL_StatusTypeDef
HAL_RTCEx_PollForTamper3Event(RTC_HandleTypeDef
*hrtc
, uint32_t Timeout
)
729 uint32_t tickstart
= 0;
732 tickstart
= HAL_GetTick();
734 /* Get the status of the Interrupt */
735 while(__HAL_RTC_TAMPER_GET_FLAG(hrtc
,RTC_FLAG_TAMP3F
) == RESET
)
737 if(Timeout
!= HAL_MAX_DELAY
)
739 if((Timeout
== 0) || ((HAL_GetTick() - tickstart
) > Timeout
))
741 hrtc
->State
= HAL_RTC_STATE_TIMEOUT
;
747 /* Clear the Tamper Flag */
748 __HAL_RTC_TAMPER_CLEAR_FLAG(hrtc
,RTC_FLAG_TAMP3F
);
750 /* Change RTC state */
751 hrtc
->State
= HAL_RTC_STATE_READY
;
761 #if defined(STM32F071xB) || defined(STM32F072xB) || defined(STM32F078xx) || defined(STM32F091xC) || defined(STM32F098xx)
762 /** @defgroup RTCEx_Exported_Functions_Group2 RTC Wake-up functions
763 * @brief RTC Wake-up functions
766 ===============================================================================
767 ##### RTC Wake-up functions #####
768 ===============================================================================
770 [..] This section provides functions allowing to configure Wake-up feature
777 * @brief Sets wake up timer.
778 * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains
779 * the configuration information for RTC.
780 * @param WakeUpCounter: Wake up counter
781 * @param WakeUpClock: Wake up clock
784 HAL_StatusTypeDef
HAL_RTCEx_SetWakeUpTimer(RTC_HandleTypeDef
*hrtc
, uint32_t WakeUpCounter
, uint32_t WakeUpClock
)
786 uint32_t tickstart
= 0;
788 /* Check the parameters */
789 assert_param(IS_WAKEUP_CLOCK(WakeUpClock
));
790 assert_param(IS_WAKEUP_COUNTER(WakeUpCounter
));
795 hrtc
->State
= HAL_RTC_STATE_BUSY
;
797 /* Disable the write protection for RTC registers */
798 __HAL_RTC_WRITEPROTECTION_DISABLE(hrtc
);
800 __HAL_RTC_WAKEUPTIMER_DISABLE(hrtc
);
803 tickstart
= HAL_GetTick();
805 /* Wait till RTC WUTWF flag is set and if Time out is reached exit */
806 while(__HAL_RTC_WAKEUPTIMER_GET_FLAG(hrtc
, RTC_FLAG_WUTWF
) == RESET
)
808 if((HAL_GetTick()-tickstart
) > RTC_TIMEOUT_VALUE
)
810 /* Enable the write protection for RTC registers */
811 __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc
);
813 hrtc
->State
= HAL_RTC_STATE_TIMEOUT
;
815 /* Process Unlocked */
822 /* Clear the Wake-up Timer clock source bits in CR register */
823 hrtc
->Instance
->CR
&= (uint32_t)~RTC_CR_WUCKSEL
;
825 /* Configure the clock source */
826 hrtc
->Instance
->CR
|= (uint32_t)WakeUpClock
;
828 /* Configure the Wake-up Timer counter */
829 hrtc
->Instance
->WUTR
= (uint32_t)WakeUpCounter
;
831 /* Enable the Wake-up Timer */
832 __HAL_RTC_WAKEUPTIMER_ENABLE(hrtc
);
834 /* Enable the write protection for RTC registers */
835 __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc
);
837 hrtc
->State
= HAL_RTC_STATE_READY
;
839 /* Process Unlocked */
846 * @brief Sets wake up timer with interrupt
847 * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains
848 * the configuration information for RTC.
849 * @param WakeUpCounter: Wake up counter
850 * @param WakeUpClock: Wake up clock
853 HAL_StatusTypeDef
HAL_RTCEx_SetWakeUpTimer_IT(RTC_HandleTypeDef
*hrtc
, uint32_t WakeUpCounter
, uint32_t WakeUpClock
)
855 uint32_t tickstart
= 0;
857 /* Check the parameters */
858 assert_param(IS_WAKEUP_CLOCK(WakeUpClock
));
859 assert_param(IS_WAKEUP_COUNTER(WakeUpCounter
));
864 hrtc
->State
= HAL_RTC_STATE_BUSY
;
866 /* Disable the write protection for RTC registers */
867 __HAL_RTC_WRITEPROTECTION_DISABLE(hrtc
);
869 __HAL_RTC_WAKEUPTIMER_DISABLE(hrtc
);
872 tickstart
= HAL_GetTick();
874 /* Wait till RTC WUTWF flag is set and if Time out is reached exit */
875 while(__HAL_RTC_WAKEUPTIMER_GET_FLAG(hrtc
, RTC_FLAG_WUTWF
) == RESET
)
877 if((HAL_GetTick()-tickstart
) > RTC_TIMEOUT_VALUE
)
879 /* Enable the write protection for RTC registers */
880 __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc
);
882 hrtc
->State
= HAL_RTC_STATE_TIMEOUT
;
884 /* Process Unlocked */
891 /* Configure the Wake-up Timer counter */
892 hrtc
->Instance
->WUTR
= (uint32_t)WakeUpCounter
;
894 /* Clear the Wake-up Timer clock source bits in CR register */
895 hrtc
->Instance
->CR
&= (uint32_t)~RTC_CR_WUCKSEL
;
897 /* Configure the clock source */
898 hrtc
->Instance
->CR
|= (uint32_t)WakeUpClock
;
900 /* RTC WakeUpTimer Interrupt Configuration: EXTI configuration */
901 __HAL_RTC_EXTI_ENABLE_IT(RTC_EXTI_LINE_WAKEUPTIMER_EVENT
);
903 EXTI
->RTSR
|= RTC_EXTI_LINE_WAKEUPTIMER_EVENT
;
905 /* Configure the Interrupt in the RTC_CR register */
906 __HAL_RTC_WAKEUPTIMER_ENABLE_IT(hrtc
,RTC_IT_WUT
);
908 /* Enable the Wake-up Timer */
909 __HAL_RTC_WAKEUPTIMER_ENABLE(hrtc
);
911 /* Enable the write protection for RTC registers */
912 __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc
);
914 hrtc
->State
= HAL_RTC_STATE_READY
;
916 /* Process Unlocked */
923 * @brief Deactivates wake up timer counter.
924 * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains
925 * the configuration information for RTC.
928 uint32_t HAL_RTCEx_DeactivateWakeUpTimer(RTC_HandleTypeDef
*hrtc
)
930 uint32_t tickstart
= 0;
935 hrtc
->State
= HAL_RTC_STATE_BUSY
;
937 /* Disable the write protection for RTC registers */
938 __HAL_RTC_WRITEPROTECTION_DISABLE(hrtc
);
940 /* Disable the Wake-up Timer */
941 __HAL_RTC_WAKEUPTIMER_DISABLE(hrtc
);
943 /* In case of interrupt mode is used, the interrupt source must disabled */
944 __HAL_RTC_WAKEUPTIMER_DISABLE_IT(hrtc
,RTC_IT_WUT
);
947 tickstart
= HAL_GetTick();
949 /* Wait till RTC WUTWF flag is set and if Time out is reached exit */
950 while(__HAL_RTC_WAKEUPTIMER_GET_FLAG(hrtc
, RTC_FLAG_WUTWF
) == RESET
)
952 if((HAL_GetTick()-tickstart
) > RTC_TIMEOUT_VALUE
)
954 /* Enable the write protection for RTC registers */
955 __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc
);
957 hrtc
->State
= HAL_RTC_STATE_TIMEOUT
;
959 /* Process Unlocked */
966 /* Enable the write protection for RTC registers */
967 __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc
);
969 hrtc
->State
= HAL_RTC_STATE_READY
;
971 /* Process Unlocked */
978 * @brief Gets wake up timer counter.
979 * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains
980 * the configuration information for RTC.
981 * @retval Counter value
983 uint32_t HAL_RTCEx_GetWakeUpTimer(RTC_HandleTypeDef
*hrtc
)
985 /* Get the counter value */
986 return ((uint32_t)(hrtc
->Instance
->WUTR
& RTC_WUTR_WUT
));
990 * @brief This function handles Wake Up Timer interrupt request.
991 * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains
992 * the configuration information for RTC.
995 void HAL_RTCEx_WakeUpTimerIRQHandler(RTC_HandleTypeDef
*hrtc
)
997 if(__HAL_RTC_WAKEUPTIMER_GET_IT(hrtc
, RTC_IT_WUT
))
999 /* Get the status of the Interrupt */
1000 if((uint32_t)(hrtc
->Instance
->CR
& RTC_IT_WUT
) != (uint32_t)RESET
)
1002 /* WAKEUPTIMER callback */
1003 HAL_RTCEx_WakeUpTimerEventCallback(hrtc
);
1005 /* Clear the WAKEUPTIMER interrupt pending bit */
1006 __HAL_RTC_WAKEUPTIMER_CLEAR_FLAG(hrtc
, RTC_FLAG_WUTF
);
1010 /* Clear the EXTI's line Flag for RTC WakeUpTimer */
1011 __HAL_RTC_EXTI_CLEAR_FLAG(RTC_EXTI_LINE_WAKEUPTIMER_EVENT
);
1013 /* Change RTC state */
1014 hrtc
->State
= HAL_RTC_STATE_READY
;
1018 * @brief Wake Up Timer callback.
1019 * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains
1020 * the configuration information for RTC.
1023 __weak
void HAL_RTCEx_WakeUpTimerEventCallback(RTC_HandleTypeDef
*hrtc
)
1025 /* NOTE : This function Should not be modified, when the callback is needed,
1026 the HAL_RTCEx_WakeUpTimerEventCallback could be implemented in the user file
1031 * @brief This function handles Wake Up Timer Polling.
1032 * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains
1033 * the configuration information for RTC.
1034 * @param Timeout: Timeout duration
1035 * @retval HAL status
1037 HAL_StatusTypeDef
HAL_RTCEx_PollForWakeUpTimerEvent(RTC_HandleTypeDef
*hrtc
, uint32_t Timeout
)
1039 uint32_t tickstart
= 0;
1042 tickstart
= HAL_GetTick();
1044 while(__HAL_RTC_WAKEUPTIMER_GET_FLAG(hrtc
, RTC_FLAG_WUTF
) == RESET
)
1046 if(Timeout
!= HAL_MAX_DELAY
)
1048 if((Timeout
== 0) || ((HAL_GetTick() - tickstart
) > Timeout
))
1050 hrtc
->State
= HAL_RTC_STATE_TIMEOUT
;
1057 /* Clear the WAKEUPTIMER Flag */
1058 __HAL_RTC_WAKEUPTIMER_CLEAR_FLAG(hrtc
, RTC_FLAG_WUTF
);
1060 /* Change RTC state */
1061 hrtc
->State
= HAL_RTC_STATE_READY
;
1069 #endif /* defined(STM32F071xB) || defined(STM32F072xB) || defined(STM32F078xx) || defined(STM32F091xC) || defined(STM32F098xx) */
1071 /** @defgroup RTCEx_Exported_Functions_Group3 Extension Peripheral Control functions
1072 * @brief Extension Peripheral Control functions
1075 ===============================================================================
1076 ##### Extension Peripheral Control functions #####
1077 ===============================================================================
1079 This subsection provides functions allowing to
1080 (+) Write a data in a specified RTC Backup data register
1081 (+) Read a data in a specified RTC Backup data register
1082 (+) Set the Coarse calibration parameters.
1083 (+) Deactivate the Coarse calibration parameters
1084 (+) Set the Smooth calibration parameters.
1085 (+) Configure the Synchronization Shift Control Settings.
1086 (+) Configure the Calibration Pinout (RTC_CALIB) Selection (1Hz or 512Hz).
1087 (+) Deactivate the Calibration Pinout (RTC_CALIB) Selection (1Hz or 512Hz).
1088 (+) Enable the RTC reference clock detection.
1089 (+) Disable the RTC reference clock detection.
1090 (+) Enable the Bypass Shadow feature.
1091 (+) Disable the Bypass Shadow feature.
1097 #if !defined(STM32F030x6) && !defined(STM32F030x8) && !defined(STM32F070x6) && !defined(STM32F070xB) && !defined(STM32F030xC)
1099 * @brief Writes a data in a specified RTC Backup data register.
1100 * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains
1101 * the configuration information for RTC.
1102 * @param BackupRegister: RTC Backup data Register number.
1103 * This parameter can be: RTC_BKP_DRx where x can be from 0 to 4 to
1104 * specify the register.
1105 * @param Data: Data to be written in the specified RTC Backup data register.
1108 void HAL_RTCEx_BKUPWrite(RTC_HandleTypeDef
*hrtc
, uint32_t BackupRegister
, uint32_t Data
)
1112 /* Check the parameters */
1113 assert_param(IS_RTC_BKP(BackupRegister
));
1115 tmp
= (uint32_t)&(hrtc
->Instance
->BKP0R
);
1116 tmp
+= (BackupRegister
* 4);
1118 /* Write the specified register */
1119 *(__IO
uint32_t *)tmp
= (uint32_t)Data
;
1123 * @brief Reads data from the specified RTC Backup data Register.
1124 * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains
1125 * the configuration information for RTC.
1126 * @param BackupRegister: RTC Backup data Register number.
1127 * This parameter can be: RTC_BKP_DRx where x can be from 0 to 4 to
1128 * specify the register.
1129 * @retval Read value
1131 uint32_t HAL_RTCEx_BKUPRead(RTC_HandleTypeDef
*hrtc
, uint32_t BackupRegister
)
1135 /* Check the parameters */
1136 assert_param(IS_RTC_BKP(BackupRegister
));
1138 tmp
= (uint32_t)&(hrtc
->Instance
->BKP0R
);
1139 tmp
+= (BackupRegister
* 4);
1141 /* Read the specified register */
1142 return (*(__IO
uint32_t *)tmp
);
1144 #endif /* !defined(STM32F030x6) && !defined(STM32F030x8) && !defined(STM32F070x6) && !defined(STM32F070xB) && !defined(STM32F030xC) */
1147 * @brief Sets the Smooth calibration parameters.
1148 * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains
1149 * the configuration information for RTC.
1150 * @param SmoothCalibPeriod: Select the Smooth Calibration Period.
1151 * This parameter can be can be one of the following values :
1152 * @arg RTC_SMOOTHCALIB_PERIOD_32SEC: The smooth calibration period is 32s.
1153 * @arg RTC_SMOOTHCALIB_PERIOD_16SEC: The smooth calibration period is 16s.
1154 * @arg RTC_SMOOTHCALIB_PERIOD_8SEC: The smooth calibration period is 8s.
1155 * @param SmoothCalibPlusPulses: Select to Set or reset the CALP bit.
1156 * This parameter can be one of the following values:
1157 * @arg RTC_SMOOTHCALIB_PLUSPULSES_SET: Add one RTCCLK pulse every 2*11 pulses.
1158 * @arg RTC_SMOOTHCALIB_PLUSPULSES_RESET: No RTCCLK pulses are added.
1159 * @param SmouthCalibMinusPulsesValue: Select the value of CALM[8:0] bits.
1160 * This parameter can be one any value from 0 to 0x000001FF.
1161 * @note To deactivate the smooth calibration, the field SmoothCalibPlusPulses
1162 * must be equal to SMOOTHCALIB_PLUSPULSES_RESET and the field
1163 * SmouthCalibMinusPulsesValue must be equal to 0.
1164 * @retval HAL status
1166 HAL_StatusTypeDef
HAL_RTCEx_SetSmoothCalib(RTC_HandleTypeDef
* hrtc
, uint32_t SmoothCalibPeriod
, uint32_t SmoothCalibPlusPulses
, uint32_t SmouthCalibMinusPulsesValue
)
1168 uint32_t tickstart
= 0;
1170 /* Check the parameters */
1171 assert_param(IS_RTC_SMOOTH_CALIB_PERIOD(SmoothCalibPeriod
));
1172 assert_param(IS_RTC_SMOOTH_CALIB_PLUS(SmoothCalibPlusPulses
));
1173 assert_param(IS_RTC_SMOOTH_CALIB_MINUS(SmouthCalibMinusPulsesValue
));
1175 /* Process Locked */
1178 hrtc
->State
= HAL_RTC_STATE_BUSY
;
1180 /* Disable the write protection for RTC registers */
1181 __HAL_RTC_WRITEPROTECTION_DISABLE(hrtc
);
1183 /* check if a calibration is pending*/
1184 if((hrtc
->Instance
->ISR
& RTC_ISR_RECALPF
) != RESET
)
1187 tickstart
= HAL_GetTick();
1189 /* check if a calibration is pending*/
1190 while((hrtc
->Instance
->ISR
& RTC_ISR_RECALPF
) != RESET
)
1192 if((HAL_GetTick()-tickstart
) > RTC_TIMEOUT_VALUE
)
1194 /* Enable the write protection for RTC registers */
1195 __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc
);
1197 /* Change RTC state */
1198 hrtc
->State
= HAL_RTC_STATE_TIMEOUT
;
1200 /* Process Unlocked */
1208 /* Configure the Smooth calibration settings */
1209 hrtc
->Instance
->CALR
= (uint32_t)((uint32_t)SmoothCalibPeriod
| (uint32_t)SmoothCalibPlusPulses
| (uint32_t)SmouthCalibMinusPulsesValue
);
1211 /* Enable the write protection for RTC registers */
1212 __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc
);
1214 /* Change RTC state */
1215 hrtc
->State
= HAL_RTC_STATE_READY
;
1217 /* Process Unlocked */
1224 * @brief Configures the Synchronization Shift Control Settings.
1225 * @note When REFCKON is set, firmware must not write to Shift control register.
1226 * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains
1227 * the configuration information for RTC.
1228 * @param ShiftAdd1S: Select to add or not 1 second to the time calendar.
1229 * This parameter can be one of the following values :
1230 * @arg RTC_SHIFTADD1S_SET: Add one second to the clock calendar.
1231 * @arg RTC_SHIFTADD1S_RESET: No effect.
1232 * @param ShiftSubFS: Select the number of Second Fractions to substitute.
1233 * This parameter can be one any value from 0 to 0x7FFF.
1234 * @retval HAL status
1236 HAL_StatusTypeDef
HAL_RTCEx_SetSynchroShift(RTC_HandleTypeDef
* hrtc
, uint32_t ShiftAdd1S
, uint32_t ShiftSubFS
)
1238 uint32_t tickstart
= 0;
1240 /* Check the parameters */
1241 assert_param(IS_RTC_SHIFT_ADD1S(ShiftAdd1S
));
1242 assert_param(IS_RTC_SHIFT_SUBFS(ShiftSubFS
));
1244 /* Process Locked */
1247 hrtc
->State
= HAL_RTC_STATE_BUSY
;
1249 /* Disable the write protection for RTC registers */
1250 __HAL_RTC_WRITEPROTECTION_DISABLE(hrtc
);
1253 tickstart
= HAL_GetTick();
1255 /* Wait until the shift is completed*/
1256 while((hrtc
->Instance
->ISR
& RTC_ISR_SHPF
) != RESET
)
1258 if((HAL_GetTick()-tickstart
) > RTC_TIMEOUT_VALUE
)
1260 /* Enable the write protection for RTC registers */
1261 __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc
);
1263 hrtc
->State
= HAL_RTC_STATE_TIMEOUT
;
1265 /* Process Unlocked */
1272 /* Check if the reference clock detection is disabled */
1273 if((hrtc
->Instance
->CR
& RTC_CR_REFCKON
) == RESET
)
1275 /* Configure the Shift settings */
1276 hrtc
->Instance
->SHIFTR
= (uint32_t)(uint32_t)(ShiftSubFS
) | (uint32_t)(ShiftAdd1S
);
1278 /* If RTC_CR_BYPSHAD bit = 0, wait for synchro else this check is not needed */
1279 if((hrtc
->Instance
->CR
& RTC_CR_BYPSHAD
) == RESET
)
1281 if(HAL_RTC_WaitForSynchro(hrtc
) != HAL_OK
)
1283 /* Enable the write protection for RTC registers */
1284 __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc
);
1286 hrtc
->State
= HAL_RTC_STATE_ERROR
;
1288 /* Process Unlocked */
1297 /* Enable the write protection for RTC registers */
1298 __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc
);
1300 /* Change RTC state */
1301 hrtc
->State
= HAL_RTC_STATE_ERROR
;
1303 /* Process Unlocked */
1309 /* Enable the write protection for RTC registers */
1310 __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc
);
1312 /* Change RTC state */
1313 hrtc
->State
= HAL_RTC_STATE_READY
;
1315 /* Process Unlocked */
1322 * @brief Configures the Calibration Pinout (RTC_CALIB) Selection (1Hz or 512Hz).
1323 * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains
1324 * the configuration information for RTC.
1325 * @param CalibOutput : Select the Calibration output Selection .
1326 * This parameter can be one of the following values:
1327 * @arg RTC_CALIBOUTPUT_512HZ: A signal has a regular waveform at 512Hz.
1328 * @arg RTC_CALIBOUTPUT_1HZ: A signal has a regular waveform at 1Hz.
1329 * @retval HAL status
1331 HAL_StatusTypeDef
HAL_RTCEx_SetCalibrationOutPut(RTC_HandleTypeDef
* hrtc
, uint32_t CalibOutput
)
1333 /* Check the parameters */
1334 assert_param(IS_RTC_CALIB_OUTPUT(CalibOutput
));
1336 /* Process Locked */
1339 hrtc
->State
= HAL_RTC_STATE_BUSY
;
1341 /* Disable the write protection for RTC registers */
1342 __HAL_RTC_WRITEPROTECTION_DISABLE(hrtc
);
1344 /* Clear flags before config */
1345 hrtc
->Instance
->CR
&= (uint32_t)~RTC_CR_COSEL
;
1347 /* Configure the RTC_CR register */
1348 hrtc
->Instance
->CR
|= (uint32_t)CalibOutput
;
1350 __HAL_RTC_CALIBRATION_OUTPUT_ENABLE(hrtc
);
1352 /* Enable the write protection for RTC registers */
1353 __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc
);
1355 /* Change RTC state */
1356 hrtc
->State
= HAL_RTC_STATE_READY
;
1358 /* Process Unlocked */
1365 * @brief Deactivates the Calibration Pinout (RTC_CALIB) Selection (1Hz or 512Hz).
1366 * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains
1367 * the configuration information for RTC.
1368 * @retval HAL status
1370 HAL_StatusTypeDef
HAL_RTCEx_DeactivateCalibrationOutPut(RTC_HandleTypeDef
* hrtc
)
1372 /* Process Locked */
1375 hrtc
->State
= HAL_RTC_STATE_BUSY
;
1377 /* Disable the write protection for RTC registers */
1378 __HAL_RTC_WRITEPROTECTION_DISABLE(hrtc
);
1380 __HAL_RTC_CALIBRATION_OUTPUT_DISABLE(hrtc
);
1382 /* Enable the write protection for RTC registers */
1383 __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc
);
1385 /* Change RTC state */
1386 hrtc
->State
= HAL_RTC_STATE_READY
;
1388 /* Process Unlocked */
1395 * @brief Enables the RTC reference clock detection.
1396 * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains
1397 * the configuration information for RTC.
1398 * @retval HAL status
1400 HAL_StatusTypeDef
HAL_RTCEx_SetRefClock(RTC_HandleTypeDef
* hrtc
)
1402 /* Process Locked */
1405 hrtc
->State
= HAL_RTC_STATE_BUSY
;
1407 /* Disable the write protection for RTC registers */
1408 __HAL_RTC_WRITEPROTECTION_DISABLE(hrtc
);
1410 /* Set Initialization mode */
1411 if(RTC_EnterInitMode(hrtc
) != HAL_OK
)
1413 /* Enable the write protection for RTC registers */
1414 __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc
);
1417 hrtc
->State
= HAL_RTC_STATE_ERROR
;
1419 /* Process Unlocked */
1426 __HAL_RTC_CLOCKREF_DETECTION_ENABLE(hrtc
);
1428 /* Exit Initialization mode */
1429 hrtc
->Instance
->ISR
&= (uint32_t)~RTC_ISR_INIT
;
1432 /* Enable the write protection for RTC registers */
1433 __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc
);
1435 /* Change RTC state */
1436 hrtc
->State
= HAL_RTC_STATE_READY
;
1438 /* Process Unlocked */
1445 * @brief Disable the RTC reference clock detection.
1446 * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains
1447 * the configuration information for RTC.
1448 * @retval HAL status
1450 HAL_StatusTypeDef
HAL_RTCEx_DeactivateRefClock(RTC_HandleTypeDef
* hrtc
)
1452 /* Process Locked */
1455 hrtc
->State
= HAL_RTC_STATE_BUSY
;
1457 /* Disable the write protection for RTC registers */
1458 __HAL_RTC_WRITEPROTECTION_DISABLE(hrtc
);
1460 /* Set Initialization mode */
1461 if(RTC_EnterInitMode(hrtc
) != HAL_OK
)
1463 /* Enable the write protection for RTC registers */
1464 __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc
);
1467 hrtc
->State
= HAL_RTC_STATE_ERROR
;
1469 /* Process Unlocked */
1476 __HAL_RTC_CLOCKREF_DETECTION_DISABLE(hrtc
);
1478 /* Exit Initialization mode */
1479 hrtc
->Instance
->ISR
&= (uint32_t)~RTC_ISR_INIT
;
1482 /* Enable the write protection for RTC registers */
1483 __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc
);
1485 /* Change RTC state */
1486 hrtc
->State
= HAL_RTC_STATE_READY
;
1488 /* Process Unlocked */
1495 * @brief Enables the Bypass Shadow feature.
1496 * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains
1497 * the configuration information for RTC.
1498 * @note When the Bypass Shadow is enabled the calendar value are taken
1499 * directly from the Calendar counter.
1500 * @retval HAL status
1502 HAL_StatusTypeDef
HAL_RTCEx_EnableBypassShadow(RTC_HandleTypeDef
* hrtc
)
1504 /* Process Locked */
1507 hrtc
->State
= HAL_RTC_STATE_BUSY
;
1509 /* Disable the write protection for RTC registers */
1510 __HAL_RTC_WRITEPROTECTION_DISABLE(hrtc
);
1512 /* Set the BYPSHAD bit */
1513 hrtc
->Instance
->CR
|= (uint8_t)RTC_CR_BYPSHAD
;
1515 /* Enable the write protection for RTC registers */
1516 __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc
);
1518 /* Change RTC state */
1519 hrtc
->State
= HAL_RTC_STATE_READY
;
1521 /* Process Unlocked */
1528 * @brief Disables the Bypass Shadow feature.
1529 * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains
1530 * the configuration information for RTC.
1531 * @note When the Bypass Shadow is enabled the calendar value are taken
1532 * directly from the Calendar counter.
1533 * @retval HAL status
1535 HAL_StatusTypeDef
HAL_RTCEx_DisableBypassShadow(RTC_HandleTypeDef
* hrtc
)
1537 /* Process Locked */
1540 hrtc
->State
= HAL_RTC_STATE_BUSY
;
1542 /* Disable the write protection for RTC registers */
1543 __HAL_RTC_WRITEPROTECTION_DISABLE(hrtc
);
1545 /* Reset the BYPSHAD bit */
1546 hrtc
->Instance
->CR
&= (uint8_t)~RTC_CR_BYPSHAD
;
1548 /* Enable the write protection for RTC registers */
1549 __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc
);
1551 /* Change RTC state */
1552 hrtc
->State
= HAL_RTC_STATE_READY
;
1554 /* Process Unlocked */
1568 #endif /* HAL_RTC_MODULE_ENABLED */
1577 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/