2 ******************************************************************************
3 * @file stm32g4xx_hal_rtc.h
4 * @author MCD Application Team
5 * @brief Header file of RTC HAL module.
6 ******************************************************************************
9 * <h2><center>© COPYRIGHT(c) 2017 STMicroelectronics</center></h2>
11 * This software component is licensed by ST under BSD 3-Clause license,
12 * the "License"; You may not use this file except in compliance with the
13 * License. You may obtain a copy of the License at:
14 * opensource.org/licenses/BSD-3-Clause
16 ******************************************************************************
19 /* Define to prevent recursive inclusion -------------------------------------*/
20 #ifndef STM32G4xx_HAL_RTC_H
21 #define STM32G4xx_HAL_RTC_H
27 /* Includes ------------------------------------------------------------------*/
28 #include "stm32g4xx_hal_def.h"
30 /** @addtogroup STM32G4xx_HAL_Driver
38 /* Exported types ------------------------------------------------------------*/
39 /** @defgroup RTC_Exported_Types RTC Exported Types
44 * @brief HAL State structures definition
48 HAL_RTC_STATE_RESET
= 0x00U
, /*!< RTC not yet initialized or disabled */
49 HAL_RTC_STATE_READY
= 0x01U
, /*!< RTC initialized and ready for use */
50 HAL_RTC_STATE_BUSY
= 0x02U
, /*!< RTC process is ongoing */
51 HAL_RTC_STATE_TIMEOUT
= 0x03U
, /*!< RTC timeout state */
52 HAL_RTC_STATE_ERROR
= 0x04U
/*!< RTC error state */
54 } HAL_RTCStateTypeDef
;
57 * @brief RTC Configuration Structure definition
61 uint32_t HourFormat
; /*!< Specifies the RTC Hour Format.
62 This parameter can be a value of @ref RTC_Hour_Formats */
64 uint32_t AsynchPrediv
; /*!< Specifies the RTC Asynchronous Predivider value.
65 This parameter must be a number between Min_Data = 0x00 and Max_Data = 0x7F */
67 uint32_t SynchPrediv
; /*!< Specifies the RTC Synchronous Predivider value.
68 This parameter must be a number between Min_Data = 0x00 and Max_Data = 0x7FFF */
70 uint32_t OutPut
; /*!< Specifies which signal will be routed to the RTC output.
71 This parameter can be a value of @ref RTCEx_Output_selection_Definitions */
73 uint32_t OutPutRemap
; /*!< Specifies the remap for RTC output.
74 This parameter can be a value of @ref RTC_Output_ALARM_OUT_Remap */
76 uint32_t OutPutPolarity
; /*!< Specifies the polarity of the output signal.
77 This parameter can be a value of @ref RTC_Output_Polarity_Definitions */
79 uint32_t OutPutType
; /*!< Specifies the RTC Output Pin mode.
80 This parameter can be a value of @ref RTC_Output_Type_ALARM_OUT */
82 uint32_t OutPutPullUp
; /*!< Specifies the RTC Output Pull-Up mode.
83 This parameter can be a value of @ref RTC_Output_PullUp_ALARM_OUT */
87 * @brief RTC Time structure definition
91 uint8_t Hours
; /*!< Specifies the RTC Time Hour.
92 This parameter must be a number between Min_Data = 0 and Max_Data = 12 if the RTC_HourFormat_12 is selected.
93 This parameter must be a number between Min_Data = 0 and Max_Data = 23 if the RTC_HourFormat_24 is selected */
95 uint8_t Minutes
; /*!< Specifies the RTC Time Minutes.
96 This parameter must be a number between Min_Data = 0 and Max_Data = 59 */
98 uint8_t Seconds
; /*!< Specifies the RTC Time Seconds.
99 This parameter must be a number between Min_Data = 0 and Max_Data = 59 */
101 uint8_t TimeFormat
; /*!< Specifies the RTC AM/PM Time.
102 This parameter can be a value of @ref RTC_AM_PM_Definitions */
104 uint32_t SubSeconds
; /*!< Specifies the RTC_SSR RTC Sub Second register content.
105 This parameter corresponds to a time unit range between [0-1] Second
106 with [1 Sec / SecondFraction +1] granularity */
108 uint32_t SecondFraction
; /*!< Specifies the range or granularity of Sub Second register content
109 corresponding to Synchronous pre-scaler factor value (PREDIV_S)
110 This parameter corresponds to a time unit range between [0-1] Second
111 with [1 Sec / SecondFraction +1] granularity.
112 This field will be used only by HAL_RTC_GetTime function */
114 uint32_t DayLightSaving
; /*!< Specifies RTC_DayLightSaveOperation: the value of hour adjustment.
115 This parameter can be a value of @ref RTC_DayLightSaving_Definitions */
117 uint32_t StoreOperation
; /*!< Specifies RTC_StoreOperation value to be written in the BKP bit
118 in CR register to store the operation.
119 This parameter can be a value of @ref RTC_StoreOperation_Definitions */
123 * @brief RTC Date structure definition
127 uint8_t WeekDay
; /*!< Specifies the RTC Date WeekDay.
128 This parameter can be a value of @ref RTC_WeekDay_Definitions */
130 uint8_t Month
; /*!< Specifies the RTC Date Month (in BCD format).
131 This parameter can be a value of @ref RTC_Month_Date_Definitions */
133 uint8_t Date
; /*!< Specifies the RTC Date.
134 This parameter must be a number between Min_Data = 1 and Max_Data = 31 */
136 uint8_t Year
; /*!< Specifies the RTC Date Year.
137 This parameter must be a number between Min_Data = 0 and Max_Data = 99 */
141 * @brief RTC Alarm structure definition
145 RTC_TimeTypeDef AlarmTime
; /*!< Specifies the RTC Alarm Time members */
147 uint32_t AlarmMask
; /*!< Specifies the RTC Alarm Masks.
148 This parameter can be a value of @ref RTC_AlarmMask_Definitions */
150 uint32_t AlarmSubSecondMask
; /*!< Specifies the RTC Alarm SubSeconds Masks.
151 This parameter can be a value of @ref RTC_Alarm_Sub_Seconds_Masks_Definitions */
153 uint32_t AlarmDateWeekDaySel
; /*!< Specifies the RTC Alarm is on Date or WeekDay.
154 This parameter can be a value of @ref RTC_AlarmDateWeekDay_Definitions */
156 uint8_t AlarmDateWeekDay
; /*!< Specifies the RTC Alarm Date/WeekDay.
157 If the Alarm Date is selected, this parameter must be set to a value in the 1-31 range.
158 If the Alarm WeekDay is selected, this parameter can be a value of @ref RTC_WeekDay_Definitions */
160 uint32_t Alarm
; /*!< Specifies the alarm .
161 This parameter can be a value of @ref RTC_Alarms_Definitions */
165 * @brief RTC Handle Structure definition
167 #if (USE_HAL_RTC_REGISTER_CALLBACKS == 1)
168 typedef struct __RTC_HandleTypeDef
171 #endif /* (USE_HAL_RTC_REGISTER_CALLBACKS) */
173 RTC_TypeDef
*Instance
; /*!< Legacy register base address. Not used anymore,
174 the driver directly uses cmsis base address */
176 RTC_InitTypeDef Init
; /*!< RTC required parameters */
178 HAL_LockTypeDef Lock
; /*!< RTC locking object */
180 __IO HAL_RTCStateTypeDef State
; /*!< Time communication state */
182 #if (USE_HAL_RTC_REGISTER_CALLBACKS == 1)
183 void (* AlarmAEventCallback
)(struct __RTC_HandleTypeDef
*hrtc
); /*!< RTC Alarm A Event callback */
184 void (* AlarmBEventCallback
)(struct __RTC_HandleTypeDef
*hrtc
); /*!< RTC Alarm B Event callback */
185 void (* TimeStampEventCallback
)(struct __RTC_HandleTypeDef
*hrtc
); /*!< RTC TimeStamp Event callback */
186 void (* WakeUpTimerEventCallback
)(struct __RTC_HandleTypeDef
*hrtc
); /*!< RTC WakeUpTimer Event callback */
188 void (* Tamper1EventCallback
)(struct __RTC_HandleTypeDef
*hrtc
); /*!< RTC Tamper 1 Event callback */
189 void (* Tamper2EventCallback
)(struct __RTC_HandleTypeDef
*hrtc
); /*!< RTC Tamper 2 Event callback */
190 #if (RTC_TAMP_NB == 3)
191 void (* Tamper3EventCallback
)(struct __RTC_HandleTypeDef
*hrtc
); /*!< RTC Tamper 3 Event callback */
192 #endif /* RTC_TAMP_NB */
193 void (* InternalTamper1EventCallback
)(struct __RTC_HandleTypeDef
*hrtc
); /*!< RTC Internal Tamper 1 Event callback */
194 #ifdef RTC_TAMP_INT_2_SUPPORT
195 void (* InternalTamper2EventCallback
)(struct __RTC_HandleTypeDef
*hrtc
); /*!< RTC Internal Tamper 2 Event callback */
196 #endif /* RTC_TAMP_INT_2_SUPPORT */
197 void (* InternalTamper3EventCallback
)(struct __RTC_HandleTypeDef
*hrtc
); /*!< RTC Internal Tamper 3 Event callback */
198 void (* InternalTamper4EventCallback
)(struct __RTC_HandleTypeDef
*hrtc
); /*!< RTC Internal Tamper 4 Event callback */
199 void (* InternalTamper5EventCallback
)(struct __RTC_HandleTypeDef
*hrtc
); /*!< RTC Internal Tamper 5 Event callback */
200 #ifdef RTC_TAMP_INT_6_SUPPORT
201 void (* InternalTamper6EventCallback
)(struct __RTC_HandleTypeDef
*hrtc
); /*!< RTC Internal Tamper 6 Event callback */
202 #endif /* RTC_TAMP_INT_6_SUPPORT */
203 #ifdef RTC_TAMP_INT_7_SUPPORT
204 void (* InternalTamper7EventCallback
)(struct __RTC_HandleTypeDef
*hrtc
); /*!< RTC Internal Tamper 7 Event callback */
205 #endif /* RTC_TAMP_INT_7_SUPPORT */
207 void (* MspInitCallback
)(struct __RTC_HandleTypeDef
*hrtc
); /*!< RTC Msp Init callback */
208 void (* MspDeInitCallback
)(struct __RTC_HandleTypeDef
*hrtc
); /*!< RTC Msp DeInit callback */
210 #endif /* (USE_HAL_RTC_REGISTER_CALLBACKS) */
214 #if (USE_HAL_RTC_REGISTER_CALLBACKS == 1)
216 * @brief HAL LPTIM Callback ID enumeration definition
220 HAL_RTC_ALARM_A_EVENT_CB_ID
= 0x00U
, /*!< RTC Alarm A Event Callback ID */
221 HAL_RTC_ALARM_B_EVENT_CB_ID
= 0x01U
, /*!< RTC Alarm B Event Callback ID */
222 HAL_RTC_TIMESTAMP_EVENT_CB_ID
= 0x02U
, /*!< RTC TimeStamp Event Callback ID */
223 HAL_RTC_WAKEUPTIMER_EVENT_CB_ID
= 0x03U
, /*!< RTC WakeUp Timer Event Callback ID */
224 HAL_RTC_TAMPER1_EVENT_CB_ID
= 0x04U
, /*!< RTC Tamper 1 Callback ID */
225 HAL_RTC_TAMPER2_EVENT_CB_ID
= 0x05U
, /*!< RTC Tamper 2 Callback ID */
226 HAL_RTC_TAMPER3_EVENT_CB_ID
= 0x06U
, /*!< RTC Tamper 3 Callback ID */
227 HAL_RTC_INTERNAL_TAMPER1_EVENT_CB_ID
= 0x07U
, /*!< RTC Internal Tamper 1 Callback ID */
228 HAL_RTC_INTERNAL_TAMPER2_EVENT_CB_ID
= 0x08U
, /*!< RTC Internal Tamper 2 Callback ID */
229 HAL_RTC_INTERNAL_TAMPER3_EVENT_CB_ID
= 0x09U
, /*!< RTC Internal Tamper 3 Callback ID */
230 HAL_RTC_INTERNAL_TAMPER4_EVENT_CB_ID
= 0x0AU
, /*!< RTC Internal Tamper 4 Callback ID */
231 HAL_RTC_INTERNAL_TAMPER5_EVENT_CB_ID
= 0x0BU
, /*!< RTC Internal Tamper 5 Callback ID */
232 HAL_RTC_INTERNAL_TAMPER6_EVENT_CB_ID
= 0x0CU
, /*!< RTC Internal Tamper 6 Callback ID */
233 HAL_RTC_INTERNAL_TAMPER7_EVENT_CB_ID
= 0x0DU
, /*!< RTC Internal Tamper 7 Callback ID */
234 HAL_RTC_MSPINIT_CB_ID
= 0x0EU
, /*!< RTC Msp Init callback ID */
235 HAL_RTC_MSPDEINIT_CB_ID
= 0x0FU
/*!< RTC Msp DeInit callback ID */
236 } HAL_RTC_CallbackIDTypeDef
;
239 * @brief HAL RTC Callback pointer definition
241 typedef void (*pRTC_CallbackTypeDef
)(RTC_HandleTypeDef
*hrtc
); /*!< pointer to an RTC callback function */
242 #endif /* USE_HAL_RTC_REGISTER_CALLBACKS */
248 /* Exported constants --------------------------------------------------------*/
249 /** @defgroup RTC_Exported_Constants RTC Exported Constants
253 /** @defgroup RTC_Hour_Formats RTC Hour Formats
256 #define RTC_HOURFORMAT_24 0x00000000U
257 #define RTC_HOURFORMAT_12 RTC_CR_FMT
262 /** @defgroup RTCEx_Output_selection_Definitions RTCEx Output Selection Definition
265 #define RTC_OUTPUT_DISABLE 0x00000000U
266 #define RTC_OUTPUT_ALARMA RTC_CR_OSEL_0
267 #define RTC_OUTPUT_ALARMB RTC_CR_OSEL_1
268 #define RTC_OUTPUT_WAKEUP RTC_CR_OSEL
269 #define RTC_OUTPUT_TAMPER RTC_CR_TAMPOE
275 /** @defgroup RTC_Output_Polarity_Definitions RTC Output Polarity Definitions
278 #define RTC_OUTPUT_POLARITY_HIGH 0x00000000U
279 #define RTC_OUTPUT_POLARITY_LOW RTC_CR_POL
284 /** @defgroup RTC_Output_Type_ALARM_OUT RTC Output Type ALARM OUT
287 #define RTC_OUTPUT_TYPE_PUSHPULL 0x00000000U
288 #define RTC_OUTPUT_TYPE_OPENDRAIN RTC_CR_TAMPALRM_TYPE
293 /** @defgroup RTC_Output_PullUp_ALARM_OUT RTC Output Pull-Up ALARM OUT
296 #define RTC_OUTPUT_PULLUP_NONE 0x00000000U
297 #define RTC_OUTPUT_PULLUP_ON RTC_CR_TAMPALRM_PU
302 /** @defgroup RTC_Output_ALARM_OUT_Remap RTC Output ALARM OUT Remap
305 #define RTC_OUTPUT_REMAP_NONE 0x00000000U
306 #define RTC_OUTPUT_REMAP_POS1 RTC_CR_OUT2EN
311 /** @defgroup RTC_AM_PM_Definitions RTC AM PM Definitions
314 #define RTC_HOURFORMAT12_AM 0x0U
315 #define RTC_HOURFORMAT12_PM 0x1U
320 /** @defgroup RTC_DayLightSaving_Definitions RTC DayLightSaving Definitions
323 #define RTC_DAYLIGHTSAVING_SUB1H RTC_CR_SUB1H
324 #define RTC_DAYLIGHTSAVING_ADD1H RTC_CR_ADD1H
325 #define RTC_DAYLIGHTSAVING_NONE 0x00000000U
330 /** @defgroup RTC_StoreOperation_Definitions RTC StoreOperation Definitions
333 #define RTC_STOREOPERATION_RESET 0x00000000U
334 #define RTC_STOREOPERATION_SET RTC_CR_BKP
339 /** @defgroup RTC_Input_parameter_format_definitions RTC Input Parameter Format Definitions
342 #define RTC_FORMAT_BIN 0x00000000U
343 #define RTC_FORMAT_BCD 0x00000001U
348 /** @defgroup RTC_Month_Date_Definitions RTC Month Date Definitions
352 /* Coded in BCD format */
353 #define RTC_MONTH_JANUARY ((uint8_t)0x01U)
354 #define RTC_MONTH_FEBRUARY ((uint8_t)0x02U)
355 #define RTC_MONTH_MARCH ((uint8_t)0x03U)
356 #define RTC_MONTH_APRIL ((uint8_t)0x04U)
357 #define RTC_MONTH_MAY ((uint8_t)0x05U)
358 #define RTC_MONTH_JUNE ((uint8_t)0x06U)
359 #define RTC_MONTH_JULY ((uint8_t)0x07U)
360 #define RTC_MONTH_AUGUST ((uint8_t)0x08U)
361 #define RTC_MONTH_SEPTEMBER ((uint8_t)0x09U)
362 #define RTC_MONTH_OCTOBER ((uint8_t)0x10U)
363 #define RTC_MONTH_NOVEMBER ((uint8_t)0x11U)
364 #define RTC_MONTH_DECEMBER ((uint8_t)0x12U)
370 /** @defgroup RTC_WeekDay_Definitions RTC WeekDay Definitions
373 #define RTC_WEEKDAY_MONDAY ((uint8_t)0x01U)
374 #define RTC_WEEKDAY_TUESDAY ((uint8_t)0x02U)
375 #define RTC_WEEKDAY_WEDNESDAY ((uint8_t)0x03U)
376 #define RTC_WEEKDAY_THURSDAY ((uint8_t)0x04U)
377 #define RTC_WEEKDAY_FRIDAY ((uint8_t)0x05U)
378 #define RTC_WEEKDAY_SATURDAY ((uint8_t)0x06U)
379 #define RTC_WEEKDAY_SUNDAY ((uint8_t)0x07U)
385 /** @defgroup RTC_AlarmDateWeekDay_Definitions RTC AlarmDateWeekDay Definitions
388 #define RTC_ALARMDATEWEEKDAYSEL_DATE 0x00000000U
389 #define RTC_ALARMDATEWEEKDAYSEL_WEEKDAY RTC_ALRMAR_WDSEL
395 /** @defgroup RTC_AlarmMask_Definitions RTC AlarmMask Definitions
398 #define RTC_ALARMMASK_NONE 0x00000000U
399 #define RTC_ALARMMASK_DATEWEEKDAY RTC_ALRMAR_MSK4
400 #define RTC_ALARMMASK_HOURS RTC_ALRMAR_MSK3
401 #define RTC_ALARMMASK_MINUTES RTC_ALRMAR_MSK2
402 #define RTC_ALARMMASK_SECONDS RTC_ALRMAR_MSK1
403 #define RTC_ALARMMASK_ALL (RTC_ALARMMASK_DATEWEEKDAY | RTC_ALARMMASK_HOURS | \
404 RTC_ALARMMASK_MINUTES | RTC_ALARMMASK_SECONDS)
410 /** @defgroup RTC_Alarms_Definitions RTC Alarms Definitions
413 #define RTC_ALARM_A RTC_CR_ALRAE
414 #define RTC_ALARM_B RTC_CR_ALRBE
421 /** @defgroup RTC_Alarm_Sub_Seconds_Masks_Definitions RTC Alarm Sub Seconds Masks Definitions
424 #define RTC_ALARMSUBSECONDMASK_ALL 0x00000000U /*!< All Alarm SS fields are masked.
425 There is no comparison on sub seconds
427 #define RTC_ALARMSUBSECONDMASK_SS14_1 RTC_ALRMASSR_MASKSS_0 /*!< SS[14:1] not used in Alarm
428 comparison. Only SS[0] is compared. */
429 #define RTC_ALARMSUBSECONDMASK_SS14_2 RTC_ALRMASSR_MASKSS_1 /*!< SS[14:2] not used in Alarm
430 comparison. Only SS[1:0] are compared */
431 #define RTC_ALARMSUBSECONDMASK_SS14_3 (RTC_ALRMASSR_MASKSS_0 | RTC_ALRMASSR_MASKSS_1) /*!< SS[14:3] not used in Alarm
432 comparison. Only SS[2:0] are compared */
433 #define RTC_ALARMSUBSECONDMASK_SS14_4 RTC_ALRMASSR_MASKSS_2 /*!< SS[14:4] not used in Alarm
434 comparison. Only SS[3:0] are compared */
435 #define RTC_ALARMSUBSECONDMASK_SS14_5 (RTC_ALRMASSR_MASKSS_0 | RTC_ALRMASSR_MASKSS_2) /*!< SS[14:5] not used in Alarm
436 comparison. Only SS[4:0] are compared */
437 #define RTC_ALARMSUBSECONDMASK_SS14_6 (RTC_ALRMASSR_MASKSS_1 | RTC_ALRMASSR_MASKSS_2) /*!< SS[14:6] not used in Alarm
438 comparison. Only SS[5:0] are compared */
439 #define RTC_ALARMSUBSECONDMASK_SS14_7 (RTC_ALRMASSR_MASKSS_0 | RTC_ALRMASSR_MASKSS_1 | RTC_ALRMASSR_MASKSS_2) /*!< SS[14:7] not used in Alarm
440 comparison. Only SS[6:0] are compared */
441 #define RTC_ALARMSUBSECONDMASK_SS14_8 RTC_ALRMASSR_MASKSS_3 /*!< SS[14:8] not used in Alarm
442 comparison. Only SS[7:0] are compared */
443 #define RTC_ALARMSUBSECONDMASK_SS14_9 (RTC_ALRMASSR_MASKSS_0 | RTC_ALRMASSR_MASKSS_3) /*!< SS[14:9] not used in Alarm
444 comparison. Only SS[8:0] are compared */
445 #define RTC_ALARMSUBSECONDMASK_SS14_10 (RTC_ALRMASSR_MASKSS_1 | RTC_ALRMASSR_MASKSS_3) /*!< SS[14:10] not used in Alarm
446 comparison. Only SS[9:0] are compared */
447 #define RTC_ALARMSUBSECONDMASK_SS14_11 (RTC_ALRMASSR_MASKSS_0 | RTC_ALRMASSR_MASKSS_1 | RTC_ALRMASSR_MASKSS_3) /*!< SS[14:11] not used in Alarm
448 comparison. Only SS[10:0] are compared */
449 #define RTC_ALARMSUBSECONDMASK_SS14_12 (RTC_ALRMASSR_MASKSS_2 | RTC_ALRMASSR_MASKSS_3) /*!< SS[14:12] not used in Alarm
450 comparison.Only SS[11:0] are compared */
451 #define RTC_ALARMSUBSECONDMASK_SS14_13 (RTC_ALRMASSR_MASKSS_0 | RTC_ALRMASSR_MASKSS_2 | RTC_ALRMASSR_MASKSS_3) /*!< SS[14:13] not used in Alarm
452 comparison. Only SS[12:0] are compared */
453 #define RTC_ALARMSUBSECONDMASK_SS14 (RTC_ALRMASSR_MASKSS_1 | RTC_ALRMASSR_MASKSS_2 | RTC_ALRMASSR_MASKSS_3) /*!< SS[14] not used in Alarm
454 comparison. Only SS[13:0] are compared */
455 #define RTC_ALARMSUBSECONDMASK_NONE RTC_ALRMASSR_MASKSS /*!< SS[14:0] are compared and must match
456 to activate alarm. */
461 /** @defgroup RTC_Interrupts_Definitions RTC Interrupts Definitions
464 #define RTC_IT_TS RTC_CR_TSIE /*!< Enable Timestamp Interrupt */
465 #define RTC_IT_WUT RTC_CR_WUTIE /*!< Enable Wakeup timer Interrupt */
466 #define RTC_IT_ALRA RTC_CR_ALRAIE /*!< Enable Alarm A Interrupt */
467 #define RTC_IT_ALRB RTC_CR_ALRBIE /*!< Enable Alarm B Interrupt */
472 /** @defgroup RTC_Interruption_Mask RTC Interruptions Flag Mask
475 #define RTC_IT_MASK 0x001FU /*!< RTC interruptions flags mask */
480 /** @defgroup RTC_Flags_Definitions RTC Flags Definitions
481 * Elements values convention: 000000XX000YYYYYb
482 * - YYYYY : Interrupt flag position in the XX register (5bits)
483 * - XX : Interrupt status register (2bits)
484 * - 01: ICSR register
488 #define RTC_FLAG_RECALPF 0x00000110U /*!< Recalibration pending Flag */
489 #define RTC_FLAG_INITF 0x00000106U /*!< Initialization flag */
490 #define RTC_FLAG_RSF 0x00000105U /*!< Registers synchronization flag */
491 #define RTC_FLAG_INITS 0x00000104U /*!< Initialization status flag */
492 #define RTC_FLAG_SHPF 0x00000103U /*!< Shift operation pending flag */
493 #define RTC_FLAG_WUTWF 0x00000102U /*!< Wakeup timer write flag */
494 #define RTC_FLAG_ALRBWF 0x00000101U /*!< Alarm B write flag */
495 #define RTC_FLAG_ALRAWF 0x00000100U /*!< Alarm A write flag */
496 #define RTC_FLAG_ITSF 0x00000205U /*!< Clear Internal Time-stamp flag */
497 #define RTC_FLAG_TSOVF 0x00000204U /*!< Clear Time-stamp overflow flag */
498 #define RTC_FLAG_TSF 0x00000203U /*!< Clear Time-stamp flag */
499 #define RTC_FLAG_WUTF 0x00000202U /*!< Clear Wakeup timer flag */
500 #define RTC_FLAG_ALRBF 0x00000201U /*!< Clear Alarm B flag */
501 #define RTC_FLAG_ALRAF 0x00000200U /*!< Clear Alarm A flag */
506 /** @defgroup RTC_Clear_Flags_Definitions RTC Clear Flags Definitions
509 #define RTC_CLEAR_ITSF RTC_SCR_CITSF /*!< Clear Internal Time-stamp flag */
510 #define RTC_CLEAR_TSOVF RTC_SCR_CTSOVF /*!< Clear Time-stamp overflow flag */
511 #define RTC_CLEAR_TSF RTC_SCR_CTSF /*!< Clear Time-stamp flag */
512 #define RTC_CLEAR_WUTF RTC_SCR_CWUTF /*!< Clear Wakeup timer flag */
513 #define RTC_CLEAR_ALRBF RTC_SCR_CALRBF /*!< Clear Alarm B flag */
514 #define RTC_CLEAR_ALRAF RTC_SCR_CALRAF /*!< Clear Alarm A flag */
523 /* Exported macros -----------------------------------------------------------*/
524 /** @defgroup RTC_Exported_Macros RTC Exported Macros
528 /** @brief Reset RTC handle state
529 * @param __HANDLE__ RTC handle.
532 #if (USE_HAL_RTC_REGISTER_CALLBACKS == 1)
533 #define __HAL_RTC_RESET_HANDLE_STATE(__HANDLE__) do{\
534 (__HANDLE__)->State = HAL_RTC_STATE_RESET;\
535 (__HANDLE__)->MspInitCallback = NULL;\
536 (__HANDLE__)->MspDeInitCallback = NULL;\
539 #define __HAL_RTC_RESET_HANDLE_STATE(__HANDLE__) ((__HANDLE__)->State = HAL_RTC_STATE_RESET)
540 #endif /* USE_HAL_RTC_REGISTER_CALLBACKS */
543 * @brief Disable the write protection for RTC registers.
544 * @param __HANDLE__ specifies the RTC handle.
547 #define __HAL_RTC_WRITEPROTECTION_DISABLE(__HANDLE__) \
554 * @brief Enable the write protection for RTC registers.
555 * @param __HANDLE__ specifies the RTC handle.
558 #define __HAL_RTC_WRITEPROTECTION_ENABLE(__HANDLE__) \
564 * @brief Add 1 hour (summer time change).
565 * @param __HANDLE__ specifies the RTC handle.
566 * @param __BKP__ Backup
567 * This parameter can be:
568 * @arg @ref RTC_STOREOPERATION_RESET
569 * @arg @ref RTC_STOREOPERATION_SET
572 #define __HAL_RTC_DAYLIGHT_SAVING_TIME_ADD1H(__HANDLE__, __BKP__) \
574 __HAL_RTC_WRITEPROTECTION_DISABLE(__HANDLE__); \
575 SET_BIT(RTC->CR, RTC_CR_ADD1H); \
576 MODIFY_REG(RTC->CR, RTC_CR_BKP , (__BKP__)); \
577 __HAL_RTC_WRITEPROTECTION_ENABLE(__HANDLE__); \
581 * @brief Subtract 1 hour (winter time change).
582 * @param __HANDLE__ specifies the RTC handle.
583 * @param __BKP__ Backup
584 * This parameter can be:
585 * @arg @ref RTC_STOREOPERATION_RESET
586 * @arg @ref RTC_STOREOPERATION_SET
589 #define __HAL_RTC_DAYLIGHT_SAVING_TIME_SUB1H(__HANDLE__, __BKP__) \
591 __HAL_RTC_WRITEPROTECTION_DISABLE(__HANDLE__); \
592 SET_BIT(RTC->CR, RTC_CR_SUB1H); \
593 MODIFY_REG(RTC->CR, RTC_CR_BKP , (__BKP__)); \
594 __HAL_RTC_WRITEPROTECTION_ENABLE(__HANDLE__); \
598 * @brief Enable the RTC ALARMA peripheral.
599 * @param __HANDLE__ specifies the RTC handle.
602 #define __HAL_RTC_ALARMA_ENABLE(__HANDLE__) (RTC->CR |= (RTC_CR_ALRAE))
605 * @brief Disable the RTC ALARMA peripheral.
606 * @param __HANDLE__ specifies the RTC handle.
609 #define __HAL_RTC_ALARMA_DISABLE(__HANDLE__) (RTC->CR &= ~(RTC_CR_ALRAE))
612 * @brief Enable the RTC ALARMB peripheral.
613 * @param __HANDLE__ specifies the RTC handle.
616 #define __HAL_RTC_ALARMB_ENABLE(__HANDLE__) (RTC->CR |= (RTC_CR_ALRBE))
619 * @brief Disable the RTC ALARMB peripheral.
620 * @param __HANDLE__ specifies the RTC handle.
623 #define __HAL_RTC_ALARMB_DISABLE(__HANDLE__) (RTC->CR &= ~(RTC_CR_ALRBE))
626 * @brief Enable the RTC Alarm interrupt.
627 * @param __HANDLE__ specifies the RTC handle.
628 * @param __INTERRUPT__ specifies the RTC Alarm interrupt sources to be enabled or disabled.
629 * This parameter can be any combination of the following values:
630 * @arg @ref RTC_IT_ALRA Alarm A interrupt
631 * @arg @ref RTC_IT_ALRB Alarm B interrupt
634 #define __HAL_RTC_ALARM_ENABLE_IT(__HANDLE__, __INTERRUPT__) (RTC->CR |= (__INTERRUPT__))
637 * @brief Disable the RTC Alarm interrupt.
638 * @param __HANDLE__ specifies the RTC handle.
639 * @param __INTERRUPT__ specifies the RTC Alarm interrupt sources to be enabled or disabled.
640 * This parameter can be any combination of the following values:
641 * @arg @ref RTC_IT_ALRA Alarm A interrupt
642 * @arg @ref RTC_IT_ALRB Alarm B interrupt
645 #define __HAL_RTC_ALARM_DISABLE_IT(__HANDLE__, __INTERRUPT__) (RTC->CR &= ~(__INTERRUPT__))
648 * @brief Check whether the specified RTC Alarm interrupt has occurred or not.
649 * @param __HANDLE__ specifies the RTC handle.
650 * @param __INTERRUPT__ specifies the RTC Alarm interrupt sources to check.
651 * This parameter can be:
652 * @arg @ref RTC_IT_ALRA Alarm A interrupt
653 * @arg @ref RTC_IT_ALRB Alarm B interrupt
656 #define __HAL_RTC_ALARM_GET_IT(__HANDLE__, __INTERRUPT__) ((((RTC->MISR)& ((__INTERRUPT__)>> 12U)) != 0U) ? 1UL : 0UL)
659 * @brief Check whether the specified RTC Alarm interrupt has been enabled or not.
660 * @param __HANDLE__ specifies the RTC handle.
661 * @param __INTERRUPT__ specifies the RTC Alarm interrupt sources to check.
662 * This parameter can be:
663 * @arg @ref RTC_IT_ALRA Alarm A interrupt
664 * @arg @ref RTC_IT_ALRB Alarm B interrupt
667 #define __HAL_RTC_ALARM_GET_IT_SOURCE(__HANDLE__, __INTERRUPT__) ((((RTC->CR) & (__INTERRUPT__)) != 0U) ? 1UL : 0UL)
670 * @brief Get the selected RTC Alarms flag status.
671 * @param __HANDLE__ specifies the RTC handle.
672 * @param __FLAG__ specifies the RTC Alarm Flag sources to check.
673 * This parameter can be:
674 * @arg @ref RTC_FLAG_ALRAF
675 * @arg @ref RTC_FLAG_ALRBF
676 * @arg @ref RTC_FLAG_ALRAWF
677 * @arg @ref RTC_FLAG_ALRBWF
680 #define __HAL_RTC_ALARM_GET_FLAG(__HANDLE__, __FLAG__) (__HAL_RTC_GET_FLAG((__HANDLE__), (__FLAG__)))
683 * @brief Clear the RTC Alarms pending flags.
684 * @param __HANDLE__ specifies the RTC handle.
685 * @param __FLAG__ specifies the RTC Alarm Flag sources to clear.
686 * This parameter can be:
687 * @arg @ref RTC_FLAG_ALRAF
688 * @arg @ref RTC_FLAG_ALRBF
691 #define __HAL_RTC_ALARM_CLEAR_FLAG(__HANDLE__, __FLAG__) (((__FLAG__) == RTC_FLAG_ALRAF) ? ((RTC->SCR = (RTC_CLEAR_ALRAF))) : \
692 (RTC->SCR = (RTC_CLEAR_ALRBF)))
694 * @brief Enable interrupt on the RTC Alarm associated Exti line.
697 #define __HAL_RTC_ALARM_EXTI_ENABLE_IT() (EXTI->IMR1 |= RTC_EXTI_LINE_ALARM_EVENT)
700 * @brief Disable interrupt on the RTC Alarm associated Exti line.
703 #define __HAL_RTC_ALARM_EXTI_DISABLE_IT() (EXTI->IMR1 &= ~(RTC_EXTI_LINE_ALARM_EVENT))
706 * @brief Enable event on the RTC Alarm associated Exti line.
709 #define __HAL_RTC_ALARM_EXTI_ENABLE_EVENT() (EXTI->EMR1 |= RTC_EXTI_LINE_ALARM_EVENT)
712 * @brief Disable event on the RTC Alarm associated Exti line.
715 #define __HAL_RTC_ALARM_EXTI_DISABLE_EVENT() (EXTI->EMR1 &= ~(RTC_EXTI_LINE_ALARM_EVENT))
718 * @brief Enable falling edge trigger on the RTC Alarm associated Exti line.
721 #define __HAL_RTC_ALARM_EXTI_ENABLE_FALLING_EDGE() (EXTI->FTSR1 |= RTC_EXTI_LINE_ALARM_EVENT)
724 * @brief Disable falling edge trigger on the RTC Alarm associated Exti line.
727 #define __HAL_RTC_ALARM_EXTI_DISABLE_FALLING_EDGE() (EXTI->FTSR1 &= ~(RTC_EXTI_LINE_ALARM_EVENT))
730 * @brief Enable rising edge trigger on the RTC Alarm associated Exti line.
733 #define __HAL_RTC_ALARM_EXTI_ENABLE_RISING_EDGE() (EXTI->RTSR1 |= RTC_EXTI_LINE_ALARM_EVENT)
736 * @brief Disable rising edge trigger on the RTC Alarm associated Exti line.
739 #define __HAL_RTC_ALARM_EXTI_DISABLE_RISING_EDGE() (EXTI->RTSR1 &= ~(RTC_EXTI_LINE_ALARM_EVENT))
742 * @brief Enable rising & falling edge trigger on the RTC Alarm associated Exti line.
745 #define __HAL_RTC_ALARM_EXTI_ENABLE_RISING_FALLING_EDGE() do { \
746 __HAL_RTC_ALARM_EXTI_ENABLE_RISING_EDGE(); \
747 __HAL_RTC_ALARM_EXTI_ENABLE_FALLING_EDGE(); \
751 * @brief Disable rising & falling edge trigger on the RTC Alarm associated Exti line.
754 #define __HAL_RTC_ALARM_EXTI_DISABLE_RISING_FALLING_EDGE() do { \
755 __HAL_RTC_ALARM_EXTI_DISABLE_RISING_EDGE(); \
756 __HAL_RTC_ALARM_EXTI_DISABLE_FALLING_EDGE(); \
760 * @brief set rising edge interrupt on the RTC Alarm associated Exti line.
763 #define __HAL_RTC_ALARM_EXTI_RISING_IT() (EXTI->RTSR1 |= RTC_EXTI_LINE_ALARM_EVENT)
766 * @brief set rising edge interrupt on the RTC Alarm associated Exti line.
769 #define __HAL_RTC_ALARM_EXTI_FALLING_IT() (EXTI->FSTR1 |= RTC_EXTI_LINE_ALARM_EVENT)
772 * @brief clear interrupt on the RTC Alarm associated Exti line.
775 #define __HAL_RTC_ALARM_EXTI_CLEAR_IT() (EXTI->PR1 = RTC_EXTI_LINE_ALARM_EVENT)
782 /* Include RTC HAL Extended module */
783 #include "stm32g4xx_hal_rtc_ex.h"
785 /* Exported functions --------------------------------------------------------*/
786 /** @defgroup RTC_Exported_Functions RTC Exported Functions
790 /** @defgroup RTC_Exported_Functions_Group1 Initialization and de-initialization functions
793 /* Initialization and de-initialization functions ****************************/
794 HAL_StatusTypeDef
HAL_RTC_Init(RTC_HandleTypeDef
*hrtc
);
795 HAL_StatusTypeDef
HAL_RTC_DeInit(RTC_HandleTypeDef
*hrtc
);
797 void HAL_RTC_MspInit(RTC_HandleTypeDef
*hrtc
);
798 void HAL_RTC_MspDeInit(RTC_HandleTypeDef
*hrtc
);
799 #if (USE_HAL_RTC_REGISTER_CALLBACKS == 1)
801 /* Callbacks Register/UnRegister functions ***********************************/
802 HAL_StatusTypeDef
HAL_RTC_RegisterCallback(RTC_HandleTypeDef
*hrtc
, HAL_RTC_CallbackIDTypeDef CallbackID
,
803 pRTC_CallbackTypeDef pCallback
);
804 HAL_StatusTypeDef
HAL_RTC_UnRegisterCallback(RTC_HandleTypeDef
*hrtc
, HAL_RTC_CallbackIDTypeDef CallbackID
);
805 #endif /* USE_HAL_RTC_REGISTER_CALLBACKS */
810 /** @defgroup RTC_Exported_Functions_Group2 RTC Time and Date functions
813 /* RTC Time and Date functions ************************************************/
814 HAL_StatusTypeDef
HAL_RTC_SetTime(RTC_HandleTypeDef
*hrtc
, RTC_TimeTypeDef
*sTime
, uint32_t Format
);
815 HAL_StatusTypeDef
HAL_RTC_GetTime(RTC_HandleTypeDef
*hrtc
, RTC_TimeTypeDef
*sTime
, uint32_t Format
);
816 HAL_StatusTypeDef
HAL_RTC_SetDate(RTC_HandleTypeDef
*hrtc
, RTC_DateTypeDef
*sDate
, uint32_t Format
);
817 HAL_StatusTypeDef
HAL_RTC_GetDate(RTC_HandleTypeDef
*hrtc
, RTC_DateTypeDef
*sDate
, uint32_t Format
);
822 /** @defgroup RTC_Exported_Functions_Group3 RTC Alarm functions
825 /* RTC Alarm functions ********************************************************/
826 HAL_StatusTypeDef
HAL_RTC_SetAlarm(RTC_HandleTypeDef
*hrtc
, RTC_AlarmTypeDef
*sAlarm
, uint32_t Format
);
827 HAL_StatusTypeDef
HAL_RTC_SetAlarm_IT(RTC_HandleTypeDef
*hrtc
, RTC_AlarmTypeDef
*sAlarm
, uint32_t Format
);
828 HAL_StatusTypeDef
HAL_RTC_DeactivateAlarm(RTC_HandleTypeDef
*hrtc
, uint32_t Alarm
);
829 HAL_StatusTypeDef
HAL_RTC_GetAlarm(RTC_HandleTypeDef
*hrtc
, RTC_AlarmTypeDef
*sAlarm
, uint32_t Alarm
, uint32_t Format
);
830 void HAL_RTC_AlarmIRQHandler(RTC_HandleTypeDef
*hrtc
);
831 HAL_StatusTypeDef
HAL_RTC_PollForAlarmAEvent(RTC_HandleTypeDef
*hrtc
, uint32_t Timeout
);
832 void HAL_RTC_AlarmAEventCallback(RTC_HandleTypeDef
*hrtc
);
837 /** @defgroup RTC_Exported_Functions_Group4 Peripheral Control functions
840 /* Peripheral Control functions ***********************************************/
841 HAL_StatusTypeDef
HAL_RTC_WaitForSynchro(RTC_HandleTypeDef
*hrtc
);
846 /** @defgroup RTC_Exported_Functions_Group5 Peripheral State functions
849 /* Peripheral State functions *************************************************/
850 HAL_RTCStateTypeDef
HAL_RTC_GetState(RTC_HandleTypeDef
*hrtc
);
859 /* Private types -------------------------------------------------------------*/
860 /* Private variables ---------------------------------------------------------*/
861 /* Private constants ---------------------------------------------------------*/
862 /** @defgroup RTC_Private_Constants RTC Private Constants
865 /* Masks Definition */
866 #define RTC_TR_RESERVED_MASK (RTC_TR_PM | RTC_TR_HT | RTC_TR_HU | \
867 RTC_TR_MNT | RTC_TR_MNU| RTC_TR_ST | \
869 #define RTC_DR_RESERVED_MASK (RTC_DR_YT | RTC_DR_YU | RTC_DR_WDU | \
870 RTC_DR_MT | RTC_DR_MU | RTC_DR_DT | \
872 #define RTC_INIT_MASK 0xFFFFFFFFU
873 #define RTC_RSF_MASK (~(RTC_ICSR_INIT | RTC_ICSR_RSF))
875 #define RTC_TIMEOUT_VALUE 1000U
881 /* Private macros ------------------------------------------------------------*/
882 /** @defgroup RTC_Private_Macros RTC Private Macros
886 /** @defgroup RTC_IS_RTC_Definitions RTC Private macros to check input parameters
889 #define IS_RTC_OUTPUT(OUTPUT) (((OUTPUT) == RTC_OUTPUT_DISABLE) || \
890 ((OUTPUT) == RTC_OUTPUT_ALARMA) || \
891 ((OUTPUT) == RTC_OUTPUT_ALARMB) || \
892 ((OUTPUT) == RTC_OUTPUT_WAKEUP) || \
893 ((OUTPUT) == RTC_OUTPUT_TAMPER))
895 #define IS_RTC_HOUR_FORMAT(FORMAT) (((FORMAT) == RTC_HOURFORMAT_12) || \
896 ((FORMAT) == RTC_HOURFORMAT_24))
898 #define IS_RTC_OUTPUT_POL(POL) (((POL) == RTC_OUTPUT_POLARITY_HIGH) || \
899 ((POL) == RTC_OUTPUT_POLARITY_LOW))
901 #define IS_RTC_OUTPUT_TYPE(TYPE) (((TYPE) == RTC_OUTPUT_TYPE_OPENDRAIN) || \
902 ((TYPE) == RTC_OUTPUT_TYPE_PUSHPULL))
904 #define IS_RTC_OUTPUT_PULLUP(TYPE) (((TYPE) == RTC_OUTPUT_PULLUP_NONE) || \
905 ((TYPE) == RTC_OUTPUT_PULLUP_ON))
907 #define IS_RTC_OUTPUT_REMAP(REMAP) (((REMAP) == RTC_OUTPUT_REMAP_NONE) || \
908 ((REMAP) == RTC_OUTPUT_REMAP_POS1))
910 #define IS_RTC_HOURFORMAT12(PM) (((PM) == RTC_HOURFORMAT12_AM) || \
911 ((PM) == RTC_HOURFORMAT12_PM))
913 #define IS_RTC_DAYLIGHT_SAVING(SAVE) (((SAVE) == RTC_DAYLIGHTSAVING_SUB1H) || \
914 ((SAVE) == RTC_DAYLIGHTSAVING_ADD1H) || \
915 ((SAVE) == RTC_DAYLIGHTSAVING_NONE))
917 #define IS_RTC_STORE_OPERATION(OPERATION) (((OPERATION) == RTC_STOREOPERATION_RESET) || \
918 ((OPERATION) == RTC_STOREOPERATION_SET))
920 #define IS_RTC_FORMAT(FORMAT) (((FORMAT) == RTC_FORMAT_BIN) || \
921 ((FORMAT) == RTC_FORMAT_BCD))
923 #define IS_RTC_YEAR(YEAR) ((YEAR) <= 99u)
925 #define IS_RTC_MONTH(MONTH) (((MONTH) >= 1u) && ((MONTH) <= 12u))
927 #define IS_RTC_DATE(DATE) (((DATE) >= 1u) && ((DATE) <= 31u))
929 #define IS_RTC_WEEKDAY(WEEKDAY) (((WEEKDAY) == RTC_WEEKDAY_MONDAY) || \
930 ((WEEKDAY) == RTC_WEEKDAY_TUESDAY) || \
931 ((WEEKDAY) == RTC_WEEKDAY_WEDNESDAY) || \
932 ((WEEKDAY) == RTC_WEEKDAY_THURSDAY) || \
933 ((WEEKDAY) == RTC_WEEKDAY_FRIDAY) || \
934 ((WEEKDAY) == RTC_WEEKDAY_SATURDAY) || \
935 ((WEEKDAY) == RTC_WEEKDAY_SUNDAY))
937 #define IS_RTC_ALARM_DATE_WEEKDAY_DATE(DATE) (((DATE) >0u) && ((DATE) <= 31u))
939 #define IS_RTC_ALARM_DATE_WEEKDAY_WEEKDAY(WEEKDAY) (((WEEKDAY) == RTC_WEEKDAY_MONDAY) || \
940 ((WEEKDAY) == RTC_WEEKDAY_TUESDAY) || \
941 ((WEEKDAY) == RTC_WEEKDAY_WEDNESDAY) || \
942 ((WEEKDAY) == RTC_WEEKDAY_THURSDAY) || \
943 ((WEEKDAY) == RTC_WEEKDAY_FRIDAY) || \
944 ((WEEKDAY) == RTC_WEEKDAY_SATURDAY) || \
945 ((WEEKDAY) == RTC_WEEKDAY_SUNDAY))
947 #define IS_RTC_ALARM_DATE_WEEKDAY_SEL(SEL) (((SEL) == RTC_ALARMDATEWEEKDAYSEL_DATE) || \
948 ((SEL) == RTC_ALARMDATEWEEKDAYSEL_WEEKDAY))
950 #define IS_RTC_ALARM_MASK(MASK) (((MASK) & ~(RTC_ALARMMASK_ALL)) == 0UL)
952 #define IS_RTC_ALARM(ALARM) (((ALARM) == RTC_ALARM_A) || \
953 ((ALARM) == RTC_ALARM_B))
955 #define IS_RTC_ALARM_SUB_SECOND_VALUE(VALUE) ((VALUE) <= RTC_ALRMASSR_SS)
957 #define IS_RTC_ALARM_SUB_SECOND_MASK(MASK) (((MASK) == 0UL) || \
958 (((MASK) >= RTC_ALARMSUBSECONDMASK_SS14_1) && ((MASK) <= RTC_ALARMSUBSECONDMASK_NONE)))
960 #define IS_RTC_ASYNCH_PREDIV(PREDIV) ((PREDIV) <= (RTC_PRER_PREDIV_A >> RTC_PRER_PREDIV_A_Pos))
962 #define IS_RTC_SYNCH_PREDIV(PREDIV) ((PREDIV) <= (RTC_PRER_PREDIV_S >> RTC_PRER_PREDIV_S_Pos))
964 #define IS_RTC_HOUR12(HOUR) (((HOUR) > 0u) && ((HOUR) <= 12u))
966 #define IS_RTC_HOUR24(HOUR) ((HOUR) <= 23u)
968 #define IS_RTC_MINUTES(MINUTES) ((MINUTES) <= 59u)
970 #define IS_RTC_SECONDS(SECONDS) ((SECONDS) <= 59u)
980 /* Private functions -------------------------------------------------------------*/
981 /** @defgroup RTC_Private_Functions RTC Private Functions
984 HAL_StatusTypeDef
RTC_EnterInitMode(RTC_HandleTypeDef
*hrtc
);
985 uint8_t RTC_ByteToBcd2(uint8_t Value
);
986 uint8_t RTC_Bcd2ToByte(uint8_t Value
);
1004 #endif /* STM32G4xx_HAL_RTC_H */
1006 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/