1 /** 2 ****************************************************************************** 3 * @file stm32f4xx_hal_rtc.h 4 * @author MCD Application Team 5 * @brief Header file of RTC HAL module. 6 ****************************************************************************** 7 * @attention 8 * 9 * <h2><center>© Copyright (c) 2017 STMicroelectronics. 10 * All rights reserved.</center></h2> 11 * 12 * This software component is licensed by ST under BSD 3-Clause license, 13 * the "License"; You may not use this file except in compliance with the 14 * License. You may obtain a copy of the License at: 15 * opensource.org/licenses/BSD-3-Clause 16 * 17 ****************************************************************************** 18 */ 19 20 /* Define to prevent recursive inclusion -------------------------------------*/ 21 #ifndef __STM32F4xx_HAL_RTC_H 22 #define __STM32F4xx_HAL_RTC_H 23 24 #ifdef __cplusplus 25 extern "C" { 26 #endif 27 28 /* Includes ------------------------------------------------------------------*/ 29 #include "stm32f4xx_hal_def.h" 30 31 /** @addtogroup STM32F4xx_HAL_Driver 32 * @{ 33 */ 34 35 /** @addtogroup RTC 36 * @{ 37 */ 38 39 /* Exported types ------------------------------------------------------------*/ 40 /** @defgroup RTC_Exported_Types RTC Exported Types 41 * @{ 42 */ 43 44 /** 45 * @brief HAL State structures definition 46 */ 47 typedef enum 48 { 49 HAL_RTC_STATE_RESET = 0x00U, /*!< RTC not yet initialized or disabled */ 50 HAL_RTC_STATE_READY = 0x01U, /*!< RTC initialized and ready for use */ 51 HAL_RTC_STATE_BUSY = 0x02U, /*!< RTC process is ongoing */ 52 HAL_RTC_STATE_TIMEOUT = 0x03U, /*!< RTC timeout state */ 53 HAL_RTC_STATE_ERROR = 0x04U /*!< RTC error state */ 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 = 0x7FFFU */ 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 OutPutPolarity; /*!< Specifies the polarity of the output signal. 74 This parameter can be a value of @ref RTC_Output_Polarity_Definitions */ 75 76 uint32_t OutPutType; /*!< Specifies the RTC Output Pin mode. 77 This parameter can be a value of @ref RTC_Output_Type_ALARM_OUT */ 78 }RTC_InitTypeDef; 79 80 /** 81 * @brief RTC Time structure definition 82 */ 83 typedef struct 84 { 85 uint8_t Hours; /*!< Specifies the RTC Time Hour. 86 This parameter must be a number between Min_Data = 0 and Max_Data = 12 if the RTC_HourFormat_12 is selected. 87 This parameter must be a number between Min_Data = 0 and Max_Data = 23 if the RTC_HourFormat_24 is selected */ 88 89 uint8_t Minutes; /*!< Specifies the RTC Time Minutes. 90 This parameter must be a number between Min_Data = 0 and Max_Data = 59 */ 91 92 uint8_t Seconds; /*!< Specifies the RTC Time Seconds. 93 This parameter must be a number between Min_Data = 0 and Max_Data = 59 */ 94 95 uint8_t TimeFormat; /*!< Specifies the RTC AM/PM Time. 96 This parameter can be a value of @ref RTC_AM_PM_Definitions */ 97 98 uint32_t SubSeconds; /*!< Specifies the RTC_SSR RTC Sub Second register content. 99 This parameter corresponds to a time unit range between [0-1] Second 100 with [1 Sec / SecondFraction +1] granularity */ 101 102 uint32_t SecondFraction; /*!< Specifies the range or granularity of Sub Second register content 103 corresponding to Synchronous pre-scaler factor value (PREDIV_S) 104 This parameter corresponds to a time unit range between [0-1] Second 105 with [1 Sec / SecondFraction +1] granularity. 106 This field will be used only by HAL_RTC_GetTime function */ 107 108 uint32_t DayLightSaving; /*!< Specifies DayLight Save Operation. 109 This parameter can be a value of @ref RTC_DayLightSaving_Definitions */ 110 111 uint32_t StoreOperation; /*!< Specifies RTC_StoreOperation value to be written in the BCK bit 112 in CR register to store the operation. 113 This parameter can be a value of @ref RTC_StoreOperation_Definitions */ 114 }RTC_TimeTypeDef; 115 116 /** 117 * @brief RTC Date structure definition 118 */ 119 typedef struct 120 { 121 uint8_t WeekDay; /*!< Specifies the RTC Date WeekDay. 122 This parameter can be a value of @ref RTC_WeekDay_Definitions */ 123 124 uint8_t Month; /*!< Specifies the RTC Date Month (in BCD format). 125 This parameter can be a value of @ref RTC_Month_Date_Definitions */ 126 127 uint8_t Date; /*!< Specifies the RTC Date. 128 This parameter must be a number between Min_Data = 1 and Max_Data = 31 */ 129 130 uint8_t Year; /*!< Specifies the RTC Date Year. 131 This parameter must be a number between Min_Data = 0 and Max_Data = 99 */ 132 133 }RTC_DateTypeDef; 134 135 /** 136 * @brief RTC Alarm structure definition 137 */ 138 typedef struct 139 { 140 RTC_TimeTypeDef AlarmTime; /*!< Specifies the RTC Alarm Time members */ 141 142 uint32_t AlarmMask; /*!< Specifies the RTC Alarm Masks. 143 This parameter can be a value of @ref RTC_AlarmMask_Definitions */ 144 145 uint32_t AlarmSubSecondMask; /*!< Specifies the RTC Alarm SubSeconds Masks. 146 This parameter can be a value of @ref RTC_Alarm_Sub_Seconds_Masks_Definitions */ 147 148 uint32_t AlarmDateWeekDaySel; /*!< Specifies the RTC Alarm is on Date or WeekDay. 149 This parameter can be a value of @ref RTC_AlarmDateWeekDay_Definitions */ 150 151 uint8_t AlarmDateWeekDay; /*!< Specifies the RTC Alarm Date/WeekDay. 152 If the Alarm Date is selected, this parameter must be set to a value in the 1-31 range. 153 If the Alarm WeekDay is selected, this parameter can be a value of @ref RTC_WeekDay_Definitions */ 154 155 uint32_t Alarm; /*!< Specifies the alarm . 156 This parameter can be a value of @ref RTC_Alarms_Definitions */ 157 }RTC_AlarmTypeDef; 158 159 /** 160 * @brief RTC Handle Structure definition 161 */ 162 #if (USE_HAL_RTC_REGISTER_CALLBACKS == 1) 163 typedef struct __RTC_HandleTypeDef 164 #else 165 typedef struct 166 #endif /* (USE_HAL_RTC_REGISTER_CALLBACKS) */ 167 { 168 RTC_TypeDef *Instance; /*!< Register base address */ 169 170 RTC_InitTypeDef Init; /*!< RTC required parameters */ 171 172 HAL_LockTypeDef Lock; /*!< RTC locking object */ 173 174 __IO HAL_RTCStateTypeDef State; /*!< Time communication state */ 175 176 #if (USE_HAL_RTC_REGISTER_CALLBACKS == 1) 177 void (* AlarmAEventCallback) ( struct __RTC_HandleTypeDef * hrtc); /*!< RTC Alarm A Event callback */ 178 179 void (* AlarmBEventCallback) ( struct __RTC_HandleTypeDef * hrtc); /*!< RTC Alarm B Event callback */ 180 181 void (* TimeStampEventCallback) ( struct __RTC_HandleTypeDef * hrtc); /*!< RTC TimeStamp Event callback */ 182 183 void (* WakeUpTimerEventCallback) ( struct __RTC_HandleTypeDef * hrtc); /*!< RTC WakeUpTimer Event callback */ 184 185 void (* Tamper1EventCallback) ( struct __RTC_HandleTypeDef * hrtc); /*!< RTC Tamper 1 Event callback */ 186 187 void (* Tamper2EventCallback) ( struct __RTC_HandleTypeDef * hrtc); /*!< RTC Tamper 2 Event callback */ 188 189 void (* MspInitCallback) ( struct __RTC_HandleTypeDef * hrtc); /*!< RTC Msp Init callback */ 190 191 void (* MspDeInitCallback) ( struct __RTC_HandleTypeDef * hrtc); /*!< RTC Msp DeInit callback */ 192 193 #endif /* (USE_HAL_RTC_REGISTER_CALLBACKS) */ 194 195 }RTC_HandleTypeDef; 196 197 #if (USE_HAL_RTC_REGISTER_CALLBACKS == 1) 198 /** 199 * @brief HAL RTC Callback ID enumeration definition 200 */ 201 typedef enum 202 { 203 HAL_RTC_ALARM_A_EVENT_CB_ID = 0x00u, /*!< RTC Alarm A Event Callback ID */ 204 HAL_RTC_ALARM_B_EVENT_CB_ID = 0x01u, /*!< RTC Alarm B Event Callback ID */ 205 HAL_RTC_TIMESTAMP_EVENT_CB_ID = 0x02u, /*!< RTC TimeStamp Event Callback ID */ 206 HAL_RTC_WAKEUPTIMER_EVENT_CB_ID = 0x03u, /*!< RTC Wake-Up Timer Event Callback ID */ 207 HAL_RTC_TAMPER1_EVENT_CB_ID = 0x04u, /*!< RTC Tamper 1 Callback ID */ 208 HAL_RTC_TAMPER2_EVENT_CB_ID = 0x05u, /*!< RTC Tamper 2 Callback ID */ 209 HAL_RTC_MSPINIT_CB_ID = 0x0Eu, /*!< RTC Msp Init callback ID */ 210 HAL_RTC_MSPDEINIT_CB_ID = 0x0Fu /*!< RTC Msp DeInit callback ID */ 211 }HAL_RTC_CallbackIDTypeDef; 212 213 /** 214 * @brief HAL RTC Callback pointer definition 215 */ 216 typedef void (*pRTC_CallbackTypeDef)(RTC_HandleTypeDef * hrtc); /*!< pointer to an RTC callback function */ 217 #endif /* USE_HAL_RTC_REGISTER_CALLBACKS */ 218 219 /** 220 * @} 221 */ 222 223 /* Exported constants --------------------------------------------------------*/ 224 /** @defgroup RTC_Exported_Constants RTC Exported Constants 225 * @{ 226 */ 227 228 /** @defgroup RTC_Hour_Formats RTC Hour Formats 229 * @{ 230 */ 231 #define RTC_HOURFORMAT_24 0x00000000U 232 #define RTC_HOURFORMAT_12 0x00000040U 233 /** 234 * @} 235 */ 236 237 /** @defgroup RTC_Output_selection_Definitions RTC Output Selection Definitions 238 * @{ 239 */ 240 #define RTC_OUTPUT_DISABLE 0x00000000U 241 #define RTC_OUTPUT_ALARMA 0x00200000U 242 #define RTC_OUTPUT_ALARMB 0x00400000U 243 #define RTC_OUTPUT_WAKEUP 0x00600000U 244 /** 245 * @} 246 */ 247 248 /** @defgroup RTC_Output_Polarity_Definitions RTC Output Polarity Definitions 249 * @{ 250 */ 251 #define RTC_OUTPUT_POLARITY_HIGH 0x00000000U 252 #define RTC_OUTPUT_POLARITY_LOW 0x00100000U 253 /** 254 * @} 255 */ 256 257 /** @defgroup RTC_Output_Type_ALARM_OUT RTC Output Type ALARM OUT 258 * @{ 259 */ 260 #define RTC_OUTPUT_TYPE_OPENDRAIN 0x00000000U 261 #define RTC_OUTPUT_TYPE_PUSHPULL 0x00040000U 262 /** 263 * @} 264 */ 265 266 /** @defgroup RTC_AM_PM_Definitions RTC AM PM Definitions 267 * @{ 268 */ 269 #define RTC_HOURFORMAT12_AM ((uint8_t)0x00) 270 #define RTC_HOURFORMAT12_PM ((uint8_t)0x40) 271 /** 272 * @} 273 */ 274 275 /** @defgroup RTC_DayLightSaving_Definitions RTC DayLight Saving Definitions 276 * @{ 277 */ 278 #define RTC_DAYLIGHTSAVING_SUB1H 0x00020000U 279 #define RTC_DAYLIGHTSAVING_ADD1H 0x00010000U 280 #define RTC_DAYLIGHTSAVING_NONE 0x00000000U 281 /** 282 * @} 283 */ 284 285 /** @defgroup RTC_StoreOperation_Definitions RTC Store Operation Definitions 286 * @{ 287 */ 288 #define RTC_STOREOPERATION_RESET 0x00000000U 289 #define RTC_STOREOPERATION_SET 0x00040000U 290 /** 291 * @} 292 */ 293 294 /** @defgroup RTC_Input_parameter_format_definitions RTC Input Parameter Format Definitions 295 * @{ 296 */ 297 #define RTC_FORMAT_BIN 0x00000000U 298 #define RTC_FORMAT_BCD 0x00000001U 299 /** 300 * @} 301 */ 302 303 /** @defgroup RTC_Month_Date_Definitions RTC Month Date Definitions 304 * @{ 305 */ 306 /* Coded in BCD format */ 307 #define RTC_MONTH_JANUARY ((uint8_t)0x01) 308 #define RTC_MONTH_FEBRUARY ((uint8_t)0x02) 309 #define RTC_MONTH_MARCH ((uint8_t)0x03) 310 #define RTC_MONTH_APRIL ((uint8_t)0x04) 311 #define RTC_MONTH_MAY ((uint8_t)0x05) 312 #define RTC_MONTH_JUNE ((uint8_t)0x06) 313 #define RTC_MONTH_JULY ((uint8_t)0x07) 314 #define RTC_MONTH_AUGUST ((uint8_t)0x08) 315 #define RTC_MONTH_SEPTEMBER ((uint8_t)0x09) 316 #define RTC_MONTH_OCTOBER ((uint8_t)0x10) 317 #define RTC_MONTH_NOVEMBER ((uint8_t)0x11) 318 #define RTC_MONTH_DECEMBER ((uint8_t)0x12) 319 /** 320 * @} 321 */ 322 323 /** @defgroup RTC_WeekDay_Definitions RTC WeekDay Definitions 324 * @{ 325 */ 326 #define RTC_WEEKDAY_MONDAY ((uint8_t)0x01) 327 #define RTC_WEEKDAY_TUESDAY ((uint8_t)0x02) 328 #define RTC_WEEKDAY_WEDNESDAY ((uint8_t)0x03) 329 #define RTC_WEEKDAY_THURSDAY ((uint8_t)0x04) 330 #define RTC_WEEKDAY_FRIDAY ((uint8_t)0x05) 331 #define RTC_WEEKDAY_SATURDAY ((uint8_t)0x06) 332 #define RTC_WEEKDAY_SUNDAY ((uint8_t)0x07) 333 /** 334 * @} 335 */ 336 337 /** @defgroup RTC_AlarmDateWeekDay_Definitions RTC Alarm Date WeekDay Definitions 338 * @{ 339 */ 340 #define RTC_ALARMDATEWEEKDAYSEL_DATE 0x00000000U 341 #define RTC_ALARMDATEWEEKDAYSEL_WEEKDAY 0x40000000U 342 /** 343 * @} 344 */ 345 346 /** @defgroup RTC_AlarmMask_Definitions RTC Alarm Mask Definitions 347 * @{ 348 */ 349 #define RTC_ALARMMASK_NONE 0x00000000U 350 #define RTC_ALARMMASK_DATEWEEKDAY RTC_ALRMAR_MSK4 351 #define RTC_ALARMMASK_HOURS RTC_ALRMAR_MSK3 352 #define RTC_ALARMMASK_MINUTES RTC_ALRMAR_MSK2 353 #define RTC_ALARMMASK_SECONDS RTC_ALRMAR_MSK1 354 #define RTC_ALARMMASK_ALL 0x80808080U 355 /** 356 * @} 357 */ 358 359 /** @defgroup RTC_Alarms_Definitions RTC Alarms Definitions 360 * @{ 361 */ 362 #define RTC_ALARM_A RTC_CR_ALRAE 363 #define RTC_ALARM_B RTC_CR_ALRBE 364 /** 365 * @} 366 */ 367 368 /** @defgroup RTC_Alarm_Sub_Seconds_Masks_Definitions RTC Alarm Sub Seconds Masks Definitions 369 * @{ 370 */ 371 #define RTC_ALARMSUBSECONDMASK_ALL 0x00000000U /*!< All Alarm SS fields are masked. 372 There is no comparison on sub seconds 373 for Alarm */ 374 #define RTC_ALARMSUBSECONDMASK_SS14_1 0x01000000U /*!< SS[14:1] are don't care in Alarm 375 comparison. Only SS[0] is compared. */ 376 #define RTC_ALARMSUBSECONDMASK_SS14_2 0x02000000U /*!< SS[14:2] are don't care in Alarm 377 comparison. Only SS[1:0] are compared */ 378 #define RTC_ALARMSUBSECONDMASK_SS14_3 0x03000000U /*!< SS[14:3] are don't care in Alarm 379 comparison. Only SS[2:0] are compared */ 380 #define RTC_ALARMSUBSECONDMASK_SS14_4 0x04000000U /*!< SS[14:4] are don't care in Alarm 381 comparison. Only SS[3:0] are compared */ 382 #define RTC_ALARMSUBSECONDMASK_SS14_5 0x05000000U /*!< SS[14:5] are don't care in Alarm 383 comparison. Only SS[4:0] are compared */ 384 #define RTC_ALARMSUBSECONDMASK_SS14_6 0x06000000U /*!< SS[14:6] are don't care in Alarm 385 comparison. Only SS[5:0] are compared */ 386 #define RTC_ALARMSUBSECONDMASK_SS14_7 0x07000000U /*!< SS[14:7] are don't care in Alarm 387 comparison. Only SS[6:0] are compared */ 388 #define RTC_ALARMSUBSECONDMASK_SS14_8 0x08000000U /*!< SS[14:8] are don't care in Alarm 389 comparison. Only SS[7:0] are compared */ 390 #define RTC_ALARMSUBSECONDMASK_SS14_9 0x09000000U /*!< SS[14:9] are don't care in Alarm 391 comparison. Only SS[8:0] are compared */ 392 #define RTC_ALARMSUBSECONDMASK_SS14_10 0x0A000000U /*!< SS[14:10] are don't care in Alarm 393 comparison. Only SS[9:0] are compared */ 394 #define RTC_ALARMSUBSECONDMASK_SS14_11 0x0B000000U /*!< SS[14:11] are don't care in Alarm 395 comparison. Only SS[10:0] are compared */ 396 #define RTC_ALARMSUBSECONDMASK_SS14_12 0x0C000000U /*!< SS[14:12] are don't care in Alarm 397 comparison.Only SS[11:0] are compared */ 398 #define RTC_ALARMSUBSECONDMASK_SS14_13 0x0D000000U /*!< SS[14:13] are don't care in Alarm 399 comparison. Only SS[12:0] are compared */ 400 #define RTC_ALARMSUBSECONDMASK_SS14 0x0E000000U /*!< SS[14] is don't care in Alarm 401 comparison.Only SS[13:0] are compared */ 402 #define RTC_ALARMSUBSECONDMASK_NONE 0x0F000000U /*!< SS[14:0] are compared and must match 403 to activate alarm. */ 404 /** 405 * @} 406 */ 407 408 /** @defgroup RTC_Interrupts_Definitions RTC Interrupts Definitions 409 * @{ 410 */ 411 #define RTC_IT_TS 0x00008000U 412 #define RTC_IT_WUT 0x00004000U 413 #define RTC_IT_ALRB 0x00002000U 414 #define RTC_IT_ALRA 0x00001000U 415 #define RTC_IT_TAMP 0x00000004U /* Used only to Enable the Tamper Interrupt */ 416 #define RTC_IT_TAMP1 0x00020000U 417 #define RTC_IT_TAMP2 0x00040000U 418 /** 419 * @} 420 */ 421 422 /** @defgroup RTC_Flags_Definitions RTC Flags Definitions 423 * @{ 424 */ 425 #define RTC_FLAG_RECALPF 0x00010000U 426 #define RTC_FLAG_TAMP2F 0x00004000U 427 #define RTC_FLAG_TAMP1F 0x00002000U 428 #define RTC_FLAG_TSOVF 0x00001000U 429 #define RTC_FLAG_TSF 0x00000800U 430 #define RTC_FLAG_WUTF 0x00000400U 431 #define RTC_FLAG_ALRBF 0x00000200U 432 #define RTC_FLAG_ALRAF 0x00000100U 433 #define RTC_FLAG_INITF 0x00000040U 434 #define RTC_FLAG_RSF 0x00000020U 435 #define RTC_FLAG_INITS 0x00000010U 436 #define RTC_FLAG_SHPF 0x00000008U 437 #define RTC_FLAG_WUTWF 0x00000004U 438 #define RTC_FLAG_ALRBWF 0x00000002U 439 #define RTC_FLAG_ALRAWF 0x00000001U 440 /** 441 * @} 442 */ 443 444 /** 445 * @} 446 */ 447 448 /* Exported macro ------------------------------------------------------------*/ 449 /** @defgroup RTC_Exported_Macros RTC Exported Macros 450 * @{ 451 */ 452 453 /** @brief Reset RTC handle state 454 * @param __HANDLE__ specifies the RTC handle. 455 * @retval None 456 */ 457 #if (USE_HAL_RTC_REGISTER_CALLBACKS == 1) 458 #define __HAL_RTC_RESET_HANDLE_STATE(__HANDLE__) do{\ 459 (__HANDLE__)->State = HAL_RTC_STATE_RESET;\ 460 (__HANDLE__)->MspInitCallback = NULL;\ 461 (__HANDLE__)->MspDeInitCallback = NULL;\ 462 }while(0u) 463 #else 464 #define __HAL_RTC_RESET_HANDLE_STATE(__HANDLE__) ((__HANDLE__)->State = HAL_RTC_STATE_RESET) 465 #endif /* USE_HAL_RTC_REGISTER_CALLBACKS */ 466 467 /** 468 * @brief Disable the write protection for RTC registers. 469 * @param __HANDLE__ specifies the RTC handle. 470 * @retval None 471 */ 472 #define __HAL_RTC_WRITEPROTECTION_DISABLE(__HANDLE__) \ 473 do{ \ 474 (__HANDLE__)->Instance->WPR = 0xCAU; \ 475 (__HANDLE__)->Instance->WPR = 0x53U; \ 476 } while(0U) 477 478 /** 479 * @brief Enable the write protection for RTC registers. 480 * @param __HANDLE__ specifies the RTC handle. 481 * @retval None 482 */ 483 #define __HAL_RTC_WRITEPROTECTION_ENABLE(__HANDLE__) \ 484 do{ \ 485 (__HANDLE__)->Instance->WPR = 0xFFU; \ 486 } while(0U) 487 488 /** 489 * @brief Enable the RTC ALARMA peripheral. 490 * @param __HANDLE__ specifies the RTC handle. 491 * @retval None 492 */ 493 #define __HAL_RTC_ALARMA_ENABLE(__HANDLE__) ((__HANDLE__)->Instance->CR |= (RTC_CR_ALRAE)) 494 495 /** 496 * @brief Disable the RTC ALARMA peripheral. 497 * @param __HANDLE__ specifies the RTC handle. 498 * @retval None 499 */ 500 #define __HAL_RTC_ALARMA_DISABLE(__HANDLE__) ((__HANDLE__)->Instance->CR &= ~(RTC_CR_ALRAE)) 501 502 /** 503 * @brief Enable the RTC ALARMB peripheral. 504 * @param __HANDLE__ specifies the RTC handle. 505 * @retval None 506 */ 507 #define __HAL_RTC_ALARMB_ENABLE(__HANDLE__) ((__HANDLE__)->Instance->CR |= (RTC_CR_ALRBE)) 508 509 /** 510 * @brief Disable the RTC ALARMB peripheral. 511 * @param __HANDLE__ specifies the RTC handle. 512 * @retval None 513 */ 514 #define __HAL_RTC_ALARMB_DISABLE(__HANDLE__) ((__HANDLE__)->Instance->CR &= ~(RTC_CR_ALRBE)) 515 516 /** 517 * @brief Enable the RTC Alarm interrupt. 518 * @param __HANDLE__ specifies the RTC handle. 519 * @param __INTERRUPT__ specifies the RTC Alarm interrupt sources to be enabled or disabled. 520 * This parameter can be any combination of the following values: 521 * @arg RTC_IT_ALRA: Alarm A interrupt 522 * @arg RTC_IT_ALRB: Alarm B interrupt 523 * @retval None 524 */ 525 #define __HAL_RTC_ALARM_ENABLE_IT(__HANDLE__, __INTERRUPT__) ((__HANDLE__)->Instance->CR |= (__INTERRUPT__)) 526 527 /** 528 * @brief Disable the RTC Alarm interrupt. 529 * @param __HANDLE__ specifies the RTC handle. 530 * @param __INTERRUPT__ specifies the RTC Alarm interrupt sources to be enabled or disabled. 531 * This parameter can be any combination of the following values: 532 * @arg RTC_IT_ALRA: Alarm A interrupt 533 * @arg RTC_IT_ALRB: Alarm B interrupt 534 * @retval None 535 */ 536 #define __HAL_RTC_ALARM_DISABLE_IT(__HANDLE__, __INTERRUPT__) ((__HANDLE__)->Instance->CR &= ~(__INTERRUPT__)) 537 538 /** 539 * @brief Check whether the specified RTC Alarm interrupt has occurred or not. 540 * @param __HANDLE__ specifies the RTC handle. 541 * @param __INTERRUPT__ specifies the RTC Alarm interrupt to check. 542 * This parameter can be: 543 * @arg RTC_IT_ALRA: Alarm A interrupt 544 * @arg RTC_IT_ALRB: Alarm B interrupt 545 * @retval None 546 */ 547 #define __HAL_RTC_ALARM_GET_IT(__HANDLE__, __INTERRUPT__) (((((__HANDLE__)->Instance->ISR)& ((__INTERRUPT__)>> 4U)) != RESET)? SET : RESET) 548 549 /** 550 * @brief Get the selected RTC Alarm's flag status. 551 * @param __HANDLE__ specifies the RTC handle. 552 * @param __FLAG__ specifies the RTC Alarm Flag to check. 553 * This parameter can be: 554 * @arg RTC_FLAG_ALRAF 555 * @arg RTC_FLAG_ALRBF 556 * @arg RTC_FLAG_ALRAWF 557 * @arg RTC_FLAG_ALRBWF 558 * @retval None 559 */ 560 #define __HAL_RTC_ALARM_GET_FLAG(__HANDLE__, __FLAG__) (((((__HANDLE__)->Instance->ISR) & (__FLAG__)) != RESET)? SET : RESET) 561 562 /** 563 * @brief Clear the RTC Alarm's pending flags. 564 * @param __HANDLE__ specifies the RTC handle. 565 * @param __FLAG__ specifies the RTC Alarm Flag sources to be enabled or disabled. 566 * This parameter can be: 567 * @arg RTC_FLAG_ALRAF 568 * @arg RTC_FLAG_ALRBF 569 * @retval None 570 */ 571 #define __HAL_RTC_ALARM_CLEAR_FLAG(__HANDLE__, __FLAG__) ((__HANDLE__)->Instance->ISR) = (~((__FLAG__) | RTC_ISR_INIT)|((__HANDLE__)->Instance->ISR & RTC_ISR_INIT)) 572 573 574 /** 575 * @brief Check whether the specified RTC Alarm interrupt has been enabled or not. 576 * @param __HANDLE__ specifies the RTC handle. 577 * @param __INTERRUPT__ specifies the RTC Alarm interrupt sources to check. 578 * This parameter can be: 579 * @arg RTC_IT_ALRA: Alarm A interrupt 580 * @arg RTC_IT_ALRB: Alarm B interrupt 581 * @retval None 582 */ 583 #define __HAL_RTC_ALARM_GET_IT_SOURCE(__HANDLE__, __INTERRUPT__) (((((__HANDLE__)->Instance->CR) & (__INTERRUPT__)) != RESET) ? SET : RESET) 584 585 /** 586 * @brief Enable interrupt on the RTC Alarm associated Exti line. 587 * @retval None 588 */ 589 #define __HAL_RTC_ALARM_EXTI_ENABLE_IT() (EXTI->IMR |= RTC_EXTI_LINE_ALARM_EVENT) 590 591 /** 592 * @brief Disable interrupt on the RTC Alarm associated Exti line. 593 * @retval None 594 */ 595 #define __HAL_RTC_ALARM_EXTI_DISABLE_IT() (EXTI->IMR &= ~(RTC_EXTI_LINE_ALARM_EVENT)) 596 597 /** 598 * @brief Enable event on the RTC Alarm associated Exti line. 599 * @retval None. 600 */ 601 #define __HAL_RTC_ALARM_EXTI_ENABLE_EVENT() (EXTI->EMR |= RTC_EXTI_LINE_ALARM_EVENT) 602 603 /** 604 * @brief Disable event on the RTC Alarm associated Exti line. 605 * @retval None. 606 */ 607 #define __HAL_RTC_ALARM_EXTI_DISABLE_EVENT() (EXTI->EMR &= ~(RTC_EXTI_LINE_ALARM_EVENT)) 608 609 /** 610 * @brief Enable falling edge trigger on the RTC Alarm associated Exti line. 611 * @retval None. 612 */ 613 #define __HAL_RTC_ALARM_EXTI_ENABLE_FALLING_EDGE() (EXTI->FTSR |= RTC_EXTI_LINE_ALARM_EVENT) 614 615 /** 616 * @brief Disable falling edge trigger on the RTC Alarm associated Exti line. 617 * @retval None. 618 */ 619 #define __HAL_RTC_ALARM_EXTI_DISABLE_FALLING_EDGE() (EXTI->FTSR &= ~(RTC_EXTI_LINE_ALARM_EVENT)) 620 621 /** 622 * @brief Enable rising edge trigger on the RTC Alarm associated Exti line. 623 * @retval None. 624 */ 625 #define __HAL_RTC_ALARM_EXTI_ENABLE_RISING_EDGE() (EXTI->RTSR |= RTC_EXTI_LINE_ALARM_EVENT) 626 627 /** 628 * @brief Disable rising edge trigger on the RTC Alarm associated Exti line. 629 * @retval None. 630 */ 631 #define __HAL_RTC_ALARM_EXTI_DISABLE_RISING_EDGE() (EXTI->RTSR &= ~(RTC_EXTI_LINE_ALARM_EVENT)) 632 633 /** 634 * @brief Enable rising & falling edge trigger on the RTC Alarm associated Exti line. 635 * @retval None. 636 */ 637 #define __HAL_RTC_ALARM_EXTI_ENABLE_RISING_FALLING_EDGE() do { __HAL_RTC_ALARM_EXTI_ENABLE_RISING_EDGE(); \ 638 __HAL_RTC_ALARM_EXTI_ENABLE_FALLING_EDGE();\ 639 } while(0U) 640 641 /** 642 * @brief Disable rising & falling edge trigger on the RTC Alarm associated Exti line. 643 * @retval None. 644 */ 645 #define __HAL_RTC_ALARM_EXTI_DISABLE_RISING_FALLING_EDGE() do { __HAL_RTC_ALARM_EXTI_DISABLE_RISING_EDGE();\ 646 __HAL_RTC_ALARM_EXTI_DISABLE_FALLING_EDGE();\ 647 } while(0U) 648 649 /** 650 * @brief Check whether the RTC Alarm associated Exti line interrupt flag is set or not. 651 * @retval Line Status. 652 */ 653 #define __HAL_RTC_ALARM_EXTI_GET_FLAG() (EXTI->PR & RTC_EXTI_LINE_ALARM_EVENT) 654 655 /** 656 * @brief Clear the RTC Alarm associated Exti line flag. 657 * @retval None. 658 */ 659 #define __HAL_RTC_ALARM_EXTI_CLEAR_FLAG() (EXTI->PR = RTC_EXTI_LINE_ALARM_EVENT) 660 661 /** 662 * @brief Generate a Software interrupt on RTC Alarm associated Exti line. 663 * @retval None. 664 */ 665 #define __HAL_RTC_ALARM_EXTI_GENERATE_SWIT() (EXTI->SWIER |= RTC_EXTI_LINE_ALARM_EVENT) 666 /** 667 * @} 668 */ 669 670 /* Include RTC HAL Extension module */ 671 #include "stm32f4xx_hal_rtc_ex.h" 672 673 /* Exported functions --------------------------------------------------------*/ 674 /** @addtogroup RTC_Exported_Functions 675 * @{ 676 */ 677 678 /** @addtogroup RTC_Exported_Functions_Group1 679 * @{ 680 */ 681 /* Initialization and de-initialization functions ****************************/ 682 HAL_StatusTypeDef HAL_RTC_Init(RTC_HandleTypeDef *hrtc); 683 HAL_StatusTypeDef HAL_RTC_DeInit(RTC_HandleTypeDef *hrtc); 684 void HAL_RTC_MspInit(RTC_HandleTypeDef *hrtc); 685 void HAL_RTC_MspDeInit(RTC_HandleTypeDef *hrtc); 686 687 /* Callbacks Register/UnRegister functions ***********************************/ 688 #if (USE_HAL_RTC_REGISTER_CALLBACKS == 1) 689 HAL_StatusTypeDef HAL_RTC_RegisterCallback(RTC_HandleTypeDef *hrtc, HAL_RTC_CallbackIDTypeDef CallbackID, pRTC_CallbackTypeDef pCallback); 690 HAL_StatusTypeDef HAL_RTC_UnRegisterCallback(RTC_HandleTypeDef *hrtc, HAL_RTC_CallbackIDTypeDef CallbackID); 691 #endif /* USE_HAL_RTC_REGISTER_CALLBACKS */ 692 /** 693 * @} 694 */ 695 696 /** @addtogroup RTC_Exported_Functions_Group2 697 * @{ 698 */ 699 /* RTC Time and Date functions ************************************************/ 700 HAL_StatusTypeDef HAL_RTC_SetTime(RTC_HandleTypeDef *hrtc, RTC_TimeTypeDef *sTime, uint32_t Format); 701 HAL_StatusTypeDef HAL_RTC_GetTime(RTC_HandleTypeDef *hrtc, RTC_TimeTypeDef *sTime, uint32_t Format); 702 HAL_StatusTypeDef HAL_RTC_SetDate(RTC_HandleTypeDef *hrtc, RTC_DateTypeDef *sDate, uint32_t Format); 703 HAL_StatusTypeDef HAL_RTC_GetDate(RTC_HandleTypeDef *hrtc, RTC_DateTypeDef *sDate, uint32_t Format); 704 /** 705 * @} 706 */ 707 708 /** @addtogroup RTC_Exported_Functions_Group3 709 * @{ 710 */ 711 /* RTC Alarm functions ********************************************************/ 712 HAL_StatusTypeDef HAL_RTC_SetAlarm(RTC_HandleTypeDef *hrtc, RTC_AlarmTypeDef *sAlarm, uint32_t Format); 713 HAL_StatusTypeDef HAL_RTC_SetAlarm_IT(RTC_HandleTypeDef *hrtc, RTC_AlarmTypeDef *sAlarm, uint32_t Format); 714 HAL_StatusTypeDef HAL_RTC_DeactivateAlarm(RTC_HandleTypeDef *hrtc, uint32_t Alarm); 715 HAL_StatusTypeDef HAL_RTC_GetAlarm(RTC_HandleTypeDef *hrtc, RTC_AlarmTypeDef *sAlarm, uint32_t Alarm, uint32_t Format); 716 void HAL_RTC_AlarmIRQHandler(RTC_HandleTypeDef *hrtc); 717 HAL_StatusTypeDef HAL_RTC_PollForAlarmAEvent(RTC_HandleTypeDef *hrtc, uint32_t Timeout); 718 void HAL_RTC_AlarmAEventCallback(RTC_HandleTypeDef *hrtc); 719 /** 720 * @} 721 */ 722 723 /** @addtogroup RTC_Exported_Functions_Group4 724 * @{ 725 */ 726 /* Peripheral Control functions ***********************************************/ 727 HAL_StatusTypeDef HAL_RTC_WaitForSynchro(RTC_HandleTypeDef* hrtc); 728 /** 729 * @} 730 */ 731 732 /** @addtogroup RTC_Exported_Functions_Group5 733 * @{ 734 */ 735 /* Peripheral State functions *************************************************/ 736 HAL_RTCStateTypeDef HAL_RTC_GetState(RTC_HandleTypeDef *hrtc); 737 /** 738 * @} 739 */ 740 741 /** 742 * @} 743 */ 744 745 /* Private types -------------------------------------------------------------*/ 746 /* Private variables ---------------------------------------------------------*/ 747 /* Private constants ---------------------------------------------------------*/ 748 /** @defgroup RTC_Private_Constants RTC Private Constants 749 * @{ 750 */ 751 /* Masks Definition */ 752 #define RTC_TR_RESERVED_MASK 0x007F7F7FU 753 #define RTC_DR_RESERVED_MASK 0x00FFFF3FU 754 #define RTC_INIT_MASK 0xFFFFFFFFU 755 #define RTC_RSF_MASK 0xFFFFFF5FU 756 #define RTC_FLAGS_MASK ((uint32_t)(RTC_FLAG_TSOVF | RTC_FLAG_TSF | RTC_FLAG_WUTF | \ 757 RTC_FLAG_ALRBF | RTC_FLAG_ALRAF | RTC_FLAG_INITF | \ 758 RTC_FLAG_RSF | RTC_FLAG_INITS | RTC_FLAG_WUTWF | \ 759 RTC_FLAG_ALRBWF | RTC_FLAG_ALRAWF | RTC_FLAG_TAMP1F | \ 760 RTC_FLAG_RECALPF | RTC_FLAG_SHPF)) 761 762 #define RTC_TIMEOUT_VALUE 1000 763 764 #define RTC_EXTI_LINE_ALARM_EVENT ((uint32_t)EXTI_IMR_MR17) /*!< External interrupt line 17 Connected to the RTC Alarm event */ 765 /** 766 * @} 767 */ 768 769 /* Private macros ------------------------------------------------------------*/ 770 /** @defgroup RTC_Private_Macros RTC Private Macros 771 * @{ 772 */ 773 774 /** @defgroup RTC_IS_RTC_Definitions RTC Private macros to check input parameters 775 * @{ 776 */ 777 #define IS_RTC_HOUR_FORMAT(FORMAT) (((FORMAT) == RTC_HOURFORMAT_12) || \ 778 ((FORMAT) == RTC_HOURFORMAT_24)) 779 #define IS_RTC_OUTPUT(OUTPUT) (((OUTPUT) == RTC_OUTPUT_DISABLE) || \ 780 ((OUTPUT) == RTC_OUTPUT_ALARMA) || \ 781 ((OUTPUT) == RTC_OUTPUT_ALARMB) || \ 782 ((OUTPUT) == RTC_OUTPUT_WAKEUP)) 783 #define IS_RTC_OUTPUT_POL(POL) (((POL) == RTC_OUTPUT_POLARITY_HIGH) || \ 784 ((POL) == RTC_OUTPUT_POLARITY_LOW)) 785 #define IS_RTC_OUTPUT_TYPE(TYPE) (((TYPE) == RTC_OUTPUT_TYPE_OPENDRAIN) || \ 786 ((TYPE) == RTC_OUTPUT_TYPE_PUSHPULL)) 787 #define IS_RTC_HOUR12(HOUR) (((HOUR) > 0U) && ((HOUR) <= 12U)) 788 #define IS_RTC_HOUR24(HOUR) ((HOUR) <= 23U) 789 #define IS_RTC_ASYNCH_PREDIV(PREDIV) ((PREDIV) <= 0x7FU) 790 #define IS_RTC_SYNCH_PREDIV(PREDIV) ((PREDIV) <= 0x7FFFU) 791 #define IS_RTC_MINUTES(MINUTES) ((MINUTES) <= 59U) 792 #define IS_RTC_SECONDS(SECONDS) ((SECONDS) <= 59U) 793 794 #define IS_RTC_HOURFORMAT12(PM) (((PM) == RTC_HOURFORMAT12_AM) || ((PM) == RTC_HOURFORMAT12_PM)) 795 #define IS_RTC_DAYLIGHT_SAVING(SAVE) (((SAVE) == RTC_DAYLIGHTSAVING_SUB1H) || \ 796 ((SAVE) == RTC_DAYLIGHTSAVING_ADD1H) || \ 797 ((SAVE) == RTC_DAYLIGHTSAVING_NONE)) 798 #define IS_RTC_STORE_OPERATION(OPERATION) (((OPERATION) == RTC_STOREOPERATION_RESET) || \ 799 ((OPERATION) == RTC_STOREOPERATION_SET)) 800 #define IS_RTC_FORMAT(FORMAT) (((FORMAT) == RTC_FORMAT_BIN) || ((FORMAT) == RTC_FORMAT_BCD)) 801 #define IS_RTC_YEAR(YEAR) ((YEAR) <= 99U) 802 #define IS_RTC_MONTH(MONTH) (((MONTH) >= 1U) && ((MONTH) <= 12U)) 803 #define IS_RTC_DATE(DATE) (((DATE) >= 1U) && ((DATE) <= 31U)) 804 #define IS_RTC_WEEKDAY(WEEKDAY) (((WEEKDAY) == RTC_WEEKDAY_MONDAY) || \ 805 ((WEEKDAY) == RTC_WEEKDAY_TUESDAY) || \ 806 ((WEEKDAY) == RTC_WEEKDAY_WEDNESDAY) || \ 807 ((WEEKDAY) == RTC_WEEKDAY_THURSDAY) || \ 808 ((WEEKDAY) == RTC_WEEKDAY_FRIDAY) || \ 809 ((WEEKDAY) == RTC_WEEKDAY_SATURDAY) || \ 810 ((WEEKDAY) == RTC_WEEKDAY_SUNDAY)) 811 #define IS_RTC_ALARM_DATE_WEEKDAY_DATE(DATE) (((DATE) > 0U) && ((DATE) <= 31U)) 812 #define IS_RTC_ALARM_DATE_WEEKDAY_WEEKDAY(WEEKDAY) (((WEEKDAY) == RTC_WEEKDAY_MONDAY) || \ 813 ((WEEKDAY) == RTC_WEEKDAY_TUESDAY) || \ 814 ((WEEKDAY) == RTC_WEEKDAY_WEDNESDAY) || \ 815 ((WEEKDAY) == RTC_WEEKDAY_THURSDAY) || \ 816 ((WEEKDAY) == RTC_WEEKDAY_FRIDAY) || \ 817 ((WEEKDAY) == RTC_WEEKDAY_SATURDAY) || \ 818 ((WEEKDAY) == RTC_WEEKDAY_SUNDAY)) 819 #define IS_RTC_ALARM_DATE_WEEKDAY_SEL(SEL) (((SEL) == RTC_ALARMDATEWEEKDAYSEL_DATE) || \ 820 ((SEL) == RTC_ALARMDATEWEEKDAYSEL_WEEKDAY)) 821 #define IS_RTC_ALARM_MASK(MASK) (((MASK) & 0x7F7F7F7FU) == (uint32_t)RESET) 822 #define IS_RTC_ALARM(ALARM) (((ALARM) == RTC_ALARM_A) || ((ALARM) == RTC_ALARM_B)) 823 #define IS_RTC_ALARM_SUB_SECOND_VALUE(VALUE) ((VALUE) <= 0x00007FFFU) 824 825 #define IS_RTC_ALARM_SUB_SECOND_MASK(MASK) (((MASK) == RTC_ALARMSUBSECONDMASK_ALL) || \ 826 ((MASK) == RTC_ALARMSUBSECONDMASK_SS14_1) || \ 827 ((MASK) == RTC_ALARMSUBSECONDMASK_SS14_2) || \ 828 ((MASK) == RTC_ALARMSUBSECONDMASK_SS14_3) || \ 829 ((MASK) == RTC_ALARMSUBSECONDMASK_SS14_4) || \ 830 ((MASK) == RTC_ALARMSUBSECONDMASK_SS14_5) || \ 831 ((MASK) == RTC_ALARMSUBSECONDMASK_SS14_6) || \ 832 ((MASK) == RTC_ALARMSUBSECONDMASK_SS14_7) || \ 833 ((MASK) == RTC_ALARMSUBSECONDMASK_SS14_8) || \ 834 ((MASK) == RTC_ALARMSUBSECONDMASK_SS14_9) || \ 835 ((MASK) == RTC_ALARMSUBSECONDMASK_SS14_10) || \ 836 ((MASK) == RTC_ALARMSUBSECONDMASK_SS14_11) || \ 837 ((MASK) == RTC_ALARMSUBSECONDMASK_SS14_12) || \ 838 ((MASK) == RTC_ALARMSUBSECONDMASK_SS14_13) || \ 839 ((MASK) == RTC_ALARMSUBSECONDMASK_SS14) || \ 840 ((MASK) == RTC_ALARMSUBSECONDMASK_NONE)) 841 /** 842 * @} 843 */ 844 845 /** 846 * @} 847 */ 848 849 /* Private functions ---------------------------------------------------------*/ 850 /** @defgroup RTC_Private_Functions RTC Private Functions 851 * @{ 852 */ 853 HAL_StatusTypeDef RTC_EnterInitMode(RTC_HandleTypeDef* hrtc); 854 uint8_t RTC_ByteToBcd2(uint8_t Value); 855 uint8_t RTC_Bcd2ToByte(uint8_t Value); 856 /** 857 * @} 858 */ 859 860 /** 861 * @} 862 */ 863 864 /** 865 * @} 866 */ 867 868 #ifdef __cplusplus 869 } 870 #endif 871 872 #endif /* __STM32F4xx_HAL_RTC_H */ 873 874 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 875