1 /** 2 ****************************************************************************** 3 * @file stm32f1xx_hal_rtc_ex.h 4 * @author MCD Application Team 5 * @brief Header file of RTC HAL Extension module. 6 ****************************************************************************** 7 * @attention 8 * 9 * <h2><center>© Copyright (c) 2016 STMicroelectronics. 10 * All rights reserved.</center></h2> 11 * 12 * This software component is licensed by ST under BSD 3-Clause license, 13 * the "License"; You may not use this file except in compliance with the 14 * License. You may obtain a copy of the License at: 15 * opensource.org/licenses/BSD-3-Clause 16 * 17 ****************************************************************************** 18 */ 19 20 /* Define to prevent recursive inclusion -------------------------------------*/ 21 #ifndef __STM32F1xx_HAL_RTC_EX_H 22 #define __STM32F1xx_HAL_RTC_EX_H 23 24 #ifdef __cplusplus 25 extern "C" { 26 #endif 27 28 /* Includes ------------------------------------------------------------------*/ 29 #include "stm32f1xx_hal_def.h" 30 31 /** @addtogroup STM32F1xx_HAL_Driver 32 * @{ 33 */ 34 35 /** @addtogroup RTCEx 36 * @{ 37 */ 38 39 /** @addtogroup RTCEx_Private_Macros 40 * @{ 41 */ 42 43 /** @defgroup RTCEx_Alias_For_Legacy Alias define maintained for legacy 44 * @{ 45 */ 46 #define HAL_RTCEx_TamperTimeStampIRQHandler HAL_RTCEx_TamperIRQHandler 47 48 /** 49 * @} 50 */ 51 52 /** @defgroup RTCEx_IS_RTC_Definitions Private macros to check input parameters 53 * @{ 54 */ 55 #define IS_RTC_TAMPER(__TAMPER__) ((__TAMPER__) == RTC_TAMPER_1) 56 57 #define IS_RTC_TAMPER_TRIGGER(__TRIGGER__) (((__TRIGGER__) == RTC_TAMPERTRIGGER_LOWLEVEL) || \ 58 ((__TRIGGER__) == RTC_TAMPERTRIGGER_HIGHLEVEL)) 59 60 #if RTC_BKP_NUMBER > 10U 61 #define IS_RTC_BKP(BKP) (((BKP) <= (uint32_t)RTC_BKP_DR10) || (((BKP) >= (uint32_t)RTC_BKP_DR11) && ((BKP) <= (uint32_t)RTC_BKP_DR42))) 62 #else 63 #define IS_RTC_BKP(BKP) ((BKP) <= (uint32_t)RTC_BKP_NUMBER) 64 #endif 65 #define IS_RTC_SMOOTH_CALIB_MINUS(__VALUE__) ((__VALUE__) <= 0x0000007FU) 66 67 /** 68 * @} 69 */ 70 71 /** 72 * @} 73 */ 74 75 /* Exported types ------------------------------------------------------------*/ 76 /** @defgroup RTCEx_Exported_Types RTCEx Exported Types 77 * @{ 78 */ 79 /** 80 * @brief RTC Tamper structure definition 81 */ 82 typedef struct 83 { 84 uint32_t Tamper; /*!< Specifies the Tamper Pin. 85 This parameter can be a value of @ref RTCEx_Tamper_Pins_Definitions */ 86 87 uint32_t Trigger; /*!< Specifies the Tamper Trigger. 88 This parameter can be a value of @ref RTCEx_Tamper_Trigger_Definitions */ 89 90 } RTC_TamperTypeDef; 91 92 /** 93 * @} 94 */ 95 96 /* Exported constants --------------------------------------------------------*/ 97 /** @defgroup RTCEx_Exported_Constants RTCEx Exported Constants 98 * @{ 99 */ 100 101 /** @defgroup RTCEx_Tamper_Pins_Definitions Tamper Pins Definitions 102 * @{ 103 */ 104 #define RTC_TAMPER_1 BKP_CR_TPE /*!< Select tamper to be enabled (mainly for legacy purposes) */ 105 106 /** 107 * @} 108 */ 109 110 /** @defgroup RTCEx_Tamper_Trigger_Definitions Tamper Trigger Definitions 111 * @{ 112 */ 113 #define RTC_TAMPERTRIGGER_LOWLEVEL BKP_CR_TPAL /*!< A high level on the TAMPER pin resets all data backup registers (if TPE bit is set) */ 114 #define RTC_TAMPERTRIGGER_HIGHLEVEL 0x00000000U /*!< A low level on the TAMPER pin resets all data backup registers (if TPE bit is set) */ 115 116 /** 117 * @} 118 */ 119 120 /** @defgroup RTCEx_Backup_Registers_Definitions Backup Registers Definitions 121 * @{ 122 */ 123 #if RTC_BKP_NUMBER > 0U 124 #define RTC_BKP_DR1 0x00000001U 125 #define RTC_BKP_DR2 0x00000002U 126 #define RTC_BKP_DR3 0x00000003U 127 #define RTC_BKP_DR4 0x00000004U 128 #define RTC_BKP_DR5 0x00000005U 129 #define RTC_BKP_DR6 0x00000006U 130 #define RTC_BKP_DR7 0x00000007U 131 #define RTC_BKP_DR8 0x00000008U 132 #define RTC_BKP_DR9 0x00000009U 133 #define RTC_BKP_DR10 0x0000000AU 134 #endif /* RTC_BKP_NUMBER > 0 */ 135 136 #if RTC_BKP_NUMBER > 10U 137 #define RTC_BKP_DR11 0x00000010U 138 #define RTC_BKP_DR12 0x00000011U 139 #define RTC_BKP_DR13 0x00000012U 140 #define RTC_BKP_DR14 0x00000013U 141 #define RTC_BKP_DR15 0x00000014U 142 #define RTC_BKP_DR16 0x00000015U 143 #define RTC_BKP_DR17 0x00000016U 144 #define RTC_BKP_DR18 0x00000017U 145 #define RTC_BKP_DR19 0x00000018U 146 #define RTC_BKP_DR20 0x00000019U 147 #define RTC_BKP_DR21 0x0000001AU 148 #define RTC_BKP_DR22 0x0000001BU 149 #define RTC_BKP_DR23 0x0000001CU 150 #define RTC_BKP_DR24 0x0000001DU 151 #define RTC_BKP_DR25 0x0000001EU 152 #define RTC_BKP_DR26 0x0000001FU 153 #define RTC_BKP_DR27 0x00000020U 154 #define RTC_BKP_DR28 0x00000021U 155 #define RTC_BKP_DR29 0x00000022U 156 #define RTC_BKP_DR30 0x00000023U 157 #define RTC_BKP_DR31 0x00000024U 158 #define RTC_BKP_DR32 0x00000025U 159 #define RTC_BKP_DR33 0x00000026U 160 #define RTC_BKP_DR34 0x00000027U 161 #define RTC_BKP_DR35 0x00000028U 162 #define RTC_BKP_DR36 0x00000029U 163 #define RTC_BKP_DR37 0x0000002AU 164 #define RTC_BKP_DR38 0x0000002BU 165 #define RTC_BKP_DR39 0x0000002CU 166 #define RTC_BKP_DR40 0x0000002DU 167 #define RTC_BKP_DR41 0x0000002EU 168 #define RTC_BKP_DR42 0x0000002FU 169 #endif /* RTC_BKP_NUMBER > 10 */ 170 171 /** 172 * @} 173 */ 174 175 /** 176 * @} 177 */ 178 179 /* Exported macro ------------------------------------------------------------*/ 180 /** @defgroup RTCEx_Exported_Macros RTCEx Exported Macros 181 * @{ 182 */ 183 184 /** 185 * @brief Enable the RTC Tamper interrupt. 186 * @param __HANDLE__: specifies the RTC handle. 187 * @param __INTERRUPT__: specifies the RTC Tamper interrupt sources to be enabled 188 * This parameter can be any combination of the following values: 189 * @arg RTC_IT_TAMP1: Tamper A interrupt 190 * @retval None 191 */ 192 #define __HAL_RTC_TAMPER_ENABLE_IT(__HANDLE__, __INTERRUPT__) SET_BIT(BKP->CSR, (__INTERRUPT__)) 193 194 /** 195 * @brief Disable the RTC Tamper interrupt. 196 * @param __HANDLE__: specifies the RTC handle. 197 * @param __INTERRUPT__: specifies the RTC Tamper interrupt sources to be disabled. 198 * This parameter can be any combination of the following values: 199 * @arg RTC_IT_TAMP1: Tamper A interrupt 200 * @retval None 201 */ 202 #define __HAL_RTC_TAMPER_DISABLE_IT(__HANDLE__, __INTERRUPT__) CLEAR_BIT(BKP->CSR, (__INTERRUPT__)) 203 204 /** 205 * @brief Check whether the specified RTC Tamper interrupt has been enabled or not. 206 * @param __HANDLE__: specifies the RTC handle. 207 * @param __INTERRUPT__: specifies the RTC Tamper interrupt sources to be checked. 208 * This parameter can be: 209 * @arg RTC_IT_TAMP1 210 * @retval None 211 */ 212 #define __HAL_RTC_TAMPER_GET_IT_SOURCE(__HANDLE__, __INTERRUPT__) ((((BKP->CSR) & ((__INTERRUPT__))) != RESET)? SET : RESET) 213 214 /** 215 * @brief Get the selected RTC Tamper's flag status. 216 * @param __HANDLE__: specifies the RTC handle. 217 * @param __FLAG__: specifies the RTC Tamper Flag sources to be enabled or disabled. 218 * This parameter can be: 219 * @arg RTC_FLAG_TAMP1F 220 * @retval None 221 */ 222 #define __HAL_RTC_TAMPER_GET_FLAG(__HANDLE__, __FLAG__) ((((BKP->CSR) & (__FLAG__)) != RESET)? SET : RESET) 223 224 /** 225 * @brief Get the selected RTC Tamper's flag status. 226 * @param __HANDLE__: specifies the RTC handle. 227 * @param __INTERRUPT__: specifies the RTC Tamper interrupt sources to be checked. 228 * This parameter can be: 229 * @arg RTC_IT_TAMP1 230 * @retval None 231 */ 232 #define __HAL_RTC_TAMPER_GET_IT(__HANDLE__, __INTERRUPT__) ((((BKP->CSR) & (BKP_CSR_TEF)) != RESET)? SET : RESET) 233 234 /** 235 * @brief Clear the RTC Tamper's pending flags. 236 * @param __HANDLE__: specifies the RTC handle. 237 * @param __FLAG__: specifies the RTC Tamper Flag sources to be enabled or disabled. 238 * This parameter can be: 239 * @arg RTC_FLAG_TAMP1F 240 * @retval None 241 */ 242 #define __HAL_RTC_TAMPER_CLEAR_FLAG(__HANDLE__, __FLAG__) SET_BIT(BKP->CSR, BKP_CSR_CTE | BKP_CSR_CTI) 243 244 /** 245 * @brief Enable the RTC Second interrupt. 246 * @param __HANDLE__: specifies the RTC handle. 247 * @param __INTERRUPT__: specifies the RTC Second interrupt sources to be enabled 248 * This parameter can be any combination of the following values: 249 * @arg RTC_IT_SEC: Second A interrupt 250 * @retval None 251 */ 252 #define __HAL_RTC_SECOND_ENABLE_IT(__HANDLE__, __INTERRUPT__) SET_BIT((__HANDLE__)->Instance->CRH, (__INTERRUPT__)) 253 254 /** 255 * @brief Disable the RTC Second interrupt. 256 * @param __HANDLE__: specifies the RTC handle. 257 * @param __INTERRUPT__: specifies the RTC Second interrupt sources to be disabled. 258 * This parameter can be any combination of the following values: 259 * @arg RTC_IT_SEC: Second A interrupt 260 * @retval None 261 */ 262 #define __HAL_RTC_SECOND_DISABLE_IT(__HANDLE__, __INTERRUPT__) CLEAR_BIT((__HANDLE__)->Instance->CRH, (__INTERRUPT__)) 263 264 /** 265 * @brief Check whether the specified RTC Second interrupt has occurred or not. 266 * @param __HANDLE__: specifies the RTC handle. 267 * @param __INTERRUPT__: specifies the RTC Second interrupt sources to be enabled or disabled. 268 * This parameter can be: 269 * @arg RTC_IT_SEC: Second A interrupt 270 * @retval None 271 */ 272 #define __HAL_RTC_SECOND_GET_IT_SOURCE(__HANDLE__, __INTERRUPT__) ((((((__HANDLE__)->Instance->CRH)& ((__INTERRUPT__)))) != RESET)? SET : RESET) 273 274 /** 275 * @brief Get the selected RTC Second's flag status. 276 * @param __HANDLE__: specifies the RTC handle. 277 * @param __FLAG__: specifies the RTC Second Flag sources to be enabled or disabled. 278 * This parameter can be: 279 * @arg RTC_FLAG_SEC 280 * @retval None 281 */ 282 #define __HAL_RTC_SECOND_GET_FLAG(__HANDLE__, __FLAG__) (((((__HANDLE__)->Instance->CRL) & (__FLAG__)) != RESET)? SET : RESET) 283 284 /** 285 * @brief Clear the RTC Second's pending flags. 286 * @param __HANDLE__: specifies the RTC handle. 287 * @param __FLAG__: specifies the RTC Second Flag sources to be enabled or disabled. 288 * This parameter can be: 289 * @arg RTC_FLAG_SEC 290 * @retval None 291 */ 292 #define __HAL_RTC_SECOND_CLEAR_FLAG(__HANDLE__, __FLAG__) ((__HANDLE__)->Instance->CRL) &= ~(__FLAG__) 293 294 /** 295 * @brief Enable the RTC Overflow interrupt. 296 * @param __HANDLE__: specifies the RTC handle. 297 * @param __INTERRUPT__: specifies the RTC Overflow interrupt sources to be enabled 298 * This parameter can be any combination of the following values: 299 * @arg RTC_IT_OW: Overflow A interrupt 300 * @retval None 301 */ 302 #define __HAL_RTC_OVERFLOW_ENABLE_IT(__HANDLE__, __INTERRUPT__) SET_BIT((__HANDLE__)->Instance->CRH, (__INTERRUPT__)) 303 304 /** 305 * @brief Disable the RTC Overflow interrupt. 306 * @param __HANDLE__: specifies the RTC handle. 307 * @param __INTERRUPT__: specifies the RTC Overflow interrupt sources to be disabled. 308 * This parameter can be any combination of the following values: 309 * @arg RTC_IT_OW: Overflow A interrupt 310 * @retval None 311 */ 312 #define __HAL_RTC_OVERFLOW_DISABLE_IT(__HANDLE__, __INTERRUPT__) CLEAR_BIT((__HANDLE__)->Instance->CRH, (__INTERRUPT__)) 313 314 /** 315 * @brief Check whether the specified RTC Overflow interrupt has occurred or not. 316 * @param __HANDLE__: specifies the RTC handle. 317 * @param __INTERRUPT__: specifies the RTC Overflow interrupt sources to be enabled or disabled. 318 * This parameter can be: 319 * @arg RTC_IT_OW: Overflow A interrupt 320 * @retval None 321 */ 322 #define __HAL_RTC_OVERFLOW_GET_IT_SOURCE(__HANDLE__, __INTERRUPT__) ((((((__HANDLE__)->Instance->CRH)& ((__INTERRUPT__))) ) != RESET)? SET : RESET) 323 324 /** 325 * @brief Get the selected RTC Overflow's flag status. 326 * @param __HANDLE__: specifies the RTC handle. 327 * @param __FLAG__: specifies the RTC Overflow Flag sources to be enabled or disabled. 328 * This parameter can be: 329 * @arg RTC_FLAG_OW 330 * @retval None 331 */ 332 #define __HAL_RTC_OVERFLOW_GET_FLAG(__HANDLE__, __FLAG__) (((((__HANDLE__)->Instance->CRL) & (__FLAG__)) != RESET)? SET : RESET) 333 334 /** 335 * @brief Clear the RTC Overflow's pending flags. 336 * @param __HANDLE__: specifies the RTC handle. 337 * @param __FLAG__: specifies the RTC Overflow Flag sources to be enabled or disabled. 338 * This parameter can be: 339 * @arg RTC_FLAG_OW 340 * @retval None 341 */ 342 #define __HAL_RTC_OVERFLOW_CLEAR_FLAG(__HANDLE__, __FLAG__) ((__HANDLE__)->Instance->CRL) = ~(__FLAG__) 343 344 /** 345 * @} 346 */ 347 348 /* Exported functions --------------------------------------------------------*/ 349 /** @addtogroup RTCEx_Exported_Functions 350 * @{ 351 */ 352 353 /* RTC Tamper functions *****************************************/ 354 /** @addtogroup RTCEx_Exported_Functions_Group1 355 * @{ 356 */ 357 HAL_StatusTypeDef HAL_RTCEx_SetTamper(RTC_HandleTypeDef *hrtc, RTC_TamperTypeDef *sTamper); 358 HAL_StatusTypeDef HAL_RTCEx_SetTamper_IT(RTC_HandleTypeDef *hrtc, RTC_TamperTypeDef *sTamper); 359 HAL_StatusTypeDef HAL_RTCEx_DeactivateTamper(RTC_HandleTypeDef *hrtc, uint32_t Tamper); 360 void HAL_RTCEx_TamperIRQHandler(RTC_HandleTypeDef *hrtc); 361 void HAL_RTCEx_Tamper1EventCallback(RTC_HandleTypeDef *hrtc); 362 HAL_StatusTypeDef HAL_RTCEx_PollForTamper1Event(RTC_HandleTypeDef *hrtc, uint32_t Timeout); 363 364 /** 365 * @} 366 */ 367 368 /* RTC Second functions *****************************************/ 369 /** @addtogroup RTCEx_Exported_Functions_Group2 370 * @{ 371 */ 372 HAL_StatusTypeDef HAL_RTCEx_SetSecond_IT(RTC_HandleTypeDef *hrtc); 373 HAL_StatusTypeDef HAL_RTCEx_DeactivateSecond(RTC_HandleTypeDef *hrtc); 374 void HAL_RTCEx_RTCIRQHandler(RTC_HandleTypeDef *hrtc); 375 void HAL_RTCEx_RTCEventCallback(RTC_HandleTypeDef *hrtc); 376 void HAL_RTCEx_RTCEventErrorCallback(RTC_HandleTypeDef *hrtc); 377 378 /** 379 * @} 380 */ 381 382 /* Extension Control functions ************************************************/ 383 /** @addtogroup RTCEx_Exported_Functions_Group3 384 * @{ 385 */ 386 void HAL_RTCEx_BKUPWrite(RTC_HandleTypeDef *hrtc, uint32_t BackupRegister, uint32_t Data); 387 uint32_t HAL_RTCEx_BKUPRead(RTC_HandleTypeDef *hrtc, uint32_t BackupRegister); 388 389 HAL_StatusTypeDef HAL_RTCEx_SetSmoothCalib(RTC_HandleTypeDef *hrtc, uint32_t SmoothCalibPeriod, uint32_t SmoothCalibPlusPulses, uint32_t SmouthCalibMinusPulsesValue); 390 /** 391 * @} 392 */ 393 394 /** 395 * @} 396 */ 397 398 /** 399 * @} 400 */ 401 402 /** 403 * @} 404 */ 405 406 #ifdef __cplusplus 407 } 408 #endif 409 410 #endif /* __STM32F1xx_HAL_RTC_EX_H */ 411 412 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 413