Rev 2 | Details | Compare with Previous | Last modification | View Log | RSS feed
| Rev | Author | Line No. | Line |
|---|---|---|---|
| 2 | mjames | 1 | /** |
| 2 | ****************************************************************************** |
||
| 3 | * @file stm32f1xx_hal_rtc_ex.c |
||
| 4 | * @author MCD Application Team |
||
| 5 | * @brief Extended RTC HAL module driver. |
||
| 9 | mjames | 6 | * This file provides firmware functions to manage the following |
| 2 | mjames | 7 | * functionalities of the Real Time Clock (RTC) Extension peripheral: |
| 9 | mjames | 8 | * + RTC Tamper functions |
| 2 | mjames | 9 | * + Extension Control functions |
| 9 | mjames | 10 | * + Extension RTC features functions |
| 11 | * |
||
| 2 | mjames | 12 | ****************************************************************************** |
| 13 | * @attention |
||
| 14 | * |
||
| 9 | mjames | 15 | * <h2><center>© Copyright (c) 2016 STMicroelectronics. |
| 16 | * All rights reserved.</center></h2> |
||
| 2 | mjames | 17 | * |
| 9 | mjames | 18 | * This software component is licensed by ST under BSD 3-Clause license, |
| 19 | * the "License"; You may not use this file except in compliance with the |
||
| 20 | * License. You may obtain a copy of the License at: |
||
| 21 | * opensource.org/licenses/BSD-3-Clause |
||
| 2 | mjames | 22 | * |
| 9 | mjames | 23 | ****************************************************************************** |
| 24 | */ |
||
| 2 | mjames | 25 | |
| 26 | /* Includes ------------------------------------------------------------------*/ |
||
| 27 | #include "stm32f1xx_hal.h" |
||
| 28 | |||
| 29 | /** @addtogroup STM32F1xx_HAL_Driver |
||
| 30 | * @{ |
||
| 31 | */ |
||
| 9 | mjames | 32 | |
| 2 | mjames | 33 | #ifdef HAL_RTC_MODULE_ENABLED |
| 34 | |||
| 35 | /** @defgroup RTCEx RTCEx |
||
| 36 | * @brief RTC Extended HAL module driver |
||
| 37 | * @{ |
||
| 38 | */ |
||
| 9 | mjames | 39 | |
| 2 | mjames | 40 | /* Private typedef -----------------------------------------------------------*/ |
| 41 | /* Private define ------------------------------------------------------------*/ |
||
| 42 | /* Private macro -------------------------------------------------------------*/ |
||
| 43 | /** @defgroup RTCEx_Private_Macros RTCEx Private Macros |
||
| 44 | * @{ |
||
| 45 | */ |
||
| 46 | /** |
||
| 47 | * @} |
||
| 48 | */ |
||
| 9 | mjames | 49 | |
| 2 | mjames | 50 | /* Private variables ---------------------------------------------------------*/ |
| 51 | /* Private function prototypes -----------------------------------------------*/ |
||
| 52 | /* Private functions ---------------------------------------------------------*/ |
||
| 53 | |||
| 54 | /** @defgroup RTCEx_Exported_Functions RTCEx Exported Functions |
||
| 55 | * @{ |
||
| 56 | */ |
||
| 9 | mjames | 57 | |
| 2 | mjames | 58 | /** @defgroup RTCEx_Exported_Functions_Group1 RTC Tamper functions |
| 59 | * @brief RTC Tamper functions |
||
| 60 | * |
||
| 9 | mjames | 61 | @verbatim |
| 2 | mjames | 62 | =============================================================================== |
| 63 | ##### RTC Tamper functions ##### |
||
| 9 | mjames | 64 | =============================================================================== |
| 65 | |||
| 2 | mjames | 66 | [..] This section provides functions allowing to configure Tamper feature |
| 67 | |||
| 68 | @endverbatim |
||
| 69 | * @{ |
||
| 70 | */ |
||
| 71 | |||
| 72 | /** |
||
| 73 | * @brief Sets Tamper |
||
| 9 | mjames | 74 | * @note By calling this API we disable the tamper interrupt for all tampers. |
| 2 | mjames | 75 | * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains |
| 76 | * the configuration information for RTC. |
||
| 77 | * @param sTamper: Pointer to Tamper Structure. |
||
| 78 | * @note Tamper can be enabled only if ASOE and CCO bit are reset |
||
| 79 | * @retval HAL status |
||
| 80 | */ |
||
| 9 | mjames | 81 | HAL_StatusTypeDef HAL_RTCEx_SetTamper(RTC_HandleTypeDef *hrtc, RTC_TamperTypeDef *sTamper) |
| 2 | mjames | 82 | { |
| 83 | /* Check input parameters */ |
||
| 9 | mjames | 84 | if ((hrtc == NULL) || (sTamper == NULL)) |
| 2 | mjames | 85 | { |
| 9 | mjames | 86 | return HAL_ERROR; |
| 2 | mjames | 87 | } |
| 9 | mjames | 88 | |
| 2 | mjames | 89 | /* Check the parameters */ |
| 90 | assert_param(IS_RTC_TAMPER(sTamper->Tamper)); |
||
| 91 | assert_param(IS_RTC_TAMPER_TRIGGER(sTamper->Trigger)); |
||
| 92 | |||
| 93 | /* Process Locked */ |
||
| 94 | __HAL_LOCK(hrtc); |
||
| 95 | |||
| 96 | hrtc->State = HAL_RTC_STATE_BUSY; |
||
| 9 | mjames | 97 | |
| 98 | if (HAL_IS_BIT_SET(BKP->RTCCR, (BKP_RTCCR_CCO | BKP_RTCCR_ASOE))) |
||
| 2 | mjames | 99 | { |
| 100 | hrtc->State = HAL_RTC_STATE_ERROR; |
||
| 9 | mjames | 101 | |
| 2 | mjames | 102 | /* Process Unlocked */ |
| 103 | __HAL_UNLOCK(hrtc); |
||
| 9 | mjames | 104 | |
| 2 | mjames | 105 | return HAL_ERROR; |
| 106 | } |
||
| 107 | |||
| 108 | MODIFY_REG(BKP->CR, (BKP_CR_TPE | BKP_CR_TPAL), (sTamper->Tamper | (sTamper->Trigger))); |
||
| 109 | |||
| 9 | mjames | 110 | hrtc->State = HAL_RTC_STATE_READY; |
| 2 | mjames | 111 | |
| 112 | /* Process Unlocked */ |
||
| 113 | __HAL_UNLOCK(hrtc); |
||
| 114 | |||
| 115 | return HAL_OK; |
||
| 116 | } |
||
| 117 | |||
| 118 | /** |
||
| 119 | * @brief Sets Tamper with interrupt. |
||
| 120 | * @note By calling this API we force the tamper interrupt for all tampers. |
||
| 121 | * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains |
||
| 122 | * the configuration information for RTC. |
||
| 123 | * @param sTamper: Pointer to RTC Tamper. |
||
| 124 | * @note Tamper can be enabled only if ASOE and CCO bit are reset |
||
| 125 | * @retval HAL status |
||
| 126 | */ |
||
| 9 | mjames | 127 | HAL_StatusTypeDef HAL_RTCEx_SetTamper_IT(RTC_HandleTypeDef *hrtc, RTC_TamperTypeDef *sTamper) |
| 2 | mjames | 128 | { |
| 129 | /* Check input parameters */ |
||
| 9 | mjames | 130 | if ((hrtc == NULL) || (sTamper == NULL)) |
| 2 | mjames | 131 | { |
| 9 | mjames | 132 | return HAL_ERROR; |
| 2 | mjames | 133 | } |
| 9 | mjames | 134 | |
| 2 | mjames | 135 | /* Check the parameters */ |
| 9 | mjames | 136 | assert_param(IS_RTC_TAMPER(sTamper->Tamper)); |
| 2 | mjames | 137 | assert_param(IS_RTC_TAMPER_TRIGGER(sTamper->Trigger)); |
| 138 | |||
| 139 | /* Process Locked */ |
||
| 140 | __HAL_LOCK(hrtc); |
||
| 141 | |||
| 142 | hrtc->State = HAL_RTC_STATE_BUSY; |
||
| 143 | |||
| 9 | mjames | 144 | if (HAL_IS_BIT_SET(BKP->RTCCR, (BKP_RTCCR_CCO | BKP_RTCCR_ASOE))) |
| 2 | mjames | 145 | { |
| 146 | hrtc->State = HAL_RTC_STATE_ERROR; |
||
| 9 | mjames | 147 | |
| 2 | mjames | 148 | /* Process Unlocked */ |
| 149 | __HAL_UNLOCK(hrtc); |
||
| 9 | mjames | 150 | |
| 2 | mjames | 151 | return HAL_ERROR; |
| 152 | } |
||
| 153 | |||
| 154 | MODIFY_REG(BKP->CR, (BKP_CR_TPE | BKP_CR_TPAL), (sTamper->Tamper | (sTamper->Trigger))); |
||
| 155 | |||
| 156 | /* Configure the Tamper Interrupt in the BKP->CSR */ |
||
| 157 | __HAL_RTC_TAMPER_ENABLE_IT(hrtc, RTC_IT_TAMP1); |
||
| 158 | |||
| 159 | hrtc->State = HAL_RTC_STATE_READY; |
||
| 160 | |||
| 161 | /* Process Unlocked */ |
||
| 162 | __HAL_UNLOCK(hrtc); |
||
| 163 | |||
| 164 | return HAL_OK; |
||
| 165 | } |
||
| 166 | |||
| 167 | /** |
||
| 168 | * @brief Deactivates Tamper. |
||
| 169 | * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains |
||
| 170 | * the configuration information for RTC. |
||
| 171 | * @param Tamper: Selected tamper pin. |
||
| 172 | * This parameter can be a value of @ref RTCEx_Tamper_Pins_Definitions |
||
| 173 | * @retval HAL status |
||
| 174 | */ |
||
| 175 | HAL_StatusTypeDef HAL_RTCEx_DeactivateTamper(RTC_HandleTypeDef *hrtc, uint32_t Tamper) |
||
| 176 | { |
||
| 177 | /* Check input parameters */ |
||
| 9 | mjames | 178 | if (hrtc == NULL) |
| 2 | mjames | 179 | { |
| 9 | mjames | 180 | return HAL_ERROR; |
| 2 | mjames | 181 | } |
| 182 | /* Prevent unused argument(s) compilation warning */ |
||
| 183 | UNUSED(Tamper); |
||
| 184 | |||
| 185 | assert_param(IS_RTC_TAMPER(Tamper)); |
||
| 186 | |||
| 187 | /* Process Locked */ |
||
| 188 | __HAL_LOCK(hrtc); |
||
| 189 | |||
| 190 | hrtc->State = HAL_RTC_STATE_BUSY; |
||
| 191 | |||
| 192 | /* Disable the selected Tamper pin */ |
||
| 193 | CLEAR_BIT(BKP->CR, BKP_CR_TPE); |
||
| 9 | mjames | 194 | |
| 2 | mjames | 195 | /* Disable the Tamper Interrupt in the BKP->CSR */ |
| 196 | /* Configure the Tamper Interrupt in the BKP->CSR */ |
||
| 197 | __HAL_RTC_TAMPER_DISABLE_IT(hrtc, RTC_IT_TAMP1); |
||
| 9 | mjames | 198 | |
| 2 | mjames | 199 | /* Clear the Tamper interrupt pending bit */ |
| 200 | __HAL_RTC_TAMPER_CLEAR_FLAG(hrtc, RTC_FLAG_TAMP1F); |
||
| 201 | SET_BIT(BKP->CSR, BKP_CSR_CTE); |
||
| 9 | mjames | 202 | |
| 2 | mjames | 203 | hrtc->State = HAL_RTC_STATE_READY; |
| 204 | |||
| 205 | /* Process Unlocked */ |
||
| 206 | __HAL_UNLOCK(hrtc); |
||
| 207 | |||
| 208 | return HAL_OK; |
||
| 209 | } |
||
| 210 | |||
| 211 | /** |
||
| 212 | * @brief This function handles Tamper interrupt request. |
||
| 213 | * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains |
||
| 214 | * the configuration information for RTC. |
||
| 215 | * @retval None |
||
| 216 | */ |
||
| 217 | void HAL_RTCEx_TamperIRQHandler(RTC_HandleTypeDef *hrtc) |
||
| 9 | mjames | 218 | { |
| 2 | mjames | 219 | /* Get the status of the Interrupt */ |
| 9 | mjames | 220 | if (__HAL_RTC_TAMPER_GET_IT_SOURCE(hrtc, RTC_IT_TAMP1)) |
| 2 | mjames | 221 | { |
| 222 | /* Get the TAMPER Interrupt enable bit and pending bit */ |
||
| 9 | mjames | 223 | if (__HAL_RTC_TAMPER_GET_FLAG(hrtc, RTC_FLAG_TAMP1F) != (uint32_t)RESET) |
| 2 | mjames | 224 | { |
| 9 | mjames | 225 | /* Tamper callback */ |
| 226 | #if (USE_HAL_RTC_REGISTER_CALLBACKS == 1) |
||
| 227 | hrtc->Tamper1EventCallback(hrtc); |
||
| 228 | #else |
||
| 2 | mjames | 229 | HAL_RTCEx_Tamper1EventCallback(hrtc); |
| 9 | mjames | 230 | #endif /* USE_HAL_RTC_REGISTER_CALLBACKS */ |
| 231 | |||
| 2 | mjames | 232 | /* Clear the Tamper interrupt pending bit */ |
| 9 | mjames | 233 | __HAL_RTC_TAMPER_CLEAR_FLAG(hrtc, RTC_FLAG_TAMP1F); |
| 2 | mjames | 234 | } |
| 235 | } |
||
| 236 | |||
| 237 | /* Change RTC state */ |
||
| 238 | hrtc->State = HAL_RTC_STATE_READY; |
||
| 239 | } |
||
| 240 | |||
| 241 | /** |
||
| 9 | mjames | 242 | * @brief Tamper 1 callback. |
| 2 | mjames | 243 | * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains |
| 244 | * the configuration information for RTC. |
||
| 245 | * @retval None |
||
| 246 | */ |
||
| 247 | __weak void HAL_RTCEx_Tamper1EventCallback(RTC_HandleTypeDef *hrtc) |
||
| 248 | { |
||
| 249 | /* Prevent unused argument(s) compilation warning */ |
||
| 250 | UNUSED(hrtc); |
||
| 251 | /* NOTE : This function Should not be modified, when the callback is needed, |
||
| 252 | the HAL_RTCEx_Tamper1EventCallback could be implemented in the user file |
||
| 253 | */ |
||
| 254 | } |
||
| 255 | |||
| 256 | /** |
||
| 257 | * @brief This function handles Tamper1 Polling. |
||
| 258 | * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains |
||
| 259 | * the configuration information for RTC. |
||
| 260 | * @param Timeout: Timeout duration |
||
| 261 | * @retval HAL status |
||
| 262 | */ |
||
| 263 | HAL_StatusTypeDef HAL_RTCEx_PollForTamper1Event(RTC_HandleTypeDef *hrtc, uint32_t Timeout) |
||
| 9 | mjames | 264 | { |
| 2 | mjames | 265 | uint32_t tickstart = HAL_GetTick(); |
| 266 | |||
| 267 | /* Check input parameters */ |
||
| 9 | mjames | 268 | if (hrtc == NULL) |
| 2 | mjames | 269 | { |
| 9 | mjames | 270 | return HAL_ERROR; |
| 2 | mjames | 271 | } |
| 9 | mjames | 272 | |
| 2 | mjames | 273 | /* Get the status of the Interrupt */ |
| 9 | mjames | 274 | while (__HAL_RTC_TAMPER_GET_FLAG(hrtc, RTC_FLAG_TAMP1F) == RESET) |
| 2 | mjames | 275 | { |
| 9 | mjames | 276 | if (Timeout != HAL_MAX_DELAY) |
| 2 | mjames | 277 | { |
| 9 | mjames | 278 | if ((Timeout == 0U) || ((HAL_GetTick() - tickstart) > Timeout)) |
| 2 | mjames | 279 | { |
| 280 | hrtc->State = HAL_RTC_STATE_TIMEOUT; |
||
| 281 | return HAL_TIMEOUT; |
||
| 282 | } |
||
| 283 | } |
||
| 284 | } |
||
| 285 | |||
| 286 | /* Clear the Tamper Flag */ |
||
| 9 | mjames | 287 | __HAL_RTC_TAMPER_CLEAR_FLAG(hrtc, RTC_FLAG_TAMP1F); |
| 2 | mjames | 288 | |
| 289 | /* Change RTC state */ |
||
| 290 | hrtc->State = HAL_RTC_STATE_READY; |
||
| 291 | |||
| 292 | return HAL_OK; |
||
| 293 | } |
||
| 294 | |||
| 295 | /** |
||
| 296 | * @} |
||
| 297 | */ |
||
| 9 | mjames | 298 | |
| 2 | mjames | 299 | /** @defgroup RTCEx_Exported_Functions_Group2 RTC Second functions |
| 300 | * @brief RTC Second functions |
||
| 301 | * |
||
| 9 | mjames | 302 | @verbatim |
| 2 | mjames | 303 | =============================================================================== |
| 304 | ##### RTC Second functions ##### |
||
| 9 | mjames | 305 | =============================================================================== |
| 306 | |||
| 2 | mjames | 307 | [..] This section provides functions implementing second interupt handlers |
| 308 | |||
| 309 | @endverbatim |
||
| 310 | * @{ |
||
| 311 | */ |
||
| 312 | |||
| 313 | /** |
||
| 314 | * @brief Sets Interrupt for second |
||
| 315 | * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains |
||
| 316 | * the configuration information for RTC. |
||
| 317 | * @retval HAL status |
||
| 318 | */ |
||
| 319 | HAL_StatusTypeDef HAL_RTCEx_SetSecond_IT(RTC_HandleTypeDef *hrtc) |
||
| 320 | { |
||
| 321 | /* Check input parameters */ |
||
| 9 | mjames | 322 | if (hrtc == NULL) |
| 2 | mjames | 323 | { |
| 9 | mjames | 324 | return HAL_ERROR; |
| 2 | mjames | 325 | } |
| 9 | mjames | 326 | |
| 2 | mjames | 327 | /* Process Locked */ |
| 328 | __HAL_LOCK(hrtc); |
||
| 329 | |||
| 330 | hrtc->State = HAL_RTC_STATE_BUSY; |
||
| 331 | |||
| 332 | /* Enable Second interuption */ |
||
| 333 | __HAL_RTC_SECOND_ENABLE_IT(hrtc, RTC_IT_SEC); |
||
| 9 | mjames | 334 | |
| 2 | mjames | 335 | hrtc->State = HAL_RTC_STATE_READY; |
| 336 | |||
| 337 | /* Process Unlocked */ |
||
| 338 | __HAL_UNLOCK(hrtc); |
||
| 339 | |||
| 340 | return HAL_OK; |
||
| 341 | } |
||
| 342 | |||
| 343 | /** |
||
| 344 | * @brief Deactivates Second. |
||
| 345 | * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains |
||
| 346 | * the configuration information for RTC. |
||
| 347 | * @retval HAL status |
||
| 348 | */ |
||
| 349 | HAL_StatusTypeDef HAL_RTCEx_DeactivateSecond(RTC_HandleTypeDef *hrtc) |
||
| 350 | { |
||
| 351 | /* Check input parameters */ |
||
| 9 | mjames | 352 | if (hrtc == NULL) |
| 2 | mjames | 353 | { |
| 9 | mjames | 354 | return HAL_ERROR; |
| 2 | mjames | 355 | } |
| 9 | mjames | 356 | |
| 2 | mjames | 357 | /* Process Locked */ |
| 358 | __HAL_LOCK(hrtc); |
||
| 359 | |||
| 360 | hrtc->State = HAL_RTC_STATE_BUSY; |
||
| 361 | |||
| 9 | mjames | 362 | /* Deactivate Second interuption*/ |
| 2 | mjames | 363 | __HAL_RTC_SECOND_DISABLE_IT(hrtc, RTC_IT_SEC); |
| 9 | mjames | 364 | |
| 2 | mjames | 365 | hrtc->State = HAL_RTC_STATE_READY; |
| 366 | |||
| 367 | /* Process Unlocked */ |
||
| 368 | __HAL_UNLOCK(hrtc); |
||
| 369 | |||
| 370 | return HAL_OK; |
||
| 371 | } |
||
| 372 | |||
| 373 | /** |
||
| 374 | * @brief This function handles second interrupt request. |
||
| 375 | * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains |
||
| 376 | * the configuration information for RTC. |
||
| 377 | * @retval None |
||
| 378 | */ |
||
| 9 | mjames | 379 | void HAL_RTCEx_RTCIRQHandler(RTC_HandleTypeDef *hrtc) |
| 2 | mjames | 380 | { |
| 9 | mjames | 381 | if (__HAL_RTC_SECOND_GET_IT_SOURCE(hrtc, RTC_IT_SEC)) |
| 2 | mjames | 382 | { |
| 383 | /* Get the status of the Interrupt */ |
||
| 9 | mjames | 384 | if (__HAL_RTC_SECOND_GET_FLAG(hrtc, RTC_FLAG_SEC)) |
| 2 | mjames | 385 | { |
| 386 | /* Check if Overrun occurred */ |
||
| 387 | if (__HAL_RTC_SECOND_GET_FLAG(hrtc, RTC_FLAG_OW)) |
||
| 388 | { |
||
| 9 | mjames | 389 | /* Second error callback */ |
| 2 | mjames | 390 | HAL_RTCEx_RTCEventErrorCallback(hrtc); |
| 9 | mjames | 391 | |
| 2 | mjames | 392 | /* Clear flag Second */ |
| 393 | __HAL_RTC_OVERFLOW_CLEAR_FLAG(hrtc, RTC_FLAG_OW); |
||
| 9 | mjames | 394 | |
| 2 | mjames | 395 | /* Change RTC state */ |
| 9 | mjames | 396 | hrtc->State = HAL_RTC_STATE_ERROR; |
| 2 | mjames | 397 | } |
| 9 | mjames | 398 | else |
| 2 | mjames | 399 | { |
| 9 | mjames | 400 | /* Second callback */ |
| 2 | mjames | 401 | HAL_RTCEx_RTCEventCallback(hrtc); |
| 9 | mjames | 402 | |
| 2 | mjames | 403 | /* Change RTC state */ |
| 9 | mjames | 404 | hrtc->State = HAL_RTC_STATE_READY; |
| 2 | mjames | 405 | } |
| 9 | mjames | 406 | |
| 2 | mjames | 407 | /* Clear flag Second */ |
| 408 | __HAL_RTC_SECOND_CLEAR_FLAG(hrtc, RTC_FLAG_SEC); |
||
| 409 | } |
||
| 410 | } |
||
| 411 | } |
||
| 412 | |||
| 413 | /** |
||
| 414 | * @brief Second event callback. |
||
| 415 | * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains |
||
| 416 | * the configuration information for RTC. |
||
| 417 | * @retval None |
||
| 418 | */ |
||
| 419 | __weak void HAL_RTCEx_RTCEventCallback(RTC_HandleTypeDef *hrtc) |
||
| 420 | { |
||
| 421 | /* Prevent unused argument(s) compilation warning */ |
||
| 422 | UNUSED(hrtc); |
||
| 423 | /* NOTE : This function Should not be modified, when the callback is needed, |
||
| 424 | the HAL_RTCEx_RTCEventCallback could be implemented in the user file |
||
| 425 | */ |
||
| 426 | } |
||
| 427 | |||
| 428 | /** |
||
| 429 | * @brief Second event error callback. |
||
| 430 | * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains |
||
| 431 | * the configuration information for RTC. |
||
| 432 | * @retval None |
||
| 433 | */ |
||
| 434 | __weak void HAL_RTCEx_RTCEventErrorCallback(RTC_HandleTypeDef *hrtc) |
||
| 435 | { |
||
| 436 | /* Prevent unused argument(s) compilation warning */ |
||
| 437 | UNUSED(hrtc); |
||
| 438 | /* NOTE : This function Should not be modified, when the callback is needed, |
||
| 439 | the HAL_RTCEx_RTCEventErrorCallback could be implemented in the user file |
||
| 440 | */ |
||
| 441 | } |
||
| 442 | |||
| 443 | /** |
||
| 444 | * @} |
||
| 445 | */ |
||
| 9 | mjames | 446 | |
| 2 | mjames | 447 | /** @defgroup RTCEx_Exported_Functions_Group3 Extended Peripheral Control functions |
| 448 | * @brief Extended Peripheral Control functions |
||
| 449 | * |
||
| 9 | mjames | 450 | @verbatim |
| 2 | mjames | 451 | =============================================================================== |
| 452 | ##### Extension Peripheral Control functions ##### |
||
| 9 | mjames | 453 | =============================================================================== |
| 2 | mjames | 454 | [..] |
| 455 | This subsection provides functions allowing to |
||
| 456 | (+) Writes a data in a specified RTC Backup data register |
||
| 457 | (+) Read a data in a specified RTC Backup data register |
||
| 458 | (+) Sets the Smooth calibration parameters. |
||
| 459 | |||
| 460 | @endverbatim |
||
| 461 | * @{ |
||
| 462 | */ |
||
| 463 | |||
| 464 | /** |
||
| 465 | * @brief Writes a data in a specified RTC Backup data register. |
||
| 466 | * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains |
||
| 9 | mjames | 467 | * the configuration information for RTC. |
| 2 | mjames | 468 | * @param BackupRegister: RTC Backup data Register number. |
| 9 | mjames | 469 | * This parameter can be: RTC_BKP_DRx where x can be from 1 to 10 (or 42) to |
| 2 | mjames | 470 | * specify the register (depending devices). |
| 9 | mjames | 471 | * @param Data: Data to be written in the specified RTC Backup data register. |
| 2 | mjames | 472 | * @retval None |
| 473 | */ |
||
| 474 | void HAL_RTCEx_BKUPWrite(RTC_HandleTypeDef *hrtc, uint32_t BackupRegister, uint32_t Data) |
||
| 475 | { |
||
| 476 | uint32_t tmp = 0U; |
||
| 477 | |||
| 478 | /* Prevent unused argument(s) compilation warning */ |
||
| 479 | UNUSED(hrtc); |
||
| 480 | |||
| 481 | /* Check the parameters */ |
||
| 482 | assert_param(IS_RTC_BKP(BackupRegister)); |
||
| 9 | mjames | 483 | |
| 484 | tmp = (uint32_t)BKP_BASE; |
||
| 2 | mjames | 485 | tmp += (BackupRegister * 4U); |
| 486 | |||
| 487 | *(__IO uint32_t *) tmp = (Data & BKP_DR1_D); |
||
| 488 | } |
||
| 489 | |||
| 490 | /** |
||
| 491 | * @brief Reads data from the specified RTC Backup data Register. |
||
| 492 | * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains |
||
| 9 | mjames | 493 | * the configuration information for RTC. |
| 2 | mjames | 494 | * @param BackupRegister: RTC Backup data Register number. |
| 9 | mjames | 495 | * This parameter can be: RTC_BKP_DRx where x can be from 1 to 10 (or 42) to |
| 2 | mjames | 496 | * specify the register (depending devices). |
| 497 | * @retval Read value |
||
| 498 | */ |
||
| 499 | uint32_t HAL_RTCEx_BKUPRead(RTC_HandleTypeDef *hrtc, uint32_t BackupRegister) |
||
| 500 | { |
||
| 501 | uint32_t backupregister = 0U; |
||
| 502 | uint32_t pvalue = 0U; |
||
| 503 | |||
| 504 | /* Prevent unused argument(s) compilation warning */ |
||
| 505 | UNUSED(hrtc); |
||
| 506 | |||
| 507 | /* Check the parameters */ |
||
| 508 | assert_param(IS_RTC_BKP(BackupRegister)); |
||
| 509 | |||
| 9 | mjames | 510 | backupregister = (uint32_t)BKP_BASE; |
| 2 | mjames | 511 | backupregister += (BackupRegister * 4U); |
| 9 | mjames | 512 | |
| 2 | mjames | 513 | pvalue = (*(__IO uint32_t *)(backupregister)) & BKP_DR1_D; |
| 514 | |||
| 515 | /* Read the specified register */ |
||
| 516 | return pvalue; |
||
| 517 | } |
||
| 518 | |||
| 519 | |||
| 520 | /** |
||
| 521 | * @brief Sets the Smooth calibration parameters. |
||
| 9 | mjames | 522 | * @param hrtc: RTC handle |
| 2 | mjames | 523 | * @param SmoothCalibPeriod: Not used (only present for compatibility with another families) |
| 524 | * @param SmoothCalibPlusPulses: Not used (only present for compatibility with another families) |
||
| 525 | * @param SmouthCalibMinusPulsesValue: specifies the RTC Clock Calibration value. |
||
| 526 | * This parameter must be a number between 0 and 0x7F. |
||
| 527 | * @retval HAL status |
||
| 528 | */ |
||
| 9 | mjames | 529 | HAL_StatusTypeDef HAL_RTCEx_SetSmoothCalib(RTC_HandleTypeDef *hrtc, uint32_t SmoothCalibPeriod, uint32_t SmoothCalibPlusPulses, uint32_t SmouthCalibMinusPulsesValue) |
| 2 | mjames | 530 | { |
| 531 | /* Check input parameters */ |
||
| 9 | mjames | 532 | if (hrtc == NULL) |
| 2 | mjames | 533 | { |
| 9 | mjames | 534 | return HAL_ERROR; |
| 2 | mjames | 535 | } |
| 536 | /* Prevent unused argument(s) compilation warning */ |
||
| 537 | UNUSED(SmoothCalibPeriod); |
||
| 538 | UNUSED(SmoothCalibPlusPulses); |
||
| 539 | |||
| 540 | /* Check the parameters */ |
||
| 541 | assert_param(IS_RTC_SMOOTH_CALIB_MINUS(SmouthCalibMinusPulsesValue)); |
||
| 9 | mjames | 542 | |
| 2 | mjames | 543 | /* Process Locked */ |
| 544 | __HAL_LOCK(hrtc); |
||
| 545 | |||
| 546 | hrtc->State = HAL_RTC_STATE_BUSY; |
||
| 547 | |||
| 548 | /* Sets RTC Clock Calibration value.*/ |
||
| 549 | MODIFY_REG(BKP->RTCCR, BKP_RTCCR_CAL, SmouthCalibMinusPulsesValue); |
||
| 550 | |||
| 551 | /* Change RTC state */ |
||
| 552 | hrtc->State = HAL_RTC_STATE_READY; |
||
| 553 | |||
| 554 | /* Process Unlocked */ |
||
| 555 | __HAL_UNLOCK(hrtc); |
||
| 556 | |||
| 557 | return HAL_OK; |
||
| 558 | } |
||
| 559 | |||
| 560 | /** |
||
| 561 | * @} |
||
| 562 | */ |
||
| 563 | |||
| 564 | /** |
||
| 565 | * @} |
||
| 566 | */ |
||
| 9 | mjames | 567 | |
| 2 | mjames | 568 | /** |
| 569 | * @} |
||
| 570 | */ |
||
| 571 | |||
| 572 | #endif /* HAL_RTC_MODULE_ENABLED */ |
||
| 573 | |||
| 574 | /** |
||
| 575 | * @} |
||
| 576 | */ |
||
| 577 | |||
| 578 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ |
||
| 579 |