| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035 |
- /**
- ******************************************************************************
- * @file stm32l0xx_hal_rtc_ex.c
- * @author MCD Application Team
- * @brief Extended RTC HAL module driver.
- * This file provides firmware functions to manage the following
- * functionalities of the Real-Time Clock (RTC) Extended peripheral:
- * + RTC Timestamp functions
- * + RTC Tamper functions
- * + RTC Wakeup functions
- * + Extended Control functions
- * + Extended RTC features functions
- *
- ******************************************************************************
- * @attention
- *
- * Copyright (c) 2016 STMicroelectronics.
- * All rights reserved.
- *
- * This software is licensed under terms that can be found in the LICENSE file
- * in the root directory of this software component.
- * If no LICENSE file comes with this software, it is provided AS-IS.
- *
- ******************************************************************************
- @verbatim
- ==============================================================================
- ##### How to use this driver #####
- ==============================================================================
- [..]
- (+) Enable the RTC domain access.
- (+) Configure the RTC Prescaler (Asynchronous and Synchronous) and RTC hour
- format using the HAL_RTC_Init() function.
- *** RTC Wakeup configuration ***
- ================================
- [..]
- (+) To configure the RTC Wakeup Clock source and Counter use the
- HAL_RTCEx_SetWakeUpTimer() function.
- You can also configure the RTC Wakeup timer in interrupt mode using the
- HAL_RTCEx_SetWakeUpTimer_IT() function.
- (+) To read the RTC Wakeup Counter register, use the HAL_RTCEx_GetWakeUpTimer()
- function.
- *** Timestamp configuration ***
- ===============================
- [..]
- (+) To configure the RTC Timestamp use the HAL_RTCEx_SetTimeStamp() function.
- You can also configure the RTC Timestamp with interrupt mode using the
- HAL_RTCEx_SetTimeStamp_IT() function.
- (+) To read the RTC Timestamp Time and Date register, use the
- HAL_RTCEx_GetTimeStamp() function.
- (+) The Timestamp alternate function is mapped to RTC_AF1 (PC13).
- *** Tamper configuration ***
- ============================
- [..]
- (+) To Enable the RTC Tamper and configure the Tamper filter count, trigger
- Edge or Level according to the Tamper filter value (if equal to 0 Edge
- else Level), sampling frequency, NoErase, MaskFlag, precharge or
- discharge and Pull-UP use the HAL_RTCEx_SetTamper() function.
- You can configure RTC Tamper in interrupt mode using HAL_RTCEx_SetTamper_IT()
- function.
- (+) The default configuration of the Tamper erases the backup registers.
- To avoid this, enable the NoErase field on the RTC_TAMPCR register.
- (+) The TAMPER1 alternate function is mapped to RTC_AF1 (PC13).
- (+) The TAMPER2 alternate function is mapped to RTC_AF2 (PA0).
- (+) The TAMPER3 alternate function is mapped to RTC_AF3 (PE6).
- *** Backup Data Registers configuration ***
- ===========================================
- [..]
- (+) To write to the RTC Backup Data registers, use the HAL_RTCEx_BKUPWrite()
- function.
- (+) To read the RTC Backup Data registers, use the HAL_RTCEx_BKUPRead()
- function.
- *** Smooth Digital Calibration configuration ***
- ================================================
- [..]
- (+) RTC frequency can be digitally calibrated with a resolution of about
- 0.954 ppm with a range from -487.1 ppm to +488.5 ppm.
- The correction of the frequency is performed using a series of small
- adjustments (adding and/or subtracting individual RTCCLK pulses).
- (+) The smooth digital calibration is performed during a cycle of about 2^20
- RTCCLK pulses (or 32 seconds) when the input frequency is 32,768 Hz.
- This cycle is maintained by a 20-bit counter clocked by RTCCLK.
- (+) The smooth calibration register (RTC_CALR) specifies the number of RTCCLK
- clock cycles to be masked during the 32-second cycle.
- (+) The RTC Smooth Digital Calibration value and the corresponding calibration
- cycle period (32s, 16s, or 8s) can be calibrated using the
- HAL_RTCEx_SetSmoothCalib() function.
- *** Outputs configuration ***
- =============================
- [..] The RTC has 2 different outputs:
- (+) RTC_ALARM: this output is used to manage the RTC Alarm A, Alarm B
- and WaKeUp signals.
- To output the selected RTC signal, use the HAL_RTC_Init() function.
- (+) RTC_CALIB: this output is 512Hz signal or 1Hz.
- To enable the RTC_CALIB, use the HAL_RTCEx_SetCalibrationOutPut() function.
- (+) Two pins can be used as RTC_ALARM or RTC_CALIB output, selected through
- bit OUT_RMP of the RTC_OR register:
- - (PC13, PB14) for STM32L05x/6x/7x/8x
- - (PA2, PB14) for STM32L03x/4x
- (+) When the RTC_CALIB or RTC_ALARM output is selected, the RTC_OUT pin is
- automatically configured in output alternate function.
- @endverbatim
- ******************************************************************************
- */
- /* Includes ------------------------------------------------------------------*/
- #include "stm32l0xx_hal.h"
- /** @addtogroup STM32L0xx_HAL_Driver
- * @{
- */
- /** @defgroup RTCEx RTCEx
- * @brief RTC Extended HAL module driver
- * @{
- */
- #ifdef HAL_RTC_MODULE_ENABLED
- /* Private typedef -----------------------------------------------------------*/
- /* Private define ------------------------------------------------------------*/
- /* Private macro -------------------------------------------------------------*/
- /* Private variables ---------------------------------------------------------*/
- /* Private function prototypes -----------------------------------------------*/
- /* Exported functions --------------------------------------------------------*/
- /** @defgroup RTCEx_Exported_Functions RTCEx Exported Functions
- * @{
- */
- /** @defgroup RTCEx_Exported_Functions_Group1 RTC Timestamp and Tamper functions
- * @brief RTC Timestamp and Tamper functions
- *
- @verbatim
- ===============================================================================
- ##### RTC Timestamp and Tamper functions #####
- ===============================================================================
- [..] This section provides functions allowing to configure Timestamp feature
- @endverbatim
- * @{
- */
- /**
- * @brief Sets Timestamp.
- * @note This API must be called before enabling the Timestamp feature.
- * @param hrtc pointer to a RTC_HandleTypeDef structure that contains
- * the configuration information for RTC.
- * @param RTC_TimeStampEdge Specifies the pin edge on which the Timestamp is
- * activated.
- * This parameter can be one of the following values:
- * @arg RTC_TIMESTAMPEDGE_RISING: the Timestamp event occurs on
- * the rising edge of the related pin.
- * @arg RTC_TIMESTAMPEDGE_FALLING: the Timestamp event occurs on
- * the falling edge of the related pin.
- * @param RTC_TimeStampPin Specifies the RTC Timestamp Pin.
- * This parameter can be one of the following values:
- * @arg RTC_TIMESTAMPPIN_DEFAULT: PC13 is selected as RTC Timestamp Pin.
- * @note RTC_TIMESTAMPPIN_DEFAULT corresponds to pin:
- * - PC13 in the case of STM32L05x/6x/7x/8x devices
- * - PA2 in the case of STM32L01x/2x/3x/4x devices
- * @note Although unused, parameter RTC_TimeStampPin has been kept for portability
- * reasons.
- * @retval HAL status
- */
- HAL_StatusTypeDef HAL_RTCEx_SetTimeStamp(RTC_HandleTypeDef *hrtc, uint32_t RTC_TimeStampEdge, uint32_t RTC_TimeStampPin)
- {
- uint32_t tmpreg = 0U;
- /* Check the parameters */
- assert_param(IS_TIMESTAMP_EDGE(RTC_TimeStampEdge));
- assert_param(IS_RTC_TIMESTAMP_PIN(RTC_TimeStampPin));
- /* Prevent compilation warning due to unused argument(s) if assert_param check
- is disabled */
- UNUSED(RTC_TimeStampPin);
- /* Process Locked */
- __HAL_LOCK(hrtc);
- /* Change RTC state to BUSY */
- hrtc->State = HAL_RTC_STATE_BUSY;
- /* Get the RTC_CR register and clear the bits to be configured */
- tmpreg = (uint32_t)(hrtc->Instance->CR & (uint32_t)~(RTC_CR_TSEDGE | RTC_CR_TSE));
- /* Configure the Timestamp TSEDGE bit */
- tmpreg |= RTC_TimeStampEdge;
- /* Disable the write protection for RTC registers */
- __HAL_RTC_WRITEPROTECTION_DISABLE(hrtc);
- /* Copy the desired configuration into the CR register */
- hrtc->Instance->CR = (uint32_t)tmpreg;
- /* Clear RTC Timestamp flag */
- __HAL_RTC_TIMESTAMP_CLEAR_FLAG(hrtc, RTC_FLAG_TSF);
- /* Clear RTC Timestamp overrun Flag */
- __HAL_RTC_TIMESTAMP_CLEAR_FLAG(hrtc, RTC_FLAG_TSOVF);
- /* Enable the Timestamp saving */
- __HAL_RTC_TIMESTAMP_ENABLE(hrtc);
- /* Enable the write protection for RTC registers */
- __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc);
- /* Change RTC state back to READY */
- hrtc->State = HAL_RTC_STATE_READY;
- /* Process Unlocked */
- __HAL_UNLOCK(hrtc);
- return HAL_OK;
- }
- /**
- * @brief Sets Timestamp with Interrupt.
- * @param hrtc pointer to a RTC_HandleTypeDef structure that contains
- * the configuration information for RTC.
- * @note This API must be called before enabling the Timestamp feature.
- * @param RTC_TimeStampEdge Specifies the pin edge on which the Timestamp is
- * activated.
- * This parameter can be one of the following values:
- * @arg RTC_TIMESTAMPEDGE_RISING: the Timestamp event occurs on
- * the rising edge of the related pin.
- * @arg RTC_TIMESTAMPEDGE_FALLING: the Timestamp event occurs on
- * the falling edge of the related pin.
- * @param RTC_TimeStampPin Specifies the RTC Timestamp Pin.
- * This parameter can be one of the following values:
- * @arg RTC_TIMESTAMPPIN_DEFAULT: PC13 is selected as RTC Timestamp Pin.
- * @note RTC_TIMESTAMPPIN_DEFAULT corresponds to pin:
- * - PC13 in the case of STM32L05x/6x/7x/8x devices
- * - PA2 in the case of STM32L01x/2x/3x/4x devices
- * @note Although unused, parameter RTC_TimeStampPin has been kept for portability
- * reasons.
- * @retval HAL status
- */
- HAL_StatusTypeDef HAL_RTCEx_SetTimeStamp_IT(RTC_HandleTypeDef *hrtc, uint32_t RTC_TimeStampEdge, uint32_t RTC_TimeStampPin)
- {
- uint32_t tmpreg = 0U;
- /* Check the parameters */
- assert_param(IS_TIMESTAMP_EDGE(RTC_TimeStampEdge));
- assert_param(IS_RTC_TIMESTAMP_PIN(RTC_TimeStampPin));
- /* Prevent compilation warning due to unused argument(s) if assert_param check
- is disabled */
- UNUSED(RTC_TimeStampPin);
- /* Process Locked */
- __HAL_LOCK(hrtc);
- /* Change RTC state to BUSY */
- hrtc->State = HAL_RTC_STATE_BUSY;
- /* Get the RTC_CR register and clear the bits to be configured */
- tmpreg = (uint32_t)(hrtc->Instance->CR & (uint32_t)~(RTC_CR_TSEDGE | RTC_CR_TSE));
- /* Configure the Timestamp TSEDGE bit */
- tmpreg |= RTC_TimeStampEdge;
- /* Disable the write protection for RTC registers */
- __HAL_RTC_WRITEPROTECTION_DISABLE(hrtc);
- /* Copy the desired configuration into the CR register */
- hrtc->Instance->CR = (uint32_t)tmpreg;
- /* Clear RTC Timestamp flag */
- __HAL_RTC_TIMESTAMP_CLEAR_FLAG(hrtc, RTC_FLAG_TSF);
- /* Clear RTC Timestamp overrun Flag */
- __HAL_RTC_TIMESTAMP_CLEAR_FLAG(hrtc, RTC_FLAG_TSOVF);
- /* Enable the Timestamp saving */
- __HAL_RTC_TIMESTAMP_ENABLE(hrtc);
- /* Enable IT Timestamp */
- __HAL_RTC_TIMESTAMP_ENABLE_IT(hrtc, RTC_IT_TS);
- /* Enable the write protection for RTC registers */
- __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc);
- /* RTC Timestamp Interrupt Configuration: EXTI configuration */
- __HAL_RTC_TAMPER_TIMESTAMP_EXTI_ENABLE_IT();
- __HAL_RTC_TAMPER_TIMESTAMP_EXTI_ENABLE_RISING_EDGE();
- /* Change RTC state back to READY */
- hrtc->State = HAL_RTC_STATE_READY;
- /* Process Unlocked */
- __HAL_UNLOCK(hrtc);
- return HAL_OK;
- }
- /**
- * @brief Deactivates Timestamp.
- * @param hrtc pointer to a RTC_HandleTypeDef structure that contains
- * the configuration information for RTC.
- * @retval HAL status
- */
- HAL_StatusTypeDef HAL_RTCEx_DeactivateTimeStamp(RTC_HandleTypeDef *hrtc)
- {
- uint32_t tmpreg = 0U;
- /* Process Locked */
- __HAL_LOCK(hrtc);
- hrtc->State = HAL_RTC_STATE_BUSY;
- /* Disable the write protection for RTC registers */
- __HAL_RTC_WRITEPROTECTION_DISABLE(hrtc);
- /* In case of interrupt mode is used, the interrupt source must disabled */
- __HAL_RTC_TIMESTAMP_DISABLE_IT(hrtc, RTC_IT_TS);
- /* Get the RTC_CR register and clear the bits to be configured */
- tmpreg = (uint32_t)(hrtc->Instance->CR & (uint32_t)~(RTC_CR_TSEDGE | RTC_CR_TSE));
- /* Configure the Timestamp TSEDGE and Enable bits */
- hrtc->Instance->CR = (uint32_t)tmpreg;
- /* Enable the write protection for RTC registers */
- __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc);
- hrtc->State = HAL_RTC_STATE_READY;
- /* Process Unlocked */
- __HAL_UNLOCK(hrtc);
- return HAL_OK;
- }
- /**
- * @brief Gets the RTC Timestamp value.
- * @param hrtc pointer to a RTC_HandleTypeDef structure that contains
- * the configuration information for RTC.
- * @param sTimeStamp Pointer to Time structure
- * @param sTimeStampDate Pointer to Date structure
- * @param Format specifies the format of the entered parameters.
- * This parameter can be one of the following values:
- * @arg RTC_FORMAT_BIN: Binary data format
- * @arg RTC_FORMAT_BCD: BCD data format
- * @retval HAL status
- */
- HAL_StatusTypeDef HAL_RTCEx_GetTimeStamp(RTC_HandleTypeDef *hrtc, RTC_TimeTypeDef *sTimeStamp, RTC_DateTypeDef *sTimeStampDate, uint32_t Format)
- {
- uint32_t tmptime = 0U;
- uint32_t tmpdate = 0U;
- /* Check the parameters */
- assert_param(IS_RTC_FORMAT(Format));
- /* Get the Timestamp time and date registers values */
- tmptime = (uint32_t)(hrtc->Instance->TSTR & RTC_TR_RESERVED_MASK);
- tmpdate = (uint32_t)(hrtc->Instance->TSDR & RTC_DR_RESERVED_MASK);
- /* Fill the Time structure fields with the read parameters */
- sTimeStamp->Hours = (uint8_t)((tmptime & (RTC_TSTR_HT | RTC_TSTR_HU)) >> RTC_TSTR_HU_Pos);
- sTimeStamp->Minutes = (uint8_t)((tmptime & (RTC_TSTR_MNT | RTC_TSTR_MNU)) >> RTC_TSTR_MNU_Pos);
- sTimeStamp->Seconds = (uint8_t)((tmptime & (RTC_TSTR_ST | RTC_TSTR_SU)) >> RTC_TSTR_SU_Pos);
- sTimeStamp->TimeFormat = (uint8_t)((tmptime & (RTC_TSTR_PM)) >> RTC_TSTR_PM_Pos);
- sTimeStamp->SubSeconds = (uint32_t) hrtc->Instance->TSSSR;
- /* Fill the Date structure fields with the read parameters */
- sTimeStampDate->Year = 0U;
- sTimeStampDate->Month = (uint8_t)((tmpdate & (RTC_TSDR_MT | RTC_TSDR_MU)) >> RTC_TSDR_MU_Pos);
- sTimeStampDate->Date = (uint8_t)((tmpdate & (RTC_TSDR_DT | RTC_TSDR_DU)) >> RTC_TSDR_DU_Pos);
- sTimeStampDate->WeekDay = (uint8_t)((tmpdate & (RTC_TSDR_WDU)) >> RTC_TSDR_WDU_Pos);
- /* Check the input parameters format */
- if (Format == RTC_FORMAT_BIN)
- {
- /* Convert the Timestamp structure parameters to Binary format */
- sTimeStamp->Hours = (uint8_t)RTC_Bcd2ToByte(sTimeStamp->Hours);
- sTimeStamp->Minutes = (uint8_t)RTC_Bcd2ToByte(sTimeStamp->Minutes);
- sTimeStamp->Seconds = (uint8_t)RTC_Bcd2ToByte(sTimeStamp->Seconds);
- /* Convert the DateTimeStamp structure parameters to Binary format */
- sTimeStampDate->Month = (uint8_t)RTC_Bcd2ToByte(sTimeStampDate->Month);
- sTimeStampDate->Date = (uint8_t)RTC_Bcd2ToByte(sTimeStampDate->Date);
- sTimeStampDate->WeekDay = (uint8_t)RTC_Bcd2ToByte(sTimeStampDate->WeekDay);
- }
- /* Clear the Timestamp Flag */
- __HAL_RTC_TIMESTAMP_CLEAR_FLAG(hrtc, RTC_FLAG_TSF);
- return HAL_OK;
- }
- /**
- * @brief Sets Tamper.
- * @note By calling this API the tamper global interrupt will be disabled and
- * the selected tamper's interrupt as well.
- * @param hrtc pointer to a RTC_HandleTypeDef structure that contains
- * the configuration information for RTC.
- * @param sTamper Pointer to Tamper Structure.
- * @retval HAL status
- */
- HAL_StatusTypeDef HAL_RTCEx_SetTamper(RTC_HandleTypeDef *hrtc, RTC_TamperTypeDef *sTamper)
- {
- uint32_t tmpreg = 0U;
- /* Check the parameters */
- assert_param(IS_RTC_TAMPER(sTamper->Tamper));
- assert_param(IS_RTC_TAMPER_TRIGGER(sTamper->Trigger));
- assert_param(IS_RTC_TAMPER_ERASE_MODE(sTamper->NoErase));
- assert_param(IS_RTC_TAMPER_MASKFLAG_STATE(sTamper->MaskFlag));
- assert_param(IS_RTC_TAMPER_FILTER(sTamper->Filter));
- assert_param(IS_RTC_TAMPER_FILTER_CONFIG_CORRECT(sTamper->Filter, sTamper->Trigger));
- assert_param(IS_RTC_TAMPER_SAMPLING_FREQ(sTamper->SamplingFrequency));
- assert_param(IS_RTC_TAMPER_PRECHARGE_DURATION(sTamper->PrechargeDuration));
- assert_param(IS_RTC_TAMPER_PULLUP_STATE(sTamper->TamperPullUp));
- assert_param(IS_RTC_TAMPER_TIMESTAMPONTAMPER_DETECTION(sTamper->TimeStampOnTamperDetection));
- /* Process Locked */
- __HAL_LOCK(hrtc);
- hrtc->State = HAL_RTC_STATE_BUSY;
- /* Copy control register into temporary variable */
- tmpreg = hrtc->Instance->TAMPCR;
- /* Enable selected tamper */
- tmpreg |= (sTamper->Tamper);
- /* Configure the tamper trigger bit (this bit is just on the right of the
- tamper enable bit, hence the one-time right shift before updating it) */
- if (sTamper->Trigger == RTC_TAMPERTRIGGER_FALLINGEDGE)
- {
- /* Set the tamper trigger bit (case of falling edge or high level) */
- tmpreg |= (uint32_t)(sTamper->Tamper << 1U);
- }
- else
- {
- /* Clear the tamper trigger bit (case of rising edge or low level) */
- tmpreg &= (uint32_t)~(sTamper->Tamper << 1U);
- }
- /* Configure the backup registers erasure enabling bits */
- if (sTamper->NoErase != RTC_TAMPER_ERASE_BACKUP_ENABLE)
- {
- #if defined(RTC_TAMPER1_SUPPORT)
- if ((sTamper->Tamper & RTC_TAMPER_1) != 0U)
- {
- tmpreg |= (uint32_t)(RTC_TAMPCR_TAMP1NOERASE);
- }
- #endif /* RTC_TAMPER1_SUPPORT */
- if ((sTamper->Tamper & RTC_TAMPER_2) != 0U)
- {
- tmpreg |= (uint32_t)(RTC_TAMPCR_TAMP2NOERASE);
- }
- #if defined(RTC_TAMPER3_SUPPORT)
- if ((sTamper->Tamper & RTC_TAMPER_3) != 0U)
- {
- tmpreg |= (uint32_t)(RTC_TAMPCR_TAMP3NOERASE);
- }
- #endif /* RTC_TAMPER3_SUPPORT */
- }
- else
- {
- #if defined(RTC_TAMPER1_SUPPORT)
- if ((sTamper->Tamper & RTC_TAMPER_1) != 0U)
- {
- tmpreg &= (uint32_t)~(RTC_TAMPCR_TAMP1NOERASE);
- }
- #endif /* RTC_TAMPER1_SUPPORT */
- if ((sTamper->Tamper & RTC_TAMPER_2) != 0U)
- {
- tmpreg &= (uint32_t)~(RTC_TAMPCR_TAMP2NOERASE);
- }
- #if defined(RTC_TAMPER3_SUPPORT)
- if ((sTamper->Tamper & RTC_TAMPER_3) != 0U)
- {
- tmpreg &= (uint32_t)~(RTC_TAMPCR_TAMP3NOERASE);
- }
- #endif /* RTC_TAMPER3_SUPPORT */
- }
- /* Configure the tamper flags masking bits */
- if (sTamper->MaskFlag != RTC_TAMPERMASK_FLAG_DISABLE)
- {
- #if defined(RTC_TAMPER1_SUPPORT)
- if ((sTamper->Tamper & RTC_TAMPER_1) != 0U)
- {
- tmpreg |= (uint32_t)(RTC_TAMPCR_TAMP1MF);
- }
- #endif /* RTC_TAMPER1_SUPPORT */
- if ((sTamper->Tamper & RTC_TAMPER_2) != 0U)
- {
- tmpreg |= (uint32_t)(RTC_TAMPCR_TAMP2MF);
- }
- #if defined(RTC_TAMPER3_SUPPORT)
- if ((sTamper->Tamper & RTC_TAMPER_3) != 0U)
- {
- tmpreg |= (uint32_t)(RTC_TAMPCR_TAMP3MF);
- }
- #endif /* RTC_TAMPER3_SUPPORT */
- }
- else
- {
- #if defined(RTC_TAMPER1_SUPPORT)
- if ((sTamper->Tamper & RTC_TAMPER_1) != 0U)
- {
- tmpreg &= (uint32_t)~(RTC_TAMPCR_TAMP1MF);
- }
- #endif /* RTC_TAMPER1_SUPPORT */
- if ((sTamper->Tamper & RTC_TAMPER_2) != 0U)
- {
- tmpreg &= (uint32_t)~(RTC_TAMPCR_TAMP2MF);
- }
- #if defined(RTC_TAMPER3_SUPPORT)
- if ((sTamper->Tamper & RTC_TAMPER_3) != 0U)
- {
- tmpreg &= (uint32_t)~(RTC_TAMPCR_TAMP3MF);
- }
- #endif /* RTC_TAMPER3_SUPPORT */
- }
- /* Clear remaining fields before setting them */
- tmpreg &= ~(RTC_TAMPERFILTER_MASK | \
- RTC_TAMPERSAMPLINGFREQ_RTCCLK_MASK | \
- RTC_TAMPERPRECHARGEDURATION_MASK | \
- RTC_TAMPER_PULLUP_MASK | \
- RTC_TIMESTAMPONTAMPERDETECTION_MASK);
- /* Set remaining parameters of desired configuration into temporary variable */
- tmpreg |= ((uint32_t)sTamper->Filter | \
- (uint32_t)sTamper->SamplingFrequency | \
- (uint32_t)sTamper->PrechargeDuration | \
- (uint32_t)sTamper->TamperPullUp | \
- (uint32_t)sTamper->TimeStampOnTamperDetection);
- /* Disable interrupt on selected tamper in case it is enabled */
- #if defined(RTC_TAMPER1_SUPPORT)
- if ((sTamper->Tamper & RTC_TAMPER_1) != 0U)
- {
- tmpreg &= (uint32_t)~RTC_IT_TAMP1;
- }
- #endif /* RTC_TAMPER1_SUPPORT */
- if ((sTamper->Tamper & RTC_TAMPER_2) != 0U)
- {
- tmpreg &= (uint32_t)~RTC_IT_TAMP2;
- }
- #if defined(RTC_TAMPER3_SUPPORT)
- if ((sTamper->Tamper & RTC_TAMPER_3) != 0U)
- {
- tmpreg &= (uint32_t)~RTC_IT_TAMP3;
- }
- #endif /* RTC_TAMPER3_SUPPORT */
- /* Disable tamper global interrupt in case it is enabled */
- tmpreg &= (uint32_t)~RTC_TAMPCR_TAMPIE;
- /* Copy desired configuration into configuration register */
- hrtc->Instance->TAMPCR = tmpreg;
- hrtc->State = HAL_RTC_STATE_READY;
- /* Process Unlocked */
- __HAL_UNLOCK(hrtc);
- return HAL_OK;
- }
- /**
- * @brief Sets Tamper with interrupt.
- * @note By setting the tamper global interrupt bit, interrupts will be
- * enabled for all tampers.
- * @param hrtc pointer to a RTC_HandleTypeDef structure that contains
- * the configuration information for RTC.
- * @param sTamper Pointer to RTC Tamper.
- * @retval HAL status
- */
- HAL_StatusTypeDef HAL_RTCEx_SetTamper_IT(RTC_HandleTypeDef *hrtc, RTC_TamperTypeDef *sTamper)
- {
- uint32_t tmpreg = 0U;
- /* Check the parameters */
- assert_param(IS_RTC_TAMPER(sTamper->Tamper));
- assert_param(IS_RTC_TAMPER_INTERRUPT(sTamper->Interrupt));
- assert_param(IS_RTC_TAMPER_TRIGGER(sTamper->Trigger));
- assert_param(IS_RTC_TAMPER_ERASE_MODE(sTamper->NoErase));
- assert_param(IS_RTC_TAMPER_MASKFLAG_STATE(sTamper->MaskFlag));
- assert_param(IS_RTC_TAMPER_FILTER(sTamper->Filter));
- assert_param(IS_RTC_TAMPER_FILTER_CONFIG_CORRECT(sTamper->Filter, sTamper->Trigger));
- assert_param(IS_RTC_TAMPER_SAMPLING_FREQ(sTamper->SamplingFrequency));
- assert_param(IS_RTC_TAMPER_PRECHARGE_DURATION(sTamper->PrechargeDuration));
- assert_param(IS_RTC_TAMPER_PULLUP_STATE(sTamper->TamperPullUp));
- assert_param(IS_RTC_TAMPER_TIMESTAMPONTAMPER_DETECTION(sTamper->TimeStampOnTamperDetection));
- /* Process Locked */
- __HAL_LOCK(hrtc);
- hrtc->State = HAL_RTC_STATE_BUSY;
- /* Copy control register into temporary variable */
- tmpreg = hrtc->Instance->TAMPCR;
- /* Enable selected tamper */
- tmpreg |= (sTamper->Tamper);
- /* Configure the tamper trigger bit (this bit is just on the right of the
- tamper enable bit, hence the one-time right shift before updating it) */
- if (sTamper->Trigger == RTC_TAMPERTRIGGER_FALLINGEDGE)
- {
- /* Set the tamper trigger bit (case of falling edge or high level) */
- tmpreg |= (uint32_t)(sTamper->Tamper << 1U);
- }
- else
- {
- /* Clear the tamper trigger bit (case of rising edge or low level) */
- tmpreg &= (uint32_t)~(sTamper->Tamper << 1U);
- }
- /* Configure the backup registers erasure enabling bits */
- if (sTamper->NoErase != RTC_TAMPER_ERASE_BACKUP_ENABLE)
- {
- #if defined(RTC_TAMPER1_SUPPORT)
- if ((sTamper->Tamper & RTC_TAMPER_1) != 0U)
- {
- tmpreg |= (uint32_t)(RTC_TAMPCR_TAMP1NOERASE);
- }
- #endif /* RTC_TAMPER1_SUPPORT */
- if ((sTamper->Tamper & RTC_TAMPER_2) != 0U)
- {
- tmpreg |= (uint32_t)(RTC_TAMPCR_TAMP2NOERASE);
- }
- #if defined(RTC_TAMPER3_SUPPORT)
- if ((sTamper->Tamper & RTC_TAMPER_3) != 0U)
- {
- tmpreg |= (uint32_t)(RTC_TAMPCR_TAMP3NOERASE);
- }
- #endif /* RTC_TAMPER3_SUPPORT */
- }
- else
- {
- #if defined(RTC_TAMPER1_SUPPORT)
- if ((sTamper->Tamper & RTC_TAMPER_1) != 0U)
- {
- tmpreg &= (uint32_t)~(RTC_TAMPCR_TAMP1NOERASE);
- }
- #endif /* RTC_TAMPER1_SUPPORT */
- if ((sTamper->Tamper & RTC_TAMPER_2) != 0U)
- {
- tmpreg &= (uint32_t)~(RTC_TAMPCR_TAMP2NOERASE);
- }
- #if defined(RTC_TAMPER3_SUPPORT)
- if ((sTamper->Tamper & RTC_TAMPER_3) != 0U)
- {
- tmpreg &= (uint32_t)~(RTC_TAMPCR_TAMP3NOERASE);
- }
- #endif /* RTC_TAMPER3_SUPPORT */
- }
- /* Configure the tamper flags masking bits */
- if (sTamper->MaskFlag != RTC_TAMPERMASK_FLAG_DISABLE)
- {
- #if defined(RTC_TAMPER1_SUPPORT)
- if ((sTamper->Tamper & RTC_TAMPER_1) != 0U)
- {
- tmpreg |= (uint32_t)(RTC_TAMPCR_TAMP1MF);
- }
- #endif /* RTC_TAMPER1_SUPPORT */
- if ((sTamper->Tamper & RTC_TAMPER_2) != 0U)
- {
- tmpreg |= (uint32_t)(RTC_TAMPCR_TAMP2MF);
- }
- #if defined(RTC_TAMPER3_SUPPORT)
- if ((sTamper->Tamper & RTC_TAMPER_3) != 0U)
- {
- tmpreg |= (uint32_t)(RTC_TAMPCR_TAMP3MF);
- }
- #endif /* RTC_TAMPER3_SUPPORT */
- }
- else
- {
- #if defined(RTC_TAMPER1_SUPPORT)
- if ((sTamper->Tamper & RTC_TAMPER_1) != 0U)
- {
- tmpreg &= (uint32_t)~(RTC_TAMPCR_TAMP1MF);
- }
- #endif /* RTC_TAMPER1_SUPPORT */
- if ((sTamper->Tamper & RTC_TAMPER_2) != 0U)
- {
- tmpreg &= (uint32_t)~(RTC_TAMPCR_TAMP2MF);
- }
- #if defined(RTC_TAMPER3_SUPPORT)
- if ((sTamper->Tamper & RTC_TAMPER_3) != 0U)
- {
- tmpreg &= (uint32_t)~(RTC_TAMPCR_TAMP3MF);
- }
- #endif /* RTC_TAMPER3_SUPPORT */
- }
- /* Clear remaining fields before setting them */
- tmpreg &= ~(RTC_TAMPERFILTER_MASK | \
- RTC_TAMPERSAMPLINGFREQ_RTCCLK_MASK | \
- RTC_TAMPERPRECHARGEDURATION_MASK | \
- RTC_TAMPER_PULLUP_MASK | \
- RTC_TIMESTAMPONTAMPERDETECTION_MASK);
- /* Set remaining parameters of desired configuration into temporary variable */
- tmpreg |= ((uint32_t)sTamper->Filter | \
- (uint32_t)sTamper->SamplingFrequency | \
- (uint32_t)sTamper->PrechargeDuration | \
- (uint32_t)sTamper->TamperPullUp | \
- (uint32_t)sTamper->TimeStampOnTamperDetection);
- /* Enable interrupt on selected tamper */
- tmpreg |= (uint32_t)sTamper->Interrupt;
- /* Copy desired configuration into configuration register */
- hrtc->Instance->TAMPCR = tmpreg;
- /* RTC Tamper Interrupt Configuration: EXTI configuration */
- __HAL_RTC_TAMPER_TIMESTAMP_EXTI_ENABLE_IT();
- __HAL_RTC_TAMPER_TIMESTAMP_EXTI_ENABLE_RISING_EDGE();
- hrtc->State = HAL_RTC_STATE_READY;
- /* Process Unlocked */
- __HAL_UNLOCK(hrtc);
- return HAL_OK;
- }
- /**
- * @brief Deactivates Tamper.
- * @note By calling this API the tamper global interrupt will be disabled.
- * @param hrtc pointer to a RTC_HandleTypeDef structure that contains
- * the configuration information for RTC.
- * @param Tamper Selected tamper pin.
- * This parameter can be any combination of the following values:
- * @arg RTC_TAMPER_1: Tamper 1
- * @arg RTC_TAMPER_2: Tamper 2
- * @arg RTC_TAMPER_3: Tamper 3
- * @note RTC_TAMPER_1 is not applicable to all devices.
- * @note RTC_TAMPER_3 is not applicable to all devices.
- * @retval HAL status
- */
- HAL_StatusTypeDef HAL_RTCEx_DeactivateTamper(RTC_HandleTypeDef *hrtc, uint32_t Tamper)
- {
- assert_param(IS_RTC_TAMPER(Tamper));
- /* Process Locked */
- __HAL_LOCK(hrtc);
- hrtc->State = HAL_RTC_STATE_BUSY;
- /* Disable the selected Tamper pin */
- hrtc->Instance->TAMPCR &= (uint32_t)~Tamper;
- #if defined(RTC_TAMPER1_SUPPORT)
- if ((Tamper & RTC_TAMPER_1) != 0U)
- {
- /* Disable the Tamper 1 interrupt */
- hrtc->Instance->TAMPCR &= (uint32_t)~(RTC_IT_TAMP | RTC_IT_TAMP1);
- }
- #endif /* RTC_TAMPER1_SUPPORT */
- if ((Tamper & RTC_TAMPER_2) != 0U)
- {
- /* Disable the Tamper 2 interrupt */
- hrtc->Instance->TAMPCR &= (uint32_t)~(RTC_IT_TAMP | RTC_IT_TAMP2);
- }
- #if defined(RTC_TAMPER3_SUPPORT)
- if ((Tamper & RTC_TAMPER_3) != 0U)
- {
- /* Disable the Tamper 3 interrupt */
- hrtc->Instance->TAMPCR &= (uint32_t)~(RTC_IT_TAMP | RTC_IT_TAMP3);
- }
- #endif /* RTC_TAMPER3_SUPPORT */
- hrtc->State = HAL_RTC_STATE_READY;
- /* Process Unlocked */
- __HAL_UNLOCK(hrtc);
- return HAL_OK;
- }
- /**
- * @brief Handles Timestamp and Tamper interrupt request.
- * @param hrtc pointer to a RTC_HandleTypeDef structure that contains
- * the configuration information for RTC.
- * @retval None
- */
- void HAL_RTCEx_TamperTimeStampIRQHandler(RTC_HandleTypeDef *hrtc)
- {
- /* Clear the EXTI's Flag for RTC Timestamp and Tamper */
- __HAL_RTC_TAMPER_TIMESTAMP_EXTI_CLEAR_FLAG();
- /* Get the Timestamp interrupt source enable status */
- if (__HAL_RTC_TIMESTAMP_GET_IT_SOURCE(hrtc, RTC_IT_TS) != 0U)
- {
- /* Get the pending status of the Timestamp Interrupt */
- if (__HAL_RTC_TIMESTAMP_GET_FLAG(hrtc, RTC_FLAG_TSF) != 0U)
- {
- /* Timestamp callback */
- #if (USE_HAL_RTC_REGISTER_CALLBACKS == 1)
- hrtc->TimeStampEventCallback(hrtc);
- #else
- HAL_RTCEx_TimeStampEventCallback(hrtc);
- #endif /* USE_HAL_RTC_REGISTER_CALLBACKS */
- /* Clear the Timestamp interrupt pending bit after returning from callback
- as RTC_TSTR and RTC_TSDR registers are cleared when TSF bit is reset */
- __HAL_RTC_TIMESTAMP_CLEAR_FLAG(hrtc, RTC_FLAG_TSF);
- }
- }
- #if defined(RTC_TAMPER1_SUPPORT)
- /* Get the Tamper 1 interrupt source enable status */
- if (__HAL_RTC_TAMPER_GET_IT_SOURCE(hrtc, RTC_IT_TAMP | RTC_IT_TAMP1) != 0U)
- {
- /* Get the pending status of the Tamper 1 Interrupt */
- if (__HAL_RTC_TAMPER_GET_FLAG(hrtc, RTC_FLAG_TAMP1F) != 0U)
- {
- /* Clear the Tamper interrupt pending bit */
- __HAL_RTC_TAMPER_CLEAR_FLAG(hrtc, RTC_FLAG_TAMP1F);
- /* Tamper callback */
- #if (USE_HAL_RTC_REGISTER_CALLBACKS == 1)
- hrtc->Tamper1EventCallback(hrtc);
- #else
- HAL_RTCEx_Tamper1EventCallback(hrtc);
- #endif /* USE_HAL_RTC_REGISTER_CALLBACKS */
- }
- }
- #endif /* RTC_TAMPER1_SUPPORT */
- /* Get the Tamper 2 interrupt source enable status */
- if (__HAL_RTC_TAMPER_GET_IT_SOURCE(hrtc, RTC_IT_TAMP | RTC_IT_TAMP2) != 0U)
- {
- /* Get the pending status of the Tamper 2 Interrupt */
- if (__HAL_RTC_TAMPER_GET_FLAG(hrtc, RTC_FLAG_TAMP2F) != 0U)
- {
- /* Clear the Tamper interrupt pending bit */
- __HAL_RTC_TAMPER_CLEAR_FLAG(hrtc, RTC_FLAG_TAMP2F);
- /* Tamper callback */
- #if (USE_HAL_RTC_REGISTER_CALLBACKS == 1)
- hrtc->Tamper2EventCallback(hrtc);
- #else
- HAL_RTCEx_Tamper2EventCallback(hrtc);
- #endif /* USE_HAL_RTC_REGISTER_CALLBACKS */
- }
- }
- #if defined(RTC_TAMPER3_SUPPORT)
- /* Get the Tamper 3 interrupt source enable status */
- if (__HAL_RTC_TAMPER_GET_IT_SOURCE(hrtc, RTC_IT_TAMP | RTC_IT_TAMP3) != 0U)
- {
- /* Get the pending status of the Tamper 3 Interrupt */
- if (__HAL_RTC_TAMPER_GET_FLAG(hrtc, RTC_FLAG_TAMP3F) != 0U)
- {
- /* Clear the Tamper interrupt pending bit */
- __HAL_RTC_TAMPER_CLEAR_FLAG(hrtc, RTC_FLAG_TAMP3F);
- /* Tamper callback */
- #if (USE_HAL_RTC_REGISTER_CALLBACKS == 1)
- hrtc->Tamper3EventCallback(hrtc);
- #else
- HAL_RTCEx_Tamper3EventCallback(hrtc);
- #endif /* USE_HAL_RTC_REGISTER_CALLBACKS */
- }
- }
- #endif /* RTC_TAMPER3_SUPPORT */
- /* Change RTC state */
- hrtc->State = HAL_RTC_STATE_READY;
- }
- /**
- * @brief Timestamp callback.
- * @param hrtc pointer to a RTC_HandleTypeDef structure that contains
- * the configuration information for RTC.
- * @retval None
- */
- __weak void HAL_RTCEx_TimeStampEventCallback(RTC_HandleTypeDef *hrtc)
- {
- /* Prevent unused argument(s) compilation warning */
- UNUSED(hrtc);
- /* NOTE: This function should not be modified, when the callback is needed,
- the HAL_RTCEx_TimeStampEventCallback could be implemented in the user file
- */
- }
- #if defined(RTC_TAMPER1_SUPPORT)
- /**
- * @brief Tamper 1 callback.
- * @param hrtc pointer to a RTC_HandleTypeDef structure that contains
- * the configuration information for RTC.
- * @retval None
- */
- __weak void HAL_RTCEx_Tamper1EventCallback(RTC_HandleTypeDef *hrtc)
- {
- /* Prevent unused argument(s) compilation warning */
- UNUSED(hrtc);
- /* NOTE: This function should not be modified, when the callback is needed,
- the HAL_RTCEx_Tamper1EventCallback could be implemented in the user file
- */
- }
- #endif /* RTC_TAMPER1_SUPPORT */
- /**
- * @brief Tamper 2 callback.
- * @param hrtc pointer to a RTC_HandleTypeDef structure that contains
- * the configuration information for RTC.
- * @retval None
- */
- __weak void HAL_RTCEx_Tamper2EventCallback(RTC_HandleTypeDef *hrtc)
- {
- /* Prevent unused argument(s) compilation warning */
- UNUSED(hrtc);
- /* NOTE: This function should not be modified, when the callback is needed,
- the HAL_RTCEx_Tamper2EventCallback could be implemented in the user file
- */
- }
- #if defined(RTC_TAMPER3_SUPPORT)
- /**
- * @brief Tamper 3 callback.
- * @param hrtc pointer to a RTC_HandleTypeDef structure that contains
- * the configuration information for RTC.
- * @retval None
- */
- __weak void HAL_RTCEx_Tamper3EventCallback(RTC_HandleTypeDef *hrtc)
- {
- /* Prevent unused argument(s) compilation warning */
- UNUSED(hrtc);
- /* NOTE: This function should not be modified, when the callback is needed,
- the HAL_RTCEx_Tamper3EventCallback could be implemented in the user file
- */
- }
- #endif /* RTC_TAMPER3_SUPPORT */
- /**
- * @brief Handles Timestamp polling request.
- * @param hrtc pointer to a RTC_HandleTypeDef structure that contains
- * the configuration information for RTC.
- * @param Timeout Timeout duration
- * @retval HAL status
- */
- HAL_StatusTypeDef HAL_RTCEx_PollForTimeStampEvent(RTC_HandleTypeDef *hrtc, uint32_t Timeout)
- {
- uint32_t tickstart = 0U;
- /* Get tick */
- tickstart = HAL_GetTick();
- while (__HAL_RTC_TIMESTAMP_GET_FLAG(hrtc, RTC_FLAG_TSF) == 0U)
- {
- if (Timeout != HAL_MAX_DELAY)
- {
- if ((Timeout == 0U) || ((HAL_GetTick() - tickstart) > Timeout))
- {
- hrtc->State = HAL_RTC_STATE_TIMEOUT;
- return HAL_TIMEOUT;
- }
- }
- if (__HAL_RTC_TIMESTAMP_GET_FLAG(hrtc, RTC_FLAG_TSOVF) != 0U)
- {
- /* Clear the Timestamp Overrun Flag */
- __HAL_RTC_TIMESTAMP_CLEAR_FLAG(hrtc, RTC_FLAG_TSOVF);
- /* Change Timestamp state */
- hrtc->State = HAL_RTC_STATE_ERROR;
- return HAL_ERROR;
- }
- }
- /* Change RTC state */
- hrtc->State = HAL_RTC_STATE_READY;
- return HAL_OK;
- }
- #if defined(RTC_TAMPER1_SUPPORT)
- /**
- * @brief Handles Tamper 1 Polling.
- * @param hrtc pointer to a RTC_HandleTypeDef structure that contains
- * the configuration information for RTC.
- * @param Timeout Timeout duration
- * @retval HAL status
- */
- HAL_StatusTypeDef HAL_RTCEx_PollForTamper1Event(RTC_HandleTypeDef *hrtc, uint32_t Timeout)
- {
- uint32_t tickstart = 0U;
- /* Get tick */
- tickstart = HAL_GetTick();
- /* Get the status of the Interrupt */
- while (__HAL_RTC_TAMPER_GET_FLAG(hrtc, RTC_FLAG_TAMP1F) == 0U)
- {
- if (Timeout != HAL_MAX_DELAY)
- {
- if ((Timeout == 0U) || ((HAL_GetTick() - tickstart) > Timeout))
- {
- hrtc->State = HAL_RTC_STATE_TIMEOUT;
- return HAL_TIMEOUT;
- }
- }
- }
- /* Clear the Tamper Flag */
- __HAL_RTC_TAMPER_CLEAR_FLAG(hrtc, RTC_FLAG_TAMP1F);
- /* Change RTC state */
- hrtc->State = HAL_RTC_STATE_READY;
- return HAL_OK;
- }
- #endif /* RTC_TAMPER1_SUPPORT */
- /**
- * @brief Handles Tamper 2 Polling.
- * @param hrtc pointer to a RTC_HandleTypeDef structure that contains
- * the configuration information for RTC.
- * @param Timeout Timeout duration
- * @retval HAL status
- */
- HAL_StatusTypeDef HAL_RTCEx_PollForTamper2Event(RTC_HandleTypeDef *hrtc, uint32_t Timeout)
- {
- uint32_t tickstart = 0U;
- /* Get tick */
- tickstart = HAL_GetTick();
- /* Get the status of the Interrupt */
- while (__HAL_RTC_TAMPER_GET_FLAG(hrtc, RTC_FLAG_TAMP2F) == 0U)
- {
- if (Timeout != HAL_MAX_DELAY)
- {
- if ((Timeout == 0U) || ((HAL_GetTick() - tickstart) > Timeout))
- {
- hrtc->State = HAL_RTC_STATE_TIMEOUT;
- return HAL_TIMEOUT;
- }
- }
- }
- /* Clear the Tamper Flag */
- __HAL_RTC_TAMPER_CLEAR_FLAG(hrtc, RTC_FLAG_TAMP2F);
- /* Change RTC state */
- hrtc->State = HAL_RTC_STATE_READY;
- return HAL_OK;
- }
- #if defined(RTC_TAMPER3_SUPPORT)
- /**
- * @brief Handles Tamper 3 Polling.
- * @param hrtc pointer to a RTC_HandleTypeDef structure that contains
- * the configuration information for RTC.
- * @param Timeout Timeout duration
- * @retval HAL status
- */
- HAL_StatusTypeDef HAL_RTCEx_PollForTamper3Event(RTC_HandleTypeDef *hrtc, uint32_t Timeout)
- {
- uint32_t tickstart = HAL_GetTick();
- /* Get the status of the Interrupt */
- while (__HAL_RTC_TAMPER_GET_FLAG(hrtc, RTC_FLAG_TAMP3F) == 0U)
- {
- if (Timeout != HAL_MAX_DELAY)
- {
- if ((Timeout == 0U) || ((HAL_GetTick() - tickstart) > Timeout))
- {
- hrtc->State = HAL_RTC_STATE_TIMEOUT;
- return HAL_TIMEOUT;
- }
- }
- }
- /* Clear the Tamper Flag */
- __HAL_RTC_TAMPER_CLEAR_FLAG(hrtc, RTC_FLAG_TAMP3F);
- /* Change RTC state */
- hrtc->State = HAL_RTC_STATE_READY;
- return HAL_OK;
- }
- #endif /* RTC_TAMPER3_SUPPORT */
- /**
- * @}
- */
- /** @defgroup RTCEx_Exported_Functions_Group2 RTC Wakeup functions
- * @brief RTC Wakeup functions
- *
- @verbatim
- ===============================================================================
- ##### RTC Wakeup functions #####
- ===============================================================================
- [..] This section provides functions allowing to configure Wakeup feature
- @endverbatim
- * @{
- */
- /**
- * @brief Sets wakeup timer.
- * @param hrtc pointer to a RTC_HandleTypeDef structure that contains
- * the configuration information for RTC.
- * @param WakeUpCounter Wakeup counter
- * @param WakeUpClock Wakeup clock
- * @retval HAL status
- */
- HAL_StatusTypeDef HAL_RTCEx_SetWakeUpTimer(RTC_HandleTypeDef *hrtc, uint32_t WakeUpCounter, uint32_t WakeUpClock)
- {
- uint32_t tickstart = 0U;
- /* Check the parameters */
- assert_param(IS_RTC_WAKEUP_CLOCK(WakeUpClock));
- assert_param(IS_RTC_WAKEUP_COUNTER(WakeUpCounter));
- /* Process Locked */
- __HAL_LOCK(hrtc);
- hrtc->State = HAL_RTC_STATE_BUSY;
- /* Disable the write protection for RTC registers */
- __HAL_RTC_WRITEPROTECTION_DISABLE(hrtc);
- /* Check RTC WUTWF flag is reset only when wakeup timer enabled*/
- if ((hrtc->Instance->CR & RTC_CR_WUTE) != 0U)
- {
- tickstart = HAL_GetTick();
- /* Wait till RTC WUTWF flag is reset and if timeout is reached exit */
- while (__HAL_RTC_WAKEUPTIMER_GET_FLAG(hrtc, RTC_FLAG_WUTWF) != 0U)
- {
- if ((HAL_GetTick() - tickstart) > RTC_TIMEOUT_VALUE)
- {
- /* Enable the write protection for RTC registers */
- __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc);
- hrtc->State = HAL_RTC_STATE_TIMEOUT;
- /* Process Unlocked */
- __HAL_UNLOCK(hrtc);
- return HAL_TIMEOUT;
- }
- }
- }
- /* Disable the Wakeup timer */
- __HAL_RTC_WAKEUPTIMER_DISABLE(hrtc);
- /* Clear the Wakeup flag */
- __HAL_RTC_WAKEUPTIMER_CLEAR_FLAG(hrtc, RTC_FLAG_WUTF);
- /* Get tick */
- tickstart = HAL_GetTick();
- /* Wait till RTC WUTWF flag is set and if timeout is reached exit */
- while (__HAL_RTC_WAKEUPTIMER_GET_FLAG(hrtc, RTC_FLAG_WUTWF) == 0U)
- {
- if ((HAL_GetTick() - tickstart) > RTC_TIMEOUT_VALUE)
- {
- /* Enable the write protection for RTC registers */
- __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc);
- hrtc->State = HAL_RTC_STATE_TIMEOUT;
- /* Process Unlocked */
- __HAL_UNLOCK(hrtc);
- return HAL_TIMEOUT;
- }
- }
- /* Clear the Wakeup Timer clock source bits in CR register */
- hrtc->Instance->CR &= (uint32_t)~RTC_CR_WUCKSEL;
- /* Configure the clock source */
- hrtc->Instance->CR |= (uint32_t)WakeUpClock;
- /* Configure the Wakeup Timer counter */
- hrtc->Instance->WUTR = (uint32_t)WakeUpCounter;
- /* Enable the Wakeup Timer */
- __HAL_RTC_WAKEUPTIMER_ENABLE(hrtc);
- /* Enable the write protection for RTC registers */
- __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc);
- hrtc->State = HAL_RTC_STATE_READY;
- /* Process Unlocked */
- __HAL_UNLOCK(hrtc);
- return HAL_OK;
- }
- /**
- * @brief Sets wakeup timer with interrupt.
- * @param hrtc pointer to a RTC_HandleTypeDef structure that contains
- * the configuration information for RTC.
- * @param WakeUpCounter Wakeup counter
- * @param WakeUpClock Wakeup clock
- * @retval HAL status
- */
- HAL_StatusTypeDef HAL_RTCEx_SetWakeUpTimer_IT(RTC_HandleTypeDef *hrtc, uint32_t WakeUpCounter, uint32_t WakeUpClock)
- {
- __IO uint32_t count = RTC_TIMEOUT_VALUE * (SystemCoreClock / 32U / 1000U);
- /* Check the parameters */
- assert_param(IS_RTC_WAKEUP_CLOCK(WakeUpClock));
- assert_param(IS_RTC_WAKEUP_COUNTER(WakeUpCounter));
- /* Process Locked */
- __HAL_LOCK(hrtc);
- hrtc->State = HAL_RTC_STATE_BUSY;
- /* Disable the write protection for RTC registers */
- __HAL_RTC_WRITEPROTECTION_DISABLE(hrtc);
- /* Check RTC WUTWF flag is reset only when wakeup timer enabled */
- if ((hrtc->Instance->CR & RTC_CR_WUTE) != 0U)
- {
- /* Wait till RTC WUTWF flag is reset and if timeout is reached exit */
- do
- {
- count = count - 1U;
- if (count == 0U)
- {
- /* Enable the write protection for RTC registers */
- __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc);
- hrtc->State = HAL_RTC_STATE_TIMEOUT;
- /* Process Unlocked */
- __HAL_UNLOCK(hrtc);
- return HAL_TIMEOUT;
- }
- } while (__HAL_RTC_WAKEUPTIMER_GET_FLAG(hrtc, RTC_FLAG_WUTWF) != 0U);
- }
- /* Disable the Wakeup timer */
- __HAL_RTC_WAKEUPTIMER_DISABLE(hrtc);
- /* Clear the Wakeup flag */
- __HAL_RTC_WAKEUPTIMER_CLEAR_FLAG(hrtc, RTC_FLAG_WUTF);
- /* Reload the counter */
- count = RTC_TIMEOUT_VALUE * (SystemCoreClock / 32U / 1000U);
- /* Wait till RTC WUTWF flag is set and if timeout is reached exit */
- do
- {
- count = count - 1U;
- if (count == 0U)
- {
- /* Enable the write protection for RTC registers */
- __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc);
- hrtc->State = HAL_RTC_STATE_TIMEOUT;
- /* Process Unlocked */
- __HAL_UNLOCK(hrtc);
- return HAL_TIMEOUT;
- }
- } while (__HAL_RTC_WAKEUPTIMER_GET_FLAG(hrtc, RTC_FLAG_WUTWF) == 0U);
- /* Clear the Wakeup Timer clock source bits in CR register */
- hrtc->Instance->CR &= (uint32_t)~RTC_CR_WUCKSEL;
- /* Configure the clock source */
- hrtc->Instance->CR |= (uint32_t)WakeUpClock;
- /* Configure the Wakeup Timer counter */
- hrtc->Instance->WUTR = (uint32_t)WakeUpCounter;
- /* RTC wakeup timer Interrupt Configuration: EXTI configuration */
- __HAL_RTC_WAKEUPTIMER_EXTI_ENABLE_IT();
- __HAL_RTC_WAKEUPTIMER_EXTI_ENABLE_RISING_EDGE();
- /* Configure the interrupt in the RTC_CR register */
- __HAL_RTC_WAKEUPTIMER_ENABLE_IT(hrtc, RTC_IT_WUT);
- /* Enable the Wakeup Timer */
- __HAL_RTC_WAKEUPTIMER_ENABLE(hrtc);
- /* Enable the write protection for RTC registers */
- __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc);
- hrtc->State = HAL_RTC_STATE_READY;
- /* Process Unlocked */
- __HAL_UNLOCK(hrtc);
- return HAL_OK;
- }
- /**
- * @brief Deactivates wakeup timer counter.
- * @param hrtc pointer to a RTC_HandleTypeDef structure that contains
- * the configuration information for RTC.
- * @retval HAL status
- */
- HAL_StatusTypeDef HAL_RTCEx_DeactivateWakeUpTimer(RTC_HandleTypeDef *hrtc)
- {
- uint32_t tickstart = 0U;
- /* Process Locked */
- __HAL_LOCK(hrtc);
- hrtc->State = HAL_RTC_STATE_BUSY;
- /* Disable the write protection for RTC registers */
- __HAL_RTC_WRITEPROTECTION_DISABLE(hrtc);
- /* Disable the Wakeup Timer */
- __HAL_RTC_WAKEUPTIMER_DISABLE(hrtc);
- /* In case of interrupt mode is used, the interrupt source must disabled */
- __HAL_RTC_WAKEUPTIMER_DISABLE_IT(hrtc, RTC_IT_WUT);
- /* Get tick */
- tickstart = HAL_GetTick();
- /* Wait till RTC WUTWF flag is set and if timeout is reached exit */
- while (__HAL_RTC_WAKEUPTIMER_GET_FLAG(hrtc, RTC_FLAG_WUTWF) == 0U)
- {
- if ((HAL_GetTick() - tickstart) > RTC_TIMEOUT_VALUE)
- {
- /* Enable the write protection for RTC registers */
- __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc);
- hrtc->State = HAL_RTC_STATE_TIMEOUT;
- /* Process Unlocked */
- __HAL_UNLOCK(hrtc);
- return HAL_TIMEOUT;
- }
- }
- /* Enable the write protection for RTC registers */
- __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc);
- hrtc->State = HAL_RTC_STATE_READY;
- /* Process Unlocked */
- __HAL_UNLOCK(hrtc);
- return HAL_OK;
- }
- /**
- * @brief Gets wakeup timer counter.
- * @param hrtc pointer to a RTC_HandleTypeDef structure that contains
- * the configuration information for RTC.
- * @retval Counter value
- */
- uint32_t HAL_RTCEx_GetWakeUpTimer(RTC_HandleTypeDef *hrtc)
- {
- /* Get the counter value */
- return ((uint32_t)(hrtc->Instance->WUTR & RTC_WUTR_WUT));
- }
- /**
- * @brief Handles Wakeup Timer interrupt request.
- * @param hrtc pointer to a RTC_HandleTypeDef structure that contains
- * the configuration information for RTC.
- * @retval None
- */
- void HAL_RTCEx_WakeUpTimerIRQHandler(RTC_HandleTypeDef *hrtc)
- {
- /* Clear the EXTI's line Flag for RTC WakeUpTimer */
- __HAL_RTC_WAKEUPTIMER_EXTI_CLEAR_FLAG();
- /* Get the Wakeup timer interrupt source enable status */
- if (__HAL_RTC_WAKEUPTIMER_GET_IT_SOURCE(hrtc, RTC_IT_WUT) != RESET)
- {
- /* Get the pending status of the Wakeup timer Interrupt */
- if (__HAL_RTC_WAKEUPTIMER_GET_FLAG(hrtc, RTC_FLAG_WUTF) != 0U)
- {
- /* Clear the Wakeup timer interrupt pending bit */
- __HAL_RTC_WAKEUPTIMER_CLEAR_FLAG(hrtc, RTC_FLAG_WUTF);
- /* Wakeup timer callback */
- #if (USE_HAL_RTC_REGISTER_CALLBACKS == 1)
- hrtc->WakeUpTimerEventCallback(hrtc);
- #else
- HAL_RTCEx_WakeUpTimerEventCallback(hrtc);
- #endif /* USE_HAL_RTC_REGISTER_CALLBACKS */
- }
- }
- /* Change RTC state */
- hrtc->State = HAL_RTC_STATE_READY;
- }
- /**
- * @brief Wakeup Timer callback.
- * @param hrtc pointer to a RTC_HandleTypeDef structure that contains
- * the configuration information for RTC.
- * @retval None
- */
- __weak void HAL_RTCEx_WakeUpTimerEventCallback(RTC_HandleTypeDef *hrtc)
- {
- /* Prevent unused argument(s) compilation warning */
- UNUSED(hrtc);
- /* NOTE: This function should not be modified, when the callback is needed,
- the HAL_RTCEx_WakeUpTimerEventCallback could be implemented in the user file
- */
- }
- /**
- * @brief Handles Wakeup Timer Polling.
- * @param hrtc pointer to a RTC_HandleTypeDef structure that contains
- * the configuration information for RTC.
- * @param Timeout Timeout duration
- * @retval HAL status
- */
- HAL_StatusTypeDef HAL_RTCEx_PollForWakeUpTimerEvent(RTC_HandleTypeDef *hrtc, uint32_t Timeout)
- {
- uint32_t tickstart = 0U;
- /* Get tick */
- tickstart = HAL_GetTick();
- while (__HAL_RTC_WAKEUPTIMER_GET_FLAG(hrtc, RTC_FLAG_WUTF) == 0U)
- {
- if (Timeout != HAL_MAX_DELAY)
- {
- if ((Timeout == 0U) || ((HAL_GetTick() - tickstart) > Timeout))
- {
- hrtc->State = HAL_RTC_STATE_TIMEOUT;
- return HAL_TIMEOUT;
- }
- }
- }
- /* Clear the Wakeup timer Flag */
- __HAL_RTC_WAKEUPTIMER_CLEAR_FLAG(hrtc, RTC_FLAG_WUTF);
- /* Change RTC state */
- hrtc->State = HAL_RTC_STATE_READY;
- return HAL_OK;
- }
- /**
- * @}
- */
- /** @defgroup RTCEx_Exported_Functions_Group3 Extended Peripheral Control functions
- * @brief Extended Peripheral Control functions
- *
- @verbatim
- ===============================================================================
- ##### Extended Peripheral Control functions #####
- ===============================================================================
- [..]
- This subsection provides functions allowing to
- (+) Write a data in a specified RTC Backup data register
- (+) Read a data in a specified RTC Backup data register
- (+) Set the Smooth calibration parameters.
- (+) Configure the Synchronization Shift Control Settings.
- (+) Configure the Calibration Pinout (RTC_CALIB) Selection (1Hz or 512Hz).
- (+) Deactivate the Calibration Pinout (RTC_CALIB) Selection (1Hz or 512Hz).
- (+) Enable the RTC reference clock detection.
- (+) Disable the RTC reference clock detection.
- (+) Enable the Bypass Shadow feature.
- (+) Disable the Bypass Shadow feature.
- @endverbatim
- * @{
- */
- /**
- * @brief Writes a data in a specified RTC Backup data register.
- * @param hrtc pointer to a RTC_HandleTypeDef structure that contains
- * the configuration information for RTC.
- * @param BackupRegister RTC Backup data Register number.
- * This parameter can be: RTC_BKP_DRx (where x can be from 0 to 4)
- * to specify the register.
- * @param Data Data to be written in the specified RTC Backup data register.
- * @retval None
- */
- void HAL_RTCEx_BKUPWrite(RTC_HandleTypeDef *hrtc, uint32_t BackupRegister, uint32_t Data)
- {
- uint32_t tmp = 0U;
- /* Check the parameters */
- assert_param(IS_RTC_BKP(BackupRegister));
- tmp = (uint32_t) & (hrtc->Instance->BKP0R);
- tmp += (BackupRegister * 4U);
- /* Write the specified register */
- *(__IO uint32_t *)tmp = (uint32_t)Data;
- }
- /**
- * @brief Reads data from the specified RTC Backup data Register.
- * @param hrtc pointer to a RTC_HandleTypeDef structure that contains
- * the configuration information for RTC.
- * @param BackupRegister RTC Backup data Register number.
- * This parameter can be: RTC_BKP_DRx (where x can be from 0 to 4)
- * to specify the register.
- * @retval Read value
- */
- uint32_t HAL_RTCEx_BKUPRead(RTC_HandleTypeDef *hrtc, uint32_t BackupRegister)
- {
- uint32_t tmp = 0U;
- /* Check the parameters */
- assert_param(IS_RTC_BKP(BackupRegister));
- tmp = (uint32_t) & (hrtc->Instance->BKP0R);
- tmp += (BackupRegister * 4U);
- /* Read the specified register */
- return (*(__IO uint32_t *)tmp);
- }
- /**
- * @brief Sets the Smooth calibration parameters.
- * @param hrtc pointer to a RTC_HandleTypeDef structure that contains
- * the configuration information for RTC.
- * @param SmoothCalibPeriod Select the Smooth Calibration Period.
- * This parameter can be can be one of the following values:
- * @arg RTC_SMOOTHCALIB_PERIOD_32SEC: The smooth calibration period is 32s.
- * @arg RTC_SMOOTHCALIB_PERIOD_16SEC: The smooth calibration period is 16s.
- * @arg RTC_SMOOTHCALIB_PERIOD_8SEC: The smooth calibration period is 8s.
- * @param SmoothCalibPlusPulses Select to Set or reset the CALP bit.
- * This parameter can be one of the following values:
- * @arg RTC_SMOOTHCALIB_PLUSPULSES_SET: Add one RTCCLK pulse every 2*11 pulses.
- * @arg RTC_SMOOTHCALIB_PLUSPULSES_RESET: No RTCCLK pulses are added.
- * @param SmoothCalibMinusPulsesValue Select the value of CALM[8:0] bits.
- * This parameter can be one any value from 0 to 0x000001FF.
- * @note To deactivate the smooth calibration, the field SmoothCalibPlusPulses
- * must be equal to SMOOTHCALIB_PLUSPULSES_RESET and the field
- * SmoothCalibMinusPulsesValue must be equal to 0.
- * @retval HAL status
- */
- HAL_StatusTypeDef HAL_RTCEx_SetSmoothCalib(RTC_HandleTypeDef *hrtc, uint32_t SmoothCalibPeriod, uint32_t SmoothCalibPlusPulses, uint32_t SmoothCalibMinusPulsesValue)
- {
- uint32_t tickstart = 0U;
- /* Check the parameters */
- assert_param(IS_RTC_SMOOTH_CALIB_PERIOD(SmoothCalibPeriod));
- assert_param(IS_RTC_SMOOTH_CALIB_PLUS(SmoothCalibPlusPulses));
- assert_param(IS_RTC_SMOOTH_CALIB_MINUS(SmoothCalibMinusPulsesValue));
- /* Process Locked */
- __HAL_LOCK(hrtc);
- hrtc->State = HAL_RTC_STATE_BUSY;
- /* Disable the write protection for RTC registers */
- __HAL_RTC_WRITEPROTECTION_DISABLE(hrtc);
- /* check if a calibration is pending*/
- if ((hrtc->Instance->ISR & RTC_ISR_RECALPF) != 0U)
- {
- /* Get tick */
- tickstart = HAL_GetTick();
- /* check if a calibration is pending*/
- while ((hrtc->Instance->ISR & RTC_ISR_RECALPF) != 0U)
- {
- if ((HAL_GetTick() - tickstart) > RTC_TIMEOUT_VALUE)
- {
- /* Enable the write protection for RTC registers */
- __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc);
- /* Change RTC state */
- hrtc->State = HAL_RTC_STATE_TIMEOUT;
- /* Process Unlocked */
- __HAL_UNLOCK(hrtc);
- return HAL_TIMEOUT;
- }
- }
- }
- /* Configure the Smooth calibration settings */
- hrtc->Instance->CALR = (uint32_t)((uint32_t)SmoothCalibPeriod | \
- (uint32_t)SmoothCalibPlusPulses | \
- (uint32_t)SmoothCalibMinusPulsesValue);
- /* Enable the write protection for RTC registers */
- __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc);
- /* Change RTC state */
- hrtc->State = HAL_RTC_STATE_READY;
- /* Process Unlocked */
- __HAL_UNLOCK(hrtc);
- return HAL_OK;
- }
- /**
- * @brief Configures the Synchronization Shift Control Settings.
- * @note When REFCKON is set, firmware must not write to Shift control register.
- * @param hrtc pointer to a RTC_HandleTypeDef structure that contains
- * the configuration information for RTC.
- * @param ShiftAdd1S Select to add or not 1 second to the time calendar.
- * This parameter can be one of the following values:
- * @arg RTC_SHIFTADD1S_SET: Add one second to the clock calendar.
- * @arg RTC_SHIFTADD1S_RESET: No effect.
- * @param ShiftSubFS Select the number of Second Fractions to substitute.
- * This parameter can be one any value from 0 to 0x7FFF.
- * @retval HAL status
- */
- HAL_StatusTypeDef HAL_RTCEx_SetSynchroShift(RTC_HandleTypeDef *hrtc, uint32_t ShiftAdd1S, uint32_t ShiftSubFS)
- {
- uint32_t tickstart = 0U;
- /* Check the parameters */
- assert_param(IS_RTC_SHIFT_ADD1S(ShiftAdd1S));
- assert_param(IS_RTC_SHIFT_SUBFS(ShiftSubFS));
- /* Process Locked */
- __HAL_LOCK(hrtc);
- hrtc->State = HAL_RTC_STATE_BUSY;
- /* Disable the write protection for RTC registers */
- __HAL_RTC_WRITEPROTECTION_DISABLE(hrtc);
- /* Get tick */
- tickstart = HAL_GetTick();
- /* Wait until the shift is completed */
- while ((hrtc->Instance->ISR & RTC_ISR_SHPF) != 0U)
- {
- if ((HAL_GetTick() - tickstart) > RTC_TIMEOUT_VALUE)
- {
- /* Enable the write protection for RTC registers */
- __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc);
- hrtc->State = HAL_RTC_STATE_TIMEOUT;
- /* Process Unlocked */
- __HAL_UNLOCK(hrtc);
- return HAL_TIMEOUT;
- }
- }
- /* Check if the reference clock detection is disabled */
- if ((hrtc->Instance->CR & RTC_CR_REFCKON) == 0U)
- {
- /* Configure the Shift settings */
- hrtc->Instance->SHIFTR = (uint32_t)(uint32_t)(ShiftSubFS) | (uint32_t)(ShiftAdd1S);
- /* If RTC_CR_BYPSHAD bit = 0, wait for synchro else this check is not needed */
- if ((hrtc->Instance->CR & RTC_CR_BYPSHAD) == 0U)
- {
- if (HAL_RTC_WaitForSynchro(hrtc) != HAL_OK)
- {
- /* Enable the write protection for RTC registers */
- __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc);
- hrtc->State = HAL_RTC_STATE_ERROR;
- /* Process Unlocked */
- __HAL_UNLOCK(hrtc);
- return HAL_ERROR;
- }
- }
- }
- else
- {
- /* Enable the write protection for RTC registers */
- __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc);
- /* Change RTC state */
- hrtc->State = HAL_RTC_STATE_ERROR;
- /* Process Unlocked */
- __HAL_UNLOCK(hrtc);
- return HAL_ERROR;
- }
- /* Enable the write protection for RTC registers */
- __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc);
- /* Change RTC state */
- hrtc->State = HAL_RTC_STATE_READY;
- /* Process Unlocked */
- __HAL_UNLOCK(hrtc);
- return HAL_OK;
- }
- /**
- * @brief Configures the Calibration Pinout (RTC_CALIB) Selection (1Hz or 512Hz).
- * @param hrtc pointer to a RTC_HandleTypeDef structure that contains
- * the configuration information for RTC.
- * @param CalibOutput Select the Calibration output Selection.
- * This parameter can be one of the following values:
- * @arg RTC_CALIBOUTPUT_512HZ: A signal has a regular waveform at 512Hz.
- * @arg RTC_CALIBOUTPUT_1HZ: A signal has a regular waveform at 1Hz.
- * @retval HAL status
- */
- HAL_StatusTypeDef HAL_RTCEx_SetCalibrationOutPut(RTC_HandleTypeDef *hrtc, uint32_t CalibOutput)
- {
- /* Check the parameters */
- assert_param(IS_RTC_CALIB_OUTPUT(CalibOutput));
- /* Process Locked */
- __HAL_LOCK(hrtc);
- hrtc->State = HAL_RTC_STATE_BUSY;
- /* Disable the write protection for RTC registers */
- __HAL_RTC_WRITEPROTECTION_DISABLE(hrtc);
- /* Clear flags before config */
- hrtc->Instance->CR &= (uint32_t)~RTC_CR_COSEL;
- /* Configure the RTC_CR register */
- hrtc->Instance->CR |= (uint32_t)CalibOutput;
- __HAL_RTC_CALIBRATION_OUTPUT_ENABLE(hrtc);
- /* Enable the write protection for RTC registers */
- __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc);
- /* Change RTC state */
- hrtc->State = HAL_RTC_STATE_READY;
- /* Process Unlocked */
- __HAL_UNLOCK(hrtc);
- return HAL_OK;
- }
- /**
- * @brief Deactivates the Calibration Pinout (RTC_CALIB) Selection (1Hz or 512Hz).
- * @param hrtc pointer to a RTC_HandleTypeDef structure that contains
- * the configuration information for RTC.
- * @retval HAL status
- */
- HAL_StatusTypeDef HAL_RTCEx_DeactivateCalibrationOutPut(RTC_HandleTypeDef *hrtc)
- {
- /* Process Locked */
- __HAL_LOCK(hrtc);
- hrtc->State = HAL_RTC_STATE_BUSY;
- /* Disable the write protection for RTC registers */
- __HAL_RTC_WRITEPROTECTION_DISABLE(hrtc);
- __HAL_RTC_CALIBRATION_OUTPUT_DISABLE(hrtc);
- /* Enable the write protection for RTC registers */
- __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc);
- /* Change RTC state */
- hrtc->State = HAL_RTC_STATE_READY;
- /* Process Unlocked */
- __HAL_UNLOCK(hrtc);
- return HAL_OK;
- }
- /**
- * @brief Enables the RTC reference clock detection.
- * @param hrtc pointer to a RTC_HandleTypeDef structure that contains
- * the configuration information for RTC.
- * @retval HAL status
- */
- HAL_StatusTypeDef HAL_RTCEx_SetRefClock(RTC_HandleTypeDef *hrtc)
- {
- HAL_StatusTypeDef status;
- /* Process Locked */
- __HAL_LOCK(hrtc);
- hrtc->State = HAL_RTC_STATE_BUSY;
- /* Disable the write protection for RTC registers */
- __HAL_RTC_WRITEPROTECTION_DISABLE(hrtc);
- /* Enter Initialization mode */
- status = RTC_EnterInitMode(hrtc);
- if (status == HAL_OK)
- {
- /* Enable the reference clock detection */
- __HAL_RTC_CLOCKREF_DETECTION_ENABLE(hrtc);
- /* Exit Initialization mode */
- status = RTC_ExitInitMode(hrtc);
- }
- if (status == HAL_OK)
- {
- hrtc->State = HAL_RTC_STATE_READY;
- }
- /* Enable the write protection for RTC registers */
- __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc);
- /* Process Unlocked */
- __HAL_UNLOCK(hrtc);
- return status;
- }
- /**
- * @brief Disable the RTC reference clock detection.
- * @param hrtc pointer to a RTC_HandleTypeDef structure that contains
- * the configuration information for RTC.
- * @retval HAL status
- */
- HAL_StatusTypeDef HAL_RTCEx_DeactivateRefClock(RTC_HandleTypeDef *hrtc)
- {
- HAL_StatusTypeDef status;
- /* Process Locked */
- __HAL_LOCK(hrtc);
- hrtc->State = HAL_RTC_STATE_BUSY;
- /* Disable the write protection for RTC registers */
- __HAL_RTC_WRITEPROTECTION_DISABLE(hrtc);
- /* Enter Initialization mode */
- status = RTC_EnterInitMode(hrtc);
- if (status == HAL_OK)
- {
- /* Disable the reference clock detection */
- __HAL_RTC_CLOCKREF_DETECTION_DISABLE(hrtc);
- /* Exit Initialization mode */
- status = RTC_ExitInitMode(hrtc);
- }
- if (status == HAL_OK)
- {
- hrtc->State = HAL_RTC_STATE_READY;
- }
- /* Enable the write protection for RTC registers */
- __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc);
- /* Process Unlocked */
- __HAL_UNLOCK(hrtc);
- return status;
- }
- /**
- * @brief Enables the Bypass Shadow feature.
- * @param hrtc pointer to a RTC_HandleTypeDef structure that contains
- * the configuration information for RTC.
- * @note When the Bypass Shadow is enabled the calendar value are taken
- * directly from the Calendar counter.
- * @retval HAL status
- */
- HAL_StatusTypeDef HAL_RTCEx_EnableBypassShadow(RTC_HandleTypeDef *hrtc)
- {
- /* Process Locked */
- __HAL_LOCK(hrtc);
- hrtc->State = HAL_RTC_STATE_BUSY;
- /* Disable the write protection for RTC registers */
- __HAL_RTC_WRITEPROTECTION_DISABLE(hrtc);
- /* Set the BYPSHAD bit */
- hrtc->Instance->CR |= (uint8_t)RTC_CR_BYPSHAD;
- /* Enable the write protection for RTC registers */
- __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc);
- /* Change RTC state */
- hrtc->State = HAL_RTC_STATE_READY;
- /* Process Unlocked */
- __HAL_UNLOCK(hrtc);
- return HAL_OK;
- }
- /**
- * @brief Disables the Bypass Shadow feature.
- * @param hrtc pointer to a RTC_HandleTypeDef structure that contains
- * the configuration information for RTC.
- * @note When the Bypass Shadow is enabled the calendar value are taken
- * directly from the Calendar counter.
- * @retval HAL status
- */
- HAL_StatusTypeDef HAL_RTCEx_DisableBypassShadow(RTC_HandleTypeDef *hrtc)
- {
- /* Process Locked */
- __HAL_LOCK(hrtc);
- hrtc->State = HAL_RTC_STATE_BUSY;
- /* Disable the write protection for RTC registers */
- __HAL_RTC_WRITEPROTECTION_DISABLE(hrtc);
- /* Reset the BYPSHAD bit */
- hrtc->Instance->CR &= (uint8_t)~RTC_CR_BYPSHAD;
- /* Enable the write protection for RTC registers */
- __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc);
- /* Change RTC state */
- hrtc->State = HAL_RTC_STATE_READY;
- /* Process Unlocked */
- __HAL_UNLOCK(hrtc);
- return HAL_OK;
- }
- /**
- * @}
- */
- /** @defgroup RTCEx_Exported_Functions_Group4 Extended features functions
- * @brief Extended features functions
- *
- @verbatim
- ===============================================================================
- ##### Extended features functions #####
- ===============================================================================
- [..] This section provides functions allowing to:
- (+) RTC Alarm B callback
- (+) RTC Poll for Alarm B request
- @endverbatim
- * @{
- */
- /**
- * @brief Alarm B callback.
- * @param hrtc pointer to a RTC_HandleTypeDef structure that contains
- * the configuration information for RTC.
- * @retval None
- */
- __weak void HAL_RTCEx_AlarmBEventCallback(RTC_HandleTypeDef *hrtc)
- {
- /* Prevent unused argument(s) compilation warning */
- UNUSED(hrtc);
- /* NOTE: This function should not be modified, when the callback is needed,
- the HAL_RTCEx_AlarmBEventCallback could be implemented in the user file
- */
- }
- /**
- * @brief Handles Alarm B Polling request.
- * @param hrtc pointer to a RTC_HandleTypeDef structure that contains
- * the configuration information for RTC.
- * @param Timeout Timeout duration
- * @retval HAL status
- */
- HAL_StatusTypeDef HAL_RTCEx_PollForAlarmBEvent(RTC_HandleTypeDef *hrtc, uint32_t Timeout)
- {
- uint32_t tickstart = 0U;
- /* Get tick */
- tickstart = HAL_GetTick();
- /* Wait till RTC ALRBF flag is set and if timeout is reached exit */
- while (__HAL_RTC_ALARM_GET_FLAG(hrtc, RTC_FLAG_ALRBF) == 0U)
- {
- if (Timeout != HAL_MAX_DELAY)
- {
- if ((Timeout == 0U) || ((HAL_GetTick() - tickstart) > Timeout))
- {
- hrtc->State = HAL_RTC_STATE_TIMEOUT;
- return HAL_TIMEOUT;
- }
- }
- }
- /* Clear the Alarm flag */
- __HAL_RTC_ALARM_CLEAR_FLAG(hrtc, RTC_FLAG_ALRBF);
- /* Change RTC state */
- hrtc->State = HAL_RTC_STATE_READY;
- return HAL_OK;
- }
- /**
- * @}
- */
- /**
- * @}
- */
- #endif /* HAL_RTC_MODULE_ENABLED */
- /**
- * @}
- */
- /**
- * @}
- */
|