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