2 ******************************************************************************
\r
3 * @file stm32l1xx_rtc.c
\r
4 * @author MCD Application Team
\r
6 * @date 31-December-2010
\r
7 * @brief This file provides firmware functions to manage the following
\r
8 * functionalities of the Real-Time Clock (RTC) peripheral:
\r
10 * - Calendar (Time and Date) configuration
\r
11 * - Alarms (Alarm A and Alarm B) configuration
\r
12 * - WakeUp Timer configuration
\r
13 * - Daylight Saving configuration
\r
14 * - Output pin Configuration
\r
15 * - Digital Calibration configuration
\r
16 * - TimeStamp configuration
\r
17 * - Tampers configuration
\r
18 * - Backup Data Registers configuration
\r
19 * - Output Type Config configuration
\r
20 * - Interrupts and flags management
\r
24 * ===================================================================
\r
26 * ===================================================================
\r
27 * After power-on reset, the RTC domain (RTC clock source configuration,
\r
28 * RTC registers and RTC Backup data registers) is reset. You can also
\r
29 * reset this domain by software using the RCC_RTCResetCmd() function.
\r
31 * ===================================================================
\r
32 * RTC Operating Condition
\r
33 * ===================================================================
\r
34 * As long as the supply voltage remains in the operating range,
\r
35 * the RTC never stops, regardless of the device status (Run mode,
\r
36 * low power modes or under reset).
\r
38 * ===================================================================
\r
40 * ===================================================================
\r
41 * After reset, the RTC domain (RTC clock source configuration,
\r
42 * RTC registers and RTC Backup data registers) are protected against
\r
43 * possible stray write accesses.
\r
44 * To enable access to the RTC Domain and RTC registers, proceed as follows:
\r
45 * - Enable the Power Controller (PWR) APB1 interface clock using the
\r
46 * RCC_APB1PeriphClockCmd() function.
\r
47 * - Enable access to RTC domain using the PWR_RTCAccessCmd() function.
\r
48 * - Select the RTC clock source using the RCC_RTCCLKConfig() function.
\r
49 * - Enable RTC Clock using the RCC_RTCCLKCmd() function.
\r
51 * ===================================================================
\r
52 * RTC Driver: how to use it
\r
53 * ===================================================================
\r
54 * - Enable the RTC domain access (see description in the section above)
\r
55 * - Configure the RTC Prescaler (Asynchronous and Synchronous) and
\r
56 * RTC hour format using the RTC_Init() function.
\r
58 * Time and Date configuration
\r
59 * ===========================
\r
60 * - To configure the RTC Calendar (Time and Date) use the RTC_SetTime()
\r
61 * and RTC_SetDate() functions.
\r
62 * - To read the RTC Calendar, use the RTC_GetTime() and RTC_GetDate()
\r
64 * - Use the RTC_DayLightSavingConfig() function to add or sub one
\r
65 * hour to the RTC Calendar.
\r
67 * Alarm configuration
\r
68 * ===================
\r
69 * - To configure the RTC Alarm use the RTC_SetAlarm() function.
\r
70 * - Enable the selected RTC Alarm using the RTC_AlarmCmd() function
\r
71 * - To read the RTC Alarm, use the RTC_GetAlarm() function.
\r
73 * RTC Wakeup configuration
\r
74 * ========================
\r
75 * - Configure the RTC Wakeup Clock source use the RTC_WakeUpClockConfig()
\r
77 * - Configure the RTC WakeUp Counter using the RTC_SetWakeUpCounter()
\r
79 * - Enable the RTC WakeUp using the RTC_WakeUpCmd() function
\r
80 * - To read the RTC WakeUp Counter register, use the RTC_GetWakeUpCounter()
\r
83 * Outputs configuration
\r
84 * =====================
\r
85 * The RTC has 2 different outputs:
\r
86 * - AFO_ALARM: this output is used to manage the RTC Alarm A, Alarm B
\r
87 * and WaKeUp signals.
\r
88 * To output the selected RTC signal on RTC_AF1 pin, use the
\r
89 * RTC_OutputConfig() function.
\r
90 * - AFO_CALIB: this output is used to manage the RTC Clock divided
\r
91 * by 64 (512Hz) signal.
\r
92 * To output the RTC Clock on RTC_AF1 pin, use the RTC_CalibOutputCmd()
\r
95 * Digital Calibration configuration
\r
96 * =================================
\r
97 * - Configure the RTC Digital Calibration Value and the corresponding
\r
98 * sign using the RTC_DigitalCalibConfig() function.
\r
99 * - Enable the RTC Digital Calibration using the RTC_DigitalCalibCmd()
\r
102 * TimeStamp configuration
\r
103 * =======================
\r
104 * - Configure the RTC_AF1 trigger and enables the RTC TimeStamp
\r
105 * using the RTC_TimeStampCmd() function.
\r
106 * - To read the RTC TimeStamp Time and Date register, use the
\r
107 * RTC_GetTimeStamp() function.
\r
109 * Tamper configuration
\r
110 * ====================
\r
111 * - Configure the RTC Tamper trigger using the RTC_TamperConfig()
\r
113 * - Enable the RTC Tamper using the RTC_TamperCmd() function.
\r
115 * Backup Data Registers configuration
\r
116 * ===================================
\r
117 * - To write to the RTC Backup Data registers, use the RTC_WriteBackupRegister()
\r
119 * - To read the RTC Backup Data registers, use the RTC_ReadBackupRegister()
\r
122 * ===================================================================
\r
123 * RTC and low power modes
\r
124 * ===================================================================
\r
125 * The MCU can be woken up from a low power mode by an RTC alternate
\r
127 * The RTC alternate functions are the RTC alarms (Alarm A and Alarm B),
\r
128 * RTC wakeup, RTC tamper event detection and RTC time stamp event detection.
\r
129 * These RTC alternate functions can wake up the system from the Stop
\r
130 * and Standby lowpower modes.
\r
131 * The system can also wake up from low power modes without depending
\r
132 * on an external interrupt (Auto-wakeup mode), by using the RTC alarm
\r
133 * or the RTC wakeup events.
\r
134 * The RTC provides a programmable time base for waking up from the
\r
135 * Stop or Standby mode at regular intervals.
\r
136 * Wakeup from STOP and Standby modes is possible only when the RTC
\r
137 * clock source is LSE or LSI.
\r
139 * ===================================================================
\r
140 * Selection of RTC_AF1 alternate functions
\r
141 * ===================================================================
\r
142 * The RTC_AF1 pin (PC13) can be used for the following purposes:
\r
143 * - Wakeup pin 2 (WKUP2) using the PWR_WakeUpPinCmd() function.
\r
144 * - AFO_ALARM output
\r
145 * - AFO_CALIB output
\r
149 * +------------------------------------------------------------------------------------------+
\r
150 * | Pin |AFO_ALARM |AFO_CALIB |AFI_TAMPER |AFI_TIMESTAMP | WKUP2 |ALARMOUTTYPE |
\r
151 * | configuration | ENABLED | ENABLED | ENABLED | ENABLED |ENABLED | AFO_ALARM |
\r
152 * | and function | | | | | |Configuration |
\r
153 * |-----------------|----------|----------|-----------|--------------|--------|--------------|
\r
154 * | Alarm out | | | | | Don't | |
\r
155 * | output OD | 1 | 0 |Don't care | Don't care | care | 0 |
\r
156 * |-----------------|----------|----------|-----------|--------------|--------|--------------|
\r
157 * | Alarm out | | | | | Don't | |
\r
158 * | output PP | 1 | 0 |Don't care | Don't care | care | 1 |
\r
159 * |-----------------|----------|----------|-----------|--------------|--------|--------------|
\r
160 * | Calibration out | | | | | Don't | |
\r
161 * | output PP | 0 | 1 |Don't care | Don't care | care | Don't care |
\r
162 * |-----------------|----------|----------|-----------|--------------|--------|--------------|
\r
163 * | TAMPER input | | | | | Don't | |
\r
164 * | floating | 0 | 0 | 1 | 0 | care | Don't care |
\r
165 * |-----------------|----------|----------|-----------|--------------|--------|--------------|
\r
166 * | TIMESTAMP and | | | | | Don't | |
\r
167 * | TAMPER input | 0 | 0 | 1 | 1 | care | Don't care |
\r
168 * | floating | | | | | | |
\r
169 * |-----------------|----------|----------|-----------|--------------|--------|--------------|
\r
170 * | TIMESTAMP input | | | | | Don't | |
\r
171 * | floating | 0 | 0 | 0 | 1 | care | Don't care |
\r
172 * |-----------------|----------|----------|-----------|--------------|--------|--------------|
\r
173 * | Wakeup Pin 2 | 0 | 0 | 0 | 0 | 1 | Don't care |
\r
174 * |-----------------|----------|----------|-----------|--------------|--------|--------------|
\r
175 * | Standard GPIO | 0 | 0 | 0 | 0 | 0 | Don't care |
\r
176 * +------------------------------------------------------------------------------------------+
\r
180 ******************************************************************************
\r
183 * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
\r
184 * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE
\r
185 * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY
\r
186 * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING
\r
187 * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE
\r
188 * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
\r
190 * <h2><center>© COPYRIGHT 2010 STMicroelectronics</center></h2>
\r
191 ******************************************************************************
\r
194 /* Includes ------------------------------------------------------------------*/
\r
195 #include "stm32l1xx_rtc.h"
\r
196 #include "stm32l1xx_rcc.h"
\r
198 /** @addtogroup STM32L1xx_StdPeriph_Driver
\r
203 * @brief RTC driver modules
\r
207 /* Private typedef -----------------------------------------------------------*/
\r
208 /* Private define ------------------------------------------------------------*/
\r
210 /* Masks Definition */
\r
211 #define RTC_TR_RESERVED_MASK ((uint32_t)0x007F7F7F)
\r
212 #define RTC_DR_RESERVED_MASK ((uint32_t)0x00FFFF3F)
\r
213 #define RTC_INIT_MASK ((uint32_t)0xFFFFFFFF)
\r
214 #define RTC_RSF_MASK ((uint32_t)0xFFFFFF5F)
\r
215 #define RTC_FLAGS_MASK ((uint32_t)(RTC_FLAG_TSOVF | RTC_FLAG_TSF | RTC_FLAG_WUTF | \
\r
216 RTC_FLAG_ALRBF | RTC_FLAG_ALRAF | RTC_FLAG_INITF | \
\r
217 RTC_FLAG_RSF | RTC_FLAG_INITS | RTC_FLAG_WUTWF | \
\r
218 RTC_FLAG_ALRBWF | RTC_FLAG_ALRAWF | RTC_FLAG_TAMP1F ))
\r
220 #define INITMODE_TIMEOUT ((uint32_t) 0x00002000)
\r
221 #define SYNCHRO_TIMEOUT ((uint32_t) 0x00001000)
\r
223 /* Private macro -------------------------------------------------------------*/
\r
224 /* Private variables ---------------------------------------------------------*/
\r
225 /* Private function prototypes -----------------------------------------------*/
\r
226 static uint8_t RTC_ByteToBcd2(uint8_t Value);
\r
227 static uint8_t RTC_Bcd2ToByte(uint8_t Value);
\r
229 /* Private functions ---------------------------------------------------------*/
\r
231 /** @defgroup RTC_Private_Functions
\r
235 /** @defgroup RTC_Group1 Initialization and Configuration functions
\r
236 * @brief Initialization and Configuration functions
\r
239 ===============================================================================
\r
240 Initialization and Configuration functions
\r
241 ===============================================================================
\r
243 This section provide functions allowing to initialize and configure the RTC
\r
244 Prescaler (Synchronous and Asynchronous), RTC Hour format, disable RTC registers
\r
245 Write protection, enter and exit the RTC initialization mode, RTC registers
\r
246 synchronization check and reference clock detection enable.
\r
248 1. The RTC Prescaler is programmed to generate the RTC 1Hz time base. It is
\r
249 split into 2 programmable prescalers to minimize power consumption.
\r
250 - A 7-bit asynchronous prescaler and A 13-bit synchronous prescaler.
\r
251 - When both prescalers are used, it is recommended to configure the asynchronous
\r
252 prescaler to a high value to minimize consumption.
\r
254 2. All RTC registers are Write protected. Writing to the RTC registers
\r
255 is enabled by writing a key into the Write Protection register, RTC_WPR.
\r
257 3. To Configure the RTC Calendar, user application should enter initialization
\r
258 mode. In this mode, the calendar counter is stopped and its value can be
\r
259 updated. When the initialization sequence is complete, the calendar restarts
\r
260 counting after 4 RTCCLK cycles.
\r
262 4. To read the calendar through the shadow registers after Calendar initialization,
\r
263 calendar update or after wakeup from low power modes the software must first
\r
264 clear the RSF flag. The software must then wait until it is set again before
\r
265 reading the calendar, which means that the calendar registers have been
\r
266 correctly copied into the RTC_TR and RTC_DR shadow registers.
\r
267 The RTC_WaitForSynchro() function implements the above software sequence
\r
268 (RSF clear and RSF check).
\r
275 * @brief Deinitializes the RTC registers to their default reset values.
\r
276 * @note This function doesn't reset the RTC Clock source and RTC Backup Data
\r
279 * @retval An ErrorStatus enumeration value:
\r
280 * - SUCCESS: RTC registers are deinitialized
\r
281 * - ERROR: RTC registers are not deinitialized
\r
283 ErrorStatus RTC_DeInit(void)
\r
285 __IO uint32_t wutcounter = 0x00;
\r
286 uint32_t wutwfstatus = 0x00;
\r
287 ErrorStatus status = ERROR;
\r
289 /* Disable the write protection for RTC registers */
\r
293 /* Set Initialization mode */
\r
294 if (RTC_EnterInitMode() == ERROR)
\r
300 /* Reset TR, DR and CR registers */
\r
301 RTC->TR = (uint32_t)0x00000000;
\r
302 RTC->DR = (uint32_t)0x00002101;
\r
303 /* Reset All CR bits except CR[2:0] */
\r
304 RTC->CR &= (uint32_t)0x00000007;
\r
306 /* Wait till RTC WUTWF flag is set and if Time out is reached exit */
\r
309 wutwfstatus = RTC->ISR & RTC_ISR_WUTWF;
\r
311 } while((wutcounter != INITMODE_TIMEOUT) && (wutwfstatus == 0x00));
\r
313 if ((RTC->ISR & RTC_ISR_WUTWF) == RESET)
\r
319 /* Reset all RTC CR register bits */
\r
320 RTC->CR &= (uint32_t)0x00000000;
\r
321 RTC->WUTR = (uint32_t)0x0000FFFF;
\r
322 RTC->PRER = (uint32_t)0x007F00FF;
\r
323 RTC->CALIBR = (uint32_t)0x00000000;
\r
324 RTC->ALRMAR = (uint32_t)0x00000000;
\r
325 RTC->ALRMBR = (uint32_t)0x00000000;
\r
327 /* Reset ISR register and exit initialization mode */
\r
328 RTC->ISR = (uint32_t)0x00000000;
\r
330 /* Reset Tamper and alternate functions configuration register */
\r
331 RTC->TAFCR = 0x00000000;
\r
333 if(RTC_WaitForSynchro() == ERROR)
\r
344 /* Enable the write protection for RTC registers */
\r
351 * @brief Initializes the RTC registers according to the specified parameters
\r
352 * in RTC_InitStruct.
\r
353 * @param RTC_InitStruct: pointer to a RTC_InitTypeDef structure that contains
\r
354 * the configuration information for the RTC peripheral.
\r
355 * @note The RTC Prescaler register is write protected and can be written in
\r
356 * initialization mode only.
\r
357 * @retval An ErrorStatus enumeration value:
\r
358 * - SUCCESS: RTC registers are initialized
\r
359 * - ERROR: RTC registers are not initialized
\r
361 ErrorStatus RTC_Init(RTC_InitTypeDef* RTC_InitStruct)
\r
363 ErrorStatus status = ERROR;
\r
365 /* Check the parameters */
\r
366 assert_param(IS_RTC_HOUR_FORMAT(RTC_InitStruct->RTC_HourFormat));
\r
367 assert_param(IS_RTC_ASYNCH_PREDIV(RTC_InitStruct->RTC_AsynchPrediv));
\r
368 assert_param(IS_RTC_SYNCH_PREDIV(RTC_InitStruct->RTC_SynchPrediv));
\r
370 /* Disable the write protection for RTC registers */
\r
374 /* Set Initialization mode */
\r
375 if (RTC_EnterInitMode() == ERROR)
\r
381 /* Clear RTC CR FMT Bit */
\r
382 RTC->CR &= ((uint32_t)~(RTC_CR_FMT));
\r
383 /* Set RTC_CR register */
\r
384 RTC->CR |= ((uint32_t)(RTC_InitStruct->RTC_HourFormat));
\r
386 /* Configure the RTC PRER */
\r
387 RTC->PRER = (uint32_t)(RTC_InitStruct->RTC_SynchPrediv);
\r
388 RTC->PRER |= (uint32_t)(RTC_InitStruct->RTC_AsynchPrediv << 16);
\r
390 /* Exit Initialization mode */
\r
391 RTC_ExitInitMode();
\r
395 /* Enable the write protection for RTC registers */
\r
402 * @brief Fills each RTC_InitStruct member with its default value.
\r
403 * @param RTC_InitStruct: pointer to a RTC_InitTypeDef structure which will be
\r
407 void RTC_StructInit(RTC_InitTypeDef* RTC_InitStruct)
\r
409 /* Initialize the RTC_HourFormat member */
\r
410 RTC_InitStruct->RTC_HourFormat = RTC_HourFormat_24;
\r
412 /* Initialize the RTC_AsynchPrediv member */
\r
413 RTC_InitStruct->RTC_AsynchPrediv = (uint32_t)0x7F;
\r
415 /* Initialize the RTC_SynchPrediv member */
\r
416 RTC_InitStruct->RTC_SynchPrediv = (uint32_t)0xFF;
\r
420 * @brief Enables or disables the RTC registers write protection.
\r
421 * @note All the RTC registers are write protected except for RTC_ISR[13:8],
\r
422 * RTC_TAFCR and RTC_BKPxR.
\r
423 * @note Writing a wrong key reactivates the write protection.
\r
424 * @note The protection mechanism is not affected by system reset.
\r
425 * @param NewState: new state of the write protection.
\r
426 * This parameter can be: ENABLE or DISABLE.
\r
429 void RTC_WriteProtectionCmd(FunctionalState NewState)
\r
431 /* Check the parameters */
\r
432 assert_param(IS_FUNCTIONAL_STATE(NewState));
\r
434 if (NewState != DISABLE)
\r
436 /* Enable the write protection for RTC registers */
\r
441 /* Disable the write protection for RTC registers */
\r
448 * @brief Enters the RTC Initialization mode.
\r
449 * @note The RTC Initialization mode is write protected, use the
\r
450 * RTC_WriteProtectionCmd(DISABLE) before calling this function.
\r
452 * @retval An ErrorStatus enumeration value:
\r
453 * - SUCCESS: RTC is in Init mode
\r
454 * - ERROR: RTC is not in Init mode
\r
456 ErrorStatus RTC_EnterInitMode(void)
\r
458 __IO uint32_t initcounter = 0x00;
\r
459 ErrorStatus status = ERROR;
\r
460 uint32_t initstatus = 0x00;
\r
462 /* Check if the Initialization mode is set */
\r
463 if ((RTC->ISR & RTC_ISR_INITF) == (uint32_t)RESET)
\r
465 /* Set the Initialization mode */
\r
466 RTC->ISR = (uint32_t)RTC_INIT_MASK;
\r
468 /* Wait till RTC is in INIT state and if Time out is reached exit */
\r
471 initstatus = RTC->ISR & RTC_ISR_INITF;
\r
473 } while((initcounter != INITMODE_TIMEOUT) && (initstatus == 0x00));
\r
475 if ((RTC->ISR & RTC_ISR_INITF) != RESET)
\r
493 * @brief Exits the RTC Initialization mode.
\r
494 * @note When the initialization sequence is complete, the calendar restarts
\r
495 * counting after 4 RTCCLK cycles.
\r
496 * @note The RTC Initialization mode is write protected, use the
\r
497 * RTC_WriteProtectionCmd(DISABLE) before calling this function.
\r
501 void RTC_ExitInitMode(void)
\r
503 /* Exit Initialization mode */
\r
504 RTC->ISR &= (uint32_t)~RTC_ISR_INIT;
\r
508 * @brief Waits until the RTC Time and Date registers (RTC_TR and RTC_DR) are
\r
509 * synchronized with RTC APB clock.
\r
510 * @note The RTC Resynchronization mode is write protected, use the
\r
511 * RTC_WriteProtectionCmd(DISABLE) before calling this function.
\r
512 * @note To read the calendar through the shadow registers after Calendar
\r
513 * initialization, calendar update or after wakeup from low power modes
\r
514 * the software must first clear the RSF flag.
\r
515 * The software must then wait until it is set again before reading
\r
516 * the calendar, which means that the calendar registers have been
\r
517 * correctly copied into the RTC_TR and RTC_DR shadow registers.
\r
519 * @retval An ErrorStatus enumeration value:
\r
520 * - SUCCESS: RTC registers are synchronised
\r
521 * - ERROR: RTC registers are not synchronised
\r
523 ErrorStatus RTC_WaitForSynchro(void)
\r
525 __IO uint32_t synchrocounter = 0;
\r
526 ErrorStatus status = ERROR;
\r
527 uint32_t synchrostatus = 0x00;
\r
529 /* Disable the write protection for RTC registers */
\r
533 /* Clear RSF flag */
\r
534 RTC->ISR &= (uint32_t)RTC_RSF_MASK;
\r
536 /* Wait the registers to be synchronised */
\r
539 synchrostatus = RTC->ISR & RTC_ISR_RSF;
\r
541 } while((synchrocounter != SYNCHRO_TIMEOUT) && (synchrostatus == 0x00));
\r
543 if ((RTC->ISR & RTC_ISR_RSF) != RESET)
\r
552 /* Enable the write protection for RTC registers */
\r
559 * @brief Enables or disables the RTC reference clock detection.
\r
560 * @param NewState: new state of the RTC reference clock.
\r
561 * This parameter can be: ENABLE or DISABLE.
\r
562 * @retval An ErrorStatus enumeration value:
\r
563 * - SUCCESS: RTC reference clock detection is enabled
\r
564 * - ERROR: RTC reference clock detection is disabled
\r
566 ErrorStatus RTC_RefClockCmd(FunctionalState NewState)
\r
568 ErrorStatus status = ERROR;
\r
570 /* Check the parameters */
\r
571 assert_param(IS_FUNCTIONAL_STATE(NewState));
\r
573 /* Disable the write protection for RTC registers */
\r
577 /* Set Initialization mode */
\r
578 if (RTC_EnterInitMode() == ERROR)
\r
584 if (NewState != DISABLE)
\r
586 /* Enable the RTC reference clock detection */
\r
587 RTC->CR |= RTC_CR_REFCKON;
\r
591 /* Disable the RTC reference clock detection */
\r
592 RTC->CR &= ~RTC_CR_REFCKON;
\r
594 /* Exit Initialization mode */
\r
595 RTC_ExitInitMode();
\r
600 /* Enable the write protection for RTC registers */
\r
610 /** @defgroup RTC_Group2 Time and Date configuration functions
\r
611 * @brief Time and Date configuration functions
\r
614 ===============================================================================
\r
615 Time and Date configuration functions
\r
616 ===============================================================================
\r
618 This section provide functions allowing to program and read the RTC Calendar
\r
626 * @brief Set the RTC current time.
\r
627 * @param RTC_Format: specifies the format of the entered parameters.
\r
628 * This parameter can be one of the following values:
\r
629 * @arg RTC_Format_BIN: Binary data format
\r
630 * @arg RTC_Format_BCD: BCD data format
\r
631 * @param RTC_TimeStruct: pointer to a RTC_TimeTypeDef structure that contains
\r
632 * the time configuration information for the RTC.
\r
633 * @retval An ErrorStatus enumeration value:
\r
634 * - SUCCESS: RTC Time register is configured
\r
635 * - ERROR: RTC Time register is not configured
\r
637 ErrorStatus RTC_SetTime(uint32_t RTC_Format, RTC_TimeTypeDef* RTC_TimeStruct)
\r
639 uint32_t tmpreg = 0;
\r
640 ErrorStatus status = ERROR;
\r
642 /* Check the parameters */
\r
643 assert_param(IS_RTC_FORMAT(RTC_Format));
\r
645 if (RTC_Format == RTC_Format_BIN)
\r
647 if ((RTC->CR & RTC_CR_FMT) != (uint32_t)RESET)
\r
649 assert_param(IS_RTC_HOUR12(RTC_TimeStruct->RTC_Hours));
\r
650 assert_param(IS_RTC_H12(RTC_TimeStruct->RTC_H12));
\r
654 RTC_TimeStruct->RTC_H12 = 0x00;
\r
655 assert_param(IS_RTC_HOUR24(RTC_TimeStruct->RTC_Hours));
\r
657 assert_param(IS_RTC_MINUTES(RTC_TimeStruct->RTC_Minutes));
\r
658 assert_param(IS_RTC_SECONDS(RTC_TimeStruct->RTC_Seconds));
\r
662 if ((RTC->CR & RTC_CR_FMT) != (uint32_t)RESET)
\r
664 tmpreg = RTC_Bcd2ToByte(RTC_TimeStruct->RTC_Hours);
\r
665 assert_param(IS_RTC_HOUR12(tmpreg));
\r
666 assert_param(IS_RTC_H12(RTC_TimeStruct->RTC_H12));
\r
670 RTC_TimeStruct->RTC_H12 = 0x00;
\r
671 assert_param(IS_RTC_HOUR24(RTC_Bcd2ToByte(RTC_TimeStruct->RTC_Hours)));
\r
673 assert_param(IS_RTC_MINUTES(RTC_Bcd2ToByte(RTC_TimeStruct->RTC_Minutes)));
\r
674 assert_param(IS_RTC_SECONDS(RTC_Bcd2ToByte(RTC_TimeStruct->RTC_Seconds)));
\r
677 /* Check the input parameters format */
\r
678 if (RTC_Format != RTC_Format_BIN)
\r
680 tmpreg = (((uint32_t)(RTC_TimeStruct->RTC_Hours) << 16) | \
\r
681 ((uint32_t)(RTC_TimeStruct->RTC_Minutes) << 8) | \
\r
682 ((uint32_t)RTC_TimeStruct->RTC_Seconds) | \
\r
683 ((uint32_t)(RTC_TimeStruct->RTC_H12) << 16));
\r
687 tmpreg = (uint32_t)(((uint32_t)RTC_ByteToBcd2(RTC_TimeStruct->RTC_Hours) << 16) | \
\r
688 ((uint32_t)RTC_ByteToBcd2(RTC_TimeStruct->RTC_Minutes) << 8) | \
\r
689 ((uint32_t)RTC_ByteToBcd2(RTC_TimeStruct->RTC_Seconds)) | \
\r
690 (((uint32_t)RTC_TimeStruct->RTC_H12) << 16));
\r
693 /* Disable the write protection for RTC registers */
\r
697 /* Set Initialization mode */
\r
698 if (RTC_EnterInitMode() == ERROR)
\r
704 /* Set the RTC_TR register */
\r
705 RTC->TR = (uint32_t)(tmpreg & RTC_TR_RESERVED_MASK);
\r
707 /* Exit Initialization mode */
\r
708 RTC_ExitInitMode();
\r
710 if(RTC_WaitForSynchro() == ERROR)
\r
720 /* Enable the write protection for RTC registers */
\r
727 * @brief Fills each RTC_TimeStruct member with its default value
\r
728 * (Time = 00h:00min:00sec).
\r
729 * @param RTC_TimeStruct: pointer to a RTC_TimeTypeDef structure which will be
\r
733 void RTC_TimeStructInit(RTC_TimeTypeDef* RTC_TimeStruct)
\r
735 /* Time = 00h:00min:00sec */
\r
736 RTC_TimeStruct->RTC_H12 = RTC_H12_AM;
\r
737 RTC_TimeStruct->RTC_Hours = 0;
\r
738 RTC_TimeStruct->RTC_Minutes = 0;
\r
739 RTC_TimeStruct->RTC_Seconds = 0;
\r
743 * @brief Get the RTC current Time.
\r
744 * @param RTC_Format: specifies the format of the returned parameters.
\r
745 * This parameter can be one of the following values:
\r
746 * @arg RTC_Format_BIN: Binary data format
\r
747 * @arg RTC_Format_BCD: BCD data format
\r
748 * @param RTC_TimeStruct: pointer to a RTC_TimeTypeDef structure that will
\r
749 * contain the returned current time configuration.
\r
752 void RTC_GetTime(uint32_t RTC_Format, RTC_TimeTypeDef* RTC_TimeStruct)
\r
754 uint32_t tmpreg = 0;
\r
756 /* Check the parameters */
\r
757 assert_param(IS_RTC_FORMAT(RTC_Format));
\r
759 /* Get the RTC_TR register */
\r
760 tmpreg = (uint32_t)(RTC->TR & RTC_TR_RESERVED_MASK);
\r
762 /* Fill the structure fields with the read parameters */
\r
763 RTC_TimeStruct->RTC_Hours = (uint8_t)((tmpreg & (RTC_TR_HT | RTC_TR_HU)) >> 16);
\r
764 RTC_TimeStruct->RTC_Minutes = (uint8_t)((tmpreg & (RTC_TR_MNT | RTC_TR_MNU)) >>8);
\r
765 RTC_TimeStruct->RTC_Seconds = (uint8_t)(tmpreg & (RTC_TR_ST | RTC_TR_SU));
\r
766 RTC_TimeStruct->RTC_H12 = (uint8_t)((tmpreg & (RTC_TR_PM)) >> 16);
\r
768 /* Check the input parameters format */
\r
769 if (RTC_Format == RTC_Format_BIN)
\r
771 /* Convert the structure parameters to Binary format */
\r
772 RTC_TimeStruct->RTC_Hours = (uint8_t)RTC_Bcd2ToByte(RTC_TimeStruct->RTC_Hours);
\r
773 RTC_TimeStruct->RTC_Minutes = (uint8_t)RTC_Bcd2ToByte(RTC_TimeStruct->RTC_Minutes);
\r
774 RTC_TimeStruct->RTC_Seconds = (uint8_t)RTC_Bcd2ToByte(RTC_TimeStruct->RTC_Seconds);
\r
779 * @brief Set the RTC current date.
\r
780 * @param RTC_Format: specifies the format of the entered parameters.
\r
781 * This parameter can be one of the following values:
\r
782 * @arg RTC_Format_BIN: Binary data format
\r
783 * @arg RTC_Format_BCD: BCD data format
\r
784 * @param RTC_DateStruct: pointer to a RTC_DateTypeDef structure that contains
\r
785 * the date configuration information for the RTC.
\r
786 * @retval An ErrorStatus enumeration value:
\r
787 * - SUCCESS: RTC Date register is configured
\r
788 * - ERROR: RTC Date register is not configured
\r
790 ErrorStatus RTC_SetDate(uint32_t RTC_Format, RTC_DateTypeDef* RTC_DateStruct)
\r
792 uint32_t tmpreg = 0;
\r
793 ErrorStatus status = ERROR;
\r
795 /* Check the parameters */
\r
796 assert_param(IS_RTC_FORMAT(RTC_Format));
\r
798 if ((RTC_Format == RTC_Format_BIN) && ((RTC_DateStruct->RTC_Month & 0x10) == 0x10))
\r
800 RTC_DateStruct->RTC_Month = (RTC_DateStruct->RTC_Month & (uint32_t)~(0x10)) + 0x0A;
\r
802 if (RTC_Format == RTC_Format_BIN)
\r
804 assert_param(IS_RTC_YEAR(RTC_DateStruct->RTC_Year));
\r
805 assert_param(IS_RTC_MONTH(RTC_DateStruct->RTC_Month));
\r
806 assert_param(IS_RTC_DATE(RTC_DateStruct->RTC_Date));
\r
810 assert_param(IS_RTC_YEAR(RTC_Bcd2ToByte(RTC_DateStruct->RTC_Year)));
\r
811 tmpreg = RTC_Bcd2ToByte(RTC_DateStruct->RTC_Month);
\r
812 assert_param(IS_RTC_MONTH(tmpreg));
\r
813 tmpreg = RTC_Bcd2ToByte(RTC_DateStruct->RTC_Date);
\r
814 assert_param(IS_RTC_DATE(tmpreg));
\r
816 assert_param(IS_RTC_WEEKDAY(RTC_DateStruct->RTC_WeekDay));
\r
818 /* Check the input parameters format */
\r
819 if (RTC_Format != RTC_Format_BIN)
\r
821 tmpreg = ((((uint32_t)RTC_DateStruct->RTC_Year) << 16) | \
\r
822 (((uint32_t)RTC_DateStruct->RTC_Month) << 8) | \
\r
823 ((uint32_t)RTC_DateStruct->RTC_Date) | \
\r
824 (((uint32_t)RTC_DateStruct->RTC_WeekDay) << 13));
\r
828 tmpreg = (((uint32_t)RTC_ByteToBcd2(RTC_DateStruct->RTC_Year) << 16) | \
\r
829 ((uint32_t)RTC_ByteToBcd2(RTC_DateStruct->RTC_Month) << 8) | \
\r
830 ((uint32_t)RTC_ByteToBcd2(RTC_DateStruct->RTC_Date)) | \
\r
831 ((uint32_t)RTC_DateStruct->RTC_WeekDay << 13));
\r
834 /* Disable the write protection for RTC registers */
\r
838 /* Set Initialization mode */
\r
839 if (RTC_EnterInitMode() == ERROR)
\r
845 /* Set the RTC_DR register */
\r
846 RTC->DR = (uint32_t)(tmpreg & RTC_DR_RESERVED_MASK);
\r
848 /* Exit Initialization mode */
\r
849 RTC_ExitInitMode();
\r
851 if(RTC_WaitForSynchro() == ERROR)
\r
860 /* Enable the write protection for RTC registers */
\r
867 * @brief Fills each RTC_DateStruct member with its default value
\r
868 * (Monday, January 01 xx00).
\r
869 * @param RTC_DateStruct: pointer to a RTC_DateTypeDef structure which will be
\r
873 void RTC_DateStructInit(RTC_DateTypeDef* RTC_DateStruct)
\r
875 /* Monday, January 01 xx00 */
\r
876 RTC_DateStruct->RTC_WeekDay = RTC_Weekday_Monday;
\r
877 RTC_DateStruct->RTC_Date = 1;
\r
878 RTC_DateStruct->RTC_Month = RTC_Month_January;
\r
879 RTC_DateStruct->RTC_Year = 0;
\r
883 * @brief Get the RTC current date.
\r
884 * @param RTC_Format: specifies the format of the returned parameters.
\r
885 * This parameter can be one of the following values:
\r
886 * @arg RTC_Format_BIN: Binary data format
\r
887 * @arg RTC_Format_BCD: BCD data format
\r
888 * @param RTC_DateStruct: pointer to a RTC_DateTypeDef structure that will
\r
889 * contain the returned current date configuration.
\r
892 void RTC_GetDate(uint32_t RTC_Format, RTC_DateTypeDef* RTC_DateStruct)
\r
894 uint32_t tmpreg = 0;
\r
896 /* Check the parameters */
\r
897 assert_param(IS_RTC_FORMAT(RTC_Format));
\r
899 /* Get the RTC_TR register */
\r
900 tmpreg = (uint32_t)(RTC->DR & RTC_DR_RESERVED_MASK);
\r
902 /* Fill the structure fields with the read parameters */
\r
903 RTC_DateStruct->RTC_Year = (uint8_t)((tmpreg & (RTC_DR_YT | RTC_DR_YU)) >> 16);
\r
904 RTC_DateStruct->RTC_Month = (uint8_t)((tmpreg & (RTC_DR_MT | RTC_DR_MU)) >> 8);
\r
905 RTC_DateStruct->RTC_Date = (uint8_t)(tmpreg & (RTC_DR_DT | RTC_DR_DU));
\r
906 RTC_DateStruct->RTC_WeekDay = (uint8_t)((tmpreg & (RTC_DR_WDU)) >> 13);
\r
908 /* Check the input parameters format */
\r
909 if (RTC_Format == RTC_Format_BIN)
\r
911 /* Convert the structure parameters to Binary format */
\r
912 RTC_DateStruct->RTC_Year = (uint8_t)RTC_Bcd2ToByte(RTC_DateStruct->RTC_Year);
\r
913 RTC_DateStruct->RTC_Month = (uint8_t)RTC_Bcd2ToByte(RTC_DateStruct->RTC_Month);
\r
914 RTC_DateStruct->RTC_Date = (uint8_t)RTC_Bcd2ToByte(RTC_DateStruct->RTC_Date);
\r
915 RTC_DateStruct->RTC_WeekDay = (uint8_t)(RTC_DateStruct->RTC_WeekDay);
\r
923 /** @defgroup RTC_Group3 Alarms configuration functions
\r
924 * @brief Alarms (Alarm A and Alarm B) configuration functions
\r
927 ===============================================================================
\r
928 Alarms (Alarm A and Alarm B) configuration functions
\r
929 ===============================================================================
\r
931 This section provide functions allowing to program and read the RTC Alarms.
\r
938 * @brief Set the specified RTC Alarm.
\r
939 * @note The Alarm register can only be written when the corresponding Alarm
\r
940 * is disabled (Use the RTC_AlarmCmd(DISABLE)).
\r
941 * @param RTC_Format: specifies the format of the returned parameters.
\r
942 * This parameter can be one of the following values:
\r
943 * @arg RTC_Format_BIN: Binary data format
\r
944 * @arg RTC_Format_BCD: BCD data format
\r
945 * @param RTC_Alarm: specifies the alarm to be configured.
\r
946 * This parameter can be one of the following values:
\r
947 * @arg RTC_Alarm_A: to select Alarm A
\r
948 * @arg RTC_Alarm_B: to select Alarm B
\r
949 * @param RTC_AlarmStruct: pointer to a RTC_AlarmTypeDef structure that
\r
950 * contains the alarm configuration parameters.
\r
953 void RTC_SetAlarm(uint32_t RTC_Format, uint32_t RTC_Alarm, RTC_AlarmTypeDef* RTC_AlarmStruct)
\r
955 uint32_t tmpreg = 0;
\r
957 /* Check the parameters */
\r
958 assert_param(IS_RTC_FORMAT(RTC_Format));
\r
959 assert_param(IS_RTC_ALARM(RTC_Alarm));
\r
960 assert_param(IS_ALARM_MASK(RTC_AlarmStruct->RTC_AlarmMask));
\r
961 assert_param(IS_RTC_ALARM_DATE_WEEKDAY_SEL(RTC_AlarmStruct->RTC_AlarmDateWeekDaySel));
\r
963 if (RTC_Format == RTC_Format_BIN)
\r
965 if ((RTC->CR & RTC_CR_FMT) != (uint32_t)RESET)
\r
967 assert_param(IS_RTC_HOUR12(RTC_AlarmStruct->RTC_AlarmTime.RTC_Hours));
\r
968 assert_param(IS_RTC_H12(RTC_AlarmStruct->RTC_AlarmTime.RTC_H12));
\r
972 RTC_AlarmStruct->RTC_AlarmTime.RTC_H12 = 0x00;
\r
973 assert_param(IS_RTC_HOUR24(RTC_AlarmStruct->RTC_AlarmTime.RTC_Hours));
\r
975 assert_param(IS_RTC_MINUTES(RTC_AlarmStruct->RTC_AlarmTime.RTC_Minutes));
\r
976 assert_param(IS_RTC_SECONDS(RTC_AlarmStruct->RTC_AlarmTime.RTC_Seconds));
\r
978 if(RTC_AlarmStruct->RTC_AlarmDateWeekDaySel == RTC_AlarmDateWeekDaySel_Date)
\r
980 assert_param(IS_RTC_ALARM_DATE_WEEKDAY_DATE(RTC_AlarmStruct->RTC_AlarmDateWeekDay));
\r
984 assert_param(IS_RTC_ALARM_DATE_WEEKDAY_WEEKDAY(RTC_AlarmStruct->RTC_AlarmDateWeekDay));
\r
989 if ((RTC->CR & RTC_CR_FMT) != (uint32_t)RESET)
\r
991 tmpreg = RTC_Bcd2ToByte(RTC_AlarmStruct->RTC_AlarmTime.RTC_Hours);
\r
992 assert_param(IS_RTC_HOUR12(tmpreg));
\r
993 assert_param(IS_RTC_H12(RTC_AlarmStruct->RTC_AlarmTime.RTC_H12));
\r
997 RTC_AlarmStruct->RTC_AlarmTime.RTC_H12 = 0x00;
\r
998 assert_param(IS_RTC_HOUR24(RTC_Bcd2ToByte(RTC_AlarmStruct->RTC_AlarmTime.RTC_Hours)));
\r
1001 assert_param(IS_RTC_MINUTES(RTC_Bcd2ToByte(RTC_AlarmStruct->RTC_AlarmTime.RTC_Minutes)));
\r
1002 assert_param(IS_RTC_SECONDS(RTC_Bcd2ToByte(RTC_AlarmStruct->RTC_AlarmTime.RTC_Seconds)));
\r
1004 if(RTC_AlarmStruct->RTC_AlarmDateWeekDaySel == RTC_AlarmDateWeekDaySel_Date)
\r
1006 tmpreg = RTC_Bcd2ToByte(RTC_AlarmStruct->RTC_AlarmDateWeekDay);
\r
1007 assert_param(IS_RTC_ALARM_DATE_WEEKDAY_DATE(tmpreg));
\r
1011 tmpreg = RTC_Bcd2ToByte(RTC_AlarmStruct->RTC_AlarmDateWeekDay);
\r
1012 assert_param(IS_RTC_ALARM_DATE_WEEKDAY_WEEKDAY(tmpreg));
\r
1016 /* Check the input parameters format */
\r
1017 if (RTC_Format != RTC_Format_BIN)
\r
1019 tmpreg = (((uint32_t)(RTC_AlarmStruct->RTC_AlarmTime.RTC_Hours) << 16) | \
\r
1020 ((uint32_t)(RTC_AlarmStruct->RTC_AlarmTime.RTC_Minutes) << 8) | \
\r
1021 ((uint32_t)RTC_AlarmStruct->RTC_AlarmTime.RTC_Seconds) | \
\r
1022 ((uint32_t)(RTC_AlarmStruct->RTC_AlarmTime.RTC_H12) << 16) | \
\r
1023 ((uint32_t)(RTC_AlarmStruct->RTC_AlarmDateWeekDay) << 24) | \
\r
1024 ((uint32_t)RTC_AlarmStruct->RTC_AlarmDateWeekDaySel) | \
\r
1025 ((uint32_t)RTC_AlarmStruct->RTC_AlarmMask));
\r
1029 tmpreg = (((uint32_t)RTC_ByteToBcd2(RTC_AlarmStruct->RTC_AlarmTime.RTC_Hours) << 16) | \
\r
1030 ((uint32_t)RTC_ByteToBcd2(RTC_AlarmStruct->RTC_AlarmTime.RTC_Minutes) << 8) | \
\r
1031 ((uint32_t)RTC_ByteToBcd2(RTC_AlarmStruct->RTC_AlarmTime.RTC_Seconds)) | \
\r
1032 ((uint32_t)(RTC_AlarmStruct->RTC_AlarmTime.RTC_H12) << 16) | \
\r
1033 ((uint32_t)RTC_ByteToBcd2(RTC_AlarmStruct->RTC_AlarmDateWeekDay) << 24) | \
\r
1034 ((uint32_t)RTC_AlarmStruct->RTC_AlarmDateWeekDaySel) | \
\r
1035 ((uint32_t)RTC_AlarmStruct->RTC_AlarmMask));
\r
1038 /* Disable the write protection for RTC registers */
\r
1042 /* Configure the Alarm register */
\r
1043 if (RTC_Alarm == RTC_Alarm_A)
\r
1045 RTC->ALRMAR = (uint32_t)tmpreg;
\r
1049 RTC->ALRMBR = (uint32_t)tmpreg;
\r
1052 /* Enable the write protection for RTC registers */
\r
1057 * @brief Fills each RTC_AlarmStruct member with its default value
\r
1058 * (Time = 00h:00mn:00sec / Date = 1st day of the month/Mask =
\r
1059 * all fields are masked).
\r
1060 * @param RTC_AlarmStruct: pointer to a @ref RTC_AlarmTypeDef structure which
\r
1061 * will be initialized.
\r
1064 void RTC_AlarmStructInit(RTC_AlarmTypeDef* RTC_AlarmStruct)
\r
1066 /* Alarm Time Settings : Time = 00h:00mn:00sec */
\r
1067 RTC_AlarmStruct->RTC_AlarmTime.RTC_H12 = RTC_H12_AM;
\r
1068 RTC_AlarmStruct->RTC_AlarmTime.RTC_Hours = 0;
\r
1069 RTC_AlarmStruct->RTC_AlarmTime.RTC_Minutes = 0;
\r
1070 RTC_AlarmStruct->RTC_AlarmTime.RTC_Seconds = 0;
\r
1072 /* Alarm Date Settings : Date = 1st day of the month */
\r
1073 RTC_AlarmStruct->RTC_AlarmDateWeekDaySel = RTC_AlarmDateWeekDaySel_Date;
\r
1074 RTC_AlarmStruct->RTC_AlarmDateWeekDay = 1;
\r
1076 /* Alarm Masks Settings : Mask = all fields are not masked */
\r
1077 RTC_AlarmStruct->RTC_AlarmMask = RTC_AlarmMask_None;
\r
1081 * @brief Get the RTC Alarm value and masks.
\r
1082 * @param RTC_Format: specifies the format of the output parameters.
\r
1083 * This parameter can be one of the following values:
\r
1084 * @arg RTC_Format_BIN: Binary data format
\r
1085 * @arg RTC_Format_BCD: BCD data format
\r
1086 * @param RTC_Alarm: specifies the alarm to be read.
\r
1087 * This parameter can be one of the following values:
\r
1088 * @arg RTC_Alarm_A: to select Alarm A
\r
1089 * @arg RTC_Alarm_B: to select Alarm B
\r
1090 * @param RTC_AlarmStruct: pointer to a RTC_AlarmTypeDef structure that will
\r
1091 * contains the output alarm configuration values.
\r
1094 void RTC_GetAlarm(uint32_t RTC_Format, uint32_t RTC_Alarm, RTC_AlarmTypeDef* RTC_AlarmStruct)
\r
1096 uint32_t tmpreg = 0;
\r
1098 /* Check the parameters */
\r
1099 assert_param(IS_RTC_FORMAT(RTC_Format));
\r
1100 assert_param(IS_RTC_ALARM(RTC_Alarm));
\r
1102 /* Get the RTC_ALRMxR register */
\r
1103 if (RTC_Alarm == RTC_Alarm_A)
\r
1105 tmpreg = (uint32_t)(RTC->ALRMAR);
\r
1109 tmpreg = (uint32_t)(RTC->ALRMBR);
\r
1112 /* Fill the structure with the read parameters */
\r
1113 RTC_AlarmStruct->RTC_AlarmTime.RTC_Hours = (uint32_t)((tmpreg & (RTC_ALRMAR_HT | \
\r
1114 RTC_ALRMAR_HU)) >> 16);
\r
1115 RTC_AlarmStruct->RTC_AlarmTime.RTC_Minutes = (uint32_t)((tmpreg & (RTC_ALRMAR_MNT | \
\r
1116 RTC_ALRMAR_MNU)) >> 8);
\r
1117 RTC_AlarmStruct->RTC_AlarmTime.RTC_Seconds = (uint32_t)(tmpreg & (RTC_ALRMAR_ST | \
\r
1119 RTC_AlarmStruct->RTC_AlarmTime.RTC_H12 = (uint32_t)((tmpreg & RTC_ALRMAR_PM) >> 16);
\r
1120 RTC_AlarmStruct->RTC_AlarmDateWeekDay = (uint32_t)((tmpreg & (RTC_ALRMAR_DT | RTC_ALRMAR_DU)) >> 24);
\r
1121 RTC_AlarmStruct->RTC_AlarmDateWeekDaySel = (uint32_t)(tmpreg & RTC_ALRMAR_WDSEL);
\r
1122 RTC_AlarmStruct->RTC_AlarmMask = (uint32_t)(tmpreg & RTC_AlarmMask_All);
\r
1124 if (RTC_Format == RTC_Format_BIN)
\r
1126 RTC_AlarmStruct->RTC_AlarmTime.RTC_Hours = RTC_Bcd2ToByte(RTC_AlarmStruct-> \
\r
1127 RTC_AlarmTime.RTC_Hours);
\r
1128 RTC_AlarmStruct->RTC_AlarmTime.RTC_Minutes = RTC_Bcd2ToByte(RTC_AlarmStruct-> \
\r
1129 RTC_AlarmTime.RTC_Minutes);
\r
1130 RTC_AlarmStruct->RTC_AlarmTime.RTC_Seconds = RTC_Bcd2ToByte(RTC_AlarmStruct-> \
\r
1131 RTC_AlarmTime.RTC_Seconds);
\r
1132 RTC_AlarmStruct->RTC_AlarmDateWeekDay = RTC_Bcd2ToByte(RTC_AlarmStruct->RTC_AlarmDateWeekDay);
\r
1137 * @brief Enables or disables the specified RTC Alarm.
\r
1138 * @param RTC_Alarm: specifies the alarm to be configured.
\r
1139 * This parameter can be any combination of the following values:
\r
1140 * @arg RTC_Alarm_A: to select Alarm A
\r
1141 * @arg RTC_Alarm_B: to select Alarm B
\r
1142 * @param NewState: new state of the specified alarm.
\r
1143 * This parameter can be: ENABLE or DISABLE.
\r
1144 * @retval An ErrorStatus enumeration value:
\r
1145 * - SUCCESS: RTC Alarm is enabled/disabled
\r
1146 * - ERROR: RTC Alarm is not enabled/disabled
\r
1148 ErrorStatus RTC_AlarmCmd(uint32_t RTC_Alarm, FunctionalState NewState)
\r
1150 __IO uint32_t alarmcounter = 0x00;
\r
1151 uint32_t alarmstatus = 0x00;
\r
1152 ErrorStatus status = ERROR;
\r
1154 /* Check the parameters */
\r
1155 assert_param(IS_RTC_CMD_ALARM(RTC_Alarm));
\r
1156 assert_param(IS_FUNCTIONAL_STATE(NewState));
\r
1158 /* Disable the write protection for RTC registers */
\r
1162 /* Configure the Alarm state */
\r
1163 if (NewState != DISABLE)
\r
1165 RTC->CR |= (uint32_t)RTC_Alarm;
\r
1167 status = SUCCESS;
\r
1171 /* Disable the Alarm in RTC_CR register */
\r
1172 RTC->CR &= (uint32_t)~RTC_Alarm;
\r
1174 /* Wait till RTC ALRxWF flag is set and if Time out is reached exit */
\r
1177 alarmstatus = RTC->ISR & (RTC_Alarm >> 8);
\r
1179 } while((alarmcounter != INITMODE_TIMEOUT) && (alarmstatus == 0x00));
\r
1181 if ((RTC->ISR & (RTC_Alarm >> 8)) == RESET)
\r
1191 /* Enable the write protection for RTC registers */
\r
1201 /** @defgroup RTC_Group4 WakeUp Timer configuration functions
\r
1202 * @brief WakeUp Timer configuration functions
\r
1205 ===============================================================================
\r
1206 WakeUp Timer configuration functions
\r
1207 ===============================================================================
\r
1209 This section provide functions allowing to program and read the RTC WakeUp.
\r
1216 * @brief Configures the RTC Wakeup clock source.
\r
1217 * @note The WakeUp Clock source can only be changed when the RTC WakeUp
\r
1218 * is disabled (Use the RTC_WakeUpCmd(DISABLE)).
\r
1219 * @param RTC_WakeUpClock: Wakeup Clock source.
\r
1220 * This parameter can be one of the following values:
\r
1221 * @arg RTC_WakeUpClock_RTCCLK_Div16
\r
1222 * @arg RTC_WakeUpClock_RTCCLK_Div8
\r
1223 * @arg RTC_WakeUpClock_RTCCLK_Div4
\r
1224 * @arg RTC_WakeUpClock_RTCCLK_Div2
\r
1225 * @arg RTC_WakeUpClock_CK_SPRE_16bits
\r
1226 * @arg RTC_WakeUpClock_CK_SPRE_17bits
\r
1229 void RTC_WakeUpClockConfig(uint32_t RTC_WakeUpClock)
\r
1231 /* Check the parameters */
\r
1232 assert_param(IS_RTC_WAKEUP_CLOCK(RTC_WakeUpClock));
\r
1234 /* Disable the write protection for RTC registers */
\r
1238 /* Clear the Wakeup Timer clock source bits in CR register */
\r
1239 RTC->CR &= (uint32_t)~RTC_CR_WUCKSEL;
\r
1241 /* Configure the clock source */
\r
1242 RTC->CR |= (uint32_t)RTC_WakeUpClock;
\r
1244 /* Enable the write protection for RTC registers */
\r
1249 * @brief Configures the RTC Wakeup counter.
\r
1250 * @note The RTC WakeUp counter can only be written when the RTC WakeUp
\r
1251 * is disabled (Use the RTC_WakeUpCmd(DISABLE)).
\r
1252 * @param RTC_WakeUpCounter: specifies the WakeUp counter.
\r
1253 * This parameter can be a value from 0x0000 to 0xFFFF.
\r
1256 void RTC_SetWakeUpCounter(uint32_t RTC_WakeUpCounter)
\r
1258 /* Check the parameters */
\r
1259 assert_param(IS_RTC_WAKEUP_COUNTER(RTC_WakeUpCounter));
\r
1261 /* Disable the write protection for RTC registers */
\r
1265 /* Configure the Wakeup Timer counter */
\r
1266 RTC->WUTR = (uint32_t)RTC_WakeUpCounter;
\r
1268 /* Enable the write protection for RTC registers */
\r
1273 * @brief Returns the RTC WakeUp timer counter value.
\r
1275 * @retval The RTC WakeUp Counter value.
\r
1277 uint32_t RTC_GetWakeUpCounter(void)
\r
1279 /* Get the counter value */
\r
1280 return ((uint32_t)(RTC->WUTR & RTC_WUTR_WUT));
\r
1284 * @brief Enables or Disables the RTC WakeUp timer.
\r
1285 * @param NewState: new state of the WakeUp timer.
\r
1286 * This parameter can be: ENABLE or DISABLE.
\r
1289 ErrorStatus RTC_WakeUpCmd(FunctionalState NewState)
\r
1291 __IO uint32_t wutcounter = 0x00;
\r
1292 uint32_t wutwfstatus = 0x00;
\r
1293 ErrorStatus status = ERROR;
\r
1295 /* Check the parameters */
\r
1296 assert_param(IS_FUNCTIONAL_STATE(NewState));
\r
1298 /* Disable the write protection for RTC registers */
\r
1302 if (NewState != DISABLE)
\r
1304 /* Enable the Wakeup Timer */
\r
1305 RTC->CR |= (uint32_t)RTC_CR_WUTE;
\r
1306 status = SUCCESS;
\r
1310 /* Disable the Wakeup Timer */
\r
1311 RTC->CR &= (uint32_t)~RTC_CR_WUTE;
\r
1312 /* Wait till RTC WUTWF flag is set and if Time out is reached exit */
\r
1315 wutwfstatus = RTC->ISR & RTC_ISR_WUTWF;
\r
1317 } while((wutcounter != INITMODE_TIMEOUT) && (wutwfstatus == 0x00));
\r
1319 if ((RTC->ISR & RTC_ISR_WUTWF) == RESET)
\r
1329 /* Enable the write protection for RTC registers */
\r
1339 /** @defgroup RTC_Group5 Daylight Saving configuration functions
\r
1340 * @brief Daylight Saving configuration functions
\r
1343 ===============================================================================
\r
1344 Daylight Saving configuration functions
\r
1345 ===============================================================================
\r
1347 This section provide functions allowing to configure the RTC DayLight Saving.
\r
1354 * @brief Adds or substract one hour from the current time.
\r
1355 * @param RTC_DayLightSaveOperation: the value of hour adjustment.
\r
1356 * This parameter can be one of the following values:
\r
1357 * @arg RTC_DayLightSaving_SUB1H: Substract one hour (winter time)
\r
1358 * @arg RTC_DayLightSaving_ADD1H: Add one hour (summer time)
\r
1359 * @param RTC_StoreOperation: Specifies the value to be written in the BCK bit
\r
1360 * in CR register to store the operation.
\r
1361 * This parameter can be one of the following values:
\r
1362 * @arg RTC_StoreOperation_Reset
\r
1363 * @arg RTC_StoreOperation_Set
\r
1366 void RTC_DayLightSavingConfig(uint32_t RTC_DayLightSaving, uint32_t RTC_StoreOperation)
\r
1368 /* Check the parameters */
\r
1369 assert_param(IS_RTC_DAYLIGHT_SAVING(RTC_DayLightSaving));
\r
1370 assert_param(IS_RTC_STORE_OPERATION(RTC_StoreOperation));
\r
1372 /* Disable the write protection for RTC registers */
\r
1376 /* Clear the bits to be configured */
\r
1377 RTC->CR &= (uint32_t)~(RTC_CR_BCK);
\r
1379 /* Configure the RTC_CR register */
\r
1380 RTC->CR |= (uint32_t)(RTC_DayLightSaving | RTC_StoreOperation);
\r
1382 /* Enable the write protection for RTC registers */
\r
1387 * @brief Returns the RTC Day Light Saving stored operation.
\r
1389 * @retval RTC Day Light Saving stored operation.
\r
1390 * - RTC_StoreOperation_Reset
\r
1391 * - RTC_StoreOperation_Set
\r
1393 uint32_t RTC_GetStoreOperation(void)
\r
1395 return (RTC->CR & RTC_CR_BCK);
\r
1402 /** @defgroup RTC_Group6 Output pin Configuration function
\r
1403 * @brief Output pin Configuration function
\r
1406 ===============================================================================
\r
1407 Output pin Configuration function
\r
1408 ===============================================================================
\r
1410 This section provide functions allowing to configure the RTC Output source.
\r
1417 * @brief Configures the RTC output source (AFO_ALARM).
\r
1418 * @param RTC_Output: Specifies which signal will be routed to the RTC output.
\r
1419 * This parameter can be one of the following values:
\r
1420 * @arg RTC_Output_Disable: No output selected
\r
1421 * @arg RTC_Output_AlarmA: signal of AlarmA mapped to output
\r
1422 * @arg RTC_Output_AlarmB: signal of AlarmB mapped to output
\r
1423 * @arg RTC_Output_WakeUp: signal of WakeUp mapped to output
\r
1424 * @param RTC_OutputPolarity: Specifies the polarity of the output signal.
\r
1425 * This parameter can be one of the following:
\r
1426 * @arg RTC_OutputPolarity_High: The output pin is high when the
\r
1427 * ALRAF/ALRBF/WUTF is high (depending on OSEL)
\r
1428 * @arg RTC_OutputPolarity_Low: The output pin is low when the
\r
1429 * ALRAF/ALRBF/WUTF is high (depending on OSEL)
\r
1432 void RTC_OutputConfig(uint32_t RTC_Output, uint32_t RTC_OutputPolarity)
\r
1434 /* Check the parameters */
\r
1435 assert_param(IS_RTC_OUTPUT(RTC_Output));
\r
1436 assert_param(IS_RTC_OUTPUT_POL(RTC_OutputPolarity));
\r
1438 /* Disable the write protection for RTC registers */
\r
1442 /* Clear the bits to be configured */
\r
1443 RTC->CR &= (uint32_t)~(RTC_CR_OSEL | RTC_CR_POL);
\r
1445 /* Configure the output selection and polarity */
\r
1446 RTC->CR |= (uint32_t)(RTC_Output | RTC_OutputPolarity);
\r
1448 /* Enable the write protection for RTC registers */
\r
1456 /** @defgroup RTC_Group7 Digital Calibration configuration functions
\r
1457 * @brief Digital Calibration configuration functions
\r
1460 ===============================================================================
\r
1461 Digital Calibration configuration functions
\r
1462 ===============================================================================
\r
1469 * @brief Configures the digital calibration parameters.
\r
1470 * @param RTC_CalibSign: specifies the sign of the calibration value.
\r
1471 * This parameter can be one of the following values:
\r
1472 * @arg RTC_CalibSign_Positive: The value sign is positive
\r
1473 * @arg RTC_CalibSign_Negative: The value sign is negative
\r
1474 * @param Value: value of calibration expressed in ppm (coded on 5 bits)
\r
1475 * - This value should be between 0 and 63 when using negative sign
\r
1476 * with a 2-ppm step.
\r
1477 * - This value should be between 0 and 126 when using positive sign
\r
1478 * with a 4-ppm step.
\r
1479 * @retval An ErrorStatus enumeration value:
\r
1480 * - SUCCESS: RTC digital calibration are initialized
\r
1481 * - ERROR: RTC digital calibration are not initialized
\r
1483 ErrorStatus RTC_DigitalCalibConfig(uint32_t RTC_CalibSign, uint32_t Value)
\r
1485 ErrorStatus status = ERROR;
\r
1487 /* Check the parameters */
\r
1488 assert_param(IS_RTC_CALIB_SIGN(RTC_CalibSign));
\r
1489 assert_param(IS_RTC_CALIB_VALUE(Value));
\r
1491 /* Disable the write protection for RTC registers */
\r
1495 /* Set Initialization mode */
\r
1496 if (RTC_EnterInitMode() == ERROR)
\r
1502 /* Set the calibration value */
\r
1503 RTC->CALIBR = (uint32_t)(RTC_CalibSign | Value);
\r
1504 /* Exit Initialization mode */
\r
1505 RTC_ExitInitMode();
\r
1510 /* Enable the write protection for RTC registers */
\r
1517 * @brief Enables or disables the digital calibration process.
\r
1518 * @param NewState: new state of the digital calibration.
\r
1519 * This parameter can be: ENABLE or DISABLE.
\r
1520 * @retval An ErrorStatus enumeration value:
\r
1521 * - SUCCESS: RTC digital calibration are enabled/disabled
\r
1522 * - ERROR: RTC digital calibration are not enabled/disabled
\r
1524 ErrorStatus RTC_DigitalCalibCmd(FunctionalState NewState)
\r
1526 ErrorStatus status = ERROR;
\r
1528 /* Check the parameters */
\r
1529 assert_param(IS_FUNCTIONAL_STATE(NewState));
\r
1531 /* Disable the write protection for RTC registers */
\r
1535 /* Set Initialization mode */
\r
1536 if (RTC_EnterInitMode() == ERROR)
\r
1542 if (NewState != DISABLE)
\r
1544 /* Enable the Digital Calibration */
\r
1545 RTC->CR |= (uint32_t)RTC_CR_DCE;
\r
1549 /* Disable the Digital Calibration */
\r
1550 RTC->CR &= (uint32_t)~RTC_CR_DCE;
\r
1552 /* Exit Initialization mode */
\r
1553 RTC_ExitInitMode();
\r
1558 /* Enable the write protection for RTC registers */
\r
1565 * @brief Enables or disables the RTC clock to be output through the relative
\r
1567 * @param NewState: new state of the digital calibration Output.
\r
1568 * This parameter can be: ENABLE or DISABLE.
\r
1571 void RTC_CalibOutputCmd(FunctionalState NewState)
\r
1573 /* Check the parameters */
\r
1574 assert_param(IS_FUNCTIONAL_STATE(NewState));
\r
1576 /* Disable the write protection for RTC registers */
\r
1580 if (NewState != DISABLE)
\r
1582 /* Enable the RTC clock output */
\r
1583 RTC->CR |= (uint32_t)RTC_CR_COE;
\r
1587 /* Disable the RTC clock output */
\r
1588 RTC->CR &= (uint32_t)~RTC_CR_COE;
\r
1591 /* Enable the write protection for RTC registers */
\r
1600 /** @defgroup RTC_Group8 TimeStamp configuration functions
\r
1601 * @brief TimeStamp configuration functions
\r
1604 ===============================================================================
\r
1605 TimeStamp configuration functions
\r
1606 ===============================================================================
\r
1613 * @brief Enables or Disables the RTC TimeStamp functionality with the
\r
1614 * specified time stamp pin stimulating edge.
\r
1615 * @param RTC_TimeStampEdge: Specifies the pin edge on which the TimeStamp is
\r
1617 * This parameter can be one of the following:
\r
1618 * @arg RTC_TimeStampEdge_Rising: the Time stamp event occurs on the rising
\r
1619 * edge of the related pin.
\r
1620 * @arg RTC_TimeStampEdge_Falling: the Time stamp event occurs on the
\r
1621 * falling edge of the related pin.
\r
1622 * @param NewState: new state of the TimeStamp.
\r
1623 * This parameter can be: ENABLE or DISABLE.
\r
1626 void RTC_TimeStampCmd(uint32_t RTC_TimeStampEdge, FunctionalState NewState)
\r
1628 uint32_t tmpreg = 0;
\r
1630 /* Check the parameters */
\r
1631 assert_param(IS_RTC_TIMESTAMP_EDGE(RTC_TimeStampEdge));
\r
1632 assert_param(IS_FUNCTIONAL_STATE(NewState));
\r
1634 /* Get the RTC_CR register and clear the bits to be configured */
\r
1635 tmpreg = (uint32_t)(RTC->CR & (uint32_t)~(RTC_CR_TSEDGE | RTC_CR_TSE));
\r
1637 /* Get the new configuration */
\r
1638 if (NewState != DISABLE)
\r
1640 tmpreg |= (uint32_t)(RTC_TimeStampEdge | RTC_CR_TSE);
\r
1644 tmpreg |= (uint32_t)(RTC_TimeStampEdge);
\r
1647 /* Disable the write protection for RTC registers */
\r
1651 /* Configure the Time Stamp TSEDGE and Enable bits */
\r
1652 RTC->CR = (uint32_t)tmpreg;
\r
1654 /* Enable the write protection for RTC registers */
\r
1659 * @brief Get the RTC TimeStamp value and masks.
\r
1660 * @param RTC_Format: specifies the format of the output parameters.
\r
1661 * This parameter can be one of the following values:
\r
1662 * @arg RTC_Format_BIN: Binary data format
\r
1663 * @arg RTC_Format_BCD: BCD data format
\r
1664 * @param RTC_StampTimeStruct: pointer to a RTC_TimeTypeDef structure that will
\r
1665 * contains the TimeStamp time values.
\r
1666 * @param RTC_StampDateStruct: pointer to a RTC_DateTypeDef structure that will
\r
1667 * contains the TimeStamp date values.
\r
1670 void RTC_GetTimeStamp(uint32_t RTC_Format, RTC_TimeTypeDef* RTC_StampTimeStruct,
\r
1671 RTC_DateTypeDef* RTC_StampDateStruct)
\r
1673 uint32_t tmptime = 0, tmpdate = 0;
\r
1675 /* Check the parameters */
\r
1676 assert_param(IS_RTC_FORMAT(RTC_Format));
\r
1678 /* Get the TimeStamp time and date registers values */
\r
1679 tmptime = (uint32_t)(RTC->TSTR & RTC_TR_RESERVED_MASK);
\r
1680 tmpdate = (uint32_t)(RTC->TSDR & RTC_DR_RESERVED_MASK);
\r
1682 /* Fill the Time structure fields with the read parameters */
\r
1683 RTC_StampTimeStruct->RTC_Hours = (uint8_t)((tmptime & (RTC_TR_HT | RTC_TR_HU)) >> 16);
\r
1684 RTC_StampTimeStruct->RTC_Minutes = (uint8_t)((tmptime & (RTC_TR_MNT | RTC_TR_MNU)) >> 8);
\r
1685 RTC_StampTimeStruct->RTC_Seconds = (uint8_t)(tmptime & (RTC_TR_ST | RTC_TR_SU));
\r
1686 RTC_StampTimeStruct->RTC_H12 = (uint8_t)((tmptime & (RTC_TR_PM)) >> 16);
\r
1688 /* Fill the Date structure fields with the read parameters */
\r
1689 RTC_StampDateStruct->RTC_Year = 0;
\r
1690 RTC_StampDateStruct->RTC_Month = (uint8_t)((tmpdate & (RTC_DR_MT | RTC_DR_MU)) >> 8);
\r
1691 RTC_StampDateStruct->RTC_Date = (uint8_t)(tmpdate & (RTC_DR_DT | RTC_DR_DU));
\r
1692 RTC_StampDateStruct->RTC_WeekDay = (uint8_t)((tmpdate & (RTC_DR_WDU)) >> 13);
\r
1694 /* Check the input parameters format */
\r
1695 if (RTC_Format == RTC_Format_BIN)
\r
1697 /* Convert the Time structure parameters to Binary format */
\r
1698 RTC_StampTimeStruct->RTC_Hours = (uint8_t)RTC_Bcd2ToByte(RTC_StampTimeStruct->RTC_Hours);
\r
1699 RTC_StampTimeStruct->RTC_Minutes = (uint8_t)RTC_Bcd2ToByte(RTC_StampTimeStruct->RTC_Minutes);
\r
1700 RTC_StampTimeStruct->RTC_Seconds = (uint8_t)RTC_Bcd2ToByte(RTC_StampTimeStruct->RTC_Seconds);
\r
1702 /* Convert the Date structure parameters to Binary format */
\r
1703 RTC_StampDateStruct->RTC_Month = (uint8_t)RTC_Bcd2ToByte(RTC_StampDateStruct->RTC_Month);
\r
1704 RTC_StampDateStruct->RTC_Date = (uint8_t)RTC_Bcd2ToByte(RTC_StampDateStruct->RTC_Date);
\r
1705 RTC_StampDateStruct->RTC_WeekDay = (uint8_t)RTC_Bcd2ToByte(RTC_StampDateStruct->RTC_WeekDay);
\r
1713 /** @defgroup RTC_Group9 Tampers configuration functions
\r
1714 * @brief Tampers configuration functions
\r
1717 ===============================================================================
\r
1718 Tampers configuration functions
\r
1719 ===============================================================================
\r
1726 * @brief Configures the select Tamper pin edge.
\r
1727 * @param RTC_Tamper: Selected tamper pin.
\r
1728 * This parameter can be RTC_Tamper_1.
\r
1729 * @param RTC_TamperTrigger: Specifies the trigger on the tamper pin that
\r
1730 * stimulates tamper event.
\r
1731 * This parameter can be one of the following values:
\r
1732 * @arg RTC_TamperTrigger_RisingEdge: Rising Edge of the tamper pin causes tamper event.
\r
1733 * @arg RTC_TamperTrigger_FallingEdge: Falling Edge of the tamper pin causes tamper event.
\r
1736 void RTC_TamperTriggerConfig(uint32_t RTC_Tamper, uint32_t RTC_TamperTrigger)
\r
1738 /* Check the parameters */
\r
1739 assert_param(IS_RTC_TAMPER(RTC_Tamper));
\r
1740 assert_param(IS_RTC_TAMPER_TRIGGER(RTC_TamperTrigger));
\r
1742 if (RTC_TamperTrigger == RTC_TamperTrigger_RisingEdge)
\r
1744 /* Configure the RTC_TAFCR register */
\r
1745 RTC->TAFCR &= (uint32_t)((uint32_t)~(RTC_Tamper << 1));
\r
1749 /* Configure the RTC_TAFCR register */
\r
1750 RTC->TAFCR |= (uint32_t)(RTC_Tamper << 1);
\r
1755 * @brief Enables or Disables the Tamper detection.
\r
1756 * @param RTC_Tamper: Selected tamper pin.
\r
1757 * This parameter can be RTC_Tamper_1.
\r
1758 * @param NewState: new state of the tamper pin.
\r
1759 * This parameter can be: ENABLE or DISABLE.
\r
1762 void RTC_TamperCmd(uint32_t RTC_Tamper, FunctionalState NewState)
\r
1764 /* Check the parameters */
\r
1765 assert_param(IS_RTC_TAMPER(RTC_Tamper));
\r
1766 assert_param(IS_FUNCTIONAL_STATE(NewState));
\r
1768 if (NewState != DISABLE)
\r
1770 /* Enable the selected Tamper pin */
\r
1771 RTC->TAFCR |= (uint32_t)RTC_Tamper;
\r
1775 /* Disable the selected Tamper pin */
\r
1776 RTC->TAFCR &= (uint32_t)~RTC_Tamper;
\r
1784 /** @defgroup RTC_Group10 Backup Data Registers configuration functions
\r
1785 * @brief Backup Data Registers configuration functions
\r
1788 ===============================================================================
\r
1789 Backup Data Registers configuration functions
\r
1790 ===============================================================================
\r
1797 * @brief Writes a data in a specified RTC Backup data register.
\r
1798 * @param RTC_BKP_DR: RTC Backup data Register number.
\r
1799 * This parameter can be: RTC_BKP_DRx where x can be from 0 to 19 to
\r
1800 * specify the register.
\r
1801 * @param Data: Data to be written in the specified RTC Backup data register.
\r
1804 void RTC_WriteBackupRegister(uint32_t RTC_BKP_DR, uint32_t Data)
\r
1806 __IO uint32_t tmp = 0;
\r
1808 /* Check the parameters */
\r
1809 assert_param(IS_RTC_BKP(RTC_BKP_DR));
\r
1811 tmp = RTC_BASE + 0x50;
\r
1812 tmp += (RTC_BKP_DR * 4);
\r
1814 /* Write the specified register */
\r
1815 *(__IO uint32_t *)tmp = (uint32_t)Data;
\r
1819 * @brief Reads data from the specified RTC Backup data Register.
\r
1820 * @param RTC_BKP_DR: RTC Backup data Register number.
\r
1821 * This parameter can be: RTC_BKP_DRx where x can be from 0 to 19 to
\r
1822 * specify the register.
\r
1825 uint32_t RTC_ReadBackupRegister(uint32_t RTC_BKP_DR)
\r
1827 __IO uint32_t tmp = 0;
\r
1829 /* Check the parameters */
\r
1830 assert_param(IS_RTC_BKP(RTC_BKP_DR));
\r
1832 tmp = RTC_BASE + 0x50;
\r
1833 tmp += (RTC_BKP_DR * 4);
\r
1835 /* Read the specified register */
\r
1836 return (*(__IO uint32_t *)tmp);
\r
1843 /** @defgroup RTC_Group11 Output Type Config configuration functions
\r
1844 * @brief Output Type Config configuration functions
\r
1847 ===============================================================================
\r
1848 Output Type Config configuration functions
\r
1849 ===============================================================================
\r
1856 * @brief Configures the RTC Output Pin mode.
\r
1857 * @param RTC_OutputType: specifies the RTC Output (PC13) pin mode.
\r
1858 * This parameter can be one of the following values:
\r
1859 * @arg RTC_OutputType_OpenDrain: RTC Output (PC13) is configured in
\r
1860 * Open Drain mode.
\r
1861 * @arg RTC_OutputType_PushPull: RTC Output (PC13) is configured in
\r
1862 * Push Pull mode.
\r
1865 void RTC_OutputTypeConfig(uint32_t RTC_OutputType)
\r
1867 /* Check the parameters */
\r
1868 assert_param(IS_RTC_OUTPUT_TYPE(RTC_OutputType));
\r
1870 RTC->TAFCR &= (uint32_t)~(RTC_TAFCR_ALARMOUTTYPE);
\r
1871 RTC->TAFCR |= (uint32_t)(RTC_OutputType);
\r
1878 /** @defgroup RTC_Group12 Interrupts and flags management functions
\r
1879 * @brief Interrupts and flags management functions
\r
1882 ===============================================================================
\r
1883 Interrupts and flags management functions
\r
1884 ===============================================================================
\r
1885 All RTC interrupts are connected to the EXTI controller.
\r
1887 - To enable the RTC Alarm interrupt, the following sequence is required:
\r
1888 - Configure and enable the EXTI Line 17 in interrupt mode and select the rising
\r
1889 edge sensitivity using the EXTI_Init() function.
\r
1890 - Configure and enable the RTC_Alarm IRQ channel in the NVIC using the NVIC_Init()
\r
1892 - Configure the RTC to generate RTC alarms (Alarm A and/or Alarm B) using
\r
1893 the RTC_SetAlarm() and RTC_AlarmCmd() functions.
\r
1895 - To enable the RTC Wakeup interrupt, the following sequence is required:
\r
1896 - Configure and enable the EXTI Line 20 in interrupt mode and select the rising
\r
1897 edge sensitivity using the EXTI_Init() function.
\r
1898 - Configure and enable the RTC_WKUP IRQ channel in the NVIC using the NVIC_Init()
\r
1900 - Configure the RTC to generate the RTC wakeup timer event using the
\r
1901 RTC_WakeUpClockConfig(), RTC_SetWakeUpCounter() and RTC_WakeUpCmd() functions.
\r
1903 - To enable the RTC Tamper interrupt, the following sequence is required:
\r
1904 - Configure and enable the EXTI Line 19 in interrupt mode and select the rising
\r
1905 edge sensitivity using the EXTI_Init() function.
\r
1906 - Configure and enable the TAMP_STAMP IRQ channel in the NVIC using the NVIC_Init()
\r
1908 - Configure the RTC to detect the RTC tamper event using the
\r
1909 RTC_TamperTriggerConfig() and RTC_TamperCmd() functions.
\r
1911 - To enable the RTC TimeStamp interrupt, the following sequence is required:
\r
1912 - Configure and enable the EXTI Line 19 in interrupt mode and select the rising
\r
1913 edge sensitivity using the EXTI_Init() function.
\r
1914 - Configure and enable the TAMP_STAMP IRQ channel in the NVIC using the NVIC_Init()
\r
1916 - Configure the RTC to detect the RTC time-stamp event using the
\r
1917 RTC_TimeStampCmd() functions.
\r
1924 * @brief Enables or disables the specified RTC interrupts.
\r
1925 * @param RTC_IT: specifies the RTC interrupt sources to be enabled or disabled.
\r
1926 * This parameter can be any combination of the following values:
\r
1927 * @arg RTC_IT_TS: Time Stamp interrupt mask
\r
1928 * @arg RTC_IT_WUT: WakeUp Timer interrupt mask
\r
1929 * @arg RTC_IT_ALRB: Alarm B interrupt mask
\r
1930 * @arg RTC_IT_ALRA: Alarm A interrupt mask
\r
1931 * @arg RTC_IT_TAMP: Tamper event interrupt mask
\r
1932 * @param NewState: new state of the specified RTC interrupts.
\r
1933 * This parameter can be: ENABLE or DISABLE.
\r
1936 void RTC_ITConfig(uint32_t RTC_IT, FunctionalState NewState)
\r
1938 /* Check the parameters */
\r
1939 assert_param(IS_RTC_CONFIG_IT(RTC_IT));
\r
1940 assert_param(IS_FUNCTIONAL_STATE(NewState));
\r
1942 /* Disable the write protection for RTC registers */
\r
1946 if (NewState != DISABLE)
\r
1948 /* Configure the Interrupts in the RTC_CR register */
\r
1949 RTC->CR |= (uint32_t)(RTC_IT & ~RTC_TAFCR_TAMPIE);
\r
1950 /* Configure the Tamper Interrupt in the RTC_TAFCR */
\r
1951 RTC->TAFCR |= (uint32_t)(RTC_IT & RTC_TAFCR_TAMPIE);
\r
1955 /* Configure the Interrupts in the RTC_CR register */
\r
1956 RTC->CR &= (uint32_t)~(RTC_IT & (uint32_t)~RTC_TAFCR_TAMPIE);
\r
1957 /* Configure the Tamper Interrupt in the RTC_TAFCR */
\r
1958 RTC->TAFCR &= (uint32_t)~(RTC_IT & RTC_TAFCR_TAMPIE);
\r
1960 /* Enable the write protection for RTC registers */
\r
1965 * @brief Checks whether the specified RTC flag is set or not.
\r
1966 * @param RTC_FLAG: specifies the flag to check.
\r
1967 * This parameter can be one of the following values:
\r
1968 * @arg RTC_FLAG_TAMP1F: Tamper 1 event flag
\r
1969 * @arg RTC_FLAG_TSOVF: Time Stamp OverFlow flag
\r
1970 * @arg RTC_FLAG_TSF: Time Stamp event flag
\r
1971 * @arg RTC_FLAG_WUTF: WakeUp Timer flag
\r
1972 * @arg RTC_FLAG_ALRBF: Alarm B flag
\r
1973 * @arg RTC_FLAG_ALRAF: Alarm A flag
\r
1974 * @arg RTC_FLAG_INITF: Initialization mode flag
\r
1975 * @arg RTC_FLAG_RSF: Registers Synchronized flag
\r
1976 * @arg RTC_FLAG_INITS: Registers Configured flag
\r
1977 * @arg RTC_FLAG_WUTWF: WakeUp Timer Write flag
\r
1978 * @arg RTC_FLAG_ALRBWF: Alarm B Write flag
\r
1979 * @arg RTC_FLAG_ALRAWF: Alarm A write flag
\r
1980 * @retval The new state of RTC_FLAG (SET or RESET).
\r
1982 FlagStatus RTC_GetFlagStatus(uint32_t RTC_FLAG)
\r
1984 FlagStatus bitstatus = RESET;
\r
1985 uint32_t tmpreg = 0;
\r
1987 /* Check the parameters */
\r
1988 assert_param(IS_RTC_GET_FLAG(RTC_FLAG));
\r
1990 /* Get all the flags */
\r
1991 tmpreg = (uint32_t)(RTC->ISR & RTC_FLAGS_MASK);
\r
1993 /* Return the status of the flag */
\r
1994 if ((tmpreg & RTC_FLAG) != (uint32_t)RESET)
\r
2000 bitstatus = RESET;
\r
2006 * @brief Clears the RTC's pending flags.
\r
2007 * @param RTC_FLAG: specifies the RTC flag to clear.
\r
2008 * This parameter can be any combination of the following values:
\r
2009 * @arg RTC_FLAG_TAMP1F: Tamper 1 event flag
\r
2010 * @arg RTC_FLAG_TSOVF: Time Stamp Overflow flag
\r
2011 * @arg RTC_FLAG_TSF: Time Stamp event flag
\r
2012 * @arg RTC_FLAG_WUTF: WakeUp Timer flag
\r
2013 * @arg RTC_FLAG_ALRBF: Alarm B flag
\r
2014 * @arg RTC_FLAG_ALRAF: Alarm A flag
\r
2015 * @arg RTC_FLAG_RSF: Registers Synchronized flag
\r
2018 void RTC_ClearFlag(uint32_t RTC_FLAG)
\r
2020 /* Check the parameters */
\r
2021 assert_param(IS_RTC_CLEAR_FLAG(RTC_FLAG));
\r
2023 /* Clear the Flags in the RTC_ISR register */
\r
2024 RTC->ISR = (uint32_t)((uint32_t)(~((RTC_FLAG | RTC_ISR_INIT)& 0x0000FFFF) | (uint32_t)(RTC->ISR & RTC_ISR_INIT)));
\r
2028 * @brief Checks whether the specified RTC interrupt has occurred or not.
\r
2029 * @param RTC_IT: specifies the RTC interrupt source to check.
\r
2030 * This parameter can be one of the following values:
\r
2031 * @arg RTC_IT_TS: Time Stamp interrupt
\r
2032 * @arg RTC_IT_WUT: WakeUp Timer interrupt
\r
2033 * @arg RTC_IT_ALRB: Alarm B interrupt
\r
2034 * @arg RTC_IT_ALRA: Alarm A interrupt
\r
2035 * @arg RTC_IT_TAMP1: Tamper 1 event interrupt
\r
2036 * @retval The new state of RTC_IT (SET or RESET).
\r
2038 ITStatus RTC_GetITStatus(uint32_t RTC_IT)
\r
2040 ITStatus bitstatus = RESET;
\r
2041 uint32_t tmpreg = 0, enablestatus = 0;
\r
2043 /* Check the parameters */
\r
2044 assert_param(IS_RTC_GET_IT(RTC_IT));
\r
2046 /* Get the TAMPER Interrupt enable bit and pending bit */
\r
2047 tmpreg = (uint32_t)(RTC->TAFCR & (RTC_TAFCR_TAMPIE));
\r
2049 /* Get the Interrupt enable Status */
\r
2050 enablestatus = (uint32_t)((RTC->CR & RTC_IT) | (tmpreg & (RTC_IT >> 15)));
\r
2052 /* Get the Interrupt pending bit */
\r
2053 tmpreg = (uint32_t)((RTC->ISR & (uint32_t)(RTC_IT >> 4)));
\r
2055 /* Get the status of the Interrupt */
\r
2056 if ((enablestatus != (uint32_t)RESET) && ((tmpreg & 0x0000FFFF) != (uint32_t)RESET))
\r
2062 bitstatus = RESET;
\r
2068 * @brief Clears the RTC's interrupt pending bits.
\r
2069 * @param RTC_IT: specifies the RTC interrupt pending bit to clear.
\r
2070 * This parameter can be any combination of the following values:
\r
2071 * @arg RTC_IT_TS: Time Stamp interrupt
\r
2072 * @arg RTC_IT_WUT: WakeUp Timer interrupt
\r
2073 * @arg RTC_IT_ALRB: Alarm B interrupt
\r
2074 * @arg RTC_IT_ALRA: Alarm A interrupt
\r
2075 * @arg RTC_IT_TAMP1: Tamper 1 event interrupt
\r
2078 void RTC_ClearITPendingBit(uint32_t RTC_IT)
\r
2080 uint32_t tmpreg = 0;
\r
2082 /* Check the parameters */
\r
2083 assert_param(IS_RTC_CLEAR_IT(RTC_IT));
\r
2085 /* Get the RTC_ISR Interrupt pending bits mask */
\r
2086 tmpreg = (uint32_t)(RTC_IT >> 4);
\r
2088 /* Clear the interrupt pending bits in the RTC_ISR register */
\r
2089 RTC->ISR = (uint32_t)((uint32_t)(~((tmpreg | RTC_ISR_INIT)& 0x0000FFFF) | (uint32_t)(RTC->ISR & RTC_ISR_INIT)));
\r
2097 * @brief Converts a 2 digit decimal to BCD format.
\r
2098 * @param Value: Byte to be converted.
\r
2099 * @retval Converted byte
\r
2101 static uint8_t RTC_ByteToBcd2(uint8_t Value)
\r
2103 uint8_t bcdhigh = 0;
\r
2105 while (Value >= 10)
\r
2111 return ((uint8_t)(bcdhigh << 4) | Value);
\r
2115 * @brief Convert from 2 digit BCD to Binary.
\r
2116 * @param Value: BCD value to be converted.
\r
2117 * @retval Converted word
\r
2119 static uint8_t RTC_Bcd2ToByte(uint8_t Value)
\r
2122 tmp = ((uint8_t)(Value & (uint8_t)0xF0) >> (uint8_t)0x4) * 10;
\r
2123 return (tmp + (Value & (uint8_t)0x0F));
\r
2138 /******************* (C) COPYRIGHT 2010 STMicroelectronics *****END OF FILE****/
\r