1 /** 2 ****************************************************************************** 3 * @file stm32h7xx_hal_rtc.h 4 * @author MCD Application Team 5 * @brief Header file of RTC HAL module. 6 ****************************************************************************** 7 * @attention 8 * 9 * Copyright (c) 2017 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 STM32H7xx_HAL_RTC_H 21 #define STM32H7xx_HAL_RTC_H 22 23 #ifdef __cplusplus 24 extern "C" { 25 #endif 26 27 /* Includes ------------------------------------------------------------------*/ 28 #include "stm32h7xx_hal_def.h" 29 30 /** @addtogroup STM32H7xx_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_Definitions */ 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 RTC_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 #if defined(TAMP) 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 #endif /* TAMP */ 85 } RTC_InitTypeDef; 86 87 /** 88 * @brief RTC Time structure definition 89 */ 90 typedef struct 91 { 92 uint8_t Hours; /*!< Specifies the RTC Time Hour. 93 This parameter must be a number between Min_Data = 0 and Max_Data = 12 if the RTC_HourFormat_12 is selected. 94 This parameter must be a number between Min_Data = 0 and Max_Data = 23 if the RTC_HourFormat_24 is selected */ 95 96 uint8_t Minutes; /*!< Specifies the RTC Time Minutes. 97 This parameter must be a number between Min_Data = 0 and Max_Data = 59 */ 98 99 uint8_t Seconds; /*!< Specifies the RTC Time Seconds. 100 This parameter must be a number between Min_Data = 0 and Max_Data = 59 */ 101 102 uint8_t TimeFormat; /*!< Specifies the RTC AM/PM Time. 103 This parameter can be a value of @ref RTC_AM_PM_Definitions */ 104 105 uint32_t SubSeconds; /*!< Specifies the RTC_SSR RTC Sub Second register content. 106 This parameter corresponds to a time unit range between [0-1] Second 107 with [1 Sec / SecondFraction +1] granularity */ 108 109 uint32_t SecondFraction; /*!< Specifies the range or granularity of Sub Second register content 110 corresponding to Synchronous pre-scaler factor value (PREDIV_S) 111 This parameter corresponds to a time unit range between [0-1] Second 112 with [1 Sec / SecondFraction +1] granularity. 113 This field will be used only by HAL_RTC_GetTime function */ 114 115 uint32_t DayLightSaving; /*!< Specifies RTC_DayLightSaveOperation: the value of hour adjustment. 116 This parameter can be a value of @ref RTC_DayLightSaving_Definitions */ 117 118 uint32_t StoreOperation; /*!< Specifies RTC_StoreOperation value to be written in the BKP bit 119 in CR register to store the operation. 120 This parameter can be a value of @ref RTC_StoreOperation_Definitions */ 121 } RTC_TimeTypeDef; 122 123 /** 124 * @brief RTC Date structure definition 125 */ 126 typedef struct 127 { 128 uint8_t WeekDay; /*!< Specifies the RTC Date WeekDay. 129 This parameter can be a value of @ref RTC_WeekDay_Definitions */ 130 131 uint8_t Month; /*!< Specifies the RTC Date Month (in BCD format). 132 This parameter can be a value of @ref RTC_Month_Date_Definitions */ 133 134 uint8_t Date; /*!< Specifies the RTC Date. 135 This parameter must be a number between Min_Data = 1 and Max_Data = 31 */ 136 137 uint8_t Year; /*!< Specifies the RTC Date Year. 138 This parameter must be a number between Min_Data = 0 and Max_Data = 99 */ 139 140 } RTC_DateTypeDef; 141 142 /** 143 * @brief RTC Alarm structure definition 144 */ 145 typedef struct 146 { 147 RTC_TimeTypeDef AlarmTime; /*!< Specifies the RTC Alarm Time members */ 148 149 uint32_t AlarmMask; /*!< Specifies the RTC Alarm Masks. 150 This parameter can be a value of @ref RTC_AlarmMask_Definitions */ 151 152 uint32_t AlarmSubSecondMask; /*!< Specifies the RTC Alarm SubSeconds Masks. 153 This parameter can be a value of @ref RTC_Alarm_Sub_Seconds_Masks_Definitions */ 154 155 uint32_t AlarmDateWeekDaySel; /*!< Specifies the RTC Alarm is on Date or WeekDay. 156 This parameter can be a value of @ref RTC_AlarmDateWeekDay_Definitions */ 157 158 uint8_t AlarmDateWeekDay; /*!< Specifies the RTC Alarm Date/WeekDay. 159 If the Alarm Date is selected, this parameter must be set to a value in the 1-31 range. 160 If the Alarm WeekDay is selected, this parameter can be a value of @ref RTC_WeekDay_Definitions */ 161 162 uint32_t Alarm; /*!< Specifies the alarm . 163 This parameter can be a value of @ref RTC_Alarms_Definitions */ 164 } RTC_AlarmTypeDef; 165 166 /** 167 * @brief RTC Handle Structure definition 168 */ 169 #if (USE_HAL_RTC_REGISTER_CALLBACKS == 1) 170 typedef struct __RTC_HandleTypeDef 171 #else 172 typedef struct 173 #endif /* (USE_HAL_RTC_REGISTER_CALLBACKS) */ 174 { 175 RTC_TypeDef *Instance; /*!< Register base address */ 176 177 RTC_InitTypeDef Init; /*!< RTC required parameters */ 178 179 HAL_LockTypeDef Lock; /*!< RTC locking object */ 180 181 __IO HAL_RTCStateTypeDef State; /*!< Time communication state */ 182 183 #if (USE_HAL_RTC_REGISTER_CALLBACKS == 1) 184 void (* AlarmAEventCallback)(struct __RTC_HandleTypeDef *hrtc); /*!< RTC Alarm A Event callback */ 185 186 void (* AlarmBEventCallback)(struct __RTC_HandleTypeDef *hrtc); /*!< RTC Alarm B Event callback */ 187 188 void (* TimeStampEventCallback)(struct __RTC_HandleTypeDef *hrtc); /*!< RTC TimeStamp Event callback */ 189 190 void (* WakeUpTimerEventCallback)(struct __RTC_HandleTypeDef *hrtc); /*!< RTC WakeUpTimer Event callback */ 191 192 void (* Tamper1EventCallback)(struct __RTC_HandleTypeDef *hrtc); /*!< RTC Tamper 1 Event callback */ 193 194 void (* Tamper2EventCallback)(struct __RTC_HandleTypeDef *hrtc); /*!< RTC Tamper 2 Event callback */ 195 196 void (* Tamper3EventCallback)(struct __RTC_HandleTypeDef *hrtc); /*!< RTC Tamper 3 Event callback */ 197 198 #if defined(TAMP) 199 void (* InternalTamper1EventCallback)(struct __RTC_HandleTypeDef *hrtc); /*!< RTC Internal Tamper 1 Event callback */ 200 201 void (* InternalTamper2EventCallback)(struct __RTC_HandleTypeDef *hrtc); /*!< RTC Internal Tamper 2 Event callback */ 202 203 void (* InternalTamper3EventCallback)(struct __RTC_HandleTypeDef *hrtc); /*!< RTC Internal Tamper 3 Event callback */ 204 205 void (* InternalTamper4EventCallback)(struct __RTC_HandleTypeDef *hrtc); /*!< RTC Internal Tamper 4 Event callback */ 206 207 void (* InternalTamper5EventCallback)(struct __RTC_HandleTypeDef *hrtc); /*!< RTC Internal Tamper 5 Event callback */ 208 209 void (* InternalTamper6EventCallback)(struct __RTC_HandleTypeDef *hrtc); /*!< RTC Internal Tamper 6 Event callback */ 210 211 void (* InternalTamper8EventCallback)(struct __RTC_HandleTypeDef *hrtc); /*!< RTC Internal Tamper 8 Event callback */ 212 #endif /* TAMP */ 213 214 void (* MspInitCallback)(struct __RTC_HandleTypeDef *hrtc); /*!< RTC Msp Init callback */ 215 216 void (* MspDeInitCallback)(struct __RTC_HandleTypeDef *hrtc); /*!< RTC Msp DeInit callback */ 217 218 #endif /* (USE_HAL_RTC_REGISTER_CALLBACKS == 1) */ 219 220 } RTC_HandleTypeDef; 221 222 #if (USE_HAL_RTC_REGISTER_CALLBACKS == 1) 223 /** 224 * @brief HAL RTC Callback ID enumeration definition 225 */ 226 typedef enum 227 { 228 HAL_RTC_ALARM_A_EVENT_CB_ID = 0u, /*!< RTC Alarm A Event Callback ID */ 229 HAL_RTC_ALARM_B_EVENT_CB_ID = 1u, /*!< RTC Alarm B Event Callback ID */ 230 HAL_RTC_TIMESTAMP_EVENT_CB_ID = 2u, /*!< RTC TimeStamp Event Callback ID */ 231 HAL_RTC_WAKEUPTIMER_EVENT_CB_ID = 3u, /*!< RTC WakeUp Timer Event Callback ID */ 232 HAL_RTC_TAMPER1_EVENT_CB_ID = 4u, /*!< RTC Tamper 1 Callback ID */ 233 HAL_RTC_TAMPER2_EVENT_CB_ID = 5u, /*!< RTC Tamper 2 Callback ID */ 234 HAL_RTC_TAMPER3_EVENT_CB_ID = 6u, /*!< RTC Tamper 3 Callback ID */ 235 #if defined(TAMP) 236 HAL_RTC_INTERNAL_TAMPER1_EVENT_CB_ID = 12u, /*!< RTC Internal Tamper 1 Callback ID */ 237 HAL_RTC_INTERNAL_TAMPER2_EVENT_CB_ID = 13u, /*!< RTC Internal Tamper 2 Callback ID */ 238 HAL_RTC_INTERNAL_TAMPER3_EVENT_CB_ID = 14u, /*!< RTC Internal Tamper 3 Callback ID */ 239 HAL_RTC_INTERNAL_TAMPER4_EVENT_CB_ID = 15u, /*!< RTC Internal Tamper 4 Callback ID */ 240 HAL_RTC_INTERNAL_TAMPER5_EVENT_CB_ID = 16u, /*!< RTC Internal Tamper 5 Callback ID */ 241 HAL_RTC_INTERNAL_TAMPER6_EVENT_CB_ID = 17u, /*!< RTC Internal Tamper 6 Callback ID */ 242 HAL_RTC_INTERNAL_TAMPER8_EVENT_CB_ID = 19u, /*!< RTC Internal Tamper 8 Callback ID */ 243 #endif /* TAMP */ 244 HAL_RTC_MSPINIT_CB_ID = 20u, /*!< RTC Msp Init callback ID */ 245 HAL_RTC_MSPDEINIT_CB_ID = 21u /*!< RTC Msp DeInit callback ID */ 246 } HAL_RTC_CallbackIDTypeDef; 247 248 /** 249 * @brief HAL RTC Callback pointer definition 250 */ 251 typedef void (*pRTC_CallbackTypeDef)(RTC_HandleTypeDef *hrtc); /*!< pointer to an RTC callback function */ 252 #endif /* (USE_HAL_RTC_REGISTER_CALLBACKS == 1) */ 253 254 /** 255 * @} 256 */ 257 258 /* Exported constants --------------------------------------------------------*/ 259 /** @defgroup RTC_Exported_Constants RTC Exported Constants 260 * @{ 261 */ 262 263 /** @defgroup RTC_Hour_Formats_Definitions RTC Hour Formats Definitions 264 * @{ 265 */ 266 #define RTC_HOURFORMAT_24 0x00000000u 267 #define RTC_HOURFORMAT_12 RTC_CR_FMT 268 /** 269 * @} 270 */ 271 272 /** @defgroup RTC_Output_selection_Definitions RTC Output Selection Definitions 273 * @{ 274 */ 275 #define RTC_OUTPUT_DISABLE 0x00000000u 276 #define RTC_OUTPUT_ALARMA RTC_CR_OSEL_0 277 #define RTC_OUTPUT_ALARMB RTC_CR_OSEL_1 278 #define RTC_OUTPUT_WAKEUP RTC_CR_OSEL 279 #if defined(TAMP) 280 #define RTC_OUTPUT_TAMPER RTC_CR_TAMPOE 281 #endif /* TAMP */ 282 /** 283 * @} 284 */ 285 286 /** @defgroup RTC_Output_Polarity_Definitions RTC Output Polarity Definitions 287 * @{ 288 */ 289 #define RTC_OUTPUT_POLARITY_HIGH 0x00000000u 290 #define RTC_OUTPUT_POLARITY_LOW RTC_CR_POL 291 /** 292 * @} 293 */ 294 295 /** @defgroup RTC_Output_Type_ALARM_OUT RTC Output Type ALARM OUT 296 * @{ 297 */ 298 #if defined(TAMP) 299 #define RTC_OUTPUT_TYPE_PUSHPULL 0x00000000u 300 #define RTC_OUTPUT_TYPE_OPENDRAIN RTC_CR_TAMPALRM_TYPE 301 #define RTC_ALARM_OUTPUT_TYPE RTC_CR_TAMPALRM_TYPE 302 #else 303 #define RTC_OUTPUT_TYPE_PUSHPULL RTC_OR_ALARMOUTTYPE 304 #define RTC_OUTPUT_TYPE_OPENDRAIN 0x00000000u 305 #define RTC_ALARM_OUTPUT_TYPE RTC_OR_ALARMOUTTYPE 306 #endif /* TAMP */ 307 /** 308 * @} 309 */ 310 311 /** @defgroup RTC_Output_PullUp_ALARM_OUT RTC Output Pull-Up ALARM OUT 312 * @{ 313 */ 314 #if defined(TAMP) 315 #define RTC_OUTPUT_PULLUP_NONE 0x00000000u 316 #define RTC_OUTPUT_PULLUP_ON RTC_CR_TAMPALRM_PU 317 #endif /* TAMP */ 318 /** 319 * @} 320 */ 321 322 /** @defgroup RTC_Output_ALARM_OUT_Remap RTC Output ALARM OUT Remap 323 * @{ 324 */ 325 #if defined(TAMP) 326 #define RTC_OUTPUT_REMAP_NONE 0x00000000u 327 #define RTC_OUTPUT_REMAP_POS1 RTC_CR_OUT2EN 328 #else 329 #define RTC_OUTPUT_REMAP_NONE 0x00000000u 330 #define RTC_OUTPUT_REMAP_POS1 RTC_OR_OUT_RMP 331 #endif /* TAMP */ 332 /** 333 * @} 334 */ 335 336 /** @defgroup RTC_AM_PM_Definitions RTC AM PM Definitions 337 * @{ 338 */ 339 #define RTC_HOURFORMAT12_AM ((uint8_t)0x00) 340 #define RTC_HOURFORMAT12_PM ((uint8_t)0x01) 341 /** 342 * @} 343 */ 344 345 /** @defgroup RTC_DayLightSaving_Definitions RTC DayLight Saving Definitions 346 * @{ 347 */ 348 #define RTC_DAYLIGHTSAVING_SUB1H RTC_CR_SUB1H 349 #define RTC_DAYLIGHTSAVING_ADD1H RTC_CR_ADD1H 350 #define RTC_DAYLIGHTSAVING_NONE 0x00000000u 351 /** 352 * @} 353 */ 354 355 /** @defgroup RTC_StoreOperation_Definitions RTC Store Operation Definitions 356 * @{ 357 */ 358 #define RTC_STOREOPERATION_RESET 0x00000000u 359 #define RTC_STOREOPERATION_SET RTC_CR_BKP 360 /** 361 * @} 362 */ 363 364 /** @defgroup RTC_Input_parameter_format_definitions RTC Input Parameter Format Definitions 365 * @{ 366 */ 367 #define RTC_FORMAT_BIN 0x00000000u 368 #define RTC_FORMAT_BCD 0x00000001u 369 /** 370 * @} 371 */ 372 373 /** @defgroup RTC_Month_Date_Definitions RTC Month Date Definitions (in BCD format) 374 * @{ 375 */ 376 #define RTC_MONTH_JANUARY ((uint8_t)0x01) 377 #define RTC_MONTH_FEBRUARY ((uint8_t)0x02) 378 #define RTC_MONTH_MARCH ((uint8_t)0x03) 379 #define RTC_MONTH_APRIL ((uint8_t)0x04) 380 #define RTC_MONTH_MAY ((uint8_t)0x05) 381 #define RTC_MONTH_JUNE ((uint8_t)0x06) 382 #define RTC_MONTH_JULY ((uint8_t)0x07) 383 #define RTC_MONTH_AUGUST ((uint8_t)0x08) 384 #define RTC_MONTH_SEPTEMBER ((uint8_t)0x09) 385 #define RTC_MONTH_OCTOBER ((uint8_t)0x10) 386 #define RTC_MONTH_NOVEMBER ((uint8_t)0x11) 387 #define RTC_MONTH_DECEMBER ((uint8_t)0x12) 388 389 /** 390 * @} 391 */ 392 393 /** @defgroup RTC_WeekDay_Definitions RTC WeekDay Definitions 394 * @{ 395 */ 396 #define RTC_WEEKDAY_MONDAY ((uint8_t)0x01) 397 #define RTC_WEEKDAY_TUESDAY ((uint8_t)0x02) 398 #define RTC_WEEKDAY_WEDNESDAY ((uint8_t)0x03) 399 #define RTC_WEEKDAY_THURSDAY ((uint8_t)0x04) 400 #define RTC_WEEKDAY_FRIDAY ((uint8_t)0x05) 401 #define RTC_WEEKDAY_SATURDAY ((uint8_t)0x06) 402 #define RTC_WEEKDAY_SUNDAY ((uint8_t)0x07) 403 404 /** 405 * @} 406 */ 407 408 /** @defgroup RTC_AlarmDateWeekDay_Definitions RTC Alarm Date WeekDay Definitions 409 * @{ 410 */ 411 #define RTC_ALARMDATEWEEKDAYSEL_DATE 0x00000000u 412 #define RTC_ALARMDATEWEEKDAYSEL_WEEKDAY RTC_ALRMAR_WDSEL 413 414 /** 415 * @} 416 */ 417 418 /** @defgroup RTC_AlarmMask_Definitions RTC Alarm Mask Definitions 419 * @{ 420 */ 421 #define RTC_ALARMMASK_NONE 0x00000000u 422 #define RTC_ALARMMASK_DATEWEEKDAY RTC_ALRMAR_MSK4 423 #define RTC_ALARMMASK_HOURS RTC_ALRMAR_MSK3 424 #define RTC_ALARMMASK_MINUTES RTC_ALRMAR_MSK2 425 #define RTC_ALARMMASK_SECONDS RTC_ALRMAR_MSK1 426 #define RTC_ALARMMASK_ALL (RTC_ALARMMASK_DATEWEEKDAY | \ 427 RTC_ALARMMASK_HOURS | \ 428 RTC_ALARMMASK_MINUTES | \ 429 RTC_ALARMMASK_SECONDS) 430 /** 431 * @} 432 */ 433 434 /** @defgroup RTC_Alarms_Definitions RTC Alarms Definitions 435 * @{ 436 */ 437 #define RTC_ALARM_A RTC_CR_ALRAE 438 #define RTC_ALARM_B RTC_CR_ALRBE 439 /** 440 * @} 441 */ 442 443 /** @defgroup RTC_Alarm_Sub_Seconds_Masks_Definitions RTC Alarm Sub Seconds Masks Definitions 444 * @{ 445 */ 446 /*!< All Alarm SS fields are masked. There is no comparison on sub seconds for Alarm */ 447 #define RTC_ALARMSUBSECONDMASK_ALL 0x00000000u 448 /*!< SS[14:1] are don't care in Alarm comparison. Only SS[0] is compared. */ 449 #define RTC_ALARMSUBSECONDMASK_SS14_1 RTC_ALRMASSR_MASKSS_0 450 /*!< SS[14:2] are don't care in Alarm comparison. Only SS[1:0] are compared. */ 451 #define RTC_ALARMSUBSECONDMASK_SS14_2 RTC_ALRMASSR_MASKSS_1 452 /*!< SS[14:3] are don't care in Alarm comparison. Only SS[2:0] are compared. */ 453 #define RTC_ALARMSUBSECONDMASK_SS14_3 (RTC_ALRMASSR_MASKSS_0 | RTC_ALRMASSR_MASKSS_1) 454 /*!< SS[14:4] are don't care in Alarm comparison. Only SS[3:0] are compared. */ 455 #define RTC_ALARMSUBSECONDMASK_SS14_4 RTC_ALRMASSR_MASKSS_2 456 /*!< SS[14:5] are don't care in Alarm comparison. Only SS[4:0] are compared. */ 457 #define RTC_ALARMSUBSECONDMASK_SS14_5 (RTC_ALRMASSR_MASKSS_0 | RTC_ALRMASSR_MASKSS_2) 458 /*!< SS[14:6] are don't care in Alarm comparison. Only SS[5:0] are compared. */ 459 #define RTC_ALARMSUBSECONDMASK_SS14_6 (RTC_ALRMASSR_MASKSS_1 | RTC_ALRMASSR_MASKSS_2) 460 /*!< SS[14:7] are don't care in Alarm comparison. Only SS[6:0] are compared. */ 461 #define RTC_ALARMSUBSECONDMASK_SS14_7 (RTC_ALRMASSR_MASKSS_0 | RTC_ALRMASSR_MASKSS_1 | RTC_ALRMASSR_MASKSS_2) 462 /*!< SS[14:8] are don't care in Alarm comparison. Only SS[7:0] are compared. */ 463 #define RTC_ALARMSUBSECONDMASK_SS14_8 RTC_ALRMASSR_MASKSS_3 464 /*!< SS[14:9] are don't care in Alarm comparison. Only SS[8:0] are compared. */ 465 #define RTC_ALARMSUBSECONDMASK_SS14_9 (RTC_ALRMASSR_MASKSS_0 | RTC_ALRMASSR_MASKSS_3) 466 /*!< SS[14:10] are don't care in Alarm comparison. Only SS[9:0] are compared. */ 467 #define RTC_ALARMSUBSECONDMASK_SS14_10 (RTC_ALRMASSR_MASKSS_1 | RTC_ALRMASSR_MASKSS_3) 468 /*!< SS[14:11] are don't care in Alarm comparison. Only SS[10:0] are compared. */ 469 #define RTC_ALARMSUBSECONDMASK_SS14_11 (RTC_ALRMASSR_MASKSS_0 | RTC_ALRMASSR_MASKSS_1 | RTC_ALRMASSR_MASKSS_3) 470 /*!< SS[14:12] are don't care in Alarm comparison. Only SS[11:0] are compared. */ 471 #define RTC_ALARMSUBSECONDMASK_SS14_12 (RTC_ALRMASSR_MASKSS_2 | RTC_ALRMASSR_MASKSS_3) 472 /*!< SS[14:13] are don't care in Alarm comparison. Only SS[12:0] are compared. */ 473 #define RTC_ALARMSUBSECONDMASK_SS14_13 (RTC_ALRMASSR_MASKSS_0 | RTC_ALRMASSR_MASKSS_2 | RTC_ALRMASSR_MASKSS_3) 474 /*!< SS[14] is don't care in Alarm comparison. Only SS[13:0] are compared. */ 475 #define RTC_ALARMSUBSECONDMASK_SS14 (RTC_ALRMASSR_MASKSS_1 | RTC_ALRMASSR_MASKSS_2 | RTC_ALRMASSR_MASKSS_3) 476 /*!< SS[14:0] are compared and must match to activate alarm. */ 477 #define RTC_ALARMSUBSECONDMASK_NONE RTC_ALRMASSR_MASKSS 478 479 /** 480 * @} 481 */ 482 483 /** @defgroup RTC_Interrupts_Definitions RTC Interrupts Definitions 484 * @{ 485 */ 486 #define RTC_IT_TS RTC_CR_TSIE /*!< Enable Timestamp Interrupt */ 487 #define RTC_IT_WUT RTC_CR_WUTIE /*!< Enable Wakeup timer Interrupt */ 488 #define RTC_IT_ALRA RTC_CR_ALRAIE /*!< Enable Alarm A Interrupt */ 489 #define RTC_IT_ALRB RTC_CR_ALRBIE /*!< Enable Alarm B Interrupt */ 490 /** 491 * @} 492 */ 493 494 /** @defgroup RTC_Flags_Definitions RTC Flags Definitions 495 * @{ 496 */ 497 #if defined(TAMP) 498 #define RTC_FLAG_RECALPF RTC_ICSR_RECALPF /*!< Recalibration pending Flag */ 499 #define RTC_FLAG_INITF RTC_ICSR_INITF /*!< Initialization pending flag */ 500 #define RTC_FLAG_RSF RTC_ICSR_RSF /*!< Registers synchronization flag */ 501 #define RTC_FLAG_INITS RTC_ICSR_INITS /*!< Initialization status flag */ 502 #define RTC_FLAG_SHPF RTC_ICSR_SHPF /*!< Shift operation pending flag */ 503 #define RTC_FLAG_WUTWF RTC_ICSR_WUTWF /*!< Wakeup timer write operation pending flag */ 504 #define RTC_FLAG_ALRBWF RTC_ICSR_ALRBWF /*!< Alarm B write operation pending flag */ 505 #define RTC_FLAG_ALRAWF RTC_ICSR_ALRAWF /*!< Alarm A write operation pending flag */ 506 #define RTC_FLAG_ITSF RTC_SR_ITSF /*!< Internal Time-stamp flag */ 507 #define RTC_FLAG_TSOVF RTC_SR_TSOVF /*!< Time-stamp overflow flag */ 508 #define RTC_FLAG_TSF RTC_SR_TSF /*!< Time-stamp flag */ 509 #define RTC_FLAG_WUTF RTC_SR_WUTF /*!< Wakeup timer flag */ 510 #define RTC_FLAG_ALRBF RTC_SR_ALRBF /*!< Alarm B flag */ 511 #define RTC_FLAG_ALRAF RTC_SR_ALRAF /*!< Alarm A flag */ 512 #else 513 #define RTC_FLAG_RECALPF RTC_ISR_RECALPF 514 #define RTC_FLAG_TSOVF RTC_ISR_TSOVF 515 #define RTC_FLAG_TSF RTC_ISR_TSF 516 #define RTC_FLAG_ITSF RTC_ISR_ITSF 517 #define RTC_FLAG_WUTF RTC_ISR_WUTF 518 #define RTC_FLAG_ALRBF RTC_ISR_ALRBF 519 #define RTC_FLAG_ALRAF RTC_ISR_ALRAF 520 #define RTC_FLAG_INITF RTC_ISR_INITF 521 #define RTC_FLAG_RSF RTC_ISR_RSF 522 #define RTC_FLAG_INITS RTC_ISR_INITS 523 #define RTC_FLAG_SHPF RTC_ISR_SHPF 524 #define RTC_FLAG_WUTWF RTC_ISR_WUTWF 525 #define RTC_FLAG_ALRBWF RTC_ISR_ALRBWF 526 #define RTC_FLAG_ALRAWF RTC_ISR_ALRAWF 527 #endif /* TAMP */ 528 /** 529 * @} 530 */ 531 532 /** @defgroup RTC_Clear_Flags_Definitions RTC Clear Flags Definitions 533 * @{ 534 */ 535 #if defined(TAMP) 536 #define RTC_CLEAR_ITSF RTC_SCR_CITSF /*!< Clear Internal Time-stamp flag */ 537 #define RTC_CLEAR_TSOVF RTC_SCR_CTSOVF /*!< Clear Time-stamp overflow flag */ 538 #define RTC_CLEAR_TSF RTC_SCR_CTSF /*!< Clear Time-stamp flag */ 539 #define RTC_CLEAR_WUTF RTC_SCR_CWUTF /*!< Clear Wakeup timer flag */ 540 #define RTC_CLEAR_ALRBF RTC_SCR_CALRBF /*!< Clear Alarm B flag */ 541 #define RTC_CLEAR_ALRAF RTC_SCR_CALRAF /*!< Clear Alarm A flag */ 542 #endif /* TAMP 543 */ 544 /** 545 * @} 546 */ 547 548 /** 549 * @} 550 */ 551 552 /* Exported macros -----------------------------------------------------------*/ 553 /** @defgroup RTC_Exported_Macros RTC Exported Macros 554 * @{ 555 */ 556 557 /** @brief Reset RTC handle state 558 * @param __HANDLE__ RTC handle. 559 * @retval None 560 */ 561 #if (USE_HAL_RTC_REGISTER_CALLBACKS == 1) 562 #define __HAL_RTC_RESET_HANDLE_STATE(__HANDLE__) do{ \ 563 (__HANDLE__)->State = HAL_RTC_STATE_RESET; \ 564 (__HANDLE__)->MspInitCallback = NULL; \ 565 (__HANDLE__)->MspDeInitCallback = NULL; \ 566 }while(0u) 567 #else 568 #define __HAL_RTC_RESET_HANDLE_STATE(__HANDLE__) ((__HANDLE__)->State = HAL_RTC_STATE_RESET) 569 #endif /* USE_HAL_RTC_REGISTER_CALLBACKS */ 570 571 /** 572 * @brief Disable the write protection for RTC registers. 573 * @param __HANDLE__ specifies the RTC handle. 574 * @retval None 575 */ 576 #define __HAL_RTC_WRITEPROTECTION_DISABLE(__HANDLE__) \ 577 do{ \ 578 (__HANDLE__)->Instance->WPR = 0xCAU; \ 579 (__HANDLE__)->Instance->WPR = 0x53U; \ 580 } while(0u) 581 582 /** 583 * @brief Enable the write protection for RTC registers. 584 * @param __HANDLE__ specifies the RTC handle. 585 * @retval None 586 */ 587 #define __HAL_RTC_WRITEPROTECTION_ENABLE(__HANDLE__) \ 588 do{ \ 589 (__HANDLE__)->Instance->WPR = 0xFFU; \ 590 } while(0u) 591 592 /** 593 * @brief Check whether the RTC Calendar is initialized. 594 * @param __HANDLE__ specifies the RTC handle. 595 * @retval None 596 */ 597 #if defined(TAMP) 598 #define __HAL_RTC_IS_CALENDAR_INITIALIZED(__HANDLE__) (((((__HANDLE__)->Instance->ICSR) & (RTC_FLAG_INITS)) == RTC_FLAG_INITS) ? 1U : 0U) 599 #else 600 #define __HAL_RTC_IS_CALENDAR_INITIALIZED(__HANDLE__) (((((__HANDLE__)->Instance->ISR) & (RTC_FLAG_INITS)) == RTC_FLAG_INITS) ? 1U : 0U) 601 #endif /* TAMP */ 602 603 /** 604 * @brief Add 1 hour (summer time change). 605 * @param __HANDLE__ specifies the RTC handle. 606 * @param __BKP__ Backup 607 * This parameter can be: 608 * @arg @ref RTC_STOREOPERATION_RESET 609 * @arg @ref RTC_STOREOPERATION_SET 610 * @retval None 611 */ 612 #define __HAL_RTC_DAYLIGHT_SAVING_TIME_ADD1H(__HANDLE__, __BKP__) \ 613 do { \ 614 __HAL_RTC_WRITEPROTECTION_DISABLE(__HANDLE__); \ 615 SET_BIT((__HANDLE__)->Instance->CR, RTC_CR_ADD1H); \ 616 MODIFY_REG((__HANDLE__)->Instance->CR, RTC_CR_BKP , (__BKP__)); \ 617 __HAL_RTC_WRITEPROTECTION_ENABLE(__HANDLE__); \ 618 } while(0u); 619 620 /** 621 * @brief Subtract 1 hour (winter time change). 622 * @param __HANDLE__ specifies the RTC handle. 623 * @param __BKP__ Backup 624 * This parameter can be: 625 * @arg @ref RTC_STOREOPERATION_RESET 626 * @arg @ref RTC_STOREOPERATION_SET 627 * @retval None 628 */ 629 #define __HAL_RTC_DAYLIGHT_SAVING_TIME_SUB1H(__HANDLE__, __BKP__) \ 630 do { \ 631 __HAL_RTC_WRITEPROTECTION_DISABLE(__HANDLE__); \ 632 SET_BIT((__HANDLE__)->Instance->CR, RTC_CR_SUB1H); \ 633 MODIFY_REG((__HANDLE__)->Instance->CR, RTC_CR_BKP , (__BKP__)); \ 634 __HAL_RTC_WRITEPROTECTION_ENABLE(__HANDLE__); \ 635 } while(0u); 636 637 /** 638 * @brief Enable the RTC ALARMA peripheral. 639 * @param __HANDLE__ specifies the RTC handle. 640 * @retval None 641 */ 642 #define __HAL_RTC_ALARMA_ENABLE(__HANDLE__) ((__HANDLE__)->Instance->CR |= (RTC_CR_ALRAE)) 643 644 /** 645 * @brief Disable the RTC ALARMA peripheral. 646 * @param __HANDLE__ specifies the RTC handle. 647 * @retval None 648 */ 649 #define __HAL_RTC_ALARMA_DISABLE(__HANDLE__) ((__HANDLE__)->Instance->CR &= ~(RTC_CR_ALRAE)) 650 651 /** 652 * @brief Enable the RTC ALARMB peripheral. 653 * @param __HANDLE__ specifies the RTC handle. 654 * @retval None 655 */ 656 #define __HAL_RTC_ALARMB_ENABLE(__HANDLE__) ((__HANDLE__)->Instance->CR |= (RTC_CR_ALRBE)) 657 658 /** 659 * @brief Disable the RTC ALARMB peripheral. 660 * @param __HANDLE__ specifies the RTC handle. 661 * @retval None 662 */ 663 #define __HAL_RTC_ALARMB_DISABLE(__HANDLE__) ((__HANDLE__)->Instance->CR &= ~(RTC_CR_ALRBE)) 664 665 /** 666 * @brief Enable the RTC Alarm interrupt. 667 * @param __HANDLE__ specifies the RTC handle. 668 * @param __INTERRUPT__ specifies the RTC Alarm interrupt sources to be enabled or disabled. 669 * This parameter can be any combination of the following values: 670 * @arg @ref RTC_IT_ALRA Alarm A interrupt 671 * @arg @ref RTC_IT_ALRB Alarm B interrupt 672 * @retval None 673 */ 674 #define __HAL_RTC_ALARM_ENABLE_IT(__HANDLE__, __INTERRUPT__) ((__HANDLE__)->Instance->CR |= (__INTERRUPT__)) 675 676 /** 677 * @brief Disable the RTC Alarm interrupt. 678 * @param __HANDLE__ specifies the RTC handle. 679 * @param __INTERRUPT__ specifies the RTC Alarm interrupt sources to be enabled or disabled. 680 * This parameter can be any combination of the following values: 681 * @arg @ref RTC_IT_ALRA Alarm A interrupt 682 * @arg @ref RTC_IT_ALRB Alarm B interrupt 683 * @retval None 684 */ 685 #define __HAL_RTC_ALARM_DISABLE_IT(__HANDLE__, __INTERRUPT__) ((__HANDLE__)->Instance->CR &= ~(__INTERRUPT__)) 686 687 /** 688 * @brief Check whether the specified RTC Alarm interrupt has occurred or not. 689 * @param __HANDLE__ specifies the RTC handle. 690 * @param __INTERRUPT__ specifies the RTC Alarm interrupt sources to check. 691 * This parameter can be: 692 * @arg @ref RTC_IT_ALRA Alarm A interrupt 693 * @arg @ref RTC_IT_ALRB Alarm B interrupt 694 * @retval None 695 */ 696 #if defined(TAMP) 697 #define __HAL_RTC_ALARM_GET_IT(__HANDLE__, __INTERRUPT__) (((((__HANDLE__)->Instance->MISR)& (__INTERRUPT__ >> 12)) != 0U)? 1U : 0U) 698 #else 699 #define __HAL_RTC_ALARM_GET_IT(__HANDLE__, __INTERRUPT__) (((((__HANDLE__)->Instance->ISR)& (__INTERRUPT__ >> 4)) != 0U)? 1U : 0U) 700 #endif /* TAMP */ 701 702 /** 703 * @brief Check whether the specified RTC Alarm interrupt has been enabled or not. 704 * @param __HANDLE__ specifies the RTC handle. 705 * @param __INTERRUPT__ specifies the RTC Alarm interrupt sources to check. 706 * This parameter can be: 707 * @arg @ref RTC_IT_ALRA Alarm A interrupt 708 * @arg @ref RTC_IT_ALRB Alarm B interrupt 709 * @retval None 710 */ 711 #define __HAL_RTC_ALARM_GET_IT_SOURCE(__HANDLE__, __INTERRUPT__) (((((__HANDLE__)->Instance->CR) & (__INTERRUPT__)) != 0U) ? 1U : 0U) 712 713 #if defined(TAMP) 714 /** 715 * @brief Get the selected RTC Alarm's flag status. 716 * @param __HANDLE__ specifies the RTC handle. 717 * @param __FLAG__ specifies the RTC Alarm Flag sources to check. 718 * This parameter can be: 719 * @arg @ref RTC_FLAG_ALRAF 720 * @arg @ref RTC_FLAG_ALRBF 721 * @retval None 722 */ 723 #define __HAL_RTC_ALARM_GET_FLAG(__HANDLE__, __FLAG__) (((((__HANDLE__)->Instance->SR) & (__FLAG__)) != 0U) ? 1U : 0U) 724 #else 725 /** 726 * @brief Get the selected RTC Alarm's flag status. 727 * @param __HANDLE__ specifies the RTC handle. 728 * @param __FLAG__ specifies the RTC Alarm Flag sources to check. 729 * This parameter can be: 730 * @arg @ref RTC_FLAG_ALRAF 731 * @arg @ref RTC_FLAG_ALRBF 732 * @arg @ref RTC_FLAG_ALRAWF 733 * @arg @ref RTC_FLAG_ALRBWF 734 * @retval None 735 */ 736 #define __HAL_RTC_ALARM_GET_FLAG(__HANDLE__, __FLAG__) (((((__HANDLE__)->Instance->ISR) & (__FLAG__)) != 0U) ? 1U : 0U) 737 #endif /* TAMP */ 738 739 /** 740 * @brief Clear the RTC Alarm's pending flags. 741 * @param __HANDLE__ specifies the RTC handle. 742 * @param __FLAG__ specifies the RTC Alarm Flag sources to clear. 743 * This parameter can be: 744 * @arg @ref RTC_FLAG_ALRAF 745 * @arg @ref RTC_FLAG_ALRBF 746 * @retval None 747 */ 748 #if defined(TAMP) 749 #define __HAL_RTC_ALARM_CLEAR_FLAG(__HANDLE__, __FLAG__) ((__HANDLE__)->Instance->SCR = __FLAG__) 750 #else 751 #define __HAL_RTC_ALARM_CLEAR_FLAG(__HANDLE__, __FLAG__) ((__HANDLE__)->Instance->ISR = (~((__FLAG__) | RTC_ISR_INIT)|((__HANDLE__)->Instance->ISR & RTC_ISR_INIT))) 752 #endif /* TAMP */ 753 754 755 /** 756 * @brief Enable interrupt on the RTC Alarm associated Exti line. 757 * @retval None 758 */ 759 #if defined(EXTI_D1) 760 #define __HAL_RTC_ALARM_EXTI_ENABLE_IT() (EXTI_D1->IMR1 |= RTC_EXTI_LINE_ALARM_EVENT) 761 #else /* EXTI */ 762 #define __HAL_RTC_ALARM_EXTI_ENABLE_IT() (EXTI->IMR1 |= RTC_EXTI_LINE_ALARM_EVENT) 763 #endif /* EXTI_D1 */ 764 765 /** 766 * @brief Disable interrupt on the RTC Alarm associated Exti line. 767 * @retval None 768 */ 769 #if defined(EXTI_D1) 770 #define __HAL_RTC_ALARM_EXTI_DISABLE_IT() (EXTI_D1->IMR1 &= ~(RTC_EXTI_LINE_ALARM_EVENT)) 771 #else /* EXTI */ 772 #define __HAL_RTC_ALARM_EXTI_DISABLE_IT() (EXTI->IMR1 &= ~(RTC_EXTI_LINE_ALARM_EVENT)) 773 #endif /* EXTI_D1 */ 774 775 /** 776 * @brief Enable event on the RTC Alarm associated Exti line. 777 * @retval None. 778 */ 779 #if defined(EXTI_D1) 780 #define __HAL_RTC_ALARM_EXTI_ENABLE_EVENT() (EXTI_D1->EMR1 |= RTC_EXTI_LINE_ALARM_EVENT) 781 #else /* EXTI */ 782 #define __HAL_RTC_ALARM_EXTI_ENABLE_EVENT() (EXTI->EMR1 |= RTC_EXTI_LINE_ALARM_EVENT) 783 #endif /* EXTI_D1 */ 784 785 /** 786 * @brief Disable event on the RTC Alarm associated Exti line. 787 * @retval None. 788 */ 789 #if defined(EXTI_D1) 790 #define __HAL_RTC_ALARM_EXTI_DISABLE_EVENT() (EXTI_D1->EMR1 &= ~(RTC_EXTI_LINE_ALARM_EVENT)) 791 #else /* EXTI */ 792 #define __HAL_RTC_ALARM_EXTI_DISABLE_EVENT() (EXTI->EMR1 &= ~(RTC_EXTI_LINE_ALARM_EVENT)) 793 #endif /* EXTI_D1 */ 794 795 #if defined(DUAL_CORE) 796 /** 797 * @brief Enable interrupt on the RTC Alarm associated D2 Exti line. 798 * @retval None 799 */ 800 #define __HAL_RTC_ALARM_EXTID2_ENABLE_IT() (EXTI_D2->IMR1 |= RTC_EXTI_LINE_ALARM_EVENT) 801 802 /** 803 * @brief Disable interrupt on the RTC Alarm associated D2 Exti line. 804 * @retval None 805 */ 806 #define __HAL_RTC_ALARM_EXTID2_DISABLE_IT() (EXTI_D2->IMR1 &= ~(RTC_EXTI_LINE_ALARM_EVENT)) 807 808 /** 809 * @brief Enable event on the RTC Alarm associated D2 Exti line. 810 * @retval None 811 */ 812 #define __HAL_RTC_ALARM_EXTID2_ENABLE_EVENT() (EXTI_D2->EMR1 |= RTC_EXTI_LINE_ALARM_EVENT) 813 814 /** 815 * @brief Disable event on the RTC Alarm associated D2 Exti line. 816 * @retval None 817 */ 818 #define __HAL_RTC_ALARM_EXTID2_DISABLE_EVENT() (EXTI_D2->EMR1 &= ~(RTC_EXTI_LINE_ALARM_EVENT)) 819 820 #endif /* DUAL_CORE */ 821 /** 822 * @brief Enable falling edge trigger on the RTC Alarm associated Exti line. 823 * @retval None 824 */ 825 #define __HAL_RTC_ALARM_EXTI_ENABLE_FALLING_EDGE() (EXTI->FTSR1 |= RTC_EXTI_LINE_ALARM_EVENT) 826 827 /** 828 * @brief Disable falling edge trigger on the RTC Alarm associated Exti line. 829 * @retval None 830 */ 831 #define __HAL_RTC_ALARM_EXTI_DISABLE_FALLING_EDGE() (EXTI->FTSR1 &= ~(RTC_EXTI_LINE_ALARM_EVENT)) 832 833 /** 834 * @brief Enable rising edge trigger on the RTC Alarm associated Exti line. 835 * @retval None 836 */ 837 #define __HAL_RTC_ALARM_EXTI_ENABLE_RISING_EDGE() (EXTI->RTSR1 |= RTC_EXTI_LINE_ALARM_EVENT) 838 839 /** 840 * @brief Disable rising edge trigger on the RTC Alarm associated Exti line. 841 * @retval None 842 */ 843 #define __HAL_RTC_ALARM_EXTI_DISABLE_RISING_EDGE() (EXTI->RTSR1 &= ~(RTC_EXTI_LINE_ALARM_EVENT)) 844 845 /** 846 * @brief Enable rising & falling edge trigger on the RTC Alarm associated Exti line. 847 * @retval None 848 */ 849 #define __HAL_RTC_ALARM_EXTI_ENABLE_RISING_FALLING_EDGE() do { \ 850 __HAL_RTC_ALARM_EXTI_ENABLE_RISING_EDGE(); \ 851 __HAL_RTC_ALARM_EXTI_ENABLE_FALLING_EDGE(); \ 852 } while(0u) 853 854 /** 855 * @brief Disable rising & falling edge trigger on the RTC Alarm associated Exti line. 856 * @retval None 857 */ 858 #define __HAL_RTC_ALARM_EXTI_DISABLE_RISING_FALLING_EDGE() do { \ 859 __HAL_RTC_ALARM_EXTI_DISABLE_RISING_EDGE(); \ 860 __HAL_RTC_ALARM_EXTI_DISABLE_FALLING_EDGE(); \ 861 } while(0u) 862 863 /** 864 * @brief Check whether the RTC Alarm associated Exti line interrupt flag is set or not. 865 * @retval Line Status. 866 */ 867 #if defined(EXTI_D1) 868 #define __HAL_RTC_ALARM_EXTI_GET_FLAG() (EXTI_D1->PR1 & RTC_EXTI_LINE_ALARM_EVENT) 869 #else /* EXTI */ 870 #define __HAL_RTC_ALARM_EXTI_GET_FLAG() (EXTI->PR1 & RTC_EXTI_LINE_ALARM_EVENT) 871 #endif /* EXTI_D1 */ 872 873 /** 874 * @brief Clear the RTC Alarm associated Exti line flag. 875 * @retval None. 876 */ 877 #if defined(EXTI_D1) 878 #define __HAL_RTC_ALARM_EXTI_CLEAR_FLAG() (EXTI_D1->PR1 = (RTC_EXTI_LINE_ALARM_EVENT)) 879 #else /* EXTI */ 880 #define __HAL_RTC_ALARM_EXTI_CLEAR_FLAG() (EXTI->PR1 = (RTC_EXTI_LINE_ALARM_EVENT)) 881 #endif /* EXTI_D1 */ 882 883 #if defined(DUAL_CORE) 884 /** 885 * @brief Check whether the RTC Alarm associated D2 Exti line interrupt flag is set or not. 886 * @retval Line Status 887 */ 888 #define __HAL_RTC_ALARM_EXTID2_GET_FLAG() (EXTI_D2->PR1 & RTC_EXTI_LINE_ALARM_EVENT) 889 890 /** 891 * @brief Clear the RTC Alarm associated D2 Exti line flag. 892 * @retval None 893 */ 894 #define __HAL_RTC_ALARM_EXTID2_CLEAR_FLAG() (EXTI_D2->PR1 = (RTC_EXTI_LINE_ALARM_EVENT)) 895 #endif /* DUAL_CORE */ 896 /** 897 * @brief Generate a Software interrupt on RTC Alarm associated Exti line. 898 * @retval None 899 */ 900 #define __HAL_RTC_ALARM_EXTI_GENERATE_SWIT() (EXTI->SWIER1 |= RTC_EXTI_LINE_ALARM_EVENT) 901 902 /** 903 * @} 904 */ 905 906 /* Include RTC HAL Extended module */ 907 #include "stm32h7xx_hal_rtc_ex.h" 908 909 /* Exported functions --------------------------------------------------------*/ 910 /** @defgroup RTC_Exported_Functions RTC Exported Functions 911 * @{ 912 */ 913 914 /** @defgroup RTC_Exported_Functions_Group1 Initialization and de-initialization functions 915 * @{ 916 */ 917 /* Initialization and de-initialization functions ****************************/ 918 HAL_StatusTypeDef HAL_RTC_Init(RTC_HandleTypeDef *hrtc); 919 HAL_StatusTypeDef HAL_RTC_DeInit(RTC_HandleTypeDef *hrtc); 920 921 void HAL_RTC_MspInit(RTC_HandleTypeDef *hrtc); 922 void HAL_RTC_MspDeInit(RTC_HandleTypeDef *hrtc); 923 924 /* Callbacks Register/UnRegister functions ***********************************/ 925 #if (USE_HAL_RTC_REGISTER_CALLBACKS == 1) 926 HAL_StatusTypeDef HAL_RTC_RegisterCallback(RTC_HandleTypeDef *hrtc, HAL_RTC_CallbackIDTypeDef CallbackID, pRTC_CallbackTypeDef pCallback); 927 HAL_StatusTypeDef HAL_RTC_UnRegisterCallback(RTC_HandleTypeDef *hrtc, HAL_RTC_CallbackIDTypeDef CallbackID); 928 #endif /* (USE_HAL_RTC_REGISTER_CALLBACKS == 1) */ 929 /** 930 * @} 931 */ 932 933 /** @defgroup RTC_Exported_Functions_Group2 RTC Time and Date functions 934 * @{ 935 */ 936 /* RTC Time and Date functions ************************************************/ 937 HAL_StatusTypeDef HAL_RTC_SetTime(RTC_HandleTypeDef *hrtc, RTC_TimeTypeDef *sTime, uint32_t Format); 938 HAL_StatusTypeDef HAL_RTC_GetTime(RTC_HandleTypeDef *hrtc, RTC_TimeTypeDef *sTime, uint32_t Format); 939 HAL_StatusTypeDef HAL_RTC_SetDate(RTC_HandleTypeDef *hrtc, RTC_DateTypeDef *sDate, uint32_t Format); 940 HAL_StatusTypeDef HAL_RTC_GetDate(RTC_HandleTypeDef *hrtc, RTC_DateTypeDef *sDate, uint32_t Format); 941 /** 942 * @} 943 */ 944 945 /** @defgroup RTC_Exported_Functions_Group3 RTC Alarm functions 946 * @{ 947 */ 948 /* RTC Alarm functions ********************************************************/ 949 HAL_StatusTypeDef HAL_RTC_SetAlarm(RTC_HandleTypeDef *hrtc, RTC_AlarmTypeDef *sAlarm, uint32_t Format); 950 HAL_StatusTypeDef HAL_RTC_SetAlarm_IT(RTC_HandleTypeDef *hrtc, RTC_AlarmTypeDef *sAlarm, uint32_t Format); 951 HAL_StatusTypeDef HAL_RTC_DeactivateAlarm(RTC_HandleTypeDef *hrtc, uint32_t Alarm); 952 HAL_StatusTypeDef HAL_RTC_GetAlarm(RTC_HandleTypeDef *hrtc, RTC_AlarmTypeDef *sAlarm, uint32_t Alarm, uint32_t Format); 953 void HAL_RTC_AlarmIRQHandler(RTC_HandleTypeDef *hrtc); 954 void HAL_RTC_AlarmAEventCallback(RTC_HandleTypeDef *hrtc); 955 HAL_StatusTypeDef HAL_RTC_PollForAlarmAEvent(RTC_HandleTypeDef *hrtc, uint32_t Timeout); 956 /** 957 * @} 958 */ 959 960 /** @defgroup RTC_Exported_Functions_Group4 Peripheral Control functions 961 * @{ 962 */ 963 /* Peripheral Control functions ***********************************************/ 964 HAL_StatusTypeDef HAL_RTC_WaitForSynchro(RTC_HandleTypeDef *hrtc); 965 /** 966 * @} 967 */ 968 969 /** @defgroup RTC_Exported_Functions_Group5 Peripheral State functions 970 * @{ 971 */ 972 /* Peripheral State functions *************************************************/ 973 HAL_RTCStateTypeDef HAL_RTC_GetState(RTC_HandleTypeDef *hrtc); 974 /** 975 * @} 976 */ 977 978 /** 979 * @} 980 */ 981 982 /* Private types -------------------------------------------------------------*/ 983 /* Private variables ---------------------------------------------------------*/ 984 /* Private constants ---------------------------------------------------------*/ 985 /** @defgroup RTC_Private_Constants RTC Private Constants 986 * @{ 987 */ 988 /* Masks Definition */ 989 #define RTC_TR_RESERVED_MASK (RTC_TR_PM | RTC_TR_HT | RTC_TR_HU | \ 990 RTC_TR_MNT | RTC_TR_MNU| RTC_TR_ST | \ 991 RTC_TR_SU) 992 993 #define RTC_DR_RESERVED_MASK (RTC_DR_YT | RTC_DR_YU | RTC_DR_WDU | \ 994 RTC_DR_MT | RTC_DR_MU | RTC_DR_DT | \ 995 RTC_DR_DU) 996 997 #define RTC_INIT_MASK 0xFFFFFFFFu 998 999 #if defined(TAMP) 1000 #define RTC_ICSR_RESERVED_MASK 0x000100FFu 1001 #define RTC_RSF_MASK (~(RTC_ICSR_INIT | RTC_ICSR_RSF)) 1002 #else 1003 #define RTC_ISR_RESERVED_MASK 0x0003FFFFu 1004 #define RTC_RSF_MASK (~(RTC_ISR_INIT | RTC_ISR_RSF)) 1005 #endif /* TAMP */ 1006 1007 #define RTC_TIMEOUT_VALUE 1000u 1008 1009 #define RTC_EXTI_LINE_ALARM_EVENT EXTI_IMR1_IM17 /*!< External interrupt line 17 Connected to the RTC Alarm event */ 1010 1011 /** 1012 * @} 1013 */ 1014 1015 /* Private macros ------------------------------------------------------------*/ 1016 /** @defgroup RTC_Private_Macros RTC Private Macros 1017 * @{ 1018 */ 1019 1020 /** @defgroup RTC_IS_RTC_Definitions RTC Private macros to check input parameters 1021 * @{ 1022 */ 1023 1024 #if defined(TAMP) 1025 #define IS_RTC_OUTPUT(OUTPUT) (((OUTPUT) == RTC_OUTPUT_DISABLE) || \ 1026 ((OUTPUT) == RTC_OUTPUT_ALARMA) || \ 1027 ((OUTPUT) == RTC_OUTPUT_ALARMB) || \ 1028 ((OUTPUT) == RTC_OUTPUT_WAKEUP) || \ 1029 ((OUTPUT) == RTC_OUTPUT_TAMPER)) 1030 #else 1031 #define IS_RTC_OUTPUT(OUTPUT) (((OUTPUT) == RTC_OUTPUT_DISABLE) || \ 1032 ((OUTPUT) == RTC_OUTPUT_ALARMA) || \ 1033 ((OUTPUT) == RTC_OUTPUT_ALARMB) || \ 1034 ((OUTPUT) == RTC_OUTPUT_WAKEUP)) 1035 #endif /* TAMP */ 1036 1037 #define IS_RTC_HOUR_FORMAT(FORMAT) (((FORMAT) == RTC_HOURFORMAT_12) || \ 1038 ((FORMAT) == RTC_HOURFORMAT_24)) 1039 1040 #define IS_RTC_OUTPUT_POL(POL) (((POL) == RTC_OUTPUT_POLARITY_HIGH) || \ 1041 ((POL) == RTC_OUTPUT_POLARITY_LOW)) 1042 1043 #define IS_RTC_OUTPUT_TYPE(TYPE) (((TYPE) == RTC_OUTPUT_TYPE_OPENDRAIN) || \ 1044 ((TYPE) == RTC_OUTPUT_TYPE_PUSHPULL)) 1045 1046 #if defined(TAMP) 1047 #define IS_RTC_OUTPUT_PULLUP(TYPE) (((TYPE) == RTC_OUTPUT_PULLUP_NONE) || \ 1048 ((TYPE) == RTC_OUTPUT_PULLUP_ON)) 1049 #endif /* TAMP */ 1050 1051 #define IS_RTC_OUTPUT_REMAP(REMAP) (((REMAP) == RTC_OUTPUT_REMAP_NONE) || \ 1052 ((REMAP) == RTC_OUTPUT_REMAP_POS1)) 1053 1054 #define IS_RTC_HOURFORMAT12(PM) (((PM) == RTC_HOURFORMAT12_AM) || \ 1055 ((PM) == RTC_HOURFORMAT12_PM)) 1056 1057 #define IS_RTC_DAYLIGHT_SAVING(SAVE) (((SAVE) == RTC_DAYLIGHTSAVING_SUB1H) || \ 1058 ((SAVE) == RTC_DAYLIGHTSAVING_ADD1H) || \ 1059 ((SAVE) == RTC_DAYLIGHTSAVING_NONE)) 1060 1061 #define IS_RTC_STORE_OPERATION(OPERATION) (((OPERATION) == RTC_STOREOPERATION_RESET) || \ 1062 ((OPERATION) == RTC_STOREOPERATION_SET)) 1063 1064 #define IS_RTC_FORMAT(FORMAT) (((FORMAT) == RTC_FORMAT_BIN) || \ 1065 ((FORMAT) == RTC_FORMAT_BCD)) 1066 1067 #define IS_RTC_YEAR(YEAR) ((YEAR) <= 99u) 1068 1069 #define IS_RTC_MONTH(MONTH) (((MONTH) >= 1u) && ((MONTH) <= 12u)) 1070 1071 #define IS_RTC_DATE(DATE) (((DATE) >= 1u) && ((DATE) <= 31u)) 1072 1073 #define IS_RTC_WEEKDAY(WEEKDAY) (((WEEKDAY) == RTC_WEEKDAY_MONDAY) || \ 1074 ((WEEKDAY) == RTC_WEEKDAY_TUESDAY) || \ 1075 ((WEEKDAY) == RTC_WEEKDAY_WEDNESDAY) || \ 1076 ((WEEKDAY) == RTC_WEEKDAY_THURSDAY) || \ 1077 ((WEEKDAY) == RTC_WEEKDAY_FRIDAY) || \ 1078 ((WEEKDAY) == RTC_WEEKDAY_SATURDAY) || \ 1079 ((WEEKDAY) == RTC_WEEKDAY_SUNDAY)) 1080 1081 #define IS_RTC_ALARM_DATE_WEEKDAY_DATE(DATE) (((DATE) > 0u) && ((DATE) <= 31u)) 1082 1083 #define IS_RTC_ALARM_DATE_WEEKDAY_WEEKDAY(WEEKDAY) (((WEEKDAY) == RTC_WEEKDAY_MONDAY) || \ 1084 ((WEEKDAY) == RTC_WEEKDAY_TUESDAY) || \ 1085 ((WEEKDAY) == RTC_WEEKDAY_WEDNESDAY) || \ 1086 ((WEEKDAY) == RTC_WEEKDAY_THURSDAY) || \ 1087 ((WEEKDAY) == RTC_WEEKDAY_FRIDAY) || \ 1088 ((WEEKDAY) == RTC_WEEKDAY_SATURDAY) || \ 1089 ((WEEKDAY) == RTC_WEEKDAY_SUNDAY)) 1090 1091 #define IS_RTC_ALARM_DATE_WEEKDAY_SEL(SEL) (((SEL) == RTC_ALARMDATEWEEKDAYSEL_DATE) || \ 1092 ((SEL) == RTC_ALARMDATEWEEKDAYSEL_WEEKDAY)) 1093 1094 #define IS_RTC_ALARM_MASK(MASK) (((MASK) & ~(RTC_ALARMMASK_ALL)) == 0u) 1095 1096 #define IS_RTC_ALARM(ALARM) (((ALARM) == RTC_ALARM_A) || \ 1097 ((ALARM) == RTC_ALARM_B)) 1098 1099 #define IS_RTC_ALARM_SUB_SECOND_VALUE(VALUE) ((VALUE) <= RTC_ALRMASSR_SS) 1100 1101 #define IS_RTC_ALARM_SUB_SECOND_MASK(MASK) (((MASK) == 0u) || \ 1102 (((MASK) >= RTC_ALARMSUBSECONDMASK_SS14_1) && ((MASK) <= RTC_ALARMSUBSECONDMASK_NONE))) 1103 1104 #define IS_RTC_ASYNCH_PREDIV(PREDIV) ((PREDIV) <= (RTC_PRER_PREDIV_A >> RTC_PRER_PREDIV_A_Pos)) 1105 1106 #define IS_RTC_SYNCH_PREDIV(PREDIV) ((PREDIV) <= (RTC_PRER_PREDIV_S >> RTC_PRER_PREDIV_S_Pos)) 1107 1108 #define IS_RTC_HOUR12(HOUR) (((HOUR) > 0u) && ((HOUR) <= 12u)) 1109 1110 #define IS_RTC_HOUR24(HOUR) ((HOUR) <= 23u) 1111 1112 #define IS_RTC_MINUTES(MINUTES) ((MINUTES) <= 59u) 1113 1114 #define IS_RTC_SECONDS(SECONDS) ((SECONDS) <= 59u) 1115 1116 /** 1117 * @} 1118 */ 1119 1120 /** 1121 * @} 1122 */ 1123 1124 /* Private functions -------------------------------------------------------------*/ 1125 /** @defgroup RTC_Private_Functions RTC Private Functions 1126 * @{ 1127 */ 1128 HAL_StatusTypeDef RTC_EnterInitMode(RTC_HandleTypeDef *hrtc); 1129 HAL_StatusTypeDef RTC_ExitInitMode(RTC_HandleTypeDef *hrtc); 1130 uint8_t RTC_ByteToBcd2(uint8_t Value); 1131 uint8_t RTC_Bcd2ToByte(uint8_t Value); 1132 1133 /** 1134 * @} 1135 */ 1136 1137 /** 1138 * @} 1139 */ 1140 1141 /** 1142 * @} 1143 */ 1144 1145 #ifdef __cplusplus 1146 } 1147 #endif 1148 1149 #endif /* STM32H7xx_HAL_RTC_H */ 1150 1151