1 /** 2 ****************************************************************************** 3 * @file stm32g4xx_hal_rtc.h 4 * @author MCD Application Team 5 * @brief Header file of RTC HAL module. 6 ****************************************************************************** 7 * @attention 8 * 9 * Copyright (c) 2019 STMicroelectronics. 10 * All rights reserved. 11 * 12 * This software is licensed under terms that can be found in the LICENSE file 13 * in the root directory of this software component. 14 * If no LICENSE file comes with this software, it is provided AS-IS. 15 * 16 ****************************************************************************** 17 */ 18 19 /* Define to prevent recursive inclusion -------------------------------------*/ 20 #ifndef STM32G4xx_HAL_RTC_H 21 #define STM32G4xx_HAL_RTC_H 22 23 #ifdef __cplusplus 24 extern "C" { 25 #endif 26 27 /* Includes ------------------------------------------------------------------*/ 28 #include "stm32g4xx_hal_def.h" 29 30 /** @addtogroup STM32G4xx_HAL_Driver 31 * @{ 32 */ 33 34 /** @defgroup RTC RTC 35 * @{ 36 */ 37 38 /* Exported types ------------------------------------------------------------*/ 39 /** @defgroup RTC_Exported_Types RTC Exported Types 40 * @{ 41 */ 42 43 /** 44 * @brief HAL State structures definition 45 */ 46 typedef enum 47 { 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 */ 53 54 } HAL_RTCStateTypeDef; 55 56 /** 57 * @brief RTC Configuration Structure definition 58 */ 59 typedef struct 60 { 61 uint32_t HourFormat; /*!< Specifies the RTC Hour Format. 62 This parameter can be a value of @ref RTC_Hour_Formats */ 63 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 */ 66 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 */ 69 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 */ 72 73 uint32_t OutPutRemap; /*!< Specifies the remap for RTC output. 74 This parameter can be a value of @ref RTC_Output_ALARM_OUT_Remap */ 75 76 uint32_t OutPutPolarity; /*!< Specifies the polarity of the output signal. 77 This parameter can be a value of @ref RTC_Output_Polarity_Definitions */ 78 79 uint32_t OutPutType; /*!< Specifies the RTC Output Pin mode. 80 This parameter can be a value of @ref RTC_Output_Type_ALARM_OUT */ 81 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 */ 84 } RTC_InitTypeDef; 85 86 /** 87 * @brief RTC Time structure definition 88 */ 89 typedef struct 90 { 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 */ 94 95 uint8_t Minutes; /*!< Specifies the RTC Time Minutes. 96 This parameter must be a number between Min_Data = 0 and Max_Data = 59 */ 97 98 uint8_t Seconds; /*!< Specifies the RTC Time Seconds. 99 This parameter must be a number between Min_Data = 0 and Max_Data = 59 */ 100 101 uint8_t TimeFormat; /*!< Specifies the RTC AM/PM Time. 102 This parameter can be a value of @ref RTC_AM_PM_Definitions */ 103 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 */ 107 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 */ 113 114 uint32_t DayLightSaving; /*!< This interface is deprecated. To manage Daylight Saving Time, 115 please use HAL_RTC_DST_xxx functions */ 116 117 uint32_t StoreOperation; /*!< This interface is deprecated. To manage Daylight Saving Time, 118 please use HAL_RTC_DST_xxx functions */ 119 } RTC_TimeTypeDef; 120 121 /** 122 * @brief RTC Date structure definition 123 */ 124 typedef struct 125 { 126 uint8_t WeekDay; /*!< Specifies the RTC Date WeekDay. 127 This parameter can be a value of @ref RTC_WeekDay_Definitions */ 128 129 uint8_t Month; /*!< Specifies the RTC Date Month (in BCD format). 130 This parameter can be a value of @ref RTC_Month_Date_Definitions */ 131 132 uint8_t Date; /*!< Specifies the RTC Date. 133 This parameter must be a number between Min_Data = 1 and Max_Data = 31 */ 134 135 uint8_t Year; /*!< Specifies the RTC Date Year. 136 This parameter must be a number between Min_Data = 0 and Max_Data = 99 */ 137 } RTC_DateTypeDef; 138 139 /** 140 * @brief RTC Alarm structure definition 141 */ 142 typedef struct 143 { 144 RTC_TimeTypeDef AlarmTime; /*!< Specifies the RTC Alarm Time members */ 145 146 uint32_t AlarmMask; /*!< Specifies the RTC Alarm Masks. 147 This parameter can be a value of @ref RTC_AlarmMask_Definitions */ 148 149 uint32_t AlarmSubSecondMask; /*!< Specifies the RTC Alarm SubSeconds Masks. 150 This parameter can be a value of @ref RTC_Alarm_Sub_Seconds_Masks_Definitions */ 151 152 uint32_t AlarmDateWeekDaySel; /*!< Specifies the RTC Alarm is on Date or WeekDay. 153 This parameter can be a value of @ref RTC_AlarmDateWeekDay_Definitions */ 154 155 uint8_t AlarmDateWeekDay; /*!< Specifies the RTC Alarm Date/WeekDay. 156 If the Alarm Date is selected, this parameter must be set to a value in the 1-31 range. 157 If the Alarm WeekDay is selected, this parameter can be a value of @ref RTC_WeekDay_Definitions */ 158 159 uint32_t Alarm; /*!< Specifies the alarm . 160 This parameter can be a value of @ref RTC_Alarms_Definitions */ 161 } RTC_AlarmTypeDef; 162 163 /** 164 * @brief RTC Handle Structure definition 165 */ 166 #if (USE_HAL_RTC_REGISTER_CALLBACKS == 1) 167 typedef struct __RTC_HandleTypeDef 168 #else 169 typedef struct 170 #endif /* (USE_HAL_RTC_REGISTER_CALLBACKS) */ 171 { 172 RTC_TypeDef *Instance; /*!< Legacy register base address. Not used anymore, 173 the driver directly uses cmsis base address */ 174 175 RTC_InitTypeDef Init; /*!< RTC required parameters */ 176 177 HAL_LockTypeDef Lock; /*!< RTC locking object */ 178 179 __IO HAL_RTCStateTypeDef State; /*!< Time communication state */ 180 181 #if (USE_HAL_RTC_REGISTER_CALLBACKS == 1) 182 void (* AlarmAEventCallback)(struct __RTC_HandleTypeDef *hrtc); /*!< RTC Alarm A Event callback */ 183 void (* AlarmBEventCallback)(struct __RTC_HandleTypeDef *hrtc); /*!< RTC Alarm B Event callback */ 184 void (* TimeStampEventCallback)(struct __RTC_HandleTypeDef *hrtc); /*!< RTC TimeStamp Event callback */ 185 void (* WakeUpTimerEventCallback)(struct __RTC_HandleTypeDef *hrtc); /*!< RTC WakeUpTimer Event callback */ 186 187 void (* Tamper1EventCallback)(struct __RTC_HandleTypeDef *hrtc); /*!< RTC Tamper 1 Event callback */ 188 void (* Tamper2EventCallback)(struct __RTC_HandleTypeDef *hrtc); /*!< RTC Tamper 2 Event callback */ 189 #if (RTC_TAMP_NB == 3) 190 void (* Tamper3EventCallback)(struct __RTC_HandleTypeDef *hrtc); /*!< RTC Tamper 3 Event callback */ 191 #endif /* RTC_TAMP_NB */ 192 void (* InternalTamper1EventCallback)(struct __RTC_HandleTypeDef *hrtc); /*!< RTC Internal Tamper 1 Event callback */ 193 #ifdef RTC_TAMP_INT_2_SUPPORT 194 void (* InternalTamper2EventCallback)(struct __RTC_HandleTypeDef *hrtc); /*!< RTC Internal Tamper 2 Event callback */ 195 #endif /* RTC_TAMP_INT_2_SUPPORT */ 196 void (* InternalTamper3EventCallback)(struct __RTC_HandleTypeDef *hrtc); /*!< RTC Internal Tamper 3 Event callback */ 197 void (* InternalTamper4EventCallback)(struct __RTC_HandleTypeDef *hrtc); /*!< RTC Internal Tamper 4 Event callback */ 198 void (* InternalTamper5EventCallback)(struct __RTC_HandleTypeDef *hrtc); /*!< RTC Internal Tamper 5 Event callback */ 199 #ifdef RTC_TAMP_INT_6_SUPPORT 200 void (* InternalTamper6EventCallback)(struct __RTC_HandleTypeDef *hrtc); /*!< RTC Internal Tamper 6 Event callback */ 201 #endif /* RTC_TAMP_INT_6_SUPPORT */ 202 #ifdef RTC_TAMP_INT_7_SUPPORT 203 void (* InternalTamper7EventCallback)(struct __RTC_HandleTypeDef *hrtc); /*!< RTC Internal Tamper 7 Event callback */ 204 #endif /* RTC_TAMP_INT_7_SUPPORT */ 205 206 void (* MspInitCallback)(struct __RTC_HandleTypeDef *hrtc); /*!< RTC Msp Init callback */ 207 void (* MspDeInitCallback)(struct __RTC_HandleTypeDef *hrtc); /*!< RTC Msp DeInit callback */ 208 209 #endif /* (USE_HAL_RTC_REGISTER_CALLBACKS) */ 210 211 } RTC_HandleTypeDef; 212 213 #if (USE_HAL_RTC_REGISTER_CALLBACKS == 1) 214 /** 215 * @brief HAL LPTIM Callback ID enumeration definition 216 */ 217 typedef enum 218 { 219 HAL_RTC_ALARM_A_EVENT_CB_ID = 0x00U, /*!< RTC Alarm A Event Callback ID */ 220 HAL_RTC_ALARM_B_EVENT_CB_ID = 0x01U, /*!< RTC Alarm B Event Callback ID */ 221 HAL_RTC_TIMESTAMP_EVENT_CB_ID = 0x02U, /*!< RTC TimeStamp Event Callback ID */ 222 HAL_RTC_WAKEUPTIMER_EVENT_CB_ID = 0x03U, /*!< RTC WakeUp Timer Event Callback ID */ 223 HAL_RTC_TAMPER1_EVENT_CB_ID = 0x04U, /*!< RTC Tamper 1 Callback ID */ 224 HAL_RTC_TAMPER2_EVENT_CB_ID = 0x05U, /*!< RTC Tamper 2 Callback ID */ 225 HAL_RTC_TAMPER3_EVENT_CB_ID = 0x06U, /*!< RTC Tamper 3 Callback ID */ 226 HAL_RTC_INTERNAL_TAMPER1_EVENT_CB_ID = 0x07U, /*!< RTC Internal Tamper 1 Callback ID */ 227 HAL_RTC_INTERNAL_TAMPER2_EVENT_CB_ID = 0x08U, /*!< RTC Internal Tamper 2 Callback ID */ 228 HAL_RTC_INTERNAL_TAMPER3_EVENT_CB_ID = 0x09U, /*!< RTC Internal Tamper 3 Callback ID */ 229 HAL_RTC_INTERNAL_TAMPER4_EVENT_CB_ID = 0x0AU, /*!< RTC Internal Tamper 4 Callback ID */ 230 HAL_RTC_INTERNAL_TAMPER5_EVENT_CB_ID = 0x0BU, /*!< RTC Internal Tamper 5 Callback ID */ 231 HAL_RTC_INTERNAL_TAMPER6_EVENT_CB_ID = 0x0CU, /*!< RTC Internal Tamper 6 Callback ID */ 232 HAL_RTC_INTERNAL_TAMPER7_EVENT_CB_ID = 0x0DU, /*!< RTC Internal Tamper 7 Callback ID */ 233 HAL_RTC_MSPINIT_CB_ID = 0x0EU, /*!< RTC Msp Init callback ID */ 234 HAL_RTC_MSPDEINIT_CB_ID = 0x0FU /*!< RTC Msp DeInit callback ID */ 235 } HAL_RTC_CallbackIDTypeDef; 236 237 /** 238 * @brief HAL RTC Callback pointer definition 239 */ 240 typedef void (*pRTC_CallbackTypeDef)(RTC_HandleTypeDef *hrtc); /*!< pointer to an RTC callback function */ 241 #endif /* USE_HAL_RTC_REGISTER_CALLBACKS */ 242 243 /** 244 * @} 245 */ 246 247 /* Exported constants --------------------------------------------------------*/ 248 /** @defgroup RTC_Exported_Constants RTC Exported Constants 249 * @{ 250 */ 251 252 /** @defgroup RTC_Hour_Formats RTC Hour Formats 253 * @{ 254 */ 255 #define RTC_HOURFORMAT_24 0x00000000U 256 #define RTC_HOURFORMAT_12 RTC_CR_FMT 257 /** 258 * @} 259 */ 260 261 /** @defgroup RTCEx_Output_selection_Definitions RTCEx Output Selection Definition 262 * @{ 263 */ 264 #define RTC_OUTPUT_DISABLE 0x00000000U 265 #define RTC_OUTPUT_ALARMA RTC_CR_OSEL_0 266 #define RTC_OUTPUT_ALARMB RTC_CR_OSEL_1 267 #define RTC_OUTPUT_WAKEUP RTC_CR_OSEL 268 #define RTC_OUTPUT_TAMPER RTC_CR_TAMPOE 269 /** 270 * @} 271 */ 272 273 274 /** @defgroup RTC_Output_Polarity_Definitions RTC Output Polarity Definitions 275 * @{ 276 */ 277 #define RTC_OUTPUT_POLARITY_HIGH 0x00000000U 278 #define RTC_OUTPUT_POLARITY_LOW RTC_CR_POL 279 /** 280 * @} 281 */ 282 283 /** @defgroup RTC_Output_Type_ALARM_OUT RTC Output Type ALARM OUT 284 * @{ 285 */ 286 #define RTC_OUTPUT_TYPE_PUSHPULL 0x00000000U 287 #define RTC_OUTPUT_TYPE_OPENDRAIN RTC_CR_TAMPALRM_TYPE 288 /** 289 * @} 290 */ 291 292 /** @defgroup RTC_Output_PullUp_ALARM_OUT RTC Output Pull-Up ALARM OUT 293 * @{ 294 */ 295 #define RTC_OUTPUT_PULLUP_NONE 0x00000000U 296 #define RTC_OUTPUT_PULLUP_ON RTC_CR_TAMPALRM_PU 297 /** 298 * @} 299 */ 300 301 /** @defgroup RTC_Output_ALARM_OUT_Remap RTC Output ALARM OUT Remap 302 * @{ 303 */ 304 #define RTC_OUTPUT_REMAP_NONE 0x00000000U 305 #define RTC_OUTPUT_REMAP_POS1 RTC_CR_OUT2EN 306 /** 307 * @} 308 */ 309 310 /** @defgroup RTC_AM_PM_Definitions RTC AM PM Definitions 311 * @{ 312 */ 313 #define RTC_HOURFORMAT12_AM 0x0U 314 #define RTC_HOURFORMAT12_PM 0x1U 315 /** 316 * @} 317 */ 318 319 /** @defgroup RTC_DayLightSaving_Definitions RTC DayLightSaving Definitions 320 * @{ 321 */ 322 #define RTC_DAYLIGHTSAVING_SUB1H RTC_CR_SUB1H 323 #define RTC_DAYLIGHTSAVING_ADD1H RTC_CR_ADD1H 324 #define RTC_DAYLIGHTSAVING_NONE 0x00000000U 325 /** 326 * @} 327 */ 328 329 /** @defgroup RTC_StoreOperation_Definitions RTC StoreOperation Definitions 330 * @{ 331 */ 332 #define RTC_STOREOPERATION_RESET 0x00000000U 333 #define RTC_STOREOPERATION_SET RTC_CR_BKP 334 /** 335 * @} 336 */ 337 338 /** @defgroup RTC_Input_parameter_format_definitions RTC Input Parameter Format Definitions 339 * @{ 340 */ 341 #define RTC_FORMAT_BIN 0x00000000U 342 #define RTC_FORMAT_BCD 0x00000001U 343 /** 344 * @} 345 */ 346 347 /** @defgroup RTC_Month_Date_Definitions RTC Month Date Definitions 348 * @{ 349 */ 350 351 /* Coded in BCD format */ 352 #define RTC_MONTH_JANUARY ((uint8_t)0x01U) 353 #define RTC_MONTH_FEBRUARY ((uint8_t)0x02U) 354 #define RTC_MONTH_MARCH ((uint8_t)0x03U) 355 #define RTC_MONTH_APRIL ((uint8_t)0x04U) 356 #define RTC_MONTH_MAY ((uint8_t)0x05U) 357 #define RTC_MONTH_JUNE ((uint8_t)0x06U) 358 #define RTC_MONTH_JULY ((uint8_t)0x07U) 359 #define RTC_MONTH_AUGUST ((uint8_t)0x08U) 360 #define RTC_MONTH_SEPTEMBER ((uint8_t)0x09U) 361 #define RTC_MONTH_OCTOBER ((uint8_t)0x10U) 362 #define RTC_MONTH_NOVEMBER ((uint8_t)0x11U) 363 #define RTC_MONTH_DECEMBER ((uint8_t)0x12U) 364 365 /** 366 * @} 367 */ 368 369 /** @defgroup RTC_WeekDay_Definitions RTC WeekDay Definitions 370 * @{ 371 */ 372 #define RTC_WEEKDAY_MONDAY ((uint8_t)0x01U) 373 #define RTC_WEEKDAY_TUESDAY ((uint8_t)0x02U) 374 #define RTC_WEEKDAY_WEDNESDAY ((uint8_t)0x03U) 375 #define RTC_WEEKDAY_THURSDAY ((uint8_t)0x04U) 376 #define RTC_WEEKDAY_FRIDAY ((uint8_t)0x05U) 377 #define RTC_WEEKDAY_SATURDAY ((uint8_t)0x06U) 378 #define RTC_WEEKDAY_SUNDAY ((uint8_t)0x07U) 379 380 /** 381 * @} 382 */ 383 384 /** @defgroup RTC_AlarmDateWeekDay_Definitions RTC AlarmDateWeekDay Definitions 385 * @{ 386 */ 387 #define RTC_ALARMDATEWEEKDAYSEL_DATE 0x00000000U 388 #define RTC_ALARMDATEWEEKDAYSEL_WEEKDAY RTC_ALRMAR_WDSEL 389 390 /** 391 * @} 392 */ 393 394 /** @defgroup RTC_AlarmMask_Definitions RTC AlarmMask Definitions 395 * @{ 396 */ 397 #define RTC_ALARMMASK_NONE 0x00000000U 398 #define RTC_ALARMMASK_DATEWEEKDAY RTC_ALRMAR_MSK4 399 #define RTC_ALARMMASK_HOURS RTC_ALRMAR_MSK3 400 #define RTC_ALARMMASK_MINUTES RTC_ALRMAR_MSK2 401 #define RTC_ALARMMASK_SECONDS RTC_ALRMAR_MSK1 402 #define RTC_ALARMMASK_ALL (RTC_ALARMMASK_DATEWEEKDAY | RTC_ALARMMASK_HOURS | \ 403 RTC_ALARMMASK_MINUTES | RTC_ALARMMASK_SECONDS) 404 405 /** 406 * @} 407 */ 408 409 /** @defgroup RTC_Alarms_Definitions RTC Alarms Definitions 410 * @{ 411 */ 412 #define RTC_ALARM_A RTC_CR_ALRAE 413 #define RTC_ALARM_B RTC_CR_ALRBE 414 415 /** 416 * @} 417 */ 418 419 420 /** @defgroup RTC_Alarm_Sub_Seconds_Masks_Definitions RTC Alarm Sub Seconds Masks Definitions 421 * @{ 422 */ 423 #define RTC_ALARMSUBSECONDMASK_ALL 0x00000000U /*!< All Alarm SS fields are masked. 424 There is no comparison on sub seconds 425 for Alarm */ 426 #define RTC_ALARMSUBSECONDMASK_SS14_1 RTC_ALRMASSR_MASKSS_0 /*!< SS[14:1] not used in Alarm 427 comparison. Only SS[0] is compared. */ 428 #define RTC_ALARMSUBSECONDMASK_SS14_2 RTC_ALRMASSR_MASKSS_1 /*!< SS[14:2] not used in Alarm 429 comparison. Only SS[1:0] are compared */ 430 #define RTC_ALARMSUBSECONDMASK_SS14_3 (RTC_ALRMASSR_MASKSS_0 | RTC_ALRMASSR_MASKSS_1) /*!< SS[14:3] not used in Alarm 431 comparison. Only SS[2:0] are compared */ 432 #define RTC_ALARMSUBSECONDMASK_SS14_4 RTC_ALRMASSR_MASKSS_2 /*!< SS[14:4] not used in Alarm 433 comparison. Only SS[3:0] are compared */ 434 #define RTC_ALARMSUBSECONDMASK_SS14_5 (RTC_ALRMASSR_MASKSS_0 | RTC_ALRMASSR_MASKSS_2) /*!< SS[14:5] not used in Alarm 435 comparison. Only SS[4:0] are compared */ 436 #define RTC_ALARMSUBSECONDMASK_SS14_6 (RTC_ALRMASSR_MASKSS_1 | RTC_ALRMASSR_MASKSS_2) /*!< SS[14:6] not used in Alarm 437 comparison. Only SS[5:0] are compared */ 438 #define RTC_ALARMSUBSECONDMASK_SS14_7 (RTC_ALRMASSR_MASKSS_0 | RTC_ALRMASSR_MASKSS_1 | RTC_ALRMASSR_MASKSS_2) /*!< SS[14:7] not used in Alarm 439 comparison. Only SS[6:0] are compared */ 440 #define RTC_ALARMSUBSECONDMASK_SS14_8 RTC_ALRMASSR_MASKSS_3 /*!< SS[14:8] not used in Alarm 441 comparison. Only SS[7:0] are compared */ 442 #define RTC_ALARMSUBSECONDMASK_SS14_9 (RTC_ALRMASSR_MASKSS_0 | RTC_ALRMASSR_MASKSS_3) /*!< SS[14:9] not used in Alarm 443 comparison. Only SS[8:0] are compared */ 444 #define RTC_ALARMSUBSECONDMASK_SS14_10 (RTC_ALRMASSR_MASKSS_1 | RTC_ALRMASSR_MASKSS_3) /*!< SS[14:10] not used in Alarm 445 comparison. Only SS[9:0] are compared */ 446 #define RTC_ALARMSUBSECONDMASK_SS14_11 (RTC_ALRMASSR_MASKSS_0 | RTC_ALRMASSR_MASKSS_1 | RTC_ALRMASSR_MASKSS_3) /*!< SS[14:11] not used in Alarm 447 comparison. Only SS[10:0] are compared */ 448 #define RTC_ALARMSUBSECONDMASK_SS14_12 (RTC_ALRMASSR_MASKSS_2 | RTC_ALRMASSR_MASKSS_3) /*!< SS[14:12] not used in Alarm 449 comparison.Only SS[11:0] are compared */ 450 #define RTC_ALARMSUBSECONDMASK_SS14_13 (RTC_ALRMASSR_MASKSS_0 | RTC_ALRMASSR_MASKSS_2 | RTC_ALRMASSR_MASKSS_3) /*!< SS[14:13] not used in Alarm 451 comparison. Only SS[12:0] are compared */ 452 #define RTC_ALARMSUBSECONDMASK_SS14 (RTC_ALRMASSR_MASKSS_1 | RTC_ALRMASSR_MASKSS_2 | RTC_ALRMASSR_MASKSS_3) /*!< SS[14] not used in Alarm 453 comparison. Only SS[13:0] are compared */ 454 #define RTC_ALARMSUBSECONDMASK_NONE RTC_ALRMASSR_MASKSS /*!< SS[14:0] are compared and must match 455 to activate alarm. */ 456 /** 457 * @} 458 */ 459 460 /** @defgroup RTC_Interrupts_Definitions RTC Interrupts Definitions 461 * @{ 462 */ 463 #define RTC_IT_TS RTC_CR_TSIE /*!< Enable Timestamp Interrupt */ 464 #define RTC_IT_WUT RTC_CR_WUTIE /*!< Enable Wakeup timer Interrupt */ 465 #define RTC_IT_ALRA RTC_CR_ALRAIE /*!< Enable Alarm A Interrupt */ 466 #define RTC_IT_ALRB RTC_CR_ALRBIE /*!< Enable Alarm B Interrupt */ 467 /** 468 * @} 469 */ 470 471 /** @defgroup RTC_Flag_Mask RTC Flag Mask (5bits) describe in RTC_Flags_Definitions 472 * @{ 473 */ 474 #define RTC_FLAG_MASK 0x001FU /*!< RTC flags mask (5bits) */ 475 /** 476 * @} 477 */ 478 479 /** @defgroup RTC_Flags_Definitions RTC Flags Definitions 480 * Elements values convention: 000000XX000YYYYYb 481 * - YYYYY : Interrupt flag position in the XX register (5bits) 482 * - XX : Interrupt status register (2bits) 483 * - 01: ICSR register 484 * - 10: SR or SCR or MISR registers 485 * @{ 486 */ 487 #define RTC_FLAG_RECALPF (0x00000100U | RTC_ICSR_RECALPF_Pos) /*!< Recalibration pending Flag */ 488 #define RTC_FLAG_INITF (0x00000100U | RTC_ICSR_INITF_Pos) /*!< Initialization flag */ 489 #define RTC_FLAG_RSF (0x00000100U | RTC_ICSR_RSF_Pos) /*!< Registers synchronization flag */ 490 #define RTC_FLAG_INITS (0x00000100U | RTC_ICSR_INITS_Pos) /*!< Initialization status flag */ 491 #define RTC_FLAG_SHPF (0x00000100U | RTC_ICSR_SHPF_Pos) /*!< Shift operation pending flag */ 492 #define RTC_FLAG_WUTWF (0x00000100U | RTC_ICSR_WUTWF_Pos) /*!< Wakeup timer write flag */ 493 #define RTC_FLAG_ALRBWF (0x00000100U | RTC_ICSR_ALRBWF_Pos) /*!< Alarm B write flag */ 494 #define RTC_FLAG_ALRAWF (0x00000100U | RTC_ICSR_ALRAWF_Pos) /*!< Alarm A write flag */ 495 #define RTC_FLAG_ITSF (0x00000200U | RTC_SR_ITSF_Pos) /*!< Internal Time-stamp flag */ 496 #define RTC_FLAG_TSOVF (0x00000200U | RTC_SR_TSOVF_Pos) /*!< Time-stamp overflow flag */ 497 #define RTC_FLAG_TSF (0x00000200U | RTC_SR_TSF_Pos) /*!< Time-stamp flag */ 498 #define RTC_FLAG_WUTF (0x00000200U | RTC_SR_WUTF_Pos) /*!< Wakeup timer flag */ 499 #define RTC_FLAG_ALRBF (0x00000200U | RTC_SR_ALRBF_Pos) /*!< Alarm B flag */ 500 #define RTC_FLAG_ALRAF (0x00000200U | RTC_SR_ALRAF_Pos) /*!< Alarm A flag */ 501 /** 502 * @} 503 */ 504 505 /** @defgroup RTC_Clear_Flags_Definitions RTC Clear Flags Definitions 506 * @{ 507 */ 508 #define RTC_CLEAR_ITSF RTC_SCR_CITSF /*!< Clear Internal Time-stamp flag */ 509 #define RTC_CLEAR_TSOVF RTC_SCR_CTSOVF /*!< Clear Time-stamp overflow flag */ 510 #define RTC_CLEAR_TSF RTC_SCR_CTSF /*!< Clear Time-stamp flag */ 511 #define RTC_CLEAR_WUTF RTC_SCR_CWUTF /*!< Clear Wakeup timer flag */ 512 #define RTC_CLEAR_ALRBF RTC_SCR_CALRBF /*!< Clear Alarm B flag */ 513 #define RTC_CLEAR_ALRAF RTC_SCR_CALRAF /*!< Clear Alarm A flag */ 514 /** 515 * @} 516 */ 517 518 /** 519 * @} 520 */ 521 522 /* Exported macros -----------------------------------------------------------*/ 523 /** @defgroup RTC_Exported_Macros RTC Exported Macros 524 * @{ 525 */ 526 527 /** @brief Reset RTC handle state 528 * @param __HANDLE__ RTC handle. 529 * @retval None 530 */ 531 #if (USE_HAL_RTC_REGISTER_CALLBACKS == 1) 532 #define __HAL_RTC_RESET_HANDLE_STATE(__HANDLE__) do{\ 533 (__HANDLE__)->State = HAL_RTC_STATE_RESET;\ 534 (__HANDLE__)->MspInitCallback = NULL;\ 535 (__HANDLE__)->MspDeInitCallback = NULL;\ 536 }while(0) 537 #else 538 #define __HAL_RTC_RESET_HANDLE_STATE(__HANDLE__) ((__HANDLE__)->State = HAL_RTC_STATE_RESET) 539 #endif /* USE_HAL_RTC_REGISTER_CALLBACKS */ 540 541 /** 542 * @brief Disable the write protection for RTC registers. 543 * @param __HANDLE__ specifies the RTC handle. 544 * @retval None 545 */ 546 #define __HAL_RTC_WRITEPROTECTION_DISABLE(__HANDLE__) \ 547 do{ \ 548 (__HANDLE__)->Instance->WPR = 0xCAU; \ 549 (__HANDLE__)->Instance->WPR = 0x53U; \ 550 } while(0U) 551 552 /** 553 * @brief Enable the write protection for RTC registers. 554 * @param __HANDLE__ specifies the RTC handle. 555 * @retval None 556 */ 557 #define __HAL_RTC_WRITEPROTECTION_ENABLE(__HANDLE__) \ 558 do{ \ 559 (__HANDLE__)->Instance->WPR = 0xFFU; \ 560 } while(0U) 561 562 /** 563 * @brief Check whether the RTC Calendar is initialized. 564 * @param __HANDLE__ specifies the RTC handle. 565 * @retval None 566 */ 567 #define __HAL_RTC_IS_CALENDAR_INITIALIZED(__HANDLE__) (((((__HANDLE__)->Instance->ICSR) & (RTC_ICSR_INITS)) == RTC_ICSR_INITS) ? 1U : 0U) 568 569 /** 570 * @brief Add 1 hour (summer time change). 571 * @note This interface is deprecated. 572 * To manage Daylight Saving Time, please use HAL_RTC_DST_xxx functions 573 * @param __HANDLE__ specifies the RTC handle. 574 * @param __BKP__ Backup 575 * This parameter can be: 576 * @arg @ref RTC_STOREOPERATION_RESET 577 * @arg @ref RTC_STOREOPERATION_SET 578 * @retval None 579 */ 580 #define __HAL_RTC_DAYLIGHT_SAVING_TIME_ADD1H(__HANDLE__, __BKP__) \ 581 do { \ 582 __HAL_RTC_WRITEPROTECTION_DISABLE(__HANDLE__); \ 583 SET_BIT((__HANDLE__)->Instance->CR, RTC_CR_ADD1H); \ 584 MODIFY_REG((__HANDLE__)->Instance->CR, RTC_CR_BKP , (__BKP__)); \ 585 __HAL_RTC_WRITEPROTECTION_ENABLE(__HANDLE__); \ 586 } while(0); 587 588 /** 589 * @brief Subtract 1 hour (winter time change). 590 * @note This interface is deprecated. 591 * To manage Daylight Saving Time, please use HAL_RTC_DST_xxx functions 592 * @param __HANDLE__ specifies the RTC handle. 593 * @param __BKP__ Backup 594 * This parameter can be: 595 * @arg @ref RTC_STOREOPERATION_RESET 596 * @arg @ref RTC_STOREOPERATION_SET 597 * @retval None 598 */ 599 #define __HAL_RTC_DAYLIGHT_SAVING_TIME_SUB1H(__HANDLE__, __BKP__) \ 600 do { \ 601 __HAL_RTC_WRITEPROTECTION_DISABLE(__HANDLE__); \ 602 SET_BIT((__HANDLE__)->Instance->CR, RTC_CR_SUB1H); \ 603 MODIFY_REG((__HANDLE__)->Instance->CR, RTC_CR_BKP , (__BKP__)); \ 604 __HAL_RTC_WRITEPROTECTION_ENABLE(__HANDLE__); \ 605 } while(0); 606 607 /** 608 * @brief Enable the RTC ALARMA peripheral. 609 * @param __HANDLE__ specifies the RTC handle. 610 * @retval None 611 */ 612 #define __HAL_RTC_ALARMA_ENABLE(__HANDLE__) ((__HANDLE__)->Instance->CR |= (RTC_CR_ALRAE)) 613 614 /** 615 * @brief Disable the RTC ALARMA peripheral. 616 * @param __HANDLE__ specifies the RTC handle. 617 * @retval None 618 */ 619 #define __HAL_RTC_ALARMA_DISABLE(__HANDLE__) ((__HANDLE__)->Instance->CR &= ~(RTC_CR_ALRAE)) 620 621 /** 622 * @brief Enable the RTC ALARMB peripheral. 623 * @param __HANDLE__ specifies the RTC handle. 624 * @retval None 625 */ 626 #define __HAL_RTC_ALARMB_ENABLE(__HANDLE__) ((__HANDLE__)->Instance->CR |= (RTC_CR_ALRBE)) 627 628 /** 629 * @brief Disable the RTC ALARMB peripheral. 630 * @param __HANDLE__ specifies the RTC handle. 631 * @retval None 632 */ 633 #define __HAL_RTC_ALARMB_DISABLE(__HANDLE__) ((__HANDLE__)->Instance->CR &= ~(RTC_CR_ALRBE)) 634 635 /** 636 * @brief Enable the RTC Alarm interrupt. 637 * @param __HANDLE__ specifies the RTC handle. 638 * @param __INTERRUPT__ specifies the RTC Alarm interrupt sources to be enabled or disabled. 639 * This parameter can be any combination of the following values: 640 * @arg @ref RTC_IT_ALRA Alarm A interrupt 641 * @arg @ref RTC_IT_ALRB Alarm B interrupt 642 * @retval None 643 */ 644 #define __HAL_RTC_ALARM_ENABLE_IT(__HANDLE__, __INTERRUPT__) ((__HANDLE__)->Instance->CR |= (__INTERRUPT__)) 645 646 /** 647 * @brief Disable the RTC Alarm interrupt. 648 * @param __HANDLE__ specifies the RTC handle. 649 * @param __INTERRUPT__ specifies the RTC Alarm interrupt sources to be enabled or disabled. 650 * This parameter can be any combination of the following values: 651 * @arg @ref RTC_IT_ALRA Alarm A interrupt 652 * @arg @ref RTC_IT_ALRB Alarm B interrupt 653 * @retval None 654 */ 655 #define __HAL_RTC_ALARM_DISABLE_IT(__HANDLE__, __INTERRUPT__) ((__HANDLE__)->Instance->CR &= ~(__INTERRUPT__)) 656 657 /** 658 * @brief Check whether the specified RTC Alarm interrupt has occurred or not. 659 * @param __HANDLE__ specifies the RTC handle. 660 * @param __INTERRUPT__ specifies the RTC Alarm interrupt sources to check. 661 * This parameter can be: 662 * @arg @ref RTC_IT_ALRA Alarm A interrupt 663 * @arg @ref RTC_IT_ALRB Alarm B interrupt 664 * @retval None 665 */ 666 #define __HAL_RTC_ALARM_GET_IT(__HANDLE__, __INTERRUPT__) (((((__HANDLE__)->Instance->MISR)& ((__INTERRUPT__)>> 12U)) != 0U) ? 1UL : 0UL) 667 668 /** 669 * @brief Check whether the specified RTC Alarm interrupt has been enabled or not. 670 * @param __HANDLE__ specifies the RTC handle. 671 * @param __INTERRUPT__ specifies the RTC Alarm interrupt sources to check. 672 * This parameter can be: 673 * @arg @ref RTC_IT_ALRA Alarm A interrupt 674 * @arg @ref RTC_IT_ALRB Alarm B interrupt 675 * @retval None 676 */ 677 #define __HAL_RTC_ALARM_GET_IT_SOURCE(__HANDLE__, __INTERRUPT__) (((((__HANDLE__)->Instance->CR) & (__INTERRUPT__)) != 0U) ? 1UL : 0UL) 678 679 /** 680 * @brief Get the selected RTC Alarms flag status. 681 * @param __HANDLE__ specifies the RTC handle. 682 * @param __FLAG__ specifies the RTC Alarm Flag sources to check. 683 * This parameter can be: 684 * @arg @ref RTC_FLAG_ALRAF 685 * @arg @ref RTC_FLAG_ALRBF 686 * @arg @ref RTC_FLAG_ALRAWF 687 * @arg @ref RTC_FLAG_ALRBWF 688 * @retval None 689 */ 690 #define __HAL_RTC_ALARM_GET_FLAG(__HANDLE__, __FLAG__) (__HAL_RTC_GET_FLAG((__HANDLE__), (__FLAG__))) 691 692 /** 693 * @brief Clear the RTC Alarms pending flags. 694 * @param __HANDLE__ specifies the RTC handle. 695 * @param __FLAG__ specifies the RTC Alarm Flag sources to clear. 696 * This parameter can be: 697 * @arg @ref RTC_FLAG_ALRAF 698 * @arg @ref RTC_FLAG_ALRBF 699 * @retval None 700 */ 701 #define __HAL_RTC_ALARM_CLEAR_FLAG(__HANDLE__, __FLAG__) (((__FLAG__) == RTC_FLAG_ALRAF) ? (((__HANDLE__)->Instance->SCR = (RTC_CLEAR_ALRAF))) : \ 702 ((__HANDLE__)->Instance->SCR = (RTC_CLEAR_ALRBF))) 703 /** 704 * @brief Enable interrupt on the RTC Alarm associated Exti line. 705 * @retval None 706 */ 707 #define __HAL_RTC_ALARM_EXTI_ENABLE_IT() (EXTI->IMR1 |= RTC_EXTI_LINE_ALARM_EVENT) 708 709 /** 710 * @brief Disable interrupt on the RTC Alarm associated Exti line. 711 * @retval None 712 */ 713 #define __HAL_RTC_ALARM_EXTI_DISABLE_IT() (EXTI->IMR1 &= ~(RTC_EXTI_LINE_ALARM_EVENT)) 714 715 /** 716 * @brief Enable event on the RTC Alarm associated Exti line. 717 * @retval None 718 */ 719 #define __HAL_RTC_ALARM_EXTI_ENABLE_EVENT() (EXTI->EMR1 |= RTC_EXTI_LINE_ALARM_EVENT) 720 721 /** 722 * @brief Disable event on the RTC Alarm associated Exti line. 723 * @retval None 724 */ 725 #define __HAL_RTC_ALARM_EXTI_DISABLE_EVENT() (EXTI->EMR1 &= ~(RTC_EXTI_LINE_ALARM_EVENT)) 726 727 /** 728 * @brief Enable falling edge trigger on the RTC Alarm associated Exti line. 729 * @retval None 730 */ 731 #define __HAL_RTC_ALARM_EXTI_ENABLE_FALLING_EDGE() (EXTI->FTSR1 |= RTC_EXTI_LINE_ALARM_EVENT) 732 733 /** 734 * @brief Disable falling edge trigger on the RTC Alarm associated Exti line. 735 * @retval None 736 */ 737 #define __HAL_RTC_ALARM_EXTI_DISABLE_FALLING_EDGE() (EXTI->FTSR1 &= ~(RTC_EXTI_LINE_ALARM_EVENT)) 738 739 /** 740 * @brief Enable rising edge trigger on the RTC Alarm associated Exti line. 741 * @retval None 742 */ 743 #define __HAL_RTC_ALARM_EXTI_ENABLE_RISING_EDGE() (EXTI->RTSR1 |= RTC_EXTI_LINE_ALARM_EVENT) 744 745 /** 746 * @brief Disable rising edge trigger on the RTC Alarm associated Exti line. 747 * @retval None 748 */ 749 #define __HAL_RTC_ALARM_EXTI_DISABLE_RISING_EDGE() (EXTI->RTSR1 &= ~(RTC_EXTI_LINE_ALARM_EVENT)) 750 751 /** 752 * @brief Enable rising & falling edge trigger on the RTC Alarm associated Exti line. 753 * @retval None 754 */ 755 #define __HAL_RTC_ALARM_EXTI_ENABLE_RISING_FALLING_EDGE() do { \ 756 __HAL_RTC_ALARM_EXTI_ENABLE_RISING_EDGE(); \ 757 __HAL_RTC_ALARM_EXTI_ENABLE_FALLING_EDGE(); \ 758 } while(0) 759 760 /** 761 * @brief Disable rising & falling edge trigger on the RTC Alarm associated Exti line. 762 * @retval None 763 */ 764 #define __HAL_RTC_ALARM_EXTI_DISABLE_RISING_FALLING_EDGE() do { \ 765 __HAL_RTC_ALARM_EXTI_DISABLE_RISING_EDGE(); \ 766 __HAL_RTC_ALARM_EXTI_DISABLE_FALLING_EDGE(); \ 767 } while(0) 768 769 /** 770 * @brief set rising edge interrupt on the RTC Alarm associated Exti line. 771 * @retval None 772 */ 773 #define __HAL_RTC_ALARM_EXTI_RISING_IT() (EXTI->RTSR1 |= RTC_EXTI_LINE_ALARM_EVENT) 774 775 /** 776 * @brief set rising edge interrupt on the RTC Alarm associated Exti line. 777 * @retval None 778 */ 779 #define __HAL_RTC_ALARM_EXTI_FALLING_IT() (EXTI->FSTR1 |= RTC_EXTI_LINE_ALARM_EVENT) 780 781 /** 782 * @brief clear interrupt on the RTC Alarm associated Exti line. 783 * @retval None 784 */ 785 #define __HAL_RTC_ALARM_EXTI_CLEAR_IT() (EXTI->PR1 = RTC_EXTI_LINE_ALARM_EVENT) 786 787 788 /** 789 * @} 790 */ 791 792 /* Include RTC HAL Extended module */ 793 #include "stm32g4xx_hal_rtc_ex.h" 794 795 /* Exported functions --------------------------------------------------------*/ 796 /** @defgroup RTC_Exported_Functions RTC Exported Functions 797 * @{ 798 */ 799 800 /** @defgroup RTC_Exported_Functions_Group1 Initialization and de-initialization functions 801 * @{ 802 */ 803 /* Initialization and de-initialization functions ****************************/ 804 HAL_StatusTypeDef HAL_RTC_Init(RTC_HandleTypeDef *hrtc); 805 HAL_StatusTypeDef HAL_RTC_DeInit(RTC_HandleTypeDef *hrtc); 806 807 void HAL_RTC_MspInit(RTC_HandleTypeDef *hrtc); 808 void HAL_RTC_MspDeInit(RTC_HandleTypeDef *hrtc); 809 #if (USE_HAL_RTC_REGISTER_CALLBACKS == 1) 810 811 /* Callbacks Register/UnRegister functions ***********************************/ 812 HAL_StatusTypeDef HAL_RTC_RegisterCallback(RTC_HandleTypeDef *hrtc, HAL_RTC_CallbackIDTypeDef CallbackID, 813 pRTC_CallbackTypeDef pCallback); 814 HAL_StatusTypeDef HAL_RTC_UnRegisterCallback(RTC_HandleTypeDef *hrtc, HAL_RTC_CallbackIDTypeDef CallbackID); 815 #endif /* USE_HAL_RTC_REGISTER_CALLBACKS */ 816 /** 817 * @} 818 */ 819 820 /** @defgroup RTC_Exported_Functions_Group2 RTC Time and Date functions 821 * @{ 822 */ 823 /* RTC Time and Date functions ************************************************/ 824 HAL_StatusTypeDef HAL_RTC_SetTime(RTC_HandleTypeDef *hrtc, RTC_TimeTypeDef *sTime, uint32_t Format); 825 HAL_StatusTypeDef HAL_RTC_GetTime(RTC_HandleTypeDef *hrtc, RTC_TimeTypeDef *sTime, uint32_t Format); 826 HAL_StatusTypeDef HAL_RTC_SetDate(RTC_HandleTypeDef *hrtc, RTC_DateTypeDef *sDate, uint32_t Format); 827 HAL_StatusTypeDef HAL_RTC_GetDate(RTC_HandleTypeDef *hrtc, RTC_DateTypeDef *sDate, uint32_t Format); 828 void HAL_RTC_DST_Add1Hour(RTC_HandleTypeDef *hrtc); 829 void HAL_RTC_DST_Sub1Hour(RTC_HandleTypeDef *hrtc); 830 void HAL_RTC_DST_SetStoreOperation(RTC_HandleTypeDef *hrtc); 831 void HAL_RTC_DST_ClearStoreOperation(RTC_HandleTypeDef *hrtc); 832 uint32_t HAL_RTC_DST_ReadStoreOperation(RTC_HandleTypeDef *hrtc); 833 /** 834 * @} 835 */ 836 837 /** @defgroup RTC_Exported_Functions_Group3 RTC Alarm functions 838 * @{ 839 */ 840 /* RTC Alarm functions ********************************************************/ 841 HAL_StatusTypeDef HAL_RTC_SetAlarm(RTC_HandleTypeDef *hrtc, RTC_AlarmTypeDef *sAlarm, uint32_t Format); 842 HAL_StatusTypeDef HAL_RTC_SetAlarm_IT(RTC_HandleTypeDef *hrtc, RTC_AlarmTypeDef *sAlarm, uint32_t Format); 843 HAL_StatusTypeDef HAL_RTC_DeactivateAlarm(RTC_HandleTypeDef *hrtc, uint32_t Alarm); 844 HAL_StatusTypeDef HAL_RTC_GetAlarm(RTC_HandleTypeDef *hrtc, RTC_AlarmTypeDef *sAlarm, uint32_t Alarm, uint32_t Format); 845 void HAL_RTC_AlarmIRQHandler(RTC_HandleTypeDef *hrtc); 846 HAL_StatusTypeDef HAL_RTC_PollForAlarmAEvent(RTC_HandleTypeDef *hrtc, uint32_t Timeout); 847 void HAL_RTC_AlarmAEventCallback(RTC_HandleTypeDef *hrtc); 848 /** 849 * @} 850 */ 851 852 /** @defgroup RTC_Exported_Functions_Group4 Peripheral Control functions 853 * @{ 854 */ 855 /* Peripheral Control functions ***********************************************/ 856 HAL_StatusTypeDef HAL_RTC_WaitForSynchro(RTC_HandleTypeDef *hrtc); 857 /** 858 * @} 859 */ 860 861 /** @defgroup RTC_Exported_Functions_Group5 Peripheral State functions 862 * @{ 863 */ 864 /* Peripheral State functions *************************************************/ 865 HAL_RTCStateTypeDef HAL_RTC_GetState(RTC_HandleTypeDef *hrtc); 866 /** 867 * @} 868 */ 869 870 /** 871 * @} 872 */ 873 874 /* Private types -------------------------------------------------------------*/ 875 /* Private variables ---------------------------------------------------------*/ 876 /* Private constants ---------------------------------------------------------*/ 877 /** @defgroup RTC_Private_Constants RTC Private Constants 878 * @{ 879 */ 880 /* Masks Definition */ 881 #define RTC_TR_RESERVED_MASK (RTC_TR_PM | RTC_TR_HT | RTC_TR_HU | \ 882 RTC_TR_MNT | RTC_TR_MNU| RTC_TR_ST | \ 883 RTC_TR_SU) 884 #define RTC_DR_RESERVED_MASK (RTC_DR_YT | RTC_DR_YU | RTC_DR_WDU | \ 885 RTC_DR_MT | RTC_DR_MU | RTC_DR_DT | \ 886 RTC_DR_DU) 887 #define RTC_ICSR_RESERVED_MASK (RTC_ICSR_RECALPF | RTC_ICSR_INIT | RTC_ICSR_INITF | \ 888 RTC_ICSR_RSF | RTC_ICSR_INITS | RTC_ICSR_SHPF | \ 889 RTC_ICSR_WUTWF | RTC_ICSR_ALRBWF | RTC_ICSR_ALRAWF) 890 #define RTC_RSF_MASK (~(RTC_ICSR_INIT | RTC_ICSR_RSF)) 891 #define RTC_INIT_MASK 0xFFFFFFFFU 892 893 #define RTC_TIMEOUT_VALUE 1000U 894 895 /** 896 * @} 897 */ 898 899 /* Private macros ------------------------------------------------------------*/ 900 /** @defgroup RTC_Private_Macros RTC Private Macros 901 * @{ 902 */ 903 904 /** @defgroup RTC_IS_RTC_Definitions RTC Private macros to check input parameters 905 * @{ 906 */ 907 #define IS_RTC_OUTPUT(OUTPUT) (((OUTPUT) == RTC_OUTPUT_DISABLE) || \ 908 ((OUTPUT) == RTC_OUTPUT_ALARMA) || \ 909 ((OUTPUT) == RTC_OUTPUT_ALARMB) || \ 910 ((OUTPUT) == RTC_OUTPUT_WAKEUP) || \ 911 ((OUTPUT) == RTC_OUTPUT_TAMPER)) 912 913 #define IS_RTC_HOUR_FORMAT(FORMAT) (((FORMAT) == RTC_HOURFORMAT_12) || \ 914 ((FORMAT) == RTC_HOURFORMAT_24)) 915 916 #define IS_RTC_OUTPUT_POL(POL) (((POL) == RTC_OUTPUT_POLARITY_HIGH) || \ 917 ((POL) == RTC_OUTPUT_POLARITY_LOW)) 918 919 #define IS_RTC_OUTPUT_TYPE(TYPE) (((TYPE) == RTC_OUTPUT_TYPE_OPENDRAIN) || \ 920 ((TYPE) == RTC_OUTPUT_TYPE_PUSHPULL)) 921 922 #define IS_RTC_OUTPUT_PULLUP(TYPE) (((TYPE) == RTC_OUTPUT_PULLUP_NONE) || \ 923 ((TYPE) == RTC_OUTPUT_PULLUP_ON)) 924 925 #define IS_RTC_OUTPUT_REMAP(REMAP) (((REMAP) == RTC_OUTPUT_REMAP_NONE) || \ 926 ((REMAP) == RTC_OUTPUT_REMAP_POS1)) 927 928 #define IS_RTC_HOURFORMAT12(PM) (((PM) == RTC_HOURFORMAT12_AM) || \ 929 ((PM) == RTC_HOURFORMAT12_PM)) 930 931 #define IS_RTC_DAYLIGHT_SAVING(SAVE) (((SAVE) == RTC_DAYLIGHTSAVING_SUB1H) || \ 932 ((SAVE) == RTC_DAYLIGHTSAVING_ADD1H) || \ 933 ((SAVE) == RTC_DAYLIGHTSAVING_NONE)) 934 935 #define IS_RTC_STORE_OPERATION(OPERATION) (((OPERATION) == RTC_STOREOPERATION_RESET) || \ 936 ((OPERATION) == RTC_STOREOPERATION_SET)) 937 938 #define IS_RTC_FORMAT(FORMAT) (((FORMAT) == RTC_FORMAT_BIN) || \ 939 ((FORMAT) == RTC_FORMAT_BCD)) 940 941 #define IS_RTC_YEAR(YEAR) ((YEAR) <= 99u) 942 943 #define IS_RTC_MONTH(MONTH) (((MONTH) >= 1u) && ((MONTH) <= 12u)) 944 945 #define IS_RTC_DATE(DATE) (((DATE) >= 1u) && ((DATE) <= 31u)) 946 947 #define IS_RTC_WEEKDAY(WEEKDAY) (((WEEKDAY) == RTC_WEEKDAY_MONDAY) || \ 948 ((WEEKDAY) == RTC_WEEKDAY_TUESDAY) || \ 949 ((WEEKDAY) == RTC_WEEKDAY_WEDNESDAY) || \ 950 ((WEEKDAY) == RTC_WEEKDAY_THURSDAY) || \ 951 ((WEEKDAY) == RTC_WEEKDAY_FRIDAY) || \ 952 ((WEEKDAY) == RTC_WEEKDAY_SATURDAY) || \ 953 ((WEEKDAY) == RTC_WEEKDAY_SUNDAY)) 954 955 #define IS_RTC_ALARM_DATE_WEEKDAY_DATE(DATE) (((DATE) >0u) && ((DATE) <= 31u)) 956 957 #define IS_RTC_ALARM_DATE_WEEKDAY_WEEKDAY(WEEKDAY) (((WEEKDAY) == RTC_WEEKDAY_MONDAY) || \ 958 ((WEEKDAY) == RTC_WEEKDAY_TUESDAY) || \ 959 ((WEEKDAY) == RTC_WEEKDAY_WEDNESDAY) || \ 960 ((WEEKDAY) == RTC_WEEKDAY_THURSDAY) || \ 961 ((WEEKDAY) == RTC_WEEKDAY_FRIDAY) || \ 962 ((WEEKDAY) == RTC_WEEKDAY_SATURDAY) || \ 963 ((WEEKDAY) == RTC_WEEKDAY_SUNDAY)) 964 965 #define IS_RTC_ALARM_DATE_WEEKDAY_SEL(SEL) (((SEL) == RTC_ALARMDATEWEEKDAYSEL_DATE) || \ 966 ((SEL) == RTC_ALARMDATEWEEKDAYSEL_WEEKDAY)) 967 968 #define IS_RTC_ALARM_MASK(MASK) (((MASK) & ~(RTC_ALARMMASK_ALL)) == 0UL) 969 970 #define IS_RTC_ALARM(ALARM) (((ALARM) == RTC_ALARM_A) || \ 971 ((ALARM) == RTC_ALARM_B)) 972 973 #define IS_RTC_ALARM_SUB_SECOND_VALUE(VALUE) ((VALUE) <= RTC_ALRMASSR_SS) 974 975 #define IS_RTC_ALARM_SUB_SECOND_MASK(MASK) (((MASK) == 0UL) || \ 976 (((MASK) >= RTC_ALARMSUBSECONDMASK_SS14_1) && ((MASK) <= RTC_ALARMSUBSECONDMASK_NONE))) 977 978 #define IS_RTC_ASYNCH_PREDIV(PREDIV) ((PREDIV) <= (RTC_PRER_PREDIV_A >> RTC_PRER_PREDIV_A_Pos)) 979 980 #define IS_RTC_SYNCH_PREDIV(PREDIV) ((PREDIV) <= (RTC_PRER_PREDIV_S >> RTC_PRER_PREDIV_S_Pos)) 981 982 #define IS_RTC_HOUR12(HOUR) (((HOUR) > 0u) && ((HOUR) <= 12u)) 983 984 #define IS_RTC_HOUR24(HOUR) ((HOUR) <= 23u) 985 986 #define IS_RTC_MINUTES(MINUTES) ((MINUTES) <= 59u) 987 988 #define IS_RTC_SECONDS(SECONDS) ((SECONDS) <= 59u) 989 990 /** 991 * @} 992 */ 993 994 /** 995 * @} 996 */ 997 998 /* Private functions -------------------------------------------------------------*/ 999 /** @defgroup RTC_Private_Functions RTC Private Functions 1000 * @{ 1001 */ 1002 HAL_StatusTypeDef RTC_EnterInitMode(RTC_HandleTypeDef *hrtc); 1003 HAL_StatusTypeDef RTC_ExitInitMode(RTC_HandleTypeDef *hrtc); 1004 uint8_t RTC_ByteToBcd2(uint8_t Value); 1005 uint8_t RTC_Bcd2ToByte(uint8_t Value); 1006 /** 1007 * @} 1008 */ 1009 1010 1011 /** 1012 * @} 1013 */ 1014 1015 /** 1016 * @} 1017 */ 1018 1019 #ifdef __cplusplus 1020 } 1021 #endif 1022 1023 #endif /* STM32G4xx_HAL_RTC_H */ 1024