1 /** 2 ****************************************************************************** 3 * @file stm32c0xx_hal_rtc_ex.h 4 * @author MCD Application Team 5 * @brief Header file of RTC HAL Extended 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_EX_H 21 #define STM32C0xx_HAL_RTC_EX_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 RTCEx RTCEx 35 * @{ 36 */ 37 38 /* Exported types ------------------------------------------------------------*/ 39 /** @defgroup RTCEx_Exported_Types RTCEx Exported Types 40 * @{ 41 */ 42 43 44 /** 45 * @} 46 */ 47 48 /* Exported constants --------------------------------------------------------*/ 49 /** @defgroup RTCEx_Exported_Constants RTCEx Exported Constants 50 * @{ 51 */ 52 53 /** @defgroup RTCEx_Time_Stamp_Edges_definitions RTCEx Time Stamp Edges definition 54 * @{ 55 */ 56 #define RTC_TIMESTAMPEDGE_RISING 0x00000000U 57 #define RTC_TIMESTAMPEDGE_FALLING RTC_CR_TSEDGE 58 /** 59 * @} 60 */ 61 62 /** @defgroup RTCEx_TimeStamp_Pin_Selections RTCEx TimeStamp Pin Selection 63 * @{ 64 */ 65 #define RTC_TIMESTAMPPIN_DEFAULT 0x00000000U 66 /** 67 * @} 68 */ 69 70 71 /** @defgroup RTCEx_Smooth_calib_period_Definitions RTCEx Smooth calib period Definitions 72 * @{ 73 */ 74 #define RTC_SMOOTHCALIB_PERIOD_32SEC 0x00000000U /*!< If RTCCLK = 32768 Hz, Smooth calibation 75 period is 32s, else 2exp20 RTCCLK pulses */ 76 #define RTC_SMOOTHCALIB_PERIOD_16SEC RTC_CALR_CALW16 /*!< If RTCCLK = 32768 Hz, Smooth calibation 77 period is 16s, else 2exp19 RTCCLK pulses */ 78 #define RTC_SMOOTHCALIB_PERIOD_8SEC RTC_CALR_CALW8 /*!< If RTCCLK = 32768 Hz, Smooth calibation 79 period is 8s, else 2exp18 RTCCLK pulses */ 80 /** 81 * @} 82 */ 83 84 /** @defgroup RTCEx_Smooth_calib_Plus_pulses_Definitions RTCEx Smooth calib Plus pulses Definitions 85 * @{ 86 */ 87 #define RTC_SMOOTHCALIB_PLUSPULSES_SET RTC_CALR_CALP /*!< The number of RTCCLK pulses added 88 during a X -second window = Y - CALM[8:0] 89 with Y = 512, 256, 128 when X = 32, 16, 8 */ 90 #define RTC_SMOOTHCALIB_PLUSPULSES_RESET 0x00000000U /*!< The number of RTCCLK pulses subbstited 91 during a 32-second window = CALM[8:0] */ 92 93 /** 94 * @} 95 */ 96 97 /** @defgroup RTCEx_Calib_Output_selection_Definitions RTCEx Calib Output selection Definitions 98 * @{ 99 */ 100 #define RTC_CALIBOUTPUT_512HZ 0x00000000U 101 #define RTC_CALIBOUTPUT_1HZ RTC_CR_COSEL 102 103 /** 104 * @} 105 */ 106 107 108 /** @defgroup RTCEx_Add_1_Second_Parameter_Definition RTCEx Add 1 Second Parameter Definitions 109 * @{ 110 */ 111 #define RTC_SHIFTADD1S_RESET 0x00000000U 112 #define RTC_SHIFTADD1S_SET RTC_SHIFTR_ADD1S 113 /** 114 * @} 115 */ 116 117 118 /** 119 * @} 120 */ 121 122 /* Exported macros -----------------------------------------------------------*/ 123 /** @defgroup RTCEx_Exported_Macros RTCEx Exported Macros 124 * @{ 125 */ 126 127 /** @brief Clear the specified RTC pending flag. 128 * @param __HANDLE__ specifies the RTC Handle. 129 * @param __FLAG__ specifies the flag to check. 130 * This parameter can be any combination of the following values: 131 * @arg @ref RTC_CLEAR_ITSF Clear Internal Time-stamp flag 132 * @arg @ref RTC_CLEAR_TSOVF Clear Time-stamp overflow flag 133 * @arg @ref RTC_CLEAR_TSF Clear Time-stamp flag 134 * @arg @ref RTC_CLEAR_ALRAF Clear Alarm A flag 135 * @retval None 136 */ 137 #define __HAL_RTC_CLEAR_FLAG(__HANDLE__, __FLAG__) ((__HANDLE__)->Instance->SCR |= (__FLAG__)) 138 139 /** @brief Check whether the specified RTC flag is set or not. 140 * @param __HANDLE__ specifies the RTC Handle. 141 * @param __FLAG__ specifies the flag to check. 142 * This parameter can be: 143 * @arg @ref RTC_FLAG_RECALPF Recalibration pending Flag 144 * @arg @ref RTC_FLAG_INITF Initialization flag 145 * @arg @ref RTC_FLAG_RSF Registers synchronization flag 146 * @arg @ref RTC_FLAG_INITS Initialization status flag 147 * @arg @ref RTC_FLAG_SHPF Shift operation pending flag 148 * @arg @ref RTC_FLAG_ALRAWF Alarm A write flag 149 * @arg @ref RTC_FLAG_ITSF Internal Time-stamp flag 150 * @arg @ref RTC_FLAG_TSOVF Time-stamp overflow flag 151 * @arg @ref RTC_FLAG_TSF Time-stamp flag 152 * @arg @ref RTC_FLAG_ALRAF Alarm A flag 153 * @retval None 154 */ 155 #define __HAL_RTC_GET_FLAG(__HANDLE__, __FLAG__) (((((__FLAG__)) >> 8U) == 1U) ? ((((__HANDLE__)->Instance->ICSR & (1U << (((uint16_t)(__FLAG__)) & RTC_FLAG_MASK))) != 0U) ? 1U : 0U) :\ 156 ((((__HANDLE__)->Instance->SR & (1U << (((uint16_t)(__FLAG__)) & RTC_FLAG_MASK))) != 0U) ? 1U : 0U)) 157 158 159 /* ---------------------------------TIMESTAMP---------------------------------*/ 160 /** @defgroup RTCEx_Timestamp RTC Timestamp 161 * @{ 162 */ 163 /** 164 * @brief Enable the RTC TimeStamp peripheral. 165 * @param __HANDLE__ specifies the RTC handle. 166 * @retval None 167 */ 168 #define __HAL_RTC_TIMESTAMP_ENABLE(__HANDLE__) ((__HANDLE__)->Instance->CR |= (RTC_CR_TSE)) 169 170 /** 171 * @brief Disable the RTC TimeStamp peripheral. 172 * @param __HANDLE__ specifies the RTC handle. 173 * @retval None 174 */ 175 #define __HAL_RTC_TIMESTAMP_DISABLE(__HANDLE__) ((__HANDLE__)->Instance->CR &= ~(RTC_CR_TSE)) 176 177 /** 178 * @brief Enable the RTC TimeStamp interrupt. 179 * @param __HANDLE__ specifies the RTC handle. 180 * @param __INTERRUPT__ specifies the RTC TimeStamp interrupt source to be enabled. 181 * This parameter can be: 182 * @arg @ref RTC_IT_TS TimeStamp interrupt 183 * @retval None 184 */ 185 #define __HAL_RTC_TIMESTAMP_ENABLE_IT(__HANDLE__, __INTERRUPT__) ((__HANDLE__)->Instance->CR |= (__INTERRUPT__)) 186 187 /** 188 * @brief Disable the RTC TimeStamp interrupt. 189 * @param __HANDLE__ specifies the RTC handle. 190 * @param __INTERRUPT__ specifies the RTC TimeStamp interrupt source to be disabled. 191 * This parameter can be: 192 * @arg @ref RTC_IT_TS TimeStamp interrupt 193 * @retval None 194 */ 195 #define __HAL_RTC_TIMESTAMP_DISABLE_IT(__HANDLE__, __INTERRUPT__) ((__HANDLE__)->Instance->CR &= ~(__INTERRUPT__)) 196 197 /** 198 * @brief Check whether the specified RTC TimeStamp interrupt has occurred or not. 199 * @param __HANDLE__ specifies the RTC handle. 200 * @param __INTERRUPT__ specifies the RTC TimeStamp interrupt to check. 201 * This parameter can be: 202 * @arg @ref RTC_IT_TS TimeStamp interrupt 203 * @retval None 204 */ 205 #define __HAL_RTC_TIMESTAMP_GET_IT(__HANDLE__, __INTERRUPT__) (((((__HANDLE__)->Instance->SR)\ 206 & ((__INTERRUPT__)>> 12U)) != 0U) ? 1U : 0U) 207 208 /** 209 * @brief Check whether the specified RTC Time Stamp interrupt has been enabled or not. 210 * @param __HANDLE__ specifies the RTC handle. 211 * @param __INTERRUPT__ specifies the RTC Time Stamp interrupt source to check. 212 * This parameter can be: 213 * @arg @ref RTC_IT_TS TimeStamp interrupt 214 * @retval None 215 */ 216 #define __HAL_RTC_TIMESTAMP_GET_IT_SOURCE(__HANDLE__, __INTERRUPT__) (((((__HANDLE__)->Instance->CR)\ 217 & (__INTERRUPT__)) != 0U) ? 1U : 0U) 218 219 /** 220 * @brief Get the selected RTC TimeStamps flag status. 221 * @param __HANDLE__ specifies the RTC handle. 222 * @param __FLAG__ specifies the RTC TimeStamp Flag is pending or not. 223 * This parameter can be: 224 * @arg @ref RTC_FLAG_TSF 225 * @arg @ref RTC_FLAG_TSOVF 226 * @retval None 227 */ 228 #define __HAL_RTC_TIMESTAMP_GET_FLAG(__HANDLE__, __FLAG__) (__HAL_RTC_GET_FLAG((__HANDLE__),(__FLAG__))) 229 230 /** 231 * @brief Clear the RTC Time Stamps pending flags. 232 * @param __HANDLE__ specifies the RTC handle. 233 * @param __FLAG__ specifies the RTC TimeStamp Flag to clear. 234 * This parameter can be: 235 * @arg @ref RTC_FLAG_TSF 236 * @arg @ref RTC_FLAG_TSOVF 237 * @retval None 238 */ 239 #define __HAL_RTC_TIMESTAMP_CLEAR_FLAG(__HANDLE__, __FLAG__) (__HAL_RTC_CLEAR_FLAG((__HANDLE__), (__FLAG__))) 240 241 /** 242 * @brief Enable interrupt on the RTC Timestamp associated Exti line. 243 * @retval None 244 */ 245 #define __HAL_RTC_TIMESTAMP_EXTI_ENABLE_IT() (EXTI->IMR1 |= RTC_EXTI_LINE_TIMESTAMP_EVENT) 246 247 /** 248 * @brief Disable interrupt on the RTC Timestamp associated Exti line. 249 * @retval None 250 */ 251 #define __HAL_RTC_TIMESTAMP_EXTI_DISABLE_IT() (EXTI->IMR1 &= ~(RTC_EXTI_LINE_TIMESTAMP_EVENT)) 252 253 /** 254 * @brief Enable event on the RTC Timestamp associated Exti line. 255 * @retval None 256 */ 257 #define __HAL_RTC_TIMESTAMP_EXTI_ENABLE_EVENT() (EXTI->EMR1 |= RTC_EXTI_LINE_TIMESTAMP_EVENT) 258 259 /** 260 * @brief Disable event on the RTC Timestamp associated Exti line. 261 * @retval None 262 */ 263 #define __HAL_RTC_TIMESTAMP_EXTI_DISABLE_EVENT() (EXTI->EMR1 &= ~(RTC_EXTI_LINE_TIMESTAMP_EVENT)) 264 265 /** 266 * @brief Enable the RTC internal TimeStamp peripheral. 267 * @param __HANDLE__ specifies the RTC handle. 268 * @retval None 269 */ 270 #define __HAL_RTC_INTERNAL_TIMESTAMP_ENABLE(__HANDLE__) ((__HANDLE__)->Instance->CR |= (RTC_CR_ITSE)) 271 272 /** 273 * @brief Disable the RTC internal TimeStamp peripheral. 274 * @param __HANDLE__ specifies the RTC handle. 275 * @retval None 276 */ 277 #define __HAL_RTC_INTERNAL_TIMESTAMP_DISABLE(__HANDLE__) ((__HANDLE__)->Instance->CR &= ~(RTC_CR_ITSE)) 278 279 /** 280 * @brief Get the selected RTC Internal Time Stamps flag status. 281 * @param __HANDLE__ specifies the RTC handle. 282 * @param __FLAG__ specifies the RTC Internal Time Stamp Flag is pending or not. 283 * This parameter can be: 284 * @arg @ref RTC_FLAG_ITSF 285 * @retval None 286 */ 287 #define __HAL_RTC_INTERNAL_TIMESTAMP_GET_FLAG(__HANDLE__, __FLAG__) (__HAL_RTC_GET_FLAG((__HANDLE__),(__FLAG__))) 288 289 /** 290 * @brief Clear the RTC Internal Time Stamps pending flags. 291 * @param __HANDLE__ specifies the RTC handle. 292 * @param __FLAG__ specifies the RTC Internal Time Stamp Flag source to clear. 293 * This parameter can be: 294 * @arg @ref RTC_FLAG_ITSF 295 * @retval None 296 */ 297 #define __HAL_RTC_INTERNAL_TIMESTAMP_CLEAR_FLAG(__HANDLE__, __FLAG__) (__HAL_RTC_CLEAR_FLAG((__HANDLE__), RTC_CLEAR_ITSF)) 298 299 /** 300 * @} 301 */ 302 303 304 /* ------------------------------Calibration----------------------------------*/ 305 /** @defgroup RTCEx_Calibration RTC Calibration 306 * @{ 307 */ 308 309 /** 310 * @brief Enable the RTC calibration output. 311 * @param __HANDLE__ specifies the RTC handle. 312 * @retval None 313 */ 314 #define __HAL_RTC_CALIBRATION_OUTPUT_ENABLE(__HANDLE__) ((__HANDLE__)->Instance->CR |= (RTC_CR_COE)) 315 316 /** 317 * @brief Disable the calibration output. 318 * @param __HANDLE__ specifies the RTC handle. 319 * @retval None 320 */ 321 #define __HAL_RTC_CALIBRATION_OUTPUT_DISABLE(__HANDLE__) ((__HANDLE__)->Instance->CR &= ~(RTC_CR_COE)) 322 323 324 /** 325 * @brief Enable the clock reference detection. 326 * @param __HANDLE__ specifies the RTC handle. 327 * @retval None 328 */ 329 #define __HAL_RTC_CLOCKREF_DETECTION_ENABLE(__HANDLE__) ((__HANDLE__)->Instance->CR |= (RTC_CR_REFCKON)) 330 331 /** 332 * @brief Disable the clock reference detection. 333 * @param __HANDLE__ specifies the RTC handle. 334 * @retval None 335 */ 336 #define __HAL_RTC_CLOCKREF_DETECTION_DISABLE(__HANDLE__) ((__HANDLE__)->Instance->CR &= ~(RTC_CR_REFCKON)) 337 338 339 /** 340 * @brief Get the selected RTC shift operations flag status. 341 * @param __HANDLE__ specifies the RTC handle. 342 * @param __FLAG__ specifies the RTC shift operation Flag is pending or not. 343 * This parameter can be: 344 * @arg @ref RTC_FLAG_SHPF 345 * @retval None 346 */ 347 #define __HAL_RTC_SHIFT_GET_FLAG(__HANDLE__, __FLAG__) (__HAL_RTC_GET_FLAG((__HANDLE__), (__FLAG__))) 348 /** 349 * @} 350 */ 351 352 353 /** 354 * @} 355 */ 356 357 /* Exported functions --------------------------------------------------------*/ 358 /** @defgroup RTCEx_Exported_Functions RTCEx Exported Functions 359 * @{ 360 */ 361 362 /* RTC TimeStamp functions *****************************************/ 363 /** @defgroup RTCEx_Exported_Functions_Group1 Extended RTC TimeStamp functions 364 * @{ 365 */ 366 367 HAL_StatusTypeDef HAL_RTCEx_SetTimeStamp(RTC_HandleTypeDef *hrtc, uint32_t TimeStampEdge, uint32_t RTC_TimeStampPin); 368 HAL_StatusTypeDef HAL_RTCEx_SetTimeStamp_IT(RTC_HandleTypeDef *hrtc, uint32_t TimeStampEdge, uint32_t RTC_TimeStampPin); 369 HAL_StatusTypeDef HAL_RTCEx_DeactivateTimeStamp(RTC_HandleTypeDef *hrtc); 370 HAL_StatusTypeDef HAL_RTCEx_SetInternalTimeStamp(RTC_HandleTypeDef *hrtc); 371 HAL_StatusTypeDef HAL_RTCEx_DeactivateInternalTimeStamp(RTC_HandleTypeDef *hrtc); 372 HAL_StatusTypeDef HAL_RTCEx_GetTimeStamp(RTC_HandleTypeDef *hrtc, RTC_TimeTypeDef *sTimeStamp, 373 RTC_DateTypeDef *sTimeStampDate, uint32_t Format); 374 void HAL_RTCEx_TimeStampIRQHandler(RTC_HandleTypeDef *hrtc); 375 HAL_StatusTypeDef HAL_RTCEx_PollForTimeStampEvent(RTC_HandleTypeDef *hrtc, uint32_t Timeout); 376 void HAL_RTCEx_TimeStampEventCallback(RTC_HandleTypeDef *hrtc); 377 /** 378 * @} 379 */ 380 381 382 /* Extended Control functions ************************************************/ 383 /** @defgroup RTCEx_Exported_Functions_Group3 Extended Peripheral Control functions 384 * @{ 385 */ 386 387 HAL_StatusTypeDef HAL_RTCEx_SetSmoothCalib(RTC_HandleTypeDef *hrtc, uint32_t SmoothCalibPeriod, 388 uint32_t SmoothCalibPlusPulses, uint32_t SmoothCalibMinusPulsesValue); 389 HAL_StatusTypeDef HAL_RTCEx_SetSynchroShift(RTC_HandleTypeDef *hrtc, uint32_t ShiftAdd1S, uint32_t ShiftSubFS); 390 HAL_StatusTypeDef HAL_RTCEx_SetCalibrationOutPut(RTC_HandleTypeDef *hrtc, uint32_t CalibOutput); 391 HAL_StatusTypeDef HAL_RTCEx_DeactivateCalibrationOutPut(RTC_HandleTypeDef *hrtc); 392 HAL_StatusTypeDef HAL_RTCEx_SetRefClock(RTC_HandleTypeDef *hrtc); 393 HAL_StatusTypeDef HAL_RTCEx_DeactivateRefClock(RTC_HandleTypeDef *hrtc); 394 HAL_StatusTypeDef HAL_RTCEx_EnableBypassShadow(RTC_HandleTypeDef *hrtc); 395 HAL_StatusTypeDef HAL_RTCEx_DisableBypassShadow(RTC_HandleTypeDef *hrtc); 396 /** 397 * @} 398 */ 399 400 /* Extended RTC features functions *******************************************/ 401 /** @defgroup RTCEx_Exported_Functions_Group4 Extended features functions 402 * @{ 403 */ 404 405 406 /** 407 * @} 408 */ 409 410 /* Private types -------------------------------------------------------------*/ 411 /* Private variables ---------------------------------------------------------*/ 412 /* Private constants ---------------------------------------------------------*/ 413 /** @defgroup RTCEx_Private_Constants RTCEx Private Constants 414 * @{ 415 */ 416 #define RTC_EXTI_LINE_TIMESTAMP_EVENT EXTI_IMR1_IM21 /*!< External interrupt line 19 Connected to the RTC Time Stamp events */ 417 418 /** 419 * @} 420 */ 421 422 /* Private macros ------------------------------------------------------------*/ 423 /** @defgroup RTCEx_Private_Macros RTCEx Private Macros 424 * @{ 425 */ 426 427 /** @defgroup RTCEx_IS_RTC_Definitions Private macros to check input parameters 428 * @{ 429 */ 430 #define IS_TIMESTAMP_EDGE(EDGE) (((EDGE) == RTC_TIMESTAMPEDGE_RISING) || \ 431 ((EDGE) == RTC_TIMESTAMPEDGE_FALLING)) 432 433 434 #define IS_RTC_TIMESTAMP_PIN(PIN) (((PIN) == RTC_TIMESTAMPPIN_DEFAULT)) 435 436 #define IS_RTC_SMOOTH_CALIB_PERIOD(PERIOD) (((PERIOD) == RTC_SMOOTHCALIB_PERIOD_32SEC) || \ 437 ((PERIOD) == RTC_SMOOTHCALIB_PERIOD_16SEC) || \ 438 ((PERIOD) == RTC_SMOOTHCALIB_PERIOD_8SEC)) 439 440 #define IS_RTC_SMOOTH_CALIB_PLUS(PLUS) (((PLUS) == RTC_SMOOTHCALIB_PLUSPULSES_SET) || \ 441 ((PLUS) == RTC_SMOOTHCALIB_PLUSPULSES_RESET)) 442 443 444 /** @defgroup RTCEx_Smooth_calib_Minus_pulses_Definitions RTCEx Smooth calib Minus pulses Definitions 445 * @{ 446 */ 447 #define IS_RTC_SMOOTH_CALIB_MINUS(VALUE) ((VALUE) <= RTC_CALR_CALM) 448 /** 449 * @} 450 */ 451 452 453 #define IS_RTC_SHIFT_ADD1S(SEL) (((SEL) == RTC_SHIFTADD1S_RESET) || \ 454 ((SEL) == RTC_SHIFTADD1S_SET)) 455 456 457 458 /** @defgroup RTCEx_Subtract_Fraction_Of_Second_Value RTCEx SubtractFraction Of Second Value 459 * @{ 460 */ 461 #define IS_RTC_SHIFT_SUBFS(FS) ((FS) <= RTC_SHIFTR_SUBFS) 462 /** 463 * @} 464 */ 465 #define IS_RTC_CALIB_OUTPUT(OUTPUT) (((OUTPUT) == RTC_CALIBOUTPUT_512HZ) || \ 466 ((OUTPUT) == RTC_CALIBOUTPUT_1HZ)) 467 468 /** 469 * @} 470 */ 471 472 /** 473 * @} 474 */ 475 476 477 478 /** 479 * @} 480 */ 481 482 /** 483 * @} 484 */ 485 486 /** 487 * @} 488 */ 489 #ifdef __cplusplus 490 } 491 #endif 492 493 #endif /* STM32C0xx_HAL_RTC_EX_H */ 494