1 /** 2 ****************************************************************************** 3 * @file stm32wb0x_hal_rtc.h 4 * @author MCD Application Team 5 * @brief Header file of RTC HAL module. 6 ****************************************************************************** 7 * @attention 8 * 9 * Copyright (c) 2024 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 STM32WB0x_HAL_RTC_H 21 #define STM32WB0x_HAL_RTC_H 22 23 #ifdef __cplusplus 24 extern "C" { 25 #endif 26 27 /* Includes ------------------------------------------------------------------*/ 28 29 #include "stm32wb0x_hal_def.h" 30 31 /** @addtogroup STM32WB0x_HAL_Driver 32 * @{ 33 */ 34 35 /** @addtogroup RTC 36 * @{ 37 */ 38 39 /* Exported types ------------------------------------------------------------*/ 40 41 /** @defgroup RTC_Exported_Types RTC Exported Types 42 * @{ 43 */ 44 45 /** 46 * @brief HAL State structures definition 47 */ 48 typedef enum 49 { 50 HAL_RTC_STATE_RESET = 0x00U, /*!< RTC not yet initialized or disabled */ 51 HAL_RTC_STATE_READY = 0x01U, /*!< RTC initialized and ready for use */ 52 HAL_RTC_STATE_BUSY = 0x02U, /*!< RTC process is ongoing */ 53 HAL_RTC_STATE_TIMEOUT = 0x03U, /*!< RTC timeout state */ 54 HAL_RTC_STATE_ERROR = 0x04U /*!< RTC error state */ 55 } HAL_RTCStateTypeDef; 56 57 /** 58 * @brief RTC Configuration Structure definition 59 */ 60 typedef struct 61 { 62 uint32_t HourFormat; /*!< Specifies the RTC Hour Format. 63 This parameter can be a value of @ref RTC_Hour_Formats */ 64 65 uint32_t AsynchPrediv; /*!< Specifies the RTC Asynchronous Predivider value. 66 This parameter must be a number between Min_Data = 0x00 and Max_Data = 0x7F */ 67 68 uint32_t SynchPrediv; /*!< Specifies the RTC Synchronous Predivider value. 69 This parameter must be a number between Min_Data = 0x0000 and Max_Data = 0x7FFF */ 70 71 uint32_t OutPut; /*!< Specifies which signal will be routed to the RTC output. 72 This parameter can be a value of @ref RTC_Output_selection_Definitions */ 73 74 uint32_t OutPutPolarity; /*!< Specifies the polarity of the output signal. 75 This parameter can be a value of @ref RTC_Output_Polarity_Definitions */ 76 } RTC_InitTypeDef; 77 78 /** 79 * @brief RTC Time structure definition 80 */ 81 typedef struct 82 { 83 uint8_t Hours; /*!< Specifies the RTC Time Hour. 84 This parameter must be a number between Min_Data = 0 and Max_Data = 12 if the RTC_HourFormat_12 is selected 85 This parameter must be a number between Min_Data = 0 and Max_Data = 23 if the RTC_HourFormat_24 is selected */ 86 87 uint8_t Minutes; /*!< Specifies the RTC Time Minutes. 88 This parameter must be a number between Min_Data = 0 and Max_Data = 59 */ 89 90 uint8_t Seconds; /*!< Specifies the RTC Time Seconds. 91 This parameter must be a number between Min_Data = 0 and Max_Data = 59 */ 92 93 uint8_t TimeFormat; /*!< Specifies the RTC AM/PM Time. 94 This parameter can be a value of @ref RTC_AM_PM_Definitions */ 95 96 uint32_t SubSeconds; /*!< Specifies the RTC_SSR RTC Sub Second register content. 97 This parameter corresponds to a time unit range between [0-1] Second 98 with [1 Sec / SecondFraction +1] granularity */ 99 100 uint32_t SecondFraction; /*!< Specifies the range or granularity of Sub Second register content 101 corresponding to Synchronous prescaler factor value (PREDIV_S) 102 This parameter corresponds to a time unit range between [0-1] Second 103 with [1 Sec / SecondFraction +1] granularity. 104 This field will be used only by HAL_RTC_GetTime function */ 105 106 uint32_t DayLightSaving; /*!< This interface is deprecated. To manage Daylight 107 Saving Time, please use HAL_RTC_DST_xxx functions */ 108 109 uint32_t StoreOperation; /*!< This interface is deprecated. To manage Daylight 110 Saving Time, please use HAL_RTC_DST_xxx functions */ 111 } RTC_TimeTypeDef; 112 113 /** 114 * @brief RTC Date structure definition 115 */ 116 typedef struct 117 { 118 uint8_t WeekDay; /*!< Specifies the RTC Date WeekDay. 119 This parameter can be a value of @ref RTC_WeekDay_Definitions */ 120 121 uint8_t Month; /*!< Specifies the RTC Date Month (in BCD format). 122 This parameter can be a value of @ref RTC_Month_Date_Definitions */ 123 124 uint8_t Date; /*!< Specifies the RTC Date. 125 This parameter must be a number between Min_Data = 1 and Max_Data = 31 */ 126 127 uint8_t Year; /*!< Specifies the RTC Date Year. 128 This parameter must be a number between Min_Data = 0 and Max_Data = 99 */ 129 130 } RTC_DateTypeDef; 131 132 /** 133 * @brief RTC Alarm structure definition 134 */ 135 typedef struct 136 { 137 RTC_TimeTypeDef AlarmTime; /*!< Specifies the RTC Alarm Time members */ 138 139 uint32_t AlarmMask; /*!< Specifies the RTC Alarm Masks. 140 This parameter can be a value of @ref RTC_AlarmMask_Definitions */ 141 142 uint32_t AlarmSubSecondMask; /*!< Specifies the RTC Alarm SubSeconds Masks. 143 This parameter can be a value of @ref RTC_Alarm_Sub_Seconds_Masks_Definitions */ 144 145 uint32_t AlarmDateWeekDaySel; /*!< Specifies the RTC Alarm is on Date or WeekDay. 146 This parameter can be a value of @ref RTC_AlarmDateWeekDay_Definitions */ 147 148 uint8_t AlarmDateWeekDay; /*!< Specifies the RTC Alarm Date/WeekDay. 149 If the Alarm Date is selected, this parameter must be set to a value in the 1-31 range. 150 If the Alarm WeekDay is selected, this parameter can be a value of @ref RTC_WeekDay_Definitions */ 151 152 uint32_t Alarm; /*!< Specifies the alarm . 153 This parameter can be a value of @ref RTC_Alarms_Definitions */ 154 } RTC_AlarmTypeDef; 155 156 /** 157 * @brief RTC Handle Structure definition 158 */ 159 #if (USE_HAL_RTC_REGISTER_CALLBACKS == 1) 160 typedef struct __RTC_HandleTypeDef 161 #else 162 typedef struct 163 #endif /* USE_HAL_RTC_REGISTER_CALLBACKS */ 164 { 165 RTC_TypeDef *Instance; /*!< Register base address */ 166 167 RTC_InitTypeDef Init; /*!< RTC required parameters */ 168 169 HAL_LockTypeDef Lock; /*!< RTC locking object */ 170 171 __IO HAL_RTCStateTypeDef State; /*!< Time communication state */ 172 173 #if (USE_HAL_RTC_REGISTER_CALLBACKS == 1) 174 void (* AlarmAEventCallback) (struct __RTC_HandleTypeDef *hrtc); /*!< RTC Alarm A Event callback */ 175 176 void (* WakeUpTimerEventCallback) (struct __RTC_HandleTypeDef *hrtc); /*!< RTC WakeUpTimer Event callback */ 177 178 void (* MspInitCallback) (struct __RTC_HandleTypeDef *hrtc); /*!< RTC Msp Init callback */ 179 180 void (* MspDeInitCallback) (struct __RTC_HandleTypeDef *hrtc); /*!< RTC Msp DeInit callback */ 181 182 #endif /* USE_HAL_RTC_REGISTER_CALLBACKS */ 183 184 } RTC_HandleTypeDef; 185 186 #if (USE_HAL_RTC_REGISTER_CALLBACKS == 1) 187 /** 188 * @brief HAL RTC Callback ID enumeration definition 189 */ 190 typedef enum 191 { 192 HAL_RTC_ALARM_A_EVENT_CB_ID = 0x00U, /*!< RTC Alarm A Event Callback ID */ 193 HAL_RTC_WAKEUPTIMER_EVENT_CB_ID = 0x03U, /*!< RTC Wakeup Timer Event Callback ID */ 194 HAL_RTC_MSPINIT_CB_ID = 0x0EU, /*!< RTC Msp Init callback ID */ 195 HAL_RTC_MSPDEINIT_CB_ID = 0x0FU /*!< RTC Msp DeInit callback ID */ 196 } HAL_RTC_CallbackIDTypeDef; 197 198 /** 199 * @brief HAL RTC Callback pointer definition 200 */ 201 typedef void (*pRTC_CallbackTypeDef)(RTC_HandleTypeDef *hrtc); /*!< pointer to an RTC callback function */ 202 #endif /* USE_HAL_RTC_REGISTER_CALLBACKS */ 203 204 /** 205 * @} 206 */ 207 208 /* Exported constants --------------------------------------------------------*/ 209 210 /** @defgroup RTC_Exported_Constants RTC Exported Constants 211 * @{ 212 */ 213 214 /** @defgroup RTC_Hour_Formats RTC Hour Formats 215 * @{ 216 */ 217 #define RTC_HOURFORMAT_24 0x00000000U 218 #define RTC_HOURFORMAT_12 RTC_CR_FMT 219 /** 220 * @} 221 */ 222 223 /** @defgroup RTC_Output_selection_Definitions RTC Output Selection Definitions 224 * @{ 225 */ 226 #define RTC_OUTPUT_DISABLE 0x00000000U 227 #define RTC_OUTPUT_ALARMA RTC_CR_OSEL_0 228 #define RTC_OUTPUT_WAKEUP RTC_CR_OSEL 229 /** 230 * @} 231 */ 232 233 /** @defgroup RTC_Output_Polarity_Definitions RTC Output Polarity Definitions 234 * @{ 235 */ 236 #define RTC_OUTPUT_POLARITY_HIGH 0x00000000U 237 #define RTC_OUTPUT_POLARITY_LOW RTC_CR_POL 238 /** 239 * @} 240 */ 241 242 /** @defgroup RTC_AM_PM_Definitions RTC AM PM Definitions 243 * @{ 244 */ 245 #define RTC_HOURFORMAT12_AM ((uint8_t)0x00) 246 #define RTC_HOURFORMAT12_PM ((uint8_t)0x01) 247 /** 248 * @} 249 */ 250 251 /** @defgroup RTC_DayLightSaving_Definitions RTC DayLight Saving Definitions 252 * @{ 253 */ 254 #define RTC_DAYLIGHTSAVING_SUB1H RTC_CR_SUB1H 255 #define RTC_DAYLIGHTSAVING_ADD1H RTC_CR_ADD1H 256 #define RTC_DAYLIGHTSAVING_NONE 0x00000000U 257 /** 258 * @} 259 */ 260 261 /** @defgroup RTC_StoreOperation_Definitions RTC Store Operation Definitions 262 * @{ 263 */ 264 #define RTC_STOREOPERATION_RESET 0x00000000U 265 #define RTC_STOREOPERATION_SET RTC_CR_BKP 266 /** 267 * @} 268 */ 269 270 /** @defgroup RTC_Input_parameter_format_definitions RTC Input Parameter Format Definitions 271 * @{ 272 */ 273 #define RTC_FORMAT_BIN 0x00000000U 274 #define RTC_FORMAT_BCD 0x00000001U 275 /** 276 * @} 277 */ 278 279 /** @defgroup RTC_Month_Date_Definitions RTC Month Date Definitions (in BCD format) 280 * @{ 281 */ 282 #define RTC_MONTH_JANUARY ((uint8_t)0x01) 283 #define RTC_MONTH_FEBRUARY ((uint8_t)0x02) 284 #define RTC_MONTH_MARCH ((uint8_t)0x03) 285 #define RTC_MONTH_APRIL ((uint8_t)0x04) 286 #define RTC_MONTH_MAY ((uint8_t)0x05) 287 #define RTC_MONTH_JUNE ((uint8_t)0x06) 288 #define RTC_MONTH_JULY ((uint8_t)0x07) 289 #define RTC_MONTH_AUGUST ((uint8_t)0x08) 290 #define RTC_MONTH_SEPTEMBER ((uint8_t)0x09) 291 #define RTC_MONTH_OCTOBER ((uint8_t)0x10) 292 #define RTC_MONTH_NOVEMBER ((uint8_t)0x11) 293 #define RTC_MONTH_DECEMBER ((uint8_t)0x12) 294 /** 295 * @} 296 */ 297 298 /** @defgroup RTC_WeekDay_Definitions RTC WeekDay Definitions 299 * @{ 300 */ 301 #define RTC_WEEKDAY_MONDAY ((uint8_t)0x01) 302 #define RTC_WEEKDAY_TUESDAY ((uint8_t)0x02) 303 #define RTC_WEEKDAY_WEDNESDAY ((uint8_t)0x03) 304 #define RTC_WEEKDAY_THURSDAY ((uint8_t)0x04) 305 #define RTC_WEEKDAY_FRIDAY ((uint8_t)0x05) 306 #define RTC_WEEKDAY_SATURDAY ((uint8_t)0x06) 307 #define RTC_WEEKDAY_SUNDAY ((uint8_t)0x07) 308 /** 309 * @} 310 */ 311 312 /** @defgroup RTC_AlarmDateWeekDay_Definitions RTC Alarm Date WeekDay Definitions 313 * @{ 314 */ 315 #define RTC_ALARMDATEWEEKDAYSEL_DATE 0x00000000U 316 #define RTC_ALARMDATEWEEKDAYSEL_WEEKDAY RTC_ALRMAR_WDSEL 317 /** 318 * @} 319 */ 320 321 /** @defgroup RTC_AlarmMask_Definitions RTC Alarm Mask Definitions 322 * @{ 323 */ 324 #define RTC_ALARMMASK_NONE 0x00000000U 325 #define RTC_ALARMMASK_DATEWEEKDAY RTC_ALRMAR_MSK4 326 #define RTC_ALARMMASK_HOURS RTC_ALRMAR_MSK3 327 #define RTC_ALARMMASK_MINUTES RTC_ALRMAR_MSK2 328 #define RTC_ALARMMASK_SECONDS RTC_ALRMAR_MSK1 329 #define RTC_ALARMMASK_ALL (RTC_ALARMMASK_DATEWEEKDAY | \ 330 RTC_ALARMMASK_HOURS | \ 331 RTC_ALARMMASK_MINUTES | \ 332 RTC_ALARMMASK_SECONDS) 333 /** 334 * @} 335 */ 336 337 /** @defgroup RTC_Alarms_Definitions RTC Alarms Definitions 338 * @{ 339 */ 340 #define RTC_ALARM_A RTC_CR_ALRAE 341 /** 342 * @} 343 */ 344 345 /** @defgroup RTC_Alarm_Sub_Seconds_Masks_Definitions RTC Alarm Sub Seconds Masks Definitions 346 * @{ 347 */ 348 /*!< All Alarm SS fields are masked. There is no comparison on sub seconds for Alarm */ 349 #define RTC_ALARMSUBSECONDMASK_ALL 0x00000000U 350 /*!< SS[14:1] are don't care in Alarm comparison. Only SS[0] is compared. */ 351 #define RTC_ALARMSUBSECONDMASK_SS14_1 RTC_ALRMASSR_MASKSS_0 352 /*!< SS[14:2] are don't care in Alarm comparison. Only SS[1:0] are compared. */ 353 #define RTC_ALARMSUBSECONDMASK_SS14_2 RTC_ALRMASSR_MASKSS_1 354 /*!< SS[14:3] are don't care in Alarm comparison. Only SS[2:0] are compared. */ 355 #define RTC_ALARMSUBSECONDMASK_SS14_3 (RTC_ALRMASSR_MASKSS_0 | RTC_ALRMASSR_MASKSS_1) 356 /*!< SS[14:4] are don't care in Alarm comparison. Only SS[3:0] are compared. */ 357 #define RTC_ALARMSUBSECONDMASK_SS14_4 RTC_ALRMASSR_MASKSS_2 358 /*!< SS[14:5] are don't care in Alarm comparison. Only SS[4:0] are compared. */ 359 #define RTC_ALARMSUBSECONDMASK_SS14_5 (RTC_ALRMASSR_MASKSS_0 | RTC_ALRMASSR_MASKSS_2) 360 /*!< SS[14:6] are don't care in Alarm comparison. Only SS[5:0] are compared. */ 361 #define RTC_ALARMSUBSECONDMASK_SS14_6 (RTC_ALRMASSR_MASKSS_1 | RTC_ALRMASSR_MASKSS_2) 362 /*!< SS[14:7] are don't care in Alarm comparison. Only SS[6:0] are compared. */ 363 #define RTC_ALARMSUBSECONDMASK_SS14_7 (RTC_ALRMASSR_MASKSS_0 | RTC_ALRMASSR_MASKSS_1 | RTC_ALRMASSR_MASKSS_2) 364 /*!< SS[14:8] are don't care in Alarm comparison. Only SS[7:0] are compared. */ 365 #define RTC_ALARMSUBSECONDMASK_SS14_8 RTC_ALRMASSR_MASKSS_3 366 /*!< SS[14:9] are don't care in Alarm comparison. Only SS[8:0] are compared. */ 367 #define RTC_ALARMSUBSECONDMASK_SS14_9 (RTC_ALRMASSR_MASKSS_0 | RTC_ALRMASSR_MASKSS_3) 368 /*!< SS[14:10] are don't care in Alarm comparison. Only SS[9:0] are compared. */ 369 #define RTC_ALARMSUBSECONDMASK_SS14_10 (RTC_ALRMASSR_MASKSS_1 | RTC_ALRMASSR_MASKSS_3) 370 /*!< SS[14:11] are don't care in Alarm comparison. Only SS[10:0] are compared. */ 371 #define RTC_ALARMSUBSECONDMASK_SS14_11 (RTC_ALRMASSR_MASKSS_0 | RTC_ALRMASSR_MASKSS_1 | RTC_ALRMASSR_MASKSS_3) 372 /*!< SS[14:12] are don't care in Alarm comparison. Only SS[11:0] are compared. */ 373 #define RTC_ALARMSUBSECONDMASK_SS14_12 (RTC_ALRMASSR_MASKSS_2 | RTC_ALRMASSR_MASKSS_3) 374 /*!< SS[14:13] are don't care in Alarm comparison. Only SS[12:0] are compared. */ 375 #define RTC_ALARMSUBSECONDMASK_SS14_13 (RTC_ALRMASSR_MASKSS_0 | RTC_ALRMASSR_MASKSS_2 | RTC_ALRMASSR_MASKSS_3) 376 /*!< SS[14] is don't care in Alarm comparison. Only SS[13:0] are compared. */ 377 #define RTC_ALARMSUBSECONDMASK_SS14 (RTC_ALRMASSR_MASKSS_1 | RTC_ALRMASSR_MASKSS_2 | RTC_ALRMASSR_MASKSS_3) 378 /*!< SS[14:0] are compared and must match to activate alarm. */ 379 #define RTC_ALARMSUBSECONDMASK_NONE RTC_ALRMASSR_MASKSS 380 /** 381 * @} 382 */ 383 384 /** @defgroup RTC_Interrupts_Definitions RTC Interrupts Definitions 385 * @{ 386 */ 387 #define RTC_IT_WUT RTC_CR_WUTIE /*!< Enable Wakeup timer Interrupt */ 388 #define RTC_IT_ALRA RTC_CR_ALRAIE /*!< Enable Alarm A Interrupt */ 389 /** 390 * @} 391 */ 392 393 /** @defgroup RTC_Flags_Definitions RTC Flags Definitions 394 * @{ 395 */ 396 #define RTC_FLAG_RECALPF RTC_ISR_RECALPF /*!< Recalibration pending flag */ 397 #define RTC_FLAG_WUTF RTC_ISR_WUTF /*!< Wakeup timer event flag */ 398 #define RTC_FLAG_ALRAF RTC_ISR_ALRAF /*!< Alarm A event flag */ 399 #define RTC_FLAG_INITF RTC_ISR_INITF /*!< RTC in initialization mode flag */ 400 #define RTC_FLAG_RSF RTC_ISR_RSF /*!< Register synchronization flag */ 401 #define RTC_FLAG_INITS RTC_ISR_INITS /*!< RTC initialization status flag */ 402 #define RTC_FLAG_SHPF RTC_ISR_SHPF /*!< Shift operation pending flag */ 403 #define RTC_FLAG_WUTWF RTC_ISR_WUTWF /*!< WUTR register write allowance flag */ 404 #define RTC_FLAG_ALRAWF RTC_ISR_ALRAWF /*!< ALRMAR register write allowance flag */ 405 /** 406 * @} 407 */ 408 409 /** 410 * @} 411 */ 412 413 /* Exported macros -----------------------------------------------------------*/ 414 415 /** @defgroup RTC_Exported_Macros RTC Exported Macros 416 * @{ 417 */ 418 419 /** @brief Reset RTC handle state 420 * @param __HANDLE__ specifies the RTC handle. 421 * @retval None 422 */ 423 #if (USE_HAL_RTC_REGISTER_CALLBACKS == 1) 424 #define __HAL_RTC_RESET_HANDLE_STATE(__HANDLE__) do { \ 425 (__HANDLE__)->State = HAL_RTC_STATE_RESET; \ 426 (__HANDLE__)->MspInitCallback = NULL; \ 427 (__HANDLE__)->MspDeInitCallback = NULL; \ 428 } while(0U) 429 #else 430 #define __HAL_RTC_RESET_HANDLE_STATE(__HANDLE__) ((__HANDLE__)->State = HAL_RTC_STATE_RESET) 431 #endif /* USE_HAL_RTC_REGISTER_CALLBACKS */ 432 433 /** 434 * @brief Disable the write protection for RTC registers. 435 * @param __HANDLE__ specifies the RTC handle. 436 * @retval None 437 */ 438 #define __HAL_RTC_WRITEPROTECTION_DISABLE(__HANDLE__) do { \ 439 (__HANDLE__)->Instance->WPR = 0xCAU; \ 440 (__HANDLE__)->Instance->WPR = 0x53U; \ 441 } while(0U) 442 443 /** 444 * @brief Enable the write protection for RTC registers. 445 * @param __HANDLE__ specifies the RTC handle. 446 * @retval None 447 */ 448 #define __HAL_RTC_WRITEPROTECTION_ENABLE(__HANDLE__) do { \ 449 (__HANDLE__)->Instance->WPR = 0xFFU; \ 450 } while(0U) 451 452 /** 453 * @brief Check whether the RTC Calendar is initialized. 454 * @param __HANDLE__ specifies the RTC handle. 455 * @retval None 456 */ 457 #define __HAL_RTC_IS_CALENDAR_INITIALIZED(__HANDLE__) (((((__HANDLE__)->Instance->ISR) & (RTC_FLAG_INITS)) == RTC_FLAG_INITS) ? 1U : 0U) 458 459 /** 460 * @brief Enable the RTC ALARMA peripheral. 461 * @param __HANDLE__ specifies the RTC handle. 462 * @retval None 463 */ 464 #define __HAL_RTC_ALARMA_ENABLE(__HANDLE__) ((__HANDLE__)->Instance->CR |= (RTC_CR_ALRAE)) 465 466 /** 467 * @brief Disable the RTC ALARMA peripheral. 468 * @param __HANDLE__ specifies the RTC handle. 469 * @retval None 470 */ 471 #define __HAL_RTC_ALARMA_DISABLE(__HANDLE__) ((__HANDLE__)->Instance->CR &= ~(RTC_CR_ALRAE)) 472 473 /** 474 * @brief Enable the RTC Alarm interrupt. 475 * @param __HANDLE__ specifies the RTC handle. 476 * @param __INTERRUPT__ specifies the RTC Alarm interrupt sources to be enabled or disabled. 477 * This parameter can be: 478 * @arg RTC_IT_ALRA: Alarm A interrupt 479 * @retval None 480 */ 481 #define __HAL_RTC_ALARM_ENABLE_IT(__HANDLE__, __INTERRUPT__) ((__HANDLE__)->Instance->CR |= (__INTERRUPT__)) 482 483 /** 484 * @brief Disable the RTC Alarm interrupt. 485 * @param __HANDLE__ specifies the RTC handle. 486 * @param __INTERRUPT__ specifies the RTC Alarm interrupt sources to be enabled or disabled. 487 * This parameter can be: 488 * @arg RTC_IT_ALRA: Alarm A interrupt 489 * @retval None 490 */ 491 #define __HAL_RTC_ALARM_DISABLE_IT(__HANDLE__, __INTERRUPT__) ((__HANDLE__)->Instance->CR &= ~(__INTERRUPT__)) 492 493 /** 494 * @brief Check whether the specified RTC Alarm interrupt has occurred or not. 495 * @param __HANDLE__ specifies the RTC handle. 496 * @param __INTERRUPT__ specifies the RTC Alarm interrupt to check. 497 * This parameter can be: 498 * @arg RTC_IT_ALRA: Alarm A interrupt 499 * @retval None 500 */ 501 #define __HAL_RTC_ALARM_GET_IT(__HANDLE__, __INTERRUPT__) (((((__HANDLE__)->Instance->ISR) & ((__INTERRUPT__) >> 4U)) != 0U) ? 1U : 0U) 502 503 /** 504 * @brief Get the selected RTC Alarm's flag status. 505 * @param __HANDLE__ specifies the RTC handle. 506 * @param __FLAG__ specifies the RTC Alarm Flag to check. 507 * This parameter can be: 508 * @arg RTC_FLAG_ALRAF: Alarm A interrupt flag 509 * @arg RTC_FLAG_ALRAWF: Alarm A 'write allowed' flag 510 * @retval None 511 */ 512 #define __HAL_RTC_ALARM_GET_FLAG(__HANDLE__, __FLAG__) (((((__HANDLE__)->Instance->ISR) & (__FLAG__)) != 0U) ? 1U : 0U) 513 514 /** 515 * @brief Clear the RTC Alarm's pending flags. 516 * @param __HANDLE__ specifies the RTC handle. 517 * @param __FLAG__ specifies the RTC Alarm flag to be cleared. 518 * This parameter can be: 519 * @arg RTC_FLAG_ALRAF 520 * @retval None 521 */ 522 #define __HAL_RTC_ALARM_CLEAR_FLAG(__HANDLE__, __FLAG__) ((__HANDLE__)->Instance->ISR) = (~((__FLAG__) | RTC_ISR_INIT)|((__HANDLE__)->Instance->ISR & RTC_ISR_INIT)) 523 524 /** 525 * @brief Check whether the specified RTC Alarm interrupt has been enabled or not. 526 * @param __HANDLE__ specifies the RTC handle. 527 * @param __INTERRUPT__ specifies the RTC Alarm interrupt sources to check. 528 * This parameter can be: 529 * @arg RTC_IT_ALRA: Alarm A interrupt 530 * @retval None 531 */ 532 #define __HAL_RTC_ALARM_GET_IT_SOURCE(__HANDLE__, __INTERRUPT__) (((((__HANDLE__)->Instance->CR) & (__INTERRUPT__)) != 0U) ? 1U : 0U) 533 534 /** 535 * @} 536 */ 537 538 /* Include RTC HAL Extended module */ 539 #include "stm32wb0x_hal_rtc_ex.h" 540 541 /* Exported functions --------------------------------------------------------*/ 542 543 /** @addtogroup RTC_Exported_Functions 544 * @{ 545 */ 546 547 /** @addtogroup RTC_Exported_Functions_Group1 548 * @{ 549 */ 550 /* Initialization and de-initialization functions ****************************/ 551 HAL_StatusTypeDef HAL_RTC_Init(RTC_HandleTypeDef *hrtc); 552 HAL_StatusTypeDef HAL_RTC_DeInit(RTC_HandleTypeDef *hrtc); 553 void HAL_RTC_MspInit(RTC_HandleTypeDef *hrtc); 554 void HAL_RTC_MspDeInit(RTC_HandleTypeDef *hrtc); 555 556 /* Callbacks Register/UnRegister functions ***********************************/ 557 #if (USE_HAL_RTC_REGISTER_CALLBACKS == 1) 558 HAL_StatusTypeDef HAL_RTC_RegisterCallback(RTC_HandleTypeDef *hrtc, HAL_RTC_CallbackIDTypeDef CallbackID, pRTC_CallbackTypeDef pCallback); 559 HAL_StatusTypeDef HAL_RTC_UnRegisterCallback(RTC_HandleTypeDef *hrtc, HAL_RTC_CallbackIDTypeDef CallbackID); 560 #endif /* USE_HAL_RTC_REGISTER_CALLBACKS */ 561 /** 562 * @} 563 */ 564 565 /** @addtogroup RTC_Exported_Functions_Group2 566 * @{ 567 */ 568 /* RTC Time and Date functions ************************************************/ 569 HAL_StatusTypeDef HAL_RTC_SetTime(RTC_HandleTypeDef *hrtc, RTC_TimeTypeDef *sTime, uint32_t Format); 570 HAL_StatusTypeDef HAL_RTC_GetTime(RTC_HandleTypeDef *hrtc, RTC_TimeTypeDef *sTime, uint32_t Format); 571 HAL_StatusTypeDef HAL_RTC_SetDate(RTC_HandleTypeDef *hrtc, RTC_DateTypeDef *sDate, uint32_t Format); 572 HAL_StatusTypeDef HAL_RTC_GetDate(RTC_HandleTypeDef *hrtc, RTC_DateTypeDef *sDate, uint32_t Format); 573 /** 574 * @} 575 */ 576 577 /** @addtogroup RTC_Exported_Functions_Group3 578 * @{ 579 */ 580 /* RTC Alarm functions ********************************************************/ 581 HAL_StatusTypeDef HAL_RTC_SetAlarm(RTC_HandleTypeDef *hrtc, RTC_AlarmTypeDef *sAlarm, uint32_t Format); 582 HAL_StatusTypeDef HAL_RTC_SetAlarm_IT(RTC_HandleTypeDef *hrtc, RTC_AlarmTypeDef *sAlarm, uint32_t Format); 583 HAL_StatusTypeDef HAL_RTC_DeactivateAlarm(RTC_HandleTypeDef *hrtc, uint32_t Alarm); 584 HAL_StatusTypeDef HAL_RTC_GetAlarm(RTC_HandleTypeDef *hrtc, RTC_AlarmTypeDef *sAlarm, uint32_t Alarm, uint32_t Format); 585 void HAL_RTC_AlarmIRQHandler(RTC_HandleTypeDef *hrtc); 586 HAL_StatusTypeDef HAL_RTC_PollForAlarmAEvent(RTC_HandleTypeDef *hrtc, uint32_t Timeout); 587 void HAL_RTC_AlarmAEventCallback(RTC_HandleTypeDef *hrtc); 588 /** 589 * @} 590 */ 591 592 /** @addtogroup RTC_Exported_Functions_Group4 593 * @{ 594 */ 595 /* Peripheral Control functions ***********************************************/ 596 HAL_StatusTypeDef HAL_RTC_WaitForSynchro(RTC_HandleTypeDef *hrtc); 597 598 /* RTC Daylight Saving Time functions *****************************************/ 599 void HAL_RTC_DST_Add1Hour(RTC_HandleTypeDef *hrtc); 600 void HAL_RTC_DST_Sub1Hour(RTC_HandleTypeDef *hrtc); 601 void HAL_RTC_DST_SetStoreOperation(RTC_HandleTypeDef *hrtc); 602 void HAL_RTC_DST_ClearStoreOperation(RTC_HandleTypeDef *hrtc); 603 uint32_t HAL_RTC_DST_ReadStoreOperation(RTC_HandleTypeDef *hrtc); 604 /** 605 * @} 606 */ 607 608 /** @addtogroup RTC_Exported_Functions_Group5 609 * @{ 610 */ 611 /* Peripheral State functions *************************************************/ 612 HAL_RTCStateTypeDef HAL_RTC_GetState(RTC_HandleTypeDef *hrtc); 613 /** 614 * @} 615 */ 616 617 /** 618 * @} 619 */ 620 621 /* Private types -------------------------------------------------------------*/ 622 /* Private variables ---------------------------------------------------------*/ 623 /* Private constants ---------------------------------------------------------*/ 624 625 /** @defgroup RTC_Private_Constants RTC Private Constants 626 * @{ 627 */ 628 /* Masks Definition */ 629 #define RTC_TR_RESERVED_MASK ((uint32_t)(RTC_TR_HT | RTC_TR_HU | \ 630 RTC_TR_MNT | RTC_TR_MNU | \ 631 RTC_TR_ST | RTC_TR_SU | \ 632 RTC_TR_PM)) 633 #define RTC_DR_RESERVED_MASK ((uint32_t)(RTC_DR_YT | RTC_DR_YU | \ 634 RTC_DR_MT | RTC_DR_MU | \ 635 RTC_DR_DT | RTC_DR_DU | \ 636 RTC_DR_WDU)) 637 #define RTC_ISR_RESERVED_MASK ((uint32_t)(RTC_FLAGS_MASK | RTC_ISR_INIT)) 638 #define RTC_INIT_MASK 0xFFFFFFFFU 639 #define RTC_RSF_MASK ((uint32_t)~(RTC_ISR_INIT | RTC_ISR_RSF)) 640 #define RTC_FLAGS_MASK ((uint32_t)(RTC_FLAG_INITF | RTC_FLAG_INITS | \ 641 RTC_FLAG_ALRAF | RTC_FLAG_ALRAWF | \ 642 RTC_FLAG_WUTF | RTC_FLAG_WUTWF | \ 643 RTC_FLAG_RECALPF | RTC_FLAG_SHPF | \ 644 RTC_FLAG_RSF)) 645 646 #define RTC_TIMEOUT_VALUE 1000U 647 648 /** 649 * @} 650 */ 651 652 /* Private macros ------------------------------------------------------------*/ 653 654 /** @defgroup RTC_Private_Macros RTC Private Macros 655 * @{ 656 */ 657 658 /** @defgroup RTC_IS_RTC_Definitions RTC Private macros to check input parameters 659 * @{ 660 */ 661 #define IS_RTC_HOUR_FORMAT(FORMAT) (((FORMAT) == RTC_HOURFORMAT_12) || \ 662 ((FORMAT) == RTC_HOURFORMAT_24)) 663 664 #define IS_RTC_OUTPUT(OUTPUT) (((OUTPUT) == RTC_OUTPUT_DISABLE) || \ 665 ((OUTPUT) == RTC_OUTPUT_ALARMA) || \ 666 ((OUTPUT) == RTC_OUTPUT_WAKEUP)) 667 668 #define IS_RTC_OUTPUT_POL(POL) (((POL) == RTC_OUTPUT_POLARITY_HIGH) || \ 669 ((POL) == RTC_OUTPUT_POLARITY_LOW)) 670 671 #define IS_RTC_ASYNCH_PREDIV(PREDIV) ((PREDIV) <= 0x7FU) 672 #define IS_RTC_SYNCH_PREDIV(PREDIV) ((PREDIV) <= 0x7FFFU) 673 674 #define IS_RTC_HOUR12(HOUR) (((HOUR) > 0U) && ((HOUR) <= 12U)) 675 #define IS_RTC_HOUR24(HOUR) ((HOUR) <= 23U) 676 #define IS_RTC_MINUTES(MINUTES) ((MINUTES) <= 59U) 677 #define IS_RTC_SECONDS(SECONDS) ((SECONDS) <= 59U) 678 679 #define IS_RTC_HOURFORMAT12(PM) (((PM) == RTC_HOURFORMAT12_AM) || \ 680 ((PM) == RTC_HOURFORMAT12_PM)) 681 682 #define IS_RTC_DAYLIGHT_SAVING(SAVE) (((SAVE) == RTC_DAYLIGHTSAVING_SUB1H) || \ 683 ((SAVE) == RTC_DAYLIGHTSAVING_ADD1H) || \ 684 ((SAVE) == RTC_DAYLIGHTSAVING_NONE)) 685 686 #define IS_RTC_STORE_OPERATION(OPERATION) (((OPERATION) == RTC_STOREOPERATION_RESET) || \ 687 ((OPERATION) == RTC_STOREOPERATION_SET)) 688 689 #define IS_RTC_FORMAT(FORMAT) (((FORMAT) == RTC_FORMAT_BIN) || ((FORMAT) == RTC_FORMAT_BCD)) 690 691 #define IS_RTC_YEAR(YEAR) ((YEAR) <= 99U) 692 #define IS_RTC_MONTH(MONTH) (((MONTH) >= 1U) && ((MONTH) <= 12U)) 693 #define IS_RTC_DATE(DATE) (((DATE) >= 1U) && ((DATE) <= 31U)) 694 695 #define IS_RTC_WEEKDAY(WEEKDAY) (((WEEKDAY) == RTC_WEEKDAY_MONDAY) || \ 696 ((WEEKDAY) == RTC_WEEKDAY_TUESDAY) || \ 697 ((WEEKDAY) == RTC_WEEKDAY_WEDNESDAY) || \ 698 ((WEEKDAY) == RTC_WEEKDAY_THURSDAY) || \ 699 ((WEEKDAY) == RTC_WEEKDAY_FRIDAY) || \ 700 ((WEEKDAY) == RTC_WEEKDAY_SATURDAY) || \ 701 ((WEEKDAY) == RTC_WEEKDAY_SUNDAY)) 702 703 #define IS_RTC_ALARM_DATE_WEEKDAY_DATE(DATE) (((DATE) > 0U) && ((DATE) <= 31U)) 704 705 #define IS_RTC_ALARM_DATE_WEEKDAY_WEEKDAY(WEEKDAY) (((WEEKDAY) == RTC_WEEKDAY_MONDAY) || \ 706 ((WEEKDAY) == RTC_WEEKDAY_TUESDAY) || \ 707 ((WEEKDAY) == RTC_WEEKDAY_WEDNESDAY) || \ 708 ((WEEKDAY) == RTC_WEEKDAY_THURSDAY) || \ 709 ((WEEKDAY) == RTC_WEEKDAY_FRIDAY) || \ 710 ((WEEKDAY) == RTC_WEEKDAY_SATURDAY) || \ 711 ((WEEKDAY) == RTC_WEEKDAY_SUNDAY)) 712 713 #define IS_RTC_ALARM_DATE_WEEKDAY_SEL(SEL) (((SEL) == RTC_ALARMDATEWEEKDAYSEL_DATE) || \ 714 ((SEL) == RTC_ALARMDATEWEEKDAYSEL_WEEKDAY)) 715 716 #define IS_RTC_ALARM_MASK(MASK) (((MASK) & ((uint32_t)~RTC_ALARMMASK_ALL)) == 0U) 717 718 #define IS_RTC_ALARM(ALARM) ((ALARM) == RTC_ALARM_A) 719 720 #define IS_RTC_ALARM_SUB_SECOND_VALUE(VALUE) ((VALUE) <= RTC_ALRMASSR_SS) 721 722 #define IS_RTC_ALARM_SUB_SECOND_MASK(MASK) (((MASK) == RTC_ALARMSUBSECONDMASK_ALL) || \ 723 ((MASK) == RTC_ALARMSUBSECONDMASK_SS14_1) || \ 724 ((MASK) == RTC_ALARMSUBSECONDMASK_SS14_2) || \ 725 ((MASK) == RTC_ALARMSUBSECONDMASK_SS14_3) || \ 726 ((MASK) == RTC_ALARMSUBSECONDMASK_SS14_4) || \ 727 ((MASK) == RTC_ALARMSUBSECONDMASK_SS14_5) || \ 728 ((MASK) == RTC_ALARMSUBSECONDMASK_SS14_6) || \ 729 ((MASK) == RTC_ALARMSUBSECONDMASK_SS14_7) || \ 730 ((MASK) == RTC_ALARMSUBSECONDMASK_SS14_8) || \ 731 ((MASK) == RTC_ALARMSUBSECONDMASK_SS14_9) || \ 732 ((MASK) == RTC_ALARMSUBSECONDMASK_SS14_10) || \ 733 ((MASK) == RTC_ALARMSUBSECONDMASK_SS14_11) || \ 734 ((MASK) == RTC_ALARMSUBSECONDMASK_SS14_12) || \ 735 ((MASK) == RTC_ALARMSUBSECONDMASK_SS14_13) || \ 736 ((MASK) == RTC_ALARMSUBSECONDMASK_SS14) || \ 737 ((MASK) == RTC_ALARMSUBSECONDMASK_NONE)) 738 /** 739 * @} 740 */ 741 742 /** 743 * @} 744 */ 745 746 /* Private functions ---------------------------------------------------------*/ 747 748 /** @defgroup RTC_Private_Functions RTC Private Functions 749 * @{ 750 */ 751 HAL_StatusTypeDef RTC_EnterInitMode(RTC_HandleTypeDef *hrtc); 752 HAL_StatusTypeDef RTC_ExitInitMode(RTC_HandleTypeDef *hrtc); 753 uint8_t RTC_ByteToBcd2(uint8_t number); 754 uint8_t RTC_Bcd2ToByte(uint8_t number); 755 /** 756 * @} 757 */ 758 759 /** 760 * @} 761 */ 762 763 /** 764 * @} 765 */ 766 767 #ifdef __cplusplus 768 } 769 #endif 770 771 #endif /* STM32WB0x_HAL_RTC_H */ 772