1 /** 2 ****************************************************************************** 3 * @file stm32c0xx_hal_rtc.h 4 * @author MCD Application Team 5 * @brief Header file of RTC HAL module. 6 ****************************************************************************** 7 * @attention 8 * 9 * Copyright (c) 2022 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 STM32C0xx_HAL_RTC_H 21 #define STM32C0xx_HAL_RTC_H 22 23 #ifdef __cplusplus 24 extern "C" { 25 #endif 26 27 /* Includes ------------------------------------------------------------------*/ 28 #include "stm32c0xx_hal_def.h" 29 30 /** @addtogroup STM32C0xx_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 93 if the RTC_HOURFORMAT_12 is selected. 94 This parameter must be a number between Min_Data = 0 and Max_Data = 23 95 if the RTC_HOURFORMAT_24 is selected */ 96 97 uint8_t Minutes; /*!< Specifies the RTC Time Minutes. 98 This parameter must be a number between Min_Data = 0 and Max_Data = 59 */ 99 100 uint8_t Seconds; /*!< Specifies the RTC Time Seconds. 101 This parameter must be a number between Min_Data = 0 and Max_Data = 59 */ 102 103 uint8_t TimeFormat; /*!< Specifies the RTC AM/PM Time. 104 This parameter can be a value of @ref RTC_AM_PM_Definitions */ 105 106 uint32_t SubSeconds; /*!< Specifies the RTC_SSR RTC Sub Second register content. 107 This parameter corresponds to a time unit range between [0-1] Second 108 with [1 Sec / SecondFraction +1] granularity */ 109 110 uint32_t SecondFraction; /*!< Specifies the range or granularity of Sub Second register content 111 corresponding to Synchronous pre-scaler factor value (PREDIV_S) 112 This parameter corresponds to a time unit range between [0-1] Second 113 with [1 Sec / SecondFraction +1] granularity. 114 This field will be used only by HAL_RTC_GetTime function */ 115 116 uint32_t DayLightSaving; /*!< Specifies RTC_DayLightSaveOperation: the value of hour adjustment. 117 This parameter can be a value of @ref RTC_DayLightSaving_Definitions */ 118 119 uint32_t StoreOperation; /*!< Specifies RTC_StoreOperation value to be written in the BKP bit 120 in CR register to store the operation. 121 This parameter can be a value of @ref RTC_StoreOperation_Definitions */ 122 } RTC_TimeTypeDef; 123 124 /** 125 * @brief RTC Date structure definition 126 */ 127 typedef struct 128 { 129 uint8_t WeekDay; /*!< Specifies the RTC Date WeekDay. 130 This parameter can be a value of @ref RTC_WeekDay_Definitions */ 131 132 uint8_t Month; /*!< Specifies the RTC Date Month (in BCD format). 133 This parameter can be a value of @ref RTC_Month_Date_Definitions */ 134 135 uint8_t Date; /*!< Specifies the RTC Date. 136 This parameter must be a number between Min_Data = 1 and Max_Data = 31 */ 137 138 uint8_t Year; /*!< Specifies the RTC Date Year. 139 This parameter must be a number between Min_Data = 0 and Max_Data = 99 */ 140 141 } RTC_DateTypeDef; 142 143 /** 144 * @brief RTC Alarm structure definition 145 */ 146 typedef struct 147 { 148 RTC_TimeTypeDef AlarmTime; /*!< Specifies the RTC Alarm Time members */ 149 150 uint32_t AlarmMask; /*!< Specifies the RTC Alarm Masks. 151 This parameter can be a value of @ref RTC_AlarmMask_Definitions */ 152 153 uint32_t AlarmSubSecondMask; /*!< Specifies the RTC Alarm SubSeconds Masks. 154 This parameter can be a value of @ref RTC_Alarm_Sub_Seconds_Masks_Definitions */ 155 156 uint32_t AlarmDateWeekDaySel; /*!< Specifies the RTC Alarm is on Date or WeekDay. 157 This parameter can be a value of @ref RTC_AlarmDateWeekDay_Definitions */ 158 159 uint8_t AlarmDateWeekDay; /*!< Specifies the RTC Alarm Date/WeekDay. 160 If the Alarm Date is selected, this parameter must be set to a value 161 in the 1-31 range. 162 If the Alarm WeekDay is selected, this parameter can be a value of 163 @ref RTC_WeekDay_Definitions */ 164 165 uint32_t Alarm; /*!< Specifies the alarm . 166 This parameter can be a value of @ref RTC_Alarms_Definitions */ 167 } RTC_AlarmTypeDef; 168 169 /** 170 * @brief RTC Handle Structure definition 171 */ 172 #if (USE_HAL_RTC_REGISTER_CALLBACKS == 1) 173 typedef struct __RTC_HandleTypeDef 174 #else 175 typedef struct 176 #endif /* USE_HAL_RTC_REGISTER_CALLBACKS */ 177 { 178 RTC_TypeDef *Instance; /*!< Register base address */ 179 180 RTC_InitTypeDef Init; /*!< RTC required parameters */ 181 182 HAL_LockTypeDef Lock; /*!< RTC locking object */ 183 184 __IO HAL_RTCStateTypeDef State; /*!< Time communication state */ 185 186 #if (USE_HAL_RTC_REGISTER_CALLBACKS == 1) 187 void (* AlarmAEventCallback)(struct __RTC_HandleTypeDef *hrtc); /*!< RTC Alarm A Event callback */ 188 189 void (* AlarmBEventCallback)(struct __RTC_HandleTypeDef *hrtc); /*!< RTC Alarm B Event callback */ 190 191 void (* TimeStampEventCallback)(struct __RTC_HandleTypeDef *hrtc); /*!< RTC TimeStamp Event callback */ 192 193 void (* MspInitCallback)(struct __RTC_HandleTypeDef *hrtc); /*!< RTC Msp Init callback */ 194 195 void (* MspDeInitCallback)(struct __RTC_HandleTypeDef *hrtc); /*!< RTC Msp DeInit callback */ 196 197 #endif /* (USE_HAL_RTC_REGISTER_CALLBACKS) */ 198 199 } RTC_HandleTypeDef; 200 201 #if (USE_HAL_RTC_REGISTER_CALLBACKS == 1) 202 /** 203 * @brief HAL RTC Callback ID enumeration definition 204 */ 205 typedef enum 206 { 207 HAL_RTC_ALARM_A_EVENT_CB_ID = 0x00U, /*!< RTC Alarm A Event Callback ID */ 208 HAL_RTC_TIMESTAMP_EVENT_CB_ID = 0x02U, /*!< RTC TimeStamp Event 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 0U 232 #define RTC_HOURFORMAT_12 RTC_CR_FMT 233 /** 234 * @} 235 */ 236 237 /** @defgroup RTCEx_Output_selection_Definitions RTCEx Output Selection Definition 238 * @{ 239 */ 240 #define RTC_OUTPUT_DISABLE 0U 241 #define RTC_OUTPUT_ALARMA RTC_CR_OSEL_0 242 243 /** 244 * @} 245 */ 246 247 /** @defgroup RTC_Output_Polarity_Definitions RTC Output Polarity Definitions 248 * @{ 249 */ 250 #define RTC_OUTPUT_POLARITY_HIGH 0U 251 #define RTC_OUTPUT_POLARITY_LOW RTC_CR_POL 252 /** 253 * @} 254 */ 255 256 /** @defgroup RTC_Output_Type_ALARM_OUT RTC Output Type ALARM OUT 257 * @{ 258 */ 259 #define RTC_OUTPUT_TYPE_PUSHPULL 0U 260 #define RTC_OUTPUT_TYPE_OPENDRAIN RTC_CR_TAMPALRM_TYPE 261 /** 262 * @} 263 */ 264 265 /** @defgroup RTC_Output_PullUp_ALARM_OUT RTC Output Pull-Up ALARM OUT 266 * @{ 267 */ 268 #define RTC_OUTPUT_PULLUP_NONE 0U 269 #define RTC_OUTPUT_PULLUP_ON RTC_CR_TAMPALRM_PU 270 /** 271 * @} 272 */ 273 274 /** @defgroup RTC_Output_ALARM_OUT_Remap RTC Output ALARM OUT Remap 275 * @{ 276 */ 277 #define RTC_OUTPUT_REMAP_NONE 0U 278 #define RTC_OUTPUT_REMAP_POS1 RTC_CR_OUT2EN 279 /** 280 * @} 281 */ 282 283 /** @defgroup RTC_AM_PM_Definitions RTC AM PM Definitions 284 * @{ 285 */ 286 #define RTC_HOURFORMAT12_AM ((uint8_t)0U) 287 #define RTC_HOURFORMAT12_PM ((uint8_t)1U) 288 /** 289 * @} 290 */ 291 292 /** @defgroup RTC_DayLightSaving_Definitions RTC DayLightSaving Definitions 293 * @{ 294 */ 295 #define RTC_DAYLIGHTSAVING_SUB1H RTC_CR_SUB1H 296 #define RTC_DAYLIGHTSAVING_ADD1H RTC_CR_ADD1H 297 #define RTC_DAYLIGHTSAVING_NONE 0U 298 /** 299 * @} 300 */ 301 302 /** @defgroup RTC_StoreOperation_Definitions RTC StoreOperation Definitions 303 * @{ 304 */ 305 #define RTC_STOREOPERATION_RESET 0U 306 #define RTC_STOREOPERATION_SET RTC_CR_BKP 307 /** 308 * @} 309 */ 310 311 /** @defgroup RTC_Input_parameter_format_definitions RTC Input Parameter Format Definitions 312 * @{ 313 */ 314 #define RTC_FORMAT_BIN 0U 315 #define RTC_FORMAT_BCD 1U 316 /** 317 * @} 318 */ 319 320 /** @defgroup RTC_Month_Date_Definitions RTC Month Date Definitions 321 * @{ 322 */ 323 324 /* Coded in BCD format */ 325 #define RTC_MONTH_JANUARY ((uint8_t)0x01U) 326 #define RTC_MONTH_FEBRUARY ((uint8_t)0x02U) 327 #define RTC_MONTH_MARCH ((uint8_t)0x03U) 328 #define RTC_MONTH_APRIL ((uint8_t)0x04U) 329 #define RTC_MONTH_MAY ((uint8_t)0x05U) 330 #define RTC_MONTH_JUNE ((uint8_t)0x06U) 331 #define RTC_MONTH_JULY ((uint8_t)0x07U) 332 #define RTC_MONTH_AUGUST ((uint8_t)0x08U) 333 #define RTC_MONTH_SEPTEMBER ((uint8_t)0x09U) 334 #define RTC_MONTH_OCTOBER ((uint8_t)0x10U) 335 #define RTC_MONTH_NOVEMBER ((uint8_t)0x11U) 336 #define RTC_MONTH_DECEMBER ((uint8_t)0x12U) 337 338 /** 339 * @} 340 */ 341 342 /** @defgroup RTC_WeekDay_Definitions RTC WeekDay Definitions 343 * @{ 344 */ 345 #define RTC_WEEKDAY_MONDAY ((uint8_t)0x01U) 346 #define RTC_WEEKDAY_TUESDAY ((uint8_t)0x02U) 347 #define RTC_WEEKDAY_WEDNESDAY ((uint8_t)0x03U) 348 #define RTC_WEEKDAY_THURSDAY ((uint8_t)0x04U) 349 #define RTC_WEEKDAY_FRIDAY ((uint8_t)0x05U) 350 #define RTC_WEEKDAY_SATURDAY ((uint8_t)0x06U) 351 #define RTC_WEEKDAY_SUNDAY ((uint8_t)0x07U) 352 353 /** 354 * @} 355 */ 356 357 /** @defgroup RTC_AlarmDateWeekDay_Definitions RTC AlarmDateWeekDay Definitions 358 * @{ 359 */ 360 #define RTC_ALARMDATEWEEKDAYSEL_DATE 0U 361 #define RTC_ALARMDATEWEEKDAYSEL_WEEKDAY RTC_ALRMAR_WDSEL 362 363 /** 364 * @} 365 */ 366 367 /** @defgroup RTC_AlarmMask_Definitions RTC AlarmMask Definitions 368 * @{ 369 */ 370 #define RTC_ALARMMASK_NONE 0U 371 #define RTC_ALARMMASK_DATEWEEKDAY RTC_ALRMAR_MSK4 372 #define RTC_ALARMMASK_HOURS RTC_ALRMAR_MSK3 373 #define RTC_ALARMMASK_MINUTES RTC_ALRMAR_MSK2 374 #define RTC_ALARMMASK_SECONDS RTC_ALRMAR_MSK1 375 #define RTC_ALARMMASK_ALL (RTC_ALARMMASK_NONE | RTC_ALARMMASK_DATEWEEKDAY | \ 376 RTC_ALARMMASK_HOURS | RTC_ALARMMASK_MINUTES | \ 377 RTC_ALARMMASK_SECONDS) 378 379 /** 380 * @} 381 */ 382 383 /** @defgroup RTC_Alarms_Definitions RTC Alarms Definitions 384 * @{ 385 */ 386 #define RTC_ALARM_A RTC_CR_ALRAE 387 388 /** 389 * @} 390 */ 391 392 393 /** @defgroup RTC_Alarm_Sub_Seconds_Masks_Definitions RTC Alarm Sub Seconds Masks Definitions 394 * @{ 395 */ 396 #define RTC_ALARMSUBSECONDMASK_ALL 0x00000000U /*!< All Alarm SS fields are masked. 397 There is no comparison on sub seconds 398 for Alarm */ 399 #define RTC_ALARMSUBSECONDMASK_SS14_1 RTC_ALRMASSR_MASKSS_0 /*!< SS[14:1] not used in Alarm 400 comparison. Only SS[0] is compared. */ 401 #define RTC_ALARMSUBSECONDMASK_SS14_2 RTC_ALRMASSR_MASKSS_1 /*!< SS[14:2] not used in Alarm 402 comparison. Only SS[1:0] are compared */ 403 #define RTC_ALARMSUBSECONDMASK_SS14_3 (RTC_ALRMASSR_MASKSS_0 | RTC_ALRMASSR_MASKSS_1) /*!< SS[14:3] not used in Alarm 404 comparison. Only SS[2:0] 405 are compared */ 406 #define RTC_ALARMSUBSECONDMASK_SS14_4 RTC_ALRMASSR_MASKSS_2 /*!< SS[14:4] not used in Alarm 407 comparison. Only SS[3:0] 408 are compared */ 409 #define RTC_ALARMSUBSECONDMASK_SS14_5 (RTC_ALRMASSR_MASKSS_0 | RTC_ALRMASSR_MASKSS_2) /*!< SS[14:5] not used in Alarm 410 comparison. Only SS[4:0] 411 are compared */ 412 #define RTC_ALARMSUBSECONDMASK_SS14_6 (RTC_ALRMASSR_MASKSS_1 | RTC_ALRMASSR_MASKSS_2) /*!< SS[14:6] not used in Alarm 413 comparison.Only SS[5:0] 414 are compared */ 415 #define RTC_ALARMSUBSECONDMASK_SS14_7 (RTC_ALRMASSR_MASKSS_0 | RTC_ALRMASSR_MASKSS_1 | \ 416 RTC_ALRMASSR_MASKSS_2) /*!< SS[14:7] not used in Alarm 417 comparison. Only SS[6:0] 418 are compared */ 419 #define RTC_ALARMSUBSECONDMASK_SS14_8 RTC_ALRMASSR_MASKSS_3 /*!< SS[14:8] not used in Alarm 420 comparison. Only SS[7:0] 421 are compared */ 422 #define RTC_ALARMSUBSECONDMASK_SS14_9 (RTC_ALRMASSR_MASKSS_0 | RTC_ALRMASSR_MASKSS_3) /*!< SS[14:9] not used in Alarm 423 comparison. Only SS[8:0] 424 are compared */ 425 #define RTC_ALARMSUBSECONDMASK_SS14_10 (RTC_ALRMASSR_MASKSS_1 | RTC_ALRMASSR_MASKSS_3) /*!< SS[14:10] not used in 426 Alarm comparison. Only 427 SS[9:0] are compared */ 428 #define RTC_ALARMSUBSECONDMASK_SS14_11 (RTC_ALRMASSR_MASKSS_0 | RTC_ALRMASSR_MASKSS_1 | \ 429 RTC_ALRMASSR_MASKSS_3) /*!< SS[14:11] not used in 430 Alarm comparison. Only 431 SS[10:0] are compared */ 432 #define RTC_ALARMSUBSECONDMASK_SS14_12 (RTC_ALRMASSR_MASKSS_2 | RTC_ALRMASSR_MASKSS_3) /*!< SS[14:12] not used in 433 Alarm comparison. Only 434 SS[11:0] are compared */ 435 #define RTC_ALARMSUBSECONDMASK_SS14_13 (RTC_ALRMASSR_MASKSS_0 | RTC_ALRMASSR_MASKSS_2 | \ 436 RTC_ALRMASSR_MASKSS_3) /*!< SS[14:13] not used in 437 Alarm comparison. Only 438 SS[12:0] are compared */ 439 #define RTC_ALARMSUBSECONDMASK_SS14 (RTC_ALRMASSR_MASKSS_1 | RTC_ALRMASSR_MASKSS_2 | \ 440 RTC_ALRMASSR_MASKSS_3) /*!< SS[14] not used in Alarm 441 comparison. Only SS[13:0] 442 are compared */ 443 #define RTC_ALARMSUBSECONDMASK_NONE RTC_ALRMASSR_MASKSS /*!< SS[14:0] are compared and 444 must match to activate 445 alarm. */ 446 /** 447 * @} 448 */ 449 450 /** @defgroup RTC_Interrupts_Definitions RTC Interrupts Definitions 451 * @{ 452 */ 453 #define RTC_IT_TS RTC_CR_TSIE /*!< Enable Timestamp Interrupt */ 454 #define RTC_IT_ALRA RTC_CR_ALRAIE /*!< Enable Alarm A Interrupt */ 455 456 /** 457 * @} 458 */ 459 460 /** @defgroup RTC_Flag_Mask RTC Flag Mask (5bits) describe __HAL_RTC_GET_FLAG() 461 * @{ 462 */ 463 #define RTC_FLAG_MASK 0x001FU /*!< RTC flags mask (5bits) */ 464 /** 465 * @} 466 */ 467 468 /** @defgroup RTC_Flags_Definitions RTC Flags Definitions 469 * Elements values convention: 000000XX000YYYYYb 470 * - YYYYY : Interrupt flag position in the XX register (5bits) 471 * - XX : Interrupt status register (2bits) 472 * - 01: ICSR register 473 * - 10: SR or SCR or MISR or SMISR registers 474 * @{ 475 */ 476 #define RTC_FLAG_RECALPF (0x00000100U | RTC_ICSR_RECALPF_Pos) /*!< Recalibration pending Flag */ 477 #define RTC_FLAG_INITF (0x00000100U | RTC_ICSR_INITF_Pos) /*!< Initialization flag */ 478 #define RTC_FLAG_RSF (0x00000100U | RTC_ICSR_RSF_Pos) /*!< Registers synchronization flag */ 479 #define RTC_FLAG_INITS (0x00000100U | RTC_ICSR_INITS_Pos) /*!< Initialization status flag */ 480 #define RTC_FLAG_SHPF (0x00000100U | RTC_ICSR_SHPF_Pos) /*!< Shift operation pending flag */ 481 #define RTC_FLAG_ALRAWF (0x00000100U | RTC_ICSR_ALRAWF_Pos) /*!< Alarm A write flag */ 482 #define RTC_FLAG_TSOVF (0x00000200U | RTC_SR_TSOVF_Pos) /*!< Time-stamp overflow flag */ 483 #define RTC_FLAG_TSF (0x00000200U | RTC_SR_TSF_Pos) /*!< Time-stamp flag */ 484 #define RTC_FLAG_ALRAF (0x00000200U | RTC_SR_ALRAF_Pos) /*!< Alarm A flag */ 485 /** 486 * @} 487 */ 488 489 /** @defgroup RTC_Clear_Flags_Definitions RTC Clear Flags Definitions 490 * @{ 491 */ 492 #define RTC_CLEAR_TSOVF RTC_SCR_CTSOVF /*!< Clear Time-stamp overflow flag */ 493 #define RTC_CLEAR_TSF RTC_SCR_CTSF /*!< Clear Time-stamp flag */ 494 #define RTC_CLEAR_ALRAF RTC_SCR_CALRAF /*!< Clear Alarm A flag */ 495 /** 496 * @} 497 */ 498 499 /** 500 * @} 501 */ 502 503 /* Exported macros -----------------------------------------------------------*/ 504 /** @defgroup RTC_Exported_Macros RTC Exported Macros 505 * @{ 506 */ 507 508 /** @brief Reset RTC handle state 509 * @param __HANDLE__ RTC handle. 510 * @retval None 511 */ 512 #if (USE_HAL_RTC_REGISTER_CALLBACKS == 1) 513 #define __HAL_RTC_RESET_HANDLE_STATE(__HANDLE__) do{\ 514 (__HANDLE__)->State = HAL_RTC_STATE_RESET;\ 515 (__HANDLE__)->MspInitCallback = NULL;\ 516 (__HANDLE__)->MspDeInitCallback = NULL;\ 517 }while(0) 518 #else 519 #define __HAL_RTC_RESET_HANDLE_STATE(__HANDLE__) ((__HANDLE__)->State = HAL_RTC_STATE_RESET) 520 #endif /* USE_HAL_RTC_REGISTER_CALLBACKS */ 521 522 /** 523 * @brief Disable the write protection for RTC registers. 524 * @param __HANDLE__ specifies the RTC handle. 525 * @retval None 526 */ 527 #define __HAL_RTC_WRITEPROTECTION_DISABLE(__HANDLE__) \ 528 do{ \ 529 (__HANDLE__)->Instance->WPR = 0xCAU; \ 530 (__HANDLE__)->Instance->WPR = 0x53U; \ 531 } while(0U) 532 533 /** 534 * @brief Enable the write protection for RTC registers. 535 * @param __HANDLE__ specifies the RTC handle. 536 * @retval None 537 */ 538 #define __HAL_RTC_WRITEPROTECTION_ENABLE(__HANDLE__) \ 539 do{ \ 540 (__HANDLE__)->Instance->WPR = 0xFFU; \ 541 } while(0U) 542 543 /** 544 * @brief Check whether the RTC Calendar is initialized. 545 * @param __HANDLE__ specifies the RTC handle. 546 * @retval None 547 */ 548 #define __HAL_RTC_IS_CALENDAR_INITIALIZED(__HANDLE__) (((((__HANDLE__)->Instance->ICSR) &\ 549 (RTC_ICSR_INITS)) == RTC_ICSR_INITS) ? 1U : 0U) 550 551 /** 552 * @brief Add 1 hour (summer time change). 553 * @param __HANDLE__ specifies the RTC handle. 554 * @param __BKP__ Backup 555 * This parameter can be: 556 * @arg @ref RTC_STOREOPERATION_RESET 557 * @arg @ref RTC_STOREOPERATION_SET 558 * @retval None 559 */ 560 #define __HAL_RTC_DAYLIGHT_SAVING_TIME_ADD1H(__HANDLE__, __BKP__) \ 561 do { \ 562 __HAL_RTC_WRITEPROTECTION_DISABLE(__HANDLE__); \ 563 SET_BIT((__HANDLE__)->Instance->CR, RTC_CR_ADD1H); \ 564 MODIFY_REG((__HANDLE__)->Instance->CR, RTC_CR_BKP , (__BKP__)); \ 565 __HAL_RTC_WRITEPROTECTION_ENABLE(__HANDLE__); \ 566 } while(0); 567 568 /** 569 * @brief Subtract 1 hour (winter time change). 570 * @param __HANDLE__ specifies the RTC handle. 571 * @param __BKP__ Backup 572 * This parameter can be: 573 * @arg @ref RTC_STOREOPERATION_RESET 574 * @arg @ref RTC_STOREOPERATION_SET 575 * @retval None 576 */ 577 #define __HAL_RTC_DAYLIGHT_SAVING_TIME_SUB1H(__HANDLE__, __BKP__) \ 578 do { \ 579 __HAL_RTC_WRITEPROTECTION_DISABLE(__HANDLE__); \ 580 SET_BIT((__HANDLE__)->Instance->CR, RTC_CR_SUB1H); \ 581 MODIFY_REG((__HANDLE__)->Instance->CR, RTC_CR_BKP , (__BKP__)); \ 582 __HAL_RTC_WRITEPROTECTION_ENABLE(__HANDLE__); \ 583 } while(0); 584 585 /** 586 * @brief Enable the RTC ALARMA peripheral. 587 * @param __HANDLE__ specifies the RTC handle. 588 * @retval None 589 */ 590 #define __HAL_RTC_ALARMA_ENABLE(__HANDLE__) ((__HANDLE__)->Instance->CR |= (RTC_CR_ALRAE)) 591 592 /** 593 * @brief Disable the RTC ALARMA peripheral. 594 * @param __HANDLE__ specifies the RTC handle. 595 * @retval None 596 */ 597 #define __HAL_RTC_ALARMA_DISABLE(__HANDLE__) ((__HANDLE__)->Instance->CR &= ~(RTC_CR_ALRAE)) 598 599 /** 600 * @brief Enable the RTC Alarm interrupt. 601 * @param __HANDLE__ specifies the RTC handle. 602 * @param __INTERRUPT__ specifies the RTC Alarm interrupt sources to be enabled or disabled. 603 * This parameter can be any combination of the following values: 604 * @arg @ref RTC_IT_ALRA Alarm A interrupt, @ref RTC_Interrupts_Definitions 605 * @retval None 606 */ 607 #define __HAL_RTC_ALARM_ENABLE_IT(__HANDLE__, __INTERRUPT__) ((__HANDLE__)->Instance->CR |= (__INTERRUPT__)) 608 609 /** 610 * @brief Disable the RTC Alarm interrupt. 611 * @param __HANDLE__ specifies the RTC handle. 612 * @param __INTERRUPT__ specifies the RTC Alarm interrupt sources to be enabled or disabled. 613 * This parameter can be any combination of the following values: 614 * @arg @ref RTC_IT_ALRA Alarm A interrupt 615 * @retval None 616 */ 617 #define __HAL_RTC_ALARM_DISABLE_IT(__HANDLE__, __INTERRUPT__) ((__HANDLE__)->Instance->CR &= ~(__INTERRUPT__)) 618 619 /** 620 * @brief Check whether the specified RTC Alarm interrupt has occurred or not. 621 * @param __HANDLE__ specifies the RTC handle. 622 * @param __INTERRUPT__ specifies the RTC Alarm interrupt sources to check. 623 * This parameter can be: 624 * @arg @ref RTC_IT_ALRA Alarm A interrupt 625 * @retval None 626 */ 627 #define __HAL_RTC_ALARM_GET_IT(__HANDLE__, __INTERRUPT__) (((((__HANDLE__)->Instance->SR\ 628 )& ((__INTERRUPT__)>> 12U)) != 0U)? 1U : 0U) 629 630 /** 631 * @brief Check whether the specified RTC Alarm interrupt has been enabled or not. 632 * @param __HANDLE__ specifies the RTC handle. 633 * @param __INTERRUPT__ specifies the RTC Alarm interrupt sources to check. 634 * This parameter can be: 635 * @arg @ref RTC_IT_ALRA Alarm A interrupt 636 * @retval None 637 */ 638 #define __HAL_RTC_ALARM_GET_IT_SOURCE(__HANDLE__, __INTERRUPT__) (((((__HANDLE__)->Instance->CR)\ 639 & (__INTERRUPT__)) != 0U) ? 1U : 0U) 640 641 /** 642 * @brief Get the selected RTC Alarms flag status. 643 * @param __HANDLE__ specifies the RTC handle. 644 * @param __FLAG__ specifies the RTC Alarm Flag sources to check. 645 * This parameter can be: 646 * @arg @ref RTC_FLAG_ALRAF 647 * @arg @ref RTC_FLAG_ALRAWF 648 * @retval None 649 */ 650 #define __HAL_RTC_ALARM_GET_FLAG(__HANDLE__, __FLAG__) (__HAL_RTC_GET_FLAG((__HANDLE__), (__FLAG__))) 651 652 /** 653 * @brief Clear the RTC Alarms pending flags. 654 * @param __HANDLE__ specifies the RTC handle. 655 * @param __FLAG__ specifies the RTC Alarm Flag sources to clear. 656 * This parameter can be: 657 * @arg @ref RTC_FLAG_ALRAF 658 * @retval None 659 */ 660 #define __HAL_RTC_ALARM_CLEAR_FLAG(__HANDLE__, __FLAG__) (__HAL_RTC_CLEAR_FLAG((__HANDLE__), RTC_CLEAR_ALRAF)) 661 662 /** 663 * @brief Enable interrupt on the RTC Alarm associated Exti line. 664 * @retval None 665 */ 666 #define __HAL_RTC_ALARM_EXTI_ENABLE_IT() (EXTI->IMR1 |= RTC_EXTI_LINE_ALARM_EVENT) 667 668 /** 669 * @brief Disable interrupt on the RTC Alarm associated Exti line. 670 * @retval None 671 */ 672 #define __HAL_RTC_ALARM_EXTI_DISABLE_IT() (EXTI->IMR1 &= ~(RTC_EXTI_LINE_ALARM_EVENT)) 673 674 /** 675 * @brief Enable event on the RTC Alarm associated Exti line. 676 * @retval None. 677 */ 678 #define __HAL_RTC_ALARM_EXTI_ENABLE_EVENT() (EXTI->EMR1 |= RTC_EXTI_LINE_ALARM_EVENT) 679 680 /** 681 * @brief Disable event on the RTC Alarm associated Exti line. 682 * @retval None. 683 */ 684 #define __HAL_RTC_ALARM_EXTI_DISABLE_EVENT() (EXTI->EMR1 &= ~(RTC_EXTI_LINE_ALARM_EVENT)) 685 686 /** 687 * @} 688 */ 689 690 /* Include RTC HAL Extended module */ 691 #include "stm32c0xx_hal_rtc_ex.h" 692 693 /* Exported functions --------------------------------------------------------*/ 694 /** @defgroup RTC_Exported_Functions RTC Exported Functions 695 * @{ 696 */ 697 698 /** @defgroup RTC_Exported_Functions_Group1 Initialization and de-initialization functions 699 * @{ 700 */ 701 /* Initialization and de-initialization functions ****************************/ 702 HAL_StatusTypeDef HAL_RTC_Init(RTC_HandleTypeDef *hrtc); 703 HAL_StatusTypeDef HAL_RTC_DeInit(RTC_HandleTypeDef *hrtc); 704 705 void HAL_RTC_MspInit(RTC_HandleTypeDef *hrtc); 706 void HAL_RTC_MspDeInit(RTC_HandleTypeDef *hrtc); 707 708 /* Callbacks Register/UnRegister functions ***********************************/ 709 #if (USE_HAL_RTC_REGISTER_CALLBACKS == 1) 710 HAL_StatusTypeDef HAL_RTC_RegisterCallback(RTC_HandleTypeDef *hrtc, HAL_RTC_CallbackIDTypeDef CallbackID, 711 pRTC_CallbackTypeDef pCallback); 712 HAL_StatusTypeDef HAL_RTC_UnRegisterCallback(RTC_HandleTypeDef *hrtc, HAL_RTC_CallbackIDTypeDef CallbackID); 713 #endif /* USE_HAL_RTC_REGISTER_CALLBACKS */ 714 715 /** 716 * @} 717 */ 718 719 /** @defgroup RTC_Exported_Functions_Group2 RTC Time and Date functions 720 * @{ 721 */ 722 /* RTC Time and Date functions ************************************************/ 723 HAL_StatusTypeDef HAL_RTC_SetTime(RTC_HandleTypeDef *hrtc, RTC_TimeTypeDef *sTime, uint32_t Format); 724 HAL_StatusTypeDef HAL_RTC_GetTime(RTC_HandleTypeDef *hrtc, RTC_TimeTypeDef *sTime, uint32_t Format); 725 HAL_StatusTypeDef HAL_RTC_SetDate(RTC_HandleTypeDef *hrtc, RTC_DateTypeDef *sDate, uint32_t Format); 726 HAL_StatusTypeDef HAL_RTC_GetDate(const RTC_HandleTypeDef *hrtc, RTC_DateTypeDef *sDate, uint32_t Format); 727 /** 728 * @} 729 */ 730 731 /** @defgroup RTC_Exported_Functions_Group3 RTC Alarm functions 732 * @{ 733 */ 734 /* RTC Alarm functions ********************************************************/ 735 HAL_StatusTypeDef HAL_RTC_SetAlarm(RTC_HandleTypeDef *hrtc, RTC_AlarmTypeDef *sAlarm, uint32_t Format); 736 HAL_StatusTypeDef HAL_RTC_SetAlarm_IT(RTC_HandleTypeDef *hrtc, RTC_AlarmTypeDef *sAlarm, uint32_t Format); 737 HAL_StatusTypeDef HAL_RTC_DeactivateAlarm(RTC_HandleTypeDef *hrtc, uint32_t Alarm); 738 HAL_StatusTypeDef HAL_RTC_GetAlarm(const RTC_HandleTypeDef *hrtc, RTC_AlarmTypeDef *sAlarm, uint32_t Alarm, 739 uint32_t Format); 740 void HAL_RTC_AlarmIRQHandler(RTC_HandleTypeDef *hrtc); 741 HAL_StatusTypeDef HAL_RTC_PollForAlarmAEvent(RTC_HandleTypeDef *hrtc, uint32_t Timeout); 742 void HAL_RTC_AlarmAEventCallback(RTC_HandleTypeDef *hrtc); 743 /** 744 * @} 745 */ 746 747 /** @defgroup RTC_Exported_Functions_Group4 Peripheral Control functions 748 * @{ 749 */ 750 /* Peripheral Control functions ***********************************************/ 751 HAL_StatusTypeDef HAL_RTC_WaitForSynchro(RTC_HandleTypeDef *hrtc); 752 /** 753 * @} 754 */ 755 756 /** @defgroup RTC_Exported_Functions_Group5 Peripheral State functions 757 * @{ 758 */ 759 /* Peripheral State functions *************************************************/ 760 HAL_RTCStateTypeDef HAL_RTC_GetState(const RTC_HandleTypeDef *hrtc); 761 /** 762 * @} 763 */ 764 765 /** 766 * @} 767 */ 768 769 /* Private types -------------------------------------------------------------*/ 770 /* Private variables ---------------------------------------------------------*/ 771 /* Private constants ---------------------------------------------------------*/ 772 /** @defgroup RTC_Private_Constants RTC Private Constants 773 * @{ 774 */ 775 /* Masks Definition */ 776 #define RTC_TR_RESERVED_MASK (RTC_TR_PM | RTC_TR_HT | RTC_TR_HU | \ 777 RTC_TR_MNT | RTC_TR_MNU| RTC_TR_ST | \ 778 RTC_TR_SU) 779 #define RTC_DR_RESERVED_MASK (RTC_DR_YT | RTC_DR_YU | RTC_DR_WDU | \ 780 RTC_DR_MT | RTC_DR_MU | RTC_DR_DT | \ 781 RTC_DR_DU) 782 #define RTC_INIT_MASK 0xFFFFFFFFU 783 #define RTC_RSF_MASK (~(RTC_ICSR_INIT | RTC_ICSR_RSF)) 784 785 #define RTC_TIMEOUT_VALUE 1000U 786 787 #define RTC_EXTI_LINE_ALARM_EVENT EXTI_IMR1_IM19 /*!< External interrupt line 19 Connected to the RTC Alarm event */ 788 789 /** 790 * @} 791 */ 792 793 /* Private macros ------------------------------------------------------------*/ 794 /** @defgroup RTC_Private_Macros RTC Private Macros 795 * @{ 796 */ 797 798 /** @defgroup RTC_IS_RTC_Definitions RTC Private macros to check input parameters 799 * @{ 800 */ 801 #define IS_RTC_OUTPUT(OUTPUT) (((OUTPUT) == RTC_OUTPUT_DISABLE) || \ 802 ((OUTPUT) == RTC_OUTPUT_ALARMA)) 803 804 #define IS_RTC_HOUR_FORMAT(FORMAT) (((FORMAT) == RTC_HOURFORMAT_12) || \ 805 ((FORMAT) == RTC_HOURFORMAT_24)) 806 807 #define IS_RTC_OUTPUT_POL(POL) (((POL) == RTC_OUTPUT_POLARITY_HIGH) || \ 808 ((POL) == RTC_OUTPUT_POLARITY_LOW)) 809 810 #define IS_RTC_OUTPUT_TYPE(TYPE) (((TYPE) == RTC_OUTPUT_TYPE_OPENDRAIN) || \ 811 ((TYPE) == RTC_OUTPUT_TYPE_PUSHPULL)) 812 813 #define IS_RTC_OUTPUT_PULLUP(TYPE) (((TYPE) == RTC_OUTPUT_PULLUP_NONE) || \ 814 ((TYPE) == RTC_OUTPUT_PULLUP_ON)) 815 816 #define IS_RTC_OUTPUT_REMAP(REMAP) (((REMAP) == RTC_OUTPUT_REMAP_NONE) || \ 817 ((REMAP) == RTC_OUTPUT_REMAP_POS1)) 818 819 #define IS_RTC_HOURFORMAT12(PM) (((PM) == RTC_HOURFORMAT12_AM) || \ 820 ((PM) == RTC_HOURFORMAT12_PM)) 821 822 #define IS_RTC_DAYLIGHT_SAVING(SAVE) (((SAVE) == RTC_DAYLIGHTSAVING_SUB1H) || \ 823 ((SAVE) == RTC_DAYLIGHTSAVING_ADD1H) || \ 824 ((SAVE) == RTC_DAYLIGHTSAVING_NONE)) 825 826 #define IS_RTC_STORE_OPERATION(OPERATION) (((OPERATION) == RTC_STOREOPERATION_RESET) || \ 827 ((OPERATION) == RTC_STOREOPERATION_SET)) 828 829 #define IS_RTC_FORMAT(FORMAT) (((FORMAT) == RTC_FORMAT_BIN) || \ 830 ((FORMAT) == RTC_FORMAT_BCD)) 831 832 #define IS_RTC_YEAR(YEAR) ((YEAR) <= 99U) 833 834 #define IS_RTC_MONTH(MONTH) (((MONTH) >= 1U) && ((MONTH) <= 12U)) 835 836 #define IS_RTC_DATE(DATE) (((DATE) >= 1U) && ((DATE) <= 31U)) 837 838 #define IS_RTC_WEEKDAY(WEEKDAY) (((WEEKDAY) == RTC_WEEKDAY_MONDAY) || \ 839 ((WEEKDAY) == RTC_WEEKDAY_TUESDAY) || \ 840 ((WEEKDAY) == RTC_WEEKDAY_WEDNESDAY) || \ 841 ((WEEKDAY) == RTC_WEEKDAY_THURSDAY) || \ 842 ((WEEKDAY) == RTC_WEEKDAY_FRIDAY) || \ 843 ((WEEKDAY) == RTC_WEEKDAY_SATURDAY) || \ 844 ((WEEKDAY) == RTC_WEEKDAY_SUNDAY)) 845 846 #define IS_RTC_ALARM_DATE_WEEKDAY_DATE(DATE) (((DATE) >0U) && ((DATE) <= 31U)) 847 848 #define IS_RTC_ALARM_DATE_WEEKDAY_WEEKDAY(WEEKDAY) (((WEEKDAY) == RTC_WEEKDAY_MONDAY) || \ 849 ((WEEKDAY) == RTC_WEEKDAY_TUESDAY) || \ 850 ((WEEKDAY) == RTC_WEEKDAY_WEDNESDAY) || \ 851 ((WEEKDAY) == RTC_WEEKDAY_THURSDAY) || \ 852 ((WEEKDAY) == RTC_WEEKDAY_FRIDAY) || \ 853 ((WEEKDAY) == RTC_WEEKDAY_SATURDAY) || \ 854 ((WEEKDAY) == RTC_WEEKDAY_SUNDAY)) 855 856 #define IS_RTC_ALARM_DATE_WEEKDAY_SEL(SEL) (((SEL) == RTC_ALARMDATEWEEKDAYSEL_DATE) || \ 857 ((SEL) == RTC_ALARMDATEWEEKDAYSEL_WEEKDAY)) 858 859 #define IS_RTC_ALARM_MASK(MASK) (((MASK) & ~(RTC_ALARMMASK_ALL)) == 0U) 860 861 #define IS_RTC_ALARM(ALARM) ((ALARM) == RTC_ALARM_A) 862 863 #define IS_RTC_ALARM_SUB_SECOND_VALUE(VALUE) ((VALUE) <= RTC_ALRMASSR_SS) 864 865 #define IS_RTC_ALARM_SUB_SECOND_MASK(MASK) (((MASK) == RTC_ALARMSUBSECONDMASK_ALL) || \ 866 ((MASK) == RTC_ALARMSUBSECONDMASK_SS14_1) || \ 867 ((MASK) == RTC_ALARMSUBSECONDMASK_SS14_2) || \ 868 ((MASK) == RTC_ALARMSUBSECONDMASK_SS14_3) || \ 869 ((MASK) == RTC_ALARMSUBSECONDMASK_SS14_4) || \ 870 ((MASK) == RTC_ALARMSUBSECONDMASK_SS14_5) || \ 871 ((MASK) == RTC_ALARMSUBSECONDMASK_SS14_6) || \ 872 ((MASK) == RTC_ALARMSUBSECONDMASK_SS14_7) || \ 873 ((MASK) == RTC_ALARMSUBSECONDMASK_SS14_8) || \ 874 ((MASK) == RTC_ALARMSUBSECONDMASK_SS14_9) || \ 875 ((MASK) == RTC_ALARMSUBSECONDMASK_SS14_10) || \ 876 ((MASK) == RTC_ALARMSUBSECONDMASK_SS14_11) || \ 877 ((MASK) == RTC_ALARMSUBSECONDMASK_SS14_12) || \ 878 ((MASK) == RTC_ALARMSUBSECONDMASK_SS14_13) || \ 879 ((MASK) == RTC_ALARMSUBSECONDMASK_SS14) || \ 880 ((MASK) == RTC_ALARMSUBSECONDMASK_NONE)) 881 882 #define IS_RTC_ASYNCH_PREDIV(PREDIV) ((PREDIV) <= 0x7FU) 883 884 #define IS_RTC_SYNCH_PREDIV(PREDIV) ((PREDIV) <= 0x7FFFU) 885 886 #define IS_RTC_HOUR12(HOUR) (((HOUR) > 0U) && ((HOUR) <= 12U)) 887 888 #define IS_RTC_HOUR24(HOUR) ((HOUR) <= 23U) 889 890 #define IS_RTC_MINUTES(MINUTES) ((MINUTES) <= 59U) 891 892 #define IS_RTC_SECONDS(SECONDS) ((SECONDS) <= 59U) 893 894 /** 895 * @} 896 */ 897 898 /** 899 * @} 900 */ 901 902 /* Private functions -------------------------------------------------------------*/ 903 /** @defgroup RTC_Private_Functions RTC Private Functions 904 * @{ 905 */ 906 HAL_StatusTypeDef RTC_EnterInitMode(RTC_HandleTypeDef *hrtc); 907 HAL_StatusTypeDef RTC_ExitInitMode(RTC_HandleTypeDef *hrtc); 908 uint8_t RTC_ByteToBcd2(uint8_t Value); 909 uint8_t RTC_Bcd2ToByte(uint8_t Value); 910 /** 911 * @} 912 */ 913 914 915 /** 916 * @} 917 */ 918 919 /** 920 * @} 921 */ 922 923 #ifdef __cplusplus 924 } 925 #endif 926 927 #endif /* STM32C0xx_HAL_RTC_H */ 928 929