STM32L486xx HAL User Manual
|
00001 /** 00002 ****************************************************************************** 00003 * @file stm32l4xx_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 @verbatim 00015 ============================================================================== 00016 ##### How to use this driver ##### 00017 ============================================================================== 00018 [..] 00019 (+) Enable the RTC domain access. 00020 (+) Configure the RTC Prescaler (Asynchronous and Synchronous) and RTC hour 00021 format using the HAL_RTC_Init() function. 00022 00023 *** RTC Wakeup configuration *** 00024 ================================ 00025 [..] 00026 (+) To configure the RTC Wakeup Clock source and Counter use the HAL_RTCEx_SetWakeUpTimer() 00027 function. You can also configure the RTC Wakeup timer with interrupt mode 00028 using the HAL_RTCEx_SetWakeUpTimer_IT() function. 00029 (+) To read the RTC WakeUp Counter register, use the HAL_RTCEx_GetWakeUpTimer() 00030 function. 00031 00032 *** Outputs configuration *** 00033 ============================= 00034 [..] The RTC has 2 different outputs: 00035 (+) RTC_ALARM: this output is used to manage the RTC Alarm A, Alarm B 00036 and WaKeUp signals. 00037 To output the selected RTC signal, use the HAL_RTC_Init() function. 00038 (+) RTC_CALIB: this output is 512Hz signal or 1Hz. 00039 To enable the RTC_CALIB, use the HAL_RTCEx_SetCalibrationOutPut() function. 00040 (+) Two pins can be used as RTC_ALARM or RTC_CALIB (PC13, PB2) managed on 00041 the RTC_OR register. 00042 (+) When the RTC_CALIB or RTC_ALARM output is selected, the RTC_OUT pin is 00043 automatically configured in output alternate function. 00044 00045 *** Smooth digital Calibration configuration *** 00046 ================================================ 00047 [..] 00048 (+) Configure the RTC Original Digital Calibration Value and the corresponding 00049 calibration cycle period (32s,16s and 8s) using the HAL_RTCEx_SetSmoothCalib() 00050 function. 00051 00052 *** TimeStamp configuration *** 00053 =============================== 00054 [..] 00055 (+) Enable the RTC TimeStamp using the HAL_RTCEx_SetTimeStamp() function. 00056 You can also configure the RTC TimeStamp with interrupt mode using the 00057 HAL_RTCEx_SetTimeStamp_IT() function. 00058 (+) To read the RTC TimeStamp Time and Date register, use the HAL_RTCEx_GetTimeStamp() 00059 function. 00060 00061 *** Internal TimeStamp configuration *** 00062 =============================== 00063 [..] 00064 (+) Enable the RTC internal TimeStamp using the HAL_RTCEx_SetInternalTimeStamp() function. 00065 User has to check internal timestamp occurrence using __HAL_RTC_INTERNAL_TIMESTAMP_GET_FLAG. 00066 (+) To read the RTC TimeStamp Time and Date register, use the HAL_RTCEx_GetTimeStamp() 00067 function. 00068 00069 *** Tamper configuration *** 00070 ============================ 00071 [..] 00072 (+) Enable the RTC Tamper and configure the Tamper filter count, trigger Edge 00073 or Level according to the Tamper filter (if equal to 0 Edge else Level) 00074 value, sampling frequency, NoErase, MaskFlag, precharge or discharge and 00075 Pull-UP using the HAL_RTCEx_SetTamper() function. You can configure RTC Tamper 00076 with interrupt mode using HAL_RTCEx_SetTamper_IT() function. 00077 (+) The default configuration of the Tamper erases the backup registers. To avoid 00078 erase, enable the NoErase field on the RTC_TAMPCR register. 00079 00080 *** Backup Data Registers configuration *** 00081 =========================================== 00082 [..] 00083 (+) To write to the RTC Backup Data registers, use the HAL_RTCEx_BKUPWrite() 00084 function. 00085 (+) To read the RTC Backup Data registers, use the HAL_RTCEx_BKUPRead() 00086 function. 00087 00088 @endverbatim 00089 ****************************************************************************** 00090 * @attention 00091 * 00092 * <h2><center>© COPYRIGHT(c) 2017 STMicroelectronics</center></h2> 00093 * 00094 * Redistribution and use in source and binary forms, with or without modification, 00095 * are permitted provided that the following conditions are met: 00096 * 1. Redistributions of source code must retain the above copyright notice, 00097 * this list of conditions and the following disclaimer. 00098 * 2. Redistributions in binary form must reproduce the above copyright notice, 00099 * this list of conditions and the following disclaimer in the documentation 00100 * and/or other materials provided with the distribution. 00101 * 3. Neither the name of STMicroelectronics nor the names of its contributors 00102 * may be used to endorse or promote products derived from this software 00103 * without specific prior written permission. 00104 * 00105 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 00106 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 00107 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 00108 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 00109 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 00110 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 00111 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 00112 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 00113 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 00114 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00115 * 00116 ****************************************************************************** 00117 */ 00118 00119 /* Includes ------------------------------------------------------------------*/ 00120 #include "stm32l4xx_hal.h" 00121 00122 /** @addtogroup STM32L4xx_HAL_Driver 00123 * @{ 00124 */ 00125 00126 /** @defgroup RTCEx RTCEx 00127 * @brief RTC Extended HAL module driver 00128 * @{ 00129 */ 00130 00131 #ifdef HAL_RTC_MODULE_ENABLED 00132 00133 /* Private typedef -----------------------------------------------------------*/ 00134 /* Private define ------------------------------------------------------------*/ 00135 #if defined(RTC_TAMPER1_SUPPORT) && defined(RTC_TAMPER3_SUPPORT) 00136 #define RTC_TAMPCR_MASK ((uint32_t)RTC_TAMPCR_TAMPTS |\ 00137 (uint32_t)RTC_TAMPCR_TAMPFREQ | (uint32_t)RTC_TAMPCR_TAMPFLT | (uint32_t)RTC_TAMPCR_TAMPPRCH |\ 00138 (uint32_t)RTC_TAMPCR_TAMPPUDIS | (uint32_t)RTC_TAMPCR_TAMPIE |\ 00139 (uint32_t)RTC_TAMPCR_TAMP1IE | (uint32_t)RTC_TAMPCR_TAMP1NOERASE | (uint32_t)RTC_TAMPCR_TAMP1MF |\ 00140 (uint32_t)RTC_TAMPCR_TAMP2IE | (uint32_t)RTC_TAMPCR_TAMP2NOERASE | (uint32_t)RTC_TAMPCR_TAMP2MF |\ 00141 (uint32_t)RTC_TAMPCR_TAMP3IE | (uint32_t)RTC_TAMPCR_TAMP3NOERASE | (uint32_t)RTC_TAMPCR_TAMP3MF) 00142 #elif defined(RTC_TAMPER1_SUPPORT) 00143 #define RTC_TAMPCR_MASK ((uint32_t)RTC_TAMPCR_TAMPTS |\ 00144 (uint32_t)RTC_TAMPCR_TAMPFREQ | (uint32_t)RTC_TAMPCR_TAMPFLT | (uint32_t)RTC_TAMPCR_TAMPPRCH |\ 00145 (uint32_t)RTC_TAMPCR_TAMPPUDIS | (uint32_t)RTC_TAMPCR_TAMPIE |\ 00146 (uint32_t)RTC_TAMPCR_TAMP1IE | (uint32_t)RTC_TAMPCR_TAMP1NOERASE | (uint32_t)RTC_TAMPCR_TAMP1MF |\ 00147 (uint32_t)RTC_TAMPCR_TAMP2IE | (uint32_t)RTC_TAMPCR_TAMP2NOERASE | (uint32_t)RTC_TAMPCR_TAMP2MF) 00148 #elif defined(RTC_TAMPER3_SUPPORT) 00149 #define RTC_TAMPCR_MASK ((uint32_t)RTC_TAMPCR_TAMPTS |\ 00150 (uint32_t)RTC_TAMPCR_TAMPFREQ | (uint32_t)RTC_TAMPCR_TAMPFLT | (uint32_t)RTC_TAMPCR_TAMPPRCH |\ 00151 (uint32_t)RTC_TAMPCR_TAMPPUDIS | (uint32_t)RTC_TAMPCR_TAMPIE |\ 00152 (uint32_t)RTC_TAMPCR_TAMP2IE | (uint32_t)RTC_TAMPCR_TAMP2NOERASE | (uint32_t)RTC_TAMPCR_TAMP2MF |\ 00153 (uint32_t)RTC_TAMPCR_TAMP3IE | (uint32_t)RTC_TAMPCR_TAMP3NOERASE | (uint32_t)RTC_TAMPCR_TAMP3MF) 00154 #else 00155 #define RTC_TAMPCR_MASK ((uint32_t)RTC_TAMPCR_TAMPTS |\ 00156 (uint32_t)RTC_TAMPCR_TAMPFREQ | (uint32_t)RTC_TAMPCR_TAMPFLT | (uint32_t)RTC_TAMPCR_TAMPPRCH |\ 00157 (uint32_t)RTC_TAMPCR_TAMPPUDIS | (uint32_t)RTC_TAMPCR_TAMPIE |\ 00158 (uint32_t)RTC_TAMPCR_TAMP2IE | (uint32_t)RTC_TAMPCR_TAMP2NOERASE | (uint32_t)RTC_TAMPCR_TAMP2MF) 00159 #endif /* RTC_TAMPER1_SUPPORT && RTC_TAMPER3_SUPPORT */ 00160 00161 /* Private macro -------------------------------------------------------------*/ 00162 /* Private variables ---------------------------------------------------------*/ 00163 /* Private function prototypes -----------------------------------------------*/ 00164 /* Exported functions --------------------------------------------------------*/ 00165 00166 /** @defgroup RTCEx_Exported_Functions RTCEx Exported Functions 00167 * @{ 00168 */ 00169 00170 00171 /** @defgroup RTCEx_Exported_Functions_Group1 RTC TimeStamp and Tamper functions 00172 * @brief RTC TimeStamp and Tamper functions 00173 * 00174 @verbatim 00175 =============================================================================== 00176 ##### RTC TimeStamp and Tamper functions ##### 00177 =============================================================================== 00178 00179 [..] This section provide functions allowing to configure TimeStamp feature 00180 00181 @endverbatim 00182 * @{ 00183 */ 00184 00185 /** 00186 * @brief Set TimeStamp. 00187 * @note This API must be called before enabling the TimeStamp feature. 00188 * @param hrtc: RTC handle 00189 * @param TimeStampEdge: Specifies the pin edge on which the TimeStamp is 00190 * activated. 00191 * This parameter can be one of the following values: 00192 * @arg RTC_TIMESTAMPEDGE_RISING: the Time stamp event occurs on the 00193 * rising edge of the related pin. 00194 * @arg RTC_TIMESTAMPEDGE_FALLING: the Time stamp event occurs on the 00195 * falling edge of the related pin. 00196 * @param RTC_TimeStampPin: specifies the RTC TimeStamp Pin. 00197 * This parameter can be one of the following values: 00198 * @arg RTC_TIMESTAMPPIN_DEFAULT: PC13 is selected as RTC TimeStamp Pin. 00199 * The RTC TimeStamp Pin is per default PC13, but for reasons of 00200 * compatibility, this parameter is required. 00201 * @retval HAL status 00202 */ 00203 HAL_StatusTypeDef HAL_RTCEx_SetTimeStamp(RTC_HandleTypeDef *hrtc, uint32_t TimeStampEdge, uint32_t RTC_TimeStampPin) 00204 { 00205 uint32_t tmpreg = 0; 00206 00207 /* Check the parameters */ 00208 assert_param(IS_TIMESTAMP_EDGE(TimeStampEdge)); 00209 assert_param(IS_RTC_TIMESTAMP_PIN(RTC_TimeStampPin)); 00210 00211 /* Prevent unused argument(s) compilation warning if no assert_param check */ 00212 UNUSED(RTC_TimeStampPin); 00213 00214 /* Process Locked */ 00215 __HAL_LOCK(hrtc); 00216 00217 hrtc->State = HAL_RTC_STATE_BUSY; 00218 00219 /* Get the RTC_CR register and clear the bits to be configured */ 00220 tmpreg = (uint32_t)(hrtc->Instance->CR & (uint32_t)~(RTC_CR_TSEDGE | RTC_CR_TSE)); 00221 00222 tmpreg|= TimeStampEdge; 00223 00224 /* Disable the write protection for RTC registers */ 00225 __HAL_RTC_WRITEPROTECTION_DISABLE(hrtc); 00226 00227 /* Configure the Time Stamp TSEDGE and Enable bits */ 00228 hrtc->Instance->CR = (uint32_t)tmpreg; 00229 00230 __HAL_RTC_TIMESTAMP_ENABLE(hrtc); 00231 00232 /* Enable the write protection for RTC registers */ 00233 __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc); 00234 00235 /* Change RTC state */ 00236 hrtc->State = HAL_RTC_STATE_READY; 00237 00238 /* Process Unlocked */ 00239 __HAL_UNLOCK(hrtc); 00240 00241 return HAL_OK; 00242 } 00243 00244 /** 00245 * @brief Set TimeStamp with Interrupt. 00246 * @param hrtc: RTC handle 00247 * @note This API must be called before enabling the TimeStamp feature. 00248 * @param TimeStampEdge: Specifies the pin edge on which the TimeStamp is 00249 * activated. 00250 * This parameter can be one of the following values: 00251 * @arg RTC_TIMESTAMPEDGE_RISING: the Time stamp event occurs on the 00252 * rising edge of the related pin. 00253 * @arg RTC_TIMESTAMPEDGE_FALLING: the Time stamp event occurs on the 00254 * falling edge of the related pin. 00255 * @param RTC_TimeStampPin: Specifies the RTC TimeStamp Pin. 00256 * This parameter can be one of the following values: 00257 * @arg RTC_TIMESTAMPPIN_DEFAULT: PC13 is selected as RTC TimeStamp Pin. 00258 * The RTC TimeStamp Pin is per default PC13, but for reasons of 00259 * compatibility, this parameter is required. 00260 * @retval HAL status 00261 */ 00262 HAL_StatusTypeDef HAL_RTCEx_SetTimeStamp_IT(RTC_HandleTypeDef *hrtc, uint32_t TimeStampEdge, uint32_t RTC_TimeStampPin) 00263 { 00264 uint32_t tmpreg = 0; 00265 00266 /* Check the parameters */ 00267 assert_param(IS_TIMESTAMP_EDGE(TimeStampEdge)); 00268 assert_param(IS_RTC_TIMESTAMP_PIN(RTC_TimeStampPin)); 00269 00270 /* Prevent unused argument(s) compilation warning if no assert_param check */ 00271 UNUSED(RTC_TimeStampPin); 00272 00273 /* Process Locked */ 00274 __HAL_LOCK(hrtc); 00275 00276 hrtc->State = HAL_RTC_STATE_BUSY; 00277 00278 /* Get the RTC_CR register and clear the bits to be configured */ 00279 tmpreg = (uint32_t)(hrtc->Instance->CR & (uint32_t)~(RTC_CR_TSEDGE | RTC_CR_TSE)); 00280 00281 tmpreg |= TimeStampEdge; 00282 00283 /* Disable the write protection for RTC registers */ 00284 __HAL_RTC_WRITEPROTECTION_DISABLE(hrtc); 00285 00286 /* Configure the Time Stamp TSEDGE and Enable bits */ 00287 hrtc->Instance->CR = (uint32_t)tmpreg; 00288 00289 __HAL_RTC_TIMESTAMP_ENABLE(hrtc); 00290 00291 /* Enable IT timestamp */ 00292 __HAL_RTC_TIMESTAMP_ENABLE_IT(hrtc,RTC_IT_TS); 00293 00294 /* RTC timestamp Interrupt Configuration: EXTI configuration */ 00295 __HAL_RTC_TAMPER_TIMESTAMP_EXTI_ENABLE_IT(); 00296 00297 __HAL_RTC_TAMPER_TIMESTAMP_EXTI_ENABLE_RISING_EDGE(); 00298 00299 /* Enable the write protection for RTC registers */ 00300 __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc); 00301 00302 hrtc->State = HAL_RTC_STATE_READY; 00303 00304 /* Process Unlocked */ 00305 __HAL_UNLOCK(hrtc); 00306 00307 return HAL_OK; 00308 } 00309 00310 /** 00311 * @brief Deactivate TimeStamp. 00312 * @param hrtc: RTC handle 00313 * @retval HAL status 00314 */ 00315 HAL_StatusTypeDef HAL_RTCEx_DeactivateTimeStamp(RTC_HandleTypeDef *hrtc) 00316 { 00317 uint32_t tmpreg = 0; 00318 00319 /* Process Locked */ 00320 __HAL_LOCK(hrtc); 00321 00322 hrtc->State = HAL_RTC_STATE_BUSY; 00323 00324 /* Disable the write protection for RTC registers */ 00325 __HAL_RTC_WRITEPROTECTION_DISABLE(hrtc); 00326 00327 /* In case of interrupt mode is used, the interrupt source must disabled */ 00328 __HAL_RTC_TIMESTAMP_DISABLE_IT(hrtc, RTC_IT_TS); 00329 00330 /* Get the RTC_CR register and clear the bits to be configured */ 00331 tmpreg = (uint32_t)(hrtc->Instance->CR & (uint32_t)~(RTC_CR_TSEDGE | RTC_CR_TSE)); 00332 00333 /* Configure the Time Stamp TSEDGE and Enable bits */ 00334 hrtc->Instance->CR = (uint32_t)tmpreg; 00335 00336 /* Enable the write protection for RTC registers */ 00337 __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc); 00338 00339 hrtc->State = HAL_RTC_STATE_READY; 00340 00341 /* Process Unlocked */ 00342 __HAL_UNLOCK(hrtc); 00343 00344 return HAL_OK; 00345 } 00346 00347 /** 00348 * @brief Set Internal TimeStamp. 00349 * @note This API must be called before enabling the internal TimeStamp feature. 00350 * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains 00351 * the configuration information for RTC. 00352 * @retval HAL status 00353 */ 00354 HAL_StatusTypeDef HAL_RTCEx_SetInternalTimeStamp(RTC_HandleTypeDef *hrtc) 00355 { 00356 /* Process Locked */ 00357 __HAL_LOCK(hrtc); 00358 00359 hrtc->State = HAL_RTC_STATE_BUSY; 00360 00361 /* Disable the write protection for RTC registers */ 00362 __HAL_RTC_WRITEPROTECTION_DISABLE(hrtc); 00363 00364 /* Configure the internal Time Stamp Enable bits */ 00365 __HAL_RTC_INTERNAL_TIMESTAMP_ENABLE(hrtc); 00366 00367 /* Enable the write protection for RTC registers */ 00368 __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc); 00369 00370 /* Change RTC state */ 00371 hrtc->State = HAL_RTC_STATE_READY; 00372 00373 /* Process Unlocked */ 00374 __HAL_UNLOCK(hrtc); 00375 00376 return HAL_OK; 00377 } 00378 00379 /** 00380 * @brief Deactivate Internal TimeStamp. 00381 * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains 00382 * the configuration information for RTC. 00383 * @retval HAL status 00384 */ 00385 HAL_StatusTypeDef HAL_RTCEx_DeactivateInternalTimeStamp(RTC_HandleTypeDef *hrtc) 00386 { 00387 /* Process Locked */ 00388 __HAL_LOCK(hrtc); 00389 00390 hrtc->State = HAL_RTC_STATE_BUSY; 00391 00392 /* Disable the write protection for RTC registers */ 00393 __HAL_RTC_WRITEPROTECTION_DISABLE(hrtc); 00394 00395 /* Configure the internal Time Stamp Enable bits */ 00396 __HAL_RTC_INTERNAL_TIMESTAMP_DISABLE(hrtc); 00397 00398 /* Enable the write protection for RTC registers */ 00399 __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc); 00400 00401 hrtc->State = HAL_RTC_STATE_READY; 00402 00403 /* Process Unlocked */ 00404 __HAL_UNLOCK(hrtc); 00405 00406 return HAL_OK; 00407 } 00408 00409 /** 00410 * @brief Get the RTC TimeStamp value. 00411 * @param hrtc: RTC handle 00412 * @param sTimeStamp: Pointer to Time structure 00413 * @param sTimeStampDate: Pointer to Date structure 00414 * @param Format: specifies the format of the entered parameters. 00415 * This parameter can be one of the following values: 00416 * @arg RTC_FORMAT_BIN: Binary data format 00417 * @arg RTC_FORMAT_BCD: BCD data format 00418 * @retval HAL status 00419 */ 00420 HAL_StatusTypeDef HAL_RTCEx_GetTimeStamp(RTC_HandleTypeDef *hrtc, RTC_TimeTypeDef* sTimeStamp, RTC_DateTypeDef* sTimeStampDate, uint32_t Format) 00421 { 00422 uint32_t tmptime = 0, tmpdate = 0; 00423 00424 /* Check the parameters */ 00425 assert_param(IS_RTC_FORMAT(Format)); 00426 00427 /* Get the TimeStamp time and date registers values */ 00428 tmptime = (uint32_t)(hrtc->Instance->TSTR & RTC_TR_RESERVED_MASK); 00429 tmpdate = (uint32_t)(hrtc->Instance->TSDR & RTC_DR_RESERVED_MASK); 00430 00431 /* Fill the Time structure fields with the read parameters */ 00432 sTimeStamp->Hours = (uint8_t)((tmptime & (RTC_TR_HT | RTC_TR_HU)) >> 16); 00433 sTimeStamp->Minutes = (uint8_t)((tmptime & (RTC_TR_MNT | RTC_TR_MNU)) >> 8); 00434 sTimeStamp->Seconds = (uint8_t)(tmptime & (RTC_TR_ST | RTC_TR_SU)); 00435 sTimeStamp->TimeFormat = (uint8_t)((tmptime & (RTC_TR_PM)) >> 16); 00436 sTimeStamp->SubSeconds = (uint32_t) hrtc->Instance->TSSSR; 00437 00438 /* Fill the Date structure fields with the read parameters */ 00439 sTimeStampDate->Year = 0; 00440 sTimeStampDate->Month = (uint8_t)((tmpdate & (RTC_DR_MT | RTC_DR_MU)) >> 8); 00441 sTimeStampDate->Date = (uint8_t)(tmpdate & (RTC_DR_DT | RTC_DR_DU)); 00442 sTimeStampDate->WeekDay = (uint8_t)((tmpdate & (RTC_DR_WDU)) >> 13); 00443 00444 /* Check the input parameters format */ 00445 if(Format == RTC_FORMAT_BIN) 00446 { 00447 /* Convert the TimeStamp structure parameters to Binary format */ 00448 sTimeStamp->Hours = (uint8_t)RTC_Bcd2ToByte(sTimeStamp->Hours); 00449 sTimeStamp->Minutes = (uint8_t)RTC_Bcd2ToByte(sTimeStamp->Minutes); 00450 sTimeStamp->Seconds = (uint8_t)RTC_Bcd2ToByte(sTimeStamp->Seconds); 00451 00452 /* Convert the DateTimeStamp structure parameters to Binary format */ 00453 sTimeStampDate->Month = (uint8_t)RTC_Bcd2ToByte(sTimeStampDate->Month); 00454 sTimeStampDate->Date = (uint8_t)RTC_Bcd2ToByte(sTimeStampDate->Date); 00455 sTimeStampDate->WeekDay = (uint8_t)RTC_Bcd2ToByte(sTimeStampDate->WeekDay); 00456 } 00457 00458 /* Clear the TIMESTAMP Flags */ 00459 __HAL_RTC_INTERNAL_TIMESTAMP_CLEAR_FLAG(hrtc, RTC_FLAG_ITSF); 00460 __HAL_RTC_TIMESTAMP_CLEAR_FLAG(hrtc, RTC_FLAG_TSF); 00461 00462 return HAL_OK; 00463 } 00464 00465 /** 00466 * @brief Set Tamper. 00467 * @note By calling this API we disable the tamper interrupt for all tampers. 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 = 0; 00475 00476 /* Check the parameters */ 00477 assert_param(IS_RTC_TAMPER(sTamper->Tamper)); 00478 assert_param(IS_RTC_TAMPER_TRIGGER(sTamper->Trigger)); 00479 assert_param(IS_RTC_TAMPER_ERASE_MODE(sTamper->NoErase)); 00480 assert_param(IS_RTC_TAMPER_MASKFLAG_STATE(sTamper->MaskFlag)); 00481 assert_param(IS_RTC_TAMPER_FILTER(sTamper->Filter)); 00482 assert_param(IS_RTC_TAMPER_SAMPLING_FREQ(sTamper->SamplingFrequency)); 00483 assert_param(IS_RTC_TAMPER_PRECHARGE_DURATION(sTamper->PrechargeDuration)); 00484 assert_param(IS_RTC_TAMPER_PULLUP_STATE(sTamper->TamperPullUp)); 00485 assert_param(IS_RTC_TAMPER_TIMESTAMPONTAMPER_DETECTION(sTamper->TimeStampOnTamperDetection)); 00486 00487 /* Process Locked */ 00488 __HAL_LOCK(hrtc); 00489 00490 hrtc->State = HAL_RTC_STATE_BUSY; 00491 00492 /* Configure the tamper trigger */ 00493 if(sTamper->Trigger != RTC_TAMPERTRIGGER_RISINGEDGE) 00494 { 00495 sTamper->Trigger = (uint32_t)(sTamper->Tamper << 1); 00496 } 00497 00498 if(sTamper->NoErase != RTC_TAMPER_ERASE_BACKUP_ENABLE) 00499 { 00500 sTamper->NoErase = 0; 00501 #if defined(RTC_TAMPER1_SUPPORT) 00502 if((sTamper->Tamper & RTC_TAMPER_1) != 0) 00503 { 00504 sTamper->NoErase |= RTC_TAMPCR_TAMP1NOERASE; 00505 } 00506 #endif /* RTC_TAMPER1_SUPPORT */ 00507 if((sTamper->Tamper & RTC_TAMPER_2) != 0) 00508 { 00509 sTamper->NoErase |= RTC_TAMPCR_TAMP2NOERASE; 00510 } 00511 #if defined(RTC_TAMPER3_SUPPORT) 00512 if((sTamper->Tamper & RTC_TAMPER_3) != 0) 00513 { 00514 sTamper->NoErase |= RTC_TAMPCR_TAMP3NOERASE; 00515 } 00516 #endif /* RTC_TAMPER3_SUPPORT */ 00517 } 00518 00519 if(sTamper->MaskFlag != RTC_TAMPERMASK_FLAG_DISABLE) 00520 { 00521 sTamper->MaskFlag = 0; 00522 #if defined(RTC_TAMPER1_SUPPORT) 00523 if((sTamper->Tamper & RTC_TAMPER_1) != 0) 00524 { 00525 sTamper->MaskFlag |= RTC_TAMPCR_TAMP1MF; 00526 } 00527 #endif /* RTC_TAMPER1_SUPPORT */ 00528 if((sTamper->Tamper & RTC_TAMPER_2) != 0) 00529 { 00530 sTamper->MaskFlag |= RTC_TAMPCR_TAMP2MF; 00531 } 00532 #if defined(RTC_TAMPER3_SUPPORT) 00533 if((sTamper->Tamper & RTC_TAMPER_3) != 0) 00534 { 00535 sTamper->MaskFlag |= RTC_TAMPCR_TAMP3MF; 00536 } 00537 #endif /* RTC_TAMPER3_SUPPORT */ 00538 } 00539 00540 tmpreg = ((uint32_t)sTamper->Tamper | (uint32_t)sTamper->Trigger | (uint32_t)sTamper->NoErase |\ 00541 (uint32_t)sTamper->MaskFlag | (uint32_t)sTamper->Filter | (uint32_t)sTamper->SamplingFrequency |\ 00542 (uint32_t)sTamper->PrechargeDuration | (uint32_t)sTamper->TamperPullUp | sTamper->TimeStampOnTamperDetection); 00543 00544 hrtc->Instance->TAMPCR &= (uint32_t)~((uint32_t)sTamper->Tamper | (uint32_t)(sTamper->Tamper << 1) | RTC_TAMPCR_MASK); 00545 00546 hrtc->Instance->TAMPCR |= tmpreg; 00547 00548 hrtc->State = HAL_RTC_STATE_READY; 00549 00550 /* Process Unlocked */ 00551 __HAL_UNLOCK(hrtc); 00552 00553 return HAL_OK; 00554 } 00555 00556 /** 00557 * @brief Set Tamper with interrupt. 00558 * @note By calling this API we force the tamper interrupt for all tampers. 00559 * @param hrtc: RTC handle 00560 * @param sTamper: Pointer to RTC Tamper. 00561 * @retval HAL status 00562 */ 00563 HAL_StatusTypeDef HAL_RTCEx_SetTamper_IT(RTC_HandleTypeDef *hrtc, RTC_TamperTypeDef* sTamper) 00564 { 00565 uint32_t tmpreg = 0; 00566 00567 /* Check the parameters */ 00568 assert_param(IS_RTC_TAMPER(sTamper->Tamper)); 00569 assert_param(IS_RTC_TAMPER_INTERRUPT(sTamper->Interrupt)); 00570 assert_param(IS_RTC_TAMPER_TRIGGER(sTamper->Trigger)); 00571 assert_param(IS_RTC_TAMPER_ERASE_MODE(sTamper->NoErase)); 00572 assert_param(IS_RTC_TAMPER_MASKFLAG_STATE(sTamper->MaskFlag)); 00573 assert_param(IS_RTC_TAMPER_FILTER(sTamper->Filter)); 00574 assert_param(IS_RTC_TAMPER_SAMPLING_FREQ(sTamper->SamplingFrequency)); 00575 assert_param(IS_RTC_TAMPER_PRECHARGE_DURATION(sTamper->PrechargeDuration)); 00576 assert_param(IS_RTC_TAMPER_PULLUP_STATE(sTamper->TamperPullUp)); 00577 assert_param(IS_RTC_TAMPER_TIMESTAMPONTAMPER_DETECTION(sTamper->TimeStampOnTamperDetection)); 00578 00579 /* Process Locked */ 00580 __HAL_LOCK(hrtc); 00581 00582 hrtc->State = HAL_RTC_STATE_BUSY; 00583 00584 /* Configure the tamper trigger */ 00585 if(sTamper->Trigger != RTC_TAMPERTRIGGER_RISINGEDGE) 00586 { 00587 sTamper->Trigger = (uint32_t)(sTamper->Tamper << 1); 00588 } 00589 00590 if(sTamper->NoErase != RTC_TAMPER_ERASE_BACKUP_ENABLE) 00591 { 00592 sTamper->NoErase = 0; 00593 #if defined(RTC_TAMPER1_SUPPORT) 00594 if((sTamper->Tamper & RTC_TAMPER_1) != 0) 00595 { 00596 sTamper->NoErase |= RTC_TAMPCR_TAMP1NOERASE; 00597 } 00598 #endif /* RTC_TAMPER1_SUPPORT */ 00599 if((sTamper->Tamper & RTC_TAMPER_2) != 0) 00600 { 00601 sTamper->NoErase |= RTC_TAMPCR_TAMP2NOERASE; 00602 } 00603 #if defined(RTC_TAMPER3_SUPPORT) 00604 if((sTamper->Tamper & RTC_TAMPER_3) != 0) 00605 { 00606 sTamper->NoErase |= RTC_TAMPCR_TAMP3NOERASE; 00607 } 00608 #endif /* RTC_TAMPER3_SUPPORT */ 00609 } 00610 00611 if(sTamper->MaskFlag != RTC_TAMPERMASK_FLAG_DISABLE) 00612 { 00613 sTamper->MaskFlag = 0; 00614 #if defined(RTC_TAMPER1_SUPPORT) 00615 if((sTamper->Tamper & RTC_TAMPER_1) != 0) 00616 { 00617 sTamper->MaskFlag |= RTC_TAMPCR_TAMP1MF; 00618 } 00619 #endif /* RTC_TAMPER1_SUPPORT */ 00620 if((sTamper->Tamper & RTC_TAMPER_2) != 0) 00621 { 00622 sTamper->MaskFlag |= RTC_TAMPCR_TAMP2MF; 00623 } 00624 #if defined(RTC_TAMPER3_SUPPORT) 00625 if((sTamper->Tamper & RTC_TAMPER_3) != 0) 00626 { 00627 sTamper->MaskFlag |= RTC_TAMPCR_TAMP3MF; 00628 } 00629 #endif /* RTC_TAMPER3_SUPPORT */ 00630 } 00631 00632 tmpreg = ((uint32_t)sTamper->Tamper | (uint32_t)sTamper->Interrupt | (uint32_t)sTamper->Trigger | (uint32_t)sTamper->NoErase |\ 00633 (uint32_t)sTamper->MaskFlag | (uint32_t)sTamper->Filter | (uint32_t)sTamper->SamplingFrequency |\ 00634 (uint32_t)sTamper->PrechargeDuration | (uint32_t)sTamper->TamperPullUp | sTamper->TimeStampOnTamperDetection); 00635 00636 hrtc->Instance->TAMPCR &= (uint32_t)~((uint32_t)sTamper->Tamper | (uint32_t)(sTamper->Tamper << 1) | RTC_TAMPCR_MASK); 00637 00638 hrtc->Instance->TAMPCR |= tmpreg; 00639 00640 /* RTC Tamper Interrupt Configuration: EXTI configuration */ 00641 __HAL_RTC_TAMPER_TIMESTAMP_EXTI_ENABLE_IT(); 00642 00643 __HAL_RTC_TAMPER_TIMESTAMP_EXTI_ENABLE_RISING_EDGE(); 00644 00645 hrtc->State = HAL_RTC_STATE_READY; 00646 00647 /* Process Unlocked */ 00648 __HAL_UNLOCK(hrtc); 00649 00650 return HAL_OK; 00651 } 00652 00653 /** 00654 * @brief Deactivate Tamper. 00655 * @param hrtc: RTC handle 00656 * @param Tamper: Selected tamper pin. 00657 * This parameter can be any combination of RTC_TAMPER_1, RTC_TAMPER_2 and RTC_TAMPER_3. 00658 * @retval HAL status 00659 */ 00660 HAL_StatusTypeDef HAL_RTCEx_DeactivateTamper(RTC_HandleTypeDef *hrtc, uint32_t Tamper) 00661 { 00662 assert_param(IS_RTC_TAMPER(Tamper)); 00663 00664 /* Process Locked */ 00665 __HAL_LOCK(hrtc); 00666 00667 hrtc->State = HAL_RTC_STATE_BUSY; 00668 00669 /* Disable the selected Tamper pin */ 00670 hrtc->Instance->TAMPCR &= ((uint32_t)~Tamper); 00671 00672 #if defined(RTC_TAMPER1_SUPPORT) 00673 if ((Tamper & RTC_TAMPER_1) != 0) 00674 { 00675 /* Disable the Tamper1 interrupt */ 00676 hrtc->Instance->TAMPCR &= ((uint32_t)~(RTC_IT_TAMP | RTC_IT_TAMP1)); 00677 } 00678 #endif /* RTC_TAMPER1_SUPPORT */ 00679 if ((Tamper & RTC_TAMPER_2) != 0) 00680 { 00681 /* Disable the Tamper2 interrupt */ 00682 hrtc->Instance->TAMPCR &= ((uint32_t)~(RTC_IT_TAMP | RTC_IT_TAMP2)); 00683 } 00684 #if defined(RTC_TAMPER3_SUPPORT) 00685 if ((Tamper & RTC_TAMPER_3) != 0) 00686 { 00687 /* Disable the Tamper3 interrupt */ 00688 hrtc->Instance->TAMPCR &= ((uint32_t)~(RTC_IT_TAMP | RTC_IT_TAMP3)); 00689 } 00690 #endif /* RTC_TAMPER3_SUPPORT */ 00691 00692 hrtc->State = HAL_RTC_STATE_READY; 00693 00694 /* Process Unlocked */ 00695 __HAL_UNLOCK(hrtc); 00696 00697 return HAL_OK; 00698 } 00699 00700 /** 00701 * @brief Handle TimeStamp interrupt request. 00702 * @param hrtc: RTC handle 00703 * @retval None 00704 */ 00705 void HAL_RTCEx_TamperTimeStampIRQHandler(RTC_HandleTypeDef *hrtc) 00706 { 00707 /* Clear the EXTI's Flag for RTC TimeStamp and Tamper */ 00708 __HAL_RTC_TAMPER_TIMESTAMP_EXTI_CLEAR_FLAG(); 00709 00710 /* As Tampers and TimeStamp are sharing the same EXTI line, exit when no more pending event */ 00711 while( 00712 ((__HAL_RTC_TIMESTAMP_GET_IT_SOURCE(hrtc, RTC_IT_TS) != RESET) && (__HAL_RTC_TIMESTAMP_GET_FLAG(hrtc, RTC_FLAG_TSF) != RESET)) 00713 #if defined(RTC_TAMPER1_SUPPORT) 00714 || ((__HAL_RTC_TAMPER_GET_IT_SOURCE(hrtc, RTC_IT_TAMP | RTC_IT_TAMP1) != RESET) && (__HAL_RTC_TAMPER_GET_FLAG(hrtc, RTC_FLAG_TAMP1F) != RESET)) 00715 #endif /* RTC_TAMPER1_SUPPORT */ 00716 || ((__HAL_RTC_TAMPER_GET_IT_SOURCE(hrtc, RTC_IT_TAMP | RTC_IT_TAMP2) != RESET) && (__HAL_RTC_TAMPER_GET_FLAG(hrtc, RTC_FLAG_TAMP2F) != RESET)) 00717 #if defined(RTC_TAMPER3_SUPPORT) 00718 || ((__HAL_RTC_TAMPER_GET_IT_SOURCE(hrtc, RTC_IT_TAMP | RTC_IT_TAMP3) != RESET) && (__HAL_RTC_TAMPER_GET_FLAG(hrtc, RTC_FLAG_TAMP3F) != RESET)) 00719 #endif /* RTC_TAMPER3_SUPPORT */ 00720 ) 00721 { 00722 00723 /* Get the TimeStamp interrupt source enable status and pending flag status */ 00724 if((__HAL_RTC_TIMESTAMP_GET_IT_SOURCE(hrtc, RTC_IT_TS) != RESET) && (__HAL_RTC_TIMESTAMP_GET_FLAG(hrtc, RTC_FLAG_TSF) != RESET)) 00725 { 00726 /* TIMESTAMP callback */ 00727 #if (USE_HAL_RTC_REGISTER_CALLBACKS == 1) 00728 hrtc->TimeStampEventCallback(hrtc); 00729 #else 00730 HAL_RTCEx_TimeStampEventCallback(hrtc); 00731 #endif /* USE_HAL_RTC_REGISTER_CALLBACKS */ 00732 00733 /* Clear the TIMESTAMP interrupt pending bit (this will clear timestamp time and date registers) */ 00734 __HAL_RTC_TIMESTAMP_CLEAR_FLAG(hrtc, RTC_FLAG_TSF); 00735 } 00736 00737 #if defined(RTC_TAMPER1_SUPPORT) 00738 /* Get the Tamper1 interrupt source enable status and pending flag status */ 00739 if((__HAL_RTC_TAMPER_GET_IT_SOURCE(hrtc, RTC_IT_TAMP | RTC_IT_TAMP1) != RESET) && (__HAL_RTC_TAMPER_GET_FLAG(hrtc, RTC_FLAG_TAMP1F) != RESET)) 00740 { 00741 /* Clear the Tamper1 interrupt pending bit */ 00742 __HAL_RTC_TAMPER_CLEAR_FLAG(hrtc, RTC_FLAG_TAMP1F); 00743 00744 /* Tamper1 callback */ 00745 #if (USE_HAL_RTC_REGISTER_CALLBACKS == 1) 00746 hrtc->Tamper1EventCallback(hrtc); 00747 #else 00748 HAL_RTCEx_Tamper1EventCallback(hrtc); 00749 #endif /* USE_HAL_RTC_REGISTER_CALLBACKS */ 00750 } 00751 #endif /* RTC_TAMPER1_SUPPORT */ 00752 00753 /* Get the Tamper2 interrupt source enable status and pending flag status */ 00754 if((__HAL_RTC_TAMPER_GET_IT_SOURCE(hrtc, RTC_IT_TAMP | RTC_IT_TAMP2) != RESET) && (__HAL_RTC_TAMPER_GET_FLAG(hrtc, RTC_FLAG_TAMP2F) != RESET)) 00755 { 00756 /* Clear the Tamper2 interrupt pending bit */ 00757 __HAL_RTC_TAMPER_CLEAR_FLAG(hrtc, RTC_FLAG_TAMP2F); 00758 00759 /* Tamper2 callback */ 00760 #if (USE_HAL_RTC_REGISTER_CALLBACKS == 1) 00761 hrtc->Tamper2EventCallback(hrtc); 00762 #else 00763 HAL_RTCEx_Tamper2EventCallback(hrtc); 00764 #endif /* USE_HAL_RTC_REGISTER_CALLBACKS */ 00765 } 00766 00767 #if defined(RTC_TAMPER3_SUPPORT) 00768 /* Get the Tamper3 interrupts source enable status and pending flag status */ 00769 if((__HAL_RTC_TAMPER_GET_IT_SOURCE(hrtc, RTC_IT_TAMP | RTC_IT_TAMP3) != RESET) && (__HAL_RTC_TAMPER_GET_FLAG(hrtc, RTC_FLAG_TAMP3F) != RESET)) 00770 { 00771 /* Clear the Tamper3 interrupt pending bit */ 00772 __HAL_RTC_TAMPER_CLEAR_FLAG(hrtc, RTC_FLAG_TAMP3F); 00773 00774 /* Tamper3 callback */ 00775 #if (USE_HAL_RTC_REGISTER_CALLBACKS == 1) 00776 hrtc->Tamper3EventCallback(hrtc); 00777 #else 00778 HAL_RTCEx_Tamper3EventCallback(hrtc); 00779 #endif /* USE_HAL_RTC_REGISTER_CALLBACKS */ 00780 } 00781 #endif /* RTC_TAMPER3_SUPPORT */ 00782 00783 } 00784 00785 /* Change RTC state */ 00786 hrtc->State = HAL_RTC_STATE_READY; 00787 } 00788 00789 /** 00790 * @brief TimeStamp callback. 00791 * @param hrtc: RTC handle 00792 * @retval None 00793 */ 00794 __weak void HAL_RTCEx_TimeStampEventCallback(RTC_HandleTypeDef *hrtc) 00795 { 00796 /* Prevent unused argument(s) compilation warning */ 00797 UNUSED(hrtc); 00798 00799 /* NOTE : This function should not be modified, when the callback is needed, 00800 the HAL_RTCEx_TimeStampEventCallback could be implemented in the user file 00801 */ 00802 } 00803 00804 #if defined(RTC_TAMPER1_SUPPORT) 00805 /** 00806 * @brief Tamper 1 callback. 00807 * @param hrtc: RTC handle 00808 * @retval None 00809 */ 00810 __weak void HAL_RTCEx_Tamper1EventCallback(RTC_HandleTypeDef *hrtc) 00811 { 00812 /* Prevent unused argument(s) compilation warning */ 00813 UNUSED(hrtc); 00814 00815 /* NOTE : This function should not be modified, when the callback is needed, 00816 the HAL_RTCEx_Tamper1EventCallback could be implemented in the user file 00817 */ 00818 } 00819 #endif /* RTC_TAMPER1_SUPPORT */ 00820 00821 /** 00822 * @brief Tamper 2 callback. 00823 * @param hrtc: RTC handle 00824 * @retval None 00825 */ 00826 __weak void HAL_RTCEx_Tamper2EventCallback(RTC_HandleTypeDef *hrtc) 00827 { 00828 /* Prevent unused argument(s) compilation warning */ 00829 UNUSED(hrtc); 00830 00831 /* NOTE : This function should not be modified, when the callback is needed, 00832 the HAL_RTCEx_Tamper2EventCallback could be implemented in the user file 00833 */ 00834 } 00835 00836 #if defined(RTC_TAMPER3_SUPPORT) 00837 /** 00838 * @brief Tamper 3 callback. 00839 * @param hrtc: RTC handle 00840 * @retval None 00841 */ 00842 __weak void HAL_RTCEx_Tamper3EventCallback(RTC_HandleTypeDef *hrtc) 00843 { 00844 /* Prevent unused argument(s) compilation warning */ 00845 UNUSED(hrtc); 00846 00847 /* NOTE : This function should not be modified, when the callback is needed, 00848 the HAL_RTCEx_Tamper3EventCallback could be implemented in the user file 00849 */ 00850 } 00851 #endif /* RTC_TAMPER3_SUPPORT */ 00852 00853 /** 00854 * @brief Handle TimeStamp polling request. 00855 * @param hrtc: RTC handle 00856 * @param Timeout: Timeout duration 00857 * @retval HAL status 00858 */ 00859 HAL_StatusTypeDef HAL_RTCEx_PollForTimeStampEvent(RTC_HandleTypeDef *hrtc, uint32_t Timeout) 00860 { 00861 uint32_t tickstart = HAL_GetTick(); 00862 00863 while(__HAL_RTC_TIMESTAMP_GET_FLAG(hrtc, RTC_FLAG_TSF) == RESET) 00864 { 00865 if(__HAL_RTC_TIMESTAMP_GET_FLAG(hrtc, RTC_FLAG_TSOVF) != RESET) 00866 { 00867 /* Clear the TIMESTAMP OverRun Flag */ 00868 __HAL_RTC_TIMESTAMP_CLEAR_FLAG(hrtc, RTC_FLAG_TSOVF); 00869 00870 /* Change TIMESTAMP state */ 00871 hrtc->State = HAL_RTC_STATE_ERROR; 00872 00873 return HAL_ERROR; 00874 } 00875 00876 if(Timeout != HAL_MAX_DELAY) 00877 { 00878 if((Timeout == 0)||((HAL_GetTick() - tickstart ) > Timeout)) 00879 { 00880 hrtc->State = HAL_RTC_STATE_TIMEOUT; 00881 return HAL_TIMEOUT; 00882 } 00883 } 00884 } 00885 00886 /* Change RTC state */ 00887 hrtc->State = HAL_RTC_STATE_READY; 00888 00889 return HAL_OK; 00890 } 00891 00892 #if defined(RTC_TAMPER1_SUPPORT) 00893 /** 00894 * @brief Handle Tamper 1 Polling. 00895 * @param hrtc: RTC handle 00896 * @param Timeout: Timeout duration 00897 * @retval HAL status 00898 */ 00899 HAL_StatusTypeDef HAL_RTCEx_PollForTamper1Event(RTC_HandleTypeDef *hrtc, uint32_t Timeout) 00900 { 00901 uint32_t tickstart = HAL_GetTick(); 00902 00903 /* Get the status of the Interrupt */ 00904 while(__HAL_RTC_TAMPER_GET_FLAG(hrtc, RTC_FLAG_TAMP1F)== RESET) 00905 { 00906 if(Timeout != HAL_MAX_DELAY) 00907 { 00908 if((Timeout == 0)||((HAL_GetTick() - tickstart ) > Timeout)) 00909 { 00910 hrtc->State = HAL_RTC_STATE_TIMEOUT; 00911 return HAL_TIMEOUT; 00912 } 00913 } 00914 } 00915 00916 /* Clear the Tamper Flag */ 00917 __HAL_RTC_TAMPER_CLEAR_FLAG(hrtc, RTC_FLAG_TAMP1F); 00918 00919 /* Change RTC state */ 00920 hrtc->State = HAL_RTC_STATE_READY; 00921 00922 return HAL_OK; 00923 } 00924 #endif /* RTC_TAMPER1_SUPPORT */ 00925 00926 /** 00927 * @brief Handle Tamper 2 Polling. 00928 * @param hrtc: RTC handle 00929 * @param Timeout: Timeout duration 00930 * @retval HAL status 00931 */ 00932 HAL_StatusTypeDef HAL_RTCEx_PollForTamper2Event(RTC_HandleTypeDef *hrtc, uint32_t Timeout) 00933 { 00934 uint32_t tickstart = HAL_GetTick(); 00935 00936 /* Get the status of the Interrupt */ 00937 while(__HAL_RTC_TAMPER_GET_FLAG(hrtc, RTC_FLAG_TAMP2F) == RESET) 00938 { 00939 if(Timeout != HAL_MAX_DELAY) 00940 { 00941 if((Timeout == 0)||((HAL_GetTick() - tickstart ) > Timeout)) 00942 { 00943 hrtc->State = HAL_RTC_STATE_TIMEOUT; 00944 return HAL_TIMEOUT; 00945 } 00946 } 00947 } 00948 00949 /* Clear the Tamper Flag */ 00950 __HAL_RTC_TAMPER_CLEAR_FLAG(hrtc, RTC_FLAG_TAMP2F); 00951 00952 /* Change RTC state */ 00953 hrtc->State = HAL_RTC_STATE_READY; 00954 00955 return HAL_OK; 00956 } 00957 00958 #if defined(RTC_TAMPER3_SUPPORT) 00959 /** 00960 * @brief Handle Tamper 3 Polling. 00961 * @param hrtc: RTC handle 00962 * @param Timeout: Timeout duration 00963 * @retval HAL status 00964 */ 00965 HAL_StatusTypeDef HAL_RTCEx_PollForTamper3Event(RTC_HandleTypeDef *hrtc, uint32_t Timeout) 00966 { 00967 uint32_t tickstart = HAL_GetTick(); 00968 00969 /* Get the status of the Interrupt */ 00970 while(__HAL_RTC_TAMPER_GET_FLAG(hrtc, RTC_FLAG_TAMP3F) == RESET) 00971 { 00972 if(Timeout != HAL_MAX_DELAY) 00973 { 00974 if((Timeout == 0)||((HAL_GetTick() - tickstart ) > Timeout)) 00975 { 00976 hrtc->State = HAL_RTC_STATE_TIMEOUT; 00977 return HAL_TIMEOUT; 00978 } 00979 } 00980 } 00981 00982 /* Clear the Tamper Flag */ 00983 __HAL_RTC_TAMPER_CLEAR_FLAG(hrtc, RTC_FLAG_TAMP3F); 00984 00985 /* Change RTC state */ 00986 hrtc->State = HAL_RTC_STATE_READY; 00987 00988 return HAL_OK; 00989 } 00990 #endif /* RTC_TAMPER3_SUPPORT */ 00991 00992 /** 00993 * @} 00994 */ 00995 00996 /** @defgroup RTCEx_Exported_Functions_Group2 RTC Wake-up functions 00997 * @brief RTC Wake-up functions 00998 * 00999 @verbatim 01000 =============================================================================== 01001 ##### RTC Wake-up functions ##### 01002 =============================================================================== 01003 01004 [..] This section provide functions allowing to configure Wake-up feature 01005 01006 @endverbatim 01007 * @{ 01008 */ 01009 01010 /** 01011 * @brief Set wake up timer. 01012 * @param hrtc: RTC handle 01013 * @param WakeUpCounter: Wake up counter 01014 * @param WakeUpClock: Wake up clock 01015 * @retval HAL status 01016 */ 01017 HAL_StatusTypeDef HAL_RTCEx_SetWakeUpTimer(RTC_HandleTypeDef *hrtc, uint32_t WakeUpCounter, uint32_t WakeUpClock) 01018 { 01019 uint32_t tickstart = 0; 01020 01021 /* Check the parameters */ 01022 assert_param(IS_RTC_WAKEUP_CLOCK(WakeUpClock)); 01023 assert_param(IS_RTC_WAKEUP_COUNTER(WakeUpCounter)); 01024 01025 /* Process Locked */ 01026 __HAL_LOCK(hrtc); 01027 01028 hrtc->State = HAL_RTC_STATE_BUSY; 01029 01030 /* Disable the write protection for RTC registers */ 01031 __HAL_RTC_WRITEPROTECTION_DISABLE(hrtc); 01032 01033 /*Check RTC WUTWF flag is reset only when wake up timer enabled*/ 01034 if((hrtc->Instance->CR & RTC_CR_WUTE) != RESET) 01035 { 01036 tickstart = HAL_GetTick(); 01037 01038 /* Wait till RTC WUTWF flag is reset and if Time out is reached exit */ 01039 while(__HAL_RTC_WAKEUPTIMER_GET_FLAG(hrtc, RTC_FLAG_WUTWF) == SET) 01040 { 01041 if((HAL_GetTick() - tickstart ) > RTC_TIMEOUT_VALUE) 01042 { 01043 /* Enable the write protection for RTC registers */ 01044 __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc); 01045 01046 hrtc->State = HAL_RTC_STATE_TIMEOUT; 01047 01048 /* Process Unlocked */ 01049 __HAL_UNLOCK(hrtc); 01050 01051 return HAL_TIMEOUT; 01052 } 01053 } 01054 } 01055 01056 __HAL_RTC_WAKEUPTIMER_DISABLE(hrtc); 01057 01058 tickstart = HAL_GetTick(); 01059 01060 /* Wait till RTC WUTWF flag is set and if Time out is reached exit */ 01061 while(__HAL_RTC_WAKEUPTIMER_GET_FLAG(hrtc, RTC_FLAG_WUTWF) == RESET) 01062 { 01063 if((HAL_GetTick() - tickstart ) > RTC_TIMEOUT_VALUE) 01064 { 01065 /* Enable the write protection for RTC registers */ 01066 __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc); 01067 01068 hrtc->State = HAL_RTC_STATE_TIMEOUT; 01069 01070 /* Process Unlocked */ 01071 __HAL_UNLOCK(hrtc); 01072 01073 return HAL_TIMEOUT; 01074 } 01075 } 01076 01077 /* Clear the Wakeup Timer clock source bits in CR register */ 01078 hrtc->Instance->CR &= (uint32_t)~RTC_CR_WUCKSEL; 01079 01080 /* Configure the clock source */ 01081 hrtc->Instance->CR |= (uint32_t)WakeUpClock; 01082 01083 /* Configure the Wakeup Timer counter */ 01084 hrtc->Instance->WUTR = (uint32_t)WakeUpCounter; 01085 01086 /* Enable the Wakeup Timer */ 01087 __HAL_RTC_WAKEUPTIMER_ENABLE(hrtc); 01088 01089 /* Enable the write protection for RTC registers */ 01090 __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc); 01091 01092 hrtc->State = HAL_RTC_STATE_READY; 01093 01094 /* Process Unlocked */ 01095 __HAL_UNLOCK(hrtc); 01096 01097 return HAL_OK; 01098 } 01099 01100 /** 01101 * @brief Set wake up timer with interrupt. 01102 * @param hrtc: RTC handle 01103 * @param WakeUpCounter: Wake up counter 01104 * @param WakeUpClock: Wake up clock 01105 * @retval HAL status 01106 */ 01107 HAL_StatusTypeDef HAL_RTCEx_SetWakeUpTimer_IT(RTC_HandleTypeDef *hrtc, uint32_t WakeUpCounter, uint32_t WakeUpClock) 01108 { 01109 uint32_t tickstart = 0; 01110 01111 /* Check the parameters */ 01112 assert_param(IS_RTC_WAKEUP_CLOCK(WakeUpClock)); 01113 assert_param(IS_RTC_WAKEUP_COUNTER(WakeUpCounter)); 01114 01115 /* Process Locked */ 01116 __HAL_LOCK(hrtc); 01117 01118 hrtc->State = HAL_RTC_STATE_BUSY; 01119 01120 /* Disable the write protection for RTC registers */ 01121 __HAL_RTC_WRITEPROTECTION_DISABLE(hrtc); 01122 01123 /*Check RTC WUTWF flag is reset only when wake up timer enabled*/ 01124 if((hrtc->Instance->CR & RTC_CR_WUTE) != RESET) 01125 { 01126 tickstart = HAL_GetTick(); 01127 01128 /* Wait till RTC WUTWF flag is reset and if Time out is reached exit */ 01129 while(__HAL_RTC_WAKEUPTIMER_GET_FLAG(hrtc, RTC_FLAG_WUTWF) == SET) 01130 { 01131 if((HAL_GetTick() - tickstart ) > RTC_TIMEOUT_VALUE) 01132 { 01133 /* Enable the write protection for RTC registers */ 01134 __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc); 01135 01136 hrtc->State = HAL_RTC_STATE_TIMEOUT; 01137 01138 /* Process Unlocked */ 01139 __HAL_UNLOCK(hrtc); 01140 01141 return HAL_TIMEOUT; 01142 } 01143 } 01144 } 01145 /* Disable the Wake-Up timer */ 01146 __HAL_RTC_WAKEUPTIMER_DISABLE(hrtc); 01147 01148 /* Clear flag Wake-Up */ 01149 __HAL_RTC_WAKEUPTIMER_CLEAR_FLAG(hrtc, RTC_FLAG_WUTF); 01150 01151 tickstart = HAL_GetTick(); 01152 01153 /* Wait till RTC WUTWF flag is set and if Time out is reached exit */ 01154 while(__HAL_RTC_WAKEUPTIMER_GET_FLAG(hrtc, RTC_FLAG_WUTWF) == RESET) 01155 { 01156 if((HAL_GetTick() - tickstart ) > RTC_TIMEOUT_VALUE) 01157 { 01158 /* Enable the write protection for RTC registers */ 01159 __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc); 01160 01161 hrtc->State = HAL_RTC_STATE_TIMEOUT; 01162 01163 /* Process Unlocked */ 01164 __HAL_UNLOCK(hrtc); 01165 01166 return HAL_TIMEOUT; 01167 } 01168 } 01169 01170 /* Configure the Wakeup Timer counter */ 01171 hrtc->Instance->WUTR = (uint32_t)WakeUpCounter; 01172 01173 /* Clear the Wakeup Timer clock source bits in CR register */ 01174 hrtc->Instance->CR &= (uint32_t)~RTC_CR_WUCKSEL; 01175 01176 /* Configure the clock source */ 01177 hrtc->Instance->CR |= (uint32_t)WakeUpClock; 01178 01179 /* RTC WakeUpTimer Interrupt Configuration: EXTI configuration */ 01180 __HAL_RTC_WAKEUPTIMER_EXTI_ENABLE_IT(); 01181 01182 __HAL_RTC_WAKEUPTIMER_EXTI_ENABLE_RISING_EDGE(); 01183 01184 /* Configure the Interrupt in the RTC_CR register */ 01185 __HAL_RTC_WAKEUPTIMER_ENABLE_IT(hrtc,RTC_IT_WUT); 01186 01187 /* Enable the Wakeup Timer */ 01188 __HAL_RTC_WAKEUPTIMER_ENABLE(hrtc); 01189 01190 /* Enable the write protection for RTC registers */ 01191 __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc); 01192 01193 hrtc->State = HAL_RTC_STATE_READY; 01194 01195 /* Process Unlocked */ 01196 __HAL_UNLOCK(hrtc); 01197 01198 return HAL_OK; 01199 } 01200 01201 /** 01202 * @brief Deactivate wake up timer counter. 01203 * @param hrtc: RTC handle 01204 * @retval HAL status 01205 */ 01206 uint32_t HAL_RTCEx_DeactivateWakeUpTimer(RTC_HandleTypeDef *hrtc) 01207 { 01208 uint32_t tickstart = 0; 01209 01210 /* Process Locked */ 01211 __HAL_LOCK(hrtc); 01212 01213 hrtc->State = HAL_RTC_STATE_BUSY; 01214 01215 /* Disable the write protection for RTC registers */ 01216 __HAL_RTC_WRITEPROTECTION_DISABLE(hrtc); 01217 01218 /* Disable the Wakeup Timer */ 01219 __HAL_RTC_WAKEUPTIMER_DISABLE(hrtc); 01220 01221 /* In case of interrupt mode is used, the interrupt source must disabled */ 01222 __HAL_RTC_WAKEUPTIMER_DISABLE_IT(hrtc,RTC_IT_WUT); 01223 01224 tickstart = HAL_GetTick(); 01225 /* Wait till RTC WUTWF flag is set and if Time out is reached exit */ 01226 while(__HAL_RTC_WAKEUPTIMER_GET_FLAG(hrtc, RTC_FLAG_WUTWF) == RESET) 01227 { 01228 if((HAL_GetTick() - tickstart ) > RTC_TIMEOUT_VALUE) 01229 { 01230 /* Enable the write protection for RTC registers */ 01231 __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc); 01232 01233 hrtc->State = HAL_RTC_STATE_TIMEOUT; 01234 01235 /* Process Unlocked */ 01236 __HAL_UNLOCK(hrtc); 01237 01238 return HAL_TIMEOUT; 01239 } 01240 } 01241 01242 /* Enable the write protection for RTC registers */ 01243 __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc); 01244 01245 hrtc->State = HAL_RTC_STATE_READY; 01246 01247 /* Process Unlocked */ 01248 __HAL_UNLOCK(hrtc); 01249 01250 return HAL_OK; 01251 } 01252 01253 /** 01254 * @brief Get wake up timer counter. 01255 * @param hrtc: RTC handle 01256 * @retval Counter value 01257 */ 01258 uint32_t HAL_RTCEx_GetWakeUpTimer(RTC_HandleTypeDef *hrtc) 01259 { 01260 /* Get the counter value */ 01261 return ((uint32_t)(hrtc->Instance->WUTR & RTC_WUTR_WUT)); 01262 } 01263 01264 /** 01265 * @brief Handle Wake Up Timer interrupt request. 01266 * @param hrtc: RTC handle 01267 * @retval None 01268 */ 01269 void HAL_RTCEx_WakeUpTimerIRQHandler(RTC_HandleTypeDef *hrtc) 01270 { 01271 /* Clear the EXTI's line Flag for RTC WakeUpTimer */ 01272 __HAL_RTC_WAKEUPTIMER_EXTI_CLEAR_FLAG(); 01273 01274 /* Get the pending status of the WAKEUPTIMER Interrupt */ 01275 if(__HAL_RTC_WAKEUPTIMER_GET_FLAG(hrtc, RTC_FLAG_WUTF) != RESET) 01276 { 01277 /* Clear the WAKEUPTIMER interrupt pending bit */ 01278 __HAL_RTC_WAKEUPTIMER_CLEAR_FLAG(hrtc, RTC_FLAG_WUTF); 01279 01280 /* WAKEUPTIMER callback */ 01281 #if (USE_HAL_RTC_REGISTER_CALLBACKS == 1) 01282 hrtc->WakeUpTimerEventCallback(hrtc); 01283 #else 01284 HAL_RTCEx_WakeUpTimerEventCallback(hrtc); 01285 #endif /* USE_HAL_RTC_REGISTER_CALLBACKS */ 01286 } 01287 01288 /* Change RTC state */ 01289 hrtc->State = HAL_RTC_STATE_READY; 01290 } 01291 01292 /** 01293 * @brief Wake Up Timer callback. 01294 * @param hrtc: RTC handle 01295 * @retval None 01296 */ 01297 __weak void HAL_RTCEx_WakeUpTimerEventCallback(RTC_HandleTypeDef *hrtc) 01298 { 01299 /* Prevent unused argument(s) compilation warning */ 01300 UNUSED(hrtc); 01301 01302 /* NOTE : This function should not be modified, when the callback is needed, 01303 the HAL_RTCEx_WakeUpTimerEventCallback could be implemented in the user file 01304 */ 01305 } 01306 01307 /** 01308 * @brief Handle Wake Up Timer Polling. 01309 * @param hrtc: RTC handle 01310 * @param Timeout: Timeout duration 01311 * @retval HAL status 01312 */ 01313 HAL_StatusTypeDef HAL_RTCEx_PollForWakeUpTimerEvent(RTC_HandleTypeDef *hrtc, uint32_t Timeout) 01314 { 01315 uint32_t tickstart = HAL_GetTick(); 01316 01317 while(__HAL_RTC_WAKEUPTIMER_GET_FLAG(hrtc, RTC_FLAG_WUTF) == RESET) 01318 { 01319 if(Timeout != HAL_MAX_DELAY) 01320 { 01321 if((Timeout == 0)||((HAL_GetTick() - tickstart ) > Timeout)) 01322 { 01323 hrtc->State = HAL_RTC_STATE_TIMEOUT; 01324 01325 return HAL_TIMEOUT; 01326 } 01327 } 01328 } 01329 01330 /* Clear the WAKEUPTIMER Flag */ 01331 __HAL_RTC_WAKEUPTIMER_CLEAR_FLAG(hrtc, RTC_FLAG_WUTF); 01332 01333 /* Change RTC state */ 01334 hrtc->State = HAL_RTC_STATE_READY; 01335 01336 return HAL_OK; 01337 } 01338 01339 /** 01340 * @} 01341 */ 01342 01343 01344 /** @defgroup RTCEx_Exported_Functions_Group3 Extended Peripheral Control functions 01345 * @brief Extended Peripheral Control functions 01346 * 01347 @verbatim 01348 =============================================================================== 01349 ##### Extended Peripheral Control functions ##### 01350 =============================================================================== 01351 [..] 01352 This subsection provides functions allowing to 01353 (+) Write a data in a specified RTC Backup data register 01354 (+) Read a data in a specified RTC Backup data register 01355 (+) Set the Coarse calibration parameters. 01356 (+) Deactivate the Coarse calibration parameters 01357 (+) Set the Smooth calibration parameters. 01358 (+) Configure the Synchronization Shift Control Settings. 01359 (+) Configure the Calibration Pinout (RTC_CALIB) Selection (1Hz or 512Hz). 01360 (+) Deactivate the Calibration Pinout (RTC_CALIB) Selection (1Hz or 512Hz). 01361 (+) Enable the RTC reference clock detection. 01362 (+) Disable the RTC reference clock detection. 01363 (+) Enable the Bypass Shadow feature. 01364 (+) Disable the Bypass Shadow feature. 01365 01366 @endverbatim 01367 * @{ 01368 */ 01369 01370 /** 01371 * @brief Write a data in a specified RTC Backup data register. 01372 * @param hrtc: RTC handle 01373 * @param BackupRegister: RTC Backup data Register number. 01374 * This parameter can be: RTC_BKP_DRx where x can be from 0 to 19 to 01375 * specify the register. 01376 * @param Data: Data to be written in the specified RTC Backup data register. 01377 * @retval None 01378 */ 01379 void HAL_RTCEx_BKUPWrite(RTC_HandleTypeDef *hrtc, uint32_t BackupRegister, uint32_t Data) 01380 { 01381 uint32_t tmp = 0; 01382 01383 /* Check the parameters */ 01384 assert_param(IS_RTC_BKP(BackupRegister)); 01385 01386 tmp = (uint32_t)&(hrtc->Instance->BKP0R); 01387 tmp += (BackupRegister * 4); 01388 01389 /* Write the specified register */ 01390 *(__IO uint32_t *)tmp = (uint32_t)Data; 01391 } 01392 01393 /** 01394 * @brief Read data from the specified RTC Backup data Register. 01395 * @param hrtc: RTC handle 01396 * @param BackupRegister: RTC Backup data Register number. 01397 * This parameter can be: RTC_BKP_DRx where x can be from 0 to 19 to 01398 * specify the register. 01399 * @retval Read value 01400 */ 01401 uint32_t HAL_RTCEx_BKUPRead(RTC_HandleTypeDef *hrtc, uint32_t BackupRegister) 01402 { 01403 uint32_t tmp = 0; 01404 01405 /* Check the parameters */ 01406 assert_param(IS_RTC_BKP(BackupRegister)); 01407 01408 tmp = (uint32_t)&(hrtc->Instance->BKP0R); 01409 tmp += (BackupRegister * 4); 01410 01411 /* Read the specified register */ 01412 return (*(__IO uint32_t *)tmp); 01413 } 01414 01415 /** 01416 * @brief Set the Smooth calibration parameters. 01417 * @param hrtc: RTC handle 01418 * @param SmoothCalibPeriod: Select the Smooth Calibration Period. 01419 * This parameter can be can be one of the following values : 01420 * @arg RTC_SMOOTHCALIB_PERIOD_32SEC: The smooth calibration period is 32s. 01421 * @arg RTC_SMOOTHCALIB_PERIOD_16SEC: The smooth calibration period is 16s. 01422 * @arg RTC_SMOOTHCALIB_PERIOD_8SEC: The smooth calibration period is 8s. 01423 * @param SmoothCalibPlusPulses: Select to Set or reset the CALP bit. 01424 * This parameter can be one of the following values: 01425 * @arg RTC_SMOOTHCALIB_PLUSPULSES_SET: Add one RTCCLK pulse every 2*11 pulses. 01426 * @arg RTC_SMOOTHCALIB_PLUSPULSES_RESET: No RTCCLK pulses are added. 01427 * @param SmoothCalibMinusPulsesValue: Select the value of CALM[8:0] bits. 01428 * This parameter can be one any value from 0 to 0x000001FF. 01429 * @note To deactivate the smooth calibration, the field SmoothCalibPlusPulses 01430 * must be equal to SMOOTHCALIB_PLUSPULSES_RESET and the field 01431 * SmoothCalibMinusPulsesValue must be equal to 0. 01432 * @retval HAL status 01433 */ 01434 HAL_StatusTypeDef HAL_RTCEx_SetSmoothCalib(RTC_HandleTypeDef* hrtc, uint32_t SmoothCalibPeriod, uint32_t SmoothCalibPlusPulses, uint32_t SmoothCalibMinusPulsesValue) 01435 { 01436 uint32_t tickstart = 0; 01437 01438 /* Check the parameters */ 01439 assert_param(IS_RTC_SMOOTH_CALIB_PERIOD(SmoothCalibPeriod)); 01440 assert_param(IS_RTC_SMOOTH_CALIB_PLUS(SmoothCalibPlusPulses)); 01441 assert_param(IS_RTC_SMOOTH_CALIB_MINUS(SmoothCalibMinusPulsesValue)); 01442 01443 /* Process Locked */ 01444 __HAL_LOCK(hrtc); 01445 01446 hrtc->State = HAL_RTC_STATE_BUSY; 01447 01448 /* Disable the write protection for RTC registers */ 01449 __HAL_RTC_WRITEPROTECTION_DISABLE(hrtc); 01450 01451 /* check if a calibration is pending*/ 01452 if((hrtc->Instance->ISR & RTC_ISR_RECALPF) != RESET) 01453 { 01454 tickstart = HAL_GetTick(); 01455 01456 /* check if a calibration is pending*/ 01457 while((hrtc->Instance->ISR & RTC_ISR_RECALPF) != RESET) 01458 { 01459 if((HAL_GetTick() - tickstart ) > RTC_TIMEOUT_VALUE) 01460 { 01461 /* Enable the write protection for RTC registers */ 01462 __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc); 01463 01464 /* Change RTC state */ 01465 hrtc->State = HAL_RTC_STATE_TIMEOUT; 01466 01467 /* Process Unlocked */ 01468 __HAL_UNLOCK(hrtc); 01469 01470 return HAL_TIMEOUT; 01471 } 01472 } 01473 } 01474 01475 /* Configure the Smooth calibration settings */ 01476 hrtc->Instance->CALR = (uint32_t)((uint32_t)SmoothCalibPeriod | (uint32_t)SmoothCalibPlusPulses | (uint32_t)SmoothCalibMinusPulsesValue); 01477 01478 /* Enable the write protection for RTC registers */ 01479 __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc); 01480 01481 /* Change RTC state */ 01482 hrtc->State = HAL_RTC_STATE_READY; 01483 01484 /* Process Unlocked */ 01485 __HAL_UNLOCK(hrtc); 01486 01487 return HAL_OK; 01488 } 01489 01490 /** 01491 * @brief Configure the Synchronization Shift Control Settings. 01492 * @note When REFCKON is set, firmware must not write to Shift control register. 01493 * @param hrtc: RTC handle 01494 * @param ShiftAdd1S: Select to add or not 1 second to the time calendar. 01495 * This parameter can be one of the following values : 01496 * @arg RTC_SHIFTADD1S_SET: Add one second to the clock calendar. 01497 * @arg RTC_SHIFTADD1S_RESET: No effect. 01498 * @param ShiftSubFS: Select the number of Second Fractions to substitute. 01499 * This parameter can be one any value from 0 to 0x7FFF. 01500 * @retval HAL status 01501 */ 01502 HAL_StatusTypeDef HAL_RTCEx_SetSynchroShift(RTC_HandleTypeDef* hrtc, uint32_t ShiftAdd1S, uint32_t ShiftSubFS) 01503 { 01504 uint32_t tickstart = 0; 01505 01506 /* Check the parameters */ 01507 assert_param(IS_RTC_SHIFT_ADD1S(ShiftAdd1S)); 01508 assert_param(IS_RTC_SHIFT_SUBFS(ShiftSubFS)); 01509 01510 /* Process Locked */ 01511 __HAL_LOCK(hrtc); 01512 01513 hrtc->State = HAL_RTC_STATE_BUSY; 01514 01515 /* Disable the write protection for RTC registers */ 01516 __HAL_RTC_WRITEPROTECTION_DISABLE(hrtc); 01517 01518 tickstart = HAL_GetTick(); 01519 01520 /* Wait until the shift is completed*/ 01521 while((hrtc->Instance->ISR & RTC_ISR_SHPF) != RESET) 01522 { 01523 if((HAL_GetTick() - tickstart ) > RTC_TIMEOUT_VALUE) 01524 { 01525 /* Enable the write protection for RTC registers */ 01526 __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc); 01527 01528 hrtc->State = HAL_RTC_STATE_TIMEOUT; 01529 01530 /* Process Unlocked */ 01531 __HAL_UNLOCK(hrtc); 01532 01533 return HAL_TIMEOUT; 01534 } 01535 } 01536 01537 /* Check if the reference clock detection is disabled */ 01538 if((hrtc->Instance->CR & RTC_CR_REFCKON) == RESET) 01539 { 01540 /* Configure the Shift settings */ 01541 hrtc->Instance->SHIFTR = (uint32_t)(uint32_t)(ShiftSubFS) | (uint32_t)(ShiftAdd1S); 01542 01543 /* If RTC_CR_BYPSHAD bit = 0, wait for synchro else this check is not needed */ 01544 if((hrtc->Instance->CR & RTC_CR_BYPSHAD) == RESET) 01545 { 01546 if(HAL_RTC_WaitForSynchro(hrtc) != HAL_OK) 01547 { 01548 /* Enable the write protection for RTC registers */ 01549 __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc); 01550 01551 hrtc->State = HAL_RTC_STATE_ERROR; 01552 01553 /* Process Unlocked */ 01554 __HAL_UNLOCK(hrtc); 01555 01556 return HAL_ERROR; 01557 } 01558 } 01559 } 01560 else 01561 { 01562 /* Enable the write protection for RTC registers */ 01563 __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc); 01564 01565 /* Change RTC state */ 01566 hrtc->State = HAL_RTC_STATE_ERROR; 01567 01568 /* Process Unlocked */ 01569 __HAL_UNLOCK(hrtc); 01570 01571 return HAL_ERROR; 01572 } 01573 01574 /* Enable the write protection for RTC registers */ 01575 __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc); 01576 01577 /* Change RTC state */ 01578 hrtc->State = HAL_RTC_STATE_READY; 01579 01580 /* Process Unlocked */ 01581 __HAL_UNLOCK(hrtc); 01582 01583 return HAL_OK; 01584 } 01585 01586 /** 01587 * @brief Configure the Calibration Pinout (RTC_CALIB) Selection (1Hz or 512Hz). 01588 * @param hrtc: RTC handle 01589 * @param CalibOutput : Select the Calibration output Selection . 01590 * This parameter can be one of the following values: 01591 * @arg RTC_CALIBOUTPUT_512HZ: A signal has a regular waveform at 512Hz. 01592 * @arg RTC_CALIBOUTPUT_1HZ: A signal has a regular waveform at 1Hz. 01593 * @retval HAL status 01594 */ 01595 HAL_StatusTypeDef HAL_RTCEx_SetCalibrationOutPut(RTC_HandleTypeDef* hrtc, uint32_t CalibOutput) 01596 { 01597 /* Check the parameters */ 01598 assert_param(IS_RTC_CALIB_OUTPUT(CalibOutput)); 01599 01600 /* Process Locked */ 01601 __HAL_LOCK(hrtc); 01602 01603 hrtc->State = HAL_RTC_STATE_BUSY; 01604 01605 /* Disable the write protection for RTC registers */ 01606 __HAL_RTC_WRITEPROTECTION_DISABLE(hrtc); 01607 01608 /* Clear flags before config */ 01609 hrtc->Instance->CR &= (uint32_t)~RTC_CR_COSEL; 01610 01611 /* Configure the RTC_CR register */ 01612 hrtc->Instance->CR |= (uint32_t)CalibOutput; 01613 01614 __HAL_RTC_CALIBRATION_OUTPUT_ENABLE(hrtc); 01615 01616 /* Enable the write protection for RTC registers */ 01617 __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc); 01618 01619 /* Change RTC state */ 01620 hrtc->State = HAL_RTC_STATE_READY; 01621 01622 /* Process Unlocked */ 01623 __HAL_UNLOCK(hrtc); 01624 01625 return HAL_OK; 01626 } 01627 01628 /** 01629 * @brief Deactivate the Calibration Pinout (RTC_CALIB) Selection (1Hz or 512Hz). 01630 * @param hrtc: RTC handle 01631 * @retval HAL status 01632 */ 01633 HAL_StatusTypeDef HAL_RTCEx_DeactivateCalibrationOutPut(RTC_HandleTypeDef* hrtc) 01634 { 01635 /* Process Locked */ 01636 __HAL_LOCK(hrtc); 01637 01638 hrtc->State = HAL_RTC_STATE_BUSY; 01639 01640 /* Disable the write protection for RTC registers */ 01641 __HAL_RTC_WRITEPROTECTION_DISABLE(hrtc); 01642 01643 __HAL_RTC_CALIBRATION_OUTPUT_DISABLE(hrtc); 01644 01645 /* Enable the write protection for RTC registers */ 01646 __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc); 01647 01648 /* Change RTC state */ 01649 hrtc->State = HAL_RTC_STATE_READY; 01650 01651 /* Process Unlocked */ 01652 __HAL_UNLOCK(hrtc); 01653 01654 return HAL_OK; 01655 } 01656 01657 /** 01658 * @brief Enable the RTC reference clock detection. 01659 * @param hrtc: RTC handle 01660 * @retval HAL status 01661 */ 01662 HAL_StatusTypeDef HAL_RTCEx_SetRefClock(RTC_HandleTypeDef* hrtc) 01663 { 01664 /* Process Locked */ 01665 __HAL_LOCK(hrtc); 01666 01667 hrtc->State = HAL_RTC_STATE_BUSY; 01668 01669 /* Disable the write protection for RTC registers */ 01670 __HAL_RTC_WRITEPROTECTION_DISABLE(hrtc); 01671 01672 /* Set Initialization mode */ 01673 if(RTC_EnterInitMode(hrtc) != HAL_OK) 01674 { 01675 /* Enable the write protection for RTC registers */ 01676 __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc); 01677 01678 /* Set RTC state*/ 01679 hrtc->State = HAL_RTC_STATE_ERROR; 01680 01681 /* Process Unlocked */ 01682 __HAL_UNLOCK(hrtc); 01683 01684 return HAL_ERROR; 01685 } 01686 else 01687 { 01688 __HAL_RTC_CLOCKREF_DETECTION_ENABLE(hrtc); 01689 01690 /* Exit Initialization mode */ 01691 hrtc->Instance->ISR &= (uint32_t)~RTC_ISR_INIT; 01692 } 01693 01694 /* Enable the write protection for RTC registers */ 01695 __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc); 01696 01697 /* Change RTC state */ 01698 hrtc->State = HAL_RTC_STATE_READY; 01699 01700 /* Process Unlocked */ 01701 __HAL_UNLOCK(hrtc); 01702 01703 return HAL_OK; 01704 } 01705 01706 /** 01707 * @brief Disable the RTC reference clock detection. 01708 * @param hrtc: RTC handle 01709 * @retval HAL status 01710 */ 01711 HAL_StatusTypeDef HAL_RTCEx_DeactivateRefClock(RTC_HandleTypeDef* hrtc) 01712 { 01713 /* Process Locked */ 01714 __HAL_LOCK(hrtc); 01715 01716 hrtc->State = HAL_RTC_STATE_BUSY; 01717 01718 /* Disable the write protection for RTC registers */ 01719 __HAL_RTC_WRITEPROTECTION_DISABLE(hrtc); 01720 01721 /* Set Initialization mode */ 01722 if(RTC_EnterInitMode(hrtc) != HAL_OK) 01723 { 01724 /* Enable the write protection for RTC registers */ 01725 __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc); 01726 01727 /* Set RTC state*/ 01728 hrtc->State = HAL_RTC_STATE_ERROR; 01729 01730 /* Process Unlocked */ 01731 __HAL_UNLOCK(hrtc); 01732 01733 return HAL_ERROR; 01734 } 01735 else 01736 { 01737 __HAL_RTC_CLOCKREF_DETECTION_DISABLE(hrtc); 01738 01739 /* Exit Initialization mode */ 01740 hrtc->Instance->ISR &= (uint32_t)~RTC_ISR_INIT; 01741 } 01742 01743 /* Enable the write protection for RTC registers */ 01744 __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc); 01745 01746 /* Change RTC state */ 01747 hrtc->State = HAL_RTC_STATE_READY; 01748 01749 /* Process Unlocked */ 01750 __HAL_UNLOCK(hrtc); 01751 01752 return HAL_OK; 01753 } 01754 01755 /** 01756 * @brief Enable the Bypass Shadow feature. 01757 * @param hrtc: RTC handle 01758 * @note When the Bypass Shadow is enabled the calendar value are taken 01759 * directly from the Calendar counter. 01760 * @retval HAL status 01761 */ 01762 HAL_StatusTypeDef HAL_RTCEx_EnableBypassShadow(RTC_HandleTypeDef* hrtc) 01763 { 01764 /* Process Locked */ 01765 __HAL_LOCK(hrtc); 01766 01767 hrtc->State = HAL_RTC_STATE_BUSY; 01768 01769 /* Disable the write protection for RTC registers */ 01770 __HAL_RTC_WRITEPROTECTION_DISABLE(hrtc); 01771 01772 /* Set the BYPSHAD bit */ 01773 hrtc->Instance->CR |= (uint8_t)RTC_CR_BYPSHAD; 01774 01775 /* Enable the write protection for RTC registers */ 01776 __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc); 01777 01778 /* Change RTC state */ 01779 hrtc->State = HAL_RTC_STATE_READY; 01780 01781 /* Process Unlocked */ 01782 __HAL_UNLOCK(hrtc); 01783 01784 return HAL_OK; 01785 } 01786 01787 /** 01788 * @brief Disable the Bypass Shadow feature. 01789 * @param hrtc: RTC handle 01790 * @note When the Bypass Shadow is enabled the calendar value are taken 01791 * directly from the Calendar counter. 01792 * @retval HAL status 01793 */ 01794 HAL_StatusTypeDef HAL_RTCEx_DisableBypassShadow(RTC_HandleTypeDef* hrtc) 01795 { 01796 /* Process Locked */ 01797 __HAL_LOCK(hrtc); 01798 01799 hrtc->State = HAL_RTC_STATE_BUSY; 01800 01801 /* Disable the write protection for RTC registers */ 01802 __HAL_RTC_WRITEPROTECTION_DISABLE(hrtc); 01803 01804 /* Reset the BYPSHAD bit */ 01805 hrtc->Instance->CR &= ((uint8_t)~RTC_CR_BYPSHAD); 01806 01807 /* Enable the write protection for RTC registers */ 01808 __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc); 01809 01810 /* Change RTC state */ 01811 hrtc->State = HAL_RTC_STATE_READY; 01812 01813 /* Process Unlocked */ 01814 __HAL_UNLOCK(hrtc); 01815 01816 return HAL_OK; 01817 } 01818 01819 /** 01820 * @} 01821 */ 01822 01823 /** @defgroup RTCEx_Exported_Functions_Group4 Extended features functions 01824 * @brief Extended features functions 01825 * 01826 @verbatim 01827 =============================================================================== 01828 ##### Extended features functions ##### 01829 =============================================================================== 01830 [..] This section provides functions allowing to: 01831 (+) RTC Alarm B callback 01832 (+) RTC Poll for Alarm B request 01833 01834 @endverbatim 01835 * @{ 01836 */ 01837 01838 /** 01839 * @brief Alarm B callback. 01840 * @param hrtc: RTC handle 01841 * @retval None 01842 */ 01843 __weak void HAL_RTCEx_AlarmBEventCallback(RTC_HandleTypeDef *hrtc) 01844 { 01845 /* Prevent unused argument(s) compilation warning */ 01846 UNUSED(hrtc); 01847 01848 /* NOTE : This function should not be modified, when the callback is needed, 01849 the HAL_RTCEx_AlarmBEventCallback could be implemented in the user file 01850 */ 01851 } 01852 01853 /** 01854 * @brief Handle Alarm B Polling request. 01855 * @param hrtc: RTC handle 01856 * @param Timeout: Timeout duration 01857 * @retval HAL status 01858 */ 01859 HAL_StatusTypeDef HAL_RTCEx_PollForAlarmBEvent(RTC_HandleTypeDef *hrtc, uint32_t Timeout) 01860 { 01861 uint32_t tickstart = HAL_GetTick(); 01862 01863 while(__HAL_RTC_ALARM_GET_FLAG(hrtc, RTC_FLAG_ALRBF) == RESET) 01864 { 01865 if(Timeout != HAL_MAX_DELAY) 01866 { 01867 if((Timeout == 0)||((HAL_GetTick() - tickstart ) > Timeout)) 01868 { 01869 hrtc->State = HAL_RTC_STATE_TIMEOUT; 01870 return HAL_TIMEOUT; 01871 } 01872 } 01873 } 01874 01875 /* Clear the Alarm Flag */ 01876 __HAL_RTC_ALARM_CLEAR_FLAG(hrtc, RTC_FLAG_ALRBF); 01877 01878 /* Change RTC state */ 01879 hrtc->State = HAL_RTC_STATE_READY; 01880 01881 return HAL_OK; 01882 } 01883 01884 /** 01885 * @} 01886 */ 01887 01888 /** 01889 * @} 01890 */ 01891 01892 #endif /* HAL_RTC_MODULE_ENABLED */ 01893 /** 01894 * @} 01895 */ 01896 01897 /** 01898 * @} 01899 */ 01900 01901 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/