| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808 |
- /**
- ******************************************************************************
- * @file stm32f3xx_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, 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 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.
- (+) To configure the RTC Smooth Digital Calibration value and the corresponding
- calibration cycle period (32s,16s and 8s) use the HAL_RTCEx_SetSmoothCalib()
- function.
- @endverbatim
- ******************************************************************************
- */
- /* Includes ------------------------------------------------------------------*/
- #include "stm32f3xx_hal.h"
- /** @addtogroup STM32F3xx_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 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 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);
- /* Enable and configure the EXTI line associated to the RTC Timestamp and Tamper interrupts */
- __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 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.
- * @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_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->TAFCR;
- /* 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);
- }
- /* 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 tamper global interrupt in case it is enabled */
- tmpreg &= (uint32_t)~RTC_TAFCR_TAMPIE;
- /* Copy desired configuration into configuration register */
- hrtc->Instance->TAFCR = tmpreg;
- hrtc->State = HAL_RTC_STATE_READY;
- /* Process Unlocked */
- __HAL_UNLOCK(hrtc);
- return HAL_OK;
- }
- /**
- * @brief Sets Tamper with interrupt.
- * @note By calling this API the tamper global interrupt will be enabled.
- * @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_TRIGGER(sTamper->Trigger));
- 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->TAFCR;
- /* 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);
- }
- /* 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 global tamper interrupt */
- tmpreg |= (uint32_t)RTC_TAFCR_TAMPIE;
- /* Copy desired configuration into configuration register */
- hrtc->Instance->TAFCR = tmpreg;
- /* Enable and configure the EXTI line associated to the RTC Timestamp and Tamper interrupts */
- __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 The tamper global interrupt bit will remain unchanged.
- * @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 (*)
- *
- * (*) value 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->TAFCR &= (uint32_t)~Tamper;
- 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 flag associated to the RTC Timestamp and Tamper interrupts */
- __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);
- }
- }
- /* Get the Tamper 1 interrupt source enable status */
- if (__HAL_RTC_TAMPER_GET_IT_SOURCE(hrtc, RTC_IT_TAMP) != 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 */
- }
- }
- /* Get the Tamper 2 interrupt source enable status */
- if (__HAL_RTC_TAMPER_GET_IT_SOURCE(hrtc, RTC_IT_TAMP) != 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) != 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
- */
- }
- /**
- * @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
- */
- }
- /**
- * @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;
- }
- /**
- * @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;
- }
- /**
- * @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;
- /* Enable and configure the EXTI line associated to the RTC Wakeup Timer interrupt */
- __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 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.
- * @note Unlike alarm interrupt line (shared by Alarms A and B) or tamper
- * interrupt line (shared by timestamp and tampers) wakeup timer
- * interrupt line is exclusive to the wakeup timer.
- * There is no need in this case to check on the interrupt enable
- * status via __HAL_RTC_WAKEUPTIMER_GET_IT_SOURCE().
- * @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 flag associated to the RTC Wakeup Timer interrupt */
- __HAL_RTC_WAKEUPTIMER_EXTI_CLEAR_FLAG();
- /* 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 15)
- * to specify the register.
- * @note The range of values possible for parameter BackupRegister depends on
- * the total number of Backup data Registers. This total number is not
- * the same on all devices.
- * @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 15)
- * to specify the register.
- * @note The range of values possible for parameter BackupRegister depends on
- * the total number of Backup data Registers. This total number is not
- * the same on all devices.
- * @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 */
- /**
- * @}
- */
- /**
- * @}
- */
|