2 ******************************************************************************
3 * @file stm32f30x_rtc.c
4 * @author MCD Application Team
6 * @date 27-February-2014
7 * @brief This file provides firmware functions to manage the following
8 * functionalities of the Real-Time Clock (RTC) peripheral:
10 * + Calendar (Time and Date) configuration
11 * + Alarms (Alarm A and Alarm B) configuration
12 * + WakeUp Timer configuration
13 * + Daylight Saving configuration
14 * + Output pin Configuration
15 * + Smooth digital Calibration configuration
16 * + TimeStamp configuration
17 * + Tampers configuration
18 * + Backup Data Registers configuration
19 * + Output Type Config configuration
20 * + Shift control synchronisation
21 * + Interrupts and flags management
25 ===============================================================================
26 ##### RTC Operating Condition #####
27 ===============================================================================
28 [..] The real-time clock (RTC) and the RTC backup registers can be powered
29 from the VBAT voltage when the main VDD supply is powered off.
30 To retain the content of the RTC backup registers and supply the RTC
31 when VDD is turned off, VBAT pin can be connected to an optional
32 standby voltage supplied by a battery or by another source.
34 [..] To allow the RTC to operate even when the main digital supply (VDD)
35 is turned off, the VBAT pin powers the following blocks:
37 (#) The LSE oscillator
38 (#) PC13 to PC15 I/Os (when available)
40 [..] When the backup domain is supplied by VDD (analog switch connected
41 to VDD), the following functions are available:
42 (#) PC14 and PC15 can be used as either GPIO or LSE pins
43 (#) PC13 can be used as a GPIO or as the RTC_AF pin
45 [..] When the backup domain is supplied by VBAT (analog switch connected
46 to VBAT because VDD is not present), the following functions are available:
47 (#) PC14 and PC15 can be used as LSE pins only
48 (#) PC13 can be used as the RTC_AF pin
50 ##### Backup Domain Reset #####
51 ===============================================================================
52 [..] The backup domain reset sets all RTC registers and the RCC_BDCR
53 register to their reset values.
54 A backup domain reset is generated when one of the following events
56 (#) Software reset, triggered by setting the BDRST bit in the
57 RCC Backup domain control register (RCC_BDCR). You can use the
59 (#) VDD or VBAT power on, if both supplies have previously been
62 ##### Backup Domain Access #####
63 ===============================================================================
64 [..] After reset, the backup domain (RTC registers and RTC backup data
65 registers) is protected against possible unwanted write accesses.
66 [..] To enable access to the Backup Domain and RTC registers, proceed as follows:
67 (#) Enable the Power Controller (PWR) APB1 interface clock using the
68 RCC_APB1PeriphClockCmd() function.
69 (#) Enable access to Backup domain using the PWR_BackupAccessCmd() function.
70 (#) Select the RTC clock source using the RCC_RTCCLKConfig() function.
71 (#) Enable RTC Clock using the RCC_RTCCLKCmd() function.
73 ##### How to use this driver #####
74 ===============================================================================
76 (+) Enable the backup domain access (see description in the section above)
77 (+) Configure the RTC Prescaler (Asynchronous and Synchronous) and
78 RTC hour format using the RTC_Init() function.
80 *** Time and Date configuration ***
81 ===================================
83 (+) To configure the RTC Calendar (Time and Date) use the RTC_SetTime()
84 and RTC_SetDate() functions.
85 (+) To read the RTC Calendar, use the RTC_GetTime() and RTC_GetDate()
87 (+) To read the RTC subsecond, use the RTC_GetSubSecond() function.
88 (+) Use the RTC_DayLightSavingConfig() function to add or sub one
89 hour to the RTC Calendar.
91 *** Alarm configuration ***
92 ===========================
94 (+) To configure the RTC Alarm use the RTC_SetAlarm() function.
95 (+) Enable the selected RTC Alarm using the RTC_AlarmCmd() function.
96 (+) To read the RTC Alarm, use the RTC_GetAlarm() function.
97 (+) To read the RTC alarm SubSecond, use the RTC_GetAlarmSubSecond() function.
99 *** RTC Wakeup configuration ***
100 ================================
102 (+) Configure the RTC Wakeup Clock source use the RTC_WakeUpClockConfig()
104 (+) Configure the RTC WakeUp Counter using the RTC_SetWakeUpCounter()
106 (+) Enable the RTC WakeUp using the RTC_WakeUpCmd() function
107 (+) To read the RTC WakeUp Counter register, use the RTC_GetWakeUpCounter()
110 *** Outputs configuration ***
111 =============================
112 [..] The RTC has 2 different outputs:
113 (+) AFO_ALARM: this output is used to manage the RTC Alarm A, Alarm B
115 To output the selected RTC signal on RTC_AF pin, use the
116 RTC_OutputConfig() function.
117 (+) AFO_CALIB: this output is 512Hz signal or 1Hz .
118 To output the RTC Clock on RTC_AF pin, use the RTC_CalibOutputCmd()
121 *** Smooth digital Calibration configuration ***
122 ================================================
124 (+) Configure the RTC Original Digital Calibration Value and the corresponding
125 calibration cycle period (32s,16s and 8s) using the RTC_SmoothCalibConfig()
128 *** TimeStamp configuration ***
129 ===============================
131 (+) Configure the RTC_AF trigger and enables the RTC TimeStamp
132 using the RTC_TimeStampCmd() function.
133 (+) To read the RTC TimeStamp Time and Date register, use the
134 RTC_GetTimeStamp() function.
135 (+) To read the RTC TimeStamp SubSecond register, use the
136 RTC_GetTimeStampSubSecond() function.
138 *** Tamper configuration ***
139 ============================
141 (+) Configure the Tamper filter count using RTC_TamperFilterConfig()
143 (+) Configure the RTC Tamper trigger Edge or Level according to the Tamper
144 filter (if equal to 0 Edge else Level) value using the RTC_TamperConfig() function.
145 (+) Configure the Tamper sampling frequency using RTC_TamperSamplingFreqConfig()
147 (+) Configure the Tamper precharge or discharge duration using
148 RTC_TamperPinsPrechargeDuration() function.
149 (+) Enable the Tamper Pull-UP using RTC_TamperPullUpDisableCmd() function.
150 (+) Enable the RTC Tamper using the RTC_TamperCmd() function.
151 (+) Enable the Time stamp on Tamper detection event using
152 RTC_TSOnTamperDetecCmd() function.
154 *** Backup Data Registers configuration ***
155 ===========================================
157 (+) To write to the RTC Backup Data registers, use the RTC_WriteBackupRegister()
159 (+) To read the RTC Backup Data registers, use the RTC_ReadBackupRegister()
162 ##### RTC and low power modes #####
163 ===============================================================================
164 [..] The MCU can be woken up from a low power mode by an RTC alternate
166 [..] The RTC alternate functions are the RTC alarms (Alarm A and Alarm B),
167 RTC wakeup, RTC tamper event detection and RTC time stamp event detection.
168 These RTC alternate functions can wake up the system from the Stop
169 and Standby lowpower modes.
170 The system can also wake up from low power modes without depending
171 on an external interrupt (Auto-wakeup mode), by using the RTC alarm
172 or the RTC wakeup events.
173 [..] The RTC provides a programmable time base for waking up from the
174 Stop or Standby mode at regular intervals.
175 Wakeup from STOP and Standby modes is possible only when the RTC
176 clock source is LSE or LSI.
178 ##### Selection of RTC_AF alternate functions #####
179 ===============================================================================
180 [..] The RTC_AF pin (PC13) can be used for the following purposes:
181 (+) Wakeup pin 2 (WKUP2) using the PWR_WakeUpPinCmd() function.
187 +------------------------------------------------------------------------------------------+
188 | Pin |RTC ALARM |RTC CALIB |RTC TAMPER |RTC TIMESTAMP |PC13MODE| PC13VALUE |
189 | configuration | OUTPUT | OUTPUT | INPUT | INPUT | bit | bit |
190 | and function | ENABLED | ENABLED | ENABLED | ENABLED | | |
191 |-----------------|----------|----------|-----------|--------------|--------|--------------|
192 | Alarm out | | | | | Don't | |
193 | output OD | 1 |Don't care|Don't care | Don't care | care | 0 |
194 |-----------------|----------|----------|-----------|--------------|--------|--------------|
195 | Alarm out | | | | | Don't | |
196 | output PP | 1 |Don't care|Don't care | Don't care | care | 1 |
197 |-----------------|----------|----------|-----------|--------------|--------|--------------|
198 | Calibration out | | | | | Don't | |
199 | output PP | 0 | 1 |Don't care | Don't care | care | Don't care |
200 |-----------------|----------|----------|-----------|--------------|--------|--------------|
201 | TAMPER input | | | | | Don't | |
202 | floating | 0 | 0 | 1 | 0 | care | Don't care |
203 |-----------------|----------|----------|-----------|--------------|--------|--------------|
204 | TIMESTAMP and | | | | | Don't | |
205 | TAMPER input | 0 | 0 | 1 | 1 | care | Don't care |
206 | floating | | | | | | |
207 |-----------------|----------|----------|-----------|--------------|--------|--------------|
208 | TIMESTAMP input | | | | | Don't | |
209 | floating | 0 | 0 | 0 | 1 | care | Don't care |
210 |-----------------|----------|----------|-----------|--------------|--------|--------------|
211 | Output PP | 0 | 0 | 0 | 0 | 1 | PC13 output |
212 | Forced | | | | | | |
213 |-----------------|----------|----------|-----------|--------------|--------|--------------|
214 | Wakeup Pin or | 0 | 0 | 0 | 0 | 0 | Don't care |
215 | Standard GPIO | | | | | | |
216 +------------------------------------------------------------------------------------------+
220 ******************************************************************************
223 * <h2><center>© COPYRIGHT(c) 2014 STMicroelectronics</center></h2>
225 * Redistribution and use in source and binary forms, with or without modification,
226 * are permitted provided that the following conditions are met:
227 * 1. Redistributions of source code must retain the above copyright notice,
228 * this list of conditions and the following disclaimer.
229 * 2. Redistributions in binary form must reproduce the above copyright notice,
230 * this list of conditions and the following disclaimer in the documentation
231 * and/or other materials provided with the distribution.
232 * 3. Neither the name of STMicroelectronics nor the names of its contributors
233 * may be used to endorse or promote products derived from this software
234 * without specific prior written permission.
236 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
237 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
238 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
239 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
240 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
241 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
242 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
243 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
244 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
245 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
247 ******************************************************************************
250 /* Includes ------------------------------------------------------------------*/
251 #include "stm32f30x_rtc.h"
252 #include "stm32f30x_rcc.h"
254 /** @addtogroup STM32F30x_StdPeriph_Driver
259 * @brief RTC driver modules
263 /* Private typedef -----------------------------------------------------------*/
264 /* Private define ------------------------------------------------------------*/
266 /* Masks Definition */
267 #define RTC_TR_RESERVED_MASK ((uint32_t)0x007F7F7F)
268 #define RTC_DR_RESERVED_MASK ((uint32_t)0x00FFFF3F)
269 #define RTC_INIT_MASK ((uint32_t)0xFFFFFFFF)
270 #define RTC_RSF_MASK ((uint32_t)0xFFFFFF5F)
271 #define RTC_FLAGS_MASK ((uint32_t)(RTC_FLAG_TSOVF | RTC_FLAG_TSF | RTC_FLAG_WUTF | \
272 RTC_FLAG_ALRBF | RTC_FLAG_ALRAF | RTC_FLAG_INITF | \
273 RTC_FLAG_RSF | RTC_FLAG_INITS | RTC_FLAG_WUTWF | \
274 RTC_FLAG_ALRBWF | RTC_FLAG_ALRAWF | RTC_FLAG_TAMP1F | \
275 RTC_FLAG_TAMP2F | RTC_FLAG_TAMP3F | RTC_FLAG_RECALPF | \
278 #define INITMODE_TIMEOUT ((uint32_t) 0x00002000)
279 #define SYNCHRO_TIMEOUT ((uint32_t) 0x00008000)
280 #define RECALPF_TIMEOUT ((uint32_t) 0x00001000)
281 #define SHPF_TIMEOUT ((uint32_t) 0x00002000)
283 /* Private macro -------------------------------------------------------------*/
284 /* Private variables ---------------------------------------------------------*/
285 /* Private function prototypes -----------------------------------------------*/
286 static uint8_t RTC_ByteToBcd2(uint8_t Value);
287 static uint8_t RTC_Bcd2ToByte(uint8_t Value);
289 /* Private functions ---------------------------------------------------------*/
291 /** @defgroup RTC_Private_Functions
295 /** @defgroup RTC_Group1 Initialization and Configuration functions
296 * @brief Initialization and Configuration functions
299 ===============================================================================
300 ##### Initialization and Configuration functions #####
301 ===============================================================================
302 [..] This section provide functions allowing to initialize and configure the RTC
303 Prescaler (Synchronous and Asynchronous), RTC Hour format, disable RTC registers
304 Write protection, enter and exit the RTC initialization mode, RTC registers
305 synchronization check and reference clock detection enable.
306 (#) The RTC Prescaler is programmed to generate the RTC 1Hz time base. It is
307 split into 2 programmable prescalers to minimize power consumption.
308 (++) A 7-bit asynchronous prescaler and A 13-bit synchronous prescaler.
309 (++) When both prescalers are used, it is recommended to configure the
310 asynchronous prescaler to a high value to minimize consumption.
311 (#) All RTC registers are Write protected. Writing to the RTC registers
312 is enabled by writing a key into the Write Protection register, RTC_WPR.
313 (#) To Configure the RTC Calendar, user application should enter initialization
314 mode. In this mode, the calendar counter is stopped and its value
315 can be updated. When the initialization sequence is complete, the
316 calendar restarts counting after 4 RTCCLK cycles.
317 (#) To read the calendar through the shadow registers after Calendar
318 initialization, calendar update or after wakeup from low power modes
319 the software must first clear the RSF flag. The software must then
320 wait until it is set again before reading the calendar, which means
321 that the calendar registers have been correctly copied into the RTC_TR
322 and RTC_DR shadow registers. The RTC_WaitForSynchro() function
323 implements the above software sequence (RSF clear and RSF check).
330 * @brief Deinitializes the RTC registers to their default reset values.
331 * @note This function doesn't reset the RTC Clock source and RTC Backup Data
334 * @retval An ErrorStatus enumeration value:
335 * - SUCCESS: RTC registers are deinitialized
336 * - ERROR: RTC registers are not deinitialized
338 ErrorStatus RTC_DeInit(void)
340 __IO uint32_t wutcounter = 0x00;
341 uint32_t wutwfstatus = 0x00;
342 ErrorStatus status = ERROR;
344 /* Disable the write protection for RTC registers */
348 /* Set Initialization mode */
349 if (RTC_EnterInitMode() == ERROR)
355 /* Reset TR, DR and CR registers */
356 RTC->TR = (uint32_t)0x00000000;
357 RTC->DR = (uint32_t)0x00002101;
359 /* Reset All CR bits except CR[2:0] */
360 RTC->CR &= (uint32_t)0x00000007;
362 /* Wait till RTC WUTWF flag is set and if Time out is reached exit */
365 wutwfstatus = RTC->ISR & RTC_ISR_WUTWF;
367 } while((wutcounter != INITMODE_TIMEOUT) && (wutwfstatus == 0x00));
369 if ((RTC->ISR & RTC_ISR_WUTWF) == RESET)
375 /* Reset all RTC CR register bits */
376 RTC->CR &= (uint32_t)0x00000000;
377 RTC->WUTR = (uint32_t)0x0000FFFF;
378 RTC->PRER = (uint32_t)0x007F00FF;
379 RTC->ALRMAR = (uint32_t)0x00000000;
380 RTC->ALRMBR = (uint32_t)0x00000000;
381 RTC->SHIFTR = (uint32_t)0x00000000;
382 RTC->CALR = (uint32_t)0x00000000;
383 RTC->ALRMASSR = (uint32_t)0x00000000;
384 RTC->ALRMBSSR = (uint32_t)0x00000000;
386 /* Reset ISR register and exit initialization mode */
387 RTC->ISR = (uint32_t)0x00000000;
389 /* Reset Tamper and alternate functions configuration register */
390 RTC->TAFCR = 0x00000000;
392 /* Wait till the RTC RSF flag is set */
393 if (RTC_WaitForSynchro() == ERROR)
404 /* Enable the write protection for RTC registers */
411 * @brief Initializes the RTC registers according to the specified parameters
413 * @param RTC_InitStruct: pointer to a RTC_InitTypeDef structure that contains
414 * the configuration information for the RTC peripheral.
415 * @note The RTC Prescaler register is write protected and can be written in
416 * initialization mode only.
417 * @retval An ErrorStatus enumeration value:
418 * - SUCCESS: RTC registers are initialized
419 * - ERROR: RTC registers are not initialized
421 ErrorStatus RTC_Init(RTC_InitTypeDef* RTC_InitStruct)
423 ErrorStatus status = ERROR;
425 /* Check the parameters */
426 assert_param(IS_RTC_HOUR_FORMAT(RTC_InitStruct->RTC_HourFormat));
427 assert_param(IS_RTC_ASYNCH_PREDIV(RTC_InitStruct->RTC_AsynchPrediv));
428 assert_param(IS_RTC_SYNCH_PREDIV(RTC_InitStruct->RTC_SynchPrediv));
430 /* Disable the write protection for RTC registers */
434 /* Set Initialization mode */
435 if (RTC_EnterInitMode() == ERROR)
441 /* Clear RTC CR FMT Bit */
442 RTC->CR &= ((uint32_t)~(RTC_CR_FMT));
443 /* Set RTC_CR register */
444 RTC->CR |= ((uint32_t)(RTC_InitStruct->RTC_HourFormat));
446 /* Configure the RTC PRER */
447 RTC->PRER = (uint32_t)(RTC_InitStruct->RTC_SynchPrediv);
448 RTC->PRER |= (uint32_t)(RTC_InitStruct->RTC_AsynchPrediv << 16);
450 /* Exit Initialization mode */
455 /* Enable the write protection for RTC registers */
462 * @brief Fills each RTC_InitStruct member with its default value.
463 * @param RTC_InitStruct: pointer to a RTC_InitTypeDef structure which will be
467 void RTC_StructInit(RTC_InitTypeDef* RTC_InitStruct)
469 /* Initialize the RTC_HourFormat member */
470 RTC_InitStruct->RTC_HourFormat = RTC_HourFormat_24;
472 /* Initialize the RTC_AsynchPrediv member */
473 RTC_InitStruct->RTC_AsynchPrediv = (uint32_t)0x7F;
475 /* Initialize the RTC_SynchPrediv member */
476 RTC_InitStruct->RTC_SynchPrediv = (uint32_t)0xFF;
480 * @brief Enables or disables the RTC registers write protection.
481 * @note All the RTC registers are write protected except for RTC_ISR[13:8],
482 * RTC_TAFCR and RTC_BKPxR.
483 * @note Writing a wrong key reactivates the write protection.
484 * @note The protection mechanism is not affected by system reset.
485 * @param NewState: new state of the write protection.
486 * This parameter can be: ENABLE or DISABLE.
489 void RTC_WriteProtectionCmd(FunctionalState NewState)
491 /* Check the parameters */
492 assert_param(IS_FUNCTIONAL_STATE(NewState));
494 if (NewState != DISABLE)
496 /* Enable the write protection for RTC registers */
501 /* Disable the write protection for RTC registers */
508 * @brief Enters the RTC Initialization mode.
509 * @note The RTC Initialization mode is write protected, use the
510 * RTC_WriteProtectionCmd(DISABLE) before calling this function.
512 * @retval An ErrorStatus enumeration value:
513 * - SUCCESS: RTC is in Init mode
514 * - ERROR: RTC is not in Init mode
516 ErrorStatus RTC_EnterInitMode(void)
518 __IO uint32_t initcounter = 0x00;
519 ErrorStatus status = ERROR;
520 uint32_t initstatus = 0x00;
522 /* Check if the Initialization mode is set */
523 if ((RTC->ISR & RTC_ISR_INITF) == (uint32_t)RESET)
525 /* Set the Initialization mode */
526 RTC->ISR = (uint32_t)RTC_INIT_MASK;
528 /* Wait till RTC is in INIT state and if Time out is reached exit */
531 initstatus = RTC->ISR & RTC_ISR_INITF;
533 } while((initcounter != INITMODE_TIMEOUT) && (initstatus == 0x00));
535 if ((RTC->ISR & RTC_ISR_INITF) != RESET)
553 * @brief Exits the RTC Initialization mode.
554 * @note When the initialization sequence is complete, the calendar restarts
555 * counting after 4 RTCCLK cycles.
556 * @note The RTC Initialization mode is write protected, use the
557 * RTC_WriteProtectionCmd(DISABLE) before calling this function.
561 void RTC_ExitInitMode(void)
563 /* Exit Initialization mode */
564 RTC->ISR &= (uint32_t)~RTC_ISR_INIT;
568 * @brief Waits until the RTC Time and Date registers (RTC_TR and RTC_DR) are
569 * synchronized with RTC APB clock.
570 * @note The RTC Resynchronization mode is write protected, use the
571 * RTC_WriteProtectionCmd(DISABLE) before calling this function.
572 * @note To read the calendar through the shadow registers after Calendar
573 * initialization, calendar update or after wakeup from low power modes
574 * the software must first clear the RSF flag.
575 * The software must then wait until it is set again before reading
576 * the calendar, which means that the calendar registers have been
577 * correctly copied into the RTC_TR and RTC_DR shadow registers.
579 * @retval An ErrorStatus enumeration value:
580 * - SUCCESS: RTC registers are synchronised
581 * - ERROR: RTC registers are not synchronised
583 ErrorStatus RTC_WaitForSynchro(void)
585 __IO uint32_t synchrocounter = 0;
586 ErrorStatus status = ERROR;
587 uint32_t synchrostatus = 0x00;
589 if ((RTC->CR & RTC_CR_BYPSHAD) != RESET)
591 /* Bypass shadow mode */
596 /* Disable the write protection for RTC registers */
601 RTC->ISR &= (uint32_t)RTC_RSF_MASK;
603 /* Wait the registers to be synchronised */
606 synchrostatus = RTC->ISR & RTC_ISR_RSF;
608 } while((synchrocounter != SYNCHRO_TIMEOUT) && (synchrostatus == 0x00));
610 if ((RTC->ISR & RTC_ISR_RSF) != RESET)
619 /* Enable the write protection for RTC registers */
627 * @brief Enables or disables the RTC reference clock detection.
628 * @param NewState: new state of the RTC reference clock.
629 * This parameter can be: ENABLE or DISABLE.
630 * @retval An ErrorStatus enumeration value:
631 * - SUCCESS: RTC reference clock detection is enabled
632 * - ERROR: RTC reference clock detection is disabled
634 ErrorStatus RTC_RefClockCmd(FunctionalState NewState)
636 ErrorStatus status = ERROR;
638 /* Check the parameters */
639 assert_param(IS_FUNCTIONAL_STATE(NewState));
641 /* Disable the write protection for RTC registers */
645 /* Set Initialization mode */
646 if (RTC_EnterInitMode() == ERROR)
652 if (NewState != DISABLE)
654 /* Enable the RTC reference clock detection */
655 RTC->CR |= RTC_CR_REFCKON;
659 /* Disable the RTC reference clock detection */
660 RTC->CR &= ~RTC_CR_REFCKON;
662 /* Exit Initialization mode */
668 /* Enable the write protection for RTC registers */
675 * @brief Enables or Disables the Bypass Shadow feature.
676 * @note When the Bypass Shadow is enabled the calendar value are taken
677 * directly from the Calendar counter.
678 * @param NewState: new state of the Bypass Shadow feature.
679 * This parameter can be: ENABLE or DISABLE.
682 void RTC_BypassShadowCmd(FunctionalState NewState)
684 /* Check the parameters */
685 assert_param(IS_FUNCTIONAL_STATE(NewState));
687 /* Disable the write protection for RTC registers */
691 if (NewState != DISABLE)
693 /* Set the BYPSHAD bit */
694 RTC->CR |= (uint8_t)RTC_CR_BYPSHAD;
698 /* Reset the BYPSHAD bit */
699 RTC->CR &= (uint8_t)~RTC_CR_BYPSHAD;
702 /* Enable the write protection for RTC registers */
710 /** @defgroup RTC_Group2 Time and Date configuration functions
711 * @brief Time and Date configuration functions
714 ===============================================================================
715 ##### Time and Date configuration functions #####
716 ===============================================================================
717 [..] This section provide functions allowing to program and read the RTC Calendar
725 * @brief Set the RTC current time.
726 * @param RTC_Format: specifies the format of the entered parameters.
727 * This parameter can be one of the following values:
728 * @arg RTC_Format_BIN: Binary data format
729 * @arg RTC_Format_BCD: BCD data format
730 * @param RTC_TimeStruct: pointer to a RTC_TimeTypeDef structure that contains
731 * the time configuration information for the RTC.
732 * @retval An ErrorStatus enumeration value:
733 * - SUCCESS: RTC Time register is configured
734 * - ERROR: RTC Time register is not configured
736 ErrorStatus RTC_SetTime(uint32_t RTC_Format, RTC_TimeTypeDef* RTC_TimeStruct)
739 ErrorStatus status = ERROR;
741 /* Check the parameters */
742 assert_param(IS_RTC_FORMAT(RTC_Format));
744 if (RTC_Format == RTC_Format_BIN)
746 if ((RTC->CR & RTC_CR_FMT) != (uint32_t)RESET)
748 assert_param(IS_RTC_HOUR12(RTC_TimeStruct->RTC_Hours));
749 assert_param(IS_RTC_H12(RTC_TimeStruct->RTC_H12));
753 RTC_TimeStruct->RTC_H12 = 0x00;
754 assert_param(IS_RTC_HOUR24(RTC_TimeStruct->RTC_Hours));
756 assert_param(IS_RTC_MINUTES(RTC_TimeStruct->RTC_Minutes));
757 assert_param(IS_RTC_SECONDS(RTC_TimeStruct->RTC_Seconds));
761 if ((RTC->CR & RTC_CR_FMT) != (uint32_t)RESET)
763 tmpreg = RTC_Bcd2ToByte(RTC_TimeStruct->RTC_Hours);
764 assert_param(IS_RTC_HOUR12(tmpreg));
765 assert_param(IS_RTC_H12(RTC_TimeStruct->RTC_H12));
769 RTC_TimeStruct->RTC_H12 = 0x00;
770 assert_param(IS_RTC_HOUR24(RTC_Bcd2ToByte(RTC_TimeStruct->RTC_Hours)));
772 assert_param(IS_RTC_MINUTES(RTC_Bcd2ToByte(RTC_TimeStruct->RTC_Minutes)));
773 assert_param(IS_RTC_SECONDS(RTC_Bcd2ToByte(RTC_TimeStruct->RTC_Seconds)));
776 /* Check the input parameters format */
777 if (RTC_Format != RTC_Format_BIN)
779 tmpreg = (((uint32_t)(RTC_TimeStruct->RTC_Hours) << 16) | \
780 ((uint32_t)(RTC_TimeStruct->RTC_Minutes) << 8) | \
781 ((uint32_t)RTC_TimeStruct->RTC_Seconds) | \
782 ((uint32_t)(RTC_TimeStruct->RTC_H12) << 16));
786 tmpreg = (uint32_t)(((uint32_t)RTC_ByteToBcd2(RTC_TimeStruct->RTC_Hours) << 16) | \
787 ((uint32_t)RTC_ByteToBcd2(RTC_TimeStruct->RTC_Minutes) << 8) | \
788 ((uint32_t)RTC_ByteToBcd2(RTC_TimeStruct->RTC_Seconds)) | \
789 (((uint32_t)RTC_TimeStruct->RTC_H12) << 16));
792 /* Disable the write protection for RTC registers */
796 /* Set Initialization mode */
797 if (RTC_EnterInitMode() == ERROR)
803 /* Set the RTC_TR register */
804 RTC->TR = (uint32_t)(tmpreg & RTC_TR_RESERVED_MASK);
806 /* Exit Initialization mode */
809 /* If RTC_CR_BYPSHAD bit = 0, wait for synchro else this check is not needed */
810 if ((RTC->CR & RTC_CR_BYPSHAD) == RESET)
812 if (RTC_WaitForSynchro() == ERROR)
827 /* Enable the write protection for RTC registers */
834 * @brief Fills each RTC_TimeStruct member with its default value
835 * (Time = 00h:00min:00sec).
836 * @param RTC_TimeStruct: pointer to a RTC_TimeTypeDef structure which will be
840 void RTC_TimeStructInit(RTC_TimeTypeDef* RTC_TimeStruct)
842 /* Time = 00h:00min:00sec */
843 RTC_TimeStruct->RTC_H12 = RTC_H12_AM;
844 RTC_TimeStruct->RTC_Hours = 0;
845 RTC_TimeStruct->RTC_Minutes = 0;
846 RTC_TimeStruct->RTC_Seconds = 0;
850 * @brief Get the RTC current Time.
851 * @param RTC_Format: specifies the format of the returned parameters.
852 * This parameter can be one of the following values:
853 * @arg RTC_Format_BIN: Binary data format
854 * @arg RTC_Format_BCD: BCD data format
855 * @param RTC_TimeStruct: pointer to a RTC_TimeTypeDef structure that will
856 * contain the returned current time configuration.
859 void RTC_GetTime(uint32_t RTC_Format, RTC_TimeTypeDef* RTC_TimeStruct)
863 /* Check the parameters */
864 assert_param(IS_RTC_FORMAT(RTC_Format));
866 /* Get the RTC_TR register */
867 tmpreg = (uint32_t)(RTC->TR & RTC_TR_RESERVED_MASK);
869 /* Fill the structure fields with the read parameters */
870 RTC_TimeStruct->RTC_Hours = (uint8_t)((tmpreg & (RTC_TR_HT | RTC_TR_HU)) >> 16);
871 RTC_TimeStruct->RTC_Minutes = (uint8_t)((tmpreg & (RTC_TR_MNT | RTC_TR_MNU)) >>8);
872 RTC_TimeStruct->RTC_Seconds = (uint8_t)(tmpreg & (RTC_TR_ST | RTC_TR_SU));
873 RTC_TimeStruct->RTC_H12 = (uint8_t)((tmpreg & (RTC_TR_PM)) >> 16);
875 /* Check the input parameters format */
876 if (RTC_Format == RTC_Format_BIN)
878 /* Convert the structure parameters to Binary format */
879 RTC_TimeStruct->RTC_Hours = (uint8_t)RTC_Bcd2ToByte(RTC_TimeStruct->RTC_Hours);
880 RTC_TimeStruct->RTC_Minutes = (uint8_t)RTC_Bcd2ToByte(RTC_TimeStruct->RTC_Minutes);
881 RTC_TimeStruct->RTC_Seconds = (uint8_t)RTC_Bcd2ToByte(RTC_TimeStruct->RTC_Seconds);
886 * @brief Gets the RTC current Calendar Subseconds value.
887 * @note This function freeze the Time and Date registers after reading the
890 * @retval RTC current Calendar Subseconds value.
892 uint32_t RTC_GetSubSecond(void)
896 /* Get subseconds values from the correspondent registers*/
897 tmpreg = (uint32_t)(RTC->SSR);
899 /* Read DR register to unfroze calendar registers */
906 * @brief Set the RTC current date.
907 * @param RTC_Format: specifies the format of the entered parameters.
908 * This parameter can be one of the following values:
909 * @arg RTC_Format_BIN: Binary data format
910 * @arg RTC_Format_BCD: BCD data format
911 * @param RTC_DateStruct: pointer to a RTC_DateTypeDef structure that contains
912 * the date configuration information for the RTC.
913 * @retval An ErrorStatus enumeration value:
914 * - SUCCESS: RTC Date register is configured
915 * - ERROR: RTC Date register is not configured
917 ErrorStatus RTC_SetDate(uint32_t RTC_Format, RTC_DateTypeDef* RTC_DateStruct)
920 ErrorStatus status = ERROR;
922 /* Check the parameters */
923 assert_param(IS_RTC_FORMAT(RTC_Format));
925 if ((RTC_Format == RTC_Format_BIN) && ((RTC_DateStruct->RTC_Month & 0x10) == 0x10))
927 RTC_DateStruct->RTC_Month = (RTC_DateStruct->RTC_Month & (uint32_t)~(0x10)) + 0x0A;
929 if (RTC_Format == RTC_Format_BIN)
931 assert_param(IS_RTC_YEAR(RTC_DateStruct->RTC_Year));
932 assert_param(IS_RTC_MONTH(RTC_DateStruct->RTC_Month));
933 assert_param(IS_RTC_DATE(RTC_DateStruct->RTC_Date));
937 assert_param(IS_RTC_YEAR(RTC_Bcd2ToByte(RTC_DateStruct->RTC_Year)));
938 tmpreg = RTC_Bcd2ToByte(RTC_DateStruct->RTC_Month);
939 assert_param(IS_RTC_MONTH(tmpreg));
940 tmpreg = RTC_Bcd2ToByte(RTC_DateStruct->RTC_Date);
941 assert_param(IS_RTC_DATE(tmpreg));
943 assert_param(IS_RTC_WEEKDAY(RTC_DateStruct->RTC_WeekDay));
945 /* Check the input parameters format */
946 if (RTC_Format != RTC_Format_BIN)
948 tmpreg = ((((uint32_t)RTC_DateStruct->RTC_Year) << 16) | \
949 (((uint32_t)RTC_DateStruct->RTC_Month) << 8) | \
950 ((uint32_t)RTC_DateStruct->RTC_Date) | \
951 (((uint32_t)RTC_DateStruct->RTC_WeekDay) << 13));
955 tmpreg = (((uint32_t)RTC_ByteToBcd2(RTC_DateStruct->RTC_Year) << 16) | \
956 ((uint32_t)RTC_ByteToBcd2(RTC_DateStruct->RTC_Month) << 8) | \
957 ((uint32_t)RTC_ByteToBcd2(RTC_DateStruct->RTC_Date)) | \
958 ((uint32_t)RTC_DateStruct->RTC_WeekDay << 13));
961 /* Disable the write protection for RTC registers */
965 /* Set Initialization mode */
966 if (RTC_EnterInitMode() == ERROR)
972 /* Set the RTC_DR register */
973 RTC->DR = (uint32_t)(tmpreg & RTC_DR_RESERVED_MASK);
975 /* Exit Initialization mode */
978 /* If RTC_CR_BYPSHAD bit = 0, wait for synchro else this check is not needed */
979 if ((RTC->CR & RTC_CR_BYPSHAD) == RESET)
981 if (RTC_WaitForSynchro() == ERROR)
995 /* Enable the write protection for RTC registers */
1002 * @brief Fills each RTC_DateStruct member with its default value
1003 * (Monday, January 01 xx00).
1004 * @param RTC_DateStruct: pointer to a RTC_DateTypeDef structure which will be
1008 void RTC_DateStructInit(RTC_DateTypeDef* RTC_DateStruct)
1010 /* Monday, January 01 xx00 */
1011 RTC_DateStruct->RTC_WeekDay = RTC_Weekday_Monday;
1012 RTC_DateStruct->RTC_Date = 1;
1013 RTC_DateStruct->RTC_Month = RTC_Month_January;
1014 RTC_DateStruct->RTC_Year = 0;
1018 * @brief Get the RTC current date.
1019 * @param RTC_Format: specifies the format of the returned parameters.
1020 * This parameter can be one of the following values:
1021 * @arg RTC_Format_BIN: Binary data format
1022 * @arg RTC_Format_BCD: BCD data format
1023 * @param RTC_DateStruct: pointer to a RTC_DateTypeDef structure that will
1024 * contain the returned current date configuration.
1027 void RTC_GetDate(uint32_t RTC_Format, RTC_DateTypeDef* RTC_DateStruct)
1029 uint32_t tmpreg = 0;
1031 /* Check the parameters */
1032 assert_param(IS_RTC_FORMAT(RTC_Format));
1034 /* Get the RTC_TR register */
1035 tmpreg = (uint32_t)(RTC->DR & RTC_DR_RESERVED_MASK);
1037 /* Fill the structure fields with the read parameters */
1038 RTC_DateStruct->RTC_Year = (uint8_t)((tmpreg & (RTC_DR_YT | RTC_DR_YU)) >> 16);
1039 RTC_DateStruct->RTC_Month = (uint8_t)((tmpreg & (RTC_DR_MT | RTC_DR_MU)) >> 8);
1040 RTC_DateStruct->RTC_Date = (uint8_t)(tmpreg & (RTC_DR_DT | RTC_DR_DU));
1041 RTC_DateStruct->RTC_WeekDay = (uint8_t)((tmpreg & (RTC_DR_WDU)) >> 13);
1043 /* Check the input parameters format */
1044 if (RTC_Format == RTC_Format_BIN)
1046 /* Convert the structure parameters to Binary format */
1047 RTC_DateStruct->RTC_Year = (uint8_t)RTC_Bcd2ToByte(RTC_DateStruct->RTC_Year);
1048 RTC_DateStruct->RTC_Month = (uint8_t)RTC_Bcd2ToByte(RTC_DateStruct->RTC_Month);
1049 RTC_DateStruct->RTC_Date = (uint8_t)RTC_Bcd2ToByte(RTC_DateStruct->RTC_Date);
1050 RTC_DateStruct->RTC_WeekDay = (uint8_t)(RTC_DateStruct->RTC_WeekDay);
1058 /** @defgroup RTC_Group3 Alarms configuration functions
1059 * @brief Alarms (Alarm A and Alarm B) configuration functions
1062 ===============================================================================
1063 ##### Alarms (Alarm A and Alarm B) configuration functions #####
1064 ===============================================================================
1065 [..] This section provides functions allowing to program and read the RTC Alarms.
1072 * @brief Set the specified RTC Alarm.
1073 * @note The Alarm register can only be written when the corresponding Alarm
1074 * is disabled (Use the RTC_AlarmCmd(DISABLE)).
1075 * @param RTC_Format: specifies the format of the returned parameters.
1076 * This parameter can be one of the following values:
1077 * @arg RTC_Format_BIN: Binary data format
1078 * @arg RTC_Format_BCD: BCD data format
1079 * @param RTC_Alarm: specifies the alarm to be configured.
1080 * This parameter can be one of the following values:
1081 * @arg RTC_Alarm_A: to select Alarm A
1082 * @arg RTC_Alarm_B: to select Alarm B
1083 * @param RTC_AlarmStruct: pointer to a RTC_AlarmTypeDef structure that
1084 * contains the alarm configuration parameters.
1087 void RTC_SetAlarm(uint32_t RTC_Format, uint32_t RTC_Alarm, RTC_AlarmTypeDef* RTC_AlarmStruct)
1089 uint32_t tmpreg = 0;
1091 /* Check the parameters */
1092 assert_param(IS_RTC_FORMAT(RTC_Format));
1093 assert_param(IS_RTC_ALARM(RTC_Alarm));
1094 assert_param(IS_ALARM_MASK(RTC_AlarmStruct->RTC_AlarmMask));
1095 assert_param(IS_RTC_ALARM_DATE_WEEKDAY_SEL(RTC_AlarmStruct->RTC_AlarmDateWeekDaySel));
1097 if (RTC_Format == RTC_Format_BIN)
1099 if ((RTC->CR & RTC_CR_FMT) != (uint32_t)RESET)
1101 assert_param(IS_RTC_HOUR12(RTC_AlarmStruct->RTC_AlarmTime.RTC_Hours));
1102 assert_param(IS_RTC_H12(RTC_AlarmStruct->RTC_AlarmTime.RTC_H12));
1106 RTC_AlarmStruct->RTC_AlarmTime.RTC_H12 = 0x00;
1107 assert_param(IS_RTC_HOUR24(RTC_AlarmStruct->RTC_AlarmTime.RTC_Hours));
1109 assert_param(IS_RTC_MINUTES(RTC_AlarmStruct->RTC_AlarmTime.RTC_Minutes));
1110 assert_param(IS_RTC_SECONDS(RTC_AlarmStruct->RTC_AlarmTime.RTC_Seconds));
1112 if(RTC_AlarmStruct->RTC_AlarmDateWeekDaySel == RTC_AlarmDateWeekDaySel_Date)
1114 assert_param(IS_RTC_ALARM_DATE_WEEKDAY_DATE(RTC_AlarmStruct->RTC_AlarmDateWeekDay));
1118 assert_param(IS_RTC_ALARM_DATE_WEEKDAY_WEEKDAY(RTC_AlarmStruct->RTC_AlarmDateWeekDay));
1123 if ((RTC->CR & RTC_CR_FMT) != (uint32_t)RESET)
1125 tmpreg = RTC_Bcd2ToByte(RTC_AlarmStruct->RTC_AlarmTime.RTC_Hours);
1126 assert_param(IS_RTC_HOUR12(tmpreg));
1127 assert_param(IS_RTC_H12(RTC_AlarmStruct->RTC_AlarmTime.RTC_H12));
1131 RTC_AlarmStruct->RTC_AlarmTime.RTC_H12 = 0x00;
1132 assert_param(IS_RTC_HOUR24(RTC_Bcd2ToByte(RTC_AlarmStruct->RTC_AlarmTime.RTC_Hours)));
1135 assert_param(IS_RTC_MINUTES(RTC_Bcd2ToByte(RTC_AlarmStruct->RTC_AlarmTime.RTC_Minutes)));
1136 assert_param(IS_RTC_SECONDS(RTC_Bcd2ToByte(RTC_AlarmStruct->RTC_AlarmTime.RTC_Seconds)));
1138 if(RTC_AlarmStruct->RTC_AlarmDateWeekDaySel == RTC_AlarmDateWeekDaySel_Date)
1140 tmpreg = RTC_Bcd2ToByte(RTC_AlarmStruct->RTC_AlarmDateWeekDay);
1141 assert_param(IS_RTC_ALARM_DATE_WEEKDAY_DATE(tmpreg));
1145 tmpreg = RTC_Bcd2ToByte(RTC_AlarmStruct->RTC_AlarmDateWeekDay);
1146 assert_param(IS_RTC_ALARM_DATE_WEEKDAY_WEEKDAY(tmpreg));
1150 /* Check the input parameters format */
1151 if (RTC_Format != RTC_Format_BIN)
1153 tmpreg = (((uint32_t)(RTC_AlarmStruct->RTC_AlarmTime.RTC_Hours) << 16) | \
1154 ((uint32_t)(RTC_AlarmStruct->RTC_AlarmTime.RTC_Minutes) << 8) | \
1155 ((uint32_t)RTC_AlarmStruct->RTC_AlarmTime.RTC_Seconds) | \
1156 ((uint32_t)(RTC_AlarmStruct->RTC_AlarmTime.RTC_H12) << 16) | \
1157 ((uint32_t)(RTC_AlarmStruct->RTC_AlarmDateWeekDay) << 24) | \
1158 ((uint32_t)RTC_AlarmStruct->RTC_AlarmDateWeekDaySel) | \
1159 ((uint32_t)RTC_AlarmStruct->RTC_AlarmMask));
1163 tmpreg = (((uint32_t)RTC_ByteToBcd2(RTC_AlarmStruct->RTC_AlarmTime.RTC_Hours) << 16) | \
1164 ((uint32_t)RTC_ByteToBcd2(RTC_AlarmStruct->RTC_AlarmTime.RTC_Minutes) << 8) | \
1165 ((uint32_t)RTC_ByteToBcd2(RTC_AlarmStruct->RTC_AlarmTime.RTC_Seconds)) | \
1166 ((uint32_t)(RTC_AlarmStruct->RTC_AlarmTime.RTC_H12) << 16) | \
1167 ((uint32_t)RTC_ByteToBcd2(RTC_AlarmStruct->RTC_AlarmDateWeekDay) << 24) | \
1168 ((uint32_t)RTC_AlarmStruct->RTC_AlarmDateWeekDaySel) | \
1169 ((uint32_t)RTC_AlarmStruct->RTC_AlarmMask));
1172 /* Disable the write protection for RTC registers */
1176 /* Configure the Alarm register */
1177 if (RTC_Alarm == RTC_Alarm_A)
1179 RTC->ALRMAR = (uint32_t)tmpreg;
1183 RTC->ALRMBR = (uint32_t)tmpreg;
1186 /* Enable the write protection for RTC registers */
1191 * @brief Fills each RTC_AlarmStruct member with its default value
1192 * (Time = 00h:00mn:00sec / Date = 1st day of the month/Mask =
1193 * all fields are masked).
1194 * @param RTC_AlarmStruct: pointer to a @ref RTC_AlarmTypeDef structure which
1195 * will be initialized.
1198 void RTC_AlarmStructInit(RTC_AlarmTypeDef* RTC_AlarmStruct)
1200 /* Alarm Time Settings : Time = 00h:00mn:00sec */
1201 RTC_AlarmStruct->RTC_AlarmTime.RTC_H12 = RTC_H12_AM;
1202 RTC_AlarmStruct->RTC_AlarmTime.RTC_Hours = 0;
1203 RTC_AlarmStruct->RTC_AlarmTime.RTC_Minutes = 0;
1204 RTC_AlarmStruct->RTC_AlarmTime.RTC_Seconds = 0;
1206 /* Alarm Date Settings : Date = 1st day of the month */
1207 RTC_AlarmStruct->RTC_AlarmDateWeekDaySel = RTC_AlarmDateWeekDaySel_Date;
1208 RTC_AlarmStruct->RTC_AlarmDateWeekDay = 1;
1210 /* Alarm Masks Settings : Mask = all fields are not masked */
1211 RTC_AlarmStruct->RTC_AlarmMask = RTC_AlarmMask_None;
1215 * @brief Get the RTC Alarm value and masks.
1216 * @param RTC_Format: specifies the format of the output parameters.
1217 * This parameter can be one of the following values:
1218 * @arg RTC_Format_BIN: Binary data format
1219 * @arg RTC_Format_BCD: BCD data format
1220 * @param RTC_Alarm: specifies the alarm to be read.
1221 * This parameter can be one of the following values:
1222 * @arg RTC_Alarm_A: to select Alarm A
1223 * @arg RTC_Alarm_B: to select Alarm B
1224 * @param RTC_AlarmStruct: pointer to a RTC_AlarmTypeDef structure that will
1225 * contains the output alarm configuration values.
1228 void RTC_GetAlarm(uint32_t RTC_Format, uint32_t RTC_Alarm, RTC_AlarmTypeDef* RTC_AlarmStruct)
1230 uint32_t tmpreg = 0;
1232 /* Check the parameters */
1233 assert_param(IS_RTC_FORMAT(RTC_Format));
1234 assert_param(IS_RTC_ALARM(RTC_Alarm));
1236 /* Get the RTC_ALRMxR register */
1237 if (RTC_Alarm == RTC_Alarm_A)
1239 tmpreg = (uint32_t)(RTC->ALRMAR);
1243 tmpreg = (uint32_t)(RTC->ALRMBR);
1246 /* Fill the structure with the read parameters */
1247 RTC_AlarmStruct->RTC_AlarmTime.RTC_Hours = (uint32_t)((tmpreg & (RTC_ALRMAR_HT | \
1248 RTC_ALRMAR_HU)) >> 16);
1249 RTC_AlarmStruct->RTC_AlarmTime.RTC_Minutes = (uint32_t)((tmpreg & (RTC_ALRMAR_MNT | \
1250 RTC_ALRMAR_MNU)) >> 8);
1251 RTC_AlarmStruct->RTC_AlarmTime.RTC_Seconds = (uint32_t)(tmpreg & (RTC_ALRMAR_ST | \
1253 RTC_AlarmStruct->RTC_AlarmTime.RTC_H12 = (uint32_t)((tmpreg & RTC_ALRMAR_PM) >> 16);
1254 RTC_AlarmStruct->RTC_AlarmDateWeekDay = (uint32_t)((tmpreg & (RTC_ALRMAR_DT | RTC_ALRMAR_DU)) >> 24);
1255 RTC_AlarmStruct->RTC_AlarmDateWeekDaySel = (uint32_t)(tmpreg & RTC_ALRMAR_WDSEL);
1256 RTC_AlarmStruct->RTC_AlarmMask = (uint32_t)(tmpreg & RTC_AlarmMask_All);
1258 if (RTC_Format == RTC_Format_BIN)
1260 RTC_AlarmStruct->RTC_AlarmTime.RTC_Hours = RTC_Bcd2ToByte(RTC_AlarmStruct-> \
1261 RTC_AlarmTime.RTC_Hours);
1262 RTC_AlarmStruct->RTC_AlarmTime.RTC_Minutes = RTC_Bcd2ToByte(RTC_AlarmStruct-> \
1263 RTC_AlarmTime.RTC_Minutes);
1264 RTC_AlarmStruct->RTC_AlarmTime.RTC_Seconds = RTC_Bcd2ToByte(RTC_AlarmStruct-> \
1265 RTC_AlarmTime.RTC_Seconds);
1266 RTC_AlarmStruct->RTC_AlarmDateWeekDay = RTC_Bcd2ToByte(RTC_AlarmStruct->RTC_AlarmDateWeekDay);
1271 * @brief Enables or disables the specified RTC Alarm.
1272 * @param RTC_Alarm: specifies the alarm to be configured.
1273 * This parameter can be any combination of the following values:
1274 * @arg RTC_Alarm_A: to select Alarm A
1275 * @arg RTC_Alarm_B: to select Alarm B
1276 * @param NewState: new state of the specified alarm.
1277 * This parameter can be: ENABLE or DISABLE.
1278 * @retval An ErrorStatus enumeration value:
1279 * - SUCCESS: RTC Alarm is enabled/disabled
1280 * - ERROR: RTC Alarm is not enabled/disabled
1282 ErrorStatus RTC_AlarmCmd(uint32_t RTC_Alarm, FunctionalState NewState)
1284 __IO uint32_t alarmcounter = 0x00;
1285 uint32_t alarmstatus = 0x00;
1286 ErrorStatus status = ERROR;
1288 /* Check the parameters */
1289 assert_param(IS_RTC_CMD_ALARM(RTC_Alarm));
1290 assert_param(IS_FUNCTIONAL_STATE(NewState));
1292 /* Disable the write protection for RTC registers */
1296 /* Configure the Alarm state */
1297 if (NewState != DISABLE)
1299 RTC->CR |= (uint32_t)RTC_Alarm;
1305 /* Disable the Alarm in RTC_CR register */
1306 RTC->CR &= (uint32_t)~RTC_Alarm;
1308 /* Wait till RTC ALRxWF flag is set and if Time out is reached exit */
1311 alarmstatus = RTC->ISR & (RTC_Alarm >> 8);
1313 } while((alarmcounter != INITMODE_TIMEOUT) && (alarmstatus == 0x00));
1315 if ((RTC->ISR & (RTC_Alarm >> 8)) == RESET)
1325 /* Enable the write protection for RTC registers */
1332 * @brief Configures the RTC AlarmA/B Subseconds value and mask.
1333 * @note This function is performed only when the Alarm is disabled.
1334 * @param RTC_Alarm: specifies the alarm to be configured.
1335 * This parameter can be one of the following values:
1336 * @arg RTC_Alarm_A: to select Alarm A
1337 * @arg RTC_Alarm_B: to select Alarm B
1338 * @param RTC_AlarmSubSecondValue: specifies the Subseconds value.
1339 * This parameter can be a value from 0 to 0x00007FFF.
1340 * @param RTC_AlarmSubSecondMask: specifies the Subseconds Mask.
1341 * This parameter can be any combination of the following values:
1342 * @arg RTC_AlarmSubSecondMask_All : All Alarm SS fields are masked.
1343 * There is no comparison on sub seconds for Alarm.
1344 * @arg RTC_AlarmSubSecondMask_SS14_1 : SS[14:1] are don't care in Alarm comparison.
1345 * Only SS[0] is compared
1346 * @arg RTC_AlarmSubSecondMask_SS14_2 : SS[14:2] are don't care in Alarm comparison.
1347 * Only SS[1:0] are compared
1348 * @arg RTC_AlarmSubSecondMask_SS14_3 : SS[14:3] are don't care in Alarm comparison.
1349 * Only SS[2:0] are compared
1350 * @arg RTC_AlarmSubSecondMask_SS14_4 : SS[14:4] are don't care in Alarm comparison.
1351 * Only SS[3:0] are compared
1352 * @arg RTC_AlarmSubSecondMask_SS14_5 : SS[14:5] are don't care in Alarm comparison.
1353 * Only SS[4:0] are compared
1354 * @arg RTC_AlarmSubSecondMask_SS14_6 : SS[14:6] are don't care in Alarm comparison.
1355 * Only SS[5:0] are compared
1356 * @arg RTC_AlarmSubSecondMask_SS14_7 : SS[14:7] are don't care in Alarm comparison.
1357 * Only SS[6:0] are compared
1358 * @arg RTC_AlarmSubSecondMask_SS14_8 : SS[14:8] are don't care in Alarm comparison.
1359 * Only SS[7:0] are compared
1360 * @arg RTC_AlarmSubSecondMask_SS14_9 : SS[14:9] are don't care in Alarm comparison.
1361 * Only SS[8:0] are compared
1362 * @arg RTC_AlarmSubSecondMask_SS14_10: SS[14:10] are don't care in Alarm comparison.
1363 * Only SS[9:0] are compared
1364 * @arg RTC_AlarmSubSecondMask_SS14_11: SS[14:11] are don't care in Alarm comparison.
1365 * Only SS[10:0] are compared
1366 * @arg RTC_AlarmSubSecondMask_SS14_12: SS[14:12] are don't care in Alarm comparison.
1367 * Only SS[11:0] are compared
1368 * @arg RTC_AlarmSubSecondMask_SS14_13: SS[14:13] are don't care in Alarm comparison.
1369 * Only SS[12:0] are compared
1370 * @arg RTC_AlarmSubSecondMask_SS14 : SS[14] is don't care in Alarm comparison.
1371 * Only SS[13:0] are compared
1372 * @arg RTC_AlarmSubSecondMask_None : SS[14:0] are compared and must match
1376 void RTC_AlarmSubSecondConfig(uint32_t RTC_Alarm, uint32_t RTC_AlarmSubSecondValue, uint32_t RTC_AlarmSubSecondMask)
1378 uint32_t tmpreg = 0;
1380 /* Check the parameters */
1381 assert_param(IS_RTC_ALARM(RTC_Alarm));
1382 assert_param(IS_RTC_ALARM_SUB_SECOND_VALUE(RTC_AlarmSubSecondValue));
1383 assert_param(IS_RTC_ALARM_SUB_SECOND_MASK(RTC_AlarmSubSecondMask));
1385 /* Disable the write protection for RTC registers */
1389 /* Configure the Alarm A or Alarm B SubSecond registers */
1390 tmpreg = (uint32_t) (uint32_t)(RTC_AlarmSubSecondValue) | (uint32_t)(RTC_AlarmSubSecondMask);
1392 if (RTC_Alarm == RTC_Alarm_A)
1394 /* Configure the AlarmA SubSecond register */
1395 RTC->ALRMASSR = tmpreg;
1399 /* Configure the Alarm B SubSecond register */
1400 RTC->ALRMBSSR = tmpreg;
1403 /* Enable the write protection for RTC registers */
1409 * @brief Gets the RTC Alarm Subseconds value.
1410 * @param RTC_Alarm: specifies the alarm to be read.
1411 * This parameter can be one of the following values:
1412 * @arg RTC_Alarm_A: to select Alarm A
1413 * @arg RTC_Alarm_B: to select Alarm B
1415 * @retval RTC Alarm Subseconds value.
1417 uint32_t RTC_GetAlarmSubSecond(uint32_t RTC_Alarm)
1419 uint32_t tmpreg = 0;
1421 /* Get the RTC_ALRMxR register */
1422 if (RTC_Alarm == RTC_Alarm_A)
1424 tmpreg = (uint32_t)((RTC->ALRMASSR) & RTC_ALRMASSR_SS);
1428 tmpreg = (uint32_t)((RTC->ALRMBSSR) & RTC_ALRMBSSR_SS);
1438 /** @defgroup RTC_Group4 WakeUp Timer configuration functions
1439 * @brief WakeUp Timer configuration functions
1442 ===============================================================================
1443 ##### WakeUp Timer configuration functions #####
1444 ===============================================================================
1445 [..] This section provide functions allowing to program and read the RTC WakeUp.
1452 * @brief Configures the RTC Wakeup clock source.
1453 * @note The WakeUp Clock source can only be changed when the RTC WakeUp
1454 * is disabled (Use the RTC_WakeUpCmd(DISABLE)).
1455 * @param RTC_WakeUpClock: Wakeup Clock source.
1456 * This parameter can be one of the following values:
1457 * @arg RTC_WakeUpClock_RTCCLK_Div16: RTC Wakeup Counter Clock = RTCCLK/16
1458 * @arg RTC_WakeUpClock_RTCCLK_Div8: RTC Wakeup Counter Clock = RTCCLK/8
1459 * @arg RTC_WakeUpClock_RTCCLK_Div4: RTC Wakeup Counter Clock = RTCCLK/4
1460 * @arg RTC_WakeUpClock_RTCCLK_Div2: RTC Wakeup Counter Clock = RTCCLK/2
1461 * @arg RTC_WakeUpClock_CK_SPRE_16bits: RTC Wakeup Counter Clock = CK_SPRE
1462 * @arg RTC_WakeUpClock_CK_SPRE_17bits: RTC Wakeup Counter Clock = CK_SPRE
1465 void RTC_WakeUpClockConfig(uint32_t RTC_WakeUpClock)
1467 /* Check the parameters */
1468 assert_param(IS_RTC_WAKEUP_CLOCK(RTC_WakeUpClock));
1470 /* Disable the write protection for RTC registers */
1474 /* Clear the Wakeup Timer clock source bits in CR register */
1475 RTC->CR &= (uint32_t)~RTC_CR_WUCKSEL;
1477 /* Configure the clock source */
1478 RTC->CR |= (uint32_t)RTC_WakeUpClock;
1480 /* Enable the write protection for RTC registers */
1485 * @brief Configures the RTC Wakeup counter.
1486 * @note The RTC WakeUp counter can only be written when the RTC WakeUp
1487 * is disabled (Use the RTC_WakeUpCmd(DISABLE)).
1488 * @param RTC_WakeUpCounter: specifies the WakeUp counter.
1489 * This parameter can be a value from 0x0000 to 0xFFFF.
1492 void RTC_SetWakeUpCounter(uint32_t RTC_WakeUpCounter)
1494 /* Check the parameters */
1495 assert_param(IS_RTC_WAKEUP_COUNTER(RTC_WakeUpCounter));
1497 /* Disable the write protection for RTC registers */
1501 /* Configure the Wakeup Timer counter */
1502 RTC->WUTR = (uint32_t)RTC_WakeUpCounter;
1504 /* Enable the write protection for RTC registers */
1509 * @brief Returns the RTC WakeUp timer counter value.
1511 * @retval The RTC WakeUp Counter value.
1513 uint32_t RTC_GetWakeUpCounter(void)
1515 /* Get the counter value */
1516 return ((uint32_t)(RTC->WUTR & RTC_WUTR_WUT));
1520 * @brief Enables or Disables the RTC WakeUp timer.
1521 * @param NewState: new state of the WakeUp timer.
1522 * This parameter can be: ENABLE or DISABLE.
1525 ErrorStatus RTC_WakeUpCmd(FunctionalState NewState)
1527 __IO uint32_t wutcounter = 0x00;
1528 uint32_t wutwfstatus = 0x00;
1529 ErrorStatus status = ERROR;
1531 /* Check the parameters */
1532 assert_param(IS_FUNCTIONAL_STATE(NewState));
1534 /* Disable the write protection for RTC registers */
1538 if (NewState != DISABLE)
1540 /* Enable the Wakeup Timer */
1541 RTC->CR |= (uint32_t)RTC_CR_WUTE;
1546 /* Disable the Wakeup Timer */
1547 RTC->CR &= (uint32_t)~RTC_CR_WUTE;
1548 /* Wait till RTC WUTWF flag is set and if Time out is reached exit */
1551 wutwfstatus = RTC->ISR & RTC_ISR_WUTWF;
1553 } while((wutcounter != INITMODE_TIMEOUT) && (wutwfstatus == 0x00));
1555 if ((RTC->ISR & RTC_ISR_WUTWF) == RESET)
1565 /* Enable the write protection for RTC registers */
1575 /** @defgroup RTC_Group5 Daylight Saving configuration functions
1576 * @brief Daylight Saving configuration functions
1579 ===============================================================================
1580 ##### Daylight Saving configuration functions #####
1581 ===============================================================================
1582 [..] This section provide functions allowing to configure the RTC DayLight Saving.
1589 * @brief Adds or substract one hour from the current time.
1590 * @param RTC_DayLightSaveOperation: the value of hour adjustment.
1591 * This parameter can be one of the following values:
1592 * @arg RTC_DayLightSaving_SUB1H: Substract one hour (winter time)
1593 * @arg RTC_DayLightSaving_ADD1H: Add one hour (summer time)
1594 * @param RTC_StoreOperation: Specifies the value to be written in the BCK bit
1595 * in CR register to store the operation.
1596 * This parameter can be one of the following values:
1597 * @arg RTC_StoreOperation_Reset: BCK Bit Reset
1598 * @arg RTC_StoreOperation_Set: BCK Bit Set
1601 void RTC_DayLightSavingConfig(uint32_t RTC_DayLightSaving, uint32_t RTC_StoreOperation)
1603 /* Check the parameters */
1604 assert_param(IS_RTC_DAYLIGHT_SAVING(RTC_DayLightSaving));
1605 assert_param(IS_RTC_STORE_OPERATION(RTC_StoreOperation));
1607 /* Disable the write protection for RTC registers */
1611 /* Clear the bits to be configured */
1612 RTC->CR &= (uint32_t)~(RTC_CR_BCK);
1614 /* Configure the RTC_CR register */
1615 RTC->CR |= (uint32_t)(RTC_DayLightSaving | RTC_StoreOperation);
1617 /* Enable the write protection for RTC registers */
1622 * @brief Returns the RTC Day Light Saving stored operation.
1624 * @retval RTC Day Light Saving stored operation.
1625 * - RTC_StoreOperation_Reset
1626 * - RTC_StoreOperation_Set
1628 uint32_t RTC_GetStoreOperation(void)
1630 return (RTC->CR & RTC_CR_BCK);
1637 /** @defgroup RTC_Group6 Output pin Configuration function
1638 * @brief Output pin Configuration function
1641 ===============================================================================
1642 ##### Output pin Configuration function #####
1643 ===============================================================================
1644 [..] This section provide functions allowing to configure the RTC Output source.
1651 * @brief Configures the RTC output source (AFO_ALARM).
1652 * @param RTC_Output: Specifies which signal will be routed to the RTC output.
1653 * This parameter can be one of the following values:
1654 * @arg RTC_Output_Disable: No output selected
1655 * @arg RTC_Output_AlarmA: signal of AlarmA mapped to output
1656 * @arg RTC_Output_AlarmB: signal of AlarmB mapped to output
1657 * @arg RTC_Output_WakeUp: signal of WakeUp mapped to output
1658 * @param RTC_OutputPolarity: Specifies the polarity of the output signal.
1659 * This parameter can be one of the following:
1660 * @arg RTC_OutputPolarity_High: The output pin is high when the
1661 * ALRAF/ALRBF/WUTF is high (depending on OSEL)
1662 * @arg RTC_OutputPolarity_Low: The output pin is low when the
1663 * ALRAF/ALRBF/WUTF is high (depending on OSEL)
1666 void RTC_OutputConfig(uint32_t RTC_Output, uint32_t RTC_OutputPolarity)
1668 /* Check the parameters */
1669 assert_param(IS_RTC_OUTPUT(RTC_Output));
1670 assert_param(IS_RTC_OUTPUT_POL(RTC_OutputPolarity));
1672 /* Disable the write protection for RTC registers */
1676 /* Clear the bits to be configured */
1677 RTC->CR &= (uint32_t)~(RTC_CR_OSEL | RTC_CR_POL);
1679 /* Configure the output selection and polarity */
1680 RTC->CR |= (uint32_t)(RTC_Output | RTC_OutputPolarity);
1682 /* Enable the write protection for RTC registers */
1690 /** @defgroup RTC_Group7 Digital Calibration configuration functions
1691 * @brief Digital Calibration configuration functions
1694 ===============================================================================
1695 ##### Digital Calibration configuration functions #####
1696 ===============================================================================
1703 * @brief Enables or disables the RTC clock to be output through the relative
1705 * @param NewState: new state of the digital calibration Output.
1706 * This parameter can be: ENABLE or DISABLE.
1709 void RTC_CalibOutputCmd(FunctionalState NewState)
1711 /* Check the parameters */
1712 assert_param(IS_FUNCTIONAL_STATE(NewState));
1714 /* Disable the write protection for RTC registers */
1718 if (NewState != DISABLE)
1720 /* Enable the RTC clock output */
1721 RTC->CR |= (uint32_t)RTC_CR_COE;
1725 /* Disable the RTC clock output */
1726 RTC->CR &= (uint32_t)~RTC_CR_COE;
1729 /* Enable the write protection for RTC registers */
1734 * @brief Configures the Calibration Pinout (RTC_CALIB) Selection (1Hz or 512Hz).
1735 * @param RTC_CalibOutput : Select the Calibration output Selection .
1736 * This parameter can be one of the following values:
1737 * @arg RTC_CalibOutput_512Hz: A signal has a regular waveform at 512Hz.
1738 * @arg RTC_CalibOutput_1Hz : A signal has a regular waveform at 1Hz.
1741 void RTC_CalibOutputConfig(uint32_t RTC_CalibOutput)
1743 /* Check the parameters */
1744 assert_param(IS_RTC_CALIB_OUTPUT(RTC_CalibOutput));
1746 /* Disable the write protection for RTC registers */
1750 /*clear flags before config*/
1751 RTC->CR &= (uint32_t)~(RTC_CR_COSEL);
1753 /* Configure the RTC_CR register */
1754 RTC->CR |= (uint32_t)RTC_CalibOutput;
1756 /* Enable the write protection for RTC registers */
1761 * @brief Configures the Smooth Calibration Settings.
1762 * @param RTC_SmoothCalibPeriod : Select the Smooth Calibration Period.
1763 * This parameter can be can be one of the following values:
1764 * @arg RTC_SmoothCalibPeriod_32sec : The smooth calibration periode is 32s.
1765 * @arg RTC_SmoothCalibPeriod_16sec : The smooth calibration periode is 16s.
1766 * @arg RTC_SmoothCalibPeriod_8sec : The smooth calibartion periode is 8s.
1767 * @param RTC_SmoothCalibPlusPulses : Select to Set or reset the CALP bit.
1768 * This parameter can be one of the following values:
1769 * @arg RTC_SmoothCalibPlusPulses_Set : Add one RTCCLK puls every 2**11 pulses.
1770 * @arg RTC_SmoothCalibPlusPulses_Reset: No RTCCLK pulses are added.
1771 * @param RTC_SmouthCalibMinusPulsesValue: Select the value of CALM[8:0] bits.
1772 * This parameter can be one any value from 0 to 0x000001FF.
1773 * @retval An ErrorStatus enumeration value:
1774 * - SUCCESS: RTC Calib registers are configured
1775 * - ERROR: RTC Calib registers are not configured
1777 ErrorStatus RTC_SmoothCalibConfig(uint32_t RTC_SmoothCalibPeriod,
1778 uint32_t RTC_SmoothCalibPlusPulses,
1779 uint32_t RTC_SmouthCalibMinusPulsesValue)
1781 ErrorStatus status = ERROR;
1782 uint32_t recalpfcount = 0;
1784 /* Check the parameters */
1785 assert_param(IS_RTC_SMOOTH_CALIB_PERIOD(RTC_SmoothCalibPeriod));
1786 assert_param(IS_RTC_SMOOTH_CALIB_PLUS(RTC_SmoothCalibPlusPulses));
1787 assert_param(IS_RTC_SMOOTH_CALIB_MINUS(RTC_SmouthCalibMinusPulsesValue));
1789 /* Disable the write protection for RTC registers */
1793 /* check if a calibration is pending*/
1794 if ((RTC->ISR & RTC_ISR_RECALPF) != RESET)
1796 /* wait until the Calibration is completed*/
1797 while (((RTC->ISR & RTC_ISR_RECALPF) != RESET) && (recalpfcount != RECALPF_TIMEOUT))
1803 /* check if the calibration pending is completed or if there is no calibration operation at all*/
1804 if ((RTC->ISR & RTC_ISR_RECALPF) == RESET)
1806 /* Configure the Smooth calibration settings */
1807 RTC->CALR = (uint32_t)((uint32_t)RTC_SmoothCalibPeriod | (uint32_t)RTC_SmoothCalibPlusPulses | (uint32_t)RTC_SmouthCalibMinusPulsesValue);
1816 /* Enable the write protection for RTC registers */
1819 return (ErrorStatus)(status);
1827 /** @defgroup RTC_Group8 TimeStamp configuration functions
1828 * @brief TimeStamp configuration functions
1831 ===============================================================================
1832 ##### TimeStamp configuration functions #####
1833 ===============================================================================
1840 * @brief Enables or Disables the RTC TimeStamp functionality with the
1841 * specified time stamp pin stimulating edge.
1842 * @param RTC_TimeStampEdge: Specifies the pin edge on which the TimeStamp is
1844 * This parameter can be one of the following:
1845 * @arg RTC_TimeStampEdge_Rising: the Time stamp event occurs on the rising
1846 * edge of the related pin.
1847 * @arg RTC_TimeStampEdge_Falling: the Time stamp event occurs on the
1848 * falling edge of the related pin.
1849 * @param NewState: new state of the TimeStamp.
1850 * This parameter can be: ENABLE or DISABLE.
1853 void RTC_TimeStampCmd(uint32_t RTC_TimeStampEdge, FunctionalState NewState)
1855 uint32_t tmpreg = 0;
1857 /* Check the parameters */
1858 assert_param(IS_RTC_TIMESTAMP_EDGE(RTC_TimeStampEdge));
1859 assert_param(IS_FUNCTIONAL_STATE(NewState));
1861 /* Get the RTC_CR register and clear the bits to be configured */
1862 tmpreg = (uint32_t)(RTC->CR & (uint32_t)~(RTC_CR_TSEDGE | RTC_CR_TSE));
1864 /* Get the new configuration */
1865 if (NewState != DISABLE)
1867 tmpreg |= (uint32_t)(RTC_TimeStampEdge | RTC_CR_TSE);
1871 tmpreg |= (uint32_t)(RTC_TimeStampEdge);
1874 /* Disable the write protection for RTC registers */
1878 /* Configure the Time Stamp TSEDGE and Enable bits */
1879 RTC->CR = (uint32_t)tmpreg;
1881 /* Enable the write protection for RTC registers */
1886 * @brief Gets the RTC TimeStamp value and masks.
1887 * @param RTC_Format: specifies the format of the output parameters.
1888 * This parameter can be one of the following values:
1889 * @arg RTC_Format_BIN: Binary data format
1890 * @arg RTC_Format_BCD: BCD data format
1891 * @param RTC_StampTimeStruct: pointer to a RTC_TimeTypeDef structure that will
1892 * contains the TimeStamp time values.
1893 * @param RTC_StampDateStruct: pointer to a RTC_DateTypeDef structure that will
1894 * contains the TimeStamp date values.
1897 void RTC_GetTimeStamp(uint32_t RTC_Format, RTC_TimeTypeDef* RTC_StampTimeStruct,
1898 RTC_DateTypeDef* RTC_StampDateStruct)
1900 uint32_t tmptime = 0, tmpdate = 0;
1902 /* Check the parameters */
1903 assert_param(IS_RTC_FORMAT(RTC_Format));
1905 /* Get the TimeStamp time and date registers values */
1906 tmptime = (uint32_t)(RTC->TSTR & RTC_TR_RESERVED_MASK);
1907 tmpdate = (uint32_t)(RTC->TSDR & RTC_DR_RESERVED_MASK);
1909 /* Fill the Time structure fields with the read parameters */
1910 RTC_StampTimeStruct->RTC_Hours = (uint8_t)((tmptime & (RTC_TR_HT | RTC_TR_HU)) >> 16);
1911 RTC_StampTimeStruct->RTC_Minutes = (uint8_t)((tmptime & (RTC_TR_MNT | RTC_TR_MNU)) >> 8);
1912 RTC_StampTimeStruct->RTC_Seconds = (uint8_t)(tmptime & (RTC_TR_ST | RTC_TR_SU));
1913 RTC_StampTimeStruct->RTC_H12 = (uint8_t)((tmptime & (RTC_TR_PM)) >> 16);
1915 /* Fill the Date structure fields with the read parameters */
1916 RTC_StampDateStruct->RTC_Year = 0;
1917 RTC_StampDateStruct->RTC_Month = (uint8_t)((tmpdate & (RTC_DR_MT | RTC_DR_MU)) >> 8);
1918 RTC_StampDateStruct->RTC_Date = (uint8_t)(tmpdate & (RTC_DR_DT | RTC_DR_DU));
1919 RTC_StampDateStruct->RTC_WeekDay = (uint8_t)((tmpdate & (RTC_DR_WDU)) >> 13);
1921 /* Check the input parameters format */
1922 if (RTC_Format == RTC_Format_BIN)
1924 /* Convert the Time structure parameters to Binary format */
1925 RTC_StampTimeStruct->RTC_Hours = (uint8_t)RTC_Bcd2ToByte(RTC_StampTimeStruct->RTC_Hours);
1926 RTC_StampTimeStruct->RTC_Minutes = (uint8_t)RTC_Bcd2ToByte(RTC_StampTimeStruct->RTC_Minutes);
1927 RTC_StampTimeStruct->RTC_Seconds = (uint8_t)RTC_Bcd2ToByte(RTC_StampTimeStruct->RTC_Seconds);
1929 /* Convert the Date structure parameters to Binary format */
1930 RTC_StampDateStruct->RTC_Month = (uint8_t)RTC_Bcd2ToByte(RTC_StampDateStruct->RTC_Month);
1931 RTC_StampDateStruct->RTC_Date = (uint8_t)RTC_Bcd2ToByte(RTC_StampDateStruct->RTC_Date);
1932 RTC_StampDateStruct->RTC_WeekDay = (uint8_t)RTC_Bcd2ToByte(RTC_StampDateStruct->RTC_WeekDay);
1937 * @brief Gets the RTC timestamp Subseconds value.
1939 * @retval RTC current timestamp Subseconds value.
1941 uint32_t RTC_GetTimeStampSubSecond(void)
1943 /* Get timestamp subseconds values from the correspondent registers */
1944 return (uint32_t)(RTC->TSSSR);
1951 /** @defgroup RTC_Group9 Tampers configuration functions
1952 * @brief Tampers configuration functions
1955 ===============================================================================
1956 ##### Tampers configuration functions #####
1957 ===============================================================================
1964 * @brief Configures the select Tamper pin edge.
1965 * @param RTC_Tamper: Selected tamper pin.
1966 * This parameter can be any combination of the following values:
1967 * @arg RTC_Tamper_1: Select Tamper 1.
1968 * @arg RTC_Tamper_2: Select Tamper 2.
1969 * @arg RTC_Tamper_3: Select Tamper 3.
1970 * @param RTC_TamperTrigger: Specifies the trigger on the tamper pin that
1971 * stimulates tamper event.
1972 * This parameter can be one of the following values:
1973 * @arg RTC_TamperTrigger_RisingEdge: Rising Edge of the tamper pin causes tamper event.
1974 * @arg RTC_TamperTrigger_FallingEdge: Falling Edge of the tamper pin causes tamper event.
1975 * @arg RTC_TamperTrigger_LowLevel: Low Level of the tamper pin causes tamper event.
1976 * @arg RTC_TamperTrigger_HighLevel: High Level of the tamper pin causes tamper event.
1979 void RTC_TamperTriggerConfig(uint32_t RTC_Tamper, uint32_t RTC_TamperTrigger)
1981 /* Check the parameters */
1982 assert_param(IS_RTC_TAMPER(RTC_Tamper));
1983 assert_param(IS_RTC_TAMPER_TRIGGER(RTC_TamperTrigger));
1985 /* Check if the active level for Tamper is rising edge (Low level)*/
1986 if (RTC_TamperTrigger == RTC_TamperTrigger_RisingEdge)
1988 /* Configure the RTC_TAFCR register */
1989 RTC->TAFCR &= (uint32_t)((uint32_t)~(RTC_Tamper << 1));
1993 /* Configure the RTC_TAFCR register */
1994 RTC->TAFCR |= (uint32_t)(RTC_Tamper << 1);
1999 * @brief Enables or Disables the Tamper detection.
2000 * @param RTC_Tamper: Selected tamper pin.
2001 * This parameter can be any combination of the following values:
2002 * @arg RTC_Tamper_1: Select Tamper 1.
2003 * @arg RTC_Tamper_2: Select Tamper 2.
2004 * @arg RTC_Tamper_3: Select Tamper 3.
2005 * @param NewState: new state of the tamper pin.
2006 * This parameter can be: ENABLE or DISABLE.
2009 void RTC_TamperCmd(uint32_t RTC_Tamper, FunctionalState NewState)
2011 /* Check the parameters */
2012 assert_param(IS_RTC_TAMPER(RTC_Tamper));
2013 assert_param(IS_FUNCTIONAL_STATE(NewState));
2015 if (NewState != DISABLE)
2017 /* Enable the selected Tamper pin */
2018 RTC->TAFCR |= (uint32_t)RTC_Tamper;
2022 /* Disable the selected Tamper pin */
2023 RTC->TAFCR &= (uint32_t)~RTC_Tamper;
2028 * @brief Configures the Tampers Filter.
2029 * @param RTC_TamperFilter: Specifies the tampers filter.
2030 * This parameter can be one of the following values:
2031 * @arg RTC_TamperFilter_Disable: Tamper filter is disabled.
2032 * @arg RTC_TamperFilter_2Sample: Tamper is activated after 2 consecutive
2033 * samples at the active level
2034 * @arg RTC_TamperFilter_4Sample: Tamper is activated after 4 consecutive
2035 * samples at the active level
2036 * @arg RTC_TamperFilter_8Sample: Tamper is activated after 8 consecutive
2037 * samples at the active level
2040 void RTC_TamperFilterConfig(uint32_t RTC_TamperFilter)
2042 /* Check the parameters */
2043 assert_param(IS_RTC_TAMPER_FILTER(RTC_TamperFilter));
2045 /* Clear TAMPFLT[1:0] bits in the RTC_TAFCR register */
2046 RTC->TAFCR &= (uint32_t)~(RTC_TAFCR_TAMPFLT);
2048 /* Configure the RTC_TAFCR register */
2049 RTC->TAFCR |= (uint32_t)RTC_TamperFilter;
2053 * @brief Configures the Tampers Sampling Frequency.
2054 * @param RTC_TamperSamplingFreq: Specifies the tampers Sampling Frequency.
2055 * This parameter can be one of the following values:
2056 * @arg RTC_TamperSamplingFreq_RTCCLK_Div32768: Each of the tamper inputs are sampled
2057 * with a frequency = RTCCLK / 32768
2058 * @arg RTC_TamperSamplingFreq_RTCCLK_Div16384: Each of the tamper inputs are sampled
2059 * with a frequency = RTCCLK / 16384
2060 * @arg RTC_TamperSamplingFreq_RTCCLK_Div8192: Each of the tamper inputs are sampled
2061 * with a frequency = RTCCLK / 8192
2062 * @arg RTC_TamperSamplingFreq_RTCCLK_Div4096: Each of the tamper inputs are sampled
2063 * with a frequency = RTCCLK / 4096
2064 * @arg RTC_TamperSamplingFreq_RTCCLK_Div2048: Each of the tamper inputs are sampled
2065 * with a frequency = RTCCLK / 2048
2066 * @arg RTC_TamperSamplingFreq_RTCCLK_Div1024: Each of the tamper inputs are sampled
2067 * with a frequency = RTCCLK / 1024
2068 * @arg RTC_TamperSamplingFreq_RTCCLK_Div512: Each of the tamper inputs are sampled
2069 * with a frequency = RTCCLK / 512
2070 * @arg RTC_TamperSamplingFreq_RTCCLK_Div256: Each of the tamper inputs are sampled
2071 * with a frequency = RTCCLK / 256
2074 void RTC_TamperSamplingFreqConfig(uint32_t RTC_TamperSamplingFreq)
2076 /* Check the parameters */
2077 assert_param(IS_RTC_TAMPER_SAMPLING_FREQ(RTC_TamperSamplingFreq));
2079 /* Clear TAMPFREQ[2:0] bits in the RTC_TAFCR register */
2080 RTC->TAFCR &= (uint32_t)~(RTC_TAFCR_TAMPFREQ);
2082 /* Configure the RTC_TAFCR register */
2083 RTC->TAFCR |= (uint32_t)RTC_TamperSamplingFreq;
2087 * @brief Configures the Tampers Pins input Precharge Duration.
2088 * @param RTC_TamperPrechargeDuration: Specifies the Tampers Pins input
2089 * Precharge Duration.
2090 * This parameter can be one of the following values:
2091 * @arg RTC_TamperPrechargeDuration_1RTCCLK: Tamper pins are pre-charged before sampling during 1 RTCCLK cycle
2092 * @arg RTC_TamperPrechargeDuration_2RTCCLK: Tamper pins are pre-charged before sampling during 2 RTCCLK cycle
2093 * @arg RTC_TamperPrechargeDuration_4RTCCLK: Tamper pins are pre-charged before sampling during 4 RTCCLK cycle
2094 * @arg RTC_TamperPrechargeDuration_8RTCCLK: Tamper pins are pre-charged before sampling during 8 RTCCLK cycle
2097 void RTC_TamperPinsPrechargeDuration(uint32_t RTC_TamperPrechargeDuration)
2099 /* Check the parameters */
2100 assert_param(IS_RTC_TAMPER_PRECHARGE_DURATION(RTC_TamperPrechargeDuration));
2102 /* Clear TAMPPRCH[1:0] bits in the RTC_TAFCR register */
2103 RTC->TAFCR &= (uint32_t)~(RTC_TAFCR_TAMPPRCH);
2105 /* Configure the RTC_TAFCR register */
2106 RTC->TAFCR |= (uint32_t)RTC_TamperPrechargeDuration;
2110 * @brief Enables or Disables the TimeStamp on Tamper Detection Event.
2111 * @note The timestamp is valid even the TSE bit in tamper control register
2113 * @param NewState: new state of the timestamp on tamper event.
2114 * This parameter can be: ENABLE or DISABLE.
2117 void RTC_TimeStampOnTamperDetectionCmd(FunctionalState NewState)
2119 /* Check the parameters */
2120 assert_param(IS_FUNCTIONAL_STATE(NewState));
2122 if (NewState != DISABLE)
2124 /* Save timestamp on tamper detection event */
2125 RTC->TAFCR |= (uint32_t)RTC_TAFCR_TAMPTS;
2129 /* Tamper detection does not cause a timestamp to be saved */
2130 RTC->TAFCR &= (uint32_t)~RTC_TAFCR_TAMPTS;
2135 * @brief Enables or Disables the Precharge of Tamper pin.
2136 * @param NewState: new state of tamper pull up.
2137 * This parameter can be: ENABLE or DISABLE.
2140 void RTC_TamperPullUpCmd(FunctionalState NewState)
2142 /* Check the parameters */
2143 assert_param(IS_FUNCTIONAL_STATE(NewState));
2145 if (NewState != DISABLE)
2147 /* Enable precharge of the selected Tamper pin */
2148 RTC->TAFCR &= (uint32_t)~RTC_TAFCR_TAMPPUDIS;
2152 /* Disable precharge of the selected Tamper pin */
2153 RTC->TAFCR |= (uint32_t)RTC_TAFCR_TAMPPUDIS;
2161 /** @defgroup RTC_Group10 Backup Data Registers configuration functions
2162 * @brief Backup Data Registers configuration functions
2165 ===============================================================================
2166 ##### Backup Data Registers configuration functions #####
2167 ===============================================================================
2174 * @brief Writes a data in a specified RTC Backup data register.
2175 * @param RTC_BKP_DR: RTC Backup data Register number.
2176 * This parameter can be: RTC_BKP_DRx where x can be from 0 to 15 to
2177 * specify the register.
2178 * @param Data: Data to be written in the specified RTC Backup data register.
2181 void RTC_WriteBackupRegister(uint32_t RTC_BKP_DR, uint32_t Data)
2183 __IO uint32_t tmp = 0;
2185 /* Check the parameters */
2186 assert_param(IS_RTC_BKP(RTC_BKP_DR));
2188 tmp = RTC_BASE + 0x50;
2189 tmp += (RTC_BKP_DR * 4);
2191 /* Write the specified register */
2192 *(__IO uint32_t *)tmp = (uint32_t)Data;
2196 * @brief Reads data from the specified RTC Backup data Register.
2197 * @param RTC_BKP_DR: RTC Backup data Register number.
2198 * This parameter can be: RTC_BKP_DRx where x can be from 0 to 15 to
2199 * specify the register.
2202 uint32_t RTC_ReadBackupRegister(uint32_t RTC_BKP_DR)
2204 __IO uint32_t tmp = 0;
2206 /* Check the parameters */
2207 assert_param(IS_RTC_BKP(RTC_BKP_DR));
2209 tmp = RTC_BASE + 0x50;
2210 tmp += (RTC_BKP_DR * 4);
2212 /* Read the specified register */
2213 return (*(__IO uint32_t *)tmp);
2220 /** @defgroup RTC_Group11 Output Type Config configuration functions
2221 * @brief Output Type Config configuration functions
2224 ===============================================================================
2225 ##### Output Type Config configuration functions #####
2226 ===============================================================================
2233 * @brief Configures the RTC Output Pin mode.
2234 * @param RTC_OutputType: specifies the RTC Output (PC13) pin mode.
2235 * This parameter can be one of the following values:
2236 * @arg RTC_OutputType_OpenDrain: RTC Output (PC13) is configured in
2238 * @arg RTC_OutputType_PushPull: RTC Output (PC13) is configured in
2242 void RTC_OutputTypeConfig(uint32_t RTC_OutputType)
2244 /* Check the parameters */
2245 assert_param(IS_RTC_OUTPUT_TYPE(RTC_OutputType));
2247 RTC->TAFCR &= (uint32_t)~(RTC_TAFCR_ALARMOUTTYPE);
2248 RTC->TAFCR |= (uint32_t)(RTC_OutputType);
2255 /** @defgroup RTC_Group12 Shift control synchronisation functions
2256 * @brief Shift control synchronisation functions
2259 ===============================================================================
2260 ##### Shift control synchronisation functions #####
2261 ===============================================================================
2268 * @brief Configures the Synchronization Shift Control Settings.
2269 * @note When REFCKON is set, firmware must not write to Shift control register
2270 * @param RTC_ShiftAdd1S : Select to add or not 1 second to the time Calendar.
2271 * This parameter can be one of the following values :
2272 * @arg RTC_ShiftAdd1S_Set : Add one second to the clock calendar.
2273 * @arg RTC_ShiftAdd1S_Reset: No effect.
2274 * @param RTC_ShiftSubFS: Select the number of Second Fractions to Substitute.
2275 * This parameter can be one any value from 0 to 0x7FFF.
2276 * @retval An ErrorStatus enumeration value:
2277 * - SUCCESS: RTC Shift registers are configured
2278 * - ERROR: RTC Shift registers are not configured
2280 ErrorStatus RTC_SynchroShiftConfig(uint32_t RTC_ShiftAdd1S, uint32_t RTC_ShiftSubFS)
2282 ErrorStatus status = ERROR;
2283 uint32_t shpfcount = 0;
2285 /* Check the parameters */
2286 assert_param(IS_RTC_SHIFT_ADD1S(RTC_ShiftAdd1S));
2287 assert_param(IS_RTC_SHIFT_SUBFS(RTC_ShiftSubFS));
2289 /* Disable the write protection for RTC registers */
2293 /* Check if a Shift is pending*/
2294 if ((RTC->ISR & RTC_ISR_SHPF) != RESET)
2296 /* Wait until the shift is completed*/
2297 while (((RTC->ISR & RTC_ISR_SHPF) != RESET) && (shpfcount != SHPF_TIMEOUT))
2303 /* Check if the Shift pending is completed or if there is no Shift operation at all*/
2304 if ((RTC->ISR & RTC_ISR_SHPF) == RESET)
2306 /* check if the reference clock detection is disabled */
2307 if((RTC->CR & RTC_CR_REFCKON) == RESET)
2309 /* Configure the Shift settings */
2310 RTC->SHIFTR = (uint32_t)(uint32_t)(RTC_ShiftSubFS) | (uint32_t)(RTC_ShiftAdd1S);
2312 if(RTC_WaitForSynchro() == ERROR)
2331 /* Enable the write protection for RTC registers */
2334 return (ErrorStatus)(status);
2341 /** @defgroup RTC_Group13 Interrupts and flags management functions
2342 * @brief Interrupts and flags management functions
2345 ===============================================================================
2346 ##### Interrupts and flags management functions #####
2347 ===============================================================================
2348 [..] All RTC interrupts are connected to the EXTI controller.
2349 (+) To enable the RTC Alarm interrupt, the following sequence is required:
2350 (++) Configure and enable the EXTI Line 17 in interrupt mode and select
2351 the rising edge sensitivity using the EXTI_Init() function.
2352 (++) Configure and enable the RTC_Alarm IRQ channel in the NVIC using
2353 the NVIC_Init() function.
2354 (++) Configure the RTC to generate RTC alarms (Alarm A and/or Alarm B)
2355 using the RTC_SetAlarm() and RTC_AlarmCmd() functions.
2356 (+) To enable the RTC Wakeup interrupt, the following sequence is required:
2357 (++) Configure and enable the EXTI Line 20 in interrupt mode and select
2358 the rising edge sensitivity using the EXTI_Init() function.
2359 (++) Configure and enable the RTC_WKUP IRQ channel in the NVIC using
2360 the NVIC_Init() function.
2361 (++) Configure the RTC to generate the RTC wakeup timer event using the
2362 RTC_WakeUpClockConfig(), RTC_SetWakeUpCounter() and RTC_WakeUpCmd()
2364 (+) To enable the RTC Tamper interrupt, the following sequence is required:
2365 (++) Configure and enable the EXTI Line 19 in interrupt mode and select
2366 the rising edge sensitivity using the EXTI_Init() function.
2367 (++) Configure and enable the TAMP_STAMP IRQ channel in the NVIC using
2368 the NVIC_Init() function.
2369 (++) Configure the RTC to detect the RTC tamper event using the
2370 RTC_TamperTriggerConfig() and RTC_TamperCmd() functions.
2371 (+) To enable the RTC TimeStamp interrupt, the following sequence is required:
2372 (++) Configure and enable the EXTI Line 19 in interrupt mode and select
2373 the rising edge sensitivity using the EXTI_Init() function.
2374 (++) Configure and enable the TAMP_STAMP IRQ channel in the NVIC using
2375 the NVIC_Init() function.
2376 (++) Configure the RTC to detect the RTC time-stamp event using the
2377 RTC_TimeStampCmd() functions.
2384 * @brief Enables or disables the specified RTC interrupts.
2385 * @param RTC_IT: specifies the RTC interrupt sources to be enabled or disabled.
2386 * This parameter can be any combination of the following values:
2387 * @arg RTC_IT_TS: Time Stamp interrupt mask
2388 * @arg RTC_IT_WUT: WakeUp Timer interrupt mask
2389 * @arg RTC_IT_ALRB: Alarm B interrupt mask
2390 * @arg RTC_IT_ALRA: Alarm A interrupt mask
2391 * @arg RTC_IT_TAMP: Tamper event interrupt mask
2392 * @param NewState: new state of the specified RTC interrupts.
2393 * This parameter can be: ENABLE or DISABLE.
2396 void RTC_ITConfig(uint32_t RTC_IT, FunctionalState NewState)
2398 /* Check the parameters */
2399 assert_param(IS_RTC_CONFIG_IT(RTC_IT));
2400 assert_param(IS_FUNCTIONAL_STATE(NewState));
2402 /* Disable the write protection for RTC registers */
2406 if (NewState != DISABLE)
2408 /* Configure the Interrupts in the RTC_CR register */
2409 RTC->CR |= (uint32_t)(RTC_IT & ~RTC_TAFCR_TAMPIE);
2410 /* Configure the Tamper Interrupt in the RTC_TAFCR */
2411 RTC->TAFCR |= (uint32_t)(RTC_IT & RTC_TAFCR_TAMPIE);
2415 /* Configure the Interrupts in the RTC_CR register */
2416 RTC->CR &= (uint32_t)~(RTC_IT & (uint32_t)~RTC_TAFCR_TAMPIE);
2417 /* Configure the Tamper Interrupt in the RTC_TAFCR */
2418 RTC->TAFCR &= (uint32_t)~(RTC_IT & RTC_TAFCR_TAMPIE);
2420 /* Enable the write protection for RTC registers */
2425 * @brief Checks whether the specified RTC flag is set or not.
2426 * @param RTC_FLAG: specifies the flag to check.
2427 * This parameter can be one of the following values:
2428 * @arg RTC_FLAG_RECALPF: RECALPF event flag
2429 * @arg RTC_FLAG_TAMP3F: Tamper 3 event flag
2430 * @arg RTC_FLAG_TAMP2F: Tamper 2 event flag
2431 * @arg RTC_FLAG_TAMP1F: Tamper 1 event flag
2432 * @arg RTC_FLAG_TSOVF: Time Stamp OverFlow flag
2433 * @arg RTC_FLAG_TSF: Time Stamp event flag
2434 * @arg RTC_FLAG_WUTF: WakeUp Timer flag
2435 * @arg RTC_FLAG_ALRBF: Alarm B flag
2436 * @arg RTC_FLAG_ALRAF: Alarm A flag
2437 * @arg RTC_FLAG_INITF: Initialization mode flag
2438 * @arg RTC_FLAG_RSF: Registers Synchronized flag
2439 * @arg RTC_FLAG_INITS: Registers Configured flag
2440 * @argRTC_FLAG_SHPF : Shift operation pending flag.
2441 * @arg RTC_FLAG_WUTWF: WakeUp Timer Write flag
2442 * @arg RTC_FLAG_ALRBWF: Alarm B Write flag
2443 * @arg RTC_FLAG_ALRAWF: Alarm A write flag
2444 * @retval The new state of RTC_FLAG (SET or RESET).
2446 FlagStatus RTC_GetFlagStatus(uint32_t RTC_FLAG)
2448 FlagStatus bitstatus = RESET;
2449 uint32_t tmpreg = 0;
2451 /* Check the parameters */
2452 assert_param(IS_RTC_GET_FLAG(RTC_FLAG));
2454 /* Get all the flags */
2455 tmpreg = (uint32_t)(RTC->ISR & RTC_FLAGS_MASK);
2457 /* Return the status of the flag */
2458 if ((tmpreg & RTC_FLAG) != (uint32_t)RESET)
2470 * @brief Clears the RTC's pending flags.
2471 * @param RTC_FLAG: specifies the RTC flag to clear.
2472 * This parameter can be any combination of the following values:
2473 * @arg RTC_FLAG_TAMP3F: Tamper 3 event flag
2474 * @arg RTC_FLAG_TAMP2F: Tamper 2 event flag
2475 * @arg RTC_FLAG_TAMP1F: Tamper 1 event flag
2476 * @arg RTC_FLAG_TSOVF: Time Stamp Overflow flag
2477 * @arg RTC_FLAG_TSF: Time Stamp event flag
2478 * @arg RTC_FLAG_WUTF: WakeUp Timer flag
2479 * @arg RTC_FLAG_ALRBF: Alarm B flag
2480 * @arg RTC_FLAG_ALRAF: Alarm A flag
2481 * @arg RTC_FLAG_RSF: Registers Synchronized flag
2484 void RTC_ClearFlag(uint32_t RTC_FLAG)
2486 /* Check the parameters */
2487 assert_param(IS_RTC_CLEAR_FLAG(RTC_FLAG));
2489 /* Clear the Flags in the RTC_ISR register */
2490 RTC->ISR = (uint32_t)((uint32_t)(~((RTC_FLAG | RTC_ISR_INIT)& 0x0001FFFF) | (uint32_t)(RTC->ISR & RTC_ISR_INIT)));
2494 * @brief Checks whether the specified RTC interrupt has occurred or not.
2495 * @param RTC_IT: specifies the RTC interrupt source to check.
2496 * This parameter can be one of the following values:
2497 * @arg RTC_IT_TS: Time Stamp interrupt
2498 * @arg RTC_IT_WUT: WakeUp Timer interrupt
2499 * @arg RTC_IT_ALRB: Alarm B interrupt
2500 * @arg RTC_IT_ALRA: Alarm A interrupt
2501 * @arg RTC_IT_TAMP1: Tamper1 event interrupt
2502 * @arg RTC_IT_TAMP2: Tamper2 event interrupt
2503 * @arg RTC_IT_TAMP3: Tamper3 event interrupt
2504 * @retval The new state of RTC_IT (SET or RESET).
2506 ITStatus RTC_GetITStatus(uint32_t RTC_IT)
2508 ITStatus bitstatus = RESET;
2509 uint32_t tmpreg = 0, enablestatus = 0;
2511 /* Check the parameters */
2512 assert_param(IS_RTC_GET_IT(RTC_IT));
2514 /* Get the TAMPER Interrupt enable bit and pending bit */
2515 tmpreg = (uint32_t)(RTC->TAFCR & (RTC_TAFCR_TAMPIE));
2517 /* Get the Interrupt enable Status */
2518 enablestatus = (uint32_t)((RTC->CR & RTC_IT) | (tmpreg & ((RTC_IT >> (RTC_IT >> 18)) >> 15)));
2520 /* Get the Interrupt pending bit */
2521 tmpreg = (uint32_t)((RTC->ISR & (uint32_t)(RTC_IT >> 4)));
2523 /* Get the status of the Interrupt */
2524 if ((enablestatus != (uint32_t)RESET) && ((tmpreg & 0x0000FFFF) != (uint32_t)RESET))
2536 * @brief Clears the RTC's interrupt pending bits.
2537 * @param RTC_IT: specifies the RTC interrupt pending bit to clear.
2538 * This parameter can be any combination of the following values:
2539 * @arg RTC_IT_TS: Time Stamp interrupt
2540 * @arg RTC_IT_WUT: WakeUp Timer interrupt
2541 * @arg RTC_IT_ALRB: Alarm B interrupt
2542 * @arg RTC_IT_ALRA: Alarm A interrupt
2543 * @arg RTC_IT_TAMP1: Tamper1 event interrupt
2544 * @arg RTC_IT_TAMP2: Tamper2 event interrupt
2545 * @arg RTC_IT_TAMP3: Tamper3 event interrupt
2548 void RTC_ClearITPendingBit(uint32_t RTC_IT)
2550 uint32_t tmpreg = 0;
2552 /* Check the parameters */
2553 assert_param(IS_RTC_CLEAR_IT(RTC_IT));
2555 /* Get the RTC_ISR Interrupt pending bits mask */
2556 tmpreg = (uint32_t)(RTC_IT >> 4);
2558 /* Clear the interrupt pending bits in the RTC_ISR register */
2559 RTC->ISR = (uint32_t)((uint32_t)(~((tmpreg | RTC_ISR_INIT)& 0x0000FFFF) | (uint32_t)(RTC->ISR & RTC_ISR_INIT)));
2567 * @brief Converts a 2 digit decimal to BCD format.
2568 * @param Value: Byte to be converted.
2569 * @retval Converted byte
2571 static uint8_t RTC_ByteToBcd2(uint8_t Value)
2573 uint8_t bcdhigh = 0;
2581 return ((uint8_t)(bcdhigh << 4) | Value);
2585 * @brief Convert from 2 digit BCD to Binary.
2586 * @param Value: BCD value to be converted.
2587 * @retval Converted word
2589 static uint8_t RTC_Bcd2ToByte(uint8_t Value)
2592 tmp = ((uint8_t)(Value & (uint8_t)0xF0) >> (uint8_t)0x4) * 10;
2593 return (tmp + (Value & (uint8_t)0x0F));
2608 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/