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_TSOVF Clear Time-stamp overflow flag 132 * @arg @ref RTC_CLEAR_TSF Clear Time-stamp flag 133 * @arg @ref RTC_CLEAR_ALRAF Clear Alarm A flag 134 * @retval None 135 */ 136 #define __HAL_RTC_CLEAR_FLAG(__HANDLE__, __FLAG__) ((__HANDLE__)->Instance->SCR = (__FLAG__)) 137 138 /** @brief Check whether the specified RTC flag is set or not. 139 * @param __HANDLE__ specifies the RTC Handle. 140 * @param __FLAG__ specifies the flag to check. 141 * This parameter can be: 142 * @arg @ref RTC_FLAG_RECALPF Recalibration pending Flag 143 * @arg @ref RTC_FLAG_INITF Initialization flag 144 * @arg @ref RTC_FLAG_RSF Registers synchronization flag 145 * @arg @ref RTC_FLAG_INITS Initialization status flag 146 * @arg @ref RTC_FLAG_SHPF Shift operation pending flag 147 * @arg @ref RTC_FLAG_ALRAWF Alarm A write flag 148 * @arg @ref RTC_FLAG_TSOVF Time-stamp overflow flag 149 * @arg @ref RTC_FLAG_TSF Time-stamp flag 150 * @arg @ref RTC_FLAG_ALRAF Alarm A flag 151 * @retval None 152 */ 153 #define __HAL_RTC_GET_FLAG(__HANDLE__, __FLAG__) \ 154 (((((__FLAG__)) >> 8U) == 1U) ? ((((__HANDLE__)->Instance->ICSR & (1U << (((uint16_t)(__FLAG__)) & RTC_FLAG_MASK))) \ 155 != 0U) ? 1U : 0U) : \ 156 ((((__HANDLE__)->Instance->SR & (1U << (((uint16_t)(__FLAG__)) & RTC_FLAG_MASK))) \ 157 != 0U) ? 1U : 0U)) 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__) \ 240 (((__FLAG__) == RTC_FLAG_TSF) ? \ 241 (__HAL_RTC_CLEAR_FLAG((__HANDLE__), RTC_CLEAR_TSF)) : \ 242 (__HAL_RTC_CLEAR_FLAG((__HANDLE__), RTC_CLEAR_TSOVF))) 243 244 /** 245 * @brief Enable interrupt on the RTC Timestamp associated Exti line. 246 * @retval None 247 */ 248 #define __HAL_RTC_TIMESTAMP_EXTI_ENABLE_IT() (EXTI->IMR1 |= RTC_EXTI_LINE_TIMESTAMP_EVENT) 249 250 /** 251 * @brief Disable interrupt on the RTC Timestamp associated Exti line. 252 * @retval None 253 */ 254 #define __HAL_RTC_TIMESTAMP_EXTI_DISABLE_IT() (EXTI->IMR1 &= ~(RTC_EXTI_LINE_TIMESTAMP_EVENT)) 255 256 /** 257 * @brief Enable event on the RTC Timestamp associated Exti line. 258 * @retval None 259 */ 260 #define __HAL_RTC_TIMESTAMP_EXTI_ENABLE_EVENT() (EXTI->EMR1 |= RTC_EXTI_LINE_TIMESTAMP_EVENT) 261 262 /** 263 * @brief Disable event on the RTC Timestamp associated Exti line. 264 * @retval None 265 */ 266 #define __HAL_RTC_TIMESTAMP_EXTI_DISABLE_EVENT() (EXTI->EMR1 &= ~(RTC_EXTI_LINE_TIMESTAMP_EVENT)) 267 268 /** 269 * @} 270 */ 271 272 273 /* ------------------------------Calibration----------------------------------*/ 274 /** @defgroup RTCEx_Calibration RTC Calibration 275 * @{ 276 */ 277 278 /** 279 * @brief Enable the RTC calibration output. 280 * @param __HANDLE__ specifies the RTC handle. 281 * @retval None 282 */ 283 #define __HAL_RTC_CALIBRATION_OUTPUT_ENABLE(__HANDLE__) ((__HANDLE__)->Instance->CR |= (RTC_CR_COE)) 284 285 /** 286 * @brief Disable the calibration output. 287 * @param __HANDLE__ specifies the RTC handle. 288 * @retval None 289 */ 290 #define __HAL_RTC_CALIBRATION_OUTPUT_DISABLE(__HANDLE__) ((__HANDLE__)->Instance->CR &= ~(RTC_CR_COE)) 291 292 293 /** 294 * @brief Enable the clock reference detection. 295 * @param __HANDLE__ specifies the RTC handle. 296 * @retval None 297 */ 298 #define __HAL_RTC_CLOCKREF_DETECTION_ENABLE(__HANDLE__) ((__HANDLE__)->Instance->CR |= (RTC_CR_REFCKON)) 299 300 /** 301 * @brief Disable the clock reference detection. 302 * @param __HANDLE__ specifies the RTC handle. 303 * @retval None 304 */ 305 #define __HAL_RTC_CLOCKREF_DETECTION_DISABLE(__HANDLE__) ((__HANDLE__)->Instance->CR &= ~(RTC_CR_REFCKON)) 306 307 308 /** 309 * @brief Get the selected RTC shift operations flag status. 310 * @param __HANDLE__ specifies the RTC handle. 311 * @param __FLAG__ specifies the RTC shift operation Flag is pending or not. 312 * This parameter can be: 313 * @arg @ref RTC_FLAG_SHPF 314 * @retval None 315 */ 316 #define __HAL_RTC_SHIFT_GET_FLAG(__HANDLE__, __FLAG__) (__HAL_RTC_GET_FLAG((__HANDLE__), (__FLAG__))) 317 /** 318 * @} 319 */ 320 321 322 /** 323 * @} 324 */ 325 326 /* Exported functions --------------------------------------------------------*/ 327 /** @defgroup RTCEx_Exported_Functions RTCEx Exported Functions 328 * @{ 329 */ 330 331 /* RTC TimeStamp functions *****************************************/ 332 /** @defgroup RTCEx_Exported_Functions_Group1 Extended RTC TimeStamp functions 333 * @{ 334 */ 335 336 HAL_StatusTypeDef HAL_RTCEx_SetTimeStamp(RTC_HandleTypeDef *hrtc, uint32_t TimeStampEdge, uint32_t RTC_TimeStampPin); 337 HAL_StatusTypeDef HAL_RTCEx_SetTimeStamp_IT(RTC_HandleTypeDef *hrtc, uint32_t TimeStampEdge, uint32_t RTC_TimeStampPin); 338 HAL_StatusTypeDef HAL_RTCEx_DeactivateTimeStamp(RTC_HandleTypeDef *hrtc); 339 HAL_StatusTypeDef HAL_RTCEx_GetTimeStamp(RTC_HandleTypeDef *hrtc, RTC_TimeTypeDef *sTimeStamp, 340 RTC_DateTypeDef *sTimeStampDate, uint32_t Format); 341 void HAL_RTCEx_TimeStampIRQHandler(RTC_HandleTypeDef *hrtc); 342 HAL_StatusTypeDef HAL_RTCEx_PollForTimeStampEvent(RTC_HandleTypeDef *hrtc, uint32_t Timeout); 343 void HAL_RTCEx_TimeStampEventCallback(RTC_HandleTypeDef *hrtc); 344 /** 345 * @} 346 */ 347 348 349 /* Extended Control functions ************************************************/ 350 /** @defgroup RTCEx_Exported_Functions_Group3 Extended Peripheral Control functions 351 * @{ 352 */ 353 354 HAL_StatusTypeDef HAL_RTCEx_SetSmoothCalib(RTC_HandleTypeDef *hrtc, uint32_t SmoothCalibPeriod, 355 uint32_t SmoothCalibPlusPulses, uint32_t SmoothCalibMinusPulsesValue); 356 HAL_StatusTypeDef HAL_RTCEx_SetSynchroShift(RTC_HandleTypeDef *hrtc, uint32_t ShiftAdd1S, uint32_t ShiftSubFS); 357 HAL_StatusTypeDef HAL_RTCEx_SetCalibrationOutPut(RTC_HandleTypeDef *hrtc, uint32_t CalibOutput); 358 HAL_StatusTypeDef HAL_RTCEx_DeactivateCalibrationOutPut(RTC_HandleTypeDef *hrtc); 359 HAL_StatusTypeDef HAL_RTCEx_SetRefClock(RTC_HandleTypeDef *hrtc); 360 HAL_StatusTypeDef HAL_RTCEx_DeactivateRefClock(RTC_HandleTypeDef *hrtc); 361 HAL_StatusTypeDef HAL_RTCEx_EnableBypassShadow(RTC_HandleTypeDef *hrtc); 362 HAL_StatusTypeDef HAL_RTCEx_DisableBypassShadow(RTC_HandleTypeDef *hrtc); 363 /** 364 * @} 365 */ 366 367 /* Extended RTC features functions *******************************************/ 368 /** @defgroup RTCEx_Exported_Functions_Group4 Extended features functions 369 * @{ 370 */ 371 372 373 /** 374 * @} 375 */ 376 377 /* Private types -------------------------------------------------------------*/ 378 /* Private variables ---------------------------------------------------------*/ 379 /* Private constants ---------------------------------------------------------*/ 380 /** @defgroup RTCEx_Private_Constants RTCEx Private Constants 381 * @{ 382 */ 383 #define RTC_EXTI_LINE_TIMESTAMP_EVENT EXTI_IMR1_IM19 /*!< External interrupt line 19 Connected to the RTC Time Stamp events */ 384 385 /** 386 * @} 387 */ 388 389 /* Private macros ------------------------------------------------------------*/ 390 /** @defgroup RTCEx_Private_Macros RTCEx Private Macros 391 * @{ 392 */ 393 394 /** @defgroup RTCEx_IS_RTC_Definitions Private macros to check input parameters 395 * @{ 396 */ 397 #define IS_TIMESTAMP_EDGE(EDGE) (((EDGE) == RTC_TIMESTAMPEDGE_RISING) || \ 398 ((EDGE) == RTC_TIMESTAMPEDGE_FALLING)) 399 400 401 #define IS_RTC_TIMESTAMP_PIN(PIN) (((PIN) == RTC_TIMESTAMPPIN_DEFAULT)) 402 403 #define IS_RTC_SMOOTH_CALIB_PERIOD(PERIOD) (((PERIOD) == RTC_SMOOTHCALIB_PERIOD_32SEC) || \ 404 ((PERIOD) == RTC_SMOOTHCALIB_PERIOD_16SEC) || \ 405 ((PERIOD) == RTC_SMOOTHCALIB_PERIOD_8SEC)) 406 407 #define IS_RTC_SMOOTH_CALIB_PLUS(PLUS) (((PLUS) == RTC_SMOOTHCALIB_PLUSPULSES_SET) || \ 408 ((PLUS) == RTC_SMOOTHCALIB_PLUSPULSES_RESET)) 409 410 411 /** @defgroup RTCEx_Smooth_calib_Minus_pulses_Definitions RTCEx Smooth calib Minus pulses Definitions 412 * @{ 413 */ 414 #define IS_RTC_SMOOTH_CALIB_MINUS(VALUE) ((VALUE) <= RTC_CALR_CALM) 415 /** 416 * @} 417 */ 418 419 420 #define IS_RTC_SHIFT_ADD1S(SEL) (((SEL) == RTC_SHIFTADD1S_RESET) || \ 421 ((SEL) == RTC_SHIFTADD1S_SET)) 422 423 424 /** @defgroup RTCEx_Subtract_Fraction_Of_Second_Value RTCEx SubtractFraction Of Second Value 425 * @{ 426 */ 427 #define IS_RTC_SHIFT_SUBFS(FS) ((FS) <= RTC_SHIFTR_SUBFS) 428 /** 429 * @} 430 */ 431 #define IS_RTC_CALIB_OUTPUT(OUTPUT) (((OUTPUT) == RTC_CALIBOUTPUT_512HZ) || \ 432 ((OUTPUT) == RTC_CALIBOUTPUT_1HZ)) 433 434 /** 435 * @} 436 */ 437 438 /** 439 * @} 440 */ 441 442 443 /** 444 * @} 445 */ 446 447 /** 448 * @} 449 */ 450 451 /** 452 * @} 453 */ 454 #ifdef __cplusplus 455 } 456 #endif 457 458 #endif /* STM32C0xx_HAL_RTC_EX_H */ 459