123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415 |
- /**
- ******************************************************************************
- * @file stm32l4xx_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 Time Stamp functions
- * + RTC Tamper functions
- * + RTC Wake-up functions
- * + Extended Control functions
- * + Extended RTC features functions
- *
- ******************************************************************************
- * @attention
- *
- * Copyright (c) 2017 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 with interrupt mode
- using the HAL_RTCEx_SetWakeUpTimer_IT() function.
- (+) To read the RTC WakeUp Counter register, use the HAL_RTCEx_GetWakeUpTimer()
- 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 (PC13, PB2) managed on
- the RTC_OR register.
- (+) When the RTC_CALIB or RTC_ALARM output is selected, the RTC_OUT pin is
- automatically configured in output alternate function.
- *** Smooth digital Calibration configuration ***
- ================================================
- [..]
- (+) Configure the RTC Original Digital Calibration Value and the corresponding
- calibration cycle period (32s,16s and 8s) using the HAL_RTCEx_SetSmoothCalib()
- function.
- *** TimeStamp configuration ***
- ===============================
- [..]
- (+) Enable the RTC TimeStamp using 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.
- *** Internal TimeStamp configuration ***
- ===============================
- [..]
- (+) Enable the RTC internal TimeStamp using the HAL_RTCEx_SetInternalTimeStamp() function.
- User has to check internal timestamp occurrence using __HAL_RTC_INTERNAL_TIMESTAMP_GET_FLAG.
- (+) To read the RTC TimeStamp Time and Date register, use the HAL_RTCEx_GetTimeStamp()
- function.
- *** Tamper configuration ***
- ============================
- [..]
- (+) Enable the RTC Tamper and configure the Tamper filter count, trigger Edge
- or Level according to the Tamper filter (if equal to 0 Edge else Level)
- value, sampling frequency, NoErase, MaskFlag, precharge or discharge and
- Pull-UP using the HAL_RTCEx_SetTamper() function. You can configure RTC Tamper
- with interrupt mode using HAL_RTCEx_SetTamper_IT() function.
- (+) The default configuration of the Tamper erases the backup registers. To avoid
- erase, enable the NoErase field on the RTC_TAMPCR register.
- (+) STM32L412xx and STM32L422xx only : With new RTC tamper configuration, you have to call HAL_RTC_Init() in order to
- perform TAMP base address offset calculation.
- (+) STM32L412xx and STM32L422xx only : If you don't intend to have tamper using RTC clock, you can bypass its initialization
- by setting ClockEnable inti field to RTC_CLOCK_DISABLE.
- (+) STM32L412xx and STM32L422xx only : Enable Internal tamper using HAL_RTCEx_SetInternalTamper. IT mode can be chosen using
- setting Interrupt field.
- *** 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.
- (+) STM32L412xx and STM32L422xx only : Before calling these functions you have to call HAL_RTC_Init() in order to
- perform TAMP base address offset calculation.
- @endverbatim
- ******************************************************************************
- */
- /* Includes ------------------------------------------------------------------*/
- #include "stm32l4xx_hal.h"
- /** @addtogroup STM32L4xx_HAL_Driver
- * @{
- */
- /** @addtogroup 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 --------------------------------------------------------*/
- /** @addtogroup RTCEx_Exported_Functions
- * @{
- */
- /** @addtogroup RTCEx_Exported_Functions_Group1
- * @brief RTC TimeStamp and Tamper functions
- *
- @verbatim
- ===============================================================================
- ##### RTC TimeStamp and Tamper functions #####
- ===============================================================================
- [..] This section provides functions allowing to configure TimeStamp feature
- @endverbatim
- * @{
- */
- /**
- * @brief Set TimeStamp.
- * @note This API must be called before enabling the TimeStamp feature.
- * @param hrtc RTC handle
- * @param 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 Time stamp event occurs on the
- * rising edge of the related pin.
- * @arg RTC_TIMESTAMPEDGE_FALLING: the Time stamp 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.
- * The RTC TimeStamp Pin is per default PC13, but for reasons of
- * compatibility, this parameter is required.
- * @retval HAL status
- */
- HAL_StatusTypeDef HAL_RTCEx_SetTimeStamp(RTC_HandleTypeDef *hrtc, uint32_t TimeStampEdge, uint32_t RTC_TimeStampPin)
- {
- uint32_t tmpreg;
- /* Check the parameters */
- assert_param(IS_TIMESTAMP_EDGE(TimeStampEdge));
- assert_param(IS_RTC_TIMESTAMP_PIN(RTC_TimeStampPin));
- /* Prevent unused argument(s) compilation warning if no assert_param check */
- UNUSED(RTC_TimeStampPin);
- /* Process Locked */
- __HAL_LOCK(hrtc);
- 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));
- tmpreg |= TimeStampEdge;
- /* Disable the write protection for RTC registers */
- __HAL_RTC_WRITEPROTECTION_DISABLE(hrtc);
- /* Configure the Time Stamp TSEDGE and Enable bits */
- hrtc->Instance->CR = (uint32_t)tmpreg;
- __HAL_RTC_TIMESTAMP_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 Set TimeStamp with Interrupt.
- * @note This API must be called before enabling the TimeStamp feature.
- * @param hrtc RTC handle
- * @param 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 Time stamp event occurs on the
- * rising edge of the related pin.
- * @arg RTC_TIMESTAMPEDGE_FALLING: the Time stamp 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.
- * The RTC TimeStamp Pin is per default PC13, but for reasons of
- * compatibility, this parameter is required.
- * @retval HAL status
- */
- HAL_StatusTypeDef HAL_RTCEx_SetTimeStamp_IT(RTC_HandleTypeDef *hrtc, uint32_t TimeStampEdge, uint32_t RTC_TimeStampPin)
- {
- uint32_t tmpreg;
- /* Check the parameters */
- assert_param(IS_TIMESTAMP_EDGE(TimeStampEdge));
- assert_param(IS_RTC_TIMESTAMP_PIN(RTC_TimeStampPin));
- /* Prevent unused argument(s) compilation warning if no assert_param check */
- UNUSED(RTC_TimeStampPin);
- /* Process Locked */
- __HAL_LOCK(hrtc);
- 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));
- tmpreg |= TimeStampEdge;
- /* Disable the write protection for RTC registers */
- __HAL_RTC_WRITEPROTECTION_DISABLE(hrtc);
- /* Configure the Time Stamp TSEDGE and Enable bits */
- hrtc->Instance->CR = (uint32_t)tmpreg;
- __HAL_RTC_TIMESTAMP_ENABLE(hrtc);
- /* Enable IT timestamp */
- __HAL_RTC_TIMESTAMP_ENABLE_IT(hrtc, RTC_IT_TS);
- /* RTC timestamp Interrupt Configuration: EXTI configuration */
- __HAL_RTC_TAMPER_TIMESTAMP_EXTI_ENABLE_IT();
- __HAL_RTC_TAMPER_TIMESTAMP_EXTI_ENABLE_RISING_EDGE();
- /* 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 Deactivate TimeStamp.
- * @param hrtc RTC handle
- * @retval HAL status
- */
- HAL_StatusTypeDef HAL_RTCEx_DeactivateTimeStamp(RTC_HandleTypeDef *hrtc)
- {
- uint32_t tmpreg;
- /* 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 Time Stamp 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 Set Internal TimeStamp.
- * @note This API must be called before enabling the internal TimeStamp feature.
- * @param hrtc RTC handle
- * @retval HAL status
- */
- HAL_StatusTypeDef HAL_RTCEx_SetInternalTimeStamp(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);
- /* Configure the internal Time Stamp Enable bits */
- __HAL_RTC_INTERNAL_TIMESTAMP_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 Deactivate Internal TimeStamp.
- * @param hrtc RTC handle
- * @retval HAL status
- */
- HAL_StatusTypeDef HAL_RTCEx_DeactivateInternalTimeStamp(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);
- /* Configure the internal Time Stamp Enable bits */
- __HAL_RTC_INTERNAL_TIMESTAMP_DISABLE(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;
- }
- #if defined (STM32L4P5xx) || defined (STM32L4Q5xx)
- /**
- * @brief Get the RTC TimeStamp value.
- * @param hrtc RTC handle
- * @param sTimeStamp Pointer to Time structure
- * if BinMode = RTC_BINARY_ONLY, sTimeStamp->SubSeconds only is used
- * @param sTimeStampDate Pointer to Date structure
- * if BinMode = RTC_BINARY_ONLY, this parameter is not used.
- * @param Format specifies the format of the entered parameters.
- * if BinMode = RTC_BINARY_ONLY, this parameter is not used
- * else 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, tmpdate;
- UNUSED(hrtc);
- sTimeStamp->SubSeconds = READ_REG(RTC->TSSSR);
- if (READ_BIT(RTC->ICSR, RTC_ICSR_BIN) != RTC_BINARY_ONLY)
- {
- /* Check the parameters */
- assert_param(IS_RTC_FORMAT(Format));
- /* Get the TimeStamp time and date registers values */
- tmptime = READ_BIT(RTC->TSTR, RTC_TR_RESERVED_MASK);
- tmpdate = READ_BIT(RTC->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 = READ_BIT(RTC->TSSSR, RTC_TSSSR_SS);
- /* 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));
- 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 Flags */
- WRITE_REG(RTC->SCR, (RTC_SCR_CITSF | RTC_SCR_CTSF));
- return HAL_OK;
- }
- #else /* #if defined (STM32L4P5xx) || defined (STM32L4Q5xx) */
- /**
- * @brief Get the RTC TimeStamp value.
- * @param hrtc RTC handle
- * @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, tmpdate;
- /* 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 Flags */
- __HAL_RTC_INTERNAL_TIMESTAMP_CLEAR_FLAG(hrtc, RTC_FLAG_ITSF);
- __HAL_RTC_TIMESTAMP_CLEAR_FLAG(hrtc, RTC_FLAG_TSF);
- return HAL_OK;
- }
- #endif /* #if defined (STM32L4P5xx) || defined (STM32L4Q5xx) */
- /**
- * @brief Handle TimeStamp interrupt request.
- * @param hrtc RTC handle
- * @retval None
- */
- #if defined(STM32L412xx) || defined(STM32L422xx) || defined (STM32L4P5xx) || defined (STM32L4Q5xx)
- void HAL_RTCEx_TamperTimeStampIRQHandler(RTC_HandleTypeDef *hrtc)
- {
- /* Process TAMP instance pointer */
- TAMP_TypeDef *tamp = (TAMP_TypeDef *)((uint32_t)hrtc->Instance + hrtc->TampOffset);
- /* Clear the EXTI's Flag for RTC TimeStamp and Tamper */
- __HAL_RTC_TAMPER_TIMESTAMP_EXTI_CLEAR_FLAG();
- if ((hrtc->Instance->MISR & RTC_MISR_TSMF) != 0u)
- {
- #if (USE_HAL_RTC_REGISTER_CALLBACKS == 1)
- /* Call TimeStampEvent registered Callback */
- hrtc->TimeStampEventCallback(hrtc);
- #else
- HAL_RTCEx_TimeStampEventCallback(hrtc);
- #endif
- /* Not immediately clear flags because the content of RTC_TSTR and RTC_TSDR arecleared when TSF bit is reset.*/
- hrtc->Instance->SCR = RTC_SCR_CTSF;
- }
- /* Get interrupt status */
- uint32_t tmp = tamp->MISR;
- /* Immediately clear flags */
- tamp->SCR = tmp;
- #if defined(RTC_TAMPER1_SUPPORT)
- /* Check Tamper1 status */
- if ((tmp & RTC_TAMPER_1) == RTC_TAMPER_1)
- {
- #if (USE_HAL_RTC_REGISTER_CALLBACKS == 1)
- /* Call Tamper 1 Event registered Callback */
- hrtc->Tamper1EventCallback(hrtc);
- #else
- /* Tamper1 callback */
- HAL_RTCEx_Tamper1EventCallback(hrtc);
- #endif
- }
- #endif /* RTC_TAMPER1_SUPPORT */
- /* Check Tamper2 status */
- if ((tmp & RTC_TAMPER_2) == RTC_TAMPER_2)
- {
- #if (USE_HAL_RTC_REGISTER_CALLBACKS == 1)
- /* Call Tamper 2 Event registered Callback */
- hrtc->Tamper2EventCallback(hrtc);
- #else
- /* Tamper2 callback */
- HAL_RTCEx_Tamper2EventCallback(hrtc);
- #endif
- }
- #if defined(RTC_TAMPER3_SUPPORT)
- /* Check Tamper3 status */
- if ((tmp & RTC_TAMPER_3) == RTC_TAMPER_3)
- {
- #if (USE_HAL_RTC_REGISTER_CALLBACKS == 1)
- /* Call Tamper 3 Event registered Callback */
- hrtc->Tamper3EventCallback(hrtc);
- #else
- /* Tamper3 callback */
- HAL_RTCEx_Tamper3EventCallback(hrtc);
- #endif
- }
- #endif /* RTC_TAMPER3_SUPPORT */
- /* Change RTC state */
- hrtc->State = HAL_RTC_STATE_READY;
- }
- #else /* #if defined(STM32L412xx) || defined(STM32L422xx) || defined (STM32L4P5xx) || defined (STM32L4Q5xx) */
- 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 and pending flag status */
- if (__HAL_RTC_TIMESTAMP_GET_IT_SOURCE(hrtc, RTC_IT_TS) != 0U)
- {
- if (__HAL_RTC_TIMESTAMP_GET_FLAG(hrtc, RTC_FLAG_TSF) != 0U)
- {
- /* TIMESTAMP callback */
- #if (USE_HAL_RTC_REGISTER_CALLBACKS == 1)
- hrtc->TimeStampEventCallback(hrtc);
- #else /* (USE_HAL_RTC_REGISTER_CALLBACKS == 1) */
- HAL_RTCEx_TimeStampEventCallback(hrtc);
- #endif /* (USE_HAL_RTC_REGISTER_CALLBACKS == 1) */
- /* Clear the TIMESTAMP interrupt pending bit (this will clear timestamp time and date registers) */
- __HAL_RTC_TIMESTAMP_CLEAR_FLAG(hrtc, RTC_FLAG_TSF);
- }
- }
- #if defined(RTC_TAMPER1_SUPPORT)
- /* Get the Tamper1 interrupt source enable status and pending flag status */
- if (__HAL_RTC_TAMPER_GET_IT_SOURCE(hrtc, RTC_IT_TAMP | RTC_IT_TAMP1) != 0U)
- {
- if (__HAL_RTC_TAMPER_GET_FLAG(hrtc, RTC_FLAG_TAMP1F) != 0U)
- {
- /* Clear the Tamper1 interrupt pending bit */
- __HAL_RTC_TAMPER_CLEAR_FLAG(hrtc, RTC_FLAG_TAMP1F);
- /* Tamper1 callback */
- #if (USE_HAL_RTC_REGISTER_CALLBACKS == 1)
- hrtc->Tamper1EventCallback(hrtc);
- #else /* (USE_HAL_RTC_REGISTER_CALLBACKS == 1) */
- HAL_RTCEx_Tamper1EventCallback(hrtc);
- #endif /* (USE_HAL_RTC_REGISTER_CALLBACKS == 1) */
- }
- }
- #endif /* RTC_TAMPER1_SUPPORT */
- /* Get the Tamper2 interrupt source enable status and pending flag status */
- if (__HAL_RTC_TAMPER_GET_IT_SOURCE(hrtc, RTC_IT_TAMP | RTC_IT_TAMP2) != 0U)
- {
- if (__HAL_RTC_TAMPER_GET_FLAG(hrtc, RTC_FLAG_TAMP2F) != 0U)
- {
- /* Clear the Tamper2 interrupt pending bit */
- __HAL_RTC_TAMPER_CLEAR_FLAG(hrtc, RTC_FLAG_TAMP2F);
- /* Tamper2 callback */
- #if (USE_HAL_RTC_REGISTER_CALLBACKS == 1)
- hrtc->Tamper2EventCallback(hrtc);
- #else /* (USE_HAL_RTC_REGISTER_CALLBACKS == 1) */
- HAL_RTCEx_Tamper2EventCallback(hrtc);
- #endif /* (USE_HAL_RTC_REGISTER_CALLBACKS == 1) */
- }
- }
- #if defined(RTC_TAMPER3_SUPPORT)
- /* Get the Tamper3 interrupts source enable status */
- if (__HAL_RTC_TAMPER_GET_IT_SOURCE(hrtc, RTC_IT_TAMP | RTC_IT_TAMP3) != 0U)
- {
- if (__HAL_RTC_TAMPER_GET_FLAG(hrtc, RTC_FLAG_TAMP3F) != 0U)
- {
- /* Clear the Tamper3 interrupt pending bit */
- __HAL_RTC_TAMPER_CLEAR_FLAG(hrtc, RTC_FLAG_TAMP3F);
- /* Tamper3 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;
- }
- #endif /* #if defined(STM32L412xx) || defined(STM32L422xx) || defined (STM32L4P5xx) || defined (STM32L4Q5xx) */
- /**
- * @brief TimeStamp callback.
- * @param hrtc RTC handle
- * @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 Handle TimeStamp polling request.
- * @param hrtc RTC handle
- * @param Timeout Timeout duration
- * @retval HAL status
- */
- HAL_StatusTypeDef HAL_RTCEx_PollForTimeStampEvent(RTC_HandleTypeDef *hrtc, uint32_t Timeout)
- {
- uint32_t tickstart = HAL_GetTick();
- while (__HAL_RTC_TIMESTAMP_GET_FLAG(hrtc, RTC_FLAG_TSF) == 0U)
- {
- 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;
- }
- if (Timeout != HAL_MAX_DELAY)
- {
- if (((HAL_GetTick() - tickstart) > Timeout) || (Timeout == 0U))
- {
- hrtc->State = HAL_RTC_STATE_TIMEOUT;
- return HAL_TIMEOUT;
- }
- }
- }
- /* Change RTC state */
- hrtc->State = HAL_RTC_STATE_READY;
- return HAL_OK;
- }
- /**
- * @}
- */
- /** @addtogroup RTCEx_Exported_Functions_Group2
- * @brief RTC Wake-up functions
- *
- @verbatim
- ===============================================================================
- ##### RTC Wake-up functions #####
- ===============================================================================
- [..] This section provides functions allowing to configure Wake-up feature
- @endverbatim
- * @{
- */
- /**
- * @brief Set wake up timer.
- * @param hrtc RTC handle
- * @param WakeUpCounter Wake up counter
- * @param WakeUpClock Wake up clock
- * @retval HAL status
- */
- HAL_StatusTypeDef HAL_RTCEx_SetWakeUpTimer(RTC_HandleTypeDef *hrtc, uint32_t WakeUpCounter, uint32_t WakeUpClock)
- {
- uint32_t tickstart;
- /* 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);
- /* Clear WUTE in RTC_CR to disable the wakeup timer */
- CLEAR_BIT(hrtc->Instance->CR, RTC_CR_WUTE);
- /* Poll WUTWF until it is set in RTC_ICSR to make sure the access to wakeup autoreload
- counter and to WUCKSEL[2:0] bits is allowed. This step must be skipped in
- calendar initialization mode. */
- #if defined(STM32L412xx) || defined(STM32L422xx) || defined (STM32L4P5xx) || defined (STM32L4Q5xx)
- if (READ_BIT(hrtc->Instance->ICSR, RTC_ICSR_INITF) == 0U)
- #else
- if (READ_BIT(hrtc->Instance->ISR, RTC_ISR_INITF) == 0U)
- #endif
- {
- tickstart = HAL_GetTick();
- #if defined(STM32L412xx) || defined(STM32L422xx) || defined (STM32L4P5xx) || defined (STM32L4Q5xx)
- while (READ_BIT(hrtc->Instance->ICSR, RTC_ICSR_WUTWF) == 0U)
- #else
- while (READ_BIT(hrtc->Instance->ISR, RTC_ISR_WUTWF) == 0U)
- #endif
- {
- 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;
- }
- }
- }
- /* Configure the clock source */
- MODIFY_REG(hrtc->Instance->CR, RTC_CR_WUCKSEL, (uint32_t)WakeUpClock);
- /* Configure the Wakeup Timer counter */
- WRITE_REG(hrtc->Instance->WUTR, (uint32_t)WakeUpCounter);
- /* Enable the Wakeup Timer */
- SET_BIT(hrtc->Instance->CR, RTC_CR_WUTE);
- /* 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 Set wake up timer with interrupt.
- * @param hrtc RTC handle
- * @param WakeUpCounter Wake up counter
- * @param WakeUpClock Wake up clock
- * @param WakeUpAutoClr Wake up auto clear value (look at WUTOCLR in reference manual)
- * - Only available for STM32L412xx and STM32L422xx
- * - No effect if WakeUpAutoClr is set to zero
- * - This feature is meaningful in case of Low power mode to avoid any RTC software execution after Wake Up.
- * That is why when WakeUpAutoClr is set, EXTI is configured as EVENT instead of Interrupt to avoid useless IRQ handler execution.
- * @retval HAL status
- */
- #if defined(STM32L412xx) || defined(STM32L422xx) || defined (STM32L4P5xx) || defined (STM32L4Q5xx)
- HAL_StatusTypeDef HAL_RTCEx_SetWakeUpTimer_IT(RTC_HandleTypeDef *hrtc, uint32_t WakeUpCounter, uint32_t WakeUpClock, uint32_t WakeUpAutoClr)
- #else
- HAL_StatusTypeDef HAL_RTCEx_SetWakeUpTimer_IT(RTC_HandleTypeDef *hrtc, uint32_t WakeUpCounter, uint32_t WakeUpClock)
- #endif
- {
- uint32_t tickstart;
- /* Check the parameters */
- assert_param(IS_RTC_WAKEUP_CLOCK(WakeUpClock));
- assert_param(IS_RTC_WAKEUP_COUNTER(WakeUpCounter));
- #if defined(STM32L412xx) || defined(STM32L422xx) || defined (STM32L4P5xx) || defined (STM32L4Q5xx)
- /* (0x0000<=WUTOCLR<=WUT) */
- assert_param(WakeUpAutoClr <= WakeUpCounter);
- #endif
- /* Process Locked */
- __HAL_LOCK(hrtc);
- hrtc->State = HAL_RTC_STATE_BUSY;
- /* Disable the write protection for RTC registers */
- __HAL_RTC_WRITEPROTECTION_DISABLE(hrtc);
- /* Clear WUTE in RTC_CR to disable the wakeup timer */
- CLEAR_BIT(hrtc->Instance->CR, RTC_CR_WUTE);
- /* Clear flag Wake-Up */
- __HAL_RTC_WAKEUPTIMER_CLEAR_FLAG(hrtc, RTC_FLAG_WUTF);
- /* Poll WUTWF until it is set in RTC_ICSR to make sure the access to wakeup autoreload
- counter and to WUCKSEL[2:0] bits is allowed. This step must be skipped in
- calendar initialization mode. */
- #if defined(STM32L412xx) || defined(STM32L422xx) || defined (STM32L4P5xx) || defined (STM32L4Q5xx)
- if (READ_BIT(hrtc->Instance->ICSR, RTC_ICSR_INITF) == 0U)
- #else
- if (READ_BIT(hrtc->Instance->ISR, RTC_ISR_INITF) == 0U)
- #endif
- {
- tickstart = HAL_GetTick();
- #if defined(STM32L412xx) || defined(STM32L422xx) || defined (STM32L4P5xx) || defined (STM32L4Q5xx)
- while (READ_BIT(hrtc->Instance->ICSR, RTC_ICSR_WUTWF) == 0U)
- #else
- while (READ_BIT(hrtc->Instance->ISR, RTC_ISR_WUTWF) == 0U)
- #endif
- {
- 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;
- }
- }
- }
- #if defined(STM32L412xx) || defined(STM32L422xx) || defined (STM32L4P5xx) || defined (STM32L4Q5xx)
- /* Configure the Wakeup Timer counter and auto clear value */
- hrtc->Instance->WUTR = (uint32_t)(WakeUpCounter | (WakeUpAutoClr << RTC_WUTR_WUTOCLR_Pos));
- #else
- /* Configure the Wakeup Timer counter */
- hrtc->Instance->WUTR = (uint32_t)WakeUpCounter;
- #endif
- /* Configure the clock source */
- MODIFY_REG(hrtc->Instance->CR, RTC_CR_WUCKSEL, (uint32_t)WakeUpClock);
- #if defined(STM32L412xx) || defined(STM32L422xx) || defined (STM32L4P5xx) || defined (STM32L4Q5xx)
- /* In case of WUT autoclr, the IRQ handler should not be called */
- if (WakeUpAutoClr != 0u)
- {
- /* RTC WakeUpTimer EXTI Configuration: Event configuration */
- __HAL_RTC_WAKEUPTIMER_EXTI_ENABLE_EVENT();
- }
- else
- {
- /* RTC WakeUpTimer EXTI Configuration: Interrupt configuration */
- __HAL_RTC_WAKEUPTIMER_EXTI_ENABLE_IT();
- }
- #else /* defined(STM32L412xx) || defined(STM32L422xx) || defined (STM32L4P5xx) || defined (STM32L4Q5xx) */
- __HAL_RTC_WAKEUPTIMER_EXTI_ENABLE_IT();
- #endif /* defined(STM32L412xx) || defined(STM32L422xx) || defined (STM32L4P5xx) || defined (STM32L4Q5xx) */
- __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 Deactivate wake up timer counter.
- * @param hrtc RTC handle
- * @retval HAL status
- */
- HAL_StatusTypeDef HAL_RTCEx_DeactivateWakeUpTimer(RTC_HandleTypeDef *hrtc)
- {
- uint32_t tickstart;
- /* 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);
- tickstart = HAL_GetTick();
- /* Wait till RTC WUTWF flag is set and if Time out 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 Get wake up timer counter.
- * @param hrtc RTC handle
- * @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 Handle Wake Up Timer interrupt request.
- * @param hrtc RTC handle
- * @retval None
- */
- void HAL_RTCEx_WakeUpTimerIRQHandler(RTC_HandleTypeDef *hrtc)
- {
- /* Clear the EXTI's line Flag for RTC WakeUpTimer */
- __HAL_RTC_WAKEUPTIMER_EXTI_CLEAR_FLAG();
- #if defined(STM32L412xx) || defined(STM32L422xx) || defined (STM32L4P5xx) || defined (STM32L4Q5xx)
- if ((hrtc->Instance->MISR & RTC_MISR_WUTMF) != 0u)
- {
- /* Immediately clear flags */
- hrtc->Instance->SCR = RTC_SCR_CWUTF;
- #else
- /* Get the pending status of the WAKEUPTIMER Interrupt */
- if (__HAL_RTC_WAKEUPTIMER_GET_FLAG(hrtc, RTC_FLAG_WUTF) != 0U)
- {
- /* Clear the WAKEUPTIMER interrupt pending bit */
- __HAL_RTC_WAKEUPTIMER_CLEAR_FLAG(hrtc, RTC_FLAG_WUTF);
- #endif
- /* WAKEUPTIMER callback */
- #if (USE_HAL_RTC_REGISTER_CALLBACKS == 1)
- /* Call WakeUpTimerEvent registered Callback */
- hrtc->WakeUpTimerEventCallback(hrtc);
- #else
- HAL_RTCEx_WakeUpTimerEventCallback(hrtc);
- #endif /* USE_HAL_RTC_REGISTER_CALLBACKS */
- }
- /* Change RTC state */
- hrtc->State = HAL_RTC_STATE_READY;
- }
- /**
- * @brief Wake Up Timer callback.
- * @param hrtc RTC handle
- * @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 Handle Wake Up Timer Polling.
- * @param hrtc RTC handle
- * @param Timeout Timeout duration
- * @retval HAL status
- */
- HAL_StatusTypeDef HAL_RTCEx_PollForWakeUpTimerEvent(RTC_HandleTypeDef *hrtc, uint32_t Timeout)
- {
- uint32_t tickstart = HAL_GetTick();
- while (__HAL_RTC_WAKEUPTIMER_GET_FLAG(hrtc, RTC_FLAG_WUTF) == 0U)
- {
- if (Timeout != HAL_MAX_DELAY)
- {
- if (((HAL_GetTick() - tickstart) > Timeout) || (Timeout == 0U))
- {
- hrtc->State = HAL_RTC_STATE_TIMEOUT;
- return HAL_TIMEOUT;
- }
- }
- }
- /* Clear the WAKEUPTIMER Flag */
- __HAL_RTC_WAKEUPTIMER_CLEAR_FLAG(hrtc, RTC_FLAG_WUTF);
- /* Change RTC state */
- hrtc->State = HAL_RTC_STATE_READY;
- return HAL_OK;
- }
- /**
- * @}
- */
- /** @addtogroup RTCEx_Exported_Functions_Group3
- * @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 Coarse calibration parameters.
- (+) Deactivate the Coarse calibration parameters
- (+) Set the Smooth calibration parameters.
- (+) STM32L412xx and STM32L422xx only : Set Low Power calibration parameter.
- (+) 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 Set the Smooth calibration parameters.
- * @param hrtc RTC handle
- * @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;
- /* 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 defined(STM32L412xx) || defined(STM32L422xx) || defined (STM32L4P5xx) || defined (STM32L4Q5xx)
- if ((hrtc->Instance->ICSR & RTC_ICSR_RECALPF) != 0U)
- #else
- if ((hrtc->Instance->ISR & RTC_ISR_RECALPF) != 0U)
- #endif
- {
- tickstart = HAL_GetTick();
- /* check if a calibration is pending*/
- #if defined(STM32L412xx) || defined(STM32L422xx) || defined (STM32L4P5xx) || defined (STM32L4Q5xx)
- while ((hrtc->Instance->ICSR & RTC_ICSR_RECALPF) != 0U)
- #else
- while ((hrtc->Instance->ISR & RTC_ISR_RECALPF) != 0U)
- #endif
- {
- 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 */
- MODIFY_REG(hrtc->Instance->CALR, (RTC_CALR_CALP | RTC_CALR_CALW8 | RTC_CALR_CALW16 | RTC_CALR_CALM), (uint32_t)(SmoothCalibPeriod | SmoothCalibPlusPulses | 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;
- }
- #if defined(STM32L412xx) || defined(STM32L422xx) || defined (STM32L4P5xx) || defined (STM32L4Q5xx)
- /**
- * @brief Select the low power Calibration mode.
- * @param hrtc RTC handle
- * @param LowPowerCalib Low power Calibration mode.
- * This parameter can be can be one of the following values :
- * @arg RTC_LPCAL_SET: Low power mode.
- * @arg RTC_LPCAL_RESET: High consumption mode.
- * @retval HAL status
- */
- HAL_StatusTypeDef HAL_RTCEx_SetLowPowerCalib(RTC_HandleTypeDef *hrtc, uint32_t LowPowerCalib)
- {
- /* Check the parameters */
- assert_param(IS_RTC_LOW_POWER_CALIB(LowPowerCalib));
- /* Process Locked */
- __HAL_LOCK(hrtc);
- hrtc->State = HAL_RTC_STATE_BUSY;
- /* Disable the write protection for RTC registers */
- __HAL_RTC_WRITEPROTECTION_DISABLE(hrtc);
- /* Configure the Smooth calibration settings */
- MODIFY_REG(hrtc->Instance->CALR, RTC_CALR_LPCAL, LowPowerCalib);
- /* 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;
- }
- #endif /* #if defined(STM32L412xx) || defined(STM32L422xx) || defined (STM32L4P5xx) || defined (STM32L4Q5xx) */
- /**
- * @brief Configure the Synchronization Shift Control Settings.
- * @note When REFCKON is set, firmware must not write to Shift control register.
- * @param hrtc RTC handle
- * @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;
- /* 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);
- tickstart = HAL_GetTick();
- /* Wait until the shift is completed*/
- #if defined(STM32L412xx) || defined(STM32L422xx) || defined (STM32L4P5xx) || defined (STM32L4Q5xx)
- while ((hrtc->Instance->ICSR & RTC_ICSR_SHPF) != 0U)
- #else
- while ((hrtc->Instance->ISR & RTC_ISR_SHPF) != 0U)
- #endif
- {
- 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 Configure the Calibration Pinout (RTC_CALIB) Selection (1Hz or 512Hz).
- * @param hrtc RTC handle
- * @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 Deactivate the Calibration Pinout (RTC_CALIB) Selection (1Hz or 512Hz).
- * @param hrtc RTC handle
- * @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 Enable the RTC reference clock detection.
- * @param hrtc RTC handle
- * @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)
- {
- __HAL_RTC_CLOCKREF_DETECTION_ENABLE(hrtc);
- /* Exit Initialization mode */
- status = RTC_ExitInitMode(hrtc);
- }
- /* Enable the write protection for RTC registers */
- __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc);
- if (status == HAL_OK)
- {
- hrtc->State = HAL_RTC_STATE_READY;
- }
- /* Process Unlocked */
- __HAL_UNLOCK(hrtc);
- return status;
- }
- /**
- * @brief Disable the RTC reference clock detection.
- * @param hrtc RTC handle
- * @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)
- {
- __HAL_RTC_CLOCKREF_DETECTION_DISABLE(hrtc);
- /* Exit Initialization mode */
- status = RTC_ExitInitMode(hrtc);
- }
- /* Enable the write protection for RTC registers */
- __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc);
- if (status == HAL_OK)
- {
- hrtc->State = HAL_RTC_STATE_READY;
- }
- /* Process Unlocked */
- __HAL_UNLOCK(hrtc);
- return status;
- }
- /**
- * @brief Enable the Bypass Shadow feature.
- * @note When the Bypass Shadow is enabled the calendar value are taken
- * directly from the Calendar counter.
- * @param hrtc RTC handle
- * @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 */
- SET_BIT(hrtc->Instance->CR, 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 Disable the Bypass Shadow feature.
- * @note When the Bypass Shadow is enabled the calendar value are taken
- * directly from the Calendar counter.
- * @param hrtc RTC handle
- * @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);
- /* Clear the BYPSHAD bit */
- CLEAR_BIT(RTC->CR, 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;
- }
- #if defined (STM32L4P5xx) || defined (STM32L4Q5xx)
- /**
- * @brief Set SSR Underflow detection with Interrupt.
- * @param hrtc RTC handle
- * @retval HAL status
- */
- HAL_StatusTypeDef HAL_RTCEx_SetSSRU_IT(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);
- /* Enable IT SSRU */
- __HAL_RTC_SSRU_ENABLE_IT(hrtc, RTC_IT_SSRU);
- /* RTC SSRU Interrupt Configuration: EXTI configuration */
- __HAL_RTC_SSRU_EXTI_ENABLE_IT();
- __HAL_RTC_ALARM_EXTI_ENABLE_RISING_EDGE();
- /* 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 Deactivate SSR Underflow.
- * @param hrtc RTC handle
- * @retval HAL status
- */
- HAL_StatusTypeDef HAL_RTCEx_DeactivateSSRU(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);
- /* In case of interrupt mode is used, the interrupt source must disabled */
- __HAL_RTC_SSRU_DISABLE_IT(hrtc, RTC_IT_TS);
- /* 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 Handle SSR underflow interrupt request.
- * @param hrtc RTC handle
- * @retval None
- */
- void HAL_RTCEx_SSRUIRQHandler(RTC_HandleTypeDef *hrtc)
- {
- if ((RTC->MISR & RTC_MISR_SSRUMF) != 0u)
- {
- /* Immediately clear flags */
- RTC->SCR = RTC_SCR_CSSRUF;
- /* SSRU callback */
- #if (USE_HAL_RTC_REGISTER_CALLBACKS == 1)
- /* Call SSRUEvent registered Callback */
- hrtc->SSRUEventCallback(hrtc);
- #else
- HAL_RTCEx_SSRUEventCallback(hrtc);
- #endif /* USE_HAL_RTC_REGISTER_CALLBACKS */
- }
- /* Change RTC state */
- hrtc->State = HAL_RTC_STATE_READY;
- }
- /**
- * @brief SSR underflow callback.
- * @param hrtc RTC handle
- * @retval None
- */
- __weak void HAL_RTCEx_SSRUEventCallback(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_SSRUEventCallback could be implemented in the user file
- */
- }
- #endif /* #if defined (STM32L4P5xx) || defined (STM32L4Q5xx) */
- /**
- * @}
- */
- /** @addtogroup RTCEx_Exported_Functions_Group4
- * @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 RTC handle
- * @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 Handle Alarm B Polling request.
- * @param hrtc RTC handle
- * @param Timeout Timeout duration
- * @retval HAL status
- */
- HAL_StatusTypeDef HAL_RTCEx_PollForAlarmBEvent(RTC_HandleTypeDef *hrtc, uint32_t Timeout)
- {
- uint32_t tickstart = HAL_GetTick();
- while (__HAL_RTC_ALARM_GET_FLAG(hrtc, RTC_FLAG_ALRBF) == 0U)
- {
- if (Timeout != HAL_MAX_DELAY)
- {
- if (((HAL_GetTick() - tickstart) > Timeout) || (Timeout == 0U))
- {
- 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;
- }
- /**
- * @}
- */
- /** @addtogroup RTCEx_Exported_Functions_Group5
- * @brief Extended RTC Tamper functions
- *
- @verbatim
- ==============================================================================
- ##### Tamper functions #####
- ==============================================================================
- [..]
- (+) Before calling any tamper or internal tamper function, you have to call first
- HAL_RTC_Init() function.
- (+) In that ine you can select to output tamper event on RTC pin.
- [..]
- (+) Enable the Tamper and configure the Tamper filter count, trigger Edge
- or Level according to the Tamper filter (if equal to 0 Edge else Level)
- value, sampling frequency, NoErase, MaskFlag, precharge or discharge and
- Pull-UP, timestamp using the HAL_RTCEx_SetTamper() function.
- You can configure Tamper with interrupt mode using HAL_RTCEx_SetTamper_IT() function.
- (+) The default configuration of the Tamper erases the backup registers. To avoid
- erase, enable the NoErase field on the TAMP_TAMPCR register.
- [..]
- (+) Enable Internal Tamper and configure it with interrupt, timestamp using
- the HAL_RTCEx_SetInternalTamper() function.
- @endverbatim
- * @{
- */
- #if defined(STM32L412xx) || defined(STM32L422xx) || defined (STM32L4P5xx) || defined (STM32L4Q5xx)
- /**
- * @brief Set Tamper
- * @param hrtc RTC handle
- * @param sTamper Pointer to Tamper Structure.
- * @retval HAL status
- */
- HAL_StatusTypeDef HAL_RTCEx_SetTamper(RTC_HandleTypeDef *hrtc, RTC_TamperTypeDef *sTamper)
- {
- uint32_t tmpreg;
- /* Process TAMP instance pointer */
- TAMP_TypeDef *tamp = (TAMP_TypeDef *)((uint32_t)hrtc->Instance + hrtc->TampOffset);
- /* 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_TIMESTAMPONTAMPER_DETECTION(sTamper->TimeStampOnTamperDetection));
- assert_param(IS_RTC_TAMPER_FILTER(sTamper->Filter));
- 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));
- /* Trigger and Filter have exclusive configurations */
- assert_param(((sTamper->Filter != RTC_TAMPERFILTER_DISABLE) && ((sTamper->Trigger == RTC_TAMPERTRIGGER_LOWLEVEL) || (sTamper->Trigger == RTC_TAMPERTRIGGER_HIGHLEVEL)))
- || ((sTamper->Filter == RTC_TAMPERFILTER_DISABLE) && ((sTamper->Trigger == RTC_TAMPERTRIGGER_RISINGEDGE) || (sTamper->Trigger == RTC_TAMPERTRIGGER_FALLINGEDGE))));
- /* Configuration register 2 */
- tmpreg = tamp->CR2;
- tmpreg &= ~((sTamper->Tamper << TAMP_CR2_TAMP1TRG_Pos) | (sTamper->Tamper << TAMP_CR2_TAMP1MSK_Pos) | (sTamper->Tamper << TAMP_CR2_TAMP1NOERASE_Pos));
- /* Configure the tamper trigger bit */
- if ((sTamper->Trigger == RTC_TAMPERTRIGGER_HIGHLEVEL) || (sTamper->Trigger == RTC_TAMPERTRIGGER_FALLINGEDGE))
- {
- tmpreg |= (sTamper->Tamper << TAMP_CR2_TAMP1TRG_Pos);
- }
- /* Configure the tamper flags masking bit */
- if (sTamper->MaskFlag != RTC_TAMPERMASK_FLAG_DISABLE)
- {
- tmpreg |= (sTamper->Tamper << TAMP_CR2_TAMP1MSK_Pos);
- }
- /* Configure the tamper backup registers erasure bit */
- if (sTamper->NoErase != RTC_TAMPER_ERASE_BACKUP_ENABLE)
- {
- tmpreg |= (sTamper->Tamper << TAMP_CR2_TAMP1NOERASE_Pos);
- }
- tamp->CR2 = tmpreg;
- /* Configure filtering parameters */
- tamp->FLTCR = (sTamper->Filter) | (sTamper->SamplingFrequency) | \
- (sTamper->PrechargeDuration) | (sTamper->TamperPullUp);
- /* Configure Timestamp saving on tamper detection */
- if ((hrtc->Instance->CR & RTC_CR_TAMPTS) != (sTamper->TimeStampOnTamperDetection))
- {
- __HAL_RTC_WRITEPROTECTION_DISABLE(hrtc);
- tmpreg = (hrtc->Instance->CR & ~RTC_CR_TAMPTS);
- hrtc->Instance->CR = (tmpreg | (sTamper->TimeStampOnTamperDetection));
- __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc);
- }
- /* Enable selected tamper */
- tamp->CR1 |= (sTamper->Tamper);
- return HAL_OK;
- }
- #else /* #if defined(STM32L412xx) || defined(STM32L422xx) || defined (STM32L4P5xx) || defined (STM32L4Q5xx) */
- /**
- * @brief Set Tamper.
- * @note By calling this API we disable the tamper interrupt for all tampers.
- * @param hrtc RTC handle
- * @param sTamper Pointer to Tamper Structure.
- * @retval HAL status
- */
- HAL_StatusTypeDef HAL_RTCEx_SetTamper(RTC_HandleTypeDef *hrtc, RTC_TamperTypeDef *sTamper)
- {
- uint32_t tmpreg;
- /* 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_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;
- /* Read register */
- tmpreg = hrtc->Instance->TAMPCR;
- #if defined(RTC_TAMPER1_SUPPORT)
- if ((sTamper->Tamper & RTC_TAMPER_1) != 0)
- {
- MODIFY_REG(tmpreg,
- (RTC_TAMPCR_TAMP1E | RTC_TAMPCR_TAMP1TRG | RTC_TAMPCR_TAMPIE | RTC_TAMPCR_TAMP1IE | RTC_TAMPCR_TAMP1NOERASE | RTC_TAMPCR_TAMP1MF), \
- sTamper->Tamper | \
- (sTamper->Trigger == RTC_TAMPERTRIGGER_RISINGEDGE ? 0U : RTC_TAMPCR_TAMP1TRG) | \
- (sTamper->NoErase == RTC_TAMPER_ERASE_BACKUP_ENABLE ? 0U : RTC_TAMPCR_TAMP1NOERASE) | \
- (sTamper->MaskFlag == RTC_TAMPERMASK_FLAG_ENABLE ? RTC_TAMPCR_TAMP1MF : 0U) \
- );
- }
- #endif /* RTC_TAMPER1_SUPPORT */
- #if defined(RTC_TAMPER2_SUPPORT)
- if ((sTamper->Tamper & RTC_TAMPER_2) != 0)
- {
- MODIFY_REG(tmpreg,
- (RTC_TAMPCR_TAMP2E | RTC_TAMPCR_TAMP2TRG | RTC_TAMPCR_TAMPIE | RTC_TAMPCR_TAMP2IE | RTC_TAMPCR_TAMP2NOERASE | RTC_TAMPCR_TAMP2MF), \
- sTamper->Tamper | \
- (sTamper->Trigger == RTC_TAMPERTRIGGER_RISINGEDGE ? 0U : RTC_TAMPCR_TAMP2TRG) | \
- (sTamper->NoErase == RTC_TAMPER_ERASE_BACKUP_ENABLE ? 0U : RTC_TAMPCR_TAMP2NOERASE) | \
- (sTamper->MaskFlag == RTC_TAMPERMASK_FLAG_ENABLE ? RTC_TAMPCR_TAMP2MF : 0U) \
- );
- }
- #endif /* RTC_TAMPER2_SUPPORT */
- #if defined(RTC_TAMPER3_SUPPORT)
- if ((sTamper->Tamper & RTC_TAMPER_3) != 0)
- {
- MODIFY_REG(tmpreg,
- (RTC_TAMPCR_TAMP3E | RTC_TAMPCR_TAMP3TRG | RTC_TAMPCR_TAMPIE | RTC_TAMPCR_TAMP3IE | RTC_TAMPCR_TAMP3NOERASE | RTC_TAMPCR_TAMP3MF), \
- sTamper->Tamper | \
- (sTamper->Trigger == RTC_TAMPERTRIGGER_RISINGEDGE ? 0U : RTC_TAMPCR_TAMP3TRG) | \
- (sTamper->NoErase == RTC_TAMPER_ERASE_BACKUP_ENABLE ? 0U : RTC_TAMPCR_TAMP3NOERASE) | \
- (sTamper->MaskFlag == RTC_TAMPERMASK_FLAG_ENABLE ? RTC_TAMPCR_TAMP3MF : 0U) \
- );
- }
- #endif /* RTC_TAMPER3_SUPPORT */
- /* Update common parameters */
- MODIFY_REG(tmpreg,
- (RTC_TAMPCR_TAMPTS | RTC_TAMPCR_TAMPFREQ | RTC_TAMPCR_TAMPFLT | RTC_TAMPCR_TAMPPRCH | RTC_TAMPCR_TAMPPUDIS), \
- sTamper->Filter | sTamper->SamplingFrequency | sTamper->PrechargeDuration | sTamper->TamperPullUp | \
- sTamper->TimeStampOnTamperDetection \
- );
- /* Set register */
- WRITE_REG(hrtc->Instance->TAMPCR, tmpreg);
- hrtc->State = HAL_RTC_STATE_READY;
- /* Process Unlocked */
- __HAL_UNLOCK(hrtc);
- return HAL_OK;
- }
- #endif /* #if defined(STM32L412xx) || defined(STM32L422xx) || defined (STM32L4P5xx) || defined (STM32L4Q5xx) */
- #if defined(STM32L412xx) || defined(STM32L422xx) || defined (STM32L4P5xx) || defined (STM32L4Q5xx)
- /**
- * @brief Set Tamper with interrupt.
- * @param hrtc RTC handle
- * @param sTamper Pointer to Tamper Structure.
- * @retval HAL status
- */
- HAL_StatusTypeDef HAL_RTCEx_SetTamper_IT(RTC_HandleTypeDef *hrtc, RTC_TamperTypeDef *sTamper)
- {
- uint32_t tmpreg;
- /* Process TAMP instance pointer */
- TAMP_TypeDef *tamp = (TAMP_TypeDef *)((uint32_t)hrtc->Instance + hrtc->TampOffset);
- /* 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_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));
- /* Copy configuration register into temporary variable */
- tmpreg = tamp->CR2;
- /* Clear the bits that are going to be configured and leave the others unchanged */
- tmpreg &= ~((sTamper->Tamper << TAMP_CR2_TAMP1TRG_Pos) | (sTamper->Tamper << TAMP_CR2_TAMP1MSK_Pos) | (sTamper->Tamper << TAMP_CR2_TAMP1NOERASE_Pos));
- if (sTamper->Trigger != RTC_TAMPERTRIGGER_RISINGEDGE)
- {
- tmpreg |= (sTamper->Tamper << TAMP_CR2_TAMP1TRG_Pos);
- }
- /* Configure the tamper flags masking bit */
- if (sTamper->MaskFlag != RTC_TAMPERMASK_FLAG_DISABLE)
- {
- tmpreg |= (sTamper->Tamper << TAMP_CR2_TAMP1MSK_Pos);
- }
- /* Configure the tamper backup registers erasure bit */
- if (sTamper->NoErase != RTC_TAMPER_ERASE_BACKUP_ENABLE)
- {
- tmpreg |= (sTamper->Tamper << TAMP_CR2_TAMP1NOERASE_Pos);
- }
- tamp->CR2 = tmpreg;
- /* Configure filtering parameters */
- tamp->FLTCR = (sTamper->Filter) | (sTamper->SamplingFrequency) | \
- (sTamper->PrechargeDuration) | (sTamper->TamperPullUp);
- /* Configure Timestamp saving on tamper detection */
- if ((hrtc->Instance->CR & RTC_CR_TAMPTS) != (sTamper->TimeStampOnTamperDetection))
- {
- __HAL_RTC_WRITEPROTECTION_DISABLE(hrtc);
- tmpreg = (hrtc->Instance->CR & ~RTC_CR_TAMPTS);
- hrtc->Instance->CR = (tmpreg | (sTamper->TimeStampOnTamperDetection));
- __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc);
- }
- /* Configure RTC Tamper Interrupt: EXTI configuration */
- __HAL_RTC_TAMPER_TIMESTAMP_EXTI_ENABLE_IT();
- __HAL_RTC_TAMPER_TIMESTAMP_EXTI_ENABLE_RISING_FALLING_EDGE();
- /* Enable interrupt on selected tamper */
- tamp->IER |= sTamper->Tamper;
- /* Enable selected tamper */
- tamp->CR1 |= sTamper->Tamper;
- return HAL_OK;
- }
- #else /* #if defined(STM32L412xx) || defined(STM32L422xx) || defined (STM32L4P5xx) || defined (STM32L4Q5xx) */
- /**
- * @brief Set Tamper with interrupt.
- * @param hrtc RTC handle
- * @param sTamper Pointer to Tamper Structure.
- * @retval HAL status
- */
- HAL_StatusTypeDef HAL_RTCEx_SetTamper_IT(RTC_HandleTypeDef *hrtc, RTC_TamperTypeDef *sTamper)
- {
- uint32_t tmpreg;
- /* 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_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;
- /* Read register */
- tmpreg = hrtc->Instance->TAMPCR;
- #if defined(RTC_TAMPER1_SUPPORT)
- if ((sTamper->Tamper & RTC_TAMPER_1) != 0)
- {
- MODIFY_REG(tmpreg,
- (RTC_TAMPCR_TAMP1E | RTC_TAMPCR_TAMP1TRG | RTC_TAMPCR_TAMPIE | RTC_TAMPCR_TAMP1IE | RTC_TAMPCR_TAMP1NOERASE | RTC_TAMPCR_TAMP1MF), \
- sTamper->Tamper | sTamper->Interrupt | \
- (sTamper->Trigger == RTC_TAMPERTRIGGER_RISINGEDGE ? 0U : RTC_TAMPCR_TAMP1TRG) | \
- (sTamper->NoErase == RTC_TAMPER_ERASE_BACKUP_ENABLE ? 0U : RTC_TAMPCR_TAMP1NOERASE) | \
- (sTamper->MaskFlag == RTC_TAMPERMASK_FLAG_ENABLE ? RTC_TAMPCR_TAMP1MF : 0U) \
- );
- }
- #endif /* RTC_TAMPER1_SUPPORT */
- #if defined(RTC_TAMPER2_SUPPORT)
- if ((sTamper->Tamper & RTC_TAMPER_2) != 0)
- {
- MODIFY_REG(tmpreg,
- (RTC_TAMPCR_TAMP2E | RTC_TAMPCR_TAMP2TRG | RTC_TAMPCR_TAMPIE | RTC_TAMPCR_TAMP2IE | RTC_TAMPCR_TAMP2NOERASE | RTC_TAMPCR_TAMP2MF), \
- sTamper->Tamper | sTamper->Interrupt | \
- (sTamper->Trigger == RTC_TAMPERTRIGGER_RISINGEDGE ? 0U : RTC_TAMPCR_TAMP2TRG) | \
- (sTamper->NoErase == RTC_TAMPER_ERASE_BACKUP_ENABLE ? 0U : RTC_TAMPCR_TAMP2NOERASE) | \
- (sTamper->MaskFlag == RTC_TAMPERMASK_FLAG_ENABLE ? RTC_TAMPCR_TAMP2MF : 0U) \
- );
- }
- #endif /* RTC_TAMPER2_SUPPORT */
- #if defined(RTC_TAMPER3_SUPPORT)
- if ((sTamper->Tamper & RTC_TAMPER_3) != 0)
- {
- MODIFY_REG(tmpreg,
- (RTC_TAMPCR_TAMP3E | RTC_TAMPCR_TAMP3TRG | RTC_TAMPCR_TAMPIE | RTC_TAMPCR_TAMP3IE | RTC_TAMPCR_TAMP3NOERASE | RTC_TAMPCR_TAMP3MF), \
- sTamper->Tamper | sTamper->Interrupt | \
- (sTamper->Trigger == RTC_TAMPERTRIGGER_RISINGEDGE ? 0U : RTC_TAMPCR_TAMP3TRG) | \
- (sTamper->NoErase == RTC_TAMPER_ERASE_BACKUP_ENABLE ? 0U : RTC_TAMPCR_TAMP3NOERASE) | \
- (sTamper->MaskFlag == RTC_TAMPERMASK_FLAG_ENABLE ? RTC_TAMPCR_TAMP3MF : 0U) \
- );
- }
- #endif /* RTC_TAMPER3_SUPPORT */
- /* Update common parameters */
- MODIFY_REG(tmpreg,
- (RTC_TAMPCR_TAMPTS | RTC_TAMPCR_TAMPFREQ | RTC_TAMPCR_TAMPFLT | RTC_TAMPCR_TAMPPRCH | RTC_TAMPCR_TAMPPUDIS), \
- sTamper->Filter | sTamper->SamplingFrequency | sTamper->PrechargeDuration | sTamper->TamperPullUp | \
- sTamper->TimeStampOnTamperDetection \
- );
- /* Set register */
- WRITE_REG(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;
- }
- #endif /* #if defined(STM32L412xx) || defined(STM32L422xx) || defined (STM32L4P5xx) || defined (STM32L4Q5xx) */
- #if defined(STM32L412xx) || defined(STM32L422xx) || defined (STM32L4P5xx) || defined (STM32L4Q5xx)
- /**
- * @brief Deactivate Tamper.
- * @param hrtc RTC handle
- * @param Tamper Selected tamper pin.
- * This parameter can be a combination of the following values:
- * @arg RTC_TAMPER_1
- * @arg RTC_TAMPER_2
- * @retval HAL status
- */
- HAL_StatusTypeDef HAL_RTCEx_DeactivateTamper(RTC_HandleTypeDef *hrtc, uint32_t Tamper)
- {
- /* Process TAMP instance pointer */
- TAMP_TypeDef *tamp = (TAMP_TypeDef *)((uint32_t)hrtc->Instance + hrtc->TampOffset);
- assert_param(IS_RTC_TAMPER(Tamper));
- /* Disable the selected Tamper pin */
- tamp->CR1 &= ~Tamper;
- /* Clear tamper mask/noerase/trigger configuration */
- tamp->CR2 &= ~((Tamper << 24) | (Tamper << 16) | Tamper);
- /* Clear tamper interrupt mode configuration */
- tamp->IER &= ~Tamper;
- /* Clear tamper interrupt and event flags (WO register) */
- tamp->SCR = Tamper;
- return HAL_OK;
- }
- #else /* #if defined(STM32L412xx) || defined(STM32L422xx) || defined (STM32L4P5xx) || defined (STM32L4Q5xx) */
- /**
- * @brief Deactivate Tamper.
- * @param hrtc RTC handle
- * @param Tamper Selected tamper pin.
- * This parameter can be any combination of the following values:
- * @arg RTC_TAMPER_1
- * @arg RTC_TAMPER_2
- * @arg RTC_TAMPER_3
- * @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 &= ~Tamper;
- #if defined(RTC_TAMPER1_SUPPORT)
- if ((Tamper & RTC_TAMPER_1) != 0U)
- {
- /* Disable the Tamper1 interrupt */
- hrtc->Instance->TAMPCR &= ((uint32_t)~(RTC_IT_TAMP | RTC_IT_TAMP1));
- }
- #endif /* RTC_TAMPER1_SUPPORT */
- if ((Tamper & RTC_TAMPER_2) != 0U)
- {
- /* Disable the Tamper2 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 Tamper3 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;
- }
- #endif /* #if defined(STM32L412xx) || defined(STM32L422xx) || defined (STM32L4P5xx) || defined (STM32L4Q5xx) */
- #if defined(RTC_TAMPER1_SUPPORT)
- /**
- * @brief Handle Tamper 1 Polling.
- * @param hrtc RTC handle
- * @param Timeout Timeout duration
- * @retval HAL status
- */
- HAL_StatusTypeDef HAL_RTCEx_PollForTamper1Event(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_TAMP1F) == 0U)
- {
- if (Timeout != HAL_MAX_DELAY)
- {
- if (((HAL_GetTick() - tickstart) > Timeout) || (Timeout == 0U))
- {
- 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 Handle Tamper 2 Polling.
- * @param hrtc RTC handle
- * @param Timeout Timeout duration
- * @retval HAL status
- */
- HAL_StatusTypeDef HAL_RTCEx_PollForTamper2Event(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_TAMP2F) == 0U)
- {
- if (Timeout != HAL_MAX_DELAY)
- {
- if (((HAL_GetTick() - tickstart) > Timeout) || (Timeout == 0U))
- {
- 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 Handle Tamper 3 Polling.
- * @param hrtc RTC handle
- * @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 == 0) || ((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 */
- #if defined(RTC_TAMPER1_SUPPORT)
- /**
- * @brief Tamper 1 callback.
- * @param hrtc RTC handle
- * @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 RTC handle
- * @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 RTC handle
- * @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 */
- /**
- * @}
- */
- /** @addtogroup RTCEx_Exported_Functions_Group6
- * @brief Extended RTC Backup register functions
- *
- @verbatim
- ===============================================================================
- ##### Extended RTC Backup register functions #####
- ===============================================================================
- [..]
- (+) Before calling any tamper or internal tamper function, you have to call first
- HAL_RTC_Init() function.
- (+) In that ine you can select to output tamper event on RTC pin.
- [..]
- 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
- @endverbatim
- * @{
- */
- /**
- * @brief Write a data in a specified RTC Backup data register.
- * @param hrtc RTC handle
- * @param BackupRegister RTC Backup data Register number.
- * This parameter can be: RTC_BKP_DRx where x can be from 0 to 31 to
- * specify the register.
- * @param Data Data to be written in the specified Backup data register.
- * @retval None
- */
- void HAL_RTCEx_BKUPWrite(RTC_HandleTypeDef *hrtc, uint32_t BackupRegister, uint32_t Data)
- {
- uint32_t __IO tmp;
- #if defined(STM32L412xx) || defined(STM32L422xx) || defined (STM32L4P5xx) || defined (STM32L4Q5xx)
- /* Process TAMP instance pointer */
- TAMP_TypeDef *tamp = (TAMP_TypeDef *)((uint32_t)hrtc->Instance + hrtc->TampOffset);
- /* Check the parameters */
- assert_param(IS_RTC_BKP(BackupRegister));
- tmp = (uint32_t) & (tamp->BKP0R);
- #else /* #if defined(STM32L412xx) || defined(STM32L422xx) || defined (STM32L4P5xx) || defined (STM32L4Q5xx) */
- /* Check the parameters */
- assert_param(IS_RTC_BKP(BackupRegister));
- tmp = (uint32_t) & (hrtc->Instance->BKP0R);
- #endif /* #if defined(STM32L412xx) || defined(STM32L422xx) || defined (STM32L4P5xx) || defined (STM32L4Q5xx) */
- tmp += (BackupRegister * 4U);
- /* Write the specified register */
- *(__IO uint32_t *)tmp = (uint32_t)Data;
- }
- /**
- * @brief Read data from the specified RTC Backup data Register.
- * @param hrtc RTC handle
- * @param BackupRegister RTC Backup data Register number.
- * This parameter can be: RTC_BKP_DRx where x can be from 0 to 31 to
- * specify the register.
- * @retval Read value
- */
- uint32_t HAL_RTCEx_BKUPRead(RTC_HandleTypeDef *hrtc, uint32_t BackupRegister)
- {
- uint32_t tmp;
- #if defined(STM32L412xx) || defined(STM32L422xx) || defined (STM32L4P5xx) || defined (STM32L4Q5xx)
- /* Process TAMP instance pointer */
- TAMP_TypeDef *tamp = (TAMP_TypeDef *)((uint32_t)hrtc->Instance + hrtc->TampOffset);
- /* Check the parameters */
- assert_param(IS_RTC_BKP(BackupRegister));
- tmp = (uint32_t) & (tamp->BKP0R);
- #else /* #if defined(STM32L412xx) || defined(STM32L422xx) || defined (STM32L4P5xx) || defined (STM32L4Q5xx) */
- /* Check the parameters */
- assert_param(IS_RTC_BKP(BackupRegister));
- tmp = (uint32_t) & (hrtc->Instance->BKP0R);
- #endif /* #if defined(STM32L412xx) || defined(STM32L422xx) || defined (STM32L4P5xx) || defined (STM32L4Q5xx) */
- tmp += (BackupRegister * 4U);
- /* Read the specified register */
- return (*(__IO uint32_t *)tmp);
- }
- /**
- * @}
- */
- /**
- * @}
- */
- #endif /* HAL_RTC_MODULE_ENABLED */
- /**
- * @}
- */
- /**
- * @}
- */
|