1 /** 2 ****************************************************************************** 3 * @file stm32f2xx_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) 2016 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 STM32F2xx_HAL_RTC_EX_H 21 #define STM32F2xx_HAL_RTC_EX_H 22 23 #ifdef __cplusplus 24 extern "C" { 25 #endif 26 27 /* Includes ------------------------------------------------------------------*/ 28 29 #include "stm32f2xx_hal_def.h" 30 31 /** @addtogroup STM32F2xx_HAL_Driver 32 * @{ 33 */ 34 35 /** @addtogroup RTCEx 36 * @{ 37 */ 38 39 /* Exported types ------------------------------------------------------------*/ 40 41 /** @defgroup RTCEx_Exported_Types RTCEx Exported Types 42 * @{ 43 */ 44 45 /** 46 * @brief RTC Tamper structure definition 47 */ 48 typedef struct 49 { 50 uint32_t Tamper; /*!< Specifies the Tamper Pin. 51 This parameter can be a value of @ref RTCEx_Tamper_Pin_Definitions */ 52 53 uint32_t PinSelection; /*!< Specifies the Tamper Pin. 54 This parameter can be a value of @ref RTCEx_Tamper_Pin_Selection */ 55 56 uint32_t Trigger; /*!< Specifies the Tamper Trigger. 57 This parameter can be a value of @ref RTCEx_Tamper_Trigger_Definitions */ 58 } RTC_TamperTypeDef; 59 /** 60 * @} 61 */ 62 63 /* Exported constants --------------------------------------------------------*/ 64 65 /** @defgroup RTCEx_Exported_Constants RTCEx Exported Constants 66 * @{ 67 */ 68 69 /** @defgroup RTCEx_Backup_Registers_Definitions RTCEx Backup Registers Definitions 70 * @{ 71 */ 72 #define RTC_BKP_DR0 0x00000000U 73 #define RTC_BKP_DR1 0x00000001U 74 #define RTC_BKP_DR2 0x00000002U 75 #define RTC_BKP_DR3 0x00000003U 76 #define RTC_BKP_DR4 0x00000004U 77 #define RTC_BKP_DR5 0x00000005U 78 #define RTC_BKP_DR6 0x00000006U 79 #define RTC_BKP_DR7 0x00000007U 80 #define RTC_BKP_DR8 0x00000008U 81 #define RTC_BKP_DR9 0x00000009U 82 #define RTC_BKP_DR10 0x0000000AU 83 #define RTC_BKP_DR11 0x0000000BU 84 #define RTC_BKP_DR12 0x0000000CU 85 #define RTC_BKP_DR13 0x0000000DU 86 #define RTC_BKP_DR14 0x0000000EU 87 #define RTC_BKP_DR15 0x0000000FU 88 #define RTC_BKP_DR16 0x00000010U 89 #define RTC_BKP_DR17 0x00000011U 90 #define RTC_BKP_DR18 0x00000012U 91 #define RTC_BKP_DR19 0x00000013U 92 /** 93 * @} 94 */ 95 96 /** @defgroup RTCEx_Timestamp_Edges_Definitions RTCEx Timestamp Edges Definitions 97 * @{ 98 */ 99 #define RTC_TIMESTAMPEDGE_RISING 0x00000000U 100 #define RTC_TIMESTAMPEDGE_FALLING RTC_CR_TSEDGE 101 /** 102 * @} 103 */ 104 105 /** @defgroup RTCEx_Timestamp_Pin_Selection RTC Timestamp Pin Selection 106 * @{ 107 */ 108 #define RTC_TIMESTAMPPIN_DEFAULT 0x00000000U 109 #define RTC_TIMESTAMPPIN_POS1 RTC_TAFCR_TSINSEL 110 /** 111 * @} 112 */ 113 114 /** @defgroup RTCEx_Tamper_Pin_Definitions RTCEx Tamper Pins Definitions 115 * @{ 116 */ 117 #define RTC_TAMPER_1 RTC_TAFCR_TAMP1E 118 /** 119 * @} 120 */ 121 122 /** @defgroup RTCEx_Tamper_Pin_Selection RTC tamper Pins Selection 123 * @{ 124 */ 125 #define RTC_TAMPERPIN_DEFAULT 0x00000000U 126 #define RTC_TAMPERPIN_POS1 RTC_TAFCR_TAMP1INSEL 127 /** 128 * @} 129 */ 130 131 /** @defgroup RTCEx_Tamper_Interrupt_Definitions RTCEx Tamper Interrupt Definitions 132 * @{ 133 */ 134 #define RTC_IT_TAMP RTC_TAFCR_TAMPIE /*!< Enable global Tamper Interrupt */ 135 /** 136 * @} 137 */ 138 139 /** @defgroup RTCEx_Tamper_Trigger_Definitions RTCEx Tamper Triggers Definitions 140 * @{ 141 */ 142 #define RTC_TAMPERTRIGGER_RISINGEDGE 0x00000000U 143 #define RTC_TAMPERTRIGGER_FALLINGEDGE 0x00000002U 144 /** 145 * @} 146 */ 147 148 /** @defgroup RTCEx_Wakeup_Timer_Definitions RTCEx Wakeup Timer Definitions 149 * @{ 150 */ 151 #define RTC_WAKEUPCLOCK_RTCCLK_DIV16 0x00000000U 152 #define RTC_WAKEUPCLOCK_RTCCLK_DIV8 RTC_CR_WUCKSEL_0 153 #define RTC_WAKEUPCLOCK_RTCCLK_DIV4 RTC_CR_WUCKSEL_1 154 #define RTC_WAKEUPCLOCK_RTCCLK_DIV2 (RTC_CR_WUCKSEL_0 | RTC_CR_WUCKSEL_1) 155 #define RTC_WAKEUPCLOCK_CK_SPRE_16BITS RTC_CR_WUCKSEL_2 156 #define RTC_WAKEUPCLOCK_CK_SPRE_17BITS (RTC_CR_WUCKSEL_1 | RTC_CR_WUCKSEL_2) 157 /** 158 * @} 159 */ 160 161 /** @defgroup RTCEx_Coarse_Calibration_Definitions RTCEx Coarse Calib Definitions 162 * @{ 163 */ 164 #define RTC_CALIBSIGN_POSITIVE 0x00000000U 165 #define RTC_CALIBSIGN_NEGATIVE RTC_CALIBR_DCS 166 /** 167 * @} 168 */ 169 170 /** 171 * @} 172 */ 173 174 /* Exported macros -----------------------------------------------------------*/ 175 176 /** @defgroup RTCEx_Exported_Macros RTCEx Exported Macros 177 * @{ 178 */ 179 180 /* ---------------------------------WAKEUPTIMER-------------------------------*/ 181 182 /** @defgroup RTCEx_WakeUp_Timer RTCEx WakeUp Timer 183 * @{ 184 */ 185 186 /** 187 * @brief Enable the RTC WakeUp Timer peripheral. 188 * @param __HANDLE__ specifies the RTC handle. 189 * @retval None 190 */ 191 #define __HAL_RTC_WAKEUPTIMER_ENABLE(__HANDLE__) ((__HANDLE__)->Instance->CR |= (RTC_CR_WUTE)) 192 193 /** 194 * @brief Disable the RTC Wakeup Timer peripheral. 195 * @param __HANDLE__ specifies the RTC handle. 196 * @retval None 197 */ 198 #define __HAL_RTC_WAKEUPTIMER_DISABLE(__HANDLE__) ((__HANDLE__)->Instance->CR &= ~(RTC_CR_WUTE)) 199 200 /** 201 * @brief Enable the RTC Wakeup Timer interrupt. 202 * @param __HANDLE__ specifies the RTC handle. 203 * @param __INTERRUPT__ specifies the RTC Wakeup Timer interrupt sources to be enabled or disabled. 204 * This parameter can be: 205 * @arg RTC_IT_WUT: Wakeup Timer interrupt 206 * @retval None 207 */ 208 #define __HAL_RTC_WAKEUPTIMER_ENABLE_IT(__HANDLE__, __INTERRUPT__) ((__HANDLE__)->Instance->CR |= (__INTERRUPT__)) 209 210 /** 211 * @brief Disable the RTC Wakeup Timer interrupt. 212 * @param __HANDLE__ specifies the RTC handle. 213 * @param __INTERRUPT__ specifies the RTC Wakeup Timer interrupt sources to be enabled or disabled. 214 * This parameter can be: 215 * @arg RTC_IT_WUT: Wakeup Timer interrupt 216 * @retval None 217 */ 218 #define __HAL_RTC_WAKEUPTIMER_DISABLE_IT(__HANDLE__, __INTERRUPT__) ((__HANDLE__)->Instance->CR &= ~(__INTERRUPT__)) 219 220 /** 221 * @brief Check whether the specified RTC Wakeup Timer interrupt has occurred or not. 222 * @param __HANDLE__ specifies the RTC handle. 223 * @param __INTERRUPT__ specifies the RTC Wakeup Timer interrupt to check. 224 * This parameter can be: 225 * @arg RTC_IT_WUT: Wakeup Timer interrupt 226 * @retval None 227 */ 228 #define __HAL_RTC_WAKEUPTIMER_GET_IT(__HANDLE__, __INTERRUPT__) (((((__HANDLE__)->Instance->ISR) & ((__INTERRUPT__) >> 4U)) != 0U) ? 1U : 0U) 229 230 /** 231 * @brief Check whether the specified RTC Wakeup timer interrupt has been enabled or not. 232 * @param __HANDLE__ specifies the RTC handle. 233 * @param __INTERRUPT__ specifies the RTC Wakeup timer interrupt sources to check. 234 * This parameter can be: 235 * @arg RTC_IT_WUT: WakeUpTimer interrupt 236 * @retval None 237 */ 238 #define __HAL_RTC_WAKEUPTIMER_GET_IT_SOURCE(__HANDLE__, __INTERRUPT__) (((((__HANDLE__)->Instance->CR) & (__INTERRUPT__)) != 0U) ? 1U : 0U) 239 240 /** 241 * @brief Get the selected RTC Wakeup Timer's flag status. 242 * @param __HANDLE__ specifies the RTC handle. 243 * @param __FLAG__ specifies the RTC Wakeup Timer flag to check. 244 * This parameter can be: 245 * @arg RTC_FLAG_WUTF: Wakeup Timer interrupt flag 246 * @arg RTC_FLAG_WUTWF: Wakeup Timer 'write allowed' flag 247 * @retval None 248 */ 249 #define __HAL_RTC_WAKEUPTIMER_GET_FLAG(__HANDLE__, __FLAG__) (((((__HANDLE__)->Instance->ISR) & (__FLAG__)) != 0U)? 1U : 0U) 250 251 /** 252 * @brief Clear the RTC Wakeup timer's pending flags. 253 * @param __HANDLE__ specifies the RTC handle. 254 * @param __FLAG__ specifies the RTC Wakeup Timer Flag to clear. 255 * This parameter can be: 256 * @arg RTC_FLAG_WUTF: Wakeup Timer interrupt Flag 257 * @retval None 258 */ 259 #define __HAL_RTC_WAKEUPTIMER_CLEAR_FLAG(__HANDLE__, __FLAG__) ((__HANDLE__)->Instance->ISR) = (~((__FLAG__) | RTC_ISR_INIT)|((__HANDLE__)->Instance->ISR & RTC_ISR_INIT)) 260 261 /** 262 * @brief Enable interrupt on the RTC Wakeup Timer associated EXTI line. 263 * @retval None 264 */ 265 #define __HAL_RTC_WAKEUPTIMER_EXTI_ENABLE_IT() (EXTI->IMR |= RTC_EXTI_LINE_WAKEUPTIMER_EVENT) 266 267 /** 268 * @brief Disable interrupt on the RTC Wakeup Timer associated EXTI line. 269 * @retval None 270 */ 271 #define __HAL_RTC_WAKEUPTIMER_EXTI_DISABLE_IT() (EXTI->IMR &= ~RTC_EXTI_LINE_WAKEUPTIMER_EVENT) 272 273 /** 274 * @brief Enable event on the RTC Wakeup Timer associated EXTI line. 275 * @retval None. 276 */ 277 #define __HAL_RTC_WAKEUPTIMER_EXTI_ENABLE_EVENT() (EXTI->EMR |= RTC_EXTI_LINE_WAKEUPTIMER_EVENT) 278 279 /** 280 * @brief Disable event on the RTC Wakeup Timer associated EXTI line. 281 * @retval None. 282 */ 283 #define __HAL_RTC_WAKEUPTIMER_EXTI_DISABLE_EVENT() (EXTI->EMR &= ~RTC_EXTI_LINE_WAKEUPTIMER_EVENT) 284 285 /** 286 * @brief Enable falling edge trigger on the RTC Wakeup Timer associated EXTI line. 287 * @retval None. 288 */ 289 #define __HAL_RTC_WAKEUPTIMER_EXTI_ENABLE_FALLING_EDGE() (EXTI->FTSR |= RTC_EXTI_LINE_WAKEUPTIMER_EVENT) 290 291 /** 292 * @brief Disable falling edge trigger on the RTC Wakeup Timer associated EXTI line. 293 * @retval None. 294 */ 295 #define __HAL_RTC_WAKEUPTIMER_EXTI_DISABLE_FALLING_EDGE() (EXTI->FTSR &= ~RTC_EXTI_LINE_WAKEUPTIMER_EVENT) 296 297 /** 298 * @brief Enable rising edge trigger on the RTC Wakeup Timer associated EXTI line. 299 * @retval None. 300 */ 301 #define __HAL_RTC_WAKEUPTIMER_EXTI_ENABLE_RISING_EDGE() (EXTI->RTSR |= RTC_EXTI_LINE_WAKEUPTIMER_EVENT) 302 303 /** 304 * @brief Disable rising edge trigger on the RTC Wakeup Timer associated EXTI line. 305 * @retval None. 306 */ 307 #define __HAL_RTC_WAKEUPTIMER_EXTI_DISABLE_RISING_EDGE() (EXTI->RTSR &= ~RTC_EXTI_LINE_WAKEUPTIMER_EVENT) 308 309 /** 310 * @brief Enable rising & falling edge trigger on the RTC Wakeup Timer associated EXTI line. 311 * @retval None. 312 */ 313 #define __HAL_RTC_WAKEUPTIMER_EXTI_ENABLE_RISING_FALLING_EDGE() do { \ 314 __HAL_RTC_WAKEUPTIMER_EXTI_ENABLE_RISING_EDGE(); \ 315 __HAL_RTC_WAKEUPTIMER_EXTI_ENABLE_FALLING_EDGE(); \ 316 } while(0U) 317 318 /** 319 * @brief Disable rising & falling edge trigger on the RTC Wakeup Timer associated EXTI line. 320 * This parameter can be: 321 * @retval None. 322 */ 323 #define __HAL_RTC_WAKEUPTIMER_EXTI_DISABLE_RISING_FALLING_EDGE() do { \ 324 __HAL_RTC_WAKEUPTIMER_EXTI_DISABLE_RISING_EDGE(); \ 325 __HAL_RTC_WAKEUPTIMER_EXTI_DISABLE_FALLING_EDGE(); \ 326 } while(0U) 327 328 /** 329 * @brief Check whether the RTC Wakeup Timer associated EXTI line interrupt flag is set or not. 330 * @retval Line Status. 331 */ 332 #define __HAL_RTC_WAKEUPTIMER_EXTI_GET_FLAG() (EXTI->PR & RTC_EXTI_LINE_WAKEUPTIMER_EVENT) 333 334 /** 335 * @brief Clear the RTC Wakeup Timer associated EXTI line flag. 336 * @retval None. 337 */ 338 #define __HAL_RTC_WAKEUPTIMER_EXTI_CLEAR_FLAG() (EXTI->PR = RTC_EXTI_LINE_WAKEUPTIMER_EVENT) 339 340 /** 341 * @brief Generate a Software interrupt on the RTC Wakeup Timer associated EXTI line. 342 * @retval None. 343 */ 344 #define __HAL_RTC_WAKEUPTIMER_EXTI_GENERATE_SWIT() (EXTI->SWIER |= RTC_EXTI_LINE_WAKEUPTIMER_EVENT) 345 346 /** 347 * @} 348 */ 349 350 /* ---------------------------------TIMESTAMP---------------------------------*/ 351 352 /** @defgroup RTCEx_Timestamp RTCEx Timestamp 353 * @{ 354 */ 355 356 /** 357 * @brief Enable the RTC Timestamp peripheral. 358 * @param __HANDLE__ specifies the RTC handle. 359 * @retval None 360 */ 361 #define __HAL_RTC_TIMESTAMP_ENABLE(__HANDLE__) ((__HANDLE__)->Instance->CR |= (RTC_CR_TSE)) 362 363 /** 364 * @brief Disable the RTC Timestamp peripheral. 365 * @param __HANDLE__ specifies the RTC handle. 366 * @retval None 367 */ 368 #define __HAL_RTC_TIMESTAMP_DISABLE(__HANDLE__) ((__HANDLE__)->Instance->CR &= ~(RTC_CR_TSE)) 369 370 /** 371 * @brief Enable the RTC Timestamp interrupt. 372 * @param __HANDLE__ specifies the RTC handle. 373 * @param __INTERRUPT__ specifies the RTC Timestamp interrupt sources to be enabled or disabled. 374 * This parameter can be: 375 * @arg RTC_IT_TS: TimeStamp interrupt 376 * @retval None 377 */ 378 #define __HAL_RTC_TIMESTAMP_ENABLE_IT(__HANDLE__, __INTERRUPT__) ((__HANDLE__)->Instance->CR |= (__INTERRUPT__)) 379 380 /** 381 * @brief Disable the RTC Timestamp interrupt. 382 * @param __HANDLE__ specifies the RTC handle. 383 * @param __INTERRUPT__ specifies the RTC Timestamp interrupt sources to be enabled or disabled. 384 * This parameter can be: 385 * @arg RTC_IT_TS: TimeStamp interrupt 386 * @retval None 387 */ 388 #define __HAL_RTC_TIMESTAMP_DISABLE_IT(__HANDLE__, __INTERRUPT__) ((__HANDLE__)->Instance->CR &= ~(__INTERRUPT__)) 389 390 /** 391 * @brief Check whether the specified RTC Timestamp interrupt has occurred or not. 392 * @param __HANDLE__ specifies the RTC handle. 393 * @param __INTERRUPT__ specifies the RTC Timestamp interrupt to check. 394 * This parameter can be: 395 * @arg RTC_IT_TS: TimeStamp interrupt 396 * @retval None 397 */ 398 #define __HAL_RTC_TIMESTAMP_GET_IT(__HANDLE__, __INTERRUPT__) (((((__HANDLE__)->Instance->ISR) & ((__INTERRUPT__) >> 4U)) != 0U) ? 1U : 0U) 399 400 /** 401 * @brief Check whether the specified RTC Timestamp interrupt has been enabled or not. 402 * @param __HANDLE__ specifies the RTC handle. 403 * @param __INTERRUPT__ specifies the RTC Timestamp interrupt source to check. 404 * This parameter can be: 405 * @arg RTC_IT_TS: TimeStamp interrupt 406 * @retval None 407 */ 408 #define __HAL_RTC_TIMESTAMP_GET_IT_SOURCE(__HANDLE__, __INTERRUPT__) (((((__HANDLE__)->Instance->CR) & (__INTERRUPT__)) != 0U) ? 1U : 0U) 409 410 /** 411 * @brief Get the selected RTC Timestamp's flag status. 412 * @param __HANDLE__ specifies the RTC handle. 413 * @param __FLAG__ specifies the RTC Timestamp flag to check. 414 * This parameter can be: 415 * @arg RTC_FLAG_TSF: Timestamp interrupt flag 416 * @arg RTC_FLAG_TSOVF: Timestamp overflow flag 417 * @retval None 418 */ 419 #define __HAL_RTC_TIMESTAMP_GET_FLAG(__HANDLE__, __FLAG__) (((((__HANDLE__)->Instance->ISR) & (__FLAG__)) != 0U)? 1U : 0U) 420 421 /** 422 * @brief Clear the RTC Timestamp's pending flags. 423 * @param __HANDLE__ specifies the RTC handle. 424 * @param __FLAG__ specifies the RTC Timestamp flag to clear. 425 * This parameter can be: 426 * @arg RTC_FLAG_TSF: Timestamp interrupt flag 427 * @arg RTC_FLAG_TSOVF: Timestamp overflow flag 428 * @retval None 429 */ 430 #define __HAL_RTC_TIMESTAMP_CLEAR_FLAG(__HANDLE__, __FLAG__) ((__HANDLE__)->Instance->ISR) = (~((__FLAG__) | RTC_ISR_INIT)|((__HANDLE__)->Instance->ISR & RTC_ISR_INIT)) 431 432 /** 433 * @} 434 */ 435 436 /* ---------------------------------TAMPER------------------------------------*/ 437 438 /** @defgroup RTCEx_Tamper RTCEx Tamper 439 * @{ 440 */ 441 442 /** 443 * @brief Enable the RTC Tamper1 input detection. 444 * @param __HANDLE__ specifies the RTC handle. 445 * @retval None 446 */ 447 #define __HAL_RTC_TAMPER1_ENABLE(__HANDLE__) ((__HANDLE__)->Instance->TAFCR |= (RTC_TAFCR_TAMP1E)) 448 449 /** 450 * @brief Disable the RTC Tamper1 input detection. 451 * @param __HANDLE__ specifies the RTC handle. 452 * @retval None 453 */ 454 #define __HAL_RTC_TAMPER1_DISABLE(__HANDLE__) ((__HANDLE__)->Instance->TAFCR &= ~(RTC_TAFCR_TAMP1E)) 455 456 /** 457 * @brief Enable the RTC Tamper interrupt. 458 * @param __HANDLE__ specifies the RTC handle. 459 * @param __INTERRUPT__ specifies the RTC Tamper interrupt sources to be enabled. 460 * This parameter can be any combination of the following values: 461 * @arg RTC_IT_TAMP: Tamper global interrupt 462 * @retval None 463 */ 464 #define __HAL_RTC_TAMPER_ENABLE_IT(__HANDLE__, __INTERRUPT__) ((__HANDLE__)->Instance->TAFCR |= (__INTERRUPT__)) 465 466 /** 467 * @brief Disable the RTC Tamper interrupt. 468 * @param __HANDLE__ specifies the RTC handle. 469 * @param __INTERRUPT__ specifies the RTC Tamper interrupt sources to be disabled. 470 * This parameter can be any combination of the following values: 471 * @arg RTC_IT_TAMP: Tamper global interrupt 472 * @retval None 473 */ 474 #define __HAL_RTC_TAMPER_DISABLE_IT(__HANDLE__, __INTERRUPT__) ((__HANDLE__)->Instance->TAFCR &= ~(__INTERRUPT__)) 475 476 /** 477 * @brief Check whether the specified RTC Tamper interrupt has been enabled or not. 478 * @param __HANDLE__ specifies the RTC handle. 479 * @param __INTERRUPT__ specifies the RTC Tamper interrupt source to check. 480 * This parameter can be: 481 * @arg RTC_IT_TAMP: Tamper global interrupt 482 * @retval None 483 */ 484 #define __HAL_RTC_TAMPER_GET_IT_SOURCE(__HANDLE__, __INTERRUPT__) (((((__HANDLE__)->Instance->TAFCR) & (__INTERRUPT__)) != 0U) ? 1U : 0U) 485 486 /** 487 * @brief Get the selected RTC Tamper's flag status. 488 * @param __HANDLE__ specifies the RTC handle. 489 * @param __FLAG__ specifies the RTC Tamper flag to be checked. 490 * This parameter can be: 491 * @arg RTC_FLAG_TAMP1F: Tamper 1 interrupt flag 492 * @retval None 493 */ 494 #define __HAL_RTC_TAMPER_GET_FLAG(__HANDLE__, __FLAG__) (((((__HANDLE__)->Instance->ISR) & (__FLAG__)) != 0U)? 1U : 0U) 495 496 /** 497 * @brief Clear the RTC Tamper's pending flags. 498 * @param __HANDLE__ specifies the RTC handle. 499 * @param __FLAG__ specifies the RTC Tamper Flag to clear. 500 * This parameter can be: 501 * @arg RTC_FLAG_TAMP1F: Tamper 1 interrupt flag 502 * @retval None 503 */ 504 #define __HAL_RTC_TAMPER_CLEAR_FLAG(__HANDLE__, __FLAG__) ((__HANDLE__)->Instance->ISR) = (~((__FLAG__) | RTC_ISR_INIT)|((__HANDLE__)->Instance->ISR & RTC_ISR_INIT)) 505 /** 506 * @} 507 */ 508 509 /* --------------------------TAMPER/TIMESTAMP---------------------------------*/ 510 /** @defgroup RTCEx_Tamper_Timestamp EXTI RTC Tamper Timestamp EXTI 511 * @{ 512 */ 513 514 /** 515 * @brief Enable interrupt on the RTC Tamper and Timestamp associated EXTI line. 516 * @retval None 517 */ 518 #define __HAL_RTC_TAMPER_TIMESTAMP_EXTI_ENABLE_IT() (EXTI->IMR |= RTC_EXTI_LINE_TAMPER_TIMESTAMP_EVENT) 519 520 /** 521 * @brief Disable interrupt on the RTC Tamper and Timestamp associated EXTI line. 522 * @retval None 523 */ 524 #define __HAL_RTC_TAMPER_TIMESTAMP_EXTI_DISABLE_IT() (EXTI->IMR &= ~RTC_EXTI_LINE_TAMPER_TIMESTAMP_EVENT) 525 526 /** 527 * @brief Enable event on the RTC Tamper and Timestamp associated EXTI line. 528 * @retval None. 529 */ 530 #define __HAL_RTC_TAMPER_TIMESTAMP_EXTI_ENABLE_EVENT() (EXTI->EMR |= RTC_EXTI_LINE_TAMPER_TIMESTAMP_EVENT) 531 532 /** 533 * @brief Disable event on the RTC Tamper and Timestamp associated EXTI line. 534 * @retval None. 535 */ 536 #define __HAL_RTC_TAMPER_TIMESTAMP_EXTI_DISABLE_EVENT() (EXTI->EMR &= ~RTC_EXTI_LINE_TAMPER_TIMESTAMP_EVENT) 537 538 /** 539 * @brief Enable falling edge trigger on the RTC Tamper and Timestamp associated EXTI line. 540 * @retval None. 541 */ 542 #define __HAL_RTC_TAMPER_TIMESTAMP_EXTI_ENABLE_FALLING_EDGE() (EXTI->FTSR |= RTC_EXTI_LINE_TAMPER_TIMESTAMP_EVENT) 543 544 /** 545 * @brief Disable falling edge trigger on the RTC Tamper and Timestamp associated EXTI line. 546 * @retval None. 547 */ 548 #define __HAL_RTC_TAMPER_TIMESTAMP_EXTI_DISABLE_FALLING_EDGE() (EXTI->FTSR &= ~RTC_EXTI_LINE_TAMPER_TIMESTAMP_EVENT) 549 550 /** 551 * @brief Enable rising edge trigger on the RTC Tamper and Timestamp associated EXTI line. 552 * @retval None. 553 */ 554 #define __HAL_RTC_TAMPER_TIMESTAMP_EXTI_ENABLE_RISING_EDGE() (EXTI->RTSR |= RTC_EXTI_LINE_TAMPER_TIMESTAMP_EVENT) 555 556 /** 557 * @brief Disable rising edge trigger on the RTC Tamper and Timestamp associated EXTI line. 558 * @retval None. 559 */ 560 #define __HAL_RTC_TAMPER_TIMESTAMP_EXTI_DISABLE_RISING_EDGE() (EXTI->RTSR &= ~RTC_EXTI_LINE_TAMPER_TIMESTAMP_EVENT) 561 562 /** 563 * @brief Enable rising & falling edge trigger on the RTC Tamper and Timestamp associated EXTI line. 564 * @retval None. 565 */ 566 #define __HAL_RTC_TAMPER_TIMESTAMP_EXTI_ENABLE_RISING_FALLING_EDGE() do { \ 567 __HAL_RTC_TAMPER_TIMESTAMP_EXTI_ENABLE_RISING_EDGE(); \ 568 __HAL_RTC_TAMPER_TIMESTAMP_EXTI_ENABLE_FALLING_EDGE(); \ 569 } while(0U) 570 571 /** 572 * @brief Disable rising & falling edge trigger on the RTC Tamper and Timestamp associated EXTI line. 573 * This parameter can be: 574 * @retval None. 575 */ 576 #define __HAL_RTC_TAMPER_TIMESTAMP_EXTI_DISABLE_RISING_FALLING_EDGE() do { \ 577 __HAL_RTC_TAMPER_TIMESTAMP_EXTI_DISABLE_RISING_EDGE(); \ 578 __HAL_RTC_TAMPER_TIMESTAMP_EXTI_DISABLE_FALLING_EDGE(); \ 579 } while(0U) 580 581 /** 582 * @brief Check whether the RTC Tamper and Timestamp associated EXTI line interrupt flag is set or not. 583 * @retval Line Status. 584 */ 585 #define __HAL_RTC_TAMPER_TIMESTAMP_EXTI_GET_FLAG() (EXTI->PR & RTC_EXTI_LINE_TAMPER_TIMESTAMP_EVENT) 586 587 /** 588 * @brief Clear the RTC Tamper and Timestamp associated EXTI line flag. 589 * @retval None. 590 */ 591 #define __HAL_RTC_TAMPER_TIMESTAMP_EXTI_CLEAR_FLAG() (EXTI->PR = RTC_EXTI_LINE_TAMPER_TIMESTAMP_EVENT) 592 593 /** 594 * @brief Generate a Software interrupt on the RTC Tamper and Timestamp associated EXTI line 595 * @retval None. 596 */ 597 #define __HAL_RTC_TAMPER_TIMESTAMP_EXTI_GENERATE_SWIT() (EXTI->SWIER |= RTC_EXTI_LINE_TAMPER_TIMESTAMP_EVENT) 598 /** 599 * @} 600 */ 601 602 /* ------------------------------CALIBRATION----------------------------------*/ 603 604 /** @defgroup RTCEx_Calibration RTCEx Calibration 605 * @{ 606 */ 607 608 /** 609 * @brief Enable the Coarse calibration process. 610 * @param __HANDLE__ specifies the RTC handle. 611 * @retval None 612 */ 613 #define __HAL_RTC_COARSE_CALIB_ENABLE(__HANDLE__) ((__HANDLE__)->Instance->CR |= (RTC_CR_DCE)) 614 615 /** 616 * @brief Disable the Coarse calibration process. 617 * @param __HANDLE__ specifies the RTC handle. 618 * @retval None 619 */ 620 #define __HAL_RTC_COARSE_CALIB_DISABLE(__HANDLE__) ((__HANDLE__)->Instance->CR &= ~(RTC_CR_DCE)) 621 622 /** 623 * @brief Enable the RTC calibration output. 624 * @param __HANDLE__ specifies the RTC handle. 625 * @retval None 626 */ 627 #define __HAL_RTC_CALIBRATION_OUTPUT_ENABLE(__HANDLE__) ((__HANDLE__)->Instance->CR |= (RTC_CR_COE)) 628 629 /** 630 * @brief Disable the calibration output. 631 * @param __HANDLE__ specifies the RTC handle. 632 * @retval None 633 */ 634 #define __HAL_RTC_CALIBRATION_OUTPUT_DISABLE(__HANDLE__) ((__HANDLE__)->Instance->CR &= ~(RTC_CR_COE)) 635 636 /** 637 * @brief Enable the clock reference detection. 638 * @param __HANDLE__ specifies the RTC handle. 639 * @retval None 640 */ 641 #define __HAL_RTC_CLOCKREF_DETECTION_ENABLE(__HANDLE__) ((__HANDLE__)->Instance->CR |= (RTC_CR_REFCKON)) 642 643 /** 644 * @brief Disable the clock reference detection. 645 * @param __HANDLE__ specifies the RTC handle. 646 * @retval None 647 */ 648 #define __HAL_RTC_CLOCKREF_DETECTION_DISABLE(__HANDLE__) ((__HANDLE__)->Instance->CR &= ~(RTC_CR_REFCKON)) 649 650 /** 651 * @} 652 */ 653 654 /* Exported functions --------------------------------------------------------*/ 655 656 /** @defgroup RTCEx_Exported_Functions RTCEx Exported Functions 657 * @{ 658 */ 659 660 /** @addtogroup RTCEx_Exported_Functions_Group1 661 * @{ 662 */ 663 /* RTC Timestamp and Tamper functions *****************************************/ 664 HAL_StatusTypeDef HAL_RTCEx_SetTimeStamp(RTC_HandleTypeDef *hrtc, uint32_t RTC_TimeStampEdge, uint32_t RTC_TimeStampPin); 665 HAL_StatusTypeDef HAL_RTCEx_SetTimeStamp_IT(RTC_HandleTypeDef *hrtc, uint32_t RTC_TimeStampEdge, uint32_t RTC_TimeStampPin); 666 HAL_StatusTypeDef HAL_RTCEx_DeactivateTimeStamp(RTC_HandleTypeDef *hrtc); 667 HAL_StatusTypeDef HAL_RTCEx_GetTimeStamp(RTC_HandleTypeDef *hrtc, RTC_TimeTypeDef *sTimeStamp, RTC_DateTypeDef *sTimeStampDate, uint32_t Format); 668 669 HAL_StatusTypeDef HAL_RTCEx_SetTamper(RTC_HandleTypeDef *hrtc, RTC_TamperTypeDef *sTamper); 670 HAL_StatusTypeDef HAL_RTCEx_SetTamper_IT(RTC_HandleTypeDef *hrtc, RTC_TamperTypeDef *sTamper); 671 HAL_StatusTypeDef HAL_RTCEx_DeactivateTamper(RTC_HandleTypeDef *hrtc, uint32_t Tamper); 672 void HAL_RTCEx_TamperTimeStampIRQHandler(RTC_HandleTypeDef *hrtc); 673 674 void HAL_RTCEx_Tamper1EventCallback(RTC_HandleTypeDef *hrtc); 675 void HAL_RTCEx_TimeStampEventCallback(RTC_HandleTypeDef *hrtc); 676 HAL_StatusTypeDef HAL_RTCEx_PollForTimeStampEvent(RTC_HandleTypeDef *hrtc, uint32_t Timeout); 677 HAL_StatusTypeDef HAL_RTCEx_PollForTamper1Event(RTC_HandleTypeDef *hrtc, uint32_t Timeout); 678 /** 679 * @} 680 */ 681 682 /** @addtogroup RTCEx_Exported_Functions_Group2 683 * @{ 684 */ 685 /* RTC Wakeup functions ******************************************************/ 686 HAL_StatusTypeDef HAL_RTCEx_SetWakeUpTimer(RTC_HandleTypeDef *hrtc, uint32_t WakeUpCounter, uint32_t WakeUpClock); 687 HAL_StatusTypeDef HAL_RTCEx_SetWakeUpTimer_IT(RTC_HandleTypeDef *hrtc, uint32_t WakeUpCounter, uint32_t WakeUpClock); 688 HAL_StatusTypeDef HAL_RTCEx_DeactivateWakeUpTimer(RTC_HandleTypeDef *hrtc); 689 uint32_t HAL_RTCEx_GetWakeUpTimer(RTC_HandleTypeDef *hrtc); 690 void HAL_RTCEx_WakeUpTimerIRQHandler(RTC_HandleTypeDef *hrtc); 691 void HAL_RTCEx_WakeUpTimerEventCallback(RTC_HandleTypeDef *hrtc); 692 HAL_StatusTypeDef HAL_RTCEx_PollForWakeUpTimerEvent(RTC_HandleTypeDef *hrtc, uint32_t Timeout); 693 /** 694 * @} 695 */ 696 697 /** @addtogroup RTCEx_Exported_Functions_Group3 698 * @{ 699 */ 700 /* Extended Control functions ************************************************/ 701 void HAL_RTCEx_BKUPWrite(RTC_HandleTypeDef *hrtc, uint32_t BackupRegister, uint32_t Data); 702 uint32_t HAL_RTCEx_BKUPRead(RTC_HandleTypeDef *hrtc, uint32_t BackupRegister); 703 704 HAL_StatusTypeDef HAL_RTCEx_SetCoarseCalib(RTC_HandleTypeDef *hrtc, uint32_t CalibSign, uint32_t Value); 705 HAL_StatusTypeDef HAL_RTCEx_DeactivateCoarseCalib(RTC_HandleTypeDef *hrtc); 706 HAL_StatusTypeDef HAL_RTCEx_SetCalibrationOutPut(RTC_HandleTypeDef *hrtc); 707 HAL_StatusTypeDef HAL_RTCEx_DeactivateCalibrationOutPut(RTC_HandleTypeDef *hrtc); 708 HAL_StatusTypeDef HAL_RTCEx_SetRefClock(RTC_HandleTypeDef *hrtc); 709 HAL_StatusTypeDef HAL_RTCEx_DeactivateRefClock(RTC_HandleTypeDef *hrtc); 710 /** 711 * @} 712 */ 713 714 /** @addtogroup RTCEx_Exported_Functions_Group4 715 * @{ 716 */ 717 /* Extended RTC features functions *******************************************/ 718 void HAL_RTCEx_AlarmBEventCallback(RTC_HandleTypeDef *hrtc); 719 HAL_StatusTypeDef HAL_RTCEx_PollForAlarmBEvent(RTC_HandleTypeDef *hrtc, uint32_t Timeout); 720 /** 721 * @} 722 */ 723 724 /** 725 * @} 726 */ 727 728 /* Private types -------------------------------------------------------------*/ 729 /* Private variables ---------------------------------------------------------*/ 730 /* Private constants ---------------------------------------------------------*/ 731 732 /** @defgroup RTCEx_Private_Constants RTCEx Private Constants 733 * @{ 734 */ 735 #define RTC_EXTI_LINE_TAMPER_TIMESTAMP_EVENT EXTI_IMR_MR21 /*!< External interrupt line 21 Connected to the RTC Tamper and Timestamp event */ 736 #define RTC_EXTI_LINE_WAKEUPTIMER_EVENT EXTI_IMR_MR22 /*!< External interrupt line 22 Connected to the RTC Wakeup event */ 737 /** 738 * @} 739 */ 740 741 /** @defgroup RTCEx_Private_Constants RTCEx Private Constants 742 * @{ 743 */ 744 /* Masks Definition */ 745 #define RTC_TAMPER_ENABLE_BITS_MASK RTC_TAMPER_1 746 747 #define RTC_TAMPER_FLAGS_MASK RTC_FLAG_TAMP1F 748 /** 749 * @} 750 */ 751 752 /* Private macros ------------------------------------------------------------*/ 753 754 /** @defgroup RTCEx_Private_Macros RTCEx Private Macros 755 * @{ 756 */ 757 758 /** @defgroup RTCEx_IS_RTC_Definitions Private macros to check input parameters 759 * @{ 760 */ 761 #define IS_RTC_BKP(BKP) ((BKP) < (uint32_t) RTC_BKP_NUMBER) 762 763 #define IS_TIMESTAMP_EDGE(EDGE) (((EDGE) == RTC_TIMESTAMPEDGE_RISING) || \ 764 ((EDGE) == RTC_TIMESTAMPEDGE_FALLING)) 765 766 #define IS_RTC_TAMPER(TAMPER) ((((TAMPER) & ((uint32_t)~RTC_TAMPER_ENABLE_BITS_MASK)) == 0x00U) && ((TAMPER) != 0U)) 767 768 #define IS_RTC_TAMPER_PIN(PIN) (((PIN) == RTC_TAMPERPIN_DEFAULT) || \ 769 ((PIN) == RTC_TAMPERPIN_POS1)) 770 771 #define IS_RTC_TIMESTAMP_PIN(PIN) (((PIN) == RTC_TIMESTAMPPIN_DEFAULT) || \ 772 ((PIN) == RTC_TIMESTAMPPIN_POS1)) 773 774 #define IS_RTC_TAMPER_TRIGGER(TRIGGER) (((TRIGGER) == RTC_TAMPERTRIGGER_RISINGEDGE) || \ 775 ((TRIGGER) == RTC_TAMPERTRIGGER_FALLINGEDGE)) 776 777 #define IS_RTC_WAKEUP_CLOCK(CLOCK) (((CLOCK) == RTC_WAKEUPCLOCK_RTCCLK_DIV16) || \ 778 ((CLOCK) == RTC_WAKEUPCLOCK_RTCCLK_DIV8) || \ 779 ((CLOCK) == RTC_WAKEUPCLOCK_RTCCLK_DIV4) || \ 780 ((CLOCK) == RTC_WAKEUPCLOCK_RTCCLK_DIV2) || \ 781 ((CLOCK) == RTC_WAKEUPCLOCK_CK_SPRE_16BITS) || \ 782 ((CLOCK) == RTC_WAKEUPCLOCK_CK_SPRE_17BITS)) 783 784 #define IS_RTC_WAKEUP_COUNTER(COUNTER) ((COUNTER) <= RTC_WUTR_WUT) 785 786 #define IS_RTC_CALIB_SIGN(SIGN) (((SIGN) == RTC_CALIBSIGN_POSITIVE) || \ 787 ((SIGN) == RTC_CALIBSIGN_NEGATIVE)) 788 789 #define IS_RTC_CALIB_VALUE(VALUE) ((VALUE) < 0x20U) 790 791 /** 792 * @} 793 */ 794 795 /** 796 * @} 797 */ 798 799 /** 800 * @} 801 */ 802 803 /** 804 * @} 805 */ 806 807 #ifdef __cplusplus 808 } 809 #endif 810 811 #endif /* STM32F2xx_HAL_RTC_EX_H */ 812