STM32H735xx HAL User Manual
|
00001 /** 00002 ****************************************************************************** 00003 * @file stm32h7xx_hal_rtc_ex.c 00004 * @author MCD Application Team 00005 * @brief Extended RTC HAL module driver. 00006 * This file provides firmware functions to manage the following 00007 * functionalities of the Real Time Clock (RTC) Extended peripheral: 00008 * + RTC Time Stamp functions 00009 * + RTC Tamper functions 00010 * + RTC Wake-up functions 00011 * + Extended Control functions 00012 * + Extended RTC features functions 00013 * 00014 ****************************************************************************** 00015 * @attention 00016 * 00017 * Copyright (c) 2017 STMicroelectronics. 00018 * All rights reserved. 00019 * 00020 * This software is licensed under terms that can be found in the LICENSE file 00021 * in the root directory of this software component. 00022 * If no LICENSE file comes with this software, it is provided AS-IS. 00023 * 00024 ****************************************************************************** 00025 @verbatim 00026 ============================================================================== 00027 ##### How to use this driver ##### 00028 ============================================================================== 00029 [..] 00030 (+) Enable the RTC domain access. 00031 (+) Configure the RTC Prescaler (Asynchronous and Synchronous) and RTC hour 00032 format using the HAL_RTC_Init() function. 00033 00034 *** RTC Wakeup configuration *** 00035 ================================ 00036 [..] 00037 (+) To configure the RTC Wakeup Clock source and Counter use the HAL_RTCEx_SetWakeUpTimer() 00038 function. You can also configure the RTC Wakeup timer with interrupt mode 00039 using the HAL_RTCEx_SetWakeUpTimer_IT() function. 00040 (+) To read the RTC WakeUp Counter register, use the HAL_RTCEx_GetWakeUpTimer() 00041 function. 00042 00043 *** Outputs configuration *** 00044 ============================= 00045 [..] The RTC has 2 different outputs: 00046 (+) RTC_ALARM: this output is used to manage the RTC Alarm A, Alarm B 00047 and WaKeUp signals. 00048 To output the selected RTC signal, use the HAL_RTC_Init() function. 00049 (+) RTC_CALIB: this output is 512Hz signal or 1Hz. 00050 To enable the RTC_CALIB, use the HAL_RTCEx_SetCalibrationOutPut() function. 00051 (+) Two pins can be used as RTC_ALARM or RTC_CALIB (PC13, PB2) managed on 00052 the RTC_OR register. 00053 (+) When the RTC_CALIB or RTC_ALARM output is selected, the RTC_OUT pin is 00054 automatically configured in output alternate function. 00055 00056 *** Smooth digital Calibration configuration *** 00057 ================================================ 00058 [..] 00059 (+) Configure the RTC Original Digital Calibration Value and the corresponding 00060 calibration cycle period (32s,16s and 8s) using the HAL_RTCEx_SetSmoothCalib() 00061 function. 00062 00063 *** TimeStamp configuration *** 00064 =============================== 00065 [..] 00066 (+) Enable the RTC TimeStamp using the HAL_RTCEx_SetTimeStamp() function. 00067 You can also configure the RTC TimeStamp with interrupt mode using the 00068 HAL_RTCEx_SetTimeStamp_IT() function. 00069 (+) To read the RTC TimeStamp Time and Date register, use the HAL_RTCEx_GetTimeStamp() 00070 function. 00071 00072 *** Internal TimeStamp configuration *** 00073 =============================== 00074 [..] 00075 (+) Enable the RTC internal TimeStamp using the HAL_RTCEx_SetInternalTimeStamp() function. 00076 User has to check internal timestamp occurrence using __HAL_RTC_INTERNAL_TIMESTAMP_GET_FLAG. 00077 (+) To read the RTC TimeStamp Time and Date register, use the HAL_RTCEx_GetTimeStamp() 00078 function. 00079 00080 *** Tamper configuration *** 00081 ============================ 00082 [..] 00083 (+) Enable the RTC Tamper and configure the Tamper filter count, trigger Edge 00084 or Level according to the Tamper filter (if equal to 0 Edge else Level) 00085 value, sampling frequency, NoErase, MaskFlag, precharge or discharge and 00086 Pull-UP using the HAL_RTCEx_SetTamper() function. You can configure RTC Tamper 00087 with interrupt mode using HAL_RTCEx_SetTamper_IT() function. 00088 (+) The default configuration of the Tamper erases the backup registers. To avoid 00089 erase, enable the NoErase field on the RTC_TAMPCR register. 00090 00091 *** Backup Data Registers configuration *** 00092 =========================================== 00093 [..] 00094 (+) To write to the RTC Backup Data registers, use the HAL_RTCEx_BKUPWrite() 00095 function. 00096 (+) To read the RTC Backup Data registers, use the HAL_RTCEx_BKUPRead() 00097 function. 00098 00099 @endverbatim 00100 */ 00101 00102 /* Includes ------------------------------------------------------------------*/ 00103 #include "stm32h7xx_hal.h" 00104 00105 /** @addtogroup STM32H7xx_HAL_Driver 00106 * @{ 00107 */ 00108 00109 /** @addtogroup RTCEx 00110 * @brief RTC Extended HAL module driver 00111 * @{ 00112 */ 00113 00114 #ifdef HAL_RTC_MODULE_ENABLED 00115 00116 /* Private typedef -----------------------------------------------------------*/ 00117 /* Private define ------------------------------------------------------------*/ 00118 #define TAMP_ALL (TAMP_CR1_TAMP1E | TAMP_CR1_TAMP2E | TAMP_CR1_TAMP3E) 00119 00120 /* Private macro -------------------------------------------------------------*/ 00121 /* Private variables ---------------------------------------------------------*/ 00122 /* Private function prototypes -----------------------------------------------*/ 00123 /* Exported functions --------------------------------------------------------*/ 00124 00125 /** @addtogroup RTCEx_Exported_Functions 00126 * @{ 00127 */ 00128 00129 00130 /** @addtogroup RTCEx_Exported_Functions_Group1 00131 * @brief RTC TimeStamp and Tamper functions 00132 * 00133 @verbatim 00134 =============================================================================== 00135 ##### RTC TimeStamp and Tamper functions ##### 00136 =============================================================================== 00137 00138 [..] This section provides functions allowing to configure TimeStamp feature 00139 00140 @endverbatim 00141 * @{ 00142 */ 00143 00144 /** 00145 * @brief Set TimeStamp. 00146 * @note This API must be called before enabling the TimeStamp feature. 00147 * @param hrtc RTC handle 00148 * @param TimeStampEdge Specifies the pin edge on which the TimeStamp is 00149 * activated. 00150 * This parameter can be one of the following values: 00151 * @arg RTC_TIMESTAMPEDGE_RISING: the Time stamp event occurs on the 00152 * rising edge of the related pin. 00153 * @arg RTC_TIMESTAMPEDGE_FALLING: the Time stamp event occurs on the 00154 * falling edge of the related pin. 00155 * @param RTC_TimeStampPin specifies the RTC TimeStamp Pin. 00156 * This parameter can be one of the following values: 00157 * @arg RTC_TIMESTAMPPIN_DEFAULT: PC13 is selected as RTC TimeStamp Pin. 00158 * The RTC TimeStamp Pin is per default PC13, but for reasons of 00159 * compatibility, this parameter is required. 00160 * @retval HAL status 00161 */ 00162 HAL_StatusTypeDef HAL_RTCEx_SetTimeStamp(RTC_HandleTypeDef *hrtc, uint32_t TimeStampEdge, uint32_t RTC_TimeStampPin) 00163 { 00164 uint32_t tmpreg; 00165 00166 /* Check the parameters */ 00167 assert_param(IS_TIMESTAMP_EDGE(TimeStampEdge)); 00168 assert_param(IS_RTC_TIMESTAMP_PIN(RTC_TimeStampPin)); 00169 00170 /* Prevent unused argument(s) compilation warning if no assert_param check */ 00171 UNUSED(RTC_TimeStampPin); 00172 00173 /* Process Locked */ 00174 __HAL_LOCK(hrtc); 00175 00176 hrtc->State = HAL_RTC_STATE_BUSY; 00177 00178 /* Get the RTC_CR register and clear the bits to be configured */ 00179 tmpreg = (uint32_t)(hrtc->Instance->CR & (uint32_t)~(RTC_CR_TSEDGE | RTC_CR_TSE)); 00180 00181 tmpreg |= TimeStampEdge; 00182 00183 /* Disable the write protection for RTC registers */ 00184 __HAL_RTC_WRITEPROTECTION_DISABLE(hrtc); 00185 00186 /* Configure the Time Stamp TSEDGE and Enable bits */ 00187 hrtc->Instance->CR = (uint32_t)tmpreg; 00188 00189 __HAL_RTC_TIMESTAMP_ENABLE(hrtc); 00190 00191 /* Enable the write protection for RTC registers */ 00192 __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc); 00193 00194 /* Change RTC state */ 00195 hrtc->State = HAL_RTC_STATE_READY; 00196 00197 /* Process Unlocked */ 00198 __HAL_UNLOCK(hrtc); 00199 00200 return HAL_OK; 00201 } 00202 00203 /** 00204 * @brief Set TimeStamp with Interrupt. 00205 * @note This API must be called before enabling the TimeStamp feature. 00206 * @param hrtc RTC handle 00207 * @param TimeStampEdge Specifies the pin edge on which the TimeStamp is 00208 * activated. 00209 * This parameter can be one of the following values: 00210 * @arg RTC_TIMESTAMPEDGE_RISING: the Time stamp event occurs on the 00211 * rising edge of the related pin. 00212 * @arg RTC_TIMESTAMPEDGE_FALLING: the Time stamp event occurs on the 00213 * falling edge of the related pin. 00214 * @param RTC_TimeStampPin Specifies the RTC TimeStamp Pin. 00215 * This parameter can be one of the following values: 00216 * @arg RTC_TIMESTAMPPIN_DEFAULT: PC13 is selected as RTC TimeStamp Pin. 00217 * The RTC TimeStamp Pin is per default PC13, but for reasons of 00218 * compatibility, this parameter is required. 00219 * @retval HAL status 00220 */ 00221 HAL_StatusTypeDef HAL_RTCEx_SetTimeStamp_IT(RTC_HandleTypeDef *hrtc, uint32_t TimeStampEdge, uint32_t RTC_TimeStampPin) 00222 { 00223 uint32_t tmpreg; 00224 00225 /* Check the parameters */ 00226 assert_param(IS_TIMESTAMP_EDGE(TimeStampEdge)); 00227 assert_param(IS_RTC_TIMESTAMP_PIN(RTC_TimeStampPin)); 00228 00229 /* Prevent unused argument(s) compilation warning if no assert_param check */ 00230 UNUSED(RTC_TimeStampPin); 00231 00232 /* Process Locked */ 00233 __HAL_LOCK(hrtc); 00234 00235 hrtc->State = HAL_RTC_STATE_BUSY; 00236 00237 /* Get the RTC_CR register and clear the bits to be configured */ 00238 tmpreg = (uint32_t)(hrtc->Instance->CR & (uint32_t)~(RTC_CR_TSEDGE | RTC_CR_TSE)); 00239 00240 tmpreg |= TimeStampEdge; 00241 00242 /* Disable the write protection for RTC registers */ 00243 __HAL_RTC_WRITEPROTECTION_DISABLE(hrtc); 00244 00245 /* Configure the Time Stamp TSEDGE and Enable bits */ 00246 hrtc->Instance->CR = (uint32_t)tmpreg; 00247 00248 __HAL_RTC_TIMESTAMP_ENABLE(hrtc); 00249 00250 /* Enable IT timestamp */ 00251 __HAL_RTC_TIMESTAMP_ENABLE_IT(hrtc, RTC_IT_TS); 00252 00253 /* RTC timestamp Interrupt Configuration: EXTI configuration */ 00254 #if defined(DUAL_CORE) 00255 if (HAL_GetCurrentCPUID() == CM7_CPUID) 00256 { 00257 __HAL_RTC_TAMPER_TIMESTAMP_EXTI_ENABLE_IT(); 00258 } 00259 else 00260 { 00261 __HAL_RTC_TAMPER_TIMESTAMP_EXTID2_ENABLE_IT(); 00262 } 00263 #else /* SINGLE_CORE */ 00264 __HAL_RTC_TAMPER_TIMESTAMP_EXTI_ENABLE_IT(); 00265 #endif /* DUAL_CORE */ 00266 00267 __HAL_RTC_TAMPER_TIMESTAMP_EXTI_ENABLE_RISING_EDGE(); 00268 00269 /* Enable the write protection for RTC registers */ 00270 __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc); 00271 00272 hrtc->State = HAL_RTC_STATE_READY; 00273 00274 /* Process Unlocked */ 00275 __HAL_UNLOCK(hrtc); 00276 00277 return HAL_OK; 00278 } 00279 00280 /** 00281 * @brief Deactivate TimeStamp. 00282 * @param hrtc RTC handle 00283 * @retval HAL status 00284 */ 00285 HAL_StatusTypeDef HAL_RTCEx_DeactivateTimeStamp(RTC_HandleTypeDef *hrtc) 00286 { 00287 uint32_t tmpreg; 00288 00289 /* Process Locked */ 00290 __HAL_LOCK(hrtc); 00291 00292 hrtc->State = HAL_RTC_STATE_BUSY; 00293 00294 /* Disable the write protection for RTC registers */ 00295 __HAL_RTC_WRITEPROTECTION_DISABLE(hrtc); 00296 00297 /* In case of interrupt mode is used, the interrupt source must disabled */ 00298 __HAL_RTC_TIMESTAMP_DISABLE_IT(hrtc, RTC_IT_TS); 00299 00300 /* Get the RTC_CR register and clear the bits to be configured */ 00301 tmpreg = (uint32_t)(hrtc->Instance->CR & (uint32_t)~(RTC_CR_TSEDGE | RTC_CR_TSE)); 00302 00303 /* Configure the Time Stamp TSEDGE and Enable bits */ 00304 hrtc->Instance->CR = (uint32_t)tmpreg; 00305 00306 /* Enable the write protection for RTC registers */ 00307 __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc); 00308 00309 hrtc->State = HAL_RTC_STATE_READY; 00310 00311 /* Process Unlocked */ 00312 __HAL_UNLOCK(hrtc); 00313 00314 return HAL_OK; 00315 } 00316 00317 /** 00318 * @brief Set Internal TimeStamp. 00319 * @note This API must be called before enabling the internal TimeStamp feature. 00320 * @param hrtc RTC handle 00321 * @retval HAL status 00322 */ 00323 HAL_StatusTypeDef HAL_RTCEx_SetInternalTimeStamp(RTC_HandleTypeDef *hrtc) 00324 { 00325 /* Process Locked */ 00326 __HAL_LOCK(hrtc); 00327 00328 hrtc->State = HAL_RTC_STATE_BUSY; 00329 00330 /* Disable the write protection for RTC registers */ 00331 __HAL_RTC_WRITEPROTECTION_DISABLE(hrtc); 00332 00333 /* Configure the internal Time Stamp Enable bits */ 00334 __HAL_RTC_INTERNAL_TIMESTAMP_ENABLE(hrtc); 00335 00336 /* Enable the write protection for RTC registers */ 00337 __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc); 00338 00339 /* Change RTC state */ 00340 hrtc->State = HAL_RTC_STATE_READY; 00341 00342 /* Process Unlocked */ 00343 __HAL_UNLOCK(hrtc); 00344 00345 return HAL_OK; 00346 } 00347 00348 /** 00349 * @brief Deactivate Internal TimeStamp. 00350 * @param hrtc RTC handle 00351 * @retval HAL status 00352 */ 00353 HAL_StatusTypeDef HAL_RTCEx_DeactivateInternalTimeStamp(RTC_HandleTypeDef *hrtc) 00354 { 00355 /* Process Locked */ 00356 __HAL_LOCK(hrtc); 00357 00358 hrtc->State = HAL_RTC_STATE_BUSY; 00359 00360 /* Disable the write protection for RTC registers */ 00361 __HAL_RTC_WRITEPROTECTION_DISABLE(hrtc); 00362 00363 /* Configure the internal Time Stamp Enable bits */ 00364 __HAL_RTC_INTERNAL_TIMESTAMP_DISABLE(hrtc); 00365 00366 /* Enable the write protection for RTC registers */ 00367 __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc); 00368 00369 hrtc->State = HAL_RTC_STATE_READY; 00370 00371 /* Process Unlocked */ 00372 __HAL_UNLOCK(hrtc); 00373 00374 return HAL_OK; 00375 } 00376 00377 /** 00378 * @brief Get the RTC TimeStamp value. 00379 * @param hrtc RTC handle 00380 * @param sTimeStamp Pointer to Time structure 00381 * @param sTimeStampDate Pointer to Date structure 00382 * @param Format specifies the format of the entered parameters. 00383 * This parameter can be one of the following values: 00384 * @arg RTC_FORMAT_BIN: Binary data format 00385 * @arg RTC_FORMAT_BCD: BCD data format 00386 * @retval HAL status 00387 */ 00388 HAL_StatusTypeDef HAL_RTCEx_GetTimeStamp(RTC_HandleTypeDef *hrtc, RTC_TimeTypeDef *sTimeStamp, RTC_DateTypeDef *sTimeStampDate, uint32_t Format) 00389 { 00390 uint32_t tmptime; 00391 uint32_t tmpdate; 00392 00393 /* Check the parameters */ 00394 assert_param(IS_RTC_FORMAT(Format)); 00395 00396 /* Get the TimeStamp time and date registers values */ 00397 tmptime = (uint32_t)(hrtc->Instance->TSTR & RTC_TR_RESERVED_MASK); 00398 tmpdate = (uint32_t)(hrtc->Instance->TSDR & RTC_DR_RESERVED_MASK); 00399 00400 /* Fill the Time structure fields with the read parameters */ 00401 sTimeStamp->Hours = (uint8_t)((tmptime & (RTC_TSTR_HT | RTC_TSTR_HU)) >> RTC_TSTR_HU_Pos); 00402 sTimeStamp->Minutes = (uint8_t)((tmptime & (RTC_TSTR_MNT | RTC_TSTR_MNU)) >> RTC_TSTR_MNU_Pos); 00403 sTimeStamp->Seconds = (uint8_t)((tmptime & (RTC_TSTR_ST | RTC_TSTR_SU)) >> RTC_TSTR_SU_Pos); 00404 sTimeStamp->TimeFormat = (uint8_t)((tmptime & (RTC_TSTR_PM)) >> RTC_TSTR_PM_Pos); 00405 sTimeStamp->SubSeconds = (uint32_t) hrtc->Instance->TSSSR; 00406 00407 /* Fill the Date structure fields with the read parameters */ 00408 sTimeStampDate->Year = 0U; 00409 sTimeStampDate->Month = (uint8_t)((tmpdate & (RTC_TSDR_MT | RTC_TSDR_MU)) >> RTC_TSDR_MU_Pos); 00410 sTimeStampDate->Date = (uint8_t)((tmpdate & (RTC_TSDR_DT | RTC_TSDR_DU)) >> RTC_TSDR_DU_Pos); 00411 sTimeStampDate->WeekDay = (uint8_t)((tmpdate & (RTC_TSDR_WDU)) >> RTC_TSDR_WDU_Pos); 00412 00413 /* Check the input parameters format */ 00414 if (Format == RTC_FORMAT_BIN) 00415 { 00416 /* Convert the TimeStamp structure parameters to Binary format */ 00417 sTimeStamp->Hours = (uint8_t)RTC_Bcd2ToByte(sTimeStamp->Hours); 00418 sTimeStamp->Minutes = (uint8_t)RTC_Bcd2ToByte(sTimeStamp->Minutes); 00419 sTimeStamp->Seconds = (uint8_t)RTC_Bcd2ToByte(sTimeStamp->Seconds); 00420 00421 /* Convert the DateTimeStamp structure parameters to Binary format */ 00422 sTimeStampDate->Month = (uint8_t)RTC_Bcd2ToByte(sTimeStampDate->Month); 00423 sTimeStampDate->Date = (uint8_t)RTC_Bcd2ToByte(sTimeStampDate->Date); 00424 sTimeStampDate->WeekDay = (uint8_t)RTC_Bcd2ToByte(sTimeStampDate->WeekDay); 00425 } 00426 00427 /* Clear the TIMESTAMP Flags */ 00428 __HAL_RTC_INTERNAL_TIMESTAMP_CLEAR_FLAG(hrtc, RTC_FLAG_ITSF); 00429 __HAL_RTC_TIMESTAMP_CLEAR_FLAG(hrtc, RTC_FLAG_TSF); 00430 00431 return HAL_OK; 00432 } 00433 00434 /** 00435 * @} 00436 */ 00437 00438 /** @addtogroup RTCEx_Exported_Functions_Group5 00439 * @brief Extended RTC Tamper functions 00440 * 00441 @verbatim 00442 ============================================================================== 00443 ##### Tamper functions ##### 00444 ============================================================================== 00445 [..] 00446 (+) Before calling any tamper or internal tamper function, you have to call first 00447 HAL_RTC_Init() function. 00448 (+) In that ine you can select to output tamper event on RTC pin. 00449 [..] 00450 (+) Enable the Tamper and configure the Tamper filter count, trigger Edge 00451 or Level according to the Tamper filter (if equal to 0 Edge else Level) 00452 value, sampling frequency, NoErase, MaskFlag, precharge or discharge and 00453 Pull-UP, timestamp using the HAL_RTCEx_SetTamper() function. 00454 You can configure Tamper with interrupt mode using HAL_RTCEx_SetTamper_IT() function. 00455 (+) The default configuration of the Tamper erases the backup registers. To avoid 00456 erase, enable the NoErase field on the TAMP_TAMPCR register. 00457 [..] 00458 (+) Enable Internal Tamper and configure it with interrupt, timestamp using 00459 the HAL_RTCEx_SetInternalTamper() function. 00460 00461 @endverbatim 00462 * @{ 00463 */ 00464 00465 #if defined(TAMP_CR1_TAMP1E) 00466 /** 00467 * @brief Set Tamper 00468 * @param hrtc RTC handle 00469 * @param sTamper Pointer to Tamper Structure. 00470 * @retval HAL status 00471 */ 00472 HAL_StatusTypeDef HAL_RTCEx_SetTamper(RTC_HandleTypeDef * hrtc, RTC_TamperTypeDef * sTamper) 00473 { 00474 uint32_t tmpreg; 00475 00476 /* Point on TAMPER registers base address */ 00477 TAMP_TypeDef *tamp = (TAMP_TypeDef *)((uint32_t)hrtc->Instance + TAMP_OFFSET); 00478 00479 /* Check the parameters */ 00480 assert_param(IS_RTC_TAMPER(sTamper->Tamper)); 00481 assert_param(IS_RTC_TAMPER_TRIGGER(sTamper->Trigger)); 00482 assert_param(IS_RTC_TAMPER_ERASE_MODE(sTamper->NoErase)); 00483 assert_param(IS_RTC_TAMPER_MASKFLAG_STATE(sTamper->MaskFlag)); 00484 assert_param(IS_RTC_TAMPER_TIMESTAMPONTAMPER_DETECTION(sTamper->TimeStampOnTamperDetection)); 00485 assert_param(IS_RTC_TAMPER_FILTER(sTamper->Filter)); 00486 assert_param(IS_RTC_TAMPER_SAMPLING_FREQ(sTamper->SamplingFrequency)); 00487 assert_param(IS_RTC_TAMPER_PRECHARGE_DURATION(sTamper->PrechargeDuration)); 00488 assert_param(IS_RTC_TAMPER_PULLUP_STATE(sTamper->TamperPullUp)); 00489 assert_param(IS_RTC_TAMPER_FILTER_CONFIG_CORRECT(sTamper->Filter, sTamper->Trigger)); 00490 00491 /* Configuration register 2 */ 00492 tmpreg = tamp->CR2; 00493 tmpreg &= ~((sTamper->Tamper << TAMP_CR2_TAMP1TRG_Pos) | (sTamper->Tamper << TAMP_CR2_TAMP1MSK_Pos) | (sTamper->Tamper << TAMP_CR2_TAMP1NOERASE_Pos)); 00494 00495 /* Configure the tamper trigger bit */ 00496 if ((sTamper->Trigger == RTC_TAMPERTRIGGER_HIGHLEVEL) || (sTamper->Trigger == RTC_TAMPERTRIGGER_FALLINGEDGE)) 00497 { 00498 tmpreg |= (sTamper->Tamper << TAMP_CR2_TAMP1TRG_Pos); 00499 } 00500 00501 /* Configure the tamper flags masking bit */ 00502 if (sTamper->MaskFlag != RTC_TAMPERMASK_FLAG_DISABLE) 00503 { 00504 tmpreg |= (sTamper->Tamper << TAMP_CR2_TAMP1MSK_Pos); 00505 } 00506 00507 /* Configure the tamper backup registers erasure bit */ 00508 if (sTamper->NoErase != RTC_TAMPER_ERASE_BACKUP_ENABLE) 00509 { 00510 tmpreg |= (sTamper->Tamper << TAMP_CR2_TAMP1NOERASE_Pos); 00511 } 00512 tamp->CR2 = tmpreg; 00513 00514 /* Configure filtering parameters */ 00515 tamp->FLTCR = (sTamper->Filter) | (sTamper->SamplingFrequency) | \ 00516 (sTamper->PrechargeDuration) | (sTamper->TamperPullUp); 00517 00518 /* Configure Timestamp saving on tamper detection */ 00519 if ((hrtc->Instance->CR & RTC_CR_TAMPTS) != (sTamper->TimeStampOnTamperDetection)) 00520 { 00521 __HAL_RTC_WRITEPROTECTION_DISABLE(hrtc); 00522 tmpreg = (hrtc->Instance->CR & ~RTC_CR_TAMPTS); 00523 hrtc->Instance->CR = (tmpreg | (sTamper->TimeStampOnTamperDetection)); 00524 __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc); 00525 } 00526 00527 /* Enable selected tamper */ 00528 tamp->CR1 |= (sTamper->Tamper); 00529 00530 return HAL_OK; 00531 } 00532 #endif /* TAMP_CR1_TAMP1E */ 00533 #if defined (RTC_TAMPCR_TAMP1E) 00534 /** 00535 * @brief Set Tamper. 00536 * @note By calling this API we disable the tamper interrupt for all tampers. 00537 * @param hrtc RTC handle 00538 * @param sTamper Pointer to Tamper Structure. 00539 * @retval HAL status 00540 */ 00541 HAL_StatusTypeDef HAL_RTCEx_SetTamper(RTC_HandleTypeDef * hrtc, RTC_TamperTypeDef * sTamper) 00542 { 00543 uint32_t tmpreg; 00544 00545 /* Check the parameters */ 00546 assert_param(IS_RTC_TAMPER(sTamper->Tamper)); 00547 assert_param(IS_RTC_TAMPER_TRIGGER(sTamper->Trigger)); 00548 assert_param(IS_RTC_TAMPER_ERASE_MODE(sTamper->NoErase)); 00549 assert_param(IS_RTC_TAMPER_MASKFLAG_STATE(sTamper->MaskFlag)); 00550 assert_param(IS_RTC_TAMPER_FILTER(sTamper->Filter)); 00551 assert_param(IS_RTC_TAMPER_SAMPLING_FREQ(sTamper->SamplingFrequency)); 00552 assert_param(IS_RTC_TAMPER_PRECHARGE_DURATION(sTamper->PrechargeDuration)); 00553 assert_param(IS_RTC_TAMPER_PULLUP_STATE(sTamper->TamperPullUp)); 00554 assert_param(IS_RTC_TAMPER_TIMESTAMPONTAMPER_DETECTION(sTamper->TimeStampOnTamperDetection)); 00555 assert_param(IS_RTC_TAMPER_FILTER_CONFIG_CORRECT(sTamper->Filter, sTamper->Trigger)); 00556 00557 /* Process Locked */ 00558 __HAL_LOCK(hrtc); 00559 00560 hrtc->State = HAL_RTC_STATE_BUSY; 00561 00562 /* Copy control register into temporary variable */ 00563 tmpreg = hrtc->Instance->TAMPCR; 00564 00565 /* Enable selected tamper */ 00566 tmpreg |= (sTamper->Tamper); 00567 00568 /* Configure the bit (located just next to the tamper enable bit) */ 00569 if ((sTamper->Trigger == RTC_TAMPERTRIGGER_HIGHLEVEL) || (sTamper->Trigger == RTC_TAMPERTRIGGER_FALLINGEDGE)) 00570 { 00571 /* Set the tamper trigger bit */ 00572 tmpreg |= (uint32_t)(sTamper->Tamper << 1U); 00573 } 00574 else 00575 { 00576 /* Clear the tamper trigger bit */ 00577 tmpreg &= (uint32_t)~(sTamper->Tamper << 1U); 00578 } 00579 00580 /* Configure the tamper backup registers erasure bit */ 00581 if (sTamper->NoErase != RTC_TAMPER_ERASE_BACKUP_ENABLE) 00582 { 00583 #if defined(RTC_TAMPCR_TAMP1E) 00584 if ((sTamper->Tamper & RTC_TAMPER_1) != 0U) 00585 { 00586 tmpreg |= (uint32_t)(RTC_TAMPCR_TAMP1NOERASE); 00587 } 00588 #endif /* RTC_TAMPCR_TAMP1E */ 00589 #if defined(RTC_TAMPCR_TAMP2E) 00590 if ((sTamper->Tamper & RTC_TAMPER_2) != 0U) 00591 { 00592 tmpreg |= (uint32_t)(RTC_TAMPCR_TAMP2NOERASE); 00593 } 00594 #endif /* RTC_TAMPCR_TAMP2E */ 00595 #if defined(RTC_TAMPCR_TAMP3E) 00596 if ((sTamper->Tamper & RTC_TAMPER_3) != 0U) 00597 { 00598 tmpreg |= (uint32_t)(RTC_TAMPCR_TAMP3NOERASE); 00599 } 00600 #endif /* RTC_TAMPCR_TAMP3E */ 00601 } 00602 else 00603 { 00604 #if defined(RTC_TAMPCR_TAMP1E) 00605 if ((sTamper->Tamper & RTC_TAMPER_1) != 0U) 00606 { 00607 tmpreg &= (uint32_t)~(RTC_TAMPCR_TAMP1NOERASE); 00608 } 00609 #endif /* RTC_TAMPCR_TAMP1E */ 00610 #if defined(RTC_TAMPCR_TAMP2E) 00611 if ((sTamper->Tamper & RTC_TAMPER_2) != 0U) 00612 { 00613 tmpreg &= (uint32_t)~(RTC_TAMPCR_TAMP2NOERASE); 00614 } 00615 #endif /* RTC_TAMPCR_TAMP2E */ 00616 #if defined(RTC_TAMPCR_TAMP3E) 00617 if ((sTamper->Tamper & RTC_TAMPER_3) != 0U) 00618 { 00619 tmpreg &= (uint32_t)~(RTC_TAMPCR_TAMP3NOERASE); 00620 } 00621 #endif /* RTC_TAMPCR_TAMP3E */ 00622 } 00623 00624 /* Configure the tamper flags masking bit */ 00625 if (sTamper->MaskFlag != RTC_TAMPERMASK_FLAG_DISABLE) 00626 { 00627 #if defined(RTC_TAMPCR_TAMP1E) 00628 if ((sTamper->Tamper & RTC_TAMPER_1) != 0U) 00629 { 00630 tmpreg |= (uint32_t)(RTC_TAMPCR_TAMP1MF); 00631 } 00632 #endif /* RTC_TAMPCR_TAMP1E */ 00633 #if defined(RTC_TAMPCR_TAMP2E) 00634 if ((sTamper->Tamper & RTC_TAMPER_2) != 0U) 00635 { 00636 tmpreg |= (uint32_t)(RTC_TAMPCR_TAMP2MF); 00637 } 00638 #endif /* RTC_TAMPCR_TAMP2E */ 00639 #if defined(RTC_TAMPCR_TAMP3E) 00640 if ((sTamper->Tamper & RTC_TAMPER_3) != 0U) 00641 { 00642 tmpreg |= (uint32_t)(RTC_TAMPCR_TAMP3MF); 00643 } 00644 #endif /* RTC_TAMPCR_TAMP3E */ 00645 } 00646 else 00647 { 00648 #if defined(RTC_TAMPCR_TAMP1E) 00649 if ((sTamper->Tamper & RTC_TAMPER_1) != 0U) 00650 { 00651 tmpreg &= (uint32_t)~(RTC_TAMPCR_TAMP1MF); 00652 } 00653 #endif /* RTC_TAMPCR_TAMP1E */ 00654 #if defined(RTC_TAMPCR_TAMP2E) 00655 if ((sTamper->Tamper & RTC_TAMPER_2) != 0U) 00656 { 00657 tmpreg &= (uint32_t)~(RTC_TAMPCR_TAMP2MF); 00658 } 00659 #endif /* RTC_TAMPCR_TAMP2E */ 00660 #if defined(RTC_TAMPCR_TAMP3E) 00661 if ((sTamper->Tamper & RTC_TAMPER_3) != 0U) 00662 { 00663 tmpreg &= (uint32_t)~(RTC_TAMPCR_TAMP3MF); 00664 } 00665 #endif /* RTC_TAMPCR_TAMP3E */ 00666 } 00667 00668 /* Clearing remaining fields before setting them */ 00669 tmpreg &= ~(RTC_TAMPERFILTER_MASK | RTC_TAMPERSAMPLINGFREQ_RTCCLK_MASK | \ 00670 RTC_TAMPERPRECHARGEDURATION_MASK | RTC_TAMPER_PULLUP_MASK | \ 00671 RTC_TIMESTAMPONTAMPERDETECTION_MASK); 00672 00673 /* Set remaining parameters of desired configuration into temporary variable */ 00674 tmpreg |= ((uint32_t)sTamper->Filter | \ 00675 (uint32_t)sTamper->SamplingFrequency | \ 00676 (uint32_t)sTamper->PrechargeDuration | \ 00677 (uint32_t)sTamper->TamperPullUp | \ 00678 (uint32_t)sTamper->TimeStampOnTamperDetection); 00679 00680 /* Copy desired configuration into configuration register */ 00681 hrtc->Instance->TAMPCR = tmpreg; 00682 00683 hrtc->State = HAL_RTC_STATE_READY; 00684 00685 /* Process Unlocked */ 00686 __HAL_UNLOCK(hrtc); 00687 00688 return HAL_OK; 00689 } 00690 #endif /* RTC_TAMPCR_TAMP1E */ 00691 00692 #if defined(TAMP_CR1_TAMP1E) 00693 /** 00694 * @brief Set Tamper with interrupt. 00695 * @param hrtc RTC handle 00696 * @param sTamper Pointer to Tamper Structure. 00697 * @retval HAL status 00698 */ 00699 HAL_StatusTypeDef HAL_RTCEx_SetTamper_IT(RTC_HandleTypeDef * hrtc, RTC_TamperTypeDef * sTamper) 00700 { 00701 uint32_t tmpreg; 00702 00703 /* Point on TAMPER registers base address */ 00704 TAMP_TypeDef *tamp = (TAMP_TypeDef *)((uint32_t)hrtc->Instance + TAMP_OFFSET); 00705 00706 /* Check the parameters */ 00707 assert_param(IS_RTC_TAMPER(sTamper->Tamper)); 00708 assert_param(IS_RTC_TAMPER_TRIGGER(sTamper->Trigger)); 00709 assert_param(IS_RTC_TAMPER_ERASE_MODE(sTamper->NoErase)); 00710 assert_param(IS_RTC_TAMPER_MASKFLAG_STATE(sTamper->MaskFlag)); 00711 assert_param(IS_RTC_TAMPER_FILTER(sTamper->Filter)); 00712 assert_param(IS_RTC_TAMPER_SAMPLING_FREQ(sTamper->SamplingFrequency)); 00713 assert_param(IS_RTC_TAMPER_PRECHARGE_DURATION(sTamper->PrechargeDuration)); 00714 assert_param(IS_RTC_TAMPER_PULLUP_STATE(sTamper->TamperPullUp)); 00715 assert_param(IS_RTC_TAMPER_TIMESTAMPONTAMPER_DETECTION(sTamper->TimeStampOnTamperDetection)); 00716 assert_param(IS_RTC_TAMPER_FILTER_CONFIG_CORRECT(sTamper->Filter, sTamper->Trigger)); 00717 00718 /* Copy configuration register into temporary variable */ 00719 tmpreg = tamp->CR2; 00720 00721 /* Clear the bits that are going to be configured and leave the others unchanged */ 00722 tmpreg &= ~((sTamper->Tamper << TAMP_CR2_TAMP1TRG_Pos) | (sTamper->Tamper << TAMP_CR2_TAMP1MSK_Pos) | (sTamper->Tamper << TAMP_CR2_TAMP1NOERASE_Pos)); 00723 00724 /* Configure the tamper trigger bit */ 00725 if ((sTamper->Trigger == RTC_TAMPERTRIGGER_HIGHLEVEL) || (sTamper->Trigger == RTC_TAMPERTRIGGER_FALLINGEDGE)) 00726 { 00727 tmpreg |= (sTamper->Tamper << TAMP_CR2_TAMP1TRG_Pos); 00728 } 00729 00730 /* Configure the tamper flags masking bit */ 00731 if (sTamper->MaskFlag != RTC_TAMPERMASK_FLAG_DISABLE) 00732 { 00733 tmpreg |= (sTamper->Tamper << TAMP_CR2_TAMP1MSK_Pos); 00734 } 00735 00736 /* Configure the tamper backup registers erasure bit */ 00737 if (sTamper->NoErase != RTC_TAMPER_ERASE_BACKUP_ENABLE) 00738 { 00739 tmpreg |= (sTamper->Tamper << TAMP_CR2_TAMP1NOERASE_Pos); 00740 } 00741 tamp->CR2 = tmpreg; 00742 00743 /* Configure filtering parameters */ 00744 tamp->FLTCR = (sTamper->Filter) | (sTamper->SamplingFrequency) | \ 00745 (sTamper->PrechargeDuration) | (sTamper->TamperPullUp); 00746 00747 /* Configure Timestamp saving on tamper detection */ 00748 if ((hrtc->Instance->CR & RTC_CR_TAMPTS) != (sTamper->TimeStampOnTamperDetection)) 00749 { 00750 __HAL_RTC_WRITEPROTECTION_DISABLE(hrtc); 00751 tmpreg = (hrtc->Instance->CR & ~RTC_CR_TAMPTS); 00752 hrtc->Instance->CR = (tmpreg | (sTamper->TimeStampOnTamperDetection)); 00753 __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc); 00754 } 00755 00756 /* Configure RTC Tamper Interrupt: EXTI configuration */ 00757 __HAL_RTC_TAMPER_TIMESTAMP_EXTI_ENABLE_IT(); 00758 __HAL_RTC_TAMPER_TIMESTAMP_EXTI_ENABLE_RISING_FALLING_EDGE(); 00759 00760 /* Enable interrupt on selected tamper */ 00761 tamp->IER |= sTamper->Tamper; 00762 00763 /* Enable selected tamper */ 00764 tamp->CR1 |= sTamper->Tamper; 00765 00766 return HAL_OK; 00767 } 00768 #endif /* TAMP_CR1_TAMP1E */ 00769 #if defined(RTC_TAMPCR_TAMP1E) 00770 /** 00771 * @brief Set Tamper with interrupt. 00772 * @note By calling this API we force the tamper interrupt for all tampers. 00773 * @param hrtc RTC handle 00774 * @param sTamper Pointer to Tamper Structure. 00775 * @retval HAL status 00776 */ 00777 HAL_StatusTypeDef HAL_RTCEx_SetTamper_IT(RTC_HandleTypeDef * hrtc, RTC_TamperTypeDef * sTamper) 00778 { 00779 uint32_t tmpreg; 00780 00781 /* Check the parameters */ 00782 assert_param(IS_RTC_TAMPER(sTamper->Tamper)); 00783 assert_param(IS_RTC_TAMPER_INTERRUPT(sTamper->Interrupt)); 00784 assert_param(IS_RTC_TAMPER_TRIGGER(sTamper->Trigger)); 00785 assert_param(IS_RTC_TAMPER_ERASE_MODE(sTamper->NoErase)); 00786 assert_param(IS_RTC_TAMPER_MASKFLAG_STATE(sTamper->MaskFlag)); 00787 assert_param(IS_RTC_TAMPER_FILTER(sTamper->Filter)); 00788 assert_param(IS_RTC_TAMPER_SAMPLING_FREQ(sTamper->SamplingFrequency)); 00789 assert_param(IS_RTC_TAMPER_PRECHARGE_DURATION(sTamper->PrechargeDuration)); 00790 assert_param(IS_RTC_TAMPER_PULLUP_STATE(sTamper->TamperPullUp)); 00791 assert_param(IS_RTC_TAMPER_TIMESTAMPONTAMPER_DETECTION(sTamper->TimeStampOnTamperDetection)); 00792 assert_param(IS_RTC_TAMPER_FILTER_CONFIG_CORRECT(sTamper->Filter, sTamper->Trigger)); 00793 00794 /* Process Locked */ 00795 __HAL_LOCK(hrtc); 00796 00797 hrtc->State = HAL_RTC_STATE_BUSY; 00798 00799 /* Copy control register into temporary variable */ 00800 tmpreg = hrtc->Instance->TAMPCR; 00801 00802 /* Enable selected tamper */ 00803 tmpreg |= (sTamper->Tamper); 00804 00805 /* Configure the tamper trigger bit (located just next to the tamper enable bit) */ 00806 if ((sTamper->Trigger == RTC_TAMPERTRIGGER_HIGHLEVEL) || (sTamper->Trigger == RTC_TAMPERTRIGGER_FALLINGEDGE)) 00807 { 00808 /* Set the tamper trigger bit */ 00809 tmpreg |= (uint32_t)(sTamper->Tamper << 1U); 00810 } 00811 else 00812 { 00813 /* Clear the tamper trigger bit */ 00814 tmpreg &= (uint32_t)~(sTamper->Tamper << 1U); 00815 } 00816 00817 /* Configure the tamper backup registers erasure bit */ 00818 if (sTamper->NoErase != RTC_TAMPER_ERASE_BACKUP_ENABLE) 00819 { 00820 #if defined(RTC_TAMPCR_TAMP1E) 00821 if ((sTamper->Tamper & RTC_TAMPER_1) != 0U) 00822 { 00823 tmpreg |= (uint32_t)(RTC_TAMPCR_TAMP1NOERASE); 00824 } 00825 #endif /* RTC_TAMPCR_TAMP1E */ 00826 #if defined(RTC_TAMPCR_TAMP2E) 00827 if ((sTamper->Tamper & RTC_TAMPER_2) != 0U) 00828 { 00829 tmpreg |= (uint32_t)(RTC_TAMPCR_TAMP2NOERASE); 00830 } 00831 #endif /* RTC_TAMPCR_TAMP2E */ 00832 #if defined(RTC_TAMPCR_TAMP3E) 00833 if ((sTamper->Tamper & RTC_TAMPER_3) != 0U) 00834 { 00835 tmpreg |= (uint32_t)(RTC_TAMPCR_TAMP3NOERASE); 00836 } 00837 #endif /* RTC_TAMPCR_TAMP3E */ 00838 } 00839 else 00840 { 00841 #if defined(RTC_TAMPCR_TAMP1E) 00842 if ((sTamper->Tamper & RTC_TAMPER_1) != 0U) 00843 { 00844 tmpreg &= (uint32_t)~(RTC_TAMPCR_TAMP1NOERASE); 00845 } 00846 #endif /* RTC_TAMPCR_TAMP1E */ 00847 #if defined(RTC_TAMPCR_TAMP2E) 00848 if ((sTamper->Tamper & RTC_TAMPER_2) != 0U) 00849 { 00850 tmpreg &= (uint32_t)~(RTC_TAMPCR_TAMP2NOERASE); 00851 } 00852 #endif /* RTC_TAMPCR_TAMP2E */ 00853 #if defined(RTC_TAMPCR_TAMP3E) 00854 if ((sTamper->Tamper & RTC_TAMPER_3) != 0U) 00855 { 00856 tmpreg &= (uint32_t)~(RTC_TAMPCR_TAMP3NOERASE); 00857 } 00858 #endif /* RTC_TAMPCR_TAMP3E */ 00859 } 00860 00861 /* Configure the tamper flags masking bit */ 00862 if (sTamper->MaskFlag != RTC_TAMPERMASK_FLAG_DISABLE) 00863 { 00864 #if defined(RTC_TAMPCR_TAMP1E) 00865 if ((sTamper->Tamper & RTC_TAMPER_1) != 0U) 00866 { 00867 tmpreg |= (uint32_t)(RTC_TAMPCR_TAMP1MF); 00868 } 00869 #endif /* RTC_TAMPCR_TAMP1E */ 00870 #if defined(RTC_TAMPCR_TAMP2E) 00871 if ((sTamper->Tamper & RTC_TAMPER_2) != 0U) 00872 { 00873 tmpreg |= (uint32_t)(RTC_TAMPCR_TAMP2MF); 00874 } 00875 #endif /* RTC_TAMPCR_TAMP2E */ 00876 #if defined(RTC_TAMPCR_TAMP3E) 00877 if ((sTamper->Tamper & RTC_TAMPER_3) != 0U) 00878 { 00879 tmpreg |= (uint32_t)(RTC_TAMPCR_TAMP3MF); 00880 } 00881 #endif /* RTC_TAMPCR_TAMP3E */ 00882 } 00883 else 00884 { 00885 #if defined(RTC_TAMPCR_TAMP1E) 00886 if ((sTamper->Tamper & RTC_TAMPER_1) != 0U) 00887 { 00888 tmpreg &= (uint32_t)~(RTC_TAMPCR_TAMP1MF); 00889 } 00890 #endif /* RTC_TAMPCR_TAMP1E */ 00891 #if defined(RTC_TAMPCR_TAMP2E) 00892 if ((sTamper->Tamper & RTC_TAMPER_2) != 0U) 00893 { 00894 tmpreg &= (uint32_t)~(RTC_TAMPCR_TAMP2MF); 00895 } 00896 #endif /* RTC_TAMPCR_TAMP2E */ 00897 #if defined(RTC_TAMPCR_TAMP3E) 00898 if ((sTamper->Tamper & RTC_TAMPER_3) != 0U) 00899 { 00900 tmpreg &= (uint32_t)~(RTC_TAMPCR_TAMP3MF); 00901 } 00902 #endif /* RTC_TAMPCR_TAMP3E */ 00903 } 00904 00905 /* Clearing remaining fields before setting them */ 00906 tmpreg &= ~(RTC_TAMPERFILTER_MASK | RTC_TAMPERSAMPLINGFREQ_RTCCLK_MASK | \ 00907 RTC_TAMPERPRECHARGEDURATION_MASK | RTC_TAMPER_PULLUP_MASK | \ 00908 RTC_TIMESTAMPONTAMPERDETECTION_MASK); 00909 00910 /* Set remaining parameters of desired configuration into temporary variable */ 00911 tmpreg |= ((uint32_t)sTamper->Filter | \ 00912 (uint32_t)sTamper->SamplingFrequency | \ 00913 (uint32_t)sTamper->PrechargeDuration | \ 00914 (uint32_t)sTamper->TamperPullUp | \ 00915 (uint32_t)sTamper->TimeStampOnTamperDetection); 00916 00917 /* Enable interrupt on selected tamper */ 00918 tmpreg |= (uint32_t)sTamper->Interrupt; 00919 00920 /* Copy desired configuration into configuration register */ 00921 hrtc->Instance->TAMPCR = tmpreg; 00922 00923 /* RTC Tamper Interrupt Configuration: EXTI configuration */ 00924 #if defined(DUAL_CORE) 00925 if (HAL_GetCurrentCPUID() == CM7_CPUID) 00926 { 00927 __HAL_RTC_TAMPER_TIMESTAMP_EXTI_ENABLE_IT(); 00928 } 00929 else 00930 { 00931 __HAL_RTC_TAMPER_TIMESTAMP_EXTID2_ENABLE_IT(); 00932 } 00933 #else /* SINGLE_CORE */ 00934 __HAL_RTC_TAMPER_TIMESTAMP_EXTI_ENABLE_IT(); 00935 #endif /* DUAL_CORE */ 00936 00937 __HAL_RTC_TAMPER_TIMESTAMP_EXTI_ENABLE_RISING_EDGE(); 00938 00939 hrtc->State = HAL_RTC_STATE_READY; 00940 00941 /* Process Unlocked */ 00942 __HAL_UNLOCK(hrtc); 00943 00944 return HAL_OK; 00945 } 00946 #endif /* RTC_TAMPCR_TAMP1E */ 00947 00948 #if defined(TAMP_CR1_TAMP1E) 00949 /** 00950 * @brief Deactivate Tamper. 00951 * @param hrtc RTC handle 00952 * @param Tamper Selected tamper pin. 00953 * This parameter can be a combination of the following values: 00954 * @arg RTC_TAMPER_1 00955 * @arg RTC_TAMPER_2 00956 * @retval HAL status 00957 */ 00958 HAL_StatusTypeDef HAL_RTCEx_DeactivateTamper(RTC_HandleTypeDef * hrtc, uint32_t Tamper) 00959 { 00960 /* Point on TAMPER registers base address */ 00961 TAMP_TypeDef *tamp = (TAMP_TypeDef *)((uint32_t)hrtc->Instance + TAMP_OFFSET); 00962 00963 assert_param(IS_RTC_TAMPER(Tamper)); 00964 00965 /* Disable the selected Tamper pin */ 00966 tamp->CR1 &= ~Tamper; 00967 00968 /* Disable the selected Tamper interrupt */ 00969 tamp->IER &= ~Tamper; 00970 00971 /* Clear the selected tamper flags in SR register by setting corresponding bits in SCR register */ 00972 tamp->SCR = Tamper; 00973 00974 /* Clear the selected tamper configuration (trigger, mask flag, and no-erase) */ 00975 tamp->CR2 &= ~((Tamper << TAMP_CR2_TAMP1TRG_Pos) | (Tamper << TAMP_CR2_TAMP1MSK_Pos) | (Tamper << TAMP_CR2_TAMP1NOERASE_Pos)); 00976 00977 return HAL_OK; 00978 } 00979 #endif /* TAMP_CR1_TAMP1E */ 00980 #if defined(RTC_TAMPCR_TAMP1E) 00981 /** 00982 * @brief Deactivate Tamper. 00983 * @param hrtc RTC handle 00984 * @param Tamper Selected tamper pin. 00985 * This parameter can be any combination of the following values: 00986 * @arg RTC_TAMPER_1 00987 * @arg RTC_TAMPER_2 00988 * @arg RTC_TAMPER_3 00989 * @retval HAL status 00990 */ 00991 HAL_StatusTypeDef HAL_RTCEx_DeactivateTamper(RTC_HandleTypeDef * hrtc, uint32_t Tamper) 00992 { 00993 assert_param(IS_RTC_TAMPER(Tamper)); 00994 00995 /* Process Locked */ 00996 __HAL_LOCK(hrtc); 00997 00998 hrtc->State = HAL_RTC_STATE_BUSY; 00999 01000 /* Disable the selected Tamper pin */ 01001 hrtc->Instance->TAMPCR &= ((uint32_t)~Tamper); 01002 01003 /* Disable the selected Tamper interrupt */ 01004 #if defined(RTC_TAMPCR_TAMP1E) 01005 if ((Tamper & RTC_TAMPER_1) != 0U) 01006 { 01007 hrtc->Instance->TAMPCR &= ((uint32_t)~(RTC_IT_TAMP | RTC_IT_TAMP1)); 01008 } 01009 #endif /* RTC_TAMPCR_TAMP1E */ 01010 #if defined(RTC_TAMPCR_TAMP2E) 01011 if ((Tamper & RTC_TAMPER_2) != 0U) 01012 { 01013 hrtc->Instance->TAMPCR &= ((uint32_t)~(RTC_IT_TAMP | RTC_IT_TAMP2)); 01014 } 01015 #endif /* RTC_TAMPCR_TAMP2E */ 01016 #if defined(RTC_TAMPCR_TAMP3E) 01017 if ((Tamper & RTC_TAMPER_3) != 0U) 01018 { 01019 hrtc->Instance->TAMPCR &= ((uint32_t)~(RTC_IT_TAMP | RTC_IT_TAMP3)); 01020 } 01021 #endif /* RTC_TAMPCR_TAMP3E */ 01022 01023 hrtc->State = HAL_RTC_STATE_READY; 01024 01025 /* Process Unlocked */ 01026 __HAL_UNLOCK(hrtc); 01027 01028 return HAL_OK; 01029 } 01030 #endif /* RTC_TAMPCR_TAMP1E */ 01031 01032 #if defined(TAMP_CR1_ITAMP1E) 01033 /** 01034 * @brief Set Internal Tamper 01035 * @param hrtc RTC handle 01036 * @param sIntTamper Pointer to Internal Tamper Structure. 01037 * @retval HAL status 01038 */ 01039 HAL_StatusTypeDef HAL_RTCEx_SetInternalTamper(RTC_HandleTypeDef *hrtc, RTC_InternalTamperTypeDef *sIntTamper) 01040 { 01041 /* Check the parameters */ 01042 assert_param(IS_RTC_INTERNAL_TAMPER(sIntTamper->IntTamper)); 01043 assert_param(IS_RTC_TAMPER_TIMESTAMPONTAMPER_DETECTION(sIntTamper->TimeStampOnTamperDetection)); 01044 01045 /* Time-Stamp on internal tamper */ 01046 if (READ_BIT(RTC->CR, RTC_CR_TAMPTS) != sIntTamper->TimeStampOnTamperDetection) 01047 { 01048 __HAL_RTC_WRITEPROTECTION_DISABLE(hrtc); 01049 MODIFY_REG(RTC->CR, RTC_CR_TAMPTS, sIntTamper->TimeStampOnTamperDetection); 01050 __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc); 01051 } 01052 01053 /* Control register 1 */ 01054 SET_BIT(TAMP->CR1, sIntTamper->IntTamper); 01055 01056 return HAL_OK; 01057 } 01058 01059 /** 01060 * @brief Set Internal Tamper in interrupt mode 01061 * @param hrtc RTC handle 01062 * @param sIntTamper Pointer to Internal Tamper Structure. 01063 * @retval HAL status 01064 */ 01065 HAL_StatusTypeDef HAL_RTCEx_SetInternalTamper_IT(RTC_HandleTypeDef *hrtc, RTC_InternalTamperTypeDef *sIntTamper) 01066 { 01067 /* Check the parameters */ 01068 assert_param(IS_RTC_INTERNAL_TAMPER(sIntTamper->IntTamper)); 01069 assert_param(IS_RTC_TAMPER_TIMESTAMPONTAMPER_DETECTION(sIntTamper->TimeStampOnTamperDetection)); 01070 01071 /* Time-stamp on internal tamper */ 01072 if (READ_BIT(RTC->CR, RTC_CR_TAMPTS) != sIntTamper->TimeStampOnTamperDetection) 01073 { 01074 __HAL_RTC_WRITEPROTECTION_DISABLE(hrtc); 01075 MODIFY_REG(RTC->CR, RTC_CR_TAMPTS, sIntTamper->TimeStampOnTamperDetection); 01076 __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc); 01077 } 01078 01079 /* RTC Tamper Interrupt Configuration: EXTI configuration */ 01080 __HAL_RTC_TAMPER_TIMESTAMP_EXTI_ENABLE_IT(); 01081 __HAL_RTC_TAMPER_TIMESTAMP_EXTI_ENABLE_RISING_FALLING_EDGE(); 01082 /* Interrupt enable register */ 01083 SET_BIT(TAMP->IER, sIntTamper->IntTamper); 01084 01085 /* Control register 1 */ 01086 SET_BIT(TAMP->CR1, sIntTamper->IntTamper); 01087 01088 return HAL_OK; 01089 } 01090 01091 /** 01092 * @brief Deactivate Internal Tamper. 01093 * @param hrtc RTC handle 01094 * @param IntTamper Selected internal tamper event. 01095 * This parameter can be any combination of existing internal tampers. 01096 * @retval HAL status 01097 */ 01098 HAL_StatusTypeDef HAL_RTCEx_DeactivateInternalTamper(RTC_HandleTypeDef *hrtc, uint32_t IntTamper) 01099 { 01100 UNUSED(hrtc); 01101 assert_param(IS_RTC_INTERNAL_TAMPER(IntTamper)); 01102 01103 /* Disable the selected Tamper pin */ 01104 CLEAR_BIT(TAMP->CR1, IntTamper); 01105 01106 /* Clear internal tamper interrupt mode configuration */ 01107 CLEAR_BIT(TAMP->IER, IntTamper); 01108 01109 /* Clear internal tamper interrupt */ 01110 WRITE_REG(TAMP->SCR, IntTamper); 01111 01112 return HAL_OK; 01113 } 01114 #endif /* TAMP_CR1_ITAMP1E */ 01115 01116 #if defined(TAMP_ATCR1_TAMP1AM) 01117 /** 01118 * @brief Set all active Tampers at the same time. 01119 * @param hrtc RTC handle 01120 * @param sAllTamper Pointer to active Tamper Structure. 01121 * @retval HAL status 01122 */ 01123 HAL_StatusTypeDef HAL_RTCEx_SetActiveTampers(RTC_HandleTypeDef *hrtc, RTC_ActiveTampersTypeDef *sAllTamper) 01124 { 01125 uint32_t IER, CR1, CR2, ATCR1, CR, i, tickstart; 01126 01127 #ifdef USE_FULL_ASSERT 01128 for (i = 0; i < RTC_TAMP_NB; i++) 01129 { 01130 assert_param(IS_RTC_TAMPER_ERASE_MODE(sAllTamper->TampInput[i].NoErase)); 01131 assert_param(IS_RTC_TAMPER_MASKFLAG_STATE(sAllTamper->TampInput[i].MaskFlag)); 01132 /* Mask flag only supported by TAMPER 1, 2 and 3 */ 01133 assert_param(!((sAllTamper->TampInput[i].MaskFlag != RTC_TAMPERMASK_FLAG_DISABLE) && (i > RTC_TAMPER_3))); 01134 } 01135 assert_param(IS_RTC_TAMPER_TIMESTAMPONTAMPER_DETECTION(sAllTamper->TimeStampOnTamperDetection)); 01136 #endif /* #ifdef USE_FULL_ASSERT */ 01137 01138 /* Active Tampers must not be already enabled */ 01139 if (READ_BIT(TAMP->ATOR, TAMP_ATOR_INITS) != 0U) 01140 { 01141 /* Disable all active tampers with HAL_RTCEx_DeactivateActiveTampers */ 01142 if (HAL_RTCEx_DeactivateActiveTampers(hrtc) != HAL_OK) 01143 { 01144 return HAL_ERROR; 01145 } 01146 } 01147 01148 /* Set TimeStamp on tamper detection */ 01149 CR = READ_REG(RTC->CR); 01150 if ((CR & RTC_CR_TAMPTS) != (sAllTamper->TimeStampOnTamperDetection)) 01151 { 01152 __HAL_RTC_WRITEPROTECTION_DISABLE(hrtc); 01153 MODIFY_REG(RTC->CR, RTC_CR_TAMPTS, sAllTamper->TimeStampOnTamperDetection); 01154 __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc); 01155 } 01156 01157 CR1 = READ_REG(TAMP->CR1); 01158 CR2 = READ_REG(TAMP->CR2); 01159 IER = READ_REG(TAMP->IER); 01160 01161 /* Set common parameters */ 01162 ATCR1 = (sAllTamper->ActiveFilter | (sAllTamper->ActiveOutputChangePeriod << TAMP_ATCR1_ATPER_Pos) | sAllTamper->ActiveAsyncPrescaler); 01163 01164 /* Set specific parameters for each active tamper inputs if enable */ 01165 for (i = 0; i < RTC_TAMP_NB; i++) 01166 { 01167 if (sAllTamper->TampInput[i].Enable != RTC_ATAMP_DISABLE) 01168 { 01169 CR1 |= (TAMP_CR1_TAMP1E << i); 01170 ATCR1 |= (TAMP_ATCR1_TAMP1AM << i); 01171 01172 if (sAllTamper->TampInput[i].Interrupt != RTC_ATAMP_INTERRUPT_DISABLE) 01173 { 01174 /* RTC Tamper Interrupt Configuration: EXTI configuration */ 01175 __HAL_RTC_TAMPER_TIMESTAMP_EXTI_ENABLE_IT(); 01176 __HAL_RTC_TAMPER_TIMESTAMP_EXTI_ENABLE_RISING_EDGE(); 01177 01178 /* Interrupt enable register */ 01179 IER |= (TAMP_IER_TAMP1IE << i); 01180 } 01181 01182 if (sAllTamper->TampInput[i].MaskFlag != RTC_TAMPERMASK_FLAG_DISABLE) 01183 { 01184 CR2 |= (TAMP_CR2_TAMP1MSK << i); 01185 } 01186 01187 if (sAllTamper->TampInput[i].NoErase != RTC_TAMPER_ERASE_BACKUP_ENABLE) 01188 { 01189 CR2 |= (TAMP_CR2_TAMP1NOERASE << i); 01190 } 01191 01192 /* Set ATOSHARE and configure ATOSELx[] in case of output sharing */ 01193 if (sAllTamper->TampInput[i].Output != i) 01194 { 01195 ATCR1 |= TAMP_ATCR1_ATOSHARE; 01196 ATCR1 |= sAllTamper->TampInput[i].Output << ((2u * i) + TAMP_ATCR1_ATOSEL1_Pos); 01197 } 01198 } 01199 } 01200 01201 WRITE_REG(TAMP->IER, IER); 01202 WRITE_REG(TAMP->IER, IER); 01203 WRITE_REG(TAMP->ATCR1, ATCR1); 01204 #if defined(TAMP_ATCR2_ATOSEL1) 01205 WRITE_REG(TAMP->ATCR2, ATCR2); 01206 #endif /* TAMP_ATCR2_ATOSEL1 */ 01207 WRITE_REG(TAMP->CR2, CR2); 01208 WRITE_REG(TAMP->CR1, CR1); 01209 01210 /* Write seed */ 01211 for (i = 0; i < RTC_ATAMP_SEED_NB_UINT32; i++) 01212 { 01213 WRITE_REG(TAMP->ATSEEDR, sAllTamper->Seed[i]); 01214 } 01215 01216 /* Wait till RTC SEEDF flag is set and if Time out is reached exit */ 01217 tickstart = HAL_GetTick(); 01218 while (READ_BIT(TAMP->ATOR, TAMP_ATOR_SEEDF) != 0u) 01219 { 01220 if ((HAL_GetTick() - tickstart) > RTC_TIMEOUT_VALUE) 01221 { 01222 hrtc->State = HAL_RTC_STATE_TIMEOUT; 01223 return HAL_TIMEOUT; 01224 } 01225 } 01226 01227 return HAL_OK; 01228 } 01229 #endif /* TAMP_ATCR1_TAMP1AM */ 01230 01231 #if defined(TAMP_ATSEEDR_SEED) 01232 /** 01233 * @brief Write a new seed. Active tamper must be enabled. 01234 * @param hrtc RTC handle 01235 * @param pSeed Pointer to active tamper seed values. 01236 * @retval HAL status 01237 */ 01238 HAL_StatusTypeDef HAL_RTCEx_SetActiveSeed(RTC_HandleTypeDef *hrtc, uint32_t *pSeed) 01239 { 01240 uint32_t i, tickstart; 01241 01242 /* Active Tampers must be enabled */ 01243 if (READ_BIT(TAMP->ATOR, TAMP_ATOR_INITS) == 0U) 01244 { 01245 return HAL_ERROR; 01246 } 01247 01248 for (i = 0; i < RTC_ATAMP_SEED_NB_UINT32; i++) 01249 { 01250 WRITE_REG(TAMP->ATSEEDR, pSeed[i]); 01251 } 01252 01253 /* Wait till RTC SEEDF flag is set and if Time out is reached exit */ 01254 tickstart = HAL_GetTick(); 01255 while (READ_BIT(TAMP->ATOR, TAMP_ATOR_SEEDF) != 0U) 01256 { 01257 if ((HAL_GetTick() - tickstart) > RTC_TIMEOUT_VALUE) 01258 { 01259 hrtc->State = HAL_RTC_STATE_TIMEOUT; 01260 return HAL_TIMEOUT; 01261 } 01262 } 01263 01264 return HAL_OK; 01265 } 01266 #endif /* TAMP_ATSEEDR_SEED */ 01267 01268 #if defined(TAMP_ATCR1_TAMP1AM) 01269 /** 01270 * @brief Deactivate all Active Tampers at the same time. 01271 * @param hrtc RTC handle 01272 * @retval HAL status 01273 */ 01274 HAL_StatusTypeDef HAL_RTCEx_DeactivateActiveTampers(RTC_HandleTypeDef *hrtc) 01275 { 01276 /* Get Active tampers */ 01277 uint32_t ATamp_mask = READ_BIT(TAMP->ATCR1, TAMP_ALL); 01278 01279 UNUSED(hrtc); 01280 /* Disable all actives tampers but not passives tampers */ 01281 CLEAR_BIT(TAMP->CR1, ATamp_mask); 01282 /* Disable no erase and mask */ 01283 CLEAR_BIT(TAMP->CR2, (ATamp_mask | ((ATamp_mask & (TAMP_ATCR1_TAMP1AM | TAMP_ATCR1_TAMP2AM | TAMP_ATCR1_TAMP3AM)) << TAMP_CR2_TAMP1MSK_Pos))); 01284 01285 /* Clear tamper interrupt and event flags (WO register) of all actives tampers but not passives tampers */ 01286 WRITE_REG(TAMP->SCR, ATamp_mask); 01287 01288 /* Clear all active tampers interrupt mode configuration but not passives tampers */ 01289 CLEAR_BIT(TAMP->IER, ATamp_mask); 01290 01291 CLEAR_BIT(TAMP->ATCR1, TAMP_ALL | TAMP_ATCR1_ATCKSEL | TAMP_ATCR1_ATPER | \ 01292 TAMP_ATCR1_ATOSHARE | TAMP_ATCR1_FLTEN); 01293 01294 #if defined(TAMP_ATCR2_ATOSEL1) 01295 CLEAR_BIT(TAMP->ATCR2, TAMP_ATCR2_ATOSEL1 | TAMP_ATCR2_ATOSEL2 | TAMP_ATCR2_ATOSEL3 | TAMP_ATCR2_ATOSEL4 | 01296 TAMP_ATCR2_ATOSEL5 | TAMP_ATCR2_ATOSEL6 | TAMP_ATCR2_ATOSEL7 | TAMP_ATCR2_ATOSEL8); 01297 #endif /* TAMP_ATCR2_ATOSEL1 */ 01298 01299 return HAL_OK; 01300 } 01301 #endif /* TAMP_ATCR1_TAMP1AM */ 01302 01303 /** 01304 * @} 01305 */ 01306 01307 /** @addtogroup RTCEx_Exported_Functions_Group1 01308 * @brief RTC TimeStamp and Tamper functions 01309 * 01310 * @{ 01311 */ 01312 01313 /** 01314 * @brief Handle TimeStamp interrupt request. 01315 * @param hrtc RTC handle 01316 * @retval None 01317 */ 01318 #if defined(RTC_MISR_TSMF) 01319 void HAL_RTCEx_TamperTimeStampIRQHandler(RTC_HandleTypeDef *hrtc) 01320 { 01321 01322 /* Point on TAMPER registers base address */ 01323 TAMP_TypeDef *tamp = (TAMP_TypeDef *)((uint32_t)hrtc->Instance + TAMP_OFFSET); 01324 01325 /* Clear the EXTI's Flag for RTC TimeStamp and Tamper */ 01326 __HAL_RTC_TAMPER_TIMESTAMP_EXTI_CLEAR_FLAG(); 01327 01328 if ((hrtc->Instance->MISR & RTC_MISR_TSMF) != 0u) 01329 { 01330 #if (USE_HAL_RTC_REGISTER_CALLBACKS == 1) 01331 /* Call TimeStampEvent registered Callback */ 01332 hrtc->TimeStampEventCallback(hrtc); 01333 #else 01334 HAL_RTCEx_TimeStampEventCallback(hrtc); 01335 #endif /* USE_HAL_RTC_REGISTER_CALLBACKS */ 01336 /* Not immediately clear flags because the content of RTC_TSTR and RTC_TSDR are cleared when TSF bit is reset.*/ 01337 hrtc->Instance->SCR = RTC_SCR_CTSF; 01338 } 01339 01340 /* Get interrupt status */ 01341 uint32_t tmp = tamp->MISR; 01342 01343 /* Immediately clear flags */ 01344 tamp->SCR = tmp; 01345 01346 #if defined(TAMP_CR1_TAMP1E) 01347 /* Check Tamper1 status */ 01348 if ((tmp & RTC_TAMPER_1) == RTC_TAMPER_1) 01349 { 01350 #if (USE_HAL_RTC_REGISTER_CALLBACKS == 1) 01351 /* Call Tamper 1 Event registered Callback */ 01352 hrtc->Tamper1EventCallback(hrtc); 01353 #else 01354 /* Tamper1 callback */ 01355 HAL_RTCEx_Tamper1EventCallback(hrtc); 01356 #endif /* USE_HAL_RTC_REGISTER_CALLBACKS */ 01357 } 01358 #endif /* TAMP_CR1_TAMP1E */ 01359 01360 #if defined(TAMP_CR1_TAMP2E) 01361 /* Check Tamper2 status */ 01362 if ((tmp & RTC_TAMPER_2) == RTC_TAMPER_2) 01363 { 01364 #if (USE_HAL_RTC_REGISTER_CALLBACKS == 1) 01365 /* Call Tamper 2 Event registered Callback */ 01366 hrtc->Tamper2EventCallback(hrtc); 01367 #else 01368 /* Tamper2 callback */ 01369 HAL_RTCEx_Tamper2EventCallback(hrtc); 01370 #endif /* USE_HAL_RTC_REGISTER_CALLBACKS */ 01371 } 01372 #endif /* TAMP_CR1_TAMP2E */ 01373 01374 #if defined(TAMP_CR1_TAMP3E) 01375 /* Check Tamper3 status */ 01376 if ((tmp & RTC_TAMPER_3) == RTC_TAMPER_3) 01377 { 01378 #if (USE_HAL_RTC_REGISTER_CALLBACKS == 1) 01379 /* Call Tamper 3 Event registered Callback */ 01380 hrtc->Tamper3EventCallback(hrtc); 01381 #else 01382 /* Tamper3 callback */ 01383 HAL_RTCEx_Tamper3EventCallback(hrtc); 01384 #endif /* USE_HAL_RTC_REGISTER_CALLBACKS */ 01385 } 01386 #endif /* TAMP_CR1_TAMP3E */ 01387 01388 #if defined(TAMP_CR1_ITAMP1E) 01389 /* Check Internal Tamper status */ 01390 if ((tmp & RTC_INT_TAMPER_1) == RTC_INT_TAMPER_1) 01391 { 01392 #if (USE_HAL_RTC_REGISTER_CALLBACKS == 1) 01393 /* Call Internal Tamper Event registered callback */ 01394 hrtc->InternalTamper1EventCallback(hrtc); 01395 #else 01396 /* Call Internal Tamper Event by-default callback */ 01397 HAL_RTCEx_InternalTamper1EventCallback(hrtc); 01398 #endif /* USE_HAL_RTC_REGISTER_CALLBACKS */ 01399 } 01400 #endif /* TAMP_CR1_ITAMP1E */ 01401 01402 #if defined(TAMP_CR1_ITAMP2E) 01403 /* Check Internal Tamper status */ 01404 if ((tmp & RTC_INT_TAMPER_2) == RTC_INT_TAMPER_2) 01405 { 01406 #if (USE_HAL_RTC_REGISTER_CALLBACKS == 1) 01407 /* Call Internal Tamper Event registered callback */ 01408 hrtc->InternalTamper2EventCallback(hrtc); 01409 #else 01410 /* Call Internal Tamper Event by-default callback */ 01411 HAL_RTCEx_InternalTamper2EventCallback(hrtc); 01412 #endif /* USE_HAL_RTC_REGISTER_CALLBACKS */ 01413 } 01414 #endif /* TAMP_CR1_ITAMP2E */ 01415 01416 #if defined(TAMP_CR1_ITAMP3E) 01417 /* Check Internal Tamper status */ 01418 if ((tmp & RTC_INT_TAMPER_3) == RTC_INT_TAMPER_3) 01419 { 01420 #if (USE_HAL_RTC_REGISTER_CALLBACKS == 1) 01421 /* Call Internal Tamper Event registered callback */ 01422 hrtc->InternalTamper3EventCallback(hrtc); 01423 #else 01424 /* Call Internal Tamper Event by-default callback */ 01425 HAL_RTCEx_InternalTamper3EventCallback(hrtc); 01426 #endif /* USE_HAL_RTC_REGISTER_CALLBACKS */ 01427 } 01428 #endif /* TAMP_CR1_ITAMP3E */ 01429 01430 #if defined(TAMP_CR1_ITAMP4E) 01431 /* Check Internal Tamper status */ 01432 if ((tmp & RTC_INT_TAMPER_4) == RTC_INT_TAMPER_4) 01433 { 01434 #if (USE_HAL_RTC_REGISTER_CALLBACKS == 1) 01435 /* Call Internal Tamper Event registered callback */ 01436 hrtc->InternalTamper4EventCallback(hrtc); 01437 #else 01438 /* Call Internal Tamper Event by-default callback */ 01439 HAL_RTCEx_InternalTamper4EventCallback(hrtc); 01440 #endif /* USE_HAL_RTC_REGISTER_CALLBACKS */ 01441 } 01442 #endif /* TAMP_CR1_ITAMP4E */ 01443 01444 #if defined(TAMP_CR1_ITAMP5E) 01445 /* Check Internal Tamper status */ 01446 if ((tmp & RTC_INT_TAMPER_5) == RTC_INT_TAMPER_5) 01447 { 01448 #if (USE_HAL_RTC_REGISTER_CALLBACKS == 1) 01449 /* Call Internal Tamper Event registered callback */ 01450 hrtc->InternalTamper5EventCallback(hrtc); 01451 #else 01452 /* Call Internal Tamper Event by-default callback */ 01453 HAL_RTCEx_InternalTamper5EventCallback(hrtc); 01454 #endif /* USE_HAL_RTC_REGISTER_CALLBACKS */ 01455 } 01456 #endif /* TAMP_CR1_ITAMP5E */ 01457 01458 #if defined(TAMP_CR1_ITAMP6E) 01459 /* Check Internal Tamper status */ 01460 if ((tmp & RTC_INT_TAMPER_6) == RTC_INT_TAMPER_6) 01461 { 01462 #if (USE_HAL_RTC_REGISTER_CALLBACKS == 1) 01463 /* Call Internal Tamper Event registered callback */ 01464 hrtc->InternalTamper6EventCallback(hrtc); 01465 #else 01466 /* Call Internal Tamper Event by-default callback */ 01467 HAL_RTCEx_InternalTamper6EventCallback(hrtc); 01468 #endif /* USE_HAL_RTC_REGISTER_CALLBACKS */ 01469 } 01470 #endif /* TAMP_CR1_ITAMP6E */ 01471 01472 #if defined(TAMP_CR1_ITAMP8E) 01473 /* Check Internal Tamper status */ 01474 if ((tmp & RTC_INT_TAMPER_8) == RTC_INT_TAMPER_8) 01475 { 01476 #if (USE_HAL_RTC_REGISTER_CALLBACKS == 1) 01477 /* Call Internal Tamper Event registered callback */ 01478 hrtc->InternalTamper8EventCallback(hrtc); 01479 #else 01480 /* Call Internal Tamper Event by-default callback */ 01481 HAL_RTCEx_InternalTamper8EventCallback(hrtc); 01482 #endif /* USE_HAL_RTC_REGISTER_CALLBACKS */ 01483 } 01484 #endif /* TAMP_CR1_ITAMP8E */ 01485 01486 /* Change RTC state */ 01487 hrtc->State = HAL_RTC_STATE_READY; 01488 } 01489 #endif /* RTC_MISR_TSMF */ 01490 #if defined(RTC_ISR_TSF) 01491 void HAL_RTCEx_TamperTimeStampIRQHandler(RTC_HandleTypeDef *hrtc) 01492 { 01493 /* Clear the EXTI's Flag for RTC TimeStamp and Tamper */ 01494 #if defined(DUAL_CORE) 01495 if (HAL_GetCurrentCPUID() == CM7_CPUID) 01496 { 01497 __HAL_RTC_TAMPER_TIMESTAMP_EXTI_CLEAR_FLAG(); 01498 } 01499 else 01500 { 01501 __HAL_RTC_TAMPER_TIMESTAMP_EXTID2_CLEAR_FLAG(); 01502 } 01503 #else /* SINGLE_CORE */ 01504 __HAL_RTC_TAMPER_TIMESTAMP_EXTI_CLEAR_FLAG(); 01505 #endif /* DUAL_CORE */ 01506 01507 /* Get the TimeStamp interrupt source enable status */ 01508 if (__HAL_RTC_TIMESTAMP_GET_IT_SOURCE(hrtc, RTC_IT_TS) != 0U) 01509 { 01510 /* Get the pending status of the TIMESTAMP Interrupt */ 01511 if (__HAL_RTC_TIMESTAMP_GET_FLAG(hrtc, RTC_FLAG_TSF) != 0U) 01512 { 01513 /* TIMESTAMP callback */ 01514 #if (USE_HAL_RTC_REGISTER_CALLBACKS == 1) 01515 hrtc->TimeStampEventCallback(hrtc); 01516 #else /* (USE_HAL_RTC_REGISTER_CALLBACKS == 1) */ 01517 HAL_RTCEx_TimeStampEventCallback(hrtc); 01518 #endif /* (USE_HAL_RTC_REGISTER_CALLBACKS == 1) */ 01519 01520 /* Clear the TIMESTAMP interrupt pending bit (this will clear timestamp time and date registers) */ 01521 __HAL_RTC_TIMESTAMP_CLEAR_FLAG(hrtc, RTC_FLAG_TSF); 01522 } 01523 } 01524 01525 #if defined(RTC_TAMPCR_TAMP1E) 01526 /* Get the Tamper1 interrupt source enable status */ 01527 if (__HAL_RTC_TAMPER_GET_IT_SOURCE(hrtc, RTC_IT_TAMP | RTC_IT_TAMP1) != 0U) 01528 { 01529 /* Get the pending status of the Tamper1 Interrupt */ 01530 if (__HAL_RTC_TAMPER_GET_FLAG(hrtc, RTC_FLAG_TAMP1F) != 0U) 01531 { 01532 /* Clear the Tamper1 interrupt pending bit */ 01533 __HAL_RTC_TAMPER_CLEAR_FLAG(hrtc, RTC_FLAG_TAMP1F); 01534 01535 /* Tamper1 callback */ 01536 #if (USE_HAL_RTC_REGISTER_CALLBACKS == 1) 01537 hrtc->Tamper1EventCallback(hrtc); 01538 #else /* (USE_HAL_RTC_REGISTER_CALLBACKS == 1) */ 01539 HAL_RTCEx_Tamper1EventCallback(hrtc); 01540 #endif /* (USE_HAL_RTC_REGISTER_CALLBACKS == 1) */ 01541 } 01542 } 01543 #endif /* RTC_TAMPCR_TAMP1E */ 01544 01545 #if defined(RTC_TAMPCR_TAMP2E) 01546 /* Get the Tamper2 interrupt source enable status */ 01547 if (__HAL_RTC_TAMPER_GET_IT_SOURCE(hrtc, RTC_IT_TAMP | RTC_IT_TAMP2) != 0U) 01548 { 01549 /* Get the pending status of the Tamper2 Interrupt */ 01550 if (__HAL_RTC_TAMPER_GET_FLAG(hrtc, RTC_FLAG_TAMP2F) != 0U) 01551 { 01552 /* Clear the Tamper2 interrupt pending bit */ 01553 __HAL_RTC_TAMPER_CLEAR_FLAG(hrtc, RTC_FLAG_TAMP2F); 01554 01555 /* Tamper2 callback */ 01556 #if (USE_HAL_RTC_REGISTER_CALLBACKS == 1) 01557 hrtc->Tamper2EventCallback(hrtc); 01558 #else /* (USE_HAL_RTC_REGISTER_CALLBACKS == 1) */ 01559 HAL_RTCEx_Tamper2EventCallback(hrtc); 01560 #endif /* (USE_HAL_RTC_REGISTER_CALLBACKS == 1) */ 01561 } 01562 } 01563 #endif /* RTC_TAMPCR_TAMP2E */ 01564 01565 #if defined(RTC_TAMPCR_TAMP3E) 01566 /* Get the Tamper3 interrupts source enable status */ 01567 if (__HAL_RTC_TAMPER_GET_IT_SOURCE(hrtc, RTC_IT_TAMP | RTC_IT_TAMP3) != 0U) 01568 { 01569 /* Get the pending status of the Tamper3 Interrupt */ 01570 if (__HAL_RTC_TAMPER_GET_FLAG(hrtc, RTC_FLAG_TAMP3F) != 0U) 01571 { 01572 /* Clear the Tamper3 interrupt pending bit */ 01573 __HAL_RTC_TAMPER_CLEAR_FLAG(hrtc, RTC_FLAG_TAMP3F); 01574 01575 /* Tamper3 callback */ 01576 #if (USE_HAL_RTC_REGISTER_CALLBACKS == 1) 01577 hrtc->Tamper3EventCallback(hrtc); 01578 #else /* (USE_HAL_RTC_REGISTER_CALLBACKS == 1) */ 01579 HAL_RTCEx_Tamper3EventCallback(hrtc); 01580 #endif /* (USE_HAL_RTC_REGISTER_CALLBACKS == 1) */ 01581 } 01582 } 01583 #endif /* RTC_TAMPCR_TAMP3E */ 01584 01585 /* Change RTC state */ 01586 hrtc->State = HAL_RTC_STATE_READY; 01587 } 01588 #endif /* RTC_ISR_TSF */ 01589 01590 /** 01591 * @brief TimeStamp callback. 01592 * @param hrtc RTC handle 01593 * @retval None 01594 */ 01595 __weak void HAL_RTCEx_TimeStampEventCallback(RTC_HandleTypeDef *hrtc) 01596 { 01597 /* Prevent unused argument(s) compilation warning */ 01598 UNUSED(hrtc); 01599 01600 /* NOTE : This function should not be modified, when the callback is needed, 01601 the HAL_RTCEx_TimeStampEventCallback could be implemented in the user file 01602 */ 01603 } 01604 01605 /** 01606 * @} 01607 */ 01608 01609 /** @addtogroup RTCEx_Exported_Functions_Group5 01610 * @brief Extended RTC Tamper functions 01611 * 01612 * @{ 01613 */ 01614 01615 #if defined(RTC_TAMPER_1) 01616 /** 01617 * @brief Tamper 1 callback. 01618 * @param hrtc RTC handle 01619 * @retval None 01620 */ 01621 __weak void HAL_RTCEx_Tamper1EventCallback(RTC_HandleTypeDef * hrtc) 01622 { 01623 /* Prevent unused argument(s) compilation warning */ 01624 UNUSED(hrtc); 01625 01626 /* NOTE : This function should not be modified, when the callback is needed, 01627 the HAL_RTCEx_Tamper1EventCallback could be implemented in the user file 01628 */ 01629 } 01630 #endif /* RTC_TAMPER_1 */ 01631 01632 #if defined(RTC_TAMPER_2) 01633 /** 01634 * @brief Tamper 2 callback. 01635 * @param hrtc RTC handle 01636 * @retval None 01637 */ 01638 __weak void HAL_RTCEx_Tamper2EventCallback(RTC_HandleTypeDef * hrtc) 01639 { 01640 /* Prevent unused argument(s) compilation warning */ 01641 UNUSED(hrtc); 01642 01643 /* NOTE : This function should not be modified, when the callback is needed, 01644 the HAL_RTCEx_Tamper2EventCallback could be implemented in the user file 01645 */ 01646 } 01647 #endif /* RTC_TAMPER_2 */ 01648 01649 #if defined(RTC_TAMPER_3) 01650 /** 01651 * @brief Tamper 3 callback. 01652 * @param hrtc RTC handle 01653 * @retval None 01654 */ 01655 __weak void HAL_RTCEx_Tamper3EventCallback(RTC_HandleTypeDef * hrtc) 01656 { 01657 /* Prevent unused argument(s) compilation warning */ 01658 UNUSED(hrtc); 01659 01660 /* NOTE : This function should not be modified, when the callback is needed, 01661 the HAL_RTCEx_Tamper3EventCallback could be implemented in the user file 01662 */ 01663 } 01664 #endif /* RTC_TAMPER_3 */ 01665 01666 /** 01667 * @brief Internal Tamper 1 callback. 01668 * @param hrtc RTC handle 01669 * @retval None 01670 */ 01671 __weak void HAL_RTCEx_InternalTamper1EventCallback(RTC_HandleTypeDef *hrtc) 01672 { 01673 /* Prevent unused argument(s) compilation warning */ 01674 UNUSED(hrtc); 01675 01676 /* NOTE : This function should not be modified, when the callback is needed, 01677 the HAL_RTCEx_InternalTamper1EventCallback could be implemented in the user file 01678 */ 01679 } 01680 01681 /** 01682 * @brief Internal Tamper 2 callback. 01683 * @param hrtc RTC handle 01684 * @retval None 01685 */ 01686 __weak void HAL_RTCEx_InternalTamper2EventCallback(RTC_HandleTypeDef *hrtc) 01687 { 01688 /* Prevent unused argument(s) compilation warning */ 01689 UNUSED(hrtc); 01690 01691 /* NOTE : This function should not be modified, when the callback is needed, 01692 the HAL_RTCEx_InternalTamper2EventCallback could be implemented in the user file 01693 */ 01694 } 01695 01696 /** 01697 * @brief Internal Tamper 3 callback. 01698 * @param hrtc RTC handle 01699 * @retval None 01700 */ 01701 __weak void HAL_RTCEx_InternalTamper3EventCallback(RTC_HandleTypeDef *hrtc) 01702 { 01703 /* Prevent unused argument(s) compilation warning */ 01704 UNUSED(hrtc); 01705 01706 /* NOTE : This function should not be modified, when the callback is needed, 01707 the HAL_RTCEx_InternalTamper3EventCallback could be implemented in the user file 01708 */ 01709 } 01710 01711 /** 01712 * @brief Internal Tamper 4 callback. 01713 * @param hrtc RTC handle 01714 * @retval None 01715 */ 01716 __weak void HAL_RTCEx_InternalTamper4EventCallback(RTC_HandleTypeDef *hrtc) 01717 { 01718 /* Prevent unused argument(s) compilation warning */ 01719 UNUSED(hrtc); 01720 01721 /* NOTE : This function should not be modified, when the callback is needed, 01722 the HAL_RTCEx_InternalTamper4EventCallback could be implemented in the user file 01723 */ 01724 } 01725 01726 /** 01727 * @brief Internal Tamper 5 callback. 01728 * @param hrtc RTC handle 01729 * @retval None 01730 */ 01731 __weak void HAL_RTCEx_InternalTamper5EventCallback(RTC_HandleTypeDef *hrtc) 01732 { 01733 /* Prevent unused argument(s) compilation warning */ 01734 UNUSED(hrtc); 01735 01736 /* NOTE : This function should not be modified, when the callback is needed, 01737 the HAL_RTCEx_InternalTamper5EventCallback could be implemented in the user file 01738 */ 01739 } 01740 01741 /** 01742 * @brief Internal Tamper 6 callback. 01743 * @param hrtc RTC handle 01744 * @retval None 01745 */ 01746 __weak void HAL_RTCEx_InternalTamper6EventCallback(RTC_HandleTypeDef *hrtc) 01747 { 01748 /* Prevent unused argument(s) compilation warning */ 01749 UNUSED(hrtc); 01750 01751 /* NOTE : This function should not be modified, when the callback is needed, 01752 the HAL_RTCEx_InternalTamper6EventCallback could be implemented in the user file 01753 */ 01754 } 01755 01756 /** 01757 * @brief Internal Tamper 8 callback. 01758 * @param hrtc RTC handle 01759 * @retval None 01760 */ 01761 __weak void HAL_RTCEx_InternalTamper8EventCallback(RTC_HandleTypeDef *hrtc) 01762 { 01763 /* Prevent unused argument(s) compilation warning */ 01764 UNUSED(hrtc); 01765 01766 /* NOTE : This function should not be modified, when the callback is needed, 01767 the HAL_RTCEx_InternalTamper8EventCallback could be implemented in the user file 01768 */ 01769 } 01770 /** 01771 * @} 01772 */ 01773 01774 /** @addtogroup RTCEx_Exported_Functions_Group1 01775 * @brief RTC TimeStamp and Tamper functions 01776 * 01777 * @{ 01778 */ 01779 01780 /** 01781 * @brief Handle TimeStamp polling request. 01782 * @param hrtc RTC handle 01783 * @param Timeout Timeout duration 01784 * @retval HAL status 01785 */ 01786 HAL_StatusTypeDef HAL_RTCEx_PollForTimeStampEvent(RTC_HandleTypeDef *hrtc, uint32_t Timeout) 01787 { 01788 uint32_t tickstart = HAL_GetTick(); 01789 01790 while (__HAL_RTC_TIMESTAMP_GET_FLAG(hrtc, RTC_FLAG_TSF) == 0U) 01791 { 01792 if (__HAL_RTC_TIMESTAMP_GET_FLAG(hrtc, RTC_FLAG_TSOVF) != 0U) 01793 { 01794 /* Clear the TIMESTAMP OverRun Flag */ 01795 __HAL_RTC_TIMESTAMP_CLEAR_FLAG(hrtc, RTC_FLAG_TSOVF); 01796 01797 /* Change TIMESTAMP state */ 01798 hrtc->State = HAL_RTC_STATE_ERROR; 01799 01800 return HAL_ERROR; 01801 } 01802 01803 if (Timeout != HAL_MAX_DELAY) 01804 { 01805 if (((HAL_GetTick() - tickstart) > Timeout) || (Timeout == 0U)) 01806 { 01807 hrtc->State = HAL_RTC_STATE_TIMEOUT; 01808 return HAL_TIMEOUT; 01809 } 01810 } 01811 } 01812 01813 /* Change RTC state */ 01814 hrtc->State = HAL_RTC_STATE_READY; 01815 01816 return HAL_OK; 01817 } 01818 01819 /** 01820 * @} 01821 */ 01822 01823 /** @addtogroup RTCEx_Exported_Functions_Group5 01824 * @brief Extended RTC Tamper functions 01825 * 01826 * @{ 01827 */ 01828 01829 #if defined(RTC_TAMPER_1) 01830 /** 01831 * @brief Handle Tamper1 Polling. 01832 * @param hrtc RTC handle 01833 * @param Timeout Timeout duration 01834 * @retval HAL status 01835 */ 01836 HAL_StatusTypeDef HAL_RTCEx_PollForTamper1Event(RTC_HandleTypeDef * hrtc, uint32_t Timeout) 01837 { 01838 uint32_t tickstart = HAL_GetTick(); 01839 01840 /* Get the status of the Interrupt */ 01841 while (__HAL_RTC_TAMPER_GET_FLAG(hrtc, RTC_FLAG_TAMP1F) == 0U) 01842 { 01843 if (Timeout != HAL_MAX_DELAY) 01844 { 01845 if (((HAL_GetTick() - tickstart) > Timeout) || (Timeout == 0U)) 01846 { 01847 hrtc->State = HAL_RTC_STATE_TIMEOUT; 01848 return HAL_TIMEOUT; 01849 } 01850 } 01851 } 01852 01853 /* Clear the Tamper Flag */ 01854 __HAL_RTC_TAMPER_CLEAR_FLAG(hrtc, RTC_FLAG_TAMP1F); 01855 01856 /* Change RTC state */ 01857 hrtc->State = HAL_RTC_STATE_READY; 01858 01859 return HAL_OK; 01860 } 01861 #endif /* RTC_TAMPER_1 */ 01862 01863 #if defined(RTC_TAMPER_2) 01864 /** 01865 * @brief Handle Tamper2 Polling. 01866 * @param hrtc RTC handle 01867 * @param Timeout Timeout duration 01868 * @retval HAL status 01869 */ 01870 HAL_StatusTypeDef HAL_RTCEx_PollForTamper2Event(RTC_HandleTypeDef * hrtc, uint32_t Timeout) 01871 { 01872 uint32_t tickstart = HAL_GetTick(); 01873 01874 /* Get the status of the Interrupt */ 01875 while (__HAL_RTC_TAMPER_GET_FLAG(hrtc, RTC_FLAG_TAMP2F) == 0U) 01876 { 01877 if (Timeout != HAL_MAX_DELAY) 01878 { 01879 if (((HAL_GetTick() - tickstart) > Timeout) || (Timeout == 0U)) 01880 { 01881 hrtc->State = HAL_RTC_STATE_TIMEOUT; 01882 return HAL_TIMEOUT; 01883 } 01884 } 01885 } 01886 01887 /* Clear the Tamper Flag */ 01888 __HAL_RTC_TAMPER_CLEAR_FLAG(hrtc, RTC_FLAG_TAMP2F); 01889 01890 /* Change RTC state */ 01891 hrtc->State = HAL_RTC_STATE_READY; 01892 01893 return HAL_OK; 01894 } 01895 #endif /* RTC_TAMPER_2 */ 01896 01897 #if defined(RTC_TAMPER_3) 01898 /** 01899 * @brief Handle Tamper3 Polling. 01900 * @param hrtc RTC handle 01901 * @param Timeout Timeout duration 01902 * @retval HAL status 01903 */ 01904 HAL_StatusTypeDef HAL_RTCEx_PollForTamper3Event(RTC_HandleTypeDef * hrtc, uint32_t Timeout) 01905 { 01906 uint32_t tickstart = HAL_GetTick(); 01907 01908 /* Get the status of the Interrupt */ 01909 while (__HAL_RTC_TAMPER_GET_FLAG(hrtc, RTC_FLAG_TAMP3F) == 0U) 01910 { 01911 if (Timeout != HAL_MAX_DELAY) 01912 { 01913 if (((HAL_GetTick() - tickstart) > Timeout) || (Timeout == 0U)) 01914 { 01915 hrtc->State = HAL_RTC_STATE_TIMEOUT; 01916 return HAL_TIMEOUT; 01917 } 01918 } 01919 } 01920 01921 /* Clear the Tamper Flag */ 01922 __HAL_RTC_TAMPER_CLEAR_FLAG(hrtc, RTC_FLAG_TAMP3F); 01923 01924 /* Change RTC state */ 01925 hrtc->State = HAL_RTC_STATE_READY; 01926 01927 return HAL_OK; 01928 } 01929 #endif /* RTC_TAMPER_3 */ 01930 01931 #if defined(TAMP_CR1_ITAMP1E) 01932 /** 01933 * @brief Internal Tamper event polling. 01934 * @param hrtc RTC handle 01935 * @param IntTamper selected tamper. 01936 * This parameter can be any combination of existing internal tampers. 01937 * @param Timeout Timeout duration 01938 * @retval HAL status 01939 */ 01940 HAL_StatusTypeDef HAL_RTCEx_PollForInternalTamperEvent(RTC_HandleTypeDef *hrtc, uint32_t IntTamper, uint32_t Timeout) 01941 { 01942 UNUSED(hrtc); 01943 assert_param(IS_RTC_INTERNAL_TAMPER(IntTamper)); 01944 01945 uint32_t tickstart = HAL_GetTick(); 01946 01947 /* Get the status of the Interrupt */ 01948 while (READ_BIT(TAMP->SR, IntTamper) != IntTamper) 01949 { 01950 if (Timeout != HAL_MAX_DELAY) 01951 { 01952 if (((HAL_GetTick() - tickstart) > Timeout) || (Timeout == 0U)) 01953 { 01954 return HAL_TIMEOUT; 01955 } 01956 } 01957 } 01958 01959 /* Clear the Tamper Flag */ 01960 WRITE_REG(TAMP->SCR, IntTamper); 01961 01962 return HAL_OK; 01963 } 01964 #endif /* TAMP_CR1_ITAMP1E */ 01965 01966 /** 01967 * @} 01968 */ 01969 01970 /** @addtogroup RTCEx_Exported_Functions_Group2 01971 * @brief RTC Wake-up functions 01972 * 01973 @verbatim 01974 =============================================================================== 01975 ##### RTC Wake-up functions ##### 01976 =============================================================================== 01977 01978 [..] This section provides functions allowing to configure Wake-up feature 01979 01980 @endverbatim 01981 * @{ 01982 */ 01983 01984 /** 01985 * @brief Set wake up timer. 01986 * @param hrtc RTC handle 01987 * @param WakeUpCounter Wake up counter 01988 * @param WakeUpClock Wake up clock 01989 * @retval HAL status 01990 */ 01991 HAL_StatusTypeDef HAL_RTCEx_SetWakeUpTimer(RTC_HandleTypeDef *hrtc, uint32_t WakeUpCounter, uint32_t WakeUpClock) 01992 { 01993 uint32_t tickstart; 01994 01995 /* Check the parameters */ 01996 assert_param(IS_RTC_WAKEUP_CLOCK(WakeUpClock)); 01997 assert_param(IS_RTC_WAKEUP_COUNTER(WakeUpCounter)); 01998 01999 /* Process Locked */ 02000 __HAL_LOCK(hrtc); 02001 02002 hrtc->State = HAL_RTC_STATE_BUSY; 02003 02004 /* Disable the write protection for RTC registers */ 02005 __HAL_RTC_WRITEPROTECTION_DISABLE(hrtc); 02006 02007 /* Clear WUTE in RTC_CR to disable the wakeup timer */ 02008 CLEAR_BIT(RTC->CR, RTC_CR_WUTE); 02009 02010 /* Poll WUTWF until it is set in RTC_ICSR / RTC_ISR to make sure the access to wakeup autoreload 02011 counter and to WUCKSEL[2:0] bits is allowed. This step must be skipped in 02012 calendar initialization mode. */ 02013 #if defined(RTC_ISR_INITF) 02014 if (READ_BIT(RTC->ISR, RTC_ISR_INITF) == 0U) 02015 #endif /* RTC_ISR_INITF */ 02016 #if defined(RTC_ICSR_INITF) 02017 if (READ_BIT(RTC->ICSR, RTC_ICSR_INITF) == 0U) 02018 #endif /* RTC_ICSR_INITF */ 02019 { 02020 tickstart = HAL_GetTick(); 02021 02022 #if defined(RTC_ICSR_WUTWF) 02023 while (READ_BIT(hrtc->Instance->ICSR, RTC_FLAG_WUTWF) == 0U) 02024 #endif /* RTC_ICSR_WUTWF */ 02025 #if defined(RTC_ISR_WUTWF) 02026 while(__HAL_RTC_WAKEUPTIMER_GET_FLAG(hrtc, RTC_FLAG_WUTWF) == 0U) 02027 #endif /* RTC_ISR_WUTWF */ 02028 { 02029 if ((HAL_GetTick() - tickstart) > RTC_TIMEOUT_VALUE) 02030 { 02031 /* Enable the write protection for RTC registers */ 02032 __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc); 02033 02034 hrtc->State = HAL_RTC_STATE_TIMEOUT; 02035 02036 /* Process Unlocked */ 02037 __HAL_UNLOCK(hrtc); 02038 02039 return HAL_TIMEOUT; 02040 } 02041 } 02042 } 02043 02044 /* Clear the Wakeup Timer clock source bits and configure the clock source in CR register */ 02045 uint32_t CR_tmp = hrtc->Instance->CR; 02046 CR_tmp &= (uint32_t)~RTC_CR_WUCKSEL; 02047 CR_tmp |= (uint32_t)WakeUpClock; 02048 hrtc->Instance->CR = CR_tmp; 02049 02050 /* Configure the Wakeup Timer counter */ 02051 hrtc->Instance->WUTR = (uint32_t)WakeUpCounter; 02052 02053 /* Enable the Wakeup Timer */ 02054 __HAL_RTC_WAKEUPTIMER_ENABLE(hrtc); 02055 02056 /* Enable the write protection for RTC registers */ 02057 __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc); 02058 02059 hrtc->State = HAL_RTC_STATE_READY; 02060 02061 /* Process Unlocked */ 02062 __HAL_UNLOCK(hrtc); 02063 02064 return HAL_OK; 02065 } 02066 02067 /** 02068 * @brief Set wake up timer with interrupt. 02069 * @param hrtc RTC handle 02070 * @param WakeUpCounter Wake up counter 02071 * @param WakeUpClock Wake up clock 02072 * @retval HAL status 02073 */ 02074 HAL_StatusTypeDef HAL_RTCEx_SetWakeUpTimer_IT(RTC_HandleTypeDef *hrtc, uint32_t WakeUpCounter, uint32_t WakeUpClock) 02075 { 02076 uint32_t tickstart; 02077 02078 /* Check the parameters */ 02079 assert_param(IS_RTC_WAKEUP_CLOCK(WakeUpClock)); 02080 assert_param(IS_RTC_WAKEUP_COUNTER(WakeUpCounter)); 02081 02082 /* Process Locked */ 02083 __HAL_LOCK(hrtc); 02084 02085 hrtc->State = HAL_RTC_STATE_BUSY; 02086 02087 /* Disable the write protection for RTC registers */ 02088 __HAL_RTC_WRITEPROTECTION_DISABLE(hrtc); 02089 02090 /* Clear WUTE in RTC_CR to disable the wakeup timer */ 02091 CLEAR_BIT(RTC->CR, RTC_CR_WUTE); 02092 02093 /* Poll WUTWF until it is set in RTC_ICSR to make sure the access to wakeup autoreload 02094 counter and to WUCKSEL[2:0] bits is allowed. This step must be skipped in 02095 calendar initialization mode. */ 02096 #if defined(RTC_ISR_INITF) 02097 if (READ_BIT(RTC->ISR, RTC_ISR_INITF) == 0U) 02098 #endif /* RTC_ISR_INITF */ 02099 #if defined(RTC_ICSR_INITF) 02100 if (READ_BIT(RTC->ICSR, RTC_ICSR_INITF) == 0U) 02101 #endif /* RTC_ICSR_INITF */ 02102 { 02103 tickstart = HAL_GetTick(); 02104 02105 #if defined(RTC_ICSR_WUTWF) 02106 while (READ_BIT(hrtc->Instance->ICSR, RTC_FLAG_WUTWF) == 0U) 02107 #endif /* RTC_ICSR_WUTWF */ 02108 #if defined(RTC_ISR_WUTWF) 02109 while(__HAL_RTC_WAKEUPTIMER_GET_FLAG(hrtc, RTC_FLAG_WUTWF) == 0U) 02110 #endif /* RTC_ISR_WUTWF */ 02111 { 02112 if ((HAL_GetTick() - tickstart) > RTC_TIMEOUT_VALUE) 02113 { 02114 /* Enable the write protection for RTC registers */ 02115 __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc); 02116 02117 hrtc->State = HAL_RTC_STATE_TIMEOUT; 02118 02119 /* Process Unlocked */ 02120 __HAL_UNLOCK(hrtc); 02121 02122 return HAL_TIMEOUT; 02123 } 02124 } 02125 } 02126 02127 /* Configure the Wakeup Timer counter */ 02128 hrtc->Instance->WUTR = (uint32_t)WakeUpCounter; 02129 02130 /* Clear the Wakeup Timer clock source bits and configure the clock source in CR register */ 02131 { 02132 uint32_t CR_tmp = hrtc->Instance->CR; 02133 CR_tmp &= (uint32_t)~RTC_CR_WUCKSEL; 02134 CR_tmp |= (uint32_t)WakeUpClock; 02135 hrtc->Instance->CR = CR_tmp; 02136 } 02137 02138 /* RTC WakeUpTimer Interrupt Configuration: EXTI configuration */ 02139 #if defined(DUAL_CORE) 02140 if (HAL_GetCurrentCPUID() == CM7_CPUID) 02141 { 02142 __HAL_RTC_WAKEUPTIMER_EXTI_ENABLE_IT(); 02143 } 02144 else 02145 { 02146 __HAL_RTC_WAKEUPTIMER_EXTID2_ENABLE_IT(); 02147 } 02148 #else /* SINGLE_CORE */ 02149 __HAL_RTC_WAKEUPTIMER_EXTI_ENABLE_IT(); 02150 #endif /* DUAL_CORE */ 02151 02152 __HAL_RTC_WAKEUPTIMER_EXTI_ENABLE_RISING_EDGE(); 02153 02154 /* Configure the Interrupt in the RTC_CR register */ 02155 __HAL_RTC_WAKEUPTIMER_ENABLE_IT(hrtc, RTC_IT_WUT); 02156 02157 /* Enable the Wakeup Timer */ 02158 __HAL_RTC_WAKEUPTIMER_ENABLE(hrtc); 02159 02160 /* Enable the write protection for RTC registers */ 02161 __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc); 02162 02163 hrtc->State = HAL_RTC_STATE_READY; 02164 02165 /* Process Unlocked */ 02166 __HAL_UNLOCK(hrtc); 02167 02168 return HAL_OK; 02169 } 02170 02171 /** 02172 * @brief Deactivate wake up timer counter. 02173 * @param hrtc RTC handle 02174 * @retval HAL status 02175 */ 02176 HAL_StatusTypeDef HAL_RTCEx_DeactivateWakeUpTimer(RTC_HandleTypeDef *hrtc) 02177 { 02178 uint32_t tickstart; 02179 02180 /* Process Locked */ 02181 __HAL_LOCK(hrtc); 02182 02183 hrtc->State = HAL_RTC_STATE_BUSY; 02184 02185 /* Disable the write protection for RTC registers */ 02186 __HAL_RTC_WRITEPROTECTION_DISABLE(hrtc); 02187 02188 /* Disable the Wakeup Timer */ 02189 __HAL_RTC_WAKEUPTIMER_DISABLE(hrtc); 02190 02191 /* In case of interrupt mode is used, the interrupt source must disabled */ 02192 __HAL_RTC_WAKEUPTIMER_DISABLE_IT(hrtc, RTC_IT_WUT); 02193 02194 tickstart = HAL_GetTick(); 02195 /* Wait till RTC WUTWF flag is set and if Time out is reached exit */ 02196 #if defined(RTC_ICSR_WUTWF) 02197 while (READ_BIT(hrtc->Instance->ICSR, RTC_FLAG_WUTWF) == 0U) 02198 #endif /* RTC_ICSR_WUTWF */ 02199 #if defined(RTC_ISR_WUTWF) 02200 while(__HAL_RTC_WAKEUPTIMER_GET_FLAG(hrtc, RTC_FLAG_WUTWF) == 0U) 02201 #endif /* RTC_ISR_WUTWF */ 02202 { 02203 if ((HAL_GetTick() - tickstart) > RTC_TIMEOUT_VALUE) 02204 { 02205 /* Enable the write protection for RTC registers */ 02206 __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc); 02207 02208 hrtc->State = HAL_RTC_STATE_TIMEOUT; 02209 02210 /* Process Unlocked */ 02211 __HAL_UNLOCK(hrtc); 02212 02213 return HAL_TIMEOUT; 02214 } 02215 } 02216 02217 /* Enable the write protection for RTC registers */ 02218 __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc); 02219 02220 hrtc->State = HAL_RTC_STATE_READY; 02221 02222 /* Process Unlocked */ 02223 __HAL_UNLOCK(hrtc); 02224 02225 return HAL_OK; 02226 } 02227 02228 /** 02229 * @brief Get wake up timer counter. 02230 * @param hrtc RTC handle 02231 * @retval Counter value 02232 */ 02233 uint32_t HAL_RTCEx_GetWakeUpTimer(RTC_HandleTypeDef *hrtc) 02234 { 02235 /* Get the counter value */ 02236 return ((uint32_t)(hrtc->Instance->WUTR & RTC_WUTR_WUT)); 02237 } 02238 02239 /** 02240 * @brief Handle Wake Up Timer interrupt request. 02241 * @param hrtc RTC handle 02242 * @retval None 02243 */ 02244 void HAL_RTCEx_WakeUpTimerIRQHandler(RTC_HandleTypeDef *hrtc) 02245 { 02246 /* Clear the EXTI's line Flag for RTC WakeUpTimer */ 02247 #if defined(DUAL_CORE) 02248 if (HAL_GetCurrentCPUID() == CM7_CPUID) 02249 { 02250 __HAL_RTC_WAKEUPTIMER_EXTI_CLEAR_FLAG(); 02251 } 02252 else 02253 { 02254 __HAL_RTC_WAKEUPTIMER_EXTID2_CLEAR_FLAG(); 02255 } 02256 #else /* SINGLE_CORE */ 02257 __HAL_RTC_WAKEUPTIMER_EXTI_CLEAR_FLAG(); 02258 #endif /* DUAL_CORE */ 02259 02260 #if defined(RTC_MISR_WUTMF) 02261 /* Get the pending status of the WAKEUPTIMER Interrupt */ 02262 if ((hrtc->Instance->MISR & RTC_MISR_WUTMF) != 0u) 02263 { 02264 /* Immediately clear flags */ 02265 hrtc->Instance->SCR = RTC_SCR_CWUTF; 02266 02267 /* WAKEUPTIMER callback */ 02268 #if (USE_HAL_RTC_REGISTER_CALLBACKS == 1) 02269 /* Call WakeUpTimerEvent registered Callback */ 02270 hrtc->WakeUpTimerEventCallback(hrtc); 02271 #else 02272 HAL_RTCEx_WakeUpTimerEventCallback(hrtc); 02273 #endif /* USE_HAL_RTC_REGISTER_CALLBACKS */ 02274 } 02275 #endif /* RTC_MISR_WUTMF */ 02276 #if defined(RTC_ISR_WUTF) 02277 /* Get the pending status of the WAKEUPTIMER Interrupt */ 02278 if (__HAL_RTC_WAKEUPTIMER_GET_FLAG(hrtc, RTC_FLAG_WUTF) != 0U) 02279 { 02280 /* Clear the WAKEUPTIMER interrupt pending bit */ 02281 __HAL_RTC_WAKEUPTIMER_CLEAR_FLAG(hrtc, RTC_FLAG_WUTF); 02282 02283 /* WAKEUPTIMER callback */ 02284 #if (USE_HAL_RTC_REGISTER_CALLBACKS == 1) 02285 /* Call WakeUpTimerEvent registered Callback */ 02286 hrtc->WakeUpTimerEventCallback(hrtc); 02287 #else 02288 HAL_RTCEx_WakeUpTimerEventCallback(hrtc); 02289 #endif /* USE_HAL_RTC_REGISTER_CALLBACKS */ 02290 } 02291 #endif /* RTC_ISR_WUTF */ 02292 02293 /* Change RTC state */ 02294 hrtc->State = HAL_RTC_STATE_READY; 02295 } 02296 02297 /** 02298 * @brief Wake Up Timer callback. 02299 * @param hrtc RTC handle 02300 * @retval None 02301 */ 02302 __weak void HAL_RTCEx_WakeUpTimerEventCallback(RTC_HandleTypeDef * hrtc) 02303 { 02304 /* Prevent unused argument(s) compilation warning */ 02305 UNUSED(hrtc); 02306 02307 /* NOTE : This function should not be modified, when the callback is needed, 02308 the HAL_RTCEx_WakeUpTimerEventCallback could be implemented in the user file 02309 */ 02310 } 02311 02312 02313 /** 02314 * @brief Handle Wake Up Timer Polling. 02315 * @param hrtc RTC handle 02316 * @param Timeout Timeout duration 02317 * @retval HAL status 02318 */ 02319 HAL_StatusTypeDef HAL_RTCEx_PollForWakeUpTimerEvent(RTC_HandleTypeDef * hrtc, uint32_t Timeout) 02320 { 02321 uint32_t tickstart = HAL_GetTick(); 02322 02323 while(__HAL_RTC_WAKEUPTIMER_GET_FLAG(hrtc, RTC_FLAG_WUTF) == 0U) 02324 { 02325 if (Timeout != HAL_MAX_DELAY) 02326 { 02327 if (((HAL_GetTick() - tickstart) > Timeout) || (Timeout == 0U)) 02328 { 02329 hrtc->State = HAL_RTC_STATE_TIMEOUT; 02330 return HAL_TIMEOUT; 02331 } 02332 } 02333 } 02334 02335 /* Clear the WAKEUPTIMER Flag */ 02336 __HAL_RTC_WAKEUPTIMER_CLEAR_FLAG(hrtc, RTC_FLAG_WUTF); 02337 02338 /* Change RTC state */ 02339 hrtc->State = HAL_RTC_STATE_READY; 02340 02341 return HAL_OK; 02342 } 02343 02344 /** 02345 * @} 02346 */ 02347 02348 02349 /** @addtogroup RTCEx_Exported_Functions_Group6 02350 * @brief Extended RTC Backup register functions 02351 * 02352 @verbatim 02353 =============================================================================== 02354 ##### Extended RTC Backup register functions ##### 02355 =============================================================================== 02356 [..] 02357 (+) Before calling any tamper or internal tamper function, you have to call first 02358 HAL_RTC_Init() function. 02359 (+) In that ine you can select to output tamper event on RTC pin. 02360 [..] 02361 This subsection provides functions allowing to 02362 (+) Write a data in a specified RTC Backup data register 02363 (+) Read a data in a specified RTC Backup data register 02364 @endverbatim 02365 * @{ 02366 */ 02367 02368 02369 /** 02370 * @brief Write a data in a specified RTC Backup data register. 02371 * @param hrtc RTC handle 02372 * @param BackupRegister RTC Backup data Register number. 02373 * This parameter can be: RTC_BKP_DRx where x can be from 0 to 31 to 02374 * specify the register. 02375 * @param Data Data to be written in the specified Backup data register. 02376 * @retval None 02377 */ 02378 void HAL_RTCEx_BKUPWrite(RTC_HandleTypeDef * hrtc, uint32_t BackupRegister, uint32_t Data) 02379 { 02380 uint32_t tmp; 02381 02382 /* Check the parameters */ 02383 assert_param(IS_RTC_BKP(BackupRegister)); 02384 02385 /* Point on address of first backup register */ 02386 #if defined(TAMP_BKP0R) 02387 tmp = (uint32_t) & (((TAMP_TypeDef *)((uint32_t)hrtc->Instance + TAMP_OFFSET))->BKP0R); 02388 #endif /* TAMP_BKP0R */ 02389 #if defined(RTC_BKP0R) 02390 tmp = (uint32_t) & (hrtc->Instance->BKP0R); 02391 #endif /* RTC_BKP0R */ 02392 02393 tmp += (BackupRegister * 4U); 02394 02395 /* Write the specified register */ 02396 *(__IO uint32_t *)tmp = (uint32_t)Data; 02397 } 02398 02399 02400 /** 02401 * @brief Read data from the specified RTC Backup data Register. 02402 * @param hrtc RTC handle 02403 * @param BackupRegister RTC Backup data Register number. 02404 * This parameter can be: RTC_BKP_DRx where x can be from 0 to 31 to 02405 * specify the register. 02406 * @retval Read value 02407 */ 02408 uint32_t HAL_RTCEx_BKUPRead(RTC_HandleTypeDef * hrtc, uint32_t BackupRegister) 02409 { 02410 uint32_t tmp; 02411 02412 /* Check the parameters */ 02413 assert_param(IS_RTC_BKP(BackupRegister)); 02414 02415 /* Point on address of first backup register */ 02416 #if defined(TAMP_BKP0R) 02417 tmp = (uint32_t) & (((TAMP_TypeDef *)((uint32_t)hrtc->Instance + TAMP_OFFSET))->BKP0R); 02418 #endif /* TAMP_BKP0R */ 02419 #if defined(RTC_BKP0R) 02420 tmp = (uint32_t) & (hrtc->Instance->BKP0R); 02421 #endif /* RTC_BKP0R */ 02422 02423 tmp += (BackupRegister * 4U); 02424 02425 /* Read the specified register */ 02426 return (*(__IO uint32_t *)tmp); 02427 } 02428 02429 02430 /** 02431 * @} 02432 */ 02433 02434 02435 /** @addtogroup RTCEx_Exported_Functions_Group3 02436 * @brief Extended Peripheral Control functions 02437 * 02438 @verbatim 02439 =============================================================================== 02440 ##### Extended Peripheral Control functions ##### 02441 =============================================================================== 02442 [..] 02443 This subsection provides functions allowing to 02444 (+) Write a data in a specified RTC Backup data register 02445 (+) Read a data in a specified RTC Backup data register 02446 (+) Set the Smooth calibration parameters. 02447 (+) Set Low Power calibration parameter (if feature supported). 02448 (+) Configure the Synchronization Shift Control Settings. 02449 (+) Configure the Calibration Pinout (RTC_CALIB) Selection (1Hz or 512Hz). 02450 (+) Deactivate the Calibration Pinout (RTC_CALIB) Selection (1Hz or 512Hz). 02451 (+) Enable the RTC reference clock detection. 02452 (+) Disable the RTC reference clock detection. 02453 (+) Enable the Bypass Shadow feature. 02454 (+) Disable the Bypass Shadow feature. 02455 02456 @endverbatim 02457 * @{ 02458 */ 02459 02460 02461 /** 02462 * @brief Set the Smooth calibration parameters. 02463 * @param hrtc RTC handle 02464 * @param SmoothCalibPeriod Select the Smooth Calibration Period. 02465 * This parameter can be can be one of the following values : 02466 * @arg RTC_SMOOTHCALIB_PERIOD_32SEC: The smooth calibration period is 32s. 02467 * @arg RTC_SMOOTHCALIB_PERIOD_16SEC: The smooth calibration period is 16s. 02468 * @arg RTC_SMOOTHCALIB_PERIOD_8SEC: The smooth calibration period is 8s. 02469 * @param SmoothCalibPlusPulses Select to Set or reset the CALP bit. 02470 * This parameter can be one of the following values: 02471 * @arg RTC_SMOOTHCALIB_PLUSPULSES_SET: Add one RTCCLK pulse every 2*11 pulses. 02472 * @arg RTC_SMOOTHCALIB_PLUSPULSES_RESET: No RTCCLK pulses are added. 02473 * @param SmoothCalibMinusPulsesValue Select the value of CALM[8:0] bits. 02474 * This parameter can be one any value from 0 to 0x000001FF. 02475 * @note To deactivate the smooth calibration, the field SmoothCalibPlusPulses 02476 * must be equal to SMOOTHCALIB_PLUSPULSES_RESET and the field 02477 * SmoothCalibMinusPulsesValue must be equal to 0. 02478 * @retval HAL status 02479 */ 02480 HAL_StatusTypeDef HAL_RTCEx_SetSmoothCalib(RTC_HandleTypeDef * hrtc, uint32_t SmoothCalibPeriod, uint32_t SmoothCalibPlusPulses, uint32_t SmoothCalibMinusPulsesValue) 02481 { 02482 uint32_t tickstart; 02483 02484 /* Check the parameters */ 02485 assert_param(IS_RTC_SMOOTH_CALIB_PERIOD(SmoothCalibPeriod)); 02486 assert_param(IS_RTC_SMOOTH_CALIB_PLUS(SmoothCalibPlusPulses)); 02487 assert_param(IS_RTC_SMOOTH_CALIB_MINUS(SmoothCalibMinusPulsesValue)); 02488 02489 /* Process Locked */ 02490 __HAL_LOCK(hrtc); 02491 02492 hrtc->State = HAL_RTC_STATE_BUSY; 02493 02494 /* Disable the write protection for RTC registers */ 02495 __HAL_RTC_WRITEPROTECTION_DISABLE(hrtc); 02496 02497 /* check if a calibration operation is pending */ 02498 #if defined(RTC_ICSR_RECALPF) 02499 if ((hrtc->Instance->ICSR & RTC_ICSR_RECALPF) != 0U) 02500 #endif /* RTC_ICSR_RECALPF */ 02501 #if defined(RTC_ISR_RECALPF) 02502 if ((hrtc->Instance->ISR & RTC_ISR_RECALPF) != 0U) 02503 #endif /* RTC_ISR_RECALPF */ 02504 { 02505 tickstart = HAL_GetTick(); 02506 02507 /* Wait for pending calibration operation to finish */ 02508 #if defined(RTC_ICSR_RECALPF) 02509 while ((hrtc->Instance->ICSR & RTC_ICSR_RECALPF) != 0U) 02510 #endif /* RTC_ICSR_RECALPF */ 02511 #if defined(RTC_ISR_RECALPF) 02512 while ((hrtc->Instance->ISR & RTC_ISR_RECALPF) != 0U) 02513 #endif /* RTC_ISR_RECALPF */ 02514 { 02515 if ((HAL_GetTick() - tickstart) > RTC_TIMEOUT_VALUE) 02516 { 02517 /* Enable the write protection for RTC registers */ 02518 __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc); 02519 02520 /* Change RTC state */ 02521 hrtc->State = HAL_RTC_STATE_TIMEOUT; 02522 02523 /* Process Unlocked */ 02524 __HAL_UNLOCK(hrtc); 02525 02526 return HAL_TIMEOUT; 02527 } 02528 } 02529 } 02530 02531 /* Configure the Smooth calibration settings */ 02532 MODIFY_REG(hrtc->Instance->CALR, (RTC_CALR_CALP | RTC_CALR_CALW8 | RTC_CALR_CALW16 | RTC_CALR_CALM), (uint32_t)(SmoothCalibPeriod | SmoothCalibPlusPulses | SmoothCalibMinusPulsesValue)); 02533 02534 /* Enable the write protection for RTC registers */ 02535 __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc); 02536 02537 /* Change RTC state */ 02538 hrtc->State = HAL_RTC_STATE_READY; 02539 02540 /* Process Unlocked */ 02541 __HAL_UNLOCK(hrtc); 02542 02543 return HAL_OK; 02544 } 02545 02546 /** 02547 * @brief Configure the Synchronization Shift Control Settings. 02548 * @note When REFCKON is set, firmware must not write to Shift control register. 02549 * @param hrtc RTC handle 02550 * @param ShiftAdd1S Select to add or not 1 second to the time calendar. 02551 * This parameter can be one of the following values: 02552 * @arg RTC_SHIFTADD1S_SET: Add one second to the clock calendar. 02553 * @arg RTC_SHIFTADD1S_RESET: No effect. 02554 * @param ShiftSubFS Select the number of Second Fractions to substitute. 02555 * This parameter can be one any value from 0 to 0x7FFF. 02556 * @retval HAL status 02557 */ 02558 HAL_StatusTypeDef HAL_RTCEx_SetSynchroShift(RTC_HandleTypeDef * hrtc, uint32_t ShiftAdd1S, uint32_t ShiftSubFS) 02559 { 02560 uint32_t tickstart; 02561 02562 /* Check the parameters */ 02563 assert_param(IS_RTC_SHIFT_ADD1S(ShiftAdd1S)); 02564 assert_param(IS_RTC_SHIFT_SUBFS(ShiftSubFS)); 02565 02566 /* Process Locked */ 02567 __HAL_LOCK(hrtc); 02568 02569 hrtc->State = HAL_RTC_STATE_BUSY; 02570 02571 /* Disable the write protection for RTC registers */ 02572 __HAL_RTC_WRITEPROTECTION_DISABLE(hrtc); 02573 02574 tickstart = HAL_GetTick(); 02575 02576 /* Wait until the shift is completed */ 02577 #if defined(RTC_ICSR_SHPF) 02578 while ((hrtc->Instance->ICSR & RTC_ICSR_SHPF) != 0U) 02579 #endif /* RTC_ICSR_SHPF */ 02580 #if defined(RTC_ISR_SHPF) 02581 while ((hrtc->Instance->ISR & RTC_ISR_SHPF) != 0U) 02582 #endif /* RTC_ISR_SHPF */ 02583 { 02584 if ((HAL_GetTick() - tickstart) > RTC_TIMEOUT_VALUE) 02585 { 02586 /* Enable the write protection for RTC registers */ 02587 __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc); 02588 02589 hrtc->State = HAL_RTC_STATE_TIMEOUT; 02590 02591 /* Process Unlocked */ 02592 __HAL_UNLOCK(hrtc); 02593 02594 return HAL_TIMEOUT; 02595 } 02596 } 02597 02598 /* Check if the reference clock detection is disabled */ 02599 if ((hrtc->Instance->CR & RTC_CR_REFCKON) == 0U) 02600 { 02601 /* Configure the Shift settings */ 02602 hrtc->Instance->SHIFTR = (uint32_t)(uint32_t)(ShiftSubFS) | (uint32_t)(ShiftAdd1S); 02603 02604 /* If RTC_CR_BYPSHAD bit = 0, wait for synchro else this check is not needed */ 02605 if ((hrtc->Instance->CR & RTC_CR_BYPSHAD) == 0U) 02606 { 02607 if (HAL_RTC_WaitForSynchro(hrtc) != HAL_OK) 02608 { 02609 /* Enable the write protection for RTC registers */ 02610 __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc); 02611 02612 hrtc->State = HAL_RTC_STATE_ERROR; 02613 02614 /* Process Unlocked */ 02615 __HAL_UNLOCK(hrtc); 02616 02617 return HAL_ERROR; 02618 } 02619 } 02620 } 02621 else 02622 { 02623 /* Enable the write protection for RTC registers */ 02624 __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc); 02625 02626 /* Change RTC state */ 02627 hrtc->State = HAL_RTC_STATE_ERROR; 02628 02629 /* Process Unlocked */ 02630 __HAL_UNLOCK(hrtc); 02631 02632 return HAL_ERROR; 02633 } 02634 02635 /* Enable the write protection for RTC registers */ 02636 __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc); 02637 02638 /* Change RTC state */ 02639 hrtc->State = HAL_RTC_STATE_READY; 02640 02641 /* Process Unlocked */ 02642 __HAL_UNLOCK(hrtc); 02643 02644 return HAL_OK; 02645 } 02646 02647 /** 02648 * @brief Configure the Calibration Pinout (RTC_CALIB) Selection (1Hz or 512Hz). 02649 * @param hrtc RTC handle 02650 * @param CalibOutput Select the Calibration output Selection. 02651 * This parameter can be one of the following values: 02652 * @arg RTC_CALIBOUTPUT_512HZ: A signal has a regular waveform at 512Hz. 02653 * @arg RTC_CALIBOUTPUT_1HZ: A signal has a regular waveform at 1Hz. 02654 * @retval HAL status 02655 */ 02656 HAL_StatusTypeDef HAL_RTCEx_SetCalibrationOutPut(RTC_HandleTypeDef * hrtc, uint32_t CalibOutput) 02657 { 02658 /* Check the parameters */ 02659 assert_param(IS_RTC_CALIB_OUTPUT(CalibOutput)); 02660 02661 /* Process Locked */ 02662 __HAL_LOCK(hrtc); 02663 02664 hrtc->State = HAL_RTC_STATE_BUSY; 02665 02666 /* Disable the write protection for RTC registers */ 02667 __HAL_RTC_WRITEPROTECTION_DISABLE(hrtc); 02668 02669 /* Clear flags before config */ 02670 hrtc->Instance->CR &= (uint32_t)~RTC_CR_COSEL; 02671 02672 /* Configure the RTC_CR register */ 02673 hrtc->Instance->CR |= (uint32_t)CalibOutput; 02674 02675 __HAL_RTC_CALIBRATION_OUTPUT_ENABLE(hrtc); 02676 02677 /* Enable the write protection for RTC registers */ 02678 __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc); 02679 02680 /* Change RTC state */ 02681 hrtc->State = HAL_RTC_STATE_READY; 02682 02683 /* Process Unlocked */ 02684 __HAL_UNLOCK(hrtc); 02685 02686 return HAL_OK; 02687 } 02688 02689 /** 02690 * @brief Deactivate the Calibration Pinout (RTC_CALIB) Selection (1Hz or 512Hz). 02691 * @param hrtc RTC handle 02692 * @retval HAL status 02693 */ 02694 HAL_StatusTypeDef HAL_RTCEx_DeactivateCalibrationOutPut(RTC_HandleTypeDef * hrtc) 02695 { 02696 /* Process Locked */ 02697 __HAL_LOCK(hrtc); 02698 02699 hrtc->State = HAL_RTC_STATE_BUSY; 02700 02701 /* Disable the write protection for RTC registers */ 02702 __HAL_RTC_WRITEPROTECTION_DISABLE(hrtc); 02703 02704 __HAL_RTC_CALIBRATION_OUTPUT_DISABLE(hrtc); 02705 02706 /* Enable the write protection for RTC registers */ 02707 __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc); 02708 02709 /* Change RTC state */ 02710 hrtc->State = HAL_RTC_STATE_READY; 02711 02712 /* Process Unlocked */ 02713 __HAL_UNLOCK(hrtc); 02714 02715 return HAL_OK; 02716 } 02717 02718 /** 02719 * @brief Enable the RTC reference clock detection. 02720 * @param hrtc RTC handle 02721 * @retval HAL status 02722 */ 02723 HAL_StatusTypeDef HAL_RTCEx_SetRefClock(RTC_HandleTypeDef * hrtc) 02724 { 02725 HAL_StatusTypeDef status; 02726 /* Process Locked */ 02727 __HAL_LOCK(hrtc); 02728 02729 hrtc->State = HAL_RTC_STATE_BUSY; 02730 02731 /* Disable the write protection for RTC registers */ 02732 __HAL_RTC_WRITEPROTECTION_DISABLE(hrtc); 02733 02734 /* Enter Initialization mode */ 02735 status = RTC_EnterInitMode(hrtc); 02736 if (status == HAL_OK) 02737 { 02738 __HAL_RTC_CLOCKREF_DETECTION_ENABLE(hrtc); 02739 02740 /* Exit Initialization mode */ 02741 status = RTC_ExitInitMode(hrtc); 02742 } 02743 02744 /* Enable the write protection for RTC registers */ 02745 __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc); 02746 if (status == HAL_OK) 02747 { 02748 /* Change RTC state */ 02749 hrtc->State = HAL_RTC_STATE_READY; 02750 } 02751 /* Process Unlocked */ 02752 __HAL_UNLOCK(hrtc); 02753 02754 return HAL_OK; 02755 } 02756 02757 /** 02758 * @brief Disable the RTC reference clock detection. 02759 * @param hrtc RTC handle 02760 * @retval HAL status 02761 */ 02762 HAL_StatusTypeDef HAL_RTCEx_DeactivateRefClock(RTC_HandleTypeDef * hrtc) 02763 { 02764 HAL_StatusTypeDef status; 02765 /* Process Locked */ 02766 __HAL_LOCK(hrtc); 02767 02768 hrtc->State = HAL_RTC_STATE_BUSY; 02769 02770 /* Disable the write protection for RTC registers */ 02771 __HAL_RTC_WRITEPROTECTION_DISABLE(hrtc); 02772 02773 /* Enter Initialization mode */ 02774 status = RTC_EnterInitMode(hrtc); 02775 if (status == HAL_OK) 02776 { 02777 __HAL_RTC_CLOCKREF_DETECTION_DISABLE(hrtc); 02778 02779 /* Exit Initialization mode */ 02780 status = RTC_ExitInitMode(hrtc); 02781 } 02782 02783 /* Enable the write protection for RTC registers */ 02784 __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc); 02785 02786 if (status == HAL_OK) 02787 { 02788 /* Change RTC state */ 02789 hrtc->State = HAL_RTC_STATE_READY; 02790 02791 } 02792 02793 /* Process Unlocked */ 02794 __HAL_UNLOCK(hrtc); 02795 02796 return HAL_OK; 02797 } 02798 02799 /** 02800 * @brief Enable the Bypass Shadow feature. 02801 * @note When the Bypass Shadow is enabled the calendar value are taken 02802 * directly from the Calendar counter. 02803 * @param hrtc RTC handle 02804 * @retval HAL status 02805 */ 02806 HAL_StatusTypeDef HAL_RTCEx_EnableBypassShadow(RTC_HandleTypeDef * hrtc) 02807 { 02808 /* Process Locked */ 02809 __HAL_LOCK(hrtc); 02810 02811 hrtc->State = HAL_RTC_STATE_BUSY; 02812 02813 /* Disable the write protection for RTC registers */ 02814 __HAL_RTC_WRITEPROTECTION_DISABLE(hrtc); 02815 02816 /* Set the BYPSHAD bit */ 02817 hrtc->Instance->CR |= (uint8_t)RTC_CR_BYPSHAD; 02818 02819 /* Enable the write protection for RTC registers */ 02820 __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc); 02821 02822 /* Change RTC state */ 02823 hrtc->State = HAL_RTC_STATE_READY; 02824 02825 /* Process Unlocked */ 02826 __HAL_UNLOCK(hrtc); 02827 02828 return HAL_OK; 02829 } 02830 02831 /** 02832 * @brief Disable the Bypass Shadow feature. 02833 * @note When the Bypass Shadow is enabled the calendar value are taken 02834 * directly from the Calendar counter. 02835 * @param hrtc RTC handle 02836 * @retval HAL status 02837 */ 02838 HAL_StatusTypeDef HAL_RTCEx_DisableBypassShadow(RTC_HandleTypeDef * hrtc) 02839 { 02840 /* Process Locked */ 02841 __HAL_LOCK(hrtc); 02842 02843 hrtc->State = HAL_RTC_STATE_BUSY; 02844 02845 /* Disable the write protection for RTC registers */ 02846 __HAL_RTC_WRITEPROTECTION_DISABLE(hrtc); 02847 02848 /* Reset the BYPSHAD bit */ 02849 hrtc->Instance->CR &= ((uint8_t)~RTC_CR_BYPSHAD); 02850 02851 /* Enable the write protection for RTC registers */ 02852 __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc); 02853 02854 /* Change RTC state */ 02855 hrtc->State = HAL_RTC_STATE_READY; 02856 02857 /* Process Unlocked */ 02858 __HAL_UNLOCK(hrtc); 02859 02860 return HAL_OK; 02861 } 02862 02863 #if defined(TAMP_COUNTR) 02864 /** 02865 * @brief Increment Monotonic counter. 02866 * @param hrtc RTC handle 02867 * @param Instance Monotonic counter Instance 02868 * This parameter can be can be one of the following values : 02869 * @arg RTC_MONOTONIC_COUNTER_1 02870 * @retval HAL status 02871 */ 02872 HAL_StatusTypeDef HAL_RTCEx_MonotonicCounterIncrement(RTC_HandleTypeDef *hrtc, uint32_t Instance) 02873 { 02874 UNUSED(hrtc); 02875 UNUSED(Instance); 02876 /* This register is read-only only and is incremented by one when a write access is done to this 02877 register. This register cannot roll-over and is frozen when reaching the maximum value. */ 02878 CLEAR_REG(TAMP->COUNTR); 02879 02880 return HAL_OK; 02881 } 02882 02883 /** 02884 * @brief Monotonic counter incrementation. 02885 * @param hrtc RTC handle 02886 * @param Instance Monotonic counter Instance 02887 * This parameter can be can be one of the following values : 02888 * @arg RTC_MONOTONIC_COUNTER_1 02889 * @param Counter monotonic counter value 02890 * @retval HAL status 02891 */ 02892 HAL_StatusTypeDef HAL_RTCEx_MonotonicCounterGet(RTC_HandleTypeDef *hrtc, uint32_t *Counter, uint32_t Instance) 02893 { 02894 UNUSED(hrtc); 02895 UNUSED(Instance); 02896 /* This register is read-only only and is incremented by one when a write access is done to this 02897 register. This register cannot roll-over and is frozen when reaching the maximum value. */ 02898 *Counter = READ_REG(TAMP->COUNTR); 02899 02900 return HAL_OK; 02901 } 02902 #endif /* TAMP_COUNTR */ 02903 02904 /** 02905 * @} 02906 */ 02907 02908 /** @addtogroup RTCEx_Exported_Functions_Group4 02909 * @brief Extended features functions 02910 * 02911 @verbatim 02912 =============================================================================== 02913 ##### Extended features functions ##### 02914 =============================================================================== 02915 [..] This section provides functions allowing to: 02916 (+) RTC Alarm B callback 02917 (+) RTC Poll for Alarm B request 02918 02919 @endverbatim 02920 * @{ 02921 */ 02922 02923 /** 02924 * @brief Alarm B callback. 02925 * @param hrtc RTC handle 02926 * @retval None 02927 */ 02928 __weak void HAL_RTCEx_AlarmBEventCallback(RTC_HandleTypeDef * hrtc) 02929 { 02930 /* Prevent unused argument(s) compilation warning */ 02931 UNUSED(hrtc); 02932 02933 /* NOTE : This function should not be modified, when the callback is needed, 02934 the HAL_RTCEx_AlarmBEventCallback could be implemented in the user file 02935 */ 02936 } 02937 02938 /** 02939 * @brief Handle Alarm B Polling request. 02940 * @param hrtc RTC handle 02941 * @param Timeout Timeout duration 02942 * @retval HAL status 02943 */ 02944 HAL_StatusTypeDef HAL_RTCEx_PollForAlarmBEvent(RTC_HandleTypeDef * hrtc, uint32_t Timeout) 02945 { 02946 uint32_t tickstart = HAL_GetTick(); 02947 02948 while (__HAL_RTC_ALARM_GET_FLAG(hrtc, RTC_FLAG_ALRBF) == 0U) 02949 { 02950 if (Timeout != HAL_MAX_DELAY) 02951 { 02952 if (((HAL_GetTick() - tickstart) > Timeout) || (Timeout == 0U)) 02953 { 02954 hrtc->State = HAL_RTC_STATE_TIMEOUT; 02955 return HAL_TIMEOUT; 02956 } 02957 } 02958 } 02959 02960 /* Clear the Alarm Flag */ 02961 __HAL_RTC_ALARM_CLEAR_FLAG(hrtc, RTC_FLAG_ALRBF); 02962 02963 /* Change RTC state */ 02964 hrtc->State = HAL_RTC_STATE_READY; 02965 02966 return HAL_OK; 02967 } 02968 02969 /** 02970 * @} 02971 */ 02972 02973 02974 /** 02975 * @} 02976 */ 02977 02978 #endif /* HAL_RTC_MODULE_ENABLED */ 02979 02980 /** 02981 * @} 02982 */ 02983 02984 /** 02985 * @} 02986 */ 02987