2 ******************************************************************************
3 * @file stm32f7xx_hal_rtc.c
4 * @author MCD Application Team
5 * @brief RTC HAL module driver.
6 * This file provides firmware functions to manage the following
7 * functionalities of the Real Time Clock (RTC) peripheral:
8 * + Initialization and de-initialization functions
9 * + RTC Time and Date functions
10 * + RTC Alarm functions
11 * + Peripheral Control functions
12 * + Peripheral State functions
15 ==============================================================================
16 ##### Backup Domain Operating Condition #####
17 ==============================================================================
18 [..] The real-time clock (RTC), the RTC backup registers, and the backup
19 SRAM (BKP SRAM) can be powered from the VBAT voltage when the main
20 VDD supply is powered off.
21 To retain the content of the RTC backup registers, backup SRAM, and supply
22 the RTC when VDD is turned off, VBAT pin can be connected to an optional
23 standby voltage supplied by a battery or by another source.
25 [..] To allow the RTC operating even when the main digital supply (VDD) is turned
26 off, the VBAT pin powers the following blocks:
28 (#) The LSE oscillator
29 (#) The backup SRAM when the low power backup regulator is enabled
30 (#) PC13 to PC15 I/Os, plus PI8 I/O (when available)
32 [..] When the backup domain is supplied by VDD (analog switch connected to VDD),
33 the following pins are available:
34 (#) PC14 and PC15 can be used as either GPIO or LSE pins
35 (#) PC13 can be used as a GPIO or as the RTC_AF1 pin
36 (#) PI8 can be used as a GPIO or as the RTC_AF2 pin
38 [..] When the backup domain is supplied by VBAT (analog switch connected to VBAT
39 because VDD is not present), the following pins are available:
40 (#) PC14 and PC15 can be used as LSE pins only
41 (#) PC13 can be used as the RTC_AF1 pin
42 (#) PI8 can be used as the RTC_AF2 pin
43 (#) PC1 can be used as the RTC_AF3 pin
45 ##### Backup Domain Reset #####
46 ==================================================================
47 [..] The backup domain reset sets all RTC registers and the RCC_BDCR register
48 to their reset values. The BKPSRAM is not affected by this reset. The only
49 way to reset the BKPSRAM is through the Flash interface by requesting
50 a protection level change from 1 to 0.
51 [..] A backup domain reset is generated when one of the following events occurs:
52 (#) Software reset, triggered by setting the BDRST bit in the
53 RCC Backup domain control register (RCC_BDCR).
54 (#) VDD or VBAT power on, if both supplies have previously been powered off.
56 ##### Backup Domain Access #####
57 ==================================================================
58 [..] After reset, the backup domain (RTC registers, RTC backup data
59 registers and backup SRAM) is protected against possible unwanted write
61 [..] To enable access to the RTC Domain and RTC registers, proceed as follows:
62 (+) Enable the Power Controller (PWR) APB1 interface clock using the
63 __HAL_RCC_PWR_CLK_ENABLE() function.
64 (+) Enable access to RTC domain using the HAL_PWR_EnableBkUpAccess() function.
65 (+) Select the RTC clock source using the __HAL_RCC_RTC_CONFIG() function.
66 (+) Enable RTC Clock using the __HAL_RCC_RTC_ENABLE() function.
69 ##### How to use this driver #####
70 ==================================================================
72 (+) Enable the RTC domain access (see description in the section above).
73 (+) Configure the RTC Prescaler (Asynchronous and Synchronous) and RTC hour
74 format using the HAL_RTC_Init() function.
76 *** Time and Date configuration ***
77 ===================================
79 (+) To configure the RTC Calendar (Time and Date) use the HAL_RTC_SetTime()
80 and HAL_RTC_SetDate() functions.
81 (+) To read the RTC Calendar, use the HAL_RTC_GetTime() and HAL_RTC_GetDate() functions.
83 *** Alarm configuration ***
84 ===========================
86 (+) To configure the RTC Alarm use the HAL_RTC_SetAlarm() function.
87 You can also configure the RTC Alarm with interrupt mode using the HAL_RTC_SetAlarm_IT() function.
88 (+) To read the RTC Alarm, use the HAL_RTC_GetAlarm() function.
90 ##### RTC and low power modes #####
91 ==================================================================
92 [..] The MCU can be woken up from a low power mode by an RTC alternate
94 [..] The RTC alternate functions are the RTC alarms (Alarm A and Alarm B),
95 RTC wake-up, RTC tamper event detection and RTC time stamp event detection.
96 These RTC alternate functions can wake up the system from the Stop and
97 Standby low power modes.
98 [..] The system can also wake up from low power modes without depending
99 on an external interrupt (Auto-wake-up mode), by using the RTC alarm
100 or the RTC wake-up events.
101 [..] The RTC provides a programmable time base for waking up from the
102 Stop or Standby mode at regular intervals.
103 Wake-up from STOP and STANDBY modes is possible only when the RTC clock source
106 *** Callback registration ***
107 =============================================
109 The compilation define USE_HAL_RTC_REGISTER_CALLBACKS when set to 1
110 allows the user to configure dynamically the driver callbacks.
111 Use Function @ref HAL_RTC_RegisterCallback() to register an interrupt callback.
113 Function @ref HAL_RTC_RegisterCallback() allows to register following callbacks:
114 (+) AlarmAEventCallback : RTC Alarm A Event callback.
115 (+) AlarmBEventCallback : RTC Alarm B Event callback.
116 (+) TimeStampEventCallback : RTC TimeStamp Event callback.
117 (+) WakeUpTimerEventCallback : RTC WakeUpTimer Event callback.
118 (+) Tamper1EventCallback : RTC Tamper 1 Event callback.
119 (+) Tamper2EventCallback : RTC Tamper 2 Event callback.
120 (+) Tamper3EventCallback : RTC Tamper 3 Event callback.
121 (+) MspInitCallback : RTC MspInit callback.
122 (+) MspDeInitCallback : RTC MspDeInit callback.
123 This function takes as parameters the HAL peripheral handle, the Callback ID
124 and a pointer to the user callback function.
126 Use function @ref HAL_RTC_UnRegisterCallback() to reset a callback to the default
128 @ref HAL_RTC_UnRegisterCallback() takes as parameters the HAL peripheral handle,
130 This function allows to reset following callbacks:
131 (+) AlarmAEventCallback : RTC Alarm A Event callback.
132 (+) AlarmBEventCallback : RTC Alarm B Event callback.
133 (+) TimeStampEventCallback : RTC TimeStamp Event callback.
134 (+) WakeUpTimerEventCallback : RTC WakeUpTimer Event callback.
135 (+) Tamper1EventCallback : RTC Tamper 1 Event callback.
136 (+) Tamper2EventCallback : RTC Tamper 2 Event callback.
137 (+) Tamper3EventCallback : RTC Tamper 3 Event callback.
138 (+) MspInitCallback : RTC MspInit callback.
139 (+) MspDeInitCallback : RTC MspDeInit callback.
141 By default, after the @ref HAL_RTC_Init() and when the state is HAL_RTC_STATE_RESET,
142 all callbacks are set to the corresponding weak functions :
143 examples @ref AlarmAEventCallback(), @ref WakeUpTimerEventCallback().
144 Exception done for MspInit and MspDeInit callbacks that are reset to the legacy weak function
145 in the @ref HAL_RTC_Init()/@ref HAL_RTC_DeInit() only when these callbacks are null
146 (not registered beforehand).
147 If not, MspInit or MspDeInit are not null, @ref HAL_RTC_Init()/@ref HAL_RTC_DeInit()
148 keep and use the user MspInit/MspDeInit callbacks (registered beforehand)
150 Callbacks can be registered/unregistered in HAL_RTC_STATE_READY state only.
151 Exception done MspInit/MspDeInit that can be registered/unregistered
152 in HAL_RTC_STATE_READY or HAL_RTC_STATE_RESET state,
153 thus registered (user) MspInit/DeInit callbacks can be used during the Init/DeInit.
154 In that case first register the MspInit/MspDeInit user callbacks
155 using @ref HAL_RTC_RegisterCallback() before calling @ref HAL_RTC_DeInit()
156 or @ref HAL_RTC_Init() function.
158 When The compilation define USE_HAL_RTC_REGISTER_CALLBACKS is set to 0 or
159 not defined, the callback registration feature is not available and all callbacks
160 are set to the corresponding weak functions.
163 ******************************************************************************
166 * <h2><center>© Copyright (c) 2017 STMicroelectronics.
167 * All rights reserved.</center></h2>
169 * This software component is licensed by ST under BSD 3-Clause license,
170 * the "License"; You may not use this file except in compliance with the
171 * License. You may obtain a copy of the License at:
172 * opensource.org/licenses/BSD-3-Clause
174 ******************************************************************************
177 /* Includes ------------------------------------------------------------------*/
178 #include "stm32f7xx_hal.h"
180 /** @addtogroup STM32F7xx_HAL_Driver
184 /** @defgroup RTC RTC
185 * @brief RTC HAL module driver
189 #ifdef HAL_RTC_MODULE_ENABLED
191 /* Private typedef -----------------------------------------------------------*/
192 /* Private define ------------------------------------------------------------*/
193 /* Private macro -------------------------------------------------------------*/
194 /* Private variables ---------------------------------------------------------*/
195 /* Private function prototypes -----------------------------------------------*/
196 /* Exported functions --------------------------------------------------------*/
198 /** @defgroup RTC_Exported_Functions RTC Exported Functions
202 /** @defgroup RTC_Group1 Initialization and de-initialization functions
203 * @brief Initialization and Configuration functions
206 ===============================================================================
207 ##### Initialization and de-initialization functions #####
208 ===============================================================================
209 [..] This section provides functions allowing to initialize and configure the
210 RTC Prescaler (Synchronous and Asynchronous), RTC Hour format, disable
211 RTC registers Write protection, enter and exit the RTC initialization mode,
212 RTC registers synchronization check and reference clock detection enable.
213 (#) The RTC Prescaler is programmed to generate the RTC 1Hz time base.
214 It is split into 2 programmable prescalers to minimize power consumption.
215 (++) A 7-bit asynchronous prescaler and a 13-bit synchronous prescaler.
216 (++) When both prescalers are used, it is recommended to configure the
217 asynchronous prescaler to a high value to minimize power consumption.
218 (#) All RTC registers are Write protected. Writing to the RTC registers
219 is enabled by writing a key into the Write Protection register, RTC_WPR.
220 (#) To configure the RTC Calendar, user application should enter
221 initialization mode. In this mode, the calendar counter is stopped
222 and its value can be updated. When the initialization sequence is
223 complete, the calendar restarts counting after 4 RTCCLK cycles.
224 (#) To read the calendar through the shadow registers after Calendar
225 initialization, calendar update or after wake-up from low power modes
226 the software must first clear the RSF flag. The software must then
227 wait until it is set again before reading the calendar, which means
228 that the calendar registers have been correctly copied into the
229 RTC_TR and RTC_DR shadow registers.The HAL_RTC_WaitForSynchro() function
230 implements the above software sequence (RSF clear and RSF check).
237 * @brief Initializes the RTC peripheral
238 * @param hrtc pointer to a RTC_HandleTypeDef structure that contains
239 * the configuration information for RTC.
242 HAL_StatusTypeDef
HAL_RTC_Init(RTC_HandleTypeDef
*hrtc
)
244 /* Check the RTC peripheral state */
250 /* Check the parameters */
251 assert_param(IS_RTC_ALL_INSTANCE(hrtc
->Instance
));
252 assert_param(IS_RTC_HOUR_FORMAT(hrtc
->Init
.HourFormat
));
253 assert_param(IS_RTC_ASYNCH_PREDIV(hrtc
->Init
.AsynchPrediv
));
254 assert_param(IS_RTC_SYNCH_PREDIV(hrtc
->Init
.SynchPrediv
));
255 assert_param (IS_RTC_OUTPUT(hrtc
->Init
.OutPut
));
256 assert_param (IS_RTC_OUTPUT_POL(hrtc
->Init
.OutPutPolarity
));
257 assert_param(IS_RTC_OUTPUT_TYPE(hrtc
->Init
.OutPutType
));
259 #if (USE_HAL_RTC_REGISTER_CALLBACKS == 1)
260 if(hrtc
->State
== HAL_RTC_STATE_RESET
)
262 /* Allocate lock resource and initialize it */
263 hrtc
->Lock
= HAL_UNLOCKED
;
265 hrtc
->AlarmAEventCallback
= HAL_RTC_AlarmAEventCallback
; /* Legacy weak AlarmAEventCallback */
266 hrtc
->AlarmBEventCallback
= HAL_RTCEx_AlarmBEventCallback
; /* Legacy weak AlarmBEventCallback */
267 hrtc
->TimeStampEventCallback
= HAL_RTCEx_TimeStampEventCallback
; /* Legacy weak TimeStampEventCallback */
268 hrtc
->WakeUpTimerEventCallback
= HAL_RTCEx_WakeUpTimerEventCallback
; /* Legacy weak WakeUpTimerEventCallback */
269 hrtc
->Tamper1EventCallback
= HAL_RTCEx_Tamper1EventCallback
; /* Legacy weak Tamper1EventCallback */
270 hrtc
->Tamper2EventCallback
= HAL_RTCEx_Tamper2EventCallback
; /* Legacy weak Tamper2EventCallback */
271 hrtc
->Tamper3EventCallback
= HAL_RTCEx_Tamper3EventCallback
; /* Legacy weak Tamper3EventCallback */
273 if(hrtc
->MspInitCallback
== NULL
)
275 hrtc
->MspInitCallback
= HAL_RTC_MspInit
;
277 /* Init the low level hardware */
278 hrtc
->MspInitCallback(hrtc
);
280 if(hrtc
->MspDeInitCallback
== NULL
)
282 hrtc
->MspDeInitCallback
= HAL_RTC_MspDeInit
;
286 if(hrtc
->State
== HAL_RTC_STATE_RESET
)
288 /* Allocate lock resource and initialize it */
289 hrtc
->Lock
= HAL_UNLOCKED
;
291 /* Initialize RTC MSP */
292 HAL_RTC_MspInit(hrtc
);
294 #endif /* (USE_HAL_RTC_REGISTER_CALLBACKS) */
297 hrtc
->State
= HAL_RTC_STATE_BUSY
;
299 /* Disable the write protection for RTC registers */
300 __HAL_RTC_WRITEPROTECTION_DISABLE(hrtc
);
302 /* Set Initialization mode */
303 if(RTC_EnterInitMode(hrtc
) != HAL_OK
)
305 /* Enable the write protection for RTC registers */
306 __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc
);
309 hrtc
->State
= HAL_RTC_STATE_ERROR
;
315 /* Clear RTC_CR FMT, OSEL and POL Bits */
316 hrtc
->Instance
->CR
&= ((uint32_t)~(RTC_CR_FMT
| RTC_CR_OSEL
| RTC_CR_POL
));
317 /* Set RTC_CR register */
318 hrtc
->Instance
->CR
|= (uint32_t)(hrtc
->Init
.HourFormat
| hrtc
->Init
.OutPut
| hrtc
->Init
.OutPutPolarity
);
320 /* Configure the RTC PRER */
321 hrtc
->Instance
->PRER
= (uint32_t)(hrtc
->Init
.SynchPrediv
);
322 hrtc
->Instance
->PRER
|= (uint32_t)(hrtc
->Init
.AsynchPrediv
<< 16);
324 /* Exit Initialization mode */
325 hrtc
->Instance
->ISR
&= (uint32_t)~RTC_ISR_INIT
;
327 hrtc
->Instance
->OR
&= (uint32_t)~RTC_OR_ALARMTYPE
;
328 hrtc
->Instance
->OR
|= (uint32_t)(hrtc
->Init
.OutPutType
);
330 /* Enable the write protection for RTC registers */
331 __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc
);
334 hrtc
->State
= HAL_RTC_STATE_READY
;
341 * @brief DeInitializes the RTC peripheral
342 * @param hrtc pointer to a RTC_HandleTypeDef structure that contains
343 * the configuration information for RTC.
344 * @note This function doesn't reset the RTC Backup Data registers.
347 HAL_StatusTypeDef
HAL_RTC_DeInit(RTC_HandleTypeDef
*hrtc
)
349 uint32_t tickstart
= 0;
351 /* Check the parameters */
352 assert_param(IS_RTC_ALL_INSTANCE(hrtc
->Instance
));
355 hrtc
->State
= HAL_RTC_STATE_BUSY
;
357 /* Disable the write protection for RTC registers */
358 __HAL_RTC_WRITEPROTECTION_DISABLE(hrtc
);
360 /* Set Initialization mode */
361 if(RTC_EnterInitMode(hrtc
) != HAL_OK
)
363 /* Enable the write protection for RTC registers */
364 __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc
);
367 hrtc
->State
= HAL_RTC_STATE_ERROR
;
373 /* Reset TR, DR and CR registers */
374 hrtc
->Instance
->TR
= (uint32_t)0x00000000;
375 hrtc
->Instance
->DR
= (uint32_t)0x00002101;
376 /* Reset All CR bits except CR[2:0] */
377 hrtc
->Instance
->CR
&= (uint32_t)0x00000007;
380 tickstart
= HAL_GetTick();
382 /* Wait till WUTWF flag is set and if Time out is reached exit */
383 while(((hrtc
->Instance
->ISR
) & RTC_ISR_WUTWF
) == (uint32_t)RESET
)
385 if((HAL_GetTick() - tickstart
) > RTC_TIMEOUT_VALUE
)
387 /* Enable the write protection for RTC registers */
388 __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc
);
391 hrtc
->State
= HAL_RTC_STATE_TIMEOUT
;
397 /* Reset all RTC CR register bits */
398 hrtc
->Instance
->CR
&= (uint32_t)0x00000000;
399 hrtc
->Instance
->WUTR
= (uint32_t)0x0000FFFF;
400 hrtc
->Instance
->PRER
= (uint32_t)0x007F00FF;
401 hrtc
->Instance
->ALRMAR
= (uint32_t)0x00000000;
402 hrtc
->Instance
->ALRMBR
= (uint32_t)0x00000000;
403 hrtc
->Instance
->SHIFTR
= (uint32_t)0x00000000;
404 hrtc
->Instance
->CALR
= (uint32_t)0x00000000;
405 hrtc
->Instance
->ALRMASSR
= (uint32_t)0x00000000;
406 hrtc
->Instance
->ALRMBSSR
= (uint32_t)0x00000000;
408 /* Reset ISR register and exit initialization mode */
409 hrtc
->Instance
->ISR
= (uint32_t)0x00000000;
411 /* Reset Tamper and alternate functions configuration register */
412 hrtc
->Instance
->TAMPCR
= 0x00000000;
414 /* Reset Option register */
415 hrtc
->Instance
->OR
= 0x00000000;
417 /* If RTC_CR_BYPSHAD bit = 0, wait for synchro else this check is not needed */
418 if((hrtc
->Instance
->CR
& RTC_CR_BYPSHAD
) == RESET
)
420 if(HAL_RTC_WaitForSynchro(hrtc
) != HAL_OK
)
422 /* Enable the write protection for RTC registers */
423 __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc
);
425 hrtc
->State
= HAL_RTC_STATE_ERROR
;
432 /* Enable the write protection for RTC registers */
433 __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc
);
435 #if (USE_HAL_RTC_REGISTER_CALLBACKS == 1)
436 if(hrtc
->MspDeInitCallback
== NULL
)
438 hrtc
->MspDeInitCallback
= HAL_RTC_MspDeInit
;
441 /* DeInit the low level hardware: CLOCK, NVIC.*/
442 hrtc
->MspDeInitCallback(hrtc
);
445 /* De-Initialize RTC MSP */
446 HAL_RTC_MspDeInit(hrtc
);
447 #endif /* (USE_HAL_RTC_REGISTER_CALLBACKS) */
449 hrtc
->State
= HAL_RTC_STATE_RESET
;
457 #if (USE_HAL_RTC_REGISTER_CALLBACKS == 1)
459 * @brief Register a User RTC Callback
460 * To be used instead of the weak predefined callback
461 * @param hrtc RTC handle
462 * @param CallbackID ID of the callback to be registered
463 * This parameter can be one of the following values:
464 * @arg @ref HAL_RTC_ALARM_A_EVENT_CB_ID Alarm A Event Callback ID
465 * @arg @ref HAL_RTC_ALARM_B_EVENT_CB_ID Alarm B Event Callback ID
466 * @arg @ref HAL_RTC_TIMESTAMP_EVENT_CB_ID TimeStamp Event Callback ID
467 * @arg @ref HAL_RTC_WAKEUPTIMER_EVENT_CB_ID Wake-Up Timer Event Callback ID
468 * @arg @ref HAL_RTC_TAMPER1_EVENT_CB_ID Tamper 1 Callback ID
469 * @arg @ref HAL_RTC_TAMPER2_EVENT_CB_ID Tamper 2 Callback ID
470 * @arg @ref HAL_RTC_TAMPER3_EVENT_CB_ID Tamper 3 Callback ID
471 * @arg @ref HAL_RTC_MSPINIT_CB_ID Msp Init callback ID
472 * @arg @ref HAL_RTC_MSPDEINIT_CB_ID Msp DeInit callback ID
473 * @param pCallback pointer to the Callback function
476 HAL_StatusTypeDef
HAL_RTC_RegisterCallback(RTC_HandleTypeDef
*hrtc
, HAL_RTC_CallbackIDTypeDef CallbackID
, pRTC_CallbackTypeDef pCallback
)
478 HAL_StatusTypeDef status
= HAL_OK
;
480 if(pCallback
== NULL
)
488 if(HAL_RTC_STATE_READY
== hrtc
->State
)
492 case HAL_RTC_ALARM_A_EVENT_CB_ID
:
493 hrtc
->AlarmAEventCallback
= pCallback
;
496 case HAL_RTC_ALARM_B_EVENT_CB_ID
:
497 hrtc
->AlarmBEventCallback
= pCallback
;
500 case HAL_RTC_TIMESTAMP_EVENT_CB_ID
:
501 hrtc
->TimeStampEventCallback
= pCallback
;
504 case HAL_RTC_WAKEUPTIMER_EVENT_CB_ID
:
505 hrtc
->WakeUpTimerEventCallback
= pCallback
;
508 case HAL_RTC_TAMPER1_EVENT_CB_ID
:
509 hrtc
->Tamper1EventCallback
= pCallback
;
512 case HAL_RTC_TAMPER2_EVENT_CB_ID
:
513 hrtc
->Tamper2EventCallback
= pCallback
;
516 case HAL_RTC_TAMPER3_EVENT_CB_ID
:
517 hrtc
->Tamper3EventCallback
= pCallback
;
520 case HAL_RTC_MSPINIT_CB_ID
:
521 hrtc
->MspInitCallback
= pCallback
;
524 case HAL_RTC_MSPDEINIT_CB_ID
:
525 hrtc
->MspDeInitCallback
= pCallback
;
529 /* Return error status */
534 else if(HAL_RTC_STATE_RESET
== hrtc
->State
)
538 case HAL_RTC_MSPINIT_CB_ID
:
539 hrtc
->MspInitCallback
= pCallback
;
542 case HAL_RTC_MSPDEINIT_CB_ID
:
543 hrtc
->MspDeInitCallback
= pCallback
;
547 /* Return error status */
554 /* Return error status */
565 * @brief Unregister an RTC Callback
566 * RTC callabck is redirected to the weak predefined callback
567 * @param hrtc RTC handle
568 * @param CallbackID ID of the callback to be unregistered
569 * This parameter can be one of the following values:
570 * @arg @ref HAL_RTC_ALARM_A_EVENT_CB_ID Alarm A Event Callback ID
571 * @arg @ref HAL_RTC_ALARM_B_EVENT_CB_ID Alarm B Event Callback ID
572 * @arg @ref HAL_RTC_TIMESTAMP_EVENT_CB_ID TimeStamp Event Callback ID
573 * @arg @ref HAL_RTC_WAKEUPTIMER_EVENT_CB_ID Wake-Up Timer Event Callback ID
574 * @arg @ref HAL_RTC_TAMPER1_EVENT_CB_ID Tamper 1 Callback ID
575 * @arg @ref HAL_RTC_TAMPER2_EVENT_CB_ID Tamper 2 Callback ID
576 * @arg @ref HAL_RTC_TAMPER3_EVENT_CB_ID Tamper 3 Callback ID
577 * @arg @ref HAL_RTC_MSPINIT_CB_ID Msp Init callback ID
578 * @arg @ref HAL_RTC_MSPDEINIT_CB_ID Msp DeInit callback ID
581 HAL_StatusTypeDef
HAL_RTC_UnRegisterCallback(RTC_HandleTypeDef
*hrtc
, HAL_RTC_CallbackIDTypeDef CallbackID
)
583 HAL_StatusTypeDef status
= HAL_OK
;
588 if(HAL_RTC_STATE_READY
== hrtc
->State
)
592 case HAL_RTC_ALARM_A_EVENT_CB_ID
:
593 hrtc
->AlarmAEventCallback
= HAL_RTC_AlarmAEventCallback
; /* Legacy weak AlarmAEventCallback */
596 case HAL_RTC_ALARM_B_EVENT_CB_ID
:
597 hrtc
->AlarmBEventCallback
= HAL_RTCEx_AlarmBEventCallback
; /* Legacy weak AlarmBEventCallback */
600 case HAL_RTC_TIMESTAMP_EVENT_CB_ID
:
601 hrtc
->TimeStampEventCallback
= HAL_RTCEx_TimeStampEventCallback
; /* Legacy weak TimeStampEventCallback */
604 case HAL_RTC_WAKEUPTIMER_EVENT_CB_ID
:
605 hrtc
->WakeUpTimerEventCallback
= HAL_RTCEx_WakeUpTimerEventCallback
; /* Legacy weak WakeUpTimerEventCallback */
608 case HAL_RTC_TAMPER1_EVENT_CB_ID
:
609 hrtc
->Tamper1EventCallback
= HAL_RTCEx_Tamper1EventCallback
; /* Legacy weak Tamper1EventCallback */
612 case HAL_RTC_TAMPER2_EVENT_CB_ID
:
613 hrtc
->Tamper2EventCallback
= HAL_RTCEx_Tamper2EventCallback
; /* Legacy weak Tamper2EventCallback */
616 case HAL_RTC_TAMPER3_EVENT_CB_ID
:
617 hrtc
->Tamper3EventCallback
= HAL_RTCEx_Tamper3EventCallback
; /* Legacy weak Tamper3EventCallback */
620 case HAL_RTC_MSPINIT_CB_ID
:
621 hrtc
->MspInitCallback
= HAL_RTC_MspInit
;
624 case HAL_RTC_MSPDEINIT_CB_ID
:
625 hrtc
->MspDeInitCallback
= HAL_RTC_MspDeInit
;
629 /* Return error status */
634 else if(HAL_RTC_STATE_RESET
== hrtc
->State
)
638 case HAL_RTC_MSPINIT_CB_ID
:
639 hrtc
->MspInitCallback
= HAL_RTC_MspInit
;
642 case HAL_RTC_MSPDEINIT_CB_ID
:
643 hrtc
->MspDeInitCallback
= HAL_RTC_MspDeInit
;
647 /* Return error status */
654 /* Return error status */
663 #endif /* USE_HAL_RTC_REGISTER_CALLBACKS */
666 * @brief Initializes the RTC MSP.
667 * @param hrtc pointer to a RTC_HandleTypeDef structure that contains
668 * the configuration information for RTC.
671 __weak
void HAL_RTC_MspInit(RTC_HandleTypeDef
* hrtc
)
673 /* Prevent unused argument(s) compilation warning */
676 /* NOTE : This function Should not be modified, when the callback is needed,
677 the HAL_RTC_MspInit could be implemented in the user file
682 * @brief DeInitializes the RTC MSP.
683 * @param hrtc pointer to a RTC_HandleTypeDef structure that contains
684 * the configuration information for RTC.
687 __weak
void HAL_RTC_MspDeInit(RTC_HandleTypeDef
* hrtc
)
689 /* Prevent unused argument(s) compilation warning */
692 /* NOTE : This function Should not be modified, when the callback is needed,
693 the HAL_RTC_MspDeInit could be implemented in the user file
701 /** @defgroup RTC_Group2 RTC Time and Date functions
702 * @brief RTC Time and Date functions
705 ===============================================================================
706 ##### RTC Time and Date functions #####
707 ===============================================================================
709 [..] This section provides functions allowing to configure Time and Date features
716 * @brief Sets RTC current time.
717 * @param hrtc pointer to a RTC_HandleTypeDef structure that contains
718 * the configuration information for RTC.
719 * @param sTime Pointer to Time structure
720 * @param Format Specifies the format of the entered parameters.
721 * This parameter can be one of the following values:
722 * @arg FORMAT_BIN: Binary data format
723 * @arg FORMAT_BCD: BCD data format
726 HAL_StatusTypeDef
HAL_RTC_SetTime(RTC_HandleTypeDef
*hrtc
, RTC_TimeTypeDef
*sTime
, uint32_t Format
)
730 /* Check the parameters */
731 assert_param(IS_RTC_FORMAT(Format
));
732 assert_param(IS_RTC_DAYLIGHT_SAVING(sTime
->DayLightSaving
));
733 assert_param(IS_RTC_STORE_OPERATION(sTime
->StoreOperation
));
738 hrtc
->State
= HAL_RTC_STATE_BUSY
;
740 if(Format
== RTC_FORMAT_BIN
)
742 if((hrtc
->Instance
->CR
& RTC_CR_FMT
) != (uint32_t)RESET
)
744 assert_param(IS_RTC_HOUR12(sTime
->Hours
));
745 assert_param(IS_RTC_HOURFORMAT12(sTime
->TimeFormat
));
749 sTime
->TimeFormat
= 0x00;
750 assert_param(IS_RTC_HOUR24(sTime
->Hours
));
752 assert_param(IS_RTC_MINUTES(sTime
->Minutes
));
753 assert_param(IS_RTC_SECONDS(sTime
->Seconds
));
755 tmpreg
= (uint32_t)(((uint32_t)RTC_ByteToBcd2(sTime
->Hours
) << 16) | \
756 ((uint32_t)RTC_ByteToBcd2(sTime
->Minutes
) << 8) | \
757 ((uint32_t)RTC_ByteToBcd2(sTime
->Seconds
)) | \
758 (((uint32_t)sTime
->TimeFormat
) << 16));
762 if((hrtc
->Instance
->CR
& RTC_CR_FMT
) != (uint32_t)RESET
)
764 assert_param(IS_RTC_HOUR12(RTC_Bcd2ToByte(sTime
->Hours
)));
765 assert_param(IS_RTC_HOURFORMAT12(sTime
->TimeFormat
));
769 sTime
->TimeFormat
= 0x00;
770 assert_param(IS_RTC_HOUR24(RTC_Bcd2ToByte(sTime
->Hours
)));
772 assert_param(IS_RTC_MINUTES(RTC_Bcd2ToByte(sTime
->Minutes
)));
773 assert_param(IS_RTC_SECONDS(RTC_Bcd2ToByte(sTime
->Seconds
)));
774 tmpreg
= (((uint32_t)(sTime
->Hours
) << 16) | \
775 ((uint32_t)(sTime
->Minutes
) << 8) | \
776 ((uint32_t)sTime
->Seconds
) | \
777 ((uint32_t)(sTime
->TimeFormat
) << 16));
780 /* Disable the write protection for RTC registers */
781 __HAL_RTC_WRITEPROTECTION_DISABLE(hrtc
);
783 /* Set Initialization mode */
784 if(RTC_EnterInitMode(hrtc
) != HAL_OK
)
786 /* Enable the write protection for RTC registers */
787 __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc
);
790 hrtc
->State
= HAL_RTC_STATE_ERROR
;
792 /* Process Unlocked */
799 /* Set the RTC_TR register */
800 hrtc
->Instance
->TR
= (uint32_t)(tmpreg
& RTC_TR_RESERVED_MASK
);
802 /* Clear the bits to be configured */
803 hrtc
->Instance
->CR
&= (uint32_t)~RTC_CR_BKP
;
805 /* Configure the RTC_CR register */
806 hrtc
->Instance
->CR
|= (uint32_t)(sTime
->DayLightSaving
| sTime
->StoreOperation
);
808 /* Exit Initialization mode */
809 hrtc
->Instance
->ISR
&= (uint32_t)~RTC_ISR_INIT
;
811 /* If CR_BYPSHAD bit = 0, wait for synchro else this check is not needed */
812 if((hrtc
->Instance
->CR
& RTC_CR_BYPSHAD
) == RESET
)
814 if(HAL_RTC_WaitForSynchro(hrtc
) != HAL_OK
)
816 /* Enable the write protection for RTC registers */
817 __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc
);
819 hrtc
->State
= HAL_RTC_STATE_ERROR
;
821 /* Process Unlocked */
828 /* Enable the write protection for RTC registers */
829 __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc
);
831 hrtc
->State
= HAL_RTC_STATE_READY
;
840 * @brief Gets RTC current time.
841 * @param hrtc RTC handle
842 * @param sTime Pointer to Time structure with Hours, Minutes and Seconds fields returned
843 * with input format (BIN or BCD), also SubSeconds field returning the
844 * RTC_SSR register content and SecondFraction field the Synchronous pre-scaler
845 * factor to be used for second fraction ratio computation.
846 * @param Format Specifies the format of the entered parameters.
847 * This parameter can be one of the following values:
848 * @arg RTC_FORMAT_BIN: Binary data format
849 * @arg RTC_FORMAT_BCD: BCD data format
850 * @note You can use SubSeconds and SecondFraction (sTime structure fields returned) to convert SubSeconds
851 * value in second fraction ratio with time unit following generic formula:
852 * Second fraction ratio * time_unit= [(SecondFraction-SubSeconds)/(SecondFraction+1)] * time_unit
853 * This conversion can be performed only if no shift operation is pending (ie. SHFP=0) when PREDIV_S >= SS
854 * @note You must call HAL_RTC_GetDate() after HAL_RTC_GetTime() to unlock the values
855 * in the higher-order calendar shadow registers to ensure consistency between the time and date values.
856 * Reading RTC current time locks the values in calendar shadow registers until Current date is read
857 * to ensure consistency between the time and date values.
860 HAL_StatusTypeDef
HAL_RTC_GetTime(RTC_HandleTypeDef
*hrtc
, RTC_TimeTypeDef
*sTime
, uint32_t Format
)
864 /* Check the parameters */
865 assert_param(IS_RTC_FORMAT(Format
));
867 /* Get subseconds values from the correspondent registers*/
868 sTime
->SubSeconds
= (uint32_t)(hrtc
->Instance
->SSR
);
870 /* Get SecondFraction structure field from the corresponding register field*/
871 sTime
->SecondFraction
= (uint32_t)(hrtc
->Instance
->PRER
& RTC_PRER_PREDIV_S
);
873 /* Get the TR register */
874 tmpreg
= (uint32_t)(hrtc
->Instance
->TR
& RTC_TR_RESERVED_MASK
);
876 /* Fill the structure fields with the read parameters */
877 sTime
->Hours
= (uint8_t)((tmpreg
& (RTC_TR_HT
| RTC_TR_HU
)) >> 16);
878 sTime
->Minutes
= (uint8_t)((tmpreg
& (RTC_TR_MNT
| RTC_TR_MNU
)) >>8);
879 sTime
->Seconds
= (uint8_t)(tmpreg
& (RTC_TR_ST
| RTC_TR_SU
));
880 sTime
->TimeFormat
= (uint8_t)((tmpreg
& (RTC_TR_PM
)) >> 16);
882 /* Check the input parameters format */
883 if(Format
== RTC_FORMAT_BIN
)
885 /* Convert the time structure parameters to Binary format */
886 sTime
->Hours
= (uint8_t)RTC_Bcd2ToByte(sTime
->Hours
);
887 sTime
->Minutes
= (uint8_t)RTC_Bcd2ToByte(sTime
->Minutes
);
888 sTime
->Seconds
= (uint8_t)RTC_Bcd2ToByte(sTime
->Seconds
);
895 * @brief Sets RTC current date.
896 * @param hrtc pointer to a RTC_HandleTypeDef structure that contains
897 * the configuration information for RTC.
898 * @param sDate Pointer to date structure
899 * @param Format specifies the format of the entered parameters.
900 * This parameter can be one of the following values:
901 * @arg RTC_FORMAT_BIN: Binary data format
902 * @arg RTC_FORMAT_BCD: BCD data format
905 HAL_StatusTypeDef
HAL_RTC_SetDate(RTC_HandleTypeDef
*hrtc
, RTC_DateTypeDef
*sDate
, uint32_t Format
)
907 uint32_t datetmpreg
= 0;
909 /* Check the parameters */
910 assert_param(IS_RTC_FORMAT(Format
));
915 hrtc
->State
= HAL_RTC_STATE_BUSY
;
917 if((Format
== RTC_FORMAT_BIN
) && ((sDate
->Month
& 0x10U
) == 0x10U
))
919 sDate
->Month
= (uint8_t)((sDate
->Month
& (uint8_t)~(0x10U
)) + (uint8_t)0x0AU
);
922 assert_param(IS_RTC_WEEKDAY(sDate
->WeekDay
));
924 if(Format
== RTC_FORMAT_BIN
)
926 assert_param(IS_RTC_YEAR(sDate
->Year
));
927 assert_param(IS_RTC_MONTH(sDate
->Month
));
928 assert_param(IS_RTC_DATE(sDate
->Date
));
930 datetmpreg
= (((uint32_t)RTC_ByteToBcd2(sDate
->Year
) << 16) | \
931 ((uint32_t)RTC_ByteToBcd2(sDate
->Month
) << 8) | \
932 ((uint32_t)RTC_ByteToBcd2(sDate
->Date
)) | \
933 ((uint32_t)sDate
->WeekDay
<< 13));
937 assert_param(IS_RTC_YEAR(RTC_Bcd2ToByte(sDate
->Year
)));
938 assert_param(IS_RTC_MONTH(RTC_Bcd2ToByte(sDate
->Month
)));
939 assert_param(IS_RTC_DATE(RTC_Bcd2ToByte(sDate
->Date
)));
941 datetmpreg
= ((((uint32_t)sDate
->Year
) << 16) | \
942 (((uint32_t)sDate
->Month
) << 8) | \
943 ((uint32_t)sDate
->Date
) | \
944 (((uint32_t)sDate
->WeekDay
) << 13));
947 /* Disable the write protection for RTC registers */
948 __HAL_RTC_WRITEPROTECTION_DISABLE(hrtc
);
950 /* Set Initialization mode */
951 if(RTC_EnterInitMode(hrtc
) != HAL_OK
)
953 /* Enable the write protection for RTC registers */
954 __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc
);
957 hrtc
->State
= HAL_RTC_STATE_ERROR
;
959 /* Process Unlocked */
966 /* Set the RTC_DR register */
967 hrtc
->Instance
->DR
= (uint32_t)(datetmpreg
& RTC_DR_RESERVED_MASK
);
969 /* Exit Initialization mode */
970 hrtc
->Instance
->ISR
&= (uint32_t)~RTC_ISR_INIT
;
972 /* If CR_BYPSHAD bit = 0, wait for synchro else this check is not needed */
973 if((hrtc
->Instance
->CR
& RTC_CR_BYPSHAD
) == RESET
)
975 if(HAL_RTC_WaitForSynchro(hrtc
) != HAL_OK
)
977 /* Enable the write protection for RTC registers */
978 __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc
);
980 hrtc
->State
= HAL_RTC_STATE_ERROR
;
982 /* Process Unlocked */
989 /* Enable the write protection for RTC registers */
990 __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc
);
992 hrtc
->State
= HAL_RTC_STATE_READY
;
994 /* Process Unlocked */
1002 * @brief Gets RTC current date.
1003 * @param hrtc pointer to a RTC_HandleTypeDef structure that contains
1004 * the configuration information for RTC.
1005 * @param sDate Pointer to Date structure
1006 * @param Format Specifies the format of the entered parameters.
1007 * This parameter can be one of the following values:
1008 * @arg RTC_FORMAT_BIN: Binary data format
1009 * @arg RTC_FORMAT_BCD: BCD data format
1010 * @note You must call HAL_RTC_GetDate() after HAL_RTC_GetTime() to unlock the values
1011 * in the higher-order calendar shadow registers to ensure consistency between the time and date values.
1012 * Reading RTC current time locks the values in calendar shadow registers until Current date is read.
1013 * @retval HAL status
1015 HAL_StatusTypeDef
HAL_RTC_GetDate(RTC_HandleTypeDef
*hrtc
, RTC_DateTypeDef
*sDate
, uint32_t Format
)
1017 uint32_t datetmpreg
= 0;
1019 /* Check the parameters */
1020 assert_param(IS_RTC_FORMAT(Format
));
1022 /* Get the DR register */
1023 datetmpreg
= (uint32_t)(hrtc
->Instance
->DR
& RTC_DR_RESERVED_MASK
);
1025 /* Fill the structure fields with the read parameters */
1026 sDate
->Year
= (uint8_t)((datetmpreg
& (RTC_DR_YT
| RTC_DR_YU
)) >> 16);
1027 sDate
->Month
= (uint8_t)((datetmpreg
& (RTC_DR_MT
| RTC_DR_MU
)) >> 8);
1028 sDate
->Date
= (uint8_t)(datetmpreg
& (RTC_DR_DT
| RTC_DR_DU
));
1029 sDate
->WeekDay
= (uint8_t)((datetmpreg
& (RTC_DR_WDU
)) >> 13);
1031 /* Check the input parameters format */
1032 if(Format
== RTC_FORMAT_BIN
)
1034 /* Convert the date structure parameters to Binary format */
1035 sDate
->Year
= (uint8_t)RTC_Bcd2ToByte(sDate
->Year
);
1036 sDate
->Month
= (uint8_t)RTC_Bcd2ToByte(sDate
->Month
);
1037 sDate
->Date
= (uint8_t)RTC_Bcd2ToByte(sDate
->Date
);
1046 /** @defgroup RTC_Group3 RTC Alarm functions
1047 * @brief RTC Alarm functions
1050 ===============================================================================
1051 ##### RTC Alarm functions #####
1052 ===============================================================================
1054 [..] This section provides functions allowing to configure Alarm feature
1060 * @brief Sets the specified RTC Alarm.
1061 * @param hrtc pointer to a RTC_HandleTypeDef structure that contains
1062 * the configuration information for RTC.
1063 * @param sAlarm Pointer to Alarm structure
1064 * @param Format Specifies the format of the entered parameters.
1065 * This parameter can be one of the following values:
1066 * @arg FORMAT_BIN: Binary data format
1067 * @arg FORMAT_BCD: BCD data format
1068 * @retval HAL status
1070 HAL_StatusTypeDef
HAL_RTC_SetAlarm(RTC_HandleTypeDef
*hrtc
, RTC_AlarmTypeDef
*sAlarm
, uint32_t Format
)
1072 uint32_t tickstart
= 0;
1073 uint32_t tmpreg
= 0, subsecondtmpreg
= 0;
1075 /* Check the parameters */
1076 assert_param(IS_RTC_FORMAT(Format
));
1077 assert_param(IS_RTC_ALARM(sAlarm
->Alarm
));
1078 assert_param(IS_RTC_ALARM_MASK(sAlarm
->AlarmMask
));
1079 assert_param(IS_RTC_ALARM_DATE_WEEKDAY_SEL(sAlarm
->AlarmDateWeekDaySel
));
1080 assert_param(IS_RTC_ALARM_SUB_SECOND_VALUE(sAlarm
->AlarmTime
.SubSeconds
));
1081 assert_param(IS_RTC_ALARM_SUB_SECOND_MASK(sAlarm
->AlarmSubSecondMask
));
1083 /* Process Locked */
1086 hrtc
->State
= HAL_RTC_STATE_BUSY
;
1088 if(Format
== RTC_FORMAT_BIN
)
1090 if((hrtc
->Instance
->CR
& RTC_CR_FMT
) != (uint32_t)RESET
)
1092 assert_param(IS_RTC_HOUR12(sAlarm
->AlarmTime
.Hours
));
1093 assert_param(IS_RTC_HOURFORMAT12(sAlarm
->AlarmTime
.TimeFormat
));
1097 sAlarm
->AlarmTime
.TimeFormat
= 0x00;
1098 assert_param(IS_RTC_HOUR24(sAlarm
->AlarmTime
.Hours
));
1100 assert_param(IS_RTC_MINUTES(sAlarm
->AlarmTime
.Minutes
));
1101 assert_param(IS_RTC_SECONDS(sAlarm
->AlarmTime
.Seconds
));
1103 if(sAlarm
->AlarmDateWeekDaySel
== RTC_ALARMDATEWEEKDAYSEL_DATE
)
1105 assert_param(IS_RTC_ALARM_DATE_WEEKDAY_DATE(sAlarm
->AlarmDateWeekDay
));
1109 assert_param(IS_RTC_ALARM_DATE_WEEKDAY_WEEKDAY(sAlarm
->AlarmDateWeekDay
));
1112 tmpreg
= (((uint32_t)RTC_ByteToBcd2(sAlarm
->AlarmTime
.Hours
) << 16) | \
1113 ((uint32_t)RTC_ByteToBcd2(sAlarm
->AlarmTime
.Minutes
) << 8) | \
1114 ((uint32_t)RTC_ByteToBcd2(sAlarm
->AlarmTime
.Seconds
)) | \
1115 ((uint32_t)(sAlarm
->AlarmTime
.TimeFormat
) << 16) | \
1116 ((uint32_t)RTC_ByteToBcd2(sAlarm
->AlarmDateWeekDay
) << 24) | \
1117 ((uint32_t)sAlarm
->AlarmDateWeekDaySel
) | \
1118 ((uint32_t)sAlarm
->AlarmMask
));
1122 if((hrtc
->Instance
->CR
& RTC_CR_FMT
) != (uint32_t)RESET
)
1124 assert_param(IS_RTC_HOUR12(RTC_Bcd2ToByte(sAlarm
->AlarmTime
.Hours
)));
1125 assert_param(IS_RTC_HOURFORMAT12(sAlarm
->AlarmTime
.TimeFormat
));
1129 sAlarm
->AlarmTime
.TimeFormat
= 0x00;
1130 assert_param(IS_RTC_HOUR24(RTC_Bcd2ToByte(sAlarm
->AlarmTime
.Hours
)));
1133 assert_param(IS_RTC_MINUTES(RTC_Bcd2ToByte(sAlarm
->AlarmTime
.Minutes
)));
1134 assert_param(IS_RTC_SECONDS(RTC_Bcd2ToByte(sAlarm
->AlarmTime
.Seconds
)));
1136 if(sAlarm
->AlarmDateWeekDaySel
== RTC_ALARMDATEWEEKDAYSEL_DATE
)
1138 assert_param(IS_RTC_ALARM_DATE_WEEKDAY_DATE(RTC_Bcd2ToByte(sAlarm
->AlarmDateWeekDay
)));
1142 assert_param(IS_RTC_ALARM_DATE_WEEKDAY_WEEKDAY(RTC_Bcd2ToByte(sAlarm
->AlarmDateWeekDay
)));
1145 tmpreg
= (((uint32_t)(sAlarm
->AlarmTime
.Hours
) << 16) | \
1146 ((uint32_t)(sAlarm
->AlarmTime
.Minutes
) << 8) | \
1147 ((uint32_t) sAlarm
->AlarmTime
.Seconds
) | \
1148 ((uint32_t)(sAlarm
->AlarmTime
.TimeFormat
) << 16) | \
1149 ((uint32_t)(sAlarm
->AlarmDateWeekDay
) << 24) | \
1150 ((uint32_t)sAlarm
->AlarmDateWeekDaySel
) | \
1151 ((uint32_t)sAlarm
->AlarmMask
));
1154 /* Configure the Alarm A or Alarm B Sub Second registers */
1155 subsecondtmpreg
= (uint32_t)((uint32_t)(sAlarm
->AlarmTime
.SubSeconds
) | (uint32_t)(sAlarm
->AlarmSubSecondMask
));
1157 /* Disable the write protection for RTC registers */
1158 __HAL_RTC_WRITEPROTECTION_DISABLE(hrtc
);
1160 /* Configure the Alarm register */
1161 if(sAlarm
->Alarm
== RTC_ALARM_A
)
1163 /* Disable the Alarm A interrupt */
1164 __HAL_RTC_ALARMA_DISABLE(hrtc
);
1166 /* In case of interrupt mode is used, the interrupt source must disabled */
1167 __HAL_RTC_ALARM_DISABLE_IT(hrtc
, RTC_IT_ALRA
);
1170 tickstart
= HAL_GetTick();
1172 /* Wait till RTC ALRAWF flag is set and if Time out is reached exit */
1173 while(__HAL_RTC_ALARM_GET_FLAG(hrtc
, RTC_FLAG_ALRAWF
) == RESET
)
1175 if((HAL_GetTick() - tickstart
) > RTC_TIMEOUT_VALUE
)
1177 /* Enable the write protection for RTC registers */
1178 __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc
);
1180 hrtc
->State
= HAL_RTC_STATE_TIMEOUT
;
1182 /* Process Unlocked */
1189 hrtc
->Instance
->ALRMAR
= (uint32_t)tmpreg
;
1190 /* Configure the Alarm A Sub Second register */
1191 hrtc
->Instance
->ALRMASSR
= subsecondtmpreg
;
1192 /* Configure the Alarm state: Enable Alarm */
1193 __HAL_RTC_ALARMA_ENABLE(hrtc
);
1197 /* Disable the Alarm B interrupt */
1198 __HAL_RTC_ALARMB_DISABLE(hrtc
);
1200 /* In case of interrupt mode is used, the interrupt source must disabled */
1201 __HAL_RTC_ALARM_DISABLE_IT(hrtc
, RTC_IT_ALRB
);
1204 tickstart
= HAL_GetTick();
1206 /* Wait till RTC ALRBWF flag is set and if Time out is reached exit */
1207 while(__HAL_RTC_ALARM_GET_FLAG(hrtc
, RTC_FLAG_ALRBWF
) == RESET
)
1209 if((HAL_GetTick() - tickstart
) > RTC_TIMEOUT_VALUE
)
1211 /* Enable the write protection for RTC registers */
1212 __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc
);
1214 hrtc
->State
= HAL_RTC_STATE_TIMEOUT
;
1216 /* Process Unlocked */
1223 hrtc
->Instance
->ALRMBR
= (uint32_t)tmpreg
;
1224 /* Configure the Alarm B Sub Second register */
1225 hrtc
->Instance
->ALRMBSSR
= subsecondtmpreg
;
1226 /* Configure the Alarm state: Enable Alarm */
1227 __HAL_RTC_ALARMB_ENABLE(hrtc
);
1230 /* Enable the write protection for RTC registers */
1231 __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc
);
1233 /* Change RTC state */
1234 hrtc
->State
= HAL_RTC_STATE_READY
;
1236 /* Process Unlocked */
1243 * @brief Sets the specified RTC Alarm with Interrupt
1244 * @param hrtc pointer to a RTC_HandleTypeDef structure that contains
1245 * the configuration information for RTC.
1246 * @param sAlarm Pointer to Alarm structure
1247 * @param Format Specifies the format of the entered parameters.
1248 * This parameter can be one of the following values:
1249 * @arg FORMAT_BIN: Binary data format
1250 * @arg FORMAT_BCD: BCD data format
1251 * @note The Alarm register can only be written when the corresponding Alarm
1252 * is disabled (Use the HAL_RTC_DeactivateAlarm()).
1253 * @note The HAL_RTC_SetTime() must be called before enabling the Alarm feature.
1254 * @retval HAL status
1256 HAL_StatusTypeDef
HAL_RTC_SetAlarm_IT(RTC_HandleTypeDef
*hrtc
, RTC_AlarmTypeDef
*sAlarm
, uint32_t Format
)
1258 uint32_t tmpreg
= 0U, subsecondtmpreg
= 0U;
1259 __IO
uint32_t count
= RTC_TIMEOUT_VALUE
* (SystemCoreClock
/ 32U / 1000U) ;
1261 /* Check the parameters */
1262 assert_param(IS_RTC_FORMAT(Format
));
1263 assert_param(IS_RTC_ALARM(sAlarm
->Alarm
));
1264 assert_param(IS_RTC_ALARM_MASK(sAlarm
->AlarmMask
));
1265 assert_param(IS_RTC_ALARM_DATE_WEEKDAY_SEL(sAlarm
->AlarmDateWeekDaySel
));
1266 assert_param(IS_RTC_ALARM_SUB_SECOND_VALUE(sAlarm
->AlarmTime
.SubSeconds
));
1267 assert_param(IS_RTC_ALARM_SUB_SECOND_MASK(sAlarm
->AlarmSubSecondMask
));
1269 /* Process Locked */
1272 hrtc
->State
= HAL_RTC_STATE_BUSY
;
1274 if(Format
== RTC_FORMAT_BIN
)
1276 if((hrtc
->Instance
->CR
& RTC_CR_FMT
) != (uint32_t)RESET
)
1278 assert_param(IS_RTC_HOUR12(sAlarm
->AlarmTime
.Hours
));
1279 assert_param(IS_RTC_HOURFORMAT12(sAlarm
->AlarmTime
.TimeFormat
));
1283 sAlarm
->AlarmTime
.TimeFormat
= 0x00U
;
1284 assert_param(IS_RTC_HOUR24(sAlarm
->AlarmTime
.Hours
));
1286 assert_param(IS_RTC_MINUTES(sAlarm
->AlarmTime
.Minutes
));
1287 assert_param(IS_RTC_SECONDS(sAlarm
->AlarmTime
.Seconds
));
1289 if(sAlarm
->AlarmDateWeekDaySel
== RTC_ALARMDATEWEEKDAYSEL_DATE
)
1291 assert_param(IS_RTC_ALARM_DATE_WEEKDAY_DATE(sAlarm
->AlarmDateWeekDay
));
1295 assert_param(IS_RTC_ALARM_DATE_WEEKDAY_WEEKDAY(sAlarm
->AlarmDateWeekDay
));
1297 tmpreg
= (((uint32_t)RTC_ByteToBcd2(sAlarm
->AlarmTime
.Hours
) << 16U) | \
1298 ((uint32_t)RTC_ByteToBcd2(sAlarm
->AlarmTime
.Minutes
) << 8U) | \
1299 ((uint32_t)RTC_ByteToBcd2(sAlarm
->AlarmTime
.Seconds
)) | \
1300 ((uint32_t)(sAlarm
->AlarmTime
.TimeFormat
) << 16U) | \
1301 ((uint32_t)RTC_ByteToBcd2(sAlarm
->AlarmDateWeekDay
) << 24U) | \
1302 ((uint32_t)sAlarm
->AlarmDateWeekDaySel
) | \
1303 ((uint32_t)sAlarm
->AlarmMask
));
1307 if((hrtc
->Instance
->CR
& RTC_CR_FMT
) != (uint32_t)RESET
)
1309 assert_param(IS_RTC_HOUR12(RTC_Bcd2ToByte(sAlarm
->AlarmTime
.Hours
)));
1310 assert_param(IS_RTC_HOURFORMAT12(sAlarm
->AlarmTime
.TimeFormat
));
1314 sAlarm
->AlarmTime
.TimeFormat
= 0x00U
;
1315 assert_param(IS_RTC_HOUR24(RTC_Bcd2ToByte(sAlarm
->AlarmTime
.Hours
)));
1318 assert_param(IS_RTC_MINUTES(RTC_Bcd2ToByte(sAlarm
->AlarmTime
.Minutes
)));
1319 assert_param(IS_RTC_SECONDS(RTC_Bcd2ToByte(sAlarm
->AlarmTime
.Seconds
)));
1321 if(sAlarm
->AlarmDateWeekDaySel
== RTC_ALARMDATEWEEKDAYSEL_DATE
)
1323 assert_param(IS_RTC_ALARM_DATE_WEEKDAY_DATE(RTC_Bcd2ToByte(sAlarm
->AlarmDateWeekDay
)));
1327 assert_param(IS_RTC_ALARM_DATE_WEEKDAY_WEEKDAY(RTC_Bcd2ToByte(sAlarm
->AlarmDateWeekDay
)));
1329 tmpreg
= (((uint32_t)(sAlarm
->AlarmTime
.Hours
) << 16U) | \
1330 ((uint32_t)(sAlarm
->AlarmTime
.Minutes
) << 8U) | \
1331 ((uint32_t) sAlarm
->AlarmTime
.Seconds
) | \
1332 ((uint32_t)(sAlarm
->AlarmTime
.TimeFormat
) << 16U) | \
1333 ((uint32_t)(sAlarm
->AlarmDateWeekDay
) << 24U) | \
1334 ((uint32_t)sAlarm
->AlarmDateWeekDaySel
) | \
1335 ((uint32_t)sAlarm
->AlarmMask
));
1337 /* Configure the Alarm A or Alarm B Sub Second registers */
1338 subsecondtmpreg
= (uint32_t)((uint32_t)(sAlarm
->AlarmTime
.SubSeconds
) | (uint32_t)(sAlarm
->AlarmSubSecondMask
));
1340 /* Disable the write protection for RTC registers */
1341 __HAL_RTC_WRITEPROTECTION_DISABLE(hrtc
);
1343 /* Configure the Alarm register */
1344 if(sAlarm
->Alarm
== RTC_ALARM_A
)
1346 /* Disable the Alarm A interrupt */
1347 __HAL_RTC_ALARMA_DISABLE(hrtc
);
1349 /* Clear flag alarm A */
1350 __HAL_RTC_ALARM_CLEAR_FLAG(hrtc
, RTC_FLAG_ALRAF
);
1352 /* Wait till RTC ALRAWF flag is set and if Time out is reached exit */
1357 /* Enable the write protection for RTC registers */
1358 __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc
);
1360 hrtc
->State
= HAL_RTC_STATE_TIMEOUT
;
1362 /* Process Unlocked */
1368 while (__HAL_RTC_ALARM_GET_FLAG(hrtc
, RTC_FLAG_ALRAWF
) == RESET
);
1370 hrtc
->Instance
->ALRMAR
= (uint32_t)tmpreg
;
1371 /* Configure the Alarm A Sub Second register */
1372 hrtc
->Instance
->ALRMASSR
= subsecondtmpreg
;
1373 /* Configure the Alarm state: Enable Alarm */
1374 __HAL_RTC_ALARMA_ENABLE(hrtc
);
1375 /* Configure the Alarm interrupt */
1376 __HAL_RTC_ALARM_ENABLE_IT(hrtc
,RTC_IT_ALRA
);
1380 /* Disable the Alarm B interrupt */
1381 __HAL_RTC_ALARMB_DISABLE(hrtc
);
1383 /* Clear flag alarm B */
1384 __HAL_RTC_ALARM_CLEAR_FLAG(hrtc
, RTC_FLAG_ALRBF
);
1386 /* Wait till RTC ALRBWF flag is set and if Time out is reached exit */
1391 /* Enable the write protection for RTC registers */
1392 __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc
);
1394 hrtc
->State
= HAL_RTC_STATE_TIMEOUT
;
1396 /* Process Unlocked */
1402 while (__HAL_RTC_ALARM_GET_FLAG(hrtc
, RTC_FLAG_ALRBWF
) == RESET
);
1404 hrtc
->Instance
->ALRMBR
= (uint32_t)tmpreg
;
1405 /* Configure the Alarm B Sub Second register */
1406 hrtc
->Instance
->ALRMBSSR
= subsecondtmpreg
;
1407 /* Configure the Alarm state: Enable Alarm */
1408 __HAL_RTC_ALARMB_ENABLE(hrtc
);
1409 /* Configure the Alarm interrupt */
1410 __HAL_RTC_ALARM_ENABLE_IT(hrtc
, RTC_IT_ALRB
);
1413 /* RTC Alarm Interrupt Configuration: EXTI configuration */
1414 __HAL_RTC_ALARM_EXTI_ENABLE_IT();
1416 EXTI
->RTSR
|= RTC_EXTI_LINE_ALARM_EVENT
;
1418 /* Enable the write protection for RTC registers */
1419 __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc
);
1421 hrtc
->State
= HAL_RTC_STATE_READY
;
1423 /* Process Unlocked */
1430 * @brief Deactivate the specified RTC Alarm
1431 * @param hrtc pointer to a RTC_HandleTypeDef structure that contains
1432 * the configuration information for RTC.
1433 * @param Alarm Specifies the Alarm.
1434 * This parameter can be one of the following values:
1435 * @arg RTC_ALARM_A: AlarmA
1436 * @arg RTC_ALARM_B: AlarmB
1437 * @retval HAL status
1439 HAL_StatusTypeDef
HAL_RTC_DeactivateAlarm(RTC_HandleTypeDef
*hrtc
, uint32_t Alarm
)
1441 uint32_t tickstart
= 0;
1443 /* Check the parameters */
1444 assert_param(IS_RTC_ALARM(Alarm
));
1446 /* Process Locked */
1449 hrtc
->State
= HAL_RTC_STATE_BUSY
;
1451 /* Disable the write protection for RTC registers */
1452 __HAL_RTC_WRITEPROTECTION_DISABLE(hrtc
);
1454 if(Alarm
== RTC_ALARM_A
)
1457 __HAL_RTC_ALARMA_DISABLE(hrtc
);
1459 /* In case of interrupt mode is used, the interrupt source must disabled */
1460 __HAL_RTC_ALARM_DISABLE_IT(hrtc
, RTC_IT_ALRA
);
1463 tickstart
= HAL_GetTick();
1465 /* Wait till RTC ALRxWF flag is set and if Time out is reached exit */
1466 while(__HAL_RTC_ALARM_GET_FLAG(hrtc
, RTC_FLAG_ALRAWF
) == RESET
)
1468 if((HAL_GetTick() - tickstart
) > RTC_TIMEOUT_VALUE
)
1470 /* Enable the write protection for RTC registers */
1471 __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc
);
1473 hrtc
->State
= HAL_RTC_STATE_TIMEOUT
;
1475 /* Process Unlocked */
1485 __HAL_RTC_ALARMB_DISABLE(hrtc
);
1487 /* In case of interrupt mode is used, the interrupt source must disabled */
1488 __HAL_RTC_ALARM_DISABLE_IT(hrtc
,RTC_IT_ALRB
);
1491 tickstart
= HAL_GetTick();
1493 /* Wait till RTC ALRxWF flag is set and if Time out is reached exit */
1494 while(__HAL_RTC_ALARM_GET_FLAG(hrtc
, RTC_FLAG_ALRBWF
) == RESET
)
1496 if((HAL_GetTick() - tickstart
) > RTC_TIMEOUT_VALUE
)
1498 /* Enable the write protection for RTC registers */
1499 __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc
);
1501 hrtc
->State
= HAL_RTC_STATE_TIMEOUT
;
1503 /* Process Unlocked */
1510 /* Enable the write protection for RTC registers */
1511 __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc
);
1513 hrtc
->State
= HAL_RTC_STATE_READY
;
1515 /* Process Unlocked */
1522 * @brief Gets the RTC Alarm value and masks.
1523 * @param hrtc pointer to a RTC_HandleTypeDef structure that contains
1524 * the configuration information for RTC.
1525 * @param sAlarm Pointer to Date structure
1526 * @param Alarm Specifies the Alarm.
1527 * This parameter can be one of the following values:
1528 * @arg RTC_ALARM_A: AlarmA
1529 * @arg RTC_ALARM_B: AlarmB
1530 * @param Format Specifies the format of the entered parameters.
1531 * This parameter can be one of the following values:
1532 * @arg RTC_FORMAT_BIN: Binary data format
1533 * @arg RTC_FORMAT_BCD: BCD data format
1534 * @retval HAL status
1536 HAL_StatusTypeDef
HAL_RTC_GetAlarm(RTC_HandleTypeDef
*hrtc
, RTC_AlarmTypeDef
*sAlarm
, uint32_t Alarm
, uint32_t Format
)
1538 uint32_t tmpreg
= 0, subsecondtmpreg
= 0;
1540 /* Check the parameters */
1541 assert_param(IS_RTC_FORMAT(Format
));
1542 assert_param(IS_RTC_ALARM(Alarm
));
1544 if(Alarm
== RTC_ALARM_A
)
1547 sAlarm
->Alarm
= RTC_ALARM_A
;
1549 tmpreg
= (uint32_t)(hrtc
->Instance
->ALRMAR
);
1550 subsecondtmpreg
= (uint32_t)((hrtc
->Instance
->ALRMASSR
) & RTC_ALRMASSR_SS
);
1554 sAlarm
->Alarm
= RTC_ALARM_B
;
1556 tmpreg
= (uint32_t)(hrtc
->Instance
->ALRMBR
);
1557 subsecondtmpreg
= (uint32_t)((hrtc
->Instance
->ALRMBSSR
) & RTC_ALRMBSSR_SS
);
1560 /* Fill the structure with the read parameters */
1561 sAlarm
->AlarmTime
.Hours
= (uint32_t)((tmpreg
& (RTC_ALRMAR_HT
| RTC_ALRMAR_HU
)) >> 16);
1562 sAlarm
->AlarmTime
.Minutes
= (uint32_t)((tmpreg
& (RTC_ALRMAR_MNT
| RTC_ALRMAR_MNU
)) >> 8);
1563 sAlarm
->AlarmTime
.Seconds
= (uint32_t)(tmpreg
& (RTC_ALRMAR_ST
| RTC_ALRMAR_SU
));
1564 sAlarm
->AlarmTime
.TimeFormat
= (uint32_t)((tmpreg
& RTC_ALRMAR_PM
) >> 16);
1565 sAlarm
->AlarmTime
.SubSeconds
= (uint32_t) subsecondtmpreg
;
1566 sAlarm
->AlarmDateWeekDay
= (uint32_t)((tmpreg
& (RTC_ALRMAR_DT
| RTC_ALRMAR_DU
)) >> 24);
1567 sAlarm
->AlarmDateWeekDaySel
= (uint32_t)(tmpreg
& RTC_ALRMAR_WDSEL
);
1568 sAlarm
->AlarmMask
= (uint32_t)(tmpreg
& RTC_ALARMMASK_ALL
);
1570 if(Format
== RTC_FORMAT_BIN
)
1572 sAlarm
->AlarmTime
.Hours
= RTC_Bcd2ToByte(sAlarm
->AlarmTime
.Hours
);
1573 sAlarm
->AlarmTime
.Minutes
= RTC_Bcd2ToByte(sAlarm
->AlarmTime
.Minutes
);
1574 sAlarm
->AlarmTime
.Seconds
= RTC_Bcd2ToByte(sAlarm
->AlarmTime
.Seconds
);
1575 sAlarm
->AlarmDateWeekDay
= RTC_Bcd2ToByte(sAlarm
->AlarmDateWeekDay
);
1582 * @brief This function handles Alarm interrupt request.
1583 * @param hrtc pointer to a RTC_HandleTypeDef structure that contains
1584 * the configuration information for RTC.
1587 void HAL_RTC_AlarmIRQHandler(RTC_HandleTypeDef
* hrtc
)
1589 if(__HAL_RTC_ALARM_GET_IT(hrtc
, RTC_IT_ALRA
))
1591 /* Get the status of the Interrupt */
1592 if((uint32_t)(hrtc
->Instance
->CR
& RTC_IT_ALRA
) != (uint32_t)RESET
)
1594 /* AlarmA callback */
1595 #if (USE_HAL_RTC_REGISTER_CALLBACKS == 1)
1596 hrtc
->AlarmAEventCallback(hrtc
);
1598 HAL_RTC_AlarmAEventCallback(hrtc
);
1599 #endif /* USE_HAL_RTC_REGISTER_CALLBACKS */
1601 /* Clear the Alarm interrupt pending bit */
1602 __HAL_RTC_ALARM_CLEAR_FLAG(hrtc
,RTC_FLAG_ALRAF
);
1606 if(__HAL_RTC_ALARM_GET_IT(hrtc
, RTC_IT_ALRB
))
1608 /* Get the status of the Interrupt */
1609 if((uint32_t)(hrtc
->Instance
->CR
& RTC_IT_ALRB
) != (uint32_t)RESET
)
1611 /* AlarmB callback */
1612 #if (USE_HAL_RTC_REGISTER_CALLBACKS == 1)
1613 hrtc
->AlarmBEventCallback(hrtc
);
1615 HAL_RTCEx_AlarmBEventCallback(hrtc
);
1616 #endif /* USE_HAL_RTC_REGISTER_CALLBACKS */
1618 /* Clear the Alarm interrupt pending bit */
1619 __HAL_RTC_ALARM_CLEAR_FLAG(hrtc
,RTC_FLAG_ALRBF
);
1623 /* Clear the EXTI's line Flag for RTC Alarm */
1624 __HAL_RTC_ALARM_EXTI_CLEAR_FLAG();
1626 /* Change RTC state */
1627 hrtc
->State
= HAL_RTC_STATE_READY
;
1631 * @brief Alarm A callback.
1632 * @param hrtc pointer to a RTC_HandleTypeDef structure that contains
1633 * the configuration information for RTC.
1636 __weak
void HAL_RTC_AlarmAEventCallback(RTC_HandleTypeDef
*hrtc
)
1638 /* Prevent unused argument(s) compilation warning */
1641 /* NOTE : This function should not be modified, when the callback is needed,
1642 the HAL_RTC_AlarmAEventCallback could be implemented in the user file
1647 * @brief This function handles AlarmA Polling request.
1648 * @param hrtc pointer to a RTC_HandleTypeDef structure that contains
1649 * the configuration information for RTC.
1650 * @param Timeout Timeout duration
1651 * @retval HAL status
1653 HAL_StatusTypeDef
HAL_RTC_PollForAlarmAEvent(RTC_HandleTypeDef
*hrtc
, uint32_t Timeout
)
1655 uint32_t tickstart
= 0;
1658 tickstart
= HAL_GetTick();
1660 while(__HAL_RTC_ALARM_GET_FLAG(hrtc
, RTC_FLAG_ALRAF
) == RESET
)
1662 if(Timeout
!= HAL_MAX_DELAY
)
1664 if((Timeout
== 0)||((HAL_GetTick() - tickstart
) > Timeout
))
1666 hrtc
->State
= HAL_RTC_STATE_TIMEOUT
;
1672 /* Clear the Alarm interrupt pending bit */
1673 __HAL_RTC_ALARM_CLEAR_FLAG(hrtc
, RTC_FLAG_ALRAF
);
1675 /* Change RTC state */
1676 hrtc
->State
= HAL_RTC_STATE_READY
;
1685 /** @defgroup RTC_Group4 Peripheral Control functions
1686 * @brief Peripheral Control functions
1689 ===============================================================================
1690 ##### Peripheral Control functions #####
1691 ===============================================================================
1693 This subsection provides functions allowing to
1694 (+) Wait for RTC Time and Date Synchronization
1701 * @brief Waits until the RTC Time and Date registers (RTC_TR and RTC_DR) are
1702 * synchronized with RTC APB clock.
1703 * @note The RTC Resynchronization mode is write protected, use the
1704 * __HAL_RTC_WRITEPROTECTION_DISABLE() before calling this function.
1705 * @note To read the calendar through the shadow registers after Calendar
1706 * initialization, calendar update or after wake-up from low power modes
1707 * the software must first clear the RSF flag.
1708 * The software must then wait until it is set again before reading
1709 * the calendar, which means that the calendar registers have been
1710 * correctly copied into the RTC_TR and RTC_DR shadow registers.
1711 * @param hrtc pointer to a RTC_HandleTypeDef structure that contains
1712 * the configuration information for RTC.
1713 * @retval HAL status
1715 HAL_StatusTypeDef
HAL_RTC_WaitForSynchro(RTC_HandleTypeDef
* hrtc
)
1717 uint32_t tickstart
= 0;
1719 /* Clear RSF flag */
1720 hrtc
->Instance
->ISR
&= (uint32_t)RTC_RSF_MASK
;
1723 tickstart
= HAL_GetTick();
1725 /* Wait the registers to be synchronised */
1726 while((hrtc
->Instance
->ISR
& RTC_ISR_RSF
) == (uint32_t)RESET
)
1728 if((HAL_GetTick() - tickstart
) > RTC_TIMEOUT_VALUE
)
1741 /** @defgroup RTC_Group5 Peripheral State functions
1742 * @brief Peripheral State functions
1745 ===============================================================================
1746 ##### Peripheral State functions #####
1747 ===============================================================================
1749 This subsection provides functions allowing to
1756 * @brief Returns the RTC state.
1757 * @param hrtc pointer to a RTC_HandleTypeDef structure that contains
1758 * the configuration information for RTC.
1761 HAL_RTCStateTypeDef
HAL_RTC_GetState(RTC_HandleTypeDef
* hrtc
)
1771 * @brief Enters the RTC Initialization mode.
1772 * @note The RTC Initialization mode is write protected, use the
1773 * __HAL_RTC_WRITEPROTECTION_DISABLE() before calling this function.
1774 * @param hrtc pointer to a RTC_HandleTypeDef structure that contains
1775 * the configuration information for RTC.
1776 * @retval HAL status
1778 HAL_StatusTypeDef
RTC_EnterInitMode(RTC_HandleTypeDef
* hrtc
)
1780 uint32_t tickstart
= 0;
1782 /* Check if the Initialization mode is set */
1783 if((hrtc
->Instance
->ISR
& RTC_ISR_INITF
) == (uint32_t)RESET
)
1785 /* Set the Initialization mode */
1786 hrtc
->Instance
->ISR
= (uint32_t)RTC_INIT_MASK
;
1789 tickstart
= HAL_GetTick();
1791 /* Wait till RTC is in INIT state and if Time out is reached exit */
1792 while((hrtc
->Instance
->ISR
& RTC_ISR_INITF
) == (uint32_t)RESET
)
1794 if((HAL_GetTick() - tickstart
) > RTC_TIMEOUT_VALUE
)
1806 * @brief Converts a 2 digit decimal to BCD format.
1807 * @param Value Byte to be converted
1808 * @retval Converted byte
1810 uint8_t RTC_ByteToBcd2(uint8_t Value
)
1812 uint32_t bcdhigh
= 0;
1820 return ((uint8_t)(bcdhigh
<< 4) | Value
);
1824 * @brief Converts from 2 digit BCD to Binary.
1825 * @param Value BCD value to be converted
1826 * @retval Converted word
1828 uint8_t RTC_Bcd2ToByte(uint8_t Value
)
1831 tmp
= ((uint8_t)(Value
& (uint8_t)0xF0) >> (uint8_t)0x4) * 10;
1832 return (tmp
+ (Value
& (uint8_t)0x0F));
1839 #endif /* HAL_RTC_MODULE_ENABLED */
1848 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/