Merge pull request #11189 from klutvott123/move-telemetry-displayport-init
[betaflight.git] / lib / main / STM32F3 / Drivers / STM32F3xx_HAL_Driver / Inc / stm32f3xx_hal_rtc.h
blobc909e94c3992d62243699dd6253a75879cb0807f
1 /**
2 ******************************************************************************
3 * @file stm32f3xx_hal_rtc.h
4 * @author MCD Application Team
5 * @brief Header file of RTC HAL module.
6 ******************************************************************************
7 * @attention
9 * <h2><center>&copy; COPYRIGHT(c) 2016 STMicroelectronics</center></h2>
11 * Redistribution and use in source and binary forms, with or without modification,
12 * are permitted provided that the following conditions are met:
13 * 1. Redistributions of source code must retain the above copyright notice,
14 * this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright notice,
16 * this list of conditions and the following disclaimer in the documentation
17 * and/or other materials provided with the distribution.
18 * 3. Neither the name of STMicroelectronics nor the names of its contributors
19 * may be used to endorse or promote products derived from this software
20 * without specific prior written permission.
22 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
23 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
25 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
26 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
28 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
30 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 ******************************************************************************
36 /* Define to prevent recursive inclusion -------------------------------------*/
37 #ifndef __STM32F3xx_HAL_RTC_H
38 #define __STM32F3xx_HAL_RTC_H
40 #ifdef __cplusplus
41 extern "C" {
42 #endif
44 /* Includes ------------------------------------------------------------------*/
45 #include "stm32f3xx_hal_def.h"
47 /** @addtogroup STM32F3xx_HAL_Driver
48 * @{
51 /** @defgroup RTC RTC
52 * @{
55 /* Exported types ------------------------------------------------------------*/
56 /** @defgroup RTC_Exported_Types RTC Exported Types
57 * @{
60 /**
61 * @brief HAL State structures definition
63 typedef enum
65 HAL_RTC_STATE_RESET = 0x00U, /*!< RTC not yet initialized or disabled */
66 HAL_RTC_STATE_READY = 0x01U, /*!< RTC initialized and ready for use */
67 HAL_RTC_STATE_BUSY = 0x02U, /*!< RTC process is ongoing */
68 HAL_RTC_STATE_TIMEOUT = 0x03U, /*!< RTC timeout state */
69 HAL_RTC_STATE_ERROR = 0x04U /*!< RTC error state */
71 }HAL_RTCStateTypeDef;
73 /**
74 * @brief RTC Configuration Structure definition
76 typedef struct
78 uint32_t HourFormat; /*!< Specifies the RTC Hour Format.
79 This parameter can be a value of @ref RTC_Hour_Formats */
81 uint32_t AsynchPrediv; /*!< Specifies the RTC Asynchronous Predivider value.
82 This parameter must be a number between Min_Data = 0x00 and Max_Data = 0x7F */
84 uint32_t SynchPrediv; /*!< Specifies the RTC Synchronous Predivider value.
85 This parameter must be a number between Min_Data = 0x00 and Max_Data = 0x7FFF */
87 uint32_t OutPut; /*!< Specifies which signal will be routed to the RTC output.
88 This parameter can be a value of @ref RTCEx_Output_selection_Definitions */
90 uint32_t OutPutPolarity; /*!< Specifies the polarity of the output signal.
91 This parameter can be a value of @ref RTC_Output_Polarity_Definitions */
93 uint32_t OutPutType; /*!< Specifies the RTC Output Pin mode.
94 This parameter can be a value of @ref RTC_Output_Type_ALARM_OUT */
95 }RTC_InitTypeDef;
97 /**
98 * @brief RTC Time structure definition
100 typedef struct
102 uint8_t Hours; /*!< Specifies the RTC Time Hour.
103 This parameter must be a number between Min_Data = 0 and Max_Data = 12 if the RTC_HourFormat_12 is selected.
104 This parameter must be a number between Min_Data = 0 and Max_Data = 23 if the RTC_HourFormat_24 is selected */
106 uint8_t Minutes; /*!< Specifies the RTC Time Minutes.
107 This parameter must be a number between Min_Data = 0 and Max_Data = 59 */
109 uint8_t Seconds; /*!< Specifies the RTC Time Seconds.
110 This parameter must be a number between Min_Data = 0 and Max_Data = 59 */
112 uint8_t TimeFormat; /*!< Specifies the RTC AM/PM Time.
113 This parameter can be a value of @ref RTC_AM_PM_Definitions */
115 uint32_t SubSeconds; /*!< Specifies the RTC_SSR RTC Sub Second register content.
116 This parameter corresponds to a time unit range between [0-1] Second
117 with [1 Sec / SecondFraction +1] granularity */
119 uint32_t SecondFraction; /*!< Specifies the range or granularity of Sub Second register content
120 corresponding to Synchronous pre-scaler factor value (PREDIV_S)
121 This parameter corresponds to a time unit range between [0-1] Second
122 with [1 Sec / SecondFraction +1] granularity.
123 This field will be used only by HAL_RTC_GetTime function */
125 uint32_t DayLightSaving; /*!< Specifies RTC_DayLightSaveOperation: the value of hour adjustment.
126 This parameter can be a value of @ref RTC_DayLightSaving_Definitions */
128 uint32_t StoreOperation; /*!< Specifies RTC_StoreOperation value to be written in the BCK bit
129 in CR register to store the operation.
130 This parameter can be a value of @ref RTC_StoreOperation_Definitions */
131 }RTC_TimeTypeDef;
133 /**
134 * @brief RTC Date structure definition
136 typedef struct
138 uint8_t WeekDay; /*!< Specifies the RTC Date WeekDay.
139 This parameter can be a value of @ref RTC_WeekDay_Definitions */
141 uint8_t Month; /*!< Specifies the RTC Date Month (in BCD format).
142 This parameter can be a value of @ref RTC_Month_Date_Definitions */
144 uint8_t Date; /*!< Specifies the RTC Date.
145 This parameter must be a number between Min_Data = 1 and Max_Data = 31 */
147 uint8_t Year; /*!< Specifies the RTC Date Year.
148 This parameter must be a number between Min_Data = 0 and Max_Data = 99 */
150 }RTC_DateTypeDef;
152 /**
153 * @brief RTC Alarm structure definition
155 typedef struct
157 RTC_TimeTypeDef AlarmTime; /*!< Specifies the RTC Alarm Time members */
159 uint32_t AlarmMask; /*!< Specifies the RTC Alarm Masks.
160 This parameter can be a value of @ref RTC_AlarmMask_Definitions */
162 uint32_t AlarmSubSecondMask; /*!< Specifies the RTC Alarm SubSeconds Masks.
163 This parameter can be a value of @ref RTC_Alarm_Sub_Seconds_Masks_Definitions */
165 uint32_t AlarmDateWeekDaySel; /*!< Specifies the RTC Alarm is on Date or WeekDay.
166 This parameter can be a value of @ref RTC_AlarmDateWeekDay_Definitions */
168 uint8_t AlarmDateWeekDay; /*!< Specifies the RTC Alarm Date/WeekDay.
169 If the Alarm Date is selected, this parameter must be set to a value in the 1-31 range.
170 If the Alarm WeekDay is selected, this parameter can be a value of @ref RTC_WeekDay_Definitions */
172 uint32_t Alarm; /*!< Specifies the alarm .
173 This parameter can be a value of @ref RTC_Alarms_Definitions */
174 }RTC_AlarmTypeDef;
176 /**
177 * @brief RTC Handle Structure definition
179 typedef struct
181 RTC_TypeDef *Instance; /*!< Register base address */
183 RTC_InitTypeDef Init; /*!< RTC required parameters */
185 HAL_LockTypeDef Lock; /*!< RTC locking object */
187 __IO HAL_RTCStateTypeDef State; /*!< Time communication state */
189 }RTC_HandleTypeDef;
191 * @}
194 /* Exported constants --------------------------------------------------------*/
195 /** @defgroup RTC_Exported_Constants RTC Exported Constants
196 * @{
199 /** @defgroup RTC_Hour_Formats RTC Hour Formats
200 * @{
202 #define RTC_HOURFORMAT_24 0x00000000U
203 #define RTC_HOURFORMAT_12 RTC_CR_FMT
205 * @}
208 /** @defgroup RTC_Output_Polarity_Definitions RTC Output Polarity Definitions
209 * @{
211 #define RTC_OUTPUT_POLARITY_HIGH 0x00000000U
212 #define RTC_OUTPUT_POLARITY_LOW RTC_CR_POL
214 * @}
217 /** @defgroup RTC_Output_Type_ALARM_OUT RTC Output Type ALARM OUT
218 * @{
220 #define RTC_OUTPUT_TYPE_OPENDRAIN 0x00000000U
221 #define RTC_OUTPUT_TYPE_PUSHPULL RTC_TAFCR_ALARMOUTTYPE
223 * @}
226 /** @defgroup RTC_AM_PM_Definitions RTC AM PM Definitions
227 * @{
229 #define RTC_HOURFORMAT12_AM ((uint8_t)0x00)
230 #define RTC_HOURFORMAT12_PM ((uint8_t)0x40)
232 * @}
235 /** @defgroup RTC_DayLightSaving_Definitions RTC DayLightSaving Definitions
236 * @{
238 #define RTC_DAYLIGHTSAVING_NONE 0x00000000U
239 #define RTC_DAYLIGHTSAVING_SUB1H RTC_CR_SUB1H
240 #define RTC_DAYLIGHTSAVING_ADD1H RTC_CR_ADD1H
242 * @}
245 /** @defgroup RTC_StoreOperation_Definitions RTC StoreOperation Definitions
246 * @{
248 #define RTC_STOREOPERATION_RESET 0x00000000U
249 #define RTC_STOREOPERATION_SET RTC_CR_BCK
251 * @}
254 /** @defgroup RTC_Input_parameter_format_definitions RTC Input parameter format definitions
255 * @{
257 #define RTC_FORMAT_BIN 0x000000000U
258 #define RTC_FORMAT_BCD 0x000000001U
260 * @}
263 /** @defgroup RTC_Month_Date_Definitions RTC Month Date Definitions
264 * @{
266 /* Coded in BCD format */
267 #define RTC_MONTH_JANUARY ((uint8_t)0x01)
268 #define RTC_MONTH_FEBRUARY ((uint8_t)0x02)
269 #define RTC_MONTH_MARCH ((uint8_t)0x03)
270 #define RTC_MONTH_APRIL ((uint8_t)0x04)
271 #define RTC_MONTH_MAY ((uint8_t)0x05)
272 #define RTC_MONTH_JUNE ((uint8_t)0x06)
273 #define RTC_MONTH_JULY ((uint8_t)0x07)
274 #define RTC_MONTH_AUGUST ((uint8_t)0x08)
275 #define RTC_MONTH_SEPTEMBER ((uint8_t)0x09)
276 #define RTC_MONTH_OCTOBER ((uint8_t)0x10)
277 #define RTC_MONTH_NOVEMBER ((uint8_t)0x11)
278 #define RTC_MONTH_DECEMBER ((uint8_t)0x12)
280 * @}
283 /** @defgroup RTC_WeekDay_Definitions RTC WeekDay Definitions
284 * @{
286 #define RTC_WEEKDAY_MONDAY ((uint8_t)0x01)
287 #define RTC_WEEKDAY_TUESDAY ((uint8_t)0x02)
288 #define RTC_WEEKDAY_WEDNESDAY ((uint8_t)0x03)
289 #define RTC_WEEKDAY_THURSDAY ((uint8_t)0x04)
290 #define RTC_WEEKDAY_FRIDAY ((uint8_t)0x05)
291 #define RTC_WEEKDAY_SATURDAY ((uint8_t)0x06)
292 #define RTC_WEEKDAY_SUNDAY ((uint8_t)0x07)
294 * @}
297 /** @defgroup RTC_AlarmDateWeekDay_Definitions RTC AlarmDateWeekDay Definitions
298 * @{
300 #define RTC_ALARMDATEWEEKDAYSEL_DATE 0x00000000U
301 #define RTC_ALARMDATEWEEKDAYSEL_WEEKDAY RTC_ALRMAR_WDSEL
303 * @}
306 /** @defgroup RTC_AlarmMask_Definitions RTC AlarmMask Definitions
307 * @{
309 #define RTC_ALARMMASK_NONE 0x00000000U
310 #define RTC_ALARMMASK_DATEWEEKDAY RTC_ALRMAR_MSK4
311 #define RTC_ALARMMASK_HOURS RTC_ALRMAR_MSK3
312 #define RTC_ALARMMASK_MINUTES RTC_ALRMAR_MSK2
313 #define RTC_ALARMMASK_SECONDS RTC_ALRMAR_MSK1
314 #define RTC_ALARMMASK_ALL (RTC_ALARMMASK_NONE | \
315 RTC_ALARMMASK_DATEWEEKDAY | \
316 RTC_ALARMMASK_HOURS | \
317 RTC_ALARMMASK_MINUTES | \
318 RTC_ALARMMASK_SECONDS)
320 * @}
323 /** @defgroup RTC_Alarms_Definitions RTC Alarms Definitions
324 * @{
326 #define RTC_ALARM_A RTC_CR_ALRAE
327 #define RTC_ALARM_B RTC_CR_ALRBE
329 * @}
332 /** @defgroup RTC_Alarm_Sub_Seconds_Masks_Definitions RTC Alarm Sub Seconds Masks Definitions
333 * @{
335 #define RTC_ALARMSUBSECONDMASK_ALL 0x00000000U /*!< All Alarm SS fields are masked.
336 There is no comparison on sub seconds
337 for Alarm */
338 #define RTC_ALARMSUBSECONDMASK_SS14_1 RTC_ALRMASSR_MASKSS_0 /*!< SS[14:1] are ignored in Alarm
339 comparison. Only SS[0] is compared. */
340 #define RTC_ALARMSUBSECONDMASK_SS14_2 RTC_ALRMASSR_MASKSS_1 /*!< SS[14:2] are ignored in Alarm
341 comparison. Only SS[1:0] are compared */
342 #define RTC_ALARMSUBSECONDMASK_SS14_3 (RTC_ALRMASSR_MASKSS_0 | RTC_ALRMASSR_MASKSS_1) /*!< SS[14:3] are ignored in Alarm
343 comparison. Only SS[2:0] are compared */
344 #define RTC_ALARMSUBSECONDMASK_SS14_4 RTC_ALRMASSR_MASKSS_2 /*!< SS[14:4] are ignored in Alarm
345 comparison. Only SS[3:0] are compared */
346 #define RTC_ALARMSUBSECONDMASK_SS14_5 (RTC_ALRMASSR_MASKSS_0 | RTC_ALRMASSR_MASKSS_2) /*!< SS[14:5] are ignored in Alarm
347 comparison. Only SS[4:0] are compared */
348 #define RTC_ALARMSUBSECONDMASK_SS14_6 (RTC_ALRMASSR_MASKSS_1 | RTC_ALRMASSR_MASKSS_2) /*!< SS[14:6] are ignored in Alarm
349 comparison. Only SS[5:0] are compared */
350 #define RTC_ALARMSUBSECONDMASK_SS14_7 (RTC_ALRMASSR_MASKSS_0 | RTC_ALRMASSR_MASKSS_1 | RTC_ALRMASSR_MASKSS_2) /*!< SS[14:7] are ignored in Alarm
351 comparison. Only SS[6:0] are compared */
352 #define RTC_ALARMSUBSECONDMASK_SS14_8 RTC_ALRMASSR_MASKSS_3 /*!< SS[14:8] are ignored in Alarm
353 comparison. Only SS[7:0] are compared */
354 #define RTC_ALARMSUBSECONDMASK_SS14_9 (RTC_ALRMASSR_MASKSS_0 | RTC_ALRMASSR_MASKSS_3) /*!< SS[14:9] are ignored in Alarm
355 comparison. Only SS[8:0] are compared */
356 #define RTC_ALARMSUBSECONDMASK_SS14_10 (RTC_ALRMASSR_MASKSS_1 | RTC_ALRMASSR_MASKSS_3) /*!< SS[14:10] are ignored in Alarm
357 comparison. Only SS[9:0] are compared */
358 #define RTC_ALARMSUBSECONDMASK_SS14_11 (RTC_ALRMASSR_MASKSS_0 | RTC_ALRMASSR_MASKSS_1 | RTC_ALRMASSR_MASKSS_3) /*!< SS[14:11] are ignored in Alarm
359 comparison. Only SS[10:0] are compared */
360 #define RTC_ALARMSUBSECONDMASK_SS14_12 (RTC_ALRMASSR_MASKSS_2 | RTC_ALRMASSR_MASKSS_3) /*!< SS[14:12] are ignored in Alarm
361 comparison.Only SS[11:0] are compared */
362 #define RTC_ALARMSUBSECONDMASK_SS14_13 (RTC_ALRMASSR_MASKSS_0 | RTC_ALRMASSR_MASKSS_2 | RTC_ALRMASSR_MASKSS_3) /*!< SS[14:13] are ignored in Alarm
363 comparison. Only SS[12:0] are compared */
364 #define RTC_ALARMSUBSECONDMASK_SS14 (RTC_ALRMASSR_MASKSS_1 | RTC_ALRMASSR_MASKSS_2 | RTC_ALRMASSR_MASKSS_3) /*!< SS[14] is don't care in Alarm
365 comparison.Only SS[13:0] are compared */
366 #define RTC_ALARMSUBSECONDMASK_NONE RTC_ALRMASSR_MASKSS /*!< SS[14:0] are compared and must match
367 to activate alarm. */
369 * @}
372 /** @defgroup RTC_Interrupts_Definitions RTC Interrupts Definitions
373 * @{
375 #define RTC_IT_TS RTC_CR_TSIE
376 #define RTC_IT_WUT RTC_CR_WUTIE
377 #define RTC_IT_ALRB RTC_CR_ALRBIE
378 #define RTC_IT_ALRA RTC_CR_ALRAIE
379 #define RTC_IT_TAMP RTC_TAFCR_TAMPIE /* Used only to Enable the Tamper Interrupt */
380 #define RTC_IT_TAMP1 0x00020000U /*only for RTC_ISR flag check*/
381 #define RTC_IT_TAMP2 0x00040000U /*only for RTC_ISR flag check*/
382 #if defined(RTC_TAMPER3_SUPPORT)
383 #define RTC_IT_TAMP3 0x00080000U /*only for RTC_ISR flag check*/
384 #endif /* RTC_TAMPER3_SUPPORT */
386 * @}
389 /** @defgroup RTC_Flags_Definitions RTC Flags Definitions
390 * @{
392 #define RTC_FLAG_RECALPF RTC_ISR_RECALPF
393 #if defined(RTC_TAMPER3_SUPPORT)
394 #define RTC_FLAG_TAMP3F RTC_ISR_TAMP3F
395 #endif /* RTC_TAMPER3_SUPPORT */
396 #define RTC_FLAG_TAMP2F RTC_ISR_TAMP2F
397 #define RTC_FLAG_TAMP1F RTC_ISR_TAMP1F
398 #define RTC_FLAG_TSOVF RTC_ISR_TSOVF
399 #define RTC_FLAG_TSF RTC_ISR_TSF
400 #define RTC_FLAG_WUTF RTC_ISR_WUTF
401 #define RTC_FLAG_ALRBF RTC_ISR_ALRBF
402 #define RTC_FLAG_ALRAF RTC_ISR_ALRAF
403 #define RTC_FLAG_INITF RTC_ISR_INITF
404 #define RTC_FLAG_RSF RTC_ISR_RSF
405 #define RTC_FLAG_INITS RTC_ISR_INITS
406 #define RTC_FLAG_SHPF RTC_ISR_SHPF
407 #define RTC_FLAG_WUTWF RTC_ISR_WUTWF
408 #define RTC_FLAG_ALRBWF RTC_ISR_ALRBWF
409 #define RTC_FLAG_ALRAWF RTC_ISR_ALRAWF
411 * @}
415 * @}
418 /* Exported macros -----------------------------------------------------------*/
419 /** @defgroup RTC_Exported_Macros RTC Exported Macros
420 * @{
423 /** @brief Reset RTC handle state
424 * @param __HANDLE__ RTC handle.
425 * @retval None
427 #define __HAL_RTC_RESET_HANDLE_STATE(__HANDLE__) ((__HANDLE__)->State = HAL_RTC_STATE_RESET)
430 * @brief Disable the write protection for RTC registers.
431 * @param __HANDLE__ specifies the RTC handle.
432 * @retval None
434 #define __HAL_RTC_WRITEPROTECTION_DISABLE(__HANDLE__) \
435 do{ \
436 (__HANDLE__)->Instance->WPR = 0xCAU; \
437 (__HANDLE__)->Instance->WPR = 0x53U; \
438 } while(0U)
441 * @brief Enable the write protection for RTC registers.
442 * @param __HANDLE__ specifies the RTC handle.
443 * @retval None
445 #define __HAL_RTC_WRITEPROTECTION_ENABLE(__HANDLE__) \
446 do{ \
447 (__HANDLE__)->Instance->WPR = 0xFFU; \
448 } while(0U)
451 * @brief Enable the RTC ALARMA peripheral.
452 * @param __HANDLE__ specifies the RTC handle.
453 * @retval None
455 #define __HAL_RTC_ALARMA_ENABLE(__HANDLE__) ((__HANDLE__)->Instance->CR |= (RTC_CR_ALRAE))
458 * @brief Disable the RTC ALARMA peripheral.
459 * @param __HANDLE__ specifies the RTC handle.
460 * @retval None
462 #define __HAL_RTC_ALARMA_DISABLE(__HANDLE__) ((__HANDLE__)->Instance->CR &= ~(RTC_CR_ALRAE))
465 * @brief Enable the RTC ALARMB peripheral.
466 * @param __HANDLE__ specifies the RTC handle.
467 * @retval None
469 #define __HAL_RTC_ALARMB_ENABLE(__HANDLE__) ((__HANDLE__)->Instance->CR |= (RTC_CR_ALRBE))
472 * @brief Disable the RTC ALARMB peripheral.
473 * @param __HANDLE__ specifies the RTC handle.
474 * @retval None
476 #define __HAL_RTC_ALARMB_DISABLE(__HANDLE__) ((__HANDLE__)->Instance->CR &= ~(RTC_CR_ALRBE))
479 * @brief Enable the RTC Alarm interrupt.
480 * @param __HANDLE__ specifies the RTC handle.
481 * @param __INTERRUPT__ specifies the RTC Alarm interrupt sources to be enabled or disabled.
482 * This parameter can be any combination of the following values:
483 * @arg RTC_IT_ALRA: Alarm A interrupt
484 * @arg RTC_IT_ALRB: Alarm B interrupt
485 * @retval None
487 #define __HAL_RTC_ALARM_ENABLE_IT(__HANDLE__, __INTERRUPT__) ((__HANDLE__)->Instance->CR |= (__INTERRUPT__))
490 * @brief Disable the RTC Alarm interrupt.
491 * @param __HANDLE__ specifies the RTC handle.
492 * @param __INTERRUPT__ specifies the RTC Alarm interrupt sources to be enabled or disabled.
493 * This parameter can be any combination of the following values:
494 * @arg RTC_IT_ALRA: Alarm A interrupt
495 * @arg RTC_IT_ALRB: Alarm B interrupt
496 * @retval None
498 #define __HAL_RTC_ALARM_DISABLE_IT(__HANDLE__, __INTERRUPT__) ((__HANDLE__)->Instance->CR &= ~(__INTERRUPT__))
501 * @brief Check whether the specified RTC Alarm interrupt has occurred or not.
502 * @param __HANDLE__ specifies the RTC handle.
503 * @param __INTERRUPT__ specifies the RTC Alarm interrupt to check.
504 * This parameter can be:
505 * @arg RTC_IT_ALRA: Alarm A interrupt
506 * @arg RTC_IT_ALRB: Alarm B interrupt
507 * @retval None
509 #define __HAL_RTC_ALARM_GET_IT(__HANDLE__, __INTERRUPT__) (((((__HANDLE__)->Instance->ISR)& ((__INTERRUPT__)>> 4U)) != RESET)? SET : RESET)
512 * @brief Check whether the specified RTC Alarm interrupt has been enabled or not.
513 * @param __HANDLE__ specifies the RTC handle.
514 * @param __INTERRUPT__ specifies the RTC Alarm interrupt sources to check.
515 * This parameter can be:
516 * @arg RTC_IT_ALRA: Alarm A interrupt
517 * @arg RTC_IT_ALRB: Alarm B interrupt
518 * @retval None
520 #define __HAL_RTC_ALARM_GET_IT_SOURCE(__HANDLE__, __INTERRUPT__) (((((__HANDLE__)->Instance->CR) & (__INTERRUPT__)) != RESET) ? SET : RESET)
523 * @brief Get the selected RTC Alarm's flag status.
524 * @param __HANDLE__ specifies the RTC handle.
525 * @param __FLAG__ specifies the RTC Alarm Flag sources to check.
526 * This parameter can be:
527 * @arg RTC_FLAG_ALRAF
528 * @arg RTC_FLAG_ALRBF
529 * @arg RTC_FLAG_ALRAWF
530 * @arg RTC_FLAG_ALRBWF
531 * @retval None
533 #define __HAL_RTC_ALARM_GET_FLAG(__HANDLE__, __FLAG__) (((((__HANDLE__)->Instance->ISR) & (__FLAG__)) != RESET)? SET : RESET)
536 * @brief Clear the RTC Alarm's pending flags.
537 * @param __HANDLE__ specifies the RTC handle.
538 * @param __FLAG__ specifies the RTC Alarm Flag sources to clear.
539 * This parameter can be:
540 * @arg RTC_FLAG_ALRAF
541 * @arg RTC_FLAG_ALRBF
542 * @retval None
544 #define __HAL_RTC_ALARM_CLEAR_FLAG(__HANDLE__, __FLAG__) ((__HANDLE__)->Instance->ISR) = (~((__FLAG__) | RTC_ISR_INIT) | ((__HANDLE__)->Instance->ISR & RTC_ISR_INIT))
547 * @brief Enable interrupt on the RTC Alarm associated Exti line.
548 * @retval None
550 #define __HAL_RTC_ALARM_EXTI_ENABLE_IT() (EXTI->IMR |= RTC_EXTI_LINE_ALARM_EVENT)
553 * @brief Disable interrupt on the RTC Alarm associated Exti line.
554 * @retval None
556 #define __HAL_RTC_ALARM_EXTI_DISABLE_IT() (EXTI->IMR &= ~(RTC_EXTI_LINE_ALARM_EVENT))
559 * @brief Enable event on the RTC Alarm associated Exti line.
560 * @retval None.
562 #define __HAL_RTC_ALARM_EXTI_ENABLE_EVENT() (EXTI->EMR |= RTC_EXTI_LINE_ALARM_EVENT)
565 * @brief Disable event on the RTC Alarm associated Exti line.
566 * @retval None.
568 #define __HAL_RTC_ALARM_EXTI_DISABLE_EVENT() (EXTI->EMR &= ~(RTC_EXTI_LINE_ALARM_EVENT))
571 * @brief Enable falling edge trigger on the RTC Alarm associated Exti line.
572 * @retval None.
574 #define __HAL_RTC_ALARM_EXTI_ENABLE_FALLING_EDGE() (EXTI->FTSR |= RTC_EXTI_LINE_ALARM_EVENT)
577 * @brief Disable falling edge trigger on the RTC Alarm associated Exti line.
578 * @retval None.
580 #define __HAL_RTC_ALARM_EXTI_DISABLE_FALLING_EDGE() (EXTI->FTSR &= ~(RTC_EXTI_LINE_ALARM_EVENT))
583 * @brief Enable rising edge trigger on the RTC Alarm associated Exti line.
584 * @retval None.
586 #define __HAL_RTC_ALARM_EXTI_ENABLE_RISING_EDGE() (EXTI->RTSR |= RTC_EXTI_LINE_ALARM_EVENT)
589 * @brief Disable rising edge trigger on the RTC Alarm associated Exti line.
590 * @retval None.
592 #define __HAL_RTC_ALARM_EXTI_DISABLE_RISING_EDGE() (EXTI->RTSR &= ~(RTC_EXTI_LINE_ALARM_EVENT))
595 * @brief Enable rising & falling edge trigger on the RTC Alarm associated Exti line.
596 * @retval None.
598 #define __HAL_RTC_ALARM_EXTI_ENABLE_RISING_FALLING_EDGE() __HAL_RTC_ALARM_EXTI_ENABLE_RISING_EDGE();__HAL_RTC_ALARM_EXTI_ENABLE_FALLING_EDGE();
601 * @brief Disable rising & falling edge trigger on the RTC Alarm associated Exti line.
602 * @retval None.
604 #define __HAL_RTC_ALARM_EXTI_DISABLE_RISING_FALLING_EDGE() __HAL_RTC_ALARM_EXTI_DISABLE_RISING_EDGE();__HAL_RTC_ALARM_EXTI_DISABLE_FALLING_EDGE();
607 * @brief Check whether the RTC Alarm associated Exti line interrupt flag is set or not.
608 * @retval Line Status.
610 #define __HAL_RTC_ALARM_EXTI_GET_FLAG() (EXTI->PR & RTC_EXTI_LINE_ALARM_EVENT)
613 * @brief Clear the RTC Alarm associated Exti line flag.
614 * @retval None.
616 #define __HAL_RTC_ALARM_EXTI_CLEAR_FLAG() (EXTI->PR = RTC_EXTI_LINE_ALARM_EVENT)
619 * @brief Generate a Software interrupt on RTC Alarm associated Exti line.
620 * @retval None.
622 #define __HAL_RTC_ALARM_EXTI_GENERATE_SWIT() (EXTI->SWIER |= RTC_EXTI_LINE_ALARM_EVENT)
624 * @}
627 /* Include RTC HAL Extended module */
628 #include "stm32f3xx_hal_rtc_ex.h"
630 /* Exported functions --------------------------------------------------------*/
631 /** @defgroup RTC_Exported_Functions RTC Exported Functions
632 * @{
635 /** @defgroup RTC_Exported_Functions_Group1 Initialization and de-initialization functions
636 * @{
639 /* Initialization and de-initialization functions ****************************/
640 HAL_StatusTypeDef HAL_RTC_Init(RTC_HandleTypeDef *hrtc);
641 HAL_StatusTypeDef HAL_RTC_DeInit(RTC_HandleTypeDef *hrtc);
642 void HAL_RTC_MspInit(RTC_HandleTypeDef *hrtc);
643 void HAL_RTC_MspDeInit(RTC_HandleTypeDef *hrtc);
645 * @}
648 /** @defgroup RTC_Exported_Functions_Group2 RTC Time and Date functions
649 * @{
652 /* RTC Time and Date functions ************************************************/
653 HAL_StatusTypeDef HAL_RTC_SetTime(RTC_HandleTypeDef *hrtc, RTC_TimeTypeDef *sTime, uint32_t Format);
654 HAL_StatusTypeDef HAL_RTC_GetTime(RTC_HandleTypeDef *hrtc, RTC_TimeTypeDef *sTime, uint32_t Format);
655 HAL_StatusTypeDef HAL_RTC_SetDate(RTC_HandleTypeDef *hrtc, RTC_DateTypeDef *sDate, uint32_t Format);
656 HAL_StatusTypeDef HAL_RTC_GetDate(RTC_HandleTypeDef *hrtc, RTC_DateTypeDef *sDate, uint32_t Format);
658 * @}
661 /** @defgroup RTC_Exported_Functions_Group3 RTC Alarm functions
662 * @{
664 /* RTC Alarm functions ********************************************************/
665 HAL_StatusTypeDef HAL_RTC_SetAlarm(RTC_HandleTypeDef *hrtc, RTC_AlarmTypeDef *sAlarm, uint32_t Format);
666 HAL_StatusTypeDef HAL_RTC_SetAlarm_IT(RTC_HandleTypeDef *hrtc, RTC_AlarmTypeDef *sAlarm, uint32_t Format);
667 HAL_StatusTypeDef HAL_RTC_DeactivateAlarm(RTC_HandleTypeDef *hrtc, uint32_t Alarm);
668 HAL_StatusTypeDef HAL_RTC_GetAlarm(RTC_HandleTypeDef *hrtc, RTC_AlarmTypeDef *sAlarm, uint32_t Alarm, uint32_t Format);
669 void HAL_RTC_AlarmIRQHandler(RTC_HandleTypeDef *hrtc);
670 HAL_StatusTypeDef HAL_RTC_PollForAlarmAEvent(RTC_HandleTypeDef *hrtc, uint32_t Timeout);
671 void HAL_RTC_AlarmAEventCallback(RTC_HandleTypeDef *hrtc);
673 * @}
676 /** @defgroup RTC_Exported_Functions_Group4 Peripheral Control functions
677 * @{
679 /* Peripheral Control functions ***********************************************/
680 HAL_StatusTypeDef HAL_RTC_WaitForSynchro(RTC_HandleTypeDef* hrtc);
682 * @}
685 /** @defgroup RTC_Exported_Functions_Group5 Peripheral State functions
686 * @{
688 /* Peripheral State functions *************************************************/
689 HAL_RTCStateTypeDef HAL_RTC_GetState(RTC_HandleTypeDef *hrtc);
691 * @}
695 * @}
698 /* Private types -------------------------------------------------------------*/
699 /* Private variables ---------------------------------------------------------*/
700 /* Private constants ---------------------------------------------------------*/
701 /** @defgroup RTC_Private_Constants RTC Private Constants
702 * @{
704 /* Masks Definition */
705 #define RTC_TR_RESERVED_MASK 0x007F7F7FU
706 #define RTC_DR_RESERVED_MASK 0x00FFFF3FU
707 #define RTC_INIT_MASK 0xFFFFFFFFU
708 #define RTC_RSF_MASK 0xFFFFFF5FU
709 #define RTC_FLAGS_MASK ((uint32_t) (RTC_FLAG_RECALPF | RTC_FLAG_TAMP3F | RTC_FLAG_TAMP2F | \
710 RTC_FLAG_TAMP1F| RTC_FLAG_TSOVF | RTC_FLAG_TSF | \
711 RTC_FLAG_WUTF | RTC_FLAG_ALRBF | RTC_FLAG_ALRAF | \
712 RTC_FLAG_INITF | RTC_FLAG_RSF | \
713 RTC_FLAG_INITS | RTC_FLAG_SHPF | RTC_FLAG_WUTWF | \
714 RTC_FLAG_ALRBWF | RTC_FLAG_ALRAWF))
716 #define RTC_TIMEOUT_VALUE 1000
718 #define RTC_EXTI_LINE_ALARM_EVENT EXTI_IMR_MR17 /*!< External interrupt line 17 Connected to the RTC Alarm event */
719 #define RTC_EXTI_LINE_TAMPER_TIMESTAMP_EVENT EXTI_IMR_MR19 /*!< External interrupt line 19 Connected to the RTC Tamper and Time Stamp events */
720 #define RTC_EXTI_LINE_WAKEUPTIMER_EVENT EXTI_IMR_MR20 /*!< External interrupt line 20 Connected to the RTC Wakeup event */
722 * @}
724 /* Private macros -----------------------------------------------------------*/
725 /** @defgroup RTC_Private_Macros RTC Private Macros
726 * @{
729 /** @defgroup RTC_IS_RTC_Definitions RTC Private macros to check input parameters
730 * @{
733 #define IS_RTC_HOUR_FORMAT(FORMAT) (((FORMAT) == RTC_HOURFORMAT_12) || \
734 ((FORMAT) == RTC_HOURFORMAT_24))
736 #define IS_RTC_OUTPUT_POL(POL) (((POL) == RTC_OUTPUT_POLARITY_HIGH) || \
737 ((POL) == RTC_OUTPUT_POLARITY_LOW))
739 #define IS_RTC_OUTPUT_TYPE(TYPE) (((TYPE) == RTC_OUTPUT_TYPE_OPENDRAIN) || \
740 ((TYPE) == RTC_OUTPUT_TYPE_PUSHPULL))
741 #define IS_RTC_HOUR12(HOUR) (((HOUR) > 0U) && ((HOUR) <= 12U))
742 #define IS_RTC_HOUR24(HOUR) ((HOUR) <= 23U)
743 #define IS_RTC_ASYNCH_PREDIV(PREDIV) ((PREDIV) <= 0x7FU)
744 #define IS_RTC_SYNCH_PREDIV(PREDIV) ((PREDIV) <= 0x7FFFU)
745 #define IS_RTC_MINUTES(MINUTES) ((MINUTES) <= 59U)
746 #define IS_RTC_SECONDS(SECONDS) ((SECONDS) <= 59U)
748 #define IS_RTC_HOURFORMAT12(PM) (((PM) == RTC_HOURFORMAT12_AM) || \
749 ((PM) == RTC_HOURFORMAT12_PM))
751 #define IS_RTC_DAYLIGHT_SAVING(SAVE) (((SAVE) == RTC_DAYLIGHTSAVING_SUB1H) || \
752 ((SAVE) == RTC_DAYLIGHTSAVING_ADD1H) || \
753 ((SAVE) == RTC_DAYLIGHTSAVING_NONE))
755 #define IS_RTC_STORE_OPERATION(OPERATION) (((OPERATION) == RTC_STOREOPERATION_RESET) || \
756 ((OPERATION) == RTC_STOREOPERATION_SET))
758 #define IS_RTC_FORMAT(FORMAT) (((FORMAT) == RTC_FORMAT_BIN) || ((FORMAT) == RTC_FORMAT_BCD))
760 #define IS_RTC_YEAR(YEAR) ((YEAR) <= 99U)
762 #define IS_RTC_MONTH(MONTH) (((MONTH) >= 1U) && ((MONTH) <= 12U))
764 #define IS_RTC_DATE(DATE) (((DATE) >= 1U) && ((DATE) <= 31U))
766 #define IS_RTC_WEEKDAY(WEEKDAY) (((WEEKDAY) == RTC_WEEKDAY_MONDAY) || \
767 ((WEEKDAY) == RTC_WEEKDAY_TUESDAY) || \
768 ((WEEKDAY) == RTC_WEEKDAY_WEDNESDAY) || \
769 ((WEEKDAY) == RTC_WEEKDAY_THURSDAY) || \
770 ((WEEKDAY) == RTC_WEEKDAY_FRIDAY) || \
771 ((WEEKDAY) == RTC_WEEKDAY_SATURDAY) || \
772 ((WEEKDAY) == RTC_WEEKDAY_SUNDAY))
774 #define IS_RTC_ALARM_DATE_WEEKDAY_DATE(DATE) (((DATE) > 0U) && ((DATE) <= 31U))
776 #define IS_RTC_ALARM_DATE_WEEKDAY_WEEKDAY(WEEKDAY) (((WEEKDAY) == RTC_WEEKDAY_MONDAY) || \
777 ((WEEKDAY) == RTC_WEEKDAY_TUESDAY) || \
778 ((WEEKDAY) == RTC_WEEKDAY_WEDNESDAY) || \
779 ((WEEKDAY) == RTC_WEEKDAY_THURSDAY) || \
780 ((WEEKDAY) == RTC_WEEKDAY_FRIDAY) || \
781 ((WEEKDAY) == RTC_WEEKDAY_SATURDAY) || \
782 ((WEEKDAY) == RTC_WEEKDAY_SUNDAY))
784 #define IS_RTC_ALARM_DATE_WEEKDAY_SEL(SEL) (((SEL) == RTC_ALARMDATEWEEKDAYSEL_DATE) || \
785 ((SEL) == RTC_ALARMDATEWEEKDAYSEL_WEEKDAY))
787 #define IS_RTC_ALARM_MASK(MASK) (((MASK) & 0x7F7F7F7FU) == (uint32_t)RESET)
789 #define IS_RTC_ALARM(ALARM) (((ALARM) == RTC_ALARM_A) || ((ALARM) == RTC_ALARM_B))
791 #define IS_RTC_ALARM_SUB_SECOND_VALUE(VALUE) ((VALUE) <= 0x00007FFFU)
793 #define IS_RTC_ALARM_SUB_SECOND_MASK(MASK) (((MASK) == RTC_ALARMSUBSECONDMASK_ALL) || \
794 ((MASK) == RTC_ALARMSUBSECONDMASK_SS14_1) || \
795 ((MASK) == RTC_ALARMSUBSECONDMASK_SS14_2) || \
796 ((MASK) == RTC_ALARMSUBSECONDMASK_SS14_3) || \
797 ((MASK) == RTC_ALARMSUBSECONDMASK_SS14_4) || \
798 ((MASK) == RTC_ALARMSUBSECONDMASK_SS14_5) || \
799 ((MASK) == RTC_ALARMSUBSECONDMASK_SS14_6) || \
800 ((MASK) == RTC_ALARMSUBSECONDMASK_SS14_7) || \
801 ((MASK) == RTC_ALARMSUBSECONDMASK_SS14_8) || \
802 ((MASK) == RTC_ALARMSUBSECONDMASK_SS14_9) || \
803 ((MASK) == RTC_ALARMSUBSECONDMASK_SS14_10) || \
804 ((MASK) == RTC_ALARMSUBSECONDMASK_SS14_11) || \
805 ((MASK) == RTC_ALARMSUBSECONDMASK_SS14_12) || \
806 ((MASK) == RTC_ALARMSUBSECONDMASK_SS14_13) || \
807 ((MASK) == RTC_ALARMSUBSECONDMASK_SS14) || \
808 ((MASK) == RTC_ALARMSUBSECONDMASK_NONE))
810 * @}
814 * @}
817 /* Private functions -------------------------------------------------------------*/
818 /** @defgroup RTC_Private_Functions RTC Private Functions
819 * @{
821 HAL_StatusTypeDef RTC_EnterInitMode(RTC_HandleTypeDef* hrtc);
822 uint8_t RTC_ByteToBcd2(uint8_t Value);
823 uint8_t RTC_Bcd2ToByte(uint8_t Value);
825 * @}
829 * @}
833 * @}
836 #ifdef __cplusplus
838 #endif
840 #endif /* __STM32F3xx_HAL_RTC_H */
842 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/