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