mbed library sources. Supersedes mbed-src.
Dependents: Nucleo_Hello_Encoder BLE_iBeaconScan AM1805_DEMO DISCO-F429ZI_ExportTemplate1 ... more
targets/TARGET_STM/TARGET_STM32L1/device/stm32l1xx_hal_rtc_ex.c@189:f392fc9709a3, 2019-02-20 (annotated)
- Committer:
- AnnaBridge
- Date:
- Wed Feb 20 22:31:08 2019 +0000
- Revision:
- 189:f392fc9709a3
- Parent:
- 184:08ed48f1de7f
mbed library release version 165
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
<> | 149:156823d33999 | 1 | /** |
<> | 149:156823d33999 | 2 | ****************************************************************************** |
<> | 149:156823d33999 | 3 | * @file stm32l1xx_hal_rtc_ex.c |
<> | 149:156823d33999 | 4 | * @author MCD Application Team |
<> | 149:156823d33999 | 5 | * @brief Extended RTC HAL module driver. |
<> | 149:156823d33999 | 6 | * This file provides firmware functions to manage the following |
<> | 149:156823d33999 | 7 | * functionalities of the Real Time Clock (RTC) Extension peripheral: |
<> | 149:156823d33999 | 8 | * + RTC Time Stamp functions |
<> | 149:156823d33999 | 9 | * + RTC Tamper functions |
<> | 149:156823d33999 | 10 | * + RTC Wake-up functions |
<> | 149:156823d33999 | 11 | * + Extension Control functions |
<> | 149:156823d33999 | 12 | * + Extension RTC features functions |
<> | 149:156823d33999 | 13 | * |
<> | 149:156823d33999 | 14 | @verbatim |
<> | 149:156823d33999 | 15 | ============================================================================== |
<> | 149:156823d33999 | 16 | ##### How to use this driver ##### |
<> | 149:156823d33999 | 17 | ============================================================================== |
<> | 149:156823d33999 | 18 | [..] |
<> | 149:156823d33999 | 19 | (+) Enable the RTC domain access. |
<> | 149:156823d33999 | 20 | (+) Configure the RTC Prescaler (Asynchronous and Synchronous) and RTC hour |
<> | 149:156823d33999 | 21 | format using the HAL_RTC_Init() function. |
<> | 149:156823d33999 | 22 | |
<> | 149:156823d33999 | 23 | *** RTC Wakeup configuration *** |
<> | 149:156823d33999 | 24 | ================================ |
<> | 149:156823d33999 | 25 | [..] |
<> | 149:156823d33999 | 26 | (+) To configure the RTC Wakeup Clock source and Counter use the HAL_RTCEx_SetWakeUpTimer() |
<> | 149:156823d33999 | 27 | function. You can also configure the RTC Wakeup timer with interrupt mode |
<> | 149:156823d33999 | 28 | using the HAL_RTCEx_SetWakeUpTimer_IT() function. |
<> | 149:156823d33999 | 29 | (+) To read the RTC WakeUp Counter register, use the HAL_RTCEx_GetWakeUpTimer() |
<> | 149:156823d33999 | 30 | function. |
<> | 149:156823d33999 | 31 | |
<> | 149:156823d33999 | 32 | *** TimeStamp configuration *** |
<> | 149:156823d33999 | 33 | =============================== |
<> | 149:156823d33999 | 34 | [..] |
<> | 149:156823d33999 | 35 | (+) Configure the RTC_AFx trigger and enable the RTC TimeStamp using the |
<> | 149:156823d33999 | 36 | HAL_RTCEx_SetTimeStamp() function. You can also configure the RTC TimeStamp with |
<> | 149:156823d33999 | 37 | interrupt mode using the HAL_RTCEx_SetTimeStamp_IT() function. |
<> | 149:156823d33999 | 38 | (+) To read the RTC TimeStamp Time and Date register, use the HAL_RTCEx_GetTimeStamp() |
<> | 149:156823d33999 | 39 | function. |
<> | 149:156823d33999 | 40 | (+) The TIMESTAMP alternate function can be mapped to RTC_AF1 (PC13). |
<> | 149:156823d33999 | 41 | |
<> | 149:156823d33999 | 42 | *** Tamper configuration *** |
<> | 149:156823d33999 | 43 | ============================ |
<> | 149:156823d33999 | 44 | [..] |
<> | 149:156823d33999 | 45 | (+) Enable the RTC Tamper and configure the Tamper filter count, trigger Edge |
<> | 149:156823d33999 | 46 | or Level according to the Tamper filter (if equal to 0 Edge else Level) |
<> | 149:156823d33999 | 47 | value, sampling frequency, precharge or discharge and Pull-UP using the |
<> | 149:156823d33999 | 48 | HAL_RTCEx_SetTamper() function. You can configure RTC Tamper with interrupt |
<> | 149:156823d33999 | 49 | mode using HAL_RTCEx_SetTamper_IT() function. |
<> | 149:156823d33999 | 50 | (+) The TAMPER1 alternate function can be mapped to RTC_AF1 (PC13). |
<> | 149:156823d33999 | 51 | |
<> | 149:156823d33999 | 52 | *** Backup Data Registers configuration *** |
<> | 149:156823d33999 | 53 | =========================================== |
<> | 149:156823d33999 | 54 | [..] |
<> | 149:156823d33999 | 55 | (+) To write to the RTC Backup Data registers, use the HAL_RTCEx_BKUPWrite() |
<> | 149:156823d33999 | 56 | function. |
<> | 149:156823d33999 | 57 | (+) To read the RTC Backup Data registers, use the HAL_RTCEx_BKUPRead() |
<> | 149:156823d33999 | 58 | function. |
<> | 149:156823d33999 | 59 | |
<> | 149:156823d33999 | 60 | @endverbatim |
<> | 149:156823d33999 | 61 | ****************************************************************************** |
<> | 149:156823d33999 | 62 | * @attention |
<> | 149:156823d33999 | 63 | * |
AnnaBridge | 184:08ed48f1de7f | 64 | * <h2><center>© COPYRIGHT(c) 2017 STMicroelectronics</center></h2> |
<> | 149:156823d33999 | 65 | * |
<> | 149:156823d33999 | 66 | * Redistribution and use in source and binary forms, with or without modification, |
<> | 149:156823d33999 | 67 | * are permitted provided that the following conditions are met: |
<> | 149:156823d33999 | 68 | * 1. Redistributions of source code must retain the above copyright notice, |
<> | 149:156823d33999 | 69 | * this list of conditions and the following disclaimer. |
<> | 149:156823d33999 | 70 | * 2. Redistributions in binary form must reproduce the above copyright notice, |
<> | 149:156823d33999 | 71 | * this list of conditions and the following disclaimer in the documentation |
<> | 149:156823d33999 | 72 | * and/or other materials provided with the distribution. |
<> | 149:156823d33999 | 73 | * 3. Neither the name of STMicroelectronics nor the names of its contributors |
<> | 149:156823d33999 | 74 | * may be used to endorse or promote products derived from this software |
<> | 149:156823d33999 | 75 | * without specific prior written permission. |
<> | 149:156823d33999 | 76 | * |
<> | 149:156823d33999 | 77 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
<> | 149:156823d33999 | 78 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
<> | 149:156823d33999 | 79 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
<> | 149:156823d33999 | 80 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE |
<> | 149:156823d33999 | 81 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
<> | 149:156823d33999 | 82 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |
<> | 149:156823d33999 | 83 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
<> | 149:156823d33999 | 84 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |
<> | 149:156823d33999 | 85 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
<> | 149:156823d33999 | 86 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
<> | 149:156823d33999 | 87 | * |
<> | 149:156823d33999 | 88 | ****************************************************************************** |
<> | 149:156823d33999 | 89 | */ |
<> | 149:156823d33999 | 90 | |
<> | 149:156823d33999 | 91 | /* Includes ------------------------------------------------------------------*/ |
<> | 149:156823d33999 | 92 | #include "stm32l1xx_hal.h" |
<> | 149:156823d33999 | 93 | |
<> | 149:156823d33999 | 94 | /** @addtogroup STM32L1xx_HAL_Driver |
<> | 149:156823d33999 | 95 | * @{ |
<> | 149:156823d33999 | 96 | */ |
<> | 149:156823d33999 | 97 | |
<> | 149:156823d33999 | 98 | /** @addtogroup RTC |
<> | 149:156823d33999 | 99 | * @{ |
<> | 149:156823d33999 | 100 | */ |
<> | 149:156823d33999 | 101 | |
<> | 149:156823d33999 | 102 | #ifdef HAL_RTC_MODULE_ENABLED |
<> | 149:156823d33999 | 103 | |
<> | 149:156823d33999 | 104 | /* Private typedef -----------------------------------------------------------*/ |
<> | 149:156823d33999 | 105 | /* Private define ------------------------------------------------------------*/ |
<> | 149:156823d33999 | 106 | /* Private macro -------------------------------------------------------------*/ |
<> | 149:156823d33999 | 107 | /* Private variables ---------------------------------------------------------*/ |
<> | 149:156823d33999 | 108 | /* Private function prototypes -----------------------------------------------*/ |
<> | 149:156823d33999 | 109 | /* Private functions ---------------------------------------------------------*/ |
<> | 149:156823d33999 | 110 | |
<> | 149:156823d33999 | 111 | /** @addtogroup RTC_Exported_Functions |
<> | 149:156823d33999 | 112 | * @{ |
<> | 149:156823d33999 | 113 | */ |
<> | 149:156823d33999 | 114 | |
<> | 149:156823d33999 | 115 | |
<> | 149:156823d33999 | 116 | /** @addtogroup RTC_Exported_Functions_Group1 |
<> | 149:156823d33999 | 117 | * @{ |
<> | 149:156823d33999 | 118 | */ |
<> | 149:156823d33999 | 119 | |
<> | 149:156823d33999 | 120 | /** |
<> | 149:156823d33999 | 121 | * @brief DeInitializes the RTC peripheral |
<> | 149:156823d33999 | 122 | * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains |
<> | 149:156823d33999 | 123 | * the configuration information for RTC. |
<> | 149:156823d33999 | 124 | * @note This function does not reset the RTC Backup Data registers. |
<> | 149:156823d33999 | 125 | * @retval HAL status |
<> | 149:156823d33999 | 126 | */ |
<> | 149:156823d33999 | 127 | HAL_StatusTypeDef HAL_RTC_DeInit(RTC_HandleTypeDef *hrtc) |
<> | 149:156823d33999 | 128 | { |
<> | 149:156823d33999 | 129 | uint32_t tickstart = 0; |
<> | 149:156823d33999 | 130 | |
<> | 149:156823d33999 | 131 | /* Check the parameters */ |
<> | 149:156823d33999 | 132 | assert_param(IS_RTC_ALL_INSTANCE(hrtc->Instance)); |
<> | 149:156823d33999 | 133 | |
<> | 149:156823d33999 | 134 | /* Set RTC state */ |
<> | 149:156823d33999 | 135 | hrtc->State = HAL_RTC_STATE_BUSY; |
<> | 149:156823d33999 | 136 | |
<> | 149:156823d33999 | 137 | /* Disable the write protection for RTC registers */ |
<> | 149:156823d33999 | 138 | __HAL_RTC_WRITEPROTECTION_DISABLE(hrtc); |
<> | 149:156823d33999 | 139 | |
<> | 149:156823d33999 | 140 | /* Set Initialization mode */ |
<> | 149:156823d33999 | 141 | if(RTC_EnterInitMode(hrtc) != HAL_OK) |
<> | 149:156823d33999 | 142 | { |
<> | 149:156823d33999 | 143 | /* Enable the write protection for RTC registers */ |
<> | 149:156823d33999 | 144 | __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc); |
<> | 149:156823d33999 | 145 | |
<> | 149:156823d33999 | 146 | /* Set RTC state */ |
<> | 149:156823d33999 | 147 | hrtc->State = HAL_RTC_STATE_ERROR; |
<> | 149:156823d33999 | 148 | |
<> | 149:156823d33999 | 149 | return HAL_ERROR; |
<> | 149:156823d33999 | 150 | } |
<> | 149:156823d33999 | 151 | else |
<> | 149:156823d33999 | 152 | { |
<> | 149:156823d33999 | 153 | /* Reset TR, DR and CR registers */ |
AnnaBridge | 184:08ed48f1de7f | 154 | hrtc->Instance->TR = 0x00000000U; |
AnnaBridge | 184:08ed48f1de7f | 155 | hrtc->Instance->DR = 0x00002101U; |
<> | 149:156823d33999 | 156 | /* Reset All CR bits except CR[2:0] */ |
AnnaBridge | 184:08ed48f1de7f | 157 | hrtc->Instance->CR &= 0x00000007U; |
<> | 149:156823d33999 | 158 | |
<> | 149:156823d33999 | 159 | tickstart = HAL_GetTick(); |
<> | 149:156823d33999 | 160 | |
<> | 149:156823d33999 | 161 | /* Wait till WUTWF flag is set and if Time out is reached exit */ |
<> | 149:156823d33999 | 162 | while(((hrtc->Instance->ISR) & RTC_ISR_WUTWF) == (uint32_t)RESET) |
<> | 149:156823d33999 | 163 | { |
<> | 149:156823d33999 | 164 | if((HAL_GetTick() - tickstart ) > RTC_TIMEOUT_VALUE) |
<> | 149:156823d33999 | 165 | { |
<> | 149:156823d33999 | 166 | /* Enable the write protection for RTC registers */ |
<> | 149:156823d33999 | 167 | __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc); |
<> | 149:156823d33999 | 168 | |
<> | 149:156823d33999 | 169 | /* Set RTC state */ |
<> | 149:156823d33999 | 170 | hrtc->State = HAL_RTC_STATE_TIMEOUT; |
<> | 149:156823d33999 | 171 | |
<> | 149:156823d33999 | 172 | return HAL_TIMEOUT; |
<> | 149:156823d33999 | 173 | } |
<> | 149:156823d33999 | 174 | } |
<> | 149:156823d33999 | 175 | |
<> | 149:156823d33999 | 176 | /* Reset all RTC CR register bits */ |
AnnaBridge | 184:08ed48f1de7f | 177 | hrtc->Instance->CR &= 0x00000000U; |
AnnaBridge | 184:08ed48f1de7f | 178 | hrtc->Instance->WUTR = 0x0000FFFFU; |
AnnaBridge | 184:08ed48f1de7f | 179 | hrtc->Instance->PRER = 0x007F00FFU; |
AnnaBridge | 184:08ed48f1de7f | 180 | hrtc->Instance->CALIBR = 0x00000000U; |
AnnaBridge | 184:08ed48f1de7f | 181 | hrtc->Instance->ALRMAR = 0x00000000U; |
AnnaBridge | 184:08ed48f1de7f | 182 | hrtc->Instance->ALRMBR = 0x00000000U; |
<> | 149:156823d33999 | 183 | #if defined(STM32L100xBA) || defined (STM32L151xBA) || defined (STM32L152xBA) || defined(STM32L100xC) || defined (STM32L151xC) || defined (STM32L152xC) || defined (STM32L162xC) || defined(STM32L151xCA) || defined (STM32L151xD) || defined (STM32L152xCA) || defined (STM32L152xD) || defined (STM32L162xCA) || defined (STM32L162xD) || defined(STM32L151xE) || defined(STM32L151xDX) || defined (STM32L152xE) || defined (STM32L152xDX) || defined (STM32L162xE) || defined (STM32L162xDX) |
AnnaBridge | 184:08ed48f1de7f | 184 | hrtc->Instance->SHIFTR = 0x00000000U; |
AnnaBridge | 184:08ed48f1de7f | 185 | hrtc->Instance->CALR = 0x00000000U; |
AnnaBridge | 184:08ed48f1de7f | 186 | hrtc->Instance->ALRMASSR = 0x00000000U; |
AnnaBridge | 184:08ed48f1de7f | 187 | hrtc->Instance->ALRMBSSR = 0x00000000U; |
<> | 149:156823d33999 | 188 | #endif /* STM32L100xBA || STM32L151xBA || STM32L152xBA || STM32L100xC || STM32L151xC || STM32L152xC || STM32L162xC || STM32L151xCA || STM32L151xD || STM32L152xCA || STM32L152xD || STM32L162xCA || STM32L162xD || STM32L151xE || STM32L151xDX || STM32L152xE || STM32L152xDX || STM32L162xE || STM32L162xDX */ |
<> | 149:156823d33999 | 189 | /* Reset ISR register and exit initialization mode */ |
AnnaBridge | 184:08ed48f1de7f | 190 | hrtc->Instance->ISR = 0x00000000U; |
<> | 149:156823d33999 | 191 | |
<> | 149:156823d33999 | 192 | /* Reset Tamper and alternate functions configuration register */ |
AnnaBridge | 184:08ed48f1de7f | 193 | hrtc->Instance->TAFCR = 0x00000000U; |
<> | 149:156823d33999 | 194 | |
<> | 149:156823d33999 | 195 | /* Wait for synchro */ |
<> | 149:156823d33999 | 196 | if(HAL_RTC_WaitForSynchro(hrtc) != HAL_OK) |
<> | 149:156823d33999 | 197 | { |
<> | 149:156823d33999 | 198 | /* Enable the write protection for RTC registers */ |
<> | 149:156823d33999 | 199 | __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc); |
<> | 149:156823d33999 | 200 | |
<> | 149:156823d33999 | 201 | hrtc->State = HAL_RTC_STATE_ERROR; |
<> | 149:156823d33999 | 202 | |
<> | 149:156823d33999 | 203 | return HAL_ERROR; |
<> | 149:156823d33999 | 204 | } |
<> | 149:156823d33999 | 205 | } |
<> | 149:156823d33999 | 206 | |
<> | 149:156823d33999 | 207 | /* Enable the write protection for RTC registers */ |
<> | 149:156823d33999 | 208 | __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc); |
<> | 149:156823d33999 | 209 | |
<> | 149:156823d33999 | 210 | /* De-Initialize RTC MSP */ |
<> | 149:156823d33999 | 211 | HAL_RTC_MspDeInit(hrtc); |
<> | 149:156823d33999 | 212 | |
<> | 149:156823d33999 | 213 | hrtc->State = HAL_RTC_STATE_RESET; |
<> | 149:156823d33999 | 214 | |
<> | 149:156823d33999 | 215 | /* Release Lock */ |
<> | 149:156823d33999 | 216 | __HAL_UNLOCK(hrtc); |
<> | 149:156823d33999 | 217 | |
<> | 149:156823d33999 | 218 | return HAL_OK; |
<> | 149:156823d33999 | 219 | } |
<> | 149:156823d33999 | 220 | |
<> | 149:156823d33999 | 221 | /** |
<> | 149:156823d33999 | 222 | * @} |
<> | 149:156823d33999 | 223 | */ |
<> | 149:156823d33999 | 224 | |
<> | 149:156823d33999 | 225 | /** @addtogroup RTC_Exported_Functions_Group2 |
<> | 149:156823d33999 | 226 | * @{ |
<> | 149:156823d33999 | 227 | */ |
<> | 149:156823d33999 | 228 | |
<> | 149:156823d33999 | 229 | /** |
<> | 149:156823d33999 | 230 | * @brief Get RTC current time. |
<> | 149:156823d33999 | 231 | * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains |
<> | 149:156823d33999 | 232 | * the configuration information for RTC. |
<> | 149:156823d33999 | 233 | * @param sTime: Pointer to Time structure with Hours, Minutes and Seconds fields returned |
<> | 149:156823d33999 | 234 | * with input format (BIN or BCD), also SubSeconds field (if availabale) returning the |
<> | 149:156823d33999 | 235 | * RTC_SSR register content and SecondFraction field the Synchronous pre-scaler |
<> | 149:156823d33999 | 236 | * factor to be used for second fraction ratio computation. |
<> | 149:156823d33999 | 237 | * @param Format: Specifies the format of the entered parameters. |
<> | 149:156823d33999 | 238 | * This parameter can be one of the following values: |
<> | 149:156823d33999 | 239 | * @arg RTC_FORMAT_BIN: Binary data format |
<> | 149:156823d33999 | 240 | * @arg RTC_FORMAT_BCD: BCD data format |
<> | 149:156823d33999 | 241 | * @note If available, you can use SubSeconds and SecondFraction (sTime structure fields returned) to convert SubSeconds |
<> | 149:156823d33999 | 242 | * value in second fraction ratio with time unit following generic formula: |
<> | 149:156823d33999 | 243 | * Second fraction ratio * time_unit= [(SecondFraction-SubSeconds)/(SecondFraction+1)] * time_unit |
<> | 149:156823d33999 | 244 | * This conversion can be performed only if no shift operation is pending (ie. SHFP=0) when PREDIV_S >= SS |
<> | 149:156823d33999 | 245 | * @note You must call HAL_RTC_GetDate() after HAL_RTC_GetTime() to unlock the values |
<> | 149:156823d33999 | 246 | * in the higher-order calendar shadow registers to ensure consistency between the time and date values. |
<> | 149:156823d33999 | 247 | * Reading RTC current time locks the values in calendar shadow registers until Current date is read |
<> | 149:156823d33999 | 248 | * to ensure consistency between the time and date values. |
<> | 149:156823d33999 | 249 | * @retval HAL status |
<> | 149:156823d33999 | 250 | */ |
<> | 149:156823d33999 | 251 | HAL_StatusTypeDef HAL_RTC_GetTime(RTC_HandleTypeDef *hrtc, RTC_TimeTypeDef *sTime, uint32_t Format) |
<> | 149:156823d33999 | 252 | { |
<> | 149:156823d33999 | 253 | uint32_t tmpreg = 0; |
<> | 149:156823d33999 | 254 | |
<> | 149:156823d33999 | 255 | /* Check the parameters */ |
<> | 149:156823d33999 | 256 | assert_param(IS_RTC_FORMAT(Format)); |
<> | 149:156823d33999 | 257 | |
<> | 149:156823d33999 | 258 | #if defined(STM32L100xBA) || defined (STM32L151xBA) || defined (STM32L152xBA) || defined(STM32L100xC) || defined (STM32L151xC) || defined (STM32L152xC) || defined (STM32L162xC) || defined(STM32L151xCA) || defined (STM32L151xD) || defined (STM32L152xCA) || defined (STM32L152xD) || defined (STM32L162xCA) || defined (STM32L162xD) || defined(STM32L151xE) || defined(STM32L151xDX) || defined (STM32L152xE) || defined (STM32L152xDX) || defined (STM32L162xE) || defined (STM32L162xDX) |
<> | 149:156823d33999 | 259 | /* Get subseconds structure field from the corresponding register*/ |
<> | 149:156823d33999 | 260 | sTime->SubSeconds = (uint32_t)((hrtc->Instance->SSR) & RTC_SSR_SS); |
<> | 149:156823d33999 | 261 | |
<> | 149:156823d33999 | 262 | /* Get SecondFraction structure field from the corresponding register field*/ |
<> | 149:156823d33999 | 263 | sTime->SecondFraction = (uint32_t)(hrtc->Instance->PRER & RTC_PRER_PREDIV_S); |
<> | 149:156823d33999 | 264 | #endif /* STM32L100xBA || STM32L151xBA || STM32L152xBA || STM32L100xC || STM32L151xC || STM32L152xC || STM32L162xC || STM32L151xCA || STM32L151xD || STM32L152xCA || STM32L152xD || STM32L162xCA || STM32L162xD || STM32L151xE || STM32L151xDX || STM32L152xE || STM32L152xDX || STM32L162xE || STM32L162xDX */ |
<> | 149:156823d33999 | 265 | |
<> | 149:156823d33999 | 266 | /* Get the TR register */ |
<> | 149:156823d33999 | 267 | tmpreg = (uint32_t)(hrtc->Instance->TR & RTC_TR_RESERVED_MASK); |
<> | 149:156823d33999 | 268 | |
<> | 149:156823d33999 | 269 | /* Fill the structure fields with the read parameters */ |
<> | 149:156823d33999 | 270 | sTime->Hours = (uint8_t)((tmpreg & (RTC_TR_HT | RTC_TR_HU)) >> 16); |
<> | 149:156823d33999 | 271 | sTime->Minutes = (uint8_t)((tmpreg & (RTC_TR_MNT | RTC_TR_MNU)) >>8); |
<> | 149:156823d33999 | 272 | sTime->Seconds = (uint8_t)(tmpreg & (RTC_TR_ST | RTC_TR_SU)); |
<> | 149:156823d33999 | 273 | sTime->TimeFormat = (uint8_t)((tmpreg & (RTC_TR_PM)) >> 16); |
<> | 149:156823d33999 | 274 | |
<> | 149:156823d33999 | 275 | /* Check the input parameters format */ |
<> | 149:156823d33999 | 276 | if(Format == RTC_FORMAT_BIN) |
<> | 149:156823d33999 | 277 | { |
<> | 149:156823d33999 | 278 | /* Convert the time structure parameters to Binary format */ |
<> | 149:156823d33999 | 279 | sTime->Hours = (uint8_t)RTC_Bcd2ToByte(sTime->Hours); |
<> | 149:156823d33999 | 280 | sTime->Minutes = (uint8_t)RTC_Bcd2ToByte(sTime->Minutes); |
<> | 149:156823d33999 | 281 | sTime->Seconds = (uint8_t)RTC_Bcd2ToByte(sTime->Seconds); |
<> | 149:156823d33999 | 282 | } |
<> | 149:156823d33999 | 283 | |
<> | 149:156823d33999 | 284 | return HAL_OK; |
<> | 149:156823d33999 | 285 | } |
<> | 149:156823d33999 | 286 | |
<> | 149:156823d33999 | 287 | /** |
<> | 149:156823d33999 | 288 | * @} |
<> | 149:156823d33999 | 289 | */ |
<> | 149:156823d33999 | 290 | |
<> | 149:156823d33999 | 291 | /** @addtogroup RTC_Exported_Functions_Group3 |
<> | 149:156823d33999 | 292 | * @{ |
<> | 149:156823d33999 | 293 | */ |
<> | 149:156823d33999 | 294 | |
<> | 149:156823d33999 | 295 | /** |
<> | 149:156823d33999 | 296 | * @brief Sets the specified RTC Alarm. |
<> | 149:156823d33999 | 297 | * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains |
<> | 149:156823d33999 | 298 | * the configuration information for RTC. |
<> | 149:156823d33999 | 299 | * @param sAlarm: Pointer to Alarm structure |
<> | 149:156823d33999 | 300 | * @param Format: Specifies the format of the entered parameters. |
<> | 149:156823d33999 | 301 | * This parameter can be one of the following values: |
<> | 149:156823d33999 | 302 | * @arg RTC_FORMAT_BIN: Binary data format |
<> | 149:156823d33999 | 303 | * @arg RTC_FORMAT_BCD: BCD data format |
<> | 149:156823d33999 | 304 | * @retval HAL status |
<> | 149:156823d33999 | 305 | */ |
<> | 149:156823d33999 | 306 | HAL_StatusTypeDef HAL_RTC_SetAlarm(RTC_HandleTypeDef *hrtc, RTC_AlarmTypeDef *sAlarm, uint32_t Format) |
<> | 149:156823d33999 | 307 | { |
<> | 149:156823d33999 | 308 | uint32_t tickstart = 0; |
<> | 149:156823d33999 | 309 | uint32_t tmpreg = 0; |
<> | 149:156823d33999 | 310 | |
<> | 149:156823d33999 | 311 | #if defined(STM32L100xBA) || defined (STM32L151xBA) || defined (STM32L152xBA) || defined(STM32L100xC) || defined (STM32L151xC) || defined (STM32L152xC) || defined (STM32L162xC) || defined(STM32L151xCA) || defined (STM32L151xD) || defined (STM32L152xCA) || defined (STM32L152xD) || defined (STM32L162xCA) || defined (STM32L162xD) || defined(STM32L151xE) || defined(STM32L151xDX) || defined (STM32L152xE) || defined (STM32L152xDX) || defined (STM32L162xE) || defined (STM32L162xDX) |
<> | 149:156823d33999 | 312 | uint32_t subsecondtmpreg = 0; |
<> | 149:156823d33999 | 313 | #endif /* STM32L100xBA || STM32L151xBA || STM32L152xBA || STM32L100xC || STM32L151xC || STM32L152xC || STM32L162xC || STM32L151xCA || STM32L151xD || STM32L152xCA || STM32L152xD || STM32L162xCA || STM32L162xD || STM32L151xE || STM32L151xDX || STM32L152xE || STM32L152xDX || STM32L162xE || STM32L162xDX */ |
<> | 149:156823d33999 | 314 | |
<> | 149:156823d33999 | 315 | /* Check the parameters */ |
<> | 149:156823d33999 | 316 | assert_param(IS_RTC_FORMAT(Format)); |
<> | 149:156823d33999 | 317 | assert_param(IS_RTC_ALARM(sAlarm->Alarm)); |
<> | 149:156823d33999 | 318 | assert_param(IS_RTC_ALARM_MASK(sAlarm->AlarmMask)); |
<> | 149:156823d33999 | 319 | assert_param(IS_RTC_ALARM_DATE_WEEKDAY_SEL(sAlarm->AlarmDateWeekDaySel)); |
<> | 149:156823d33999 | 320 | #if defined(STM32L100xBA) || defined (STM32L151xBA) || defined (STM32L152xBA) || defined(STM32L100xC) || defined (STM32L151xC) || defined (STM32L152xC) || defined (STM32L162xC) || defined(STM32L151xCA) || defined (STM32L151xD) || defined (STM32L152xCA) || defined (STM32L152xD) || defined (STM32L162xCA) || defined (STM32L162xD) || defined(STM32L151xE) || defined(STM32L151xDX) || defined (STM32L152xE) || defined (STM32L152xDX) || defined (STM32L162xE) || defined (STM32L162xDX) |
<> | 149:156823d33999 | 321 | assert_param(IS_RTC_ALARM_SUB_SECOND_VALUE(sAlarm->AlarmTime.SubSeconds)); |
<> | 149:156823d33999 | 322 | assert_param(IS_RTC_ALARM_SUB_SECOND_MASK(sAlarm->AlarmSubSecondMask)); |
<> | 149:156823d33999 | 323 | #endif /* STM32L100xBA || STM32L151xBA || STM32L152xBA || STM32L100xC || STM32L151xC || STM32L152xC || STM32L162xC || STM32L151xCA || STM32L151xD || STM32L152xCA || STM32L152xD || STM32L162xCA || STM32L162xD || STM32L151xE || STM32L151xDX || STM32L152xE || STM32L152xDX || STM32L162xE || STM32L162xDX */ |
<> | 149:156823d33999 | 324 | |
<> | 149:156823d33999 | 325 | /* Process Locked */ |
<> | 149:156823d33999 | 326 | __HAL_LOCK(hrtc); |
<> | 149:156823d33999 | 327 | |
<> | 149:156823d33999 | 328 | hrtc->State = HAL_RTC_STATE_BUSY; |
<> | 149:156823d33999 | 329 | |
<> | 149:156823d33999 | 330 | if(Format == RTC_FORMAT_BIN) |
<> | 149:156823d33999 | 331 | { |
<> | 149:156823d33999 | 332 | if((hrtc->Instance->CR & RTC_CR_FMT) != (uint32_t)RESET) |
<> | 149:156823d33999 | 333 | { |
<> | 149:156823d33999 | 334 | assert_param(IS_RTC_HOUR12(sAlarm->AlarmTime.Hours)); |
<> | 149:156823d33999 | 335 | assert_param(IS_RTC_HOURFORMAT12(sAlarm->AlarmTime.TimeFormat)); |
<> | 149:156823d33999 | 336 | } |
<> | 149:156823d33999 | 337 | else |
<> | 149:156823d33999 | 338 | { |
<> | 149:156823d33999 | 339 | sAlarm->AlarmTime.TimeFormat = 0x00; |
<> | 149:156823d33999 | 340 | assert_param(IS_RTC_HOUR24(sAlarm->AlarmTime.Hours)); |
<> | 149:156823d33999 | 341 | } |
<> | 149:156823d33999 | 342 | assert_param(IS_RTC_MINUTES(sAlarm->AlarmTime.Minutes)); |
<> | 149:156823d33999 | 343 | assert_param(IS_RTC_SECONDS(sAlarm->AlarmTime.Seconds)); |
<> | 149:156823d33999 | 344 | |
<> | 149:156823d33999 | 345 | if(sAlarm->AlarmDateWeekDaySel == RTC_ALARMDATEWEEKDAYSEL_DATE) |
<> | 149:156823d33999 | 346 | { |
<> | 149:156823d33999 | 347 | assert_param(IS_RTC_ALARM_DATE_WEEKDAY_DATE(sAlarm->AlarmDateWeekDay)); |
<> | 149:156823d33999 | 348 | } |
<> | 149:156823d33999 | 349 | else |
<> | 149:156823d33999 | 350 | { |
<> | 149:156823d33999 | 351 | assert_param(IS_RTC_ALARM_DATE_WEEKDAY_WEEKDAY(sAlarm->AlarmDateWeekDay)); |
<> | 149:156823d33999 | 352 | } |
<> | 149:156823d33999 | 353 | |
<> | 149:156823d33999 | 354 | tmpreg = (((uint32_t)RTC_ByteToBcd2(sAlarm->AlarmTime.Hours) << 16) | \ |
<> | 149:156823d33999 | 355 | ((uint32_t)RTC_ByteToBcd2(sAlarm->AlarmTime.Minutes) << 8) | \ |
<> | 149:156823d33999 | 356 | ((uint32_t)RTC_ByteToBcd2(sAlarm->AlarmTime.Seconds)) | \ |
<> | 149:156823d33999 | 357 | ((uint32_t)(sAlarm->AlarmTime.TimeFormat) << 16) | \ |
<> | 149:156823d33999 | 358 | ((uint32_t)RTC_ByteToBcd2(sAlarm->AlarmDateWeekDay) << 24) | \ |
<> | 149:156823d33999 | 359 | ((uint32_t)sAlarm->AlarmDateWeekDaySel) | \ |
<> | 149:156823d33999 | 360 | ((uint32_t)sAlarm->AlarmMask)); |
<> | 149:156823d33999 | 361 | } |
<> | 149:156823d33999 | 362 | else |
<> | 149:156823d33999 | 363 | { |
<> | 149:156823d33999 | 364 | if((hrtc->Instance->CR & RTC_CR_FMT) != (uint32_t)RESET) |
<> | 149:156823d33999 | 365 | { |
<> | 149:156823d33999 | 366 | tmpreg = RTC_Bcd2ToByte(sAlarm->AlarmTime.Hours); |
<> | 149:156823d33999 | 367 | assert_param(IS_RTC_HOUR12(tmpreg)); |
<> | 149:156823d33999 | 368 | assert_param(IS_RTC_HOURFORMAT12(sAlarm->AlarmTime.TimeFormat)); |
<> | 149:156823d33999 | 369 | } |
<> | 149:156823d33999 | 370 | else |
<> | 149:156823d33999 | 371 | { |
<> | 149:156823d33999 | 372 | sAlarm->AlarmTime.TimeFormat = 0x00; |
<> | 149:156823d33999 | 373 | assert_param(IS_RTC_HOUR24(RTC_Bcd2ToByte(sAlarm->AlarmTime.Hours))); |
<> | 149:156823d33999 | 374 | } |
<> | 149:156823d33999 | 375 | |
<> | 149:156823d33999 | 376 | assert_param(IS_RTC_MINUTES(RTC_Bcd2ToByte(sAlarm->AlarmTime.Minutes))); |
<> | 149:156823d33999 | 377 | assert_param(IS_RTC_SECONDS(RTC_Bcd2ToByte(sAlarm->AlarmTime.Seconds))); |
<> | 149:156823d33999 | 378 | |
<> | 149:156823d33999 | 379 | if(sAlarm->AlarmDateWeekDaySel == RTC_ALARMDATEWEEKDAYSEL_DATE) |
<> | 149:156823d33999 | 380 | { |
<> | 149:156823d33999 | 381 | tmpreg = RTC_Bcd2ToByte(sAlarm->AlarmDateWeekDay); |
<> | 149:156823d33999 | 382 | assert_param(IS_RTC_ALARM_DATE_WEEKDAY_DATE(tmpreg)); |
<> | 149:156823d33999 | 383 | } |
<> | 149:156823d33999 | 384 | else |
<> | 149:156823d33999 | 385 | { |
<> | 149:156823d33999 | 386 | tmpreg = RTC_Bcd2ToByte(sAlarm->AlarmDateWeekDay); |
<> | 149:156823d33999 | 387 | assert_param(IS_RTC_ALARM_DATE_WEEKDAY_WEEKDAY(tmpreg)); |
<> | 149:156823d33999 | 388 | } |
<> | 149:156823d33999 | 389 | |
<> | 149:156823d33999 | 390 | tmpreg = (((uint32_t)(sAlarm->AlarmTime.Hours) << 16) | \ |
<> | 149:156823d33999 | 391 | ((uint32_t)(sAlarm->AlarmTime.Minutes) << 8) | \ |
<> | 149:156823d33999 | 392 | ((uint32_t) sAlarm->AlarmTime.Seconds) | \ |
<> | 149:156823d33999 | 393 | ((uint32_t)(sAlarm->AlarmTime.TimeFormat) << 16) | \ |
<> | 149:156823d33999 | 394 | ((uint32_t)(sAlarm->AlarmDateWeekDay) << 24) | \ |
<> | 149:156823d33999 | 395 | ((uint32_t)sAlarm->AlarmDateWeekDaySel) | \ |
<> | 149:156823d33999 | 396 | ((uint32_t)sAlarm->AlarmMask)); |
<> | 149:156823d33999 | 397 | } |
<> | 149:156823d33999 | 398 | |
<> | 149:156823d33999 | 399 | #if defined(STM32L100xBA) || defined (STM32L151xBA) || defined (STM32L152xBA) || defined(STM32L100xC) || defined (STM32L151xC) || defined (STM32L152xC) || defined (STM32L162xC) || defined(STM32L151xCA) || defined (STM32L151xD) || defined (STM32L152xCA) || defined (STM32L152xD) || defined (STM32L162xCA) || defined (STM32L162xD) || defined(STM32L151xE) || defined(STM32L151xDX) || defined (STM32L152xE) || defined (STM32L152xDX) || defined (STM32L162xE) || defined (STM32L162xDX) |
<> | 149:156823d33999 | 400 | /* Configure the Alarm A or Alarm B Sub Second registers */ |
<> | 149:156823d33999 | 401 | subsecondtmpreg = (uint32_t)((uint32_t)(sAlarm->AlarmTime.SubSeconds) | (uint32_t)(sAlarm->AlarmSubSecondMask)); |
<> | 149:156823d33999 | 402 | #endif /* STM32L100xBA || STM32L151xBA || STM32L152xBA || STM32L100xC || STM32L151xC || STM32L152xC || STM32L162xC || STM32L151xCA || STM32L151xD || STM32L152xCA || STM32L152xD || STM32L162xCA || STM32L162xD || STM32L151xE || STM32L151xDX || STM32L152xE || STM32L152xDX || STM32L162xE || STM32L162xDX */ |
<> | 149:156823d33999 | 403 | |
<> | 149:156823d33999 | 404 | /* Disable the write protection for RTC registers */ |
<> | 149:156823d33999 | 405 | __HAL_RTC_WRITEPROTECTION_DISABLE(hrtc); |
<> | 149:156823d33999 | 406 | |
<> | 149:156823d33999 | 407 | /* Configure the Alarm register */ |
<> | 149:156823d33999 | 408 | if(sAlarm->Alarm == RTC_ALARM_A) |
<> | 149:156823d33999 | 409 | { |
<> | 149:156823d33999 | 410 | /* Disable the Alarm A interrupt */ |
<> | 149:156823d33999 | 411 | __HAL_RTC_ALARMA_DISABLE(hrtc); |
<> | 149:156823d33999 | 412 | |
<> | 149:156823d33999 | 413 | /* In case of interrupt mode is used, the interrupt source must disabled */ |
<> | 149:156823d33999 | 414 | __HAL_RTC_ALARM_DISABLE_IT(hrtc, RTC_IT_ALRA); |
<> | 149:156823d33999 | 415 | |
<> | 149:156823d33999 | 416 | tickstart = HAL_GetTick(); |
<> | 149:156823d33999 | 417 | /* Wait till RTC ALRAWF flag is set and if Time out is reached exit */ |
<> | 149:156823d33999 | 418 | while(__HAL_RTC_ALARM_GET_FLAG(hrtc, RTC_FLAG_ALRAWF) == RESET) |
<> | 149:156823d33999 | 419 | { |
<> | 149:156823d33999 | 420 | if((HAL_GetTick() - tickstart ) > RTC_TIMEOUT_VALUE) |
<> | 149:156823d33999 | 421 | { |
<> | 149:156823d33999 | 422 | /* Enable the write protection for RTC registers */ |
<> | 149:156823d33999 | 423 | __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc); |
<> | 149:156823d33999 | 424 | |
<> | 149:156823d33999 | 425 | hrtc->State = HAL_RTC_STATE_TIMEOUT; |
<> | 149:156823d33999 | 426 | |
<> | 149:156823d33999 | 427 | /* Process Unlocked */ |
<> | 149:156823d33999 | 428 | __HAL_UNLOCK(hrtc); |
<> | 149:156823d33999 | 429 | |
<> | 149:156823d33999 | 430 | return HAL_TIMEOUT; |
<> | 149:156823d33999 | 431 | } |
<> | 149:156823d33999 | 432 | } |
<> | 149:156823d33999 | 433 | |
<> | 149:156823d33999 | 434 | hrtc->Instance->ALRMAR = (uint32_t)tmpreg; |
<> | 149:156823d33999 | 435 | #if defined(STM32L100xBA) || defined (STM32L151xBA) || defined (STM32L152xBA) || defined(STM32L100xC) || defined (STM32L151xC) || defined (STM32L152xC) || defined (STM32L162xC) || defined(STM32L151xCA) || defined (STM32L151xD) || defined (STM32L152xCA) || defined (STM32L152xD) || defined (STM32L162xCA) || defined (STM32L162xD) || defined(STM32L151xE) || defined(STM32L151xDX) || defined (STM32L152xE) || defined (STM32L152xDX) || defined (STM32L162xE) || defined (STM32L162xDX) |
<> | 149:156823d33999 | 436 | /* Configure the Alarm A Sub Second register */ |
<> | 149:156823d33999 | 437 | hrtc->Instance->ALRMASSR = subsecondtmpreg; |
<> | 149:156823d33999 | 438 | #endif /* STM32L100xBA || STM32L151xBA || STM32L152xBA || STM32L100xC || STM32L151xC || STM32L152xC || STM32L162xC || STM32L151xCA || STM32L151xD || STM32L152xCA || STM32L152xD || STM32L162xCA || STM32L162xD || STM32L151xE || STM32L151xDX || STM32L152xE || STM32L152xDX || STM32L162xE || STM32L162xDX */ |
<> | 149:156823d33999 | 439 | /* Configure the Alarm state: Enable Alarm */ |
<> | 149:156823d33999 | 440 | __HAL_RTC_ALARMA_ENABLE(hrtc); |
<> | 149:156823d33999 | 441 | } |
<> | 149:156823d33999 | 442 | else |
<> | 149:156823d33999 | 443 | { |
<> | 149:156823d33999 | 444 | /* Disable the Alarm B interrupt */ |
<> | 149:156823d33999 | 445 | __HAL_RTC_ALARMB_DISABLE(hrtc); |
<> | 149:156823d33999 | 446 | |
<> | 149:156823d33999 | 447 | /* In case of interrupt mode is used, the interrupt source must disabled */ |
<> | 149:156823d33999 | 448 | __HAL_RTC_ALARM_DISABLE_IT(hrtc, RTC_IT_ALRB); |
<> | 149:156823d33999 | 449 | |
<> | 149:156823d33999 | 450 | tickstart = HAL_GetTick(); |
<> | 149:156823d33999 | 451 | /* Wait till RTC ALRBWF flag is set and if Time out is reached exit */ |
<> | 149:156823d33999 | 452 | while(__HAL_RTC_ALARM_GET_FLAG(hrtc, RTC_FLAG_ALRBWF) == RESET) |
<> | 149:156823d33999 | 453 | { |
<> | 149:156823d33999 | 454 | if((HAL_GetTick() - tickstart ) > RTC_TIMEOUT_VALUE) |
<> | 149:156823d33999 | 455 | { |
<> | 149:156823d33999 | 456 | /* Enable the write protection for RTC registers */ |
<> | 149:156823d33999 | 457 | __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc); |
<> | 149:156823d33999 | 458 | |
<> | 149:156823d33999 | 459 | hrtc->State = HAL_RTC_STATE_TIMEOUT; |
<> | 149:156823d33999 | 460 | |
<> | 149:156823d33999 | 461 | /* Process Unlocked */ |
<> | 149:156823d33999 | 462 | __HAL_UNLOCK(hrtc); |
<> | 149:156823d33999 | 463 | |
<> | 149:156823d33999 | 464 | return HAL_TIMEOUT; |
<> | 149:156823d33999 | 465 | } |
<> | 149:156823d33999 | 466 | } |
<> | 149:156823d33999 | 467 | |
<> | 149:156823d33999 | 468 | hrtc->Instance->ALRMBR = (uint32_t)tmpreg; |
<> | 149:156823d33999 | 469 | #if defined(STM32L100xBA) || defined (STM32L151xBA) || defined (STM32L152xBA) || defined(STM32L100xC) || defined (STM32L151xC) || defined (STM32L152xC) || defined (STM32L162xC) || defined(STM32L151xCA) || defined (STM32L151xD) || defined (STM32L152xCA) || defined (STM32L152xD) || defined (STM32L162xCA) || defined (STM32L162xD) || defined(STM32L151xE) || defined(STM32L151xDX) || defined (STM32L152xE) || defined (STM32L152xDX) || defined (STM32L162xE) || defined (STM32L162xDX) |
<> | 149:156823d33999 | 470 | /* Configure the Alarm B Sub Second register */ |
<> | 149:156823d33999 | 471 | hrtc->Instance->ALRMBSSR = subsecondtmpreg; |
<> | 149:156823d33999 | 472 | #endif /* STM32L100xBA || STM32L151xBA || STM32L152xBA || STM32L100xC || STM32L151xC || STM32L152xC || STM32L162xC || STM32L151xCA || STM32L151xD || STM32L152xCA || STM32L152xD || STM32L162xCA || STM32L162xD || STM32L151xE || STM32L151xDX || STM32L152xE || STM32L152xDX || STM32L162xE || STM32L162xDX */ |
<> | 149:156823d33999 | 473 | /* Configure the Alarm state: Enable Alarm */ |
<> | 149:156823d33999 | 474 | __HAL_RTC_ALARMB_ENABLE(hrtc); |
<> | 149:156823d33999 | 475 | } |
<> | 149:156823d33999 | 476 | |
<> | 149:156823d33999 | 477 | /* Enable the write protection for RTC registers */ |
<> | 149:156823d33999 | 478 | __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc); |
<> | 149:156823d33999 | 479 | |
<> | 149:156823d33999 | 480 | /* Change RTC state */ |
<> | 149:156823d33999 | 481 | hrtc->State = HAL_RTC_STATE_READY; |
<> | 149:156823d33999 | 482 | |
<> | 149:156823d33999 | 483 | /* Process Unlocked */ |
<> | 149:156823d33999 | 484 | __HAL_UNLOCK(hrtc); |
<> | 149:156823d33999 | 485 | |
<> | 149:156823d33999 | 486 | return HAL_OK; |
<> | 149:156823d33999 | 487 | } |
<> | 149:156823d33999 | 488 | |
<> | 149:156823d33999 | 489 | /** |
<> | 149:156823d33999 | 490 | * @brief Sets the specified RTC Alarm with Interrupt |
<> | 149:156823d33999 | 491 | * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains |
<> | 149:156823d33999 | 492 | * the configuration information for RTC. |
<> | 149:156823d33999 | 493 | * @param sAlarm: Pointer to Alarm structure |
<> | 149:156823d33999 | 494 | * @param Format: Specifies the format of the entered parameters. |
<> | 149:156823d33999 | 495 | * This parameter can be one of the following values: |
<> | 149:156823d33999 | 496 | * @arg RTC_FORMAT_BIN: Binary data format |
<> | 149:156823d33999 | 497 | * @arg RTC_FORMAT_BCD: BCD data format |
<> | 149:156823d33999 | 498 | * @note The Alarm register can only be written when the corresponding Alarm |
<> | 149:156823d33999 | 499 | * is disabled (Use the HAL_RTC_DeactivateAlarm()). |
<> | 149:156823d33999 | 500 | * @note The HAL_RTC_SetTime() must be called before enabling the Alarm feature. |
<> | 149:156823d33999 | 501 | * @retval HAL status |
<> | 149:156823d33999 | 502 | */ |
<> | 149:156823d33999 | 503 | HAL_StatusTypeDef HAL_RTC_SetAlarm_IT(RTC_HandleTypeDef *hrtc, RTC_AlarmTypeDef *sAlarm, uint32_t Format) |
<> | 149:156823d33999 | 504 | { |
<> | 149:156823d33999 | 505 | uint32_t tickstart = 0; |
<> | 149:156823d33999 | 506 | uint32_t tmpreg = 0; |
<> | 149:156823d33999 | 507 | #if defined(STM32L100xBA) || defined (STM32L151xBA) || defined (STM32L152xBA) || defined(STM32L100xC) || defined (STM32L151xC) || defined (STM32L152xC) || defined (STM32L162xC) || defined(STM32L151xCA) || defined (STM32L151xD) || defined (STM32L152xCA) || defined (STM32L152xD) || defined (STM32L162xCA) || defined (STM32L162xD) || defined(STM32L151xE) || defined(STM32L151xDX) || defined (STM32L152xE) || defined (STM32L152xDX) || defined (STM32L162xE) || defined (STM32L162xDX) |
<> | 149:156823d33999 | 508 | uint32_t subsecondtmpreg = 0; |
<> | 149:156823d33999 | 509 | #endif /* STM32L100xBA || STM32L151xBA || STM32L152xBA || STM32L100xC || STM32L151xC || STM32L152xC || STM32L162xC || STM32L151xCA || STM32L151xD || STM32L152xCA || STM32L152xD || STM32L162xCA || STM32L162xD || STM32L151xE || STM32L151xDX || STM32L152xE || STM32L152xDX || STM32L162xE || STM32L162xDX */ |
<> | 149:156823d33999 | 510 | |
<> | 149:156823d33999 | 511 | /* Check the parameters */ |
<> | 149:156823d33999 | 512 | assert_param(IS_RTC_FORMAT(Format)); |
<> | 149:156823d33999 | 513 | assert_param(IS_RTC_ALARM(sAlarm->Alarm)); |
<> | 149:156823d33999 | 514 | assert_param(IS_RTC_ALARM_MASK(sAlarm->AlarmMask)); |
<> | 149:156823d33999 | 515 | assert_param(IS_RTC_ALARM_DATE_WEEKDAY_SEL(sAlarm->AlarmDateWeekDaySel)); |
<> | 149:156823d33999 | 516 | #if defined(STM32L100xBA) || defined (STM32L151xBA) || defined (STM32L152xBA) || defined(STM32L100xC) || defined (STM32L151xC) || defined (STM32L152xC) || defined (STM32L162xC) || defined(STM32L151xCA) || defined (STM32L151xD) || defined (STM32L152xCA) || defined (STM32L152xD) || defined (STM32L162xCA) || defined (STM32L162xD) || defined(STM32L151xE) || defined(STM32L151xDX) || defined (STM32L152xE) || defined (STM32L152xDX) || defined (STM32L162xE) || defined (STM32L162xDX) |
<> | 149:156823d33999 | 517 | assert_param(IS_RTC_ALARM_SUB_SECOND_VALUE(sAlarm->AlarmTime.SubSeconds)); |
<> | 149:156823d33999 | 518 | assert_param(IS_RTC_ALARM_SUB_SECOND_MASK(sAlarm->AlarmSubSecondMask)); |
<> | 149:156823d33999 | 519 | #endif /* STM32L100xBA || STM32L151xBA || STM32L152xBA || STM32L100xC || STM32L151xC || STM32L152xC || STM32L162xC || STM32L151xCA || STM32L151xD || STM32L152xCA || STM32L152xD || STM32L162xCA || STM32L162xD || STM32L151xE || STM32L151xDX || STM32L152xE || STM32L152xDX || STM32L162xE || STM32L162xDX */ |
<> | 149:156823d33999 | 520 | |
<> | 149:156823d33999 | 521 | /* Process Locked */ |
<> | 149:156823d33999 | 522 | __HAL_LOCK(hrtc); |
<> | 149:156823d33999 | 523 | |
<> | 149:156823d33999 | 524 | hrtc->State = HAL_RTC_STATE_BUSY; |
<> | 149:156823d33999 | 525 | |
<> | 149:156823d33999 | 526 | if(Format == RTC_FORMAT_BIN) |
<> | 149:156823d33999 | 527 | { |
<> | 149:156823d33999 | 528 | if((hrtc->Instance->CR & RTC_CR_FMT) != (uint32_t)RESET) |
<> | 149:156823d33999 | 529 | { |
<> | 149:156823d33999 | 530 | assert_param(IS_RTC_HOUR12(sAlarm->AlarmTime.Hours)); |
<> | 149:156823d33999 | 531 | assert_param(IS_RTC_HOURFORMAT12(sAlarm->AlarmTime.TimeFormat)); |
<> | 149:156823d33999 | 532 | } |
<> | 149:156823d33999 | 533 | else |
<> | 149:156823d33999 | 534 | { |
<> | 149:156823d33999 | 535 | sAlarm->AlarmTime.TimeFormat = 0x00; |
<> | 149:156823d33999 | 536 | assert_param(IS_RTC_HOUR24(sAlarm->AlarmTime.Hours)); |
<> | 149:156823d33999 | 537 | } |
<> | 149:156823d33999 | 538 | assert_param(IS_RTC_MINUTES(sAlarm->AlarmTime.Minutes)); |
<> | 149:156823d33999 | 539 | assert_param(IS_RTC_SECONDS(sAlarm->AlarmTime.Seconds)); |
<> | 149:156823d33999 | 540 | |
<> | 149:156823d33999 | 541 | if(sAlarm->AlarmDateWeekDaySel == RTC_ALARMDATEWEEKDAYSEL_DATE) |
<> | 149:156823d33999 | 542 | { |
<> | 149:156823d33999 | 543 | assert_param(IS_RTC_ALARM_DATE_WEEKDAY_DATE(sAlarm->AlarmDateWeekDay)); |
<> | 149:156823d33999 | 544 | } |
<> | 149:156823d33999 | 545 | else |
<> | 149:156823d33999 | 546 | { |
<> | 149:156823d33999 | 547 | assert_param(IS_RTC_ALARM_DATE_WEEKDAY_WEEKDAY(sAlarm->AlarmDateWeekDay)); |
<> | 149:156823d33999 | 548 | } |
<> | 149:156823d33999 | 549 | tmpreg = (((uint32_t)RTC_ByteToBcd2(sAlarm->AlarmTime.Hours) << 16) | \ |
<> | 149:156823d33999 | 550 | ((uint32_t)RTC_ByteToBcd2(sAlarm->AlarmTime.Minutes) << 8) | \ |
<> | 149:156823d33999 | 551 | ((uint32_t)RTC_ByteToBcd2(sAlarm->AlarmTime.Seconds)) | \ |
<> | 149:156823d33999 | 552 | ((uint32_t)(sAlarm->AlarmTime.TimeFormat) << 16) | \ |
<> | 149:156823d33999 | 553 | ((uint32_t)RTC_ByteToBcd2(sAlarm->AlarmDateWeekDay) << 24) | \ |
<> | 149:156823d33999 | 554 | ((uint32_t)sAlarm->AlarmDateWeekDaySel) | \ |
<> | 149:156823d33999 | 555 | ((uint32_t)sAlarm->AlarmMask)); |
<> | 149:156823d33999 | 556 | } |
<> | 149:156823d33999 | 557 | else |
<> | 149:156823d33999 | 558 | { |
<> | 149:156823d33999 | 559 | if((hrtc->Instance->CR & RTC_CR_FMT) != (uint32_t)RESET) |
<> | 149:156823d33999 | 560 | { |
<> | 149:156823d33999 | 561 | tmpreg = RTC_Bcd2ToByte(sAlarm->AlarmTime.Hours); |
<> | 149:156823d33999 | 562 | assert_param(IS_RTC_HOUR12(tmpreg)); |
<> | 149:156823d33999 | 563 | assert_param(IS_RTC_HOURFORMAT12(sAlarm->AlarmTime.TimeFormat)); |
<> | 149:156823d33999 | 564 | } |
<> | 149:156823d33999 | 565 | else |
<> | 149:156823d33999 | 566 | { |
<> | 149:156823d33999 | 567 | sAlarm->AlarmTime.TimeFormat = 0x00; |
<> | 149:156823d33999 | 568 | assert_param(IS_RTC_HOUR24(RTC_Bcd2ToByte(sAlarm->AlarmTime.Hours))); |
<> | 149:156823d33999 | 569 | } |
<> | 149:156823d33999 | 570 | |
<> | 149:156823d33999 | 571 | assert_param(IS_RTC_MINUTES(RTC_Bcd2ToByte(sAlarm->AlarmTime.Minutes))); |
<> | 149:156823d33999 | 572 | assert_param(IS_RTC_SECONDS(RTC_Bcd2ToByte(sAlarm->AlarmTime.Seconds))); |
<> | 149:156823d33999 | 573 | |
<> | 149:156823d33999 | 574 | if(sAlarm->AlarmDateWeekDaySel == RTC_ALARMDATEWEEKDAYSEL_DATE) |
<> | 149:156823d33999 | 575 | { |
<> | 149:156823d33999 | 576 | tmpreg = RTC_Bcd2ToByte(sAlarm->AlarmDateWeekDay); |
<> | 149:156823d33999 | 577 | assert_param(IS_RTC_ALARM_DATE_WEEKDAY_DATE(tmpreg)); |
<> | 149:156823d33999 | 578 | } |
<> | 149:156823d33999 | 579 | else |
<> | 149:156823d33999 | 580 | { |
<> | 149:156823d33999 | 581 | tmpreg = RTC_Bcd2ToByte(sAlarm->AlarmDateWeekDay); |
<> | 149:156823d33999 | 582 | assert_param(IS_RTC_ALARM_DATE_WEEKDAY_WEEKDAY(tmpreg)); |
<> | 149:156823d33999 | 583 | } |
<> | 149:156823d33999 | 584 | tmpreg = (((uint32_t)(sAlarm->AlarmTime.Hours) << 16) | \ |
<> | 149:156823d33999 | 585 | ((uint32_t)(sAlarm->AlarmTime.Minutes) << 8) | \ |
<> | 149:156823d33999 | 586 | ((uint32_t) sAlarm->AlarmTime.Seconds) | \ |
<> | 149:156823d33999 | 587 | ((uint32_t)(sAlarm->AlarmTime.TimeFormat) << 16) | \ |
<> | 149:156823d33999 | 588 | ((uint32_t)(sAlarm->AlarmDateWeekDay) << 24) | \ |
<> | 149:156823d33999 | 589 | ((uint32_t)sAlarm->AlarmDateWeekDaySel) | \ |
<> | 149:156823d33999 | 590 | ((uint32_t)sAlarm->AlarmMask)); |
<> | 149:156823d33999 | 591 | } |
<> | 149:156823d33999 | 592 | #if defined(STM32L100xBA) || defined (STM32L151xBA) || defined (STM32L152xBA) || defined(STM32L100xC) || defined (STM32L151xC) || defined (STM32L152xC) || defined (STM32L162xC) || defined(STM32L151xCA) || defined (STM32L151xD) || defined (STM32L152xCA) || defined (STM32L152xD) || defined (STM32L162xCA) || defined (STM32L162xD) || defined(STM32L151xE) || defined(STM32L151xDX) || defined (STM32L152xE) || defined (STM32L152xDX) || defined (STM32L162xE) || defined (STM32L162xDX) |
<> | 149:156823d33999 | 593 | /* Configure the Alarm A or Alarm B Sub Second registers */ |
<> | 149:156823d33999 | 594 | subsecondtmpreg = (uint32_t)((uint32_t)(sAlarm->AlarmTime.SubSeconds) | (uint32_t)(sAlarm->AlarmSubSecondMask)); |
<> | 149:156823d33999 | 595 | #endif /* STM32L100xBA || STM32L151xBA || STM32L152xBA || STM32L100xC || STM32L151xC || STM32L152xC || STM32L162xC || STM32L151xCA || STM32L151xD || STM32L152xCA || STM32L152xD || STM32L162xCA || STM32L162xD || STM32L151xE || STM32L151xDX || STM32L152xE || STM32L152xDX || STM32L162xE || STM32L162xDX */ |
<> | 149:156823d33999 | 596 | |
<> | 149:156823d33999 | 597 | /* Disable the write protection for RTC registers */ |
<> | 149:156823d33999 | 598 | __HAL_RTC_WRITEPROTECTION_DISABLE(hrtc); |
<> | 149:156823d33999 | 599 | |
<> | 149:156823d33999 | 600 | /* Configure the Alarm register */ |
<> | 149:156823d33999 | 601 | if(sAlarm->Alarm == RTC_ALARM_A) |
<> | 149:156823d33999 | 602 | { |
<> | 149:156823d33999 | 603 | /* Disable the Alarm A interrupt */ |
<> | 149:156823d33999 | 604 | __HAL_RTC_ALARMA_DISABLE(hrtc); |
<> | 149:156823d33999 | 605 | |
<> | 149:156823d33999 | 606 | /* Clear flag alarm A */ |
<> | 149:156823d33999 | 607 | __HAL_RTC_ALARM_CLEAR_FLAG(hrtc, RTC_FLAG_ALRAF); |
<> | 149:156823d33999 | 608 | |
<> | 149:156823d33999 | 609 | tickstart = HAL_GetTick(); |
<> | 149:156823d33999 | 610 | /* Wait till RTC ALRAWF flag is set and if Time out is reached exit */ |
<> | 149:156823d33999 | 611 | while(__HAL_RTC_ALARM_GET_FLAG(hrtc, RTC_FLAG_ALRAWF) == RESET) |
<> | 149:156823d33999 | 612 | { |
<> | 149:156823d33999 | 613 | if((HAL_GetTick() - tickstart ) > RTC_TIMEOUT_VALUE) |
<> | 149:156823d33999 | 614 | { |
<> | 149:156823d33999 | 615 | /* Enable the write protection for RTC registers */ |
<> | 149:156823d33999 | 616 | __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc); |
<> | 149:156823d33999 | 617 | |
<> | 149:156823d33999 | 618 | hrtc->State = HAL_RTC_STATE_TIMEOUT; |
<> | 149:156823d33999 | 619 | |
<> | 149:156823d33999 | 620 | /* Process Unlocked */ |
<> | 149:156823d33999 | 621 | __HAL_UNLOCK(hrtc); |
<> | 149:156823d33999 | 622 | |
<> | 149:156823d33999 | 623 | return HAL_TIMEOUT; |
<> | 149:156823d33999 | 624 | } |
<> | 149:156823d33999 | 625 | } |
<> | 149:156823d33999 | 626 | |
<> | 149:156823d33999 | 627 | hrtc->Instance->ALRMAR = (uint32_t)tmpreg; |
<> | 149:156823d33999 | 628 | #if defined(STM32L100xBA) || defined (STM32L151xBA) || defined (STM32L152xBA) || defined(STM32L100xC) || defined (STM32L151xC) || defined (STM32L152xC) || defined (STM32L162xC) || defined(STM32L151xCA) || defined (STM32L151xD) || defined (STM32L152xCA) || defined (STM32L152xD) || defined (STM32L162xCA) || defined (STM32L162xD) || defined(STM32L151xE) || defined(STM32L151xDX) || defined (STM32L152xE) || defined (STM32L152xDX) || defined (STM32L162xE) || defined (STM32L162xDX) |
<> | 149:156823d33999 | 629 | /* Configure the Alarm A Sub Second register */ |
<> | 149:156823d33999 | 630 | hrtc->Instance->ALRMASSR = subsecondtmpreg; |
<> | 149:156823d33999 | 631 | #endif /* STM32L100xBA || STM32L151xBA || STM32L152xBA || STM32L100xC || STM32L151xC || STM32L152xC || STM32L162xC || STM32L151xCA || STM32L151xD || STM32L152xCA || STM32L152xD || STM32L162xCA || STM32L162xD || STM32L151xE || STM32L151xDX || STM32L152xE || STM32L152xDX || STM32L162xE || STM32L162xDX */ |
<> | 149:156823d33999 | 632 | /* Configure the Alarm state: Enable Alarm */ |
<> | 149:156823d33999 | 633 | __HAL_RTC_ALARMA_ENABLE(hrtc); |
<> | 149:156823d33999 | 634 | /* Configure the Alarm interrupt */ |
<> | 149:156823d33999 | 635 | __HAL_RTC_ALARM_ENABLE_IT(hrtc,RTC_IT_ALRA); |
<> | 149:156823d33999 | 636 | } |
<> | 149:156823d33999 | 637 | else |
<> | 149:156823d33999 | 638 | { |
<> | 149:156823d33999 | 639 | /* Disable the Alarm B interrupt */ |
<> | 149:156823d33999 | 640 | __HAL_RTC_ALARMB_DISABLE(hrtc); |
<> | 149:156823d33999 | 641 | |
<> | 149:156823d33999 | 642 | /* Clear flag alarm B */ |
<> | 149:156823d33999 | 643 | __HAL_RTC_ALARM_CLEAR_FLAG(hrtc, RTC_FLAG_ALRBF); |
<> | 149:156823d33999 | 644 | |
<> | 149:156823d33999 | 645 | tickstart = HAL_GetTick(); |
<> | 149:156823d33999 | 646 | /* Wait till RTC ALRBWF flag is set and if Time out is reached exit */ |
<> | 149:156823d33999 | 647 | while(__HAL_RTC_ALARM_GET_FLAG(hrtc, RTC_FLAG_ALRBWF) == RESET) |
<> | 149:156823d33999 | 648 | { |
<> | 149:156823d33999 | 649 | if((HAL_GetTick() - tickstart ) > RTC_TIMEOUT_VALUE) |
<> | 149:156823d33999 | 650 | { |
<> | 149:156823d33999 | 651 | /* Enable the write protection for RTC registers */ |
<> | 149:156823d33999 | 652 | __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc); |
<> | 149:156823d33999 | 653 | |
<> | 149:156823d33999 | 654 | hrtc->State = HAL_RTC_STATE_TIMEOUT; |
<> | 149:156823d33999 | 655 | |
<> | 149:156823d33999 | 656 | /* Process Unlocked */ |
<> | 149:156823d33999 | 657 | __HAL_UNLOCK(hrtc); |
<> | 149:156823d33999 | 658 | |
<> | 149:156823d33999 | 659 | return HAL_TIMEOUT; |
<> | 149:156823d33999 | 660 | } |
<> | 149:156823d33999 | 661 | } |
<> | 149:156823d33999 | 662 | |
<> | 149:156823d33999 | 663 | hrtc->Instance->ALRMBR = (uint32_t)tmpreg; |
<> | 149:156823d33999 | 664 | #if defined(STM32L100xBA) || defined (STM32L151xBA) || defined (STM32L152xBA) || defined(STM32L100xC) || defined (STM32L151xC) || defined (STM32L152xC) || defined (STM32L162xC) || defined(STM32L151xCA) || defined (STM32L151xD) || defined (STM32L152xCA) || defined (STM32L152xD) || defined (STM32L162xCA) || defined (STM32L162xD) || defined(STM32L151xE) || defined(STM32L151xDX) || defined (STM32L152xE) || defined (STM32L152xDX) || defined (STM32L162xE) || defined (STM32L162xDX) |
<> | 149:156823d33999 | 665 | /* Configure the Alarm B Sub Second register */ |
<> | 149:156823d33999 | 666 | hrtc->Instance->ALRMBSSR = subsecondtmpreg; |
<> | 149:156823d33999 | 667 | #endif /* STM32L100xBA || STM32L151xBA || STM32L152xBA || STM32L100xC || STM32L151xC || STM32L152xC || STM32L162xC || STM32L151xCA || STM32L151xD || STM32L152xCA || STM32L152xD || STM32L162xCA || STM32L162xD || STM32L151xE || STM32L151xDX || STM32L152xE || STM32L152xDX || STM32L162xE || STM32L162xDX */ |
<> | 149:156823d33999 | 668 | /* Configure the Alarm state: Enable Alarm */ |
<> | 149:156823d33999 | 669 | __HAL_RTC_ALARMB_ENABLE(hrtc); |
<> | 149:156823d33999 | 670 | /* Configure the Alarm interrupt */ |
<> | 149:156823d33999 | 671 | __HAL_RTC_ALARM_ENABLE_IT(hrtc, RTC_IT_ALRB); |
<> | 149:156823d33999 | 672 | } |
<> | 149:156823d33999 | 673 | |
<> | 149:156823d33999 | 674 | /* RTC Alarm Interrupt Configuration: EXTI configuration */ |
<> | 149:156823d33999 | 675 | __HAL_RTC_ALARM_EXTI_ENABLE_IT(); |
<> | 149:156823d33999 | 676 | |
<> | 149:156823d33999 | 677 | __HAL_RTC_ALARM_EXTI_ENABLE_RISING_EDGE(); |
<> | 149:156823d33999 | 678 | |
<> | 149:156823d33999 | 679 | /* Enable the write protection for RTC registers */ |
<> | 149:156823d33999 | 680 | __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc); |
<> | 149:156823d33999 | 681 | |
<> | 149:156823d33999 | 682 | hrtc->State = HAL_RTC_STATE_READY; |
<> | 149:156823d33999 | 683 | |
<> | 149:156823d33999 | 684 | /* Process Unlocked */ |
<> | 149:156823d33999 | 685 | __HAL_UNLOCK(hrtc); |
<> | 149:156823d33999 | 686 | |
<> | 149:156823d33999 | 687 | return HAL_OK; |
<> | 149:156823d33999 | 688 | } |
<> | 149:156823d33999 | 689 | |
<> | 149:156823d33999 | 690 | /** |
<> | 149:156823d33999 | 691 | * @brief Gets the RTC Alarm value and masks. |
<> | 149:156823d33999 | 692 | * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains |
<> | 149:156823d33999 | 693 | * the configuration information for RTC. |
<> | 149:156823d33999 | 694 | * @param sAlarm: Pointer to Date structure |
<> | 149:156823d33999 | 695 | * @param Alarm: Specifies the Alarm. |
<> | 149:156823d33999 | 696 | * This parameter can be one of the following values: |
<> | 149:156823d33999 | 697 | * @arg RTC_ALARM_A: AlarmA |
<> | 149:156823d33999 | 698 | * @arg RTC_ALARM_B: AlarmB |
<> | 149:156823d33999 | 699 | * @param Format: Specifies the format of the entered parameters. |
<> | 149:156823d33999 | 700 | * This parameter can be one of the following values: |
<> | 149:156823d33999 | 701 | * @arg RTC_FORMAT_BIN: Binary data format |
<> | 149:156823d33999 | 702 | * @arg RTC_FORMAT_BCD: BCD data format |
<> | 149:156823d33999 | 703 | * @retval HAL status |
<> | 149:156823d33999 | 704 | */ |
<> | 149:156823d33999 | 705 | HAL_StatusTypeDef HAL_RTC_GetAlarm(RTC_HandleTypeDef *hrtc, RTC_AlarmTypeDef *sAlarm, uint32_t Alarm, uint32_t Format) |
<> | 149:156823d33999 | 706 | { |
<> | 149:156823d33999 | 707 | uint32_t tmpreg = 0; |
<> | 149:156823d33999 | 708 | #if defined(STM32L100xBA) || defined (STM32L151xBA) || defined (STM32L152xBA) || defined(STM32L100xC) || defined (STM32L151xC) || defined (STM32L152xC) || defined (STM32L162xC) || defined(STM32L151xCA) || defined (STM32L151xD) || defined (STM32L152xCA) || defined (STM32L152xD) || defined (STM32L162xCA) || defined (STM32L162xD) || defined(STM32L151xE) || defined(STM32L151xDX) || defined (STM32L152xE) || defined (STM32L152xDX) || defined (STM32L162xE) || defined (STM32L162xDX) |
<> | 149:156823d33999 | 709 | uint32_t subsecondtmpreg = 0; |
<> | 149:156823d33999 | 710 | #endif /* STM32L100xBA || STM32L151xBA || STM32L152xBA || STM32L100xC || STM32L151xC || STM32L152xC || STM32L162xC || STM32L151xCA || STM32L151xD || STM32L152xCA || STM32L152xD || STM32L162xCA || STM32L162xD || STM32L151xE || STM32L151xDX || STM32L152xE || STM32L152xDX || STM32L162xE || STM32L162xDX */ |
<> | 149:156823d33999 | 711 | |
<> | 149:156823d33999 | 712 | /* Check the parameters */ |
<> | 149:156823d33999 | 713 | assert_param(IS_RTC_FORMAT(Format)); |
<> | 149:156823d33999 | 714 | assert_param(IS_RTC_ALARM(Alarm)); |
<> | 149:156823d33999 | 715 | |
<> | 149:156823d33999 | 716 | if(Alarm == RTC_ALARM_A) |
<> | 149:156823d33999 | 717 | { |
<> | 149:156823d33999 | 718 | /* AlarmA */ |
<> | 149:156823d33999 | 719 | sAlarm->Alarm = RTC_ALARM_A; |
<> | 149:156823d33999 | 720 | |
<> | 149:156823d33999 | 721 | tmpreg = (uint32_t)(hrtc->Instance->ALRMAR); |
<> | 149:156823d33999 | 722 | #if defined(STM32L100xBA) || defined (STM32L151xBA) || defined (STM32L152xBA) || defined(STM32L100xC) || defined (STM32L151xC) || defined (STM32L152xC) || defined (STM32L162xC) || defined(STM32L151xCA) || defined (STM32L151xD) || defined (STM32L152xCA) || defined (STM32L152xD) || defined (STM32L162xCA) || defined (STM32L162xD) || defined(STM32L151xE) || defined(STM32L151xDX) || defined (STM32L152xE) || defined (STM32L152xDX) || defined (STM32L162xE) || defined (STM32L162xDX) |
<> | 149:156823d33999 | 723 | subsecondtmpreg = (uint32_t)((hrtc->Instance->ALRMASSR) & RTC_ALRMASSR_SS); |
<> | 149:156823d33999 | 724 | #endif /* STM32L100xBA || STM32L151xBA || STM32L152xBA || STM32L100xC || STM32L151xC || STM32L152xC || STM32L162xC || STM32L151xCA || STM32L151xD || STM32L152xCA || STM32L152xD || STM32L162xCA || STM32L162xD || STM32L151xE || STM32L151xDX || STM32L152xE || STM32L152xDX || STM32L162xE || STM32L162xDX */ |
<> | 149:156823d33999 | 725 | } |
<> | 149:156823d33999 | 726 | else |
<> | 149:156823d33999 | 727 | { |
<> | 149:156823d33999 | 728 | sAlarm->Alarm = RTC_ALARM_B; |
<> | 149:156823d33999 | 729 | |
<> | 149:156823d33999 | 730 | tmpreg = (uint32_t)(hrtc->Instance->ALRMBR); |
<> | 149:156823d33999 | 731 | #if defined(STM32L100xBA) || defined (STM32L151xBA) || defined (STM32L152xBA) || defined(STM32L100xC) || defined (STM32L151xC) || defined (STM32L152xC) || defined (STM32L162xC) || defined(STM32L151xCA) || defined (STM32L151xD) || defined (STM32L152xCA) || defined (STM32L152xD) || defined (STM32L162xCA) || defined (STM32L162xD) || defined(STM32L151xE) || defined(STM32L151xDX) || defined (STM32L152xE) || defined (STM32L152xDX) || defined (STM32L162xE) || defined (STM32L162xDX) |
<> | 149:156823d33999 | 732 | subsecondtmpreg = (uint32_t)((hrtc->Instance->ALRMBSSR) & RTC_ALRMBSSR_SS); |
<> | 149:156823d33999 | 733 | #endif /* STM32L100xBA || STM32L151xBA || STM32L152xBA || STM32L100xC || STM32L151xC || STM32L152xC || STM32L162xC || STM32L151xCA || STM32L151xD || STM32L152xCA || STM32L152xD || STM32L162xCA || STM32L162xD || STM32L151xE || STM32L151xDX || STM32L152xE || STM32L152xDX || STM32L162xE || STM32L162xDX */ |
<> | 149:156823d33999 | 734 | } |
<> | 149:156823d33999 | 735 | |
<> | 149:156823d33999 | 736 | /* Fill the structure with the read parameters */ |
<> | 149:156823d33999 | 737 | sAlarm->AlarmTime.Hours = (uint32_t)((tmpreg & (RTC_ALRMAR_HT | RTC_ALRMAR_HU)) >> 16); |
<> | 149:156823d33999 | 738 | sAlarm->AlarmTime.Minutes = (uint32_t)((tmpreg & (RTC_ALRMAR_MNT | RTC_ALRMAR_MNU)) >> 8); |
<> | 149:156823d33999 | 739 | sAlarm->AlarmTime.Seconds = (uint32_t)(tmpreg & (RTC_ALRMAR_ST | RTC_ALRMAR_SU)); |
<> | 149:156823d33999 | 740 | sAlarm->AlarmTime.TimeFormat = (uint32_t)((tmpreg & RTC_ALRMAR_PM) >> 16); |
<> | 149:156823d33999 | 741 | #if defined(STM32L100xBA) || defined (STM32L151xBA) || defined (STM32L152xBA) || defined(STM32L100xC) || defined (STM32L151xC) || defined (STM32L152xC) || defined (STM32L162xC) || defined(STM32L151xCA) || defined (STM32L151xD) || defined (STM32L152xCA) || defined (STM32L152xD) || defined (STM32L162xCA) || defined (STM32L162xD) || defined(STM32L151xE) || defined(STM32L151xDX) || defined (STM32L152xE) || defined (STM32L152xDX) || defined (STM32L162xE) || defined (STM32L162xDX) |
<> | 149:156823d33999 | 742 | sAlarm->AlarmTime.SubSeconds = (uint32_t) subsecondtmpreg; |
<> | 149:156823d33999 | 743 | #endif /* STM32L100xBA || STM32L151xBA || STM32L152xBA || STM32L100xC || STM32L151xC || STM32L152xC || STM32L162xC || STM32L151xCA || STM32L151xD || STM32L152xCA || STM32L152xD || STM32L162xCA || STM32L162xD || STM32L151xE || STM32L151xDX || STM32L152xE || STM32L152xDX || STM32L162xE || STM32L162xDX */ |
<> | 149:156823d33999 | 744 | sAlarm->AlarmDateWeekDay = (uint32_t)((tmpreg & (RTC_ALRMAR_DT | RTC_ALRMAR_DU)) >> 24); |
<> | 149:156823d33999 | 745 | sAlarm->AlarmDateWeekDaySel = (uint32_t)(tmpreg & RTC_ALRMAR_WDSEL); |
<> | 149:156823d33999 | 746 | sAlarm->AlarmMask = (uint32_t)(tmpreg & RTC_ALARMMASK_ALL); |
<> | 149:156823d33999 | 747 | |
<> | 149:156823d33999 | 748 | if(Format == RTC_FORMAT_BIN) |
<> | 149:156823d33999 | 749 | { |
<> | 149:156823d33999 | 750 | sAlarm->AlarmTime.Hours = RTC_Bcd2ToByte(sAlarm->AlarmTime.Hours); |
<> | 149:156823d33999 | 751 | sAlarm->AlarmTime.Minutes = RTC_Bcd2ToByte(sAlarm->AlarmTime.Minutes); |
<> | 149:156823d33999 | 752 | sAlarm->AlarmTime.Seconds = RTC_Bcd2ToByte(sAlarm->AlarmTime.Seconds); |
<> | 149:156823d33999 | 753 | sAlarm->AlarmDateWeekDay = RTC_Bcd2ToByte(sAlarm->AlarmDateWeekDay); |
<> | 149:156823d33999 | 754 | } |
<> | 149:156823d33999 | 755 | |
<> | 149:156823d33999 | 756 | return HAL_OK; |
<> | 149:156823d33999 | 757 | } |
<> | 149:156823d33999 | 758 | |
<> | 149:156823d33999 | 759 | /** |
<> | 149:156823d33999 | 760 | * @} |
<> | 149:156823d33999 | 761 | */ |
<> | 149:156823d33999 | 762 | |
<> | 149:156823d33999 | 763 | |
<> | 149:156823d33999 | 764 | /** @defgroup RTC_Exported_Functions_Group6 Peripheral Control functions |
<> | 149:156823d33999 | 765 | * @brief Peripheral Control functions |
<> | 149:156823d33999 | 766 | * |
<> | 149:156823d33999 | 767 | @verbatim |
<> | 149:156823d33999 | 768 | =============================================================================== |
<> | 149:156823d33999 | 769 | ##### Peripheral Control functions ##### |
<> | 149:156823d33999 | 770 | =============================================================================== |
<> | 149:156823d33999 | 771 | [..] |
<> | 149:156823d33999 | 772 | This subsection provides functions allowing to |
<> | 149:156823d33999 | 773 | (+) Wait for RTC Time and Date Synchronization |
<> | 149:156823d33999 | 774 | |
<> | 149:156823d33999 | 775 | @endverbatim |
<> | 149:156823d33999 | 776 | * @{ |
<> | 149:156823d33999 | 777 | */ |
<> | 149:156823d33999 | 778 | |
<> | 149:156823d33999 | 779 | /** |
<> | 149:156823d33999 | 780 | * @brief Waits until the RTC Time and Date registers (RTC_TR and RTC_DR) are |
<> | 149:156823d33999 | 781 | * synchronized with RTC APB clock. |
<> | 149:156823d33999 | 782 | * @note The RTC Resynchronization mode is write protected, use the |
<> | 149:156823d33999 | 783 | * __HAL_RTC_WRITEPROTECTION_DISABLE() before calling this function. |
<> | 149:156823d33999 | 784 | * @note To read the calendar through the shadow registers after Calendar |
<> | 149:156823d33999 | 785 | * initialization, calendar update or after wakeup from low power modes |
<> | 149:156823d33999 | 786 | * the software must first clear the RSF flag. |
<> | 149:156823d33999 | 787 | * The software must then wait until it is set again before reading |
<> | 149:156823d33999 | 788 | * the calendar, which means that the calendar registers have been |
<> | 149:156823d33999 | 789 | * correctly copied into the RTC_TR and RTC_DR shadow registers. |
<> | 149:156823d33999 | 790 | * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains |
<> | 149:156823d33999 | 791 | * the configuration information for RTC. |
<> | 149:156823d33999 | 792 | * @retval HAL status |
<> | 149:156823d33999 | 793 | */ |
<> | 149:156823d33999 | 794 | HAL_StatusTypeDef HAL_RTC_WaitForSynchro(RTC_HandleTypeDef* hrtc) |
<> | 149:156823d33999 | 795 | { |
<> | 149:156823d33999 | 796 | uint32_t tickstart = 0; |
<> | 149:156823d33999 | 797 | |
<> | 149:156823d33999 | 798 | #if defined(STM32L100xBA) || defined (STM32L151xBA) || defined (STM32L152xBA) || defined(STM32L100xC) || defined (STM32L151xC) || defined (STM32L152xC) || defined (STM32L162xC) || defined(STM32L151xCA) || defined (STM32L151xD) || defined (STM32L152xCA) || defined (STM32L152xD) || defined (STM32L162xCA) || defined (STM32L162xD) || defined(STM32L151xE) || defined(STM32L151xDX) || defined (STM32L152xE) || defined (STM32L152xDX) || defined (STM32L162xE) || defined (STM32L162xDX) |
<> | 149:156823d33999 | 799 | /* If RTC_CR_BYPSHAD bit = 0, wait for synchro else this check is not needed */ |
<> | 149:156823d33999 | 800 | if((hrtc->Instance->CR & RTC_CR_BYPSHAD) == RESET) |
<> | 149:156823d33999 | 801 | #endif /* STM32L100xBA || STM32L151xBA || STM32L152xBA || STM32L100xC || STM32L151xC || STM32L152xC || STM32L162xC || STM32L151xCA || STM32L151xD || STM32L152xCA || STM32L152xD || STM32L162xCA || STM32L162xD || STM32L151xE || STM32L151xDX || STM32L152xE || STM32L152xDX || STM32L162xE || STM32L162xDX */ |
<> | 149:156823d33999 | 802 | { |
<> | 149:156823d33999 | 803 | /* Clear RSF flag */ |
<> | 149:156823d33999 | 804 | hrtc->Instance->ISR &= (uint32_t)RTC_RSF_MASK; |
<> | 149:156823d33999 | 805 | |
<> | 149:156823d33999 | 806 | tickstart = HAL_GetTick(); |
<> | 149:156823d33999 | 807 | |
<> | 149:156823d33999 | 808 | /* Wait the registers to be synchronised */ |
<> | 149:156823d33999 | 809 | while((hrtc->Instance->ISR & RTC_ISR_RSF) == (uint32_t)RESET) |
<> | 149:156823d33999 | 810 | { |
<> | 149:156823d33999 | 811 | if((HAL_GetTick() - tickstart ) > RTC_TIMEOUT_VALUE) |
<> | 149:156823d33999 | 812 | { |
<> | 149:156823d33999 | 813 | return HAL_TIMEOUT; |
<> | 149:156823d33999 | 814 | } |
<> | 149:156823d33999 | 815 | } |
<> | 149:156823d33999 | 816 | } |
<> | 149:156823d33999 | 817 | |
<> | 149:156823d33999 | 818 | return HAL_OK; |
<> | 149:156823d33999 | 819 | } |
<> | 149:156823d33999 | 820 | |
<> | 149:156823d33999 | 821 | /** |
<> | 149:156823d33999 | 822 | * @} |
<> | 149:156823d33999 | 823 | */ |
<> | 149:156823d33999 | 824 | |
<> | 149:156823d33999 | 825 | /** |
<> | 149:156823d33999 | 826 | * @} |
<> | 149:156823d33999 | 827 | */ |
<> | 149:156823d33999 | 828 | |
<> | 149:156823d33999 | 829 | /** |
<> | 149:156823d33999 | 830 | * @} |
<> | 149:156823d33999 | 831 | */ |
<> | 149:156823d33999 | 832 | |
<> | 149:156823d33999 | 833 | /** @defgroup RTCEx RTCEx |
<> | 149:156823d33999 | 834 | * @brief RTC Extended HAL module driver |
<> | 149:156823d33999 | 835 | * @{ |
<> | 149:156823d33999 | 836 | */ |
<> | 149:156823d33999 | 837 | |
<> | 149:156823d33999 | 838 | /** @defgroup RTCEx_Exported_Functions RTCEx Exported Functions |
<> | 149:156823d33999 | 839 | * @{ |
<> | 149:156823d33999 | 840 | */ |
<> | 149:156823d33999 | 841 | |
<> | 149:156823d33999 | 842 | /** @defgroup RTCEx_Exported_Functions_Group4 RTC TimeStamp and Tamper functions |
<> | 149:156823d33999 | 843 | * @brief RTC TimeStamp and Tamper functions |
<> | 149:156823d33999 | 844 | * |
<> | 149:156823d33999 | 845 | @verbatim |
<> | 149:156823d33999 | 846 | =============================================================================== |
<> | 149:156823d33999 | 847 | ##### RTC TimeStamp and Tamper functions ##### |
<> | 149:156823d33999 | 848 | =============================================================================== |
<> | 149:156823d33999 | 849 | |
<> | 149:156823d33999 | 850 | [..] This section provides functions allowing to configure TimeStamp feature |
<> | 149:156823d33999 | 851 | |
<> | 149:156823d33999 | 852 | @endverbatim |
<> | 149:156823d33999 | 853 | * @{ |
<> | 149:156823d33999 | 854 | */ |
<> | 149:156823d33999 | 855 | |
<> | 149:156823d33999 | 856 | /** |
<> | 149:156823d33999 | 857 | * @brief Sets TimeStamp. |
<> | 149:156823d33999 | 858 | * @note This API must be called before enabling the TimeStamp feature. |
<> | 149:156823d33999 | 859 | * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains |
<> | 149:156823d33999 | 860 | * the configuration information for RTC. |
<> | 149:156823d33999 | 861 | * @param TimeStampEdge: Specifies the pin edge on which the TimeStamp is |
<> | 149:156823d33999 | 862 | * activated. |
<> | 149:156823d33999 | 863 | * This parameter can be one of the following values: |
<> | 149:156823d33999 | 864 | * @arg RTC_TIMESTAMPEDGE_RISING: the Time stamp event occurs on the |
<> | 149:156823d33999 | 865 | * rising edge of the related pin. |
<> | 149:156823d33999 | 866 | * @arg RTC_TIMESTAMPEDGE_FALLING: the Time stamp event occurs on the |
<> | 149:156823d33999 | 867 | * falling edge of the related pin. |
<> | 149:156823d33999 | 868 | * @retval HAL status |
<> | 149:156823d33999 | 869 | */ |
<> | 149:156823d33999 | 870 | HAL_StatusTypeDef HAL_RTCEx_SetTimeStamp(RTC_HandleTypeDef *hrtc, uint32_t TimeStampEdge) |
<> | 149:156823d33999 | 871 | { |
<> | 149:156823d33999 | 872 | uint32_t tmpreg = 0; |
<> | 149:156823d33999 | 873 | |
<> | 149:156823d33999 | 874 | /* Check the parameters */ |
<> | 149:156823d33999 | 875 | assert_param(IS_TIMESTAMP_EDGE(TimeStampEdge)); |
<> | 149:156823d33999 | 876 | |
<> | 149:156823d33999 | 877 | /* Process Locked */ |
<> | 149:156823d33999 | 878 | __HAL_LOCK(hrtc); |
<> | 149:156823d33999 | 879 | |
<> | 149:156823d33999 | 880 | hrtc->State = HAL_RTC_STATE_BUSY; |
<> | 149:156823d33999 | 881 | |
<> | 149:156823d33999 | 882 | /* Get the RTC_CR register and clear the bits to be configured */ |
<> | 149:156823d33999 | 883 | tmpreg = (uint32_t)(hrtc->Instance->CR & (uint32_t)~(RTC_CR_TSEDGE | RTC_CR_TSE)); |
<> | 149:156823d33999 | 884 | |
<> | 149:156823d33999 | 885 | tmpreg|= TimeStampEdge; |
<> | 149:156823d33999 | 886 | |
<> | 149:156823d33999 | 887 | /* Disable the write protection for RTC registers */ |
<> | 149:156823d33999 | 888 | __HAL_RTC_WRITEPROTECTION_DISABLE(hrtc); |
<> | 149:156823d33999 | 889 | |
<> | 149:156823d33999 | 890 | /* Configure the Time Stamp TSEDGE and Enable bits */ |
<> | 149:156823d33999 | 891 | hrtc->Instance->CR = (uint32_t)tmpreg; |
<> | 149:156823d33999 | 892 | |
<> | 149:156823d33999 | 893 | __HAL_RTC_TIMESTAMP_ENABLE(hrtc); |
<> | 149:156823d33999 | 894 | |
<> | 149:156823d33999 | 895 | /* Enable the write protection for RTC registers */ |
<> | 149:156823d33999 | 896 | __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc); |
<> | 149:156823d33999 | 897 | |
<> | 149:156823d33999 | 898 | /* Change RTC state */ |
<> | 149:156823d33999 | 899 | hrtc->State = HAL_RTC_STATE_READY; |
<> | 149:156823d33999 | 900 | |
<> | 149:156823d33999 | 901 | /* Process Unlocked */ |
<> | 149:156823d33999 | 902 | __HAL_UNLOCK(hrtc); |
<> | 149:156823d33999 | 903 | |
<> | 149:156823d33999 | 904 | return HAL_OK; |
<> | 149:156823d33999 | 905 | } |
<> | 149:156823d33999 | 906 | |
<> | 149:156823d33999 | 907 | /** |
<> | 149:156823d33999 | 908 | * @brief Sets TimeStamp with Interrupt. |
<> | 149:156823d33999 | 909 | * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains |
<> | 149:156823d33999 | 910 | * the configuration information for RTC. |
<> | 149:156823d33999 | 911 | * @note This API must be called before enabling the TimeStamp feature. |
<> | 149:156823d33999 | 912 | * @param TimeStampEdge: Specifies the pin edge on which the TimeStamp is |
<> | 149:156823d33999 | 913 | * activated. |
<> | 149:156823d33999 | 914 | * This parameter can be one of the following values: |
<> | 149:156823d33999 | 915 | * @arg RTC_TIMESTAMPEDGE_RISING: the Time stamp event occurs on the |
<> | 149:156823d33999 | 916 | * rising edge of the related pin. |
<> | 149:156823d33999 | 917 | * @arg RTC_TIMESTAMPEDGE_FALLING: the Time stamp event occurs on the |
<> | 149:156823d33999 | 918 | * falling edge of the related pin. |
<> | 149:156823d33999 | 919 | * @retval HAL status |
<> | 149:156823d33999 | 920 | */ |
<> | 149:156823d33999 | 921 | HAL_StatusTypeDef HAL_RTCEx_SetTimeStamp_IT(RTC_HandleTypeDef *hrtc, uint32_t TimeStampEdge) |
<> | 149:156823d33999 | 922 | { |
<> | 149:156823d33999 | 923 | uint32_t tmpreg = 0; |
<> | 149:156823d33999 | 924 | |
<> | 149:156823d33999 | 925 | /* Check the parameters */ |
<> | 149:156823d33999 | 926 | assert_param(IS_TIMESTAMP_EDGE(TimeStampEdge)); |
<> | 149:156823d33999 | 927 | |
<> | 149:156823d33999 | 928 | /* Process Locked */ |
<> | 149:156823d33999 | 929 | __HAL_LOCK(hrtc); |
<> | 149:156823d33999 | 930 | |
<> | 149:156823d33999 | 931 | hrtc->State = HAL_RTC_STATE_BUSY; |
<> | 149:156823d33999 | 932 | |
<> | 149:156823d33999 | 933 | /* Get the RTC_CR register and clear the bits to be configured */ |
<> | 149:156823d33999 | 934 | tmpreg = (uint32_t)(hrtc->Instance->CR & (uint32_t)~(RTC_CR_TSEDGE | RTC_CR_TSE)); |
<> | 149:156823d33999 | 935 | |
<> | 149:156823d33999 | 936 | tmpreg |= TimeStampEdge; |
<> | 149:156823d33999 | 937 | |
<> | 149:156823d33999 | 938 | /* Disable the write protection for RTC registers */ |
<> | 149:156823d33999 | 939 | __HAL_RTC_WRITEPROTECTION_DISABLE(hrtc); |
<> | 149:156823d33999 | 940 | |
<> | 149:156823d33999 | 941 | /* Configure the Time Stamp TSEDGE and Enable bits */ |
<> | 149:156823d33999 | 942 | hrtc->Instance->CR = (uint32_t)tmpreg; |
<> | 149:156823d33999 | 943 | |
<> | 149:156823d33999 | 944 | __HAL_RTC_TIMESTAMP_ENABLE(hrtc); |
<> | 149:156823d33999 | 945 | |
<> | 149:156823d33999 | 946 | /* Enable IT timestamp */ |
<> | 149:156823d33999 | 947 | __HAL_RTC_TIMESTAMP_ENABLE_IT(hrtc,RTC_IT_TS); |
<> | 149:156823d33999 | 948 | |
<> | 149:156823d33999 | 949 | /* RTC timestamp Interrupt Configuration: EXTI configuration */ |
<> | 149:156823d33999 | 950 | __HAL_RTC_TAMPER_TIMESTAMP_EXTI_ENABLE_IT(); |
<> | 149:156823d33999 | 951 | |
<> | 149:156823d33999 | 952 | __HAL_RTC_TAMPER_TIMESTAMP_EXTI_ENABLE_RISING_EDGE(); |
<> | 149:156823d33999 | 953 | |
<> | 149:156823d33999 | 954 | /* Enable the write protection for RTC registers */ |
<> | 149:156823d33999 | 955 | __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc); |
<> | 149:156823d33999 | 956 | |
<> | 149:156823d33999 | 957 | hrtc->State = HAL_RTC_STATE_READY; |
<> | 149:156823d33999 | 958 | |
<> | 149:156823d33999 | 959 | /* Process Unlocked */ |
<> | 149:156823d33999 | 960 | __HAL_UNLOCK(hrtc); |
<> | 149:156823d33999 | 961 | |
<> | 149:156823d33999 | 962 | return HAL_OK; |
<> | 149:156823d33999 | 963 | } |
<> | 149:156823d33999 | 964 | |
<> | 149:156823d33999 | 965 | /** |
<> | 149:156823d33999 | 966 | * @brief Deactivates TimeStamp. |
<> | 149:156823d33999 | 967 | * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains |
<> | 149:156823d33999 | 968 | * the configuration information for RTC. |
<> | 149:156823d33999 | 969 | * @retval HAL status |
<> | 149:156823d33999 | 970 | */ |
<> | 149:156823d33999 | 971 | HAL_StatusTypeDef HAL_RTCEx_DeactivateTimeStamp(RTC_HandleTypeDef *hrtc) |
<> | 149:156823d33999 | 972 | { |
<> | 149:156823d33999 | 973 | uint32_t tmpreg = 0; |
<> | 149:156823d33999 | 974 | |
<> | 149:156823d33999 | 975 | /* Process Locked */ |
<> | 149:156823d33999 | 976 | __HAL_LOCK(hrtc); |
<> | 149:156823d33999 | 977 | |
<> | 149:156823d33999 | 978 | hrtc->State = HAL_RTC_STATE_BUSY; |
<> | 149:156823d33999 | 979 | |
<> | 149:156823d33999 | 980 | /* Disable the write protection for RTC registers */ |
<> | 149:156823d33999 | 981 | __HAL_RTC_WRITEPROTECTION_DISABLE(hrtc); |
<> | 149:156823d33999 | 982 | |
<> | 149:156823d33999 | 983 | /* In case of interrupt mode is used, the interrupt source must disabled */ |
<> | 149:156823d33999 | 984 | __HAL_RTC_TIMESTAMP_DISABLE_IT(hrtc, RTC_IT_TS); |
<> | 149:156823d33999 | 985 | |
<> | 149:156823d33999 | 986 | /* Get the RTC_CR register and clear the bits to be configured */ |
<> | 149:156823d33999 | 987 | tmpreg = (uint32_t)(hrtc->Instance->CR & (uint32_t)~(RTC_CR_TSEDGE | RTC_CR_TSE)); |
<> | 149:156823d33999 | 988 | |
<> | 149:156823d33999 | 989 | /* Configure the Time Stamp TSEDGE and Enable bits */ |
<> | 149:156823d33999 | 990 | hrtc->Instance->CR = (uint32_t)tmpreg; |
<> | 149:156823d33999 | 991 | |
<> | 149:156823d33999 | 992 | /* Enable the write protection for RTC registers */ |
<> | 149:156823d33999 | 993 | __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc); |
<> | 149:156823d33999 | 994 | |
<> | 149:156823d33999 | 995 | hrtc->State = HAL_RTC_STATE_READY; |
<> | 149:156823d33999 | 996 | |
<> | 149:156823d33999 | 997 | /* Process Unlocked */ |
<> | 149:156823d33999 | 998 | __HAL_UNLOCK(hrtc); |
<> | 149:156823d33999 | 999 | |
<> | 149:156823d33999 | 1000 | return HAL_OK; |
<> | 149:156823d33999 | 1001 | } |
<> | 149:156823d33999 | 1002 | |
<> | 149:156823d33999 | 1003 | /** |
<> | 149:156823d33999 | 1004 | * @brief Gets the RTC TimeStamp value. |
<> | 149:156823d33999 | 1005 | * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains |
<> | 149:156823d33999 | 1006 | * the configuration information for RTC. |
<> | 149:156823d33999 | 1007 | * @param sTimeStamp: Pointer to Time structure |
<> | 149:156823d33999 | 1008 | * @param sTimeStampDate: Pointer to Date structure |
<> | 149:156823d33999 | 1009 | * @param Format: specifies the format of the entered parameters. |
<> | 149:156823d33999 | 1010 | * This parameter can be one of the following values: |
<> | 149:156823d33999 | 1011 | * RTC_FORMAT_BIN: Binary data format |
<> | 149:156823d33999 | 1012 | * RTC_FORMAT_BCD: BCD data format |
<> | 149:156823d33999 | 1013 | * @retval HAL status |
<> | 149:156823d33999 | 1014 | */ |
<> | 149:156823d33999 | 1015 | HAL_StatusTypeDef HAL_RTCEx_GetTimeStamp(RTC_HandleTypeDef *hrtc, RTC_TimeTypeDef* sTimeStamp, RTC_DateTypeDef* sTimeStampDate, uint32_t Format) |
<> | 149:156823d33999 | 1016 | { |
<> | 149:156823d33999 | 1017 | uint32_t tmptime = 0, tmpdate = 0; |
<> | 149:156823d33999 | 1018 | |
<> | 149:156823d33999 | 1019 | /* Check the parameters */ |
<> | 149:156823d33999 | 1020 | assert_param(IS_RTC_FORMAT(Format)); |
<> | 149:156823d33999 | 1021 | |
<> | 149:156823d33999 | 1022 | /* Get the TimeStamp time and date registers values */ |
<> | 149:156823d33999 | 1023 | tmptime = (uint32_t)(hrtc->Instance->TSTR & RTC_TR_RESERVED_MASK); |
<> | 149:156823d33999 | 1024 | tmpdate = (uint32_t)(hrtc->Instance->TSDR & RTC_DR_RESERVED_MASK); |
<> | 149:156823d33999 | 1025 | |
<> | 149:156823d33999 | 1026 | /* Fill the Time structure fields with the read parameters */ |
<> | 149:156823d33999 | 1027 | sTimeStamp->Hours = (uint8_t)((tmptime & (RTC_TR_HT | RTC_TR_HU)) >> 16); |
<> | 149:156823d33999 | 1028 | sTimeStamp->Minutes = (uint8_t)((tmptime & (RTC_TR_MNT | RTC_TR_MNU)) >> 8); |
<> | 149:156823d33999 | 1029 | sTimeStamp->Seconds = (uint8_t)(tmptime & (RTC_TR_ST | RTC_TR_SU)); |
<> | 149:156823d33999 | 1030 | sTimeStamp->TimeFormat = (uint8_t)((tmptime & (RTC_TR_PM)) >> 16); |
<> | 149:156823d33999 | 1031 | #if defined(STM32L100xBA) || defined (STM32L151xBA) || defined (STM32L152xBA) || defined(STM32L100xC) || defined (STM32L151xC) || defined (STM32L152xC) || defined (STM32L162xC) || defined(STM32L151xCA) || defined (STM32L151xD) || defined (STM32L152xCA) || defined (STM32L152xD) || defined (STM32L162xCA) || defined (STM32L162xD) || defined(STM32L151xE) || defined(STM32L151xDX) || defined (STM32L152xE) || defined (STM32L152xDX) || defined (STM32L162xE) || defined (STM32L162xDX) |
<> | 149:156823d33999 | 1032 | sTimeStamp->SubSeconds = (uint32_t)((hrtc->Instance->TSSSR) & RTC_TSSSR_SS); |
<> | 149:156823d33999 | 1033 | #endif /* STM32L100xBA || STM32L151xBA || STM32L152xBA || STM32L100xC || STM32L151xC || STM32L152xC || STM32L162xC || STM32L151xCA || STM32L151xD || STM32L152xCA || STM32L152xD || STM32L162xCA || STM32L162xD || STM32L151xE || STM32L151xDX || STM32L152xE || STM32L152xDX || STM32L162xE || STM32L162xDX */ |
<> | 149:156823d33999 | 1034 | |
<> | 149:156823d33999 | 1035 | /* Fill the Date structure fields with the read parameters */ |
<> | 149:156823d33999 | 1036 | sTimeStampDate->Year = 0; |
<> | 149:156823d33999 | 1037 | sTimeStampDate->Month = (uint8_t)((tmpdate & (RTC_DR_MT | RTC_DR_MU)) >> 8); |
<> | 149:156823d33999 | 1038 | sTimeStampDate->Date = (uint8_t)(tmpdate & (RTC_DR_DT | RTC_DR_DU)); |
<> | 149:156823d33999 | 1039 | sTimeStampDate->WeekDay = (uint8_t)((tmpdate & (RTC_DR_WDU)) >> 13); |
<> | 149:156823d33999 | 1040 | |
<> | 149:156823d33999 | 1041 | /* Check the input parameters format */ |
<> | 149:156823d33999 | 1042 | if(Format == RTC_FORMAT_BIN) |
<> | 149:156823d33999 | 1043 | { |
<> | 149:156823d33999 | 1044 | /* Convert the TimeStamp structure parameters to Binary format */ |
<> | 149:156823d33999 | 1045 | sTimeStamp->Hours = (uint8_t)RTC_Bcd2ToByte(sTimeStamp->Hours); |
<> | 149:156823d33999 | 1046 | sTimeStamp->Minutes = (uint8_t)RTC_Bcd2ToByte(sTimeStamp->Minutes); |
<> | 149:156823d33999 | 1047 | sTimeStamp->Seconds = (uint8_t)RTC_Bcd2ToByte(sTimeStamp->Seconds); |
<> | 149:156823d33999 | 1048 | |
<> | 149:156823d33999 | 1049 | /* Convert the DateTimeStamp structure parameters to Binary format */ |
<> | 149:156823d33999 | 1050 | sTimeStampDate->Month = (uint8_t)RTC_Bcd2ToByte(sTimeStampDate->Month); |
<> | 149:156823d33999 | 1051 | sTimeStampDate->Date = (uint8_t)RTC_Bcd2ToByte(sTimeStampDate->Date); |
<> | 149:156823d33999 | 1052 | sTimeStampDate->WeekDay = (uint8_t)RTC_Bcd2ToByte(sTimeStampDate->WeekDay); |
<> | 149:156823d33999 | 1053 | } |
<> | 149:156823d33999 | 1054 | |
<> | 149:156823d33999 | 1055 | /* Clear the TIMESTAMP Flag */ |
<> | 149:156823d33999 | 1056 | __HAL_RTC_TIMESTAMP_CLEAR_FLAG(hrtc, RTC_FLAG_TSF); |
<> | 149:156823d33999 | 1057 | |
<> | 149:156823d33999 | 1058 | return HAL_OK; |
<> | 149:156823d33999 | 1059 | } |
<> | 149:156823d33999 | 1060 | |
<> | 149:156823d33999 | 1061 | /** |
<> | 149:156823d33999 | 1062 | * @brief Sets Tamper |
<> | 149:156823d33999 | 1063 | * @note By calling this API we disable the tamper interrupt for all tampers. |
<> | 149:156823d33999 | 1064 | * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains |
<> | 149:156823d33999 | 1065 | * the configuration information for RTC. |
<> | 149:156823d33999 | 1066 | * @param sTamper: Pointer to Tamper Structure. |
<> | 149:156823d33999 | 1067 | * @retval HAL status |
<> | 149:156823d33999 | 1068 | */ |
<> | 149:156823d33999 | 1069 | HAL_StatusTypeDef HAL_RTCEx_SetTamper(RTC_HandleTypeDef *hrtc, RTC_TamperTypeDef* sTamper) |
<> | 149:156823d33999 | 1070 | { |
<> | 149:156823d33999 | 1071 | uint32_t tmpreg = 0; |
<> | 149:156823d33999 | 1072 | |
<> | 149:156823d33999 | 1073 | /* Check the parameters */ |
<> | 149:156823d33999 | 1074 | assert_param(IS_RTC_TAMPER(sTamper->Tamper)); |
<> | 149:156823d33999 | 1075 | assert_param(IS_RTC_TAMPER_TRIGGER(sTamper->Trigger)); |
<> | 149:156823d33999 | 1076 | #if defined(STM32L100xBA) || defined (STM32L151xBA) || defined (STM32L152xBA) || defined(STM32L100xC) || defined (STM32L151xC) || defined (STM32L152xC) || defined (STM32L162xC) || defined(STM32L151xCA) || defined (STM32L151xD) || defined (STM32L152xCA) || defined (STM32L152xD) || defined (STM32L162xCA) || defined (STM32L162xD) || defined(STM32L151xE) || defined(STM32L151xDX) || defined (STM32L152xE) || defined (STM32L152xDX) || defined (STM32L162xE) || defined (STM32L162xDX) |
<> | 149:156823d33999 | 1077 | assert_param(IS_RTC_TAMPER_FILTER(sTamper->Filter)); |
<> | 149:156823d33999 | 1078 | assert_param(IS_RTC_TAMPER_SAMPLING_FREQ(sTamper->SamplingFrequency)); |
<> | 149:156823d33999 | 1079 | assert_param(IS_RTC_TAMPER_PRECHARGE_DURATION(sTamper->PrechargeDuration)); |
<> | 149:156823d33999 | 1080 | assert_param(IS_RTC_TAMPER_PULLUP_STATE(sTamper->TamperPullUp)); |
<> | 149:156823d33999 | 1081 | assert_param(IS_RTC_TAMPER_TIMESTAMPONTAMPER_DETECTION(sTamper->TimeStampOnTamperDetection)); |
<> | 149:156823d33999 | 1082 | #endif /* STM32L100xBA || STM32L151xBA || STM32L152xBA || STM32L100xC || STM32L151xC || STM32L152xC || STM32L162xC || STM32L151xCA || STM32L151xD || STM32L152xCA || STM32L152xD || STM32L162xCA || STM32L162xD || STM32L151xE || STM32L151xDX || STM32L152xE || STM32L152xDX || STM32L162xE || STM32L162xDX */ |
<> | 149:156823d33999 | 1083 | |
<> | 149:156823d33999 | 1084 | /* Process Locked */ |
<> | 149:156823d33999 | 1085 | __HAL_LOCK(hrtc); |
<> | 149:156823d33999 | 1086 | |
<> | 149:156823d33999 | 1087 | hrtc->State = HAL_RTC_STATE_BUSY; |
<> | 149:156823d33999 | 1088 | |
<> | 149:156823d33999 | 1089 | #if defined(STM32L100xBA) || defined (STM32L151xBA) || defined (STM32L152xBA) || defined(STM32L100xC) || defined (STM32L151xC) || defined (STM32L152xC) || defined (STM32L162xC) || defined(STM32L151xCA) || defined (STM32L151xD) || defined (STM32L152xCA) || defined (STM32L152xD) || defined (STM32L162xCA) || defined (STM32L162xD) || defined(STM32L151xE) || defined(STM32L151xDX) || defined (STM32L152xE) || defined (STM32L152xDX) || defined (STM32L162xE) || defined (STM32L162xDX) |
<> | 149:156823d33999 | 1090 | if((sTamper->Trigger == RTC_TAMPERTRIGGER_RISINGEDGE)) |
<> | 149:156823d33999 | 1091 | { |
<> | 149:156823d33999 | 1092 | /* Configure the RTC_TAFCR register */ |
<> | 149:156823d33999 | 1093 | sTamper->Trigger = RTC_TAMPERTRIGGER_RISINGEDGE; |
<> | 149:156823d33999 | 1094 | } |
<> | 149:156823d33999 | 1095 | else |
<> | 149:156823d33999 | 1096 | { |
<> | 149:156823d33999 | 1097 | sTamper->Trigger = (uint32_t)(sTamper->Tamper << 1); |
<> | 149:156823d33999 | 1098 | } |
<> | 149:156823d33999 | 1099 | |
<> | 149:156823d33999 | 1100 | tmpreg = ((uint32_t)sTamper->Tamper | (uint32_t)sTamper->Trigger | (uint32_t)sTamper->Filter |\ |
<> | 149:156823d33999 | 1101 | (uint32_t)sTamper->SamplingFrequency | (uint32_t)sTamper->PrechargeDuration |\ |
<> | 149:156823d33999 | 1102 | (uint32_t)sTamper->TamperPullUp | sTamper->TimeStampOnTamperDetection); |
<> | 149:156823d33999 | 1103 | |
<> | 149:156823d33999 | 1104 | hrtc->Instance->TAFCR &= (uint32_t)~((uint32_t)sTamper->Tamper | (uint32_t)(sTamper->Tamper << 1) | (uint32_t)RTC_TAFCR_TAMPTS |\ |
<> | 149:156823d33999 | 1105 | (uint32_t)RTC_TAFCR_TAMPFREQ | (uint32_t)RTC_TAFCR_TAMPFLT | (uint32_t)RTC_TAFCR_TAMPPRCH |\ |
<> | 149:156823d33999 | 1106 | (uint32_t)RTC_TAFCR_TAMPPUDIS | (uint32_t)RTC_TAFCR_TAMPIE); |
<> | 149:156823d33999 | 1107 | #else |
<> | 149:156823d33999 | 1108 | tmpreg = ((uint32_t)sTamper->Tamper | (uint32_t)(sTamper->Trigger)); |
<> | 149:156823d33999 | 1109 | |
<> | 149:156823d33999 | 1110 | hrtc->Instance->TAFCR &= (uint32_t)~((uint32_t)RTC_TAFCR_TAMP1E | (uint32_t)RTC_TAFCR_TAMP1TRG); |
<> | 149:156823d33999 | 1111 | |
<> | 149:156823d33999 | 1112 | #endif /* STM32L100xBA || STM32L151xBA || STM32L152xBA || STM32L100xC || STM32L151xC || STM32L152xC || STM32L162xC || STM32L151xCA || STM32L151xD || STM32L152xCA || STM32L152xD || STM32L162xCA || STM32L162xD || STM32L151xE || STM32L151xDX || STM32L152xE || STM32L152xDX || STM32L162xE || STM32L162xDX */ |
<> | 149:156823d33999 | 1113 | hrtc->Instance->TAFCR |= tmpreg; |
<> | 149:156823d33999 | 1114 | |
<> | 149:156823d33999 | 1115 | hrtc->State = HAL_RTC_STATE_READY; |
<> | 149:156823d33999 | 1116 | |
<> | 149:156823d33999 | 1117 | /* Process Unlocked */ |
<> | 149:156823d33999 | 1118 | __HAL_UNLOCK(hrtc); |
<> | 149:156823d33999 | 1119 | |
<> | 149:156823d33999 | 1120 | return HAL_OK; |
<> | 149:156823d33999 | 1121 | } |
<> | 149:156823d33999 | 1122 | |
<> | 149:156823d33999 | 1123 | /** |
<> | 149:156823d33999 | 1124 | * @brief Sets Tamper with interrupt. |
<> | 149:156823d33999 | 1125 | * @note By calling this API we force the tamper interrupt for all tampers. |
<> | 149:156823d33999 | 1126 | * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains |
<> | 149:156823d33999 | 1127 | * the configuration information for RTC. |
<> | 149:156823d33999 | 1128 | * @param sTamper: Pointer to RTC Tamper. |
<> | 149:156823d33999 | 1129 | * @retval HAL status |
<> | 149:156823d33999 | 1130 | */ |
<> | 149:156823d33999 | 1131 | HAL_StatusTypeDef HAL_RTCEx_SetTamper_IT(RTC_HandleTypeDef *hrtc, RTC_TamperTypeDef* sTamper) |
<> | 149:156823d33999 | 1132 | { |
<> | 149:156823d33999 | 1133 | uint32_t tmpreg = 0; |
<> | 149:156823d33999 | 1134 | |
<> | 149:156823d33999 | 1135 | /* Check the parameters */ |
<> | 149:156823d33999 | 1136 | assert_param(IS_RTC_TAMPER(sTamper->Tamper)); |
<> | 149:156823d33999 | 1137 | assert_param(IS_RTC_TAMPER_TRIGGER(sTamper->Trigger)); |
<> | 149:156823d33999 | 1138 | #if defined(STM32L100xBA) || defined (STM32L151xBA) || defined (STM32L152xBA) || defined(STM32L100xC) || defined (STM32L151xC) || defined (STM32L152xC) || defined (STM32L162xC) || defined(STM32L151xCA) || defined (STM32L151xD) || defined (STM32L152xCA) || defined (STM32L152xD) || defined (STM32L162xCA) || defined (STM32L162xD) || defined(STM32L151xE) || defined(STM32L151xDX) || defined (STM32L152xE) || defined (STM32L152xDX) || defined (STM32L162xE) || defined (STM32L162xDX) |
<> | 149:156823d33999 | 1139 | assert_param(IS_RTC_TAMPER_FILTER(sTamper->Filter)); |
<> | 149:156823d33999 | 1140 | assert_param(IS_RTC_TAMPER_SAMPLING_FREQ(sTamper->SamplingFrequency)); |
<> | 149:156823d33999 | 1141 | assert_param(IS_RTC_TAMPER_PRECHARGE_DURATION(sTamper->PrechargeDuration)); |
<> | 149:156823d33999 | 1142 | assert_param(IS_RTC_TAMPER_PULLUP_STATE(sTamper->TamperPullUp)); |
<> | 149:156823d33999 | 1143 | assert_param(IS_RTC_TAMPER_TIMESTAMPONTAMPER_DETECTION(sTamper->TimeStampOnTamperDetection)); |
<> | 149:156823d33999 | 1144 | #endif /* STM32L100xBA || STM32L151xBA || STM32L152xBA || STM32L100xC || STM32L151xC || STM32L152xC || STM32L162xC || STM32L151xCA || STM32L151xD || STM32L152xCA || STM32L152xD || STM32L162xCA || STM32L162xD || STM32L151xE || STM32L151xDX || STM32L152xE || STM32L152xDX || STM32L162xE || STM32L162xDX */ |
<> | 149:156823d33999 | 1145 | |
<> | 149:156823d33999 | 1146 | /* Process Locked */ |
<> | 149:156823d33999 | 1147 | __HAL_LOCK(hrtc); |
<> | 149:156823d33999 | 1148 | |
<> | 149:156823d33999 | 1149 | hrtc->State = HAL_RTC_STATE_BUSY; |
<> | 149:156823d33999 | 1150 | |
<> | 149:156823d33999 | 1151 | #if defined(STM32L100xBA) || defined (STM32L151xBA) || defined (STM32L152xBA) || defined(STM32L100xC) || defined (STM32L151xC) || defined (STM32L152xC) || defined (STM32L162xC) || defined(STM32L151xCA) || defined (STM32L151xD) || defined (STM32L152xCA) || defined (STM32L152xD) || defined (STM32L162xCA) || defined (STM32L162xD) || defined(STM32L151xE) || defined(STM32L151xDX) || defined (STM32L152xE) || defined (STM32L152xDX) || defined (STM32L162xE) || defined (STM32L162xDX) |
<> | 149:156823d33999 | 1152 | /* Configure the tamper trigger */ |
<> | 149:156823d33999 | 1153 | if((sTamper->Trigger == RTC_TAMPERTRIGGER_RISINGEDGE)) |
<> | 149:156823d33999 | 1154 | { |
<> | 149:156823d33999 | 1155 | sTamper->Trigger = RTC_TAMPERTRIGGER_RISINGEDGE; |
<> | 149:156823d33999 | 1156 | } |
<> | 149:156823d33999 | 1157 | else |
<> | 149:156823d33999 | 1158 | { |
<> | 149:156823d33999 | 1159 | sTamper->Trigger = (uint32_t) (sTamper->Tamper<<1); |
<> | 149:156823d33999 | 1160 | } |
<> | 149:156823d33999 | 1161 | |
<> | 149:156823d33999 | 1162 | tmpreg = ((uint32_t)sTamper->Tamper | (uint32_t)sTamper->Trigger | (uint32_t)sTamper->Filter |\ |
<> | 149:156823d33999 | 1163 | (uint32_t)sTamper->SamplingFrequency | (uint32_t)sTamper->PrechargeDuration |\ |
<> | 149:156823d33999 | 1164 | (uint32_t)sTamper->TamperPullUp | sTamper->TimeStampOnTamperDetection); |
<> | 149:156823d33999 | 1165 | |
<> | 149:156823d33999 | 1166 | hrtc->Instance->TAFCR &= (uint32_t)~((uint32_t)sTamper->Tamper | (uint32_t)(sTamper->Tamper << 1) | (uint32_t)RTC_TAFCR_TAMPTS |\ |
<> | 149:156823d33999 | 1167 | (uint32_t)RTC_TAFCR_TAMPFREQ | (uint32_t)RTC_TAFCR_TAMPFLT | (uint32_t)RTC_TAFCR_TAMPPRCH |\ |
<> | 149:156823d33999 | 1168 | (uint32_t)RTC_TAFCR_TAMPPUDIS); |
<> | 149:156823d33999 | 1169 | #else |
<> | 149:156823d33999 | 1170 | tmpreg = ((uint32_t)sTamper->Tamper | (uint32_t)sTamper->Trigger); |
<> | 149:156823d33999 | 1171 | |
<> | 149:156823d33999 | 1172 | hrtc->Instance->TAFCR &= (uint32_t)~((uint32_t)RTC_TAFCR_TAMP1E | (uint32_t)RTC_TAFCR_TAMP1TRG | (uint32_t)RTC_TAFCR_TAMPIE); |
<> | 149:156823d33999 | 1173 | #endif /* STM32L100xBA || STM32L151xBA || STM32L152xBA || STM32L100xC || STM32L151xC || STM32L152xC || STM32L162xC || STM32L151xCA || STM32L151xD || STM32L152xCA || STM32L152xD || STM32L162xCA || STM32L162xD || STM32L151xE || STM32L151xDX || STM32L152xE || STM32L152xDX || STM32L162xE || STM32L162xDX */ |
<> | 149:156823d33999 | 1174 | hrtc->Instance->TAFCR |= tmpreg; |
<> | 149:156823d33999 | 1175 | |
<> | 149:156823d33999 | 1176 | /* Configure the Tamper Interrupt in the RTC_TAFCR */ |
<> | 149:156823d33999 | 1177 | hrtc->Instance->TAFCR |= (uint32_t)RTC_TAFCR_TAMPIE; |
<> | 149:156823d33999 | 1178 | |
<> | 149:156823d33999 | 1179 | /* RTC Tamper Interrupt Configuration: EXTI configuration */ |
<> | 149:156823d33999 | 1180 | __HAL_RTC_TAMPER_TIMESTAMP_EXTI_ENABLE_IT(); |
<> | 149:156823d33999 | 1181 | |
<> | 149:156823d33999 | 1182 | __HAL_RTC_TAMPER_TIMESTAMP_EXTI_ENABLE_RISING_EDGE(); |
<> | 149:156823d33999 | 1183 | |
<> | 149:156823d33999 | 1184 | hrtc->State = HAL_RTC_STATE_READY; |
<> | 149:156823d33999 | 1185 | |
<> | 149:156823d33999 | 1186 | /* Process Unlocked */ |
<> | 149:156823d33999 | 1187 | __HAL_UNLOCK(hrtc); |
<> | 149:156823d33999 | 1188 | |
<> | 149:156823d33999 | 1189 | return HAL_OK; |
<> | 149:156823d33999 | 1190 | } |
<> | 149:156823d33999 | 1191 | |
<> | 149:156823d33999 | 1192 | /** |
<> | 149:156823d33999 | 1193 | * @brief Deactivates Tamper. |
<> | 149:156823d33999 | 1194 | * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains |
<> | 149:156823d33999 | 1195 | * the configuration information for RTC. |
<> | 149:156823d33999 | 1196 | * @param Tamper: Selected tamper pin. |
<> | 149:156823d33999 | 1197 | * This parameter can be a value of @ref RTCEx_Tamper_Pins_Definitions |
<> | 149:156823d33999 | 1198 | * @retval HAL status |
<> | 149:156823d33999 | 1199 | */ |
<> | 149:156823d33999 | 1200 | HAL_StatusTypeDef HAL_RTCEx_DeactivateTamper(RTC_HandleTypeDef *hrtc, uint32_t Tamper) |
<> | 149:156823d33999 | 1201 | { |
<> | 149:156823d33999 | 1202 | assert_param(IS_RTC_TAMPER(Tamper)); |
<> | 149:156823d33999 | 1203 | |
<> | 149:156823d33999 | 1204 | /* Process Locked */ |
<> | 149:156823d33999 | 1205 | __HAL_LOCK(hrtc); |
<> | 149:156823d33999 | 1206 | |
<> | 149:156823d33999 | 1207 | hrtc->State = HAL_RTC_STATE_BUSY; |
<> | 149:156823d33999 | 1208 | |
<> | 149:156823d33999 | 1209 | /* Disable the selected Tamper pin */ |
<> | 149:156823d33999 | 1210 | hrtc->Instance->TAFCR &= (uint32_t)~Tamper; |
<> | 149:156823d33999 | 1211 | |
<> | 149:156823d33999 | 1212 | hrtc->State = HAL_RTC_STATE_READY; |
<> | 149:156823d33999 | 1213 | |
<> | 149:156823d33999 | 1214 | /* Process Unlocked */ |
<> | 149:156823d33999 | 1215 | __HAL_UNLOCK(hrtc); |
<> | 149:156823d33999 | 1216 | |
<> | 149:156823d33999 | 1217 | return HAL_OK; |
<> | 149:156823d33999 | 1218 | } |
<> | 149:156823d33999 | 1219 | |
<> | 149:156823d33999 | 1220 | /** |
<> | 149:156823d33999 | 1221 | * @brief This function handles TimeStamp interrupt request. |
<> | 149:156823d33999 | 1222 | * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains |
<> | 149:156823d33999 | 1223 | * the configuration information for RTC. |
<> | 149:156823d33999 | 1224 | * @retval None |
<> | 149:156823d33999 | 1225 | */ |
<> | 149:156823d33999 | 1226 | void HAL_RTCEx_TamperTimeStampIRQHandler(RTC_HandleTypeDef *hrtc) |
<> | 149:156823d33999 | 1227 | { |
<> | 149:156823d33999 | 1228 | /* Get the TimeStamp interrupt source enable status */ |
<> | 149:156823d33999 | 1229 | if(__HAL_RTC_TIMESTAMP_GET_IT_SOURCE(hrtc, RTC_IT_TS) != RESET) |
<> | 149:156823d33999 | 1230 | { |
<> | 149:156823d33999 | 1231 | /* Get the pending status of the TIMESTAMP Interrupt */ |
<> | 149:156823d33999 | 1232 | if(__HAL_RTC_TIMESTAMP_GET_FLAG(hrtc, RTC_FLAG_TSF) != RESET) |
<> | 149:156823d33999 | 1233 | { |
<> | 149:156823d33999 | 1234 | /* TIMESTAMP callback */ |
<> | 149:156823d33999 | 1235 | HAL_RTCEx_TimeStampEventCallback(hrtc); |
<> | 149:156823d33999 | 1236 | |
<> | 149:156823d33999 | 1237 | /* Clear the TIMESTAMP interrupt pending bit */ |
<> | 149:156823d33999 | 1238 | __HAL_RTC_TIMESTAMP_CLEAR_FLAG(hrtc, RTC_FLAG_TSF); |
<> | 149:156823d33999 | 1239 | } |
<> | 149:156823d33999 | 1240 | } |
<> | 149:156823d33999 | 1241 | |
<> | 149:156823d33999 | 1242 | /* Get the Tamper1 interrupts source enable status */ |
<> | 149:156823d33999 | 1243 | if(__HAL_RTC_TAMPER_GET_IT_SOURCE(hrtc, RTC_IT_TAMP | RTC_IT_TAMP1) != RESET) |
<> | 149:156823d33999 | 1244 | { |
<> | 149:156823d33999 | 1245 | /* Get the pending status of the Tamper1 Interrupt */ |
<> | 149:156823d33999 | 1246 | if(__HAL_RTC_TAMPER_GET_FLAG(hrtc, RTC_FLAG_TAMP1F) != RESET) |
<> | 149:156823d33999 | 1247 | { |
<> | 149:156823d33999 | 1248 | /* Tamper1 callback */ |
<> | 149:156823d33999 | 1249 | HAL_RTCEx_Tamper1EventCallback(hrtc); |
<> | 149:156823d33999 | 1250 | |
<> | 149:156823d33999 | 1251 | /* Clear the Tamper1 interrupt pending bit */ |
<> | 149:156823d33999 | 1252 | __HAL_RTC_TAMPER_CLEAR_FLAG(hrtc, RTC_FLAG_TAMP1F); |
<> | 149:156823d33999 | 1253 | } |
<> | 149:156823d33999 | 1254 | } |
<> | 149:156823d33999 | 1255 | |
<> | 149:156823d33999 | 1256 | #if defined(STM32L100xBA) || defined (STM32L151xBA) || defined (STM32L152xBA) || defined(STM32L100xC) || defined (STM32L151xC) || defined (STM32L152xC) || defined (STM32L162xC) || defined(STM32L151xCA) || defined (STM32L151xD) || defined (STM32L152xCA) || defined (STM32L152xD) || defined (STM32L162xCA) || defined (STM32L162xD) || defined(STM32L151xE) || defined(STM32L151xDX) || defined (STM32L152xE) || defined (STM32L152xDX) || defined (STM32L162xE) || defined (STM32L162xDX) |
<> | 149:156823d33999 | 1257 | /* Get the Tamper2 interrupts source enable status */ |
<> | 149:156823d33999 | 1258 | if(__HAL_RTC_TAMPER_GET_IT_SOURCE(hrtc, RTC_IT_TAMP | RTC_IT_TAMP2) != RESET) |
<> | 149:156823d33999 | 1259 | { |
<> | 149:156823d33999 | 1260 | /* Get the pending status of the Tamper2 Interrupt */ |
<> | 149:156823d33999 | 1261 | if(__HAL_RTC_TAMPER_GET_FLAG(hrtc, RTC_FLAG_TAMP2F) != RESET) |
<> | 149:156823d33999 | 1262 | { |
<> | 149:156823d33999 | 1263 | /* Tamper2 callback */ |
<> | 149:156823d33999 | 1264 | HAL_RTCEx_Tamper2EventCallback(hrtc); |
<> | 149:156823d33999 | 1265 | |
<> | 149:156823d33999 | 1266 | /* Clear the Tamper2 interrupt pending bit */ |
<> | 149:156823d33999 | 1267 | __HAL_RTC_TAMPER_CLEAR_FLAG(hrtc, RTC_FLAG_TAMP2F); |
<> | 149:156823d33999 | 1268 | } |
<> | 149:156823d33999 | 1269 | } |
<> | 149:156823d33999 | 1270 | |
<> | 149:156823d33999 | 1271 | /* Get the Tamper3 interrupts source enable status */ |
<> | 149:156823d33999 | 1272 | if(__HAL_RTC_TAMPER_GET_IT_SOURCE(hrtc, RTC_IT_TAMP | RTC_IT_TAMP3) != RESET) |
<> | 149:156823d33999 | 1273 | { |
<> | 149:156823d33999 | 1274 | /* Get the pending status of the Tamper3 Interrupt */ |
<> | 149:156823d33999 | 1275 | if(__HAL_RTC_TAMPER_GET_FLAG(hrtc, RTC_FLAG_TAMP3F) != RESET) |
<> | 149:156823d33999 | 1276 | { |
<> | 149:156823d33999 | 1277 | /* Tamper3 callback */ |
<> | 149:156823d33999 | 1278 | HAL_RTCEx_Tamper3EventCallback(hrtc); |
<> | 149:156823d33999 | 1279 | |
<> | 149:156823d33999 | 1280 | /* Clear the Tamper3 interrupt pending bit */ |
<> | 149:156823d33999 | 1281 | __HAL_RTC_TAMPER_CLEAR_FLAG(hrtc, RTC_FLAG_TAMP3F); |
<> | 149:156823d33999 | 1282 | } |
<> | 149:156823d33999 | 1283 | } |
<> | 149:156823d33999 | 1284 | #endif /* STM32L100xBA || STM32L151xBA || STM32L152xBA || STM32L100xC || STM32L151xC || STM32L152xC || STM32L162xC || STM32L151xCA || STM32L151xD || STM32L152xCA || STM32L152xD || STM32L162xCA || STM32L162xD || STM32L151xE || STM32L151xDX || STM32L152xE || STM32L152xDX || STM32L162xE || STM32L162xDX */ |
<> | 149:156823d33999 | 1285 | |
<> | 149:156823d33999 | 1286 | /* Clear the EXTI's Flag for RTC TimeStamp and Tamper */ |
<> | 149:156823d33999 | 1287 | __HAL_RTC_TAMPER_TIMESTAMP_EXTI_CLEAR_FLAG(); |
<> | 149:156823d33999 | 1288 | |
<> | 149:156823d33999 | 1289 | /* Change RTC state */ |
<> | 149:156823d33999 | 1290 | hrtc->State = HAL_RTC_STATE_READY; |
<> | 149:156823d33999 | 1291 | } |
<> | 149:156823d33999 | 1292 | |
<> | 149:156823d33999 | 1293 | /** |
<> | 149:156823d33999 | 1294 | * @brief TimeStamp callback. |
<> | 149:156823d33999 | 1295 | * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains |
<> | 149:156823d33999 | 1296 | * the configuration information for RTC. |
<> | 149:156823d33999 | 1297 | * @retval None |
<> | 149:156823d33999 | 1298 | */ |
<> | 149:156823d33999 | 1299 | __weak void HAL_RTCEx_TimeStampEventCallback(RTC_HandleTypeDef *hrtc) |
<> | 149:156823d33999 | 1300 | { |
<> | 149:156823d33999 | 1301 | /* Prevent unused argument(s) compilation warning */ |
<> | 149:156823d33999 | 1302 | UNUSED(hrtc); |
<> | 149:156823d33999 | 1303 | |
<> | 149:156823d33999 | 1304 | /* NOTE : This function Should not be modified, when the callback is needed, |
<> | 149:156823d33999 | 1305 | the HAL_RTCEx_TimeStampEventCallback could be implemented in the user file |
<> | 149:156823d33999 | 1306 | */ |
<> | 149:156823d33999 | 1307 | } |
<> | 149:156823d33999 | 1308 | |
<> | 149:156823d33999 | 1309 | /** |
<> | 149:156823d33999 | 1310 | * @brief Tamper 1 callback. |
<> | 149:156823d33999 | 1311 | * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains |
<> | 149:156823d33999 | 1312 | * the configuration information for RTC. |
<> | 149:156823d33999 | 1313 | * @retval None |
<> | 149:156823d33999 | 1314 | */ |
<> | 149:156823d33999 | 1315 | __weak void HAL_RTCEx_Tamper1EventCallback(RTC_HandleTypeDef *hrtc) |
<> | 149:156823d33999 | 1316 | { |
<> | 149:156823d33999 | 1317 | /* Prevent unused argument(s) compilation warning */ |
<> | 149:156823d33999 | 1318 | UNUSED(hrtc); |
<> | 149:156823d33999 | 1319 | |
<> | 149:156823d33999 | 1320 | /* NOTE : This function Should not be modified, when the callback is needed, |
<> | 149:156823d33999 | 1321 | the HAL_RTCEx_Tamper1EventCallback could be implemented in the user file |
<> | 149:156823d33999 | 1322 | */ |
<> | 149:156823d33999 | 1323 | } |
<> | 149:156823d33999 | 1324 | |
<> | 149:156823d33999 | 1325 | #if defined(STM32L100xBA) || defined (STM32L151xBA) || defined (STM32L152xBA) || defined(STM32L100xC) || defined (STM32L151xC) || defined (STM32L152xC) || defined (STM32L162xC) || defined(STM32L151xCA) || defined (STM32L151xD) || defined (STM32L152xCA) || defined (STM32L152xD) || defined (STM32L162xCA) || defined (STM32L162xD) || defined(STM32L151xE) || defined(STM32L151xDX) || defined (STM32L152xE) || defined (STM32L152xDX) || defined (STM32L162xE) || defined (STM32L162xDX) |
<> | 149:156823d33999 | 1326 | /** |
<> | 149:156823d33999 | 1327 | * @brief Tamper 2 callback. |
<> | 149:156823d33999 | 1328 | * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains |
<> | 149:156823d33999 | 1329 | * the configuration information for RTC. |
<> | 149:156823d33999 | 1330 | * @retval None |
<> | 149:156823d33999 | 1331 | */ |
<> | 149:156823d33999 | 1332 | __weak void HAL_RTCEx_Tamper2EventCallback(RTC_HandleTypeDef *hrtc) |
<> | 149:156823d33999 | 1333 | { |
<> | 149:156823d33999 | 1334 | /* Prevent unused argument(s) compilation warning */ |
<> | 149:156823d33999 | 1335 | UNUSED(hrtc); |
<> | 149:156823d33999 | 1336 | |
<> | 149:156823d33999 | 1337 | /* NOTE : This function should not be modified, when the callback is needed, |
<> | 149:156823d33999 | 1338 | the HAL_RTCEx_Tamper2EventCallback could be implemented in the user file |
<> | 149:156823d33999 | 1339 | */ |
<> | 149:156823d33999 | 1340 | } |
<> | 149:156823d33999 | 1341 | |
<> | 149:156823d33999 | 1342 | /** |
<> | 149:156823d33999 | 1343 | * @brief Tamper 3 callback. |
<> | 149:156823d33999 | 1344 | * @param hrtc: RTC handle |
<> | 149:156823d33999 | 1345 | * @retval None |
<> | 149:156823d33999 | 1346 | */ |
<> | 149:156823d33999 | 1347 | __weak void HAL_RTCEx_Tamper3EventCallback(RTC_HandleTypeDef *hrtc) |
<> | 149:156823d33999 | 1348 | { |
<> | 149:156823d33999 | 1349 | /* Prevent unused argument(s) compilation warning */ |
<> | 149:156823d33999 | 1350 | UNUSED(hrtc); |
<> | 149:156823d33999 | 1351 | |
<> | 149:156823d33999 | 1352 | /* NOTE : This function Should not be modified, when the callback is needed, |
<> | 149:156823d33999 | 1353 | the HAL_RTCEx_Tamper3EventCallback could be implemented in the user file |
<> | 149:156823d33999 | 1354 | */ |
<> | 149:156823d33999 | 1355 | } |
<> | 149:156823d33999 | 1356 | #endif /* STM32L100xBA || STM32L151xBA || STM32L152xBA || STM32L100xC || STM32L151xC || STM32L152xC || STM32L162xC || STM32L151xCA || STM32L151xD || STM32L152xCA || STM32L152xD || STM32L162xCA || STM32L162xD || STM32L151xE || STM32L151xDX || STM32L152xE || STM32L152xDX || STM32L162xE || STM32L162xDX */ |
<> | 149:156823d33999 | 1357 | |
<> | 149:156823d33999 | 1358 | /** |
<> | 149:156823d33999 | 1359 | * @brief This function handles TimeStamp polling request. |
<> | 149:156823d33999 | 1360 | * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains |
<> | 149:156823d33999 | 1361 | * the configuration information for RTC. |
<> | 149:156823d33999 | 1362 | * @param Timeout: Timeout duration |
<> | 149:156823d33999 | 1363 | * @retval HAL status |
<> | 149:156823d33999 | 1364 | */ |
<> | 149:156823d33999 | 1365 | HAL_StatusTypeDef HAL_RTCEx_PollForTimeStampEvent(RTC_HandleTypeDef *hrtc, uint32_t Timeout) |
<> | 149:156823d33999 | 1366 | { |
<> | 149:156823d33999 | 1367 | uint32_t tickstart = HAL_GetTick(); |
<> | 149:156823d33999 | 1368 | |
<> | 149:156823d33999 | 1369 | while(__HAL_RTC_TIMESTAMP_GET_FLAG(hrtc, RTC_FLAG_TSF) == RESET) |
<> | 149:156823d33999 | 1370 | { |
<> | 149:156823d33999 | 1371 | if(__HAL_RTC_TIMESTAMP_GET_FLAG(hrtc, RTC_FLAG_TSOVF) != RESET) |
<> | 149:156823d33999 | 1372 | { |
<> | 149:156823d33999 | 1373 | /* Clear the TIMESTAMP OverRun Flag */ |
<> | 149:156823d33999 | 1374 | __HAL_RTC_TIMESTAMP_CLEAR_FLAG(hrtc, RTC_FLAG_TSOVF); |
<> | 149:156823d33999 | 1375 | |
<> | 149:156823d33999 | 1376 | /* Change TIMESTAMP state */ |
<> | 149:156823d33999 | 1377 | hrtc->State = HAL_RTC_STATE_ERROR; |
<> | 149:156823d33999 | 1378 | |
<> | 149:156823d33999 | 1379 | return HAL_ERROR; |
<> | 149:156823d33999 | 1380 | } |
<> | 149:156823d33999 | 1381 | |
<> | 149:156823d33999 | 1382 | if(Timeout != HAL_MAX_DELAY) |
<> | 149:156823d33999 | 1383 | { |
<> | 149:156823d33999 | 1384 | if((Timeout == 0)||((HAL_GetTick() - tickstart ) > Timeout)) |
<> | 149:156823d33999 | 1385 | { |
<> | 149:156823d33999 | 1386 | hrtc->State = HAL_RTC_STATE_TIMEOUT; |
<> | 149:156823d33999 | 1387 | return HAL_TIMEOUT; |
<> | 149:156823d33999 | 1388 | } |
<> | 149:156823d33999 | 1389 | } |
<> | 149:156823d33999 | 1390 | } |
<> | 149:156823d33999 | 1391 | |
<> | 149:156823d33999 | 1392 | /* Change RTC state */ |
<> | 149:156823d33999 | 1393 | hrtc->State = HAL_RTC_STATE_READY; |
<> | 149:156823d33999 | 1394 | |
<> | 149:156823d33999 | 1395 | return HAL_OK; |
<> | 149:156823d33999 | 1396 | } |
<> | 149:156823d33999 | 1397 | |
<> | 149:156823d33999 | 1398 | /** |
<> | 149:156823d33999 | 1399 | * @brief This function handles Tamper1 Polling. |
<> | 149:156823d33999 | 1400 | * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains |
<> | 149:156823d33999 | 1401 | * the configuration information for RTC. |
<> | 149:156823d33999 | 1402 | * @param Timeout: Timeout duration |
<> | 149:156823d33999 | 1403 | * @retval HAL status |
<> | 149:156823d33999 | 1404 | */ |
<> | 149:156823d33999 | 1405 | HAL_StatusTypeDef HAL_RTCEx_PollForTamper1Event(RTC_HandleTypeDef *hrtc, uint32_t Timeout) |
<> | 149:156823d33999 | 1406 | { |
<> | 149:156823d33999 | 1407 | uint32_t tickstart = HAL_GetTick(); |
<> | 149:156823d33999 | 1408 | |
<> | 149:156823d33999 | 1409 | /* Get the status of the Interrupt */ |
<> | 149:156823d33999 | 1410 | while(__HAL_RTC_TAMPER_GET_FLAG(hrtc,RTC_FLAG_TAMP1F)== RESET) |
<> | 149:156823d33999 | 1411 | { |
<> | 149:156823d33999 | 1412 | if(Timeout != HAL_MAX_DELAY) |
<> | 149:156823d33999 | 1413 | { |
<> | 149:156823d33999 | 1414 | if((Timeout == 0)||((HAL_GetTick() - tickstart ) > Timeout)) |
<> | 149:156823d33999 | 1415 | { |
<> | 149:156823d33999 | 1416 | hrtc->State = HAL_RTC_STATE_TIMEOUT; |
<> | 149:156823d33999 | 1417 | return HAL_TIMEOUT; |
<> | 149:156823d33999 | 1418 | } |
<> | 149:156823d33999 | 1419 | } |
<> | 149:156823d33999 | 1420 | } |
<> | 149:156823d33999 | 1421 | |
<> | 149:156823d33999 | 1422 | /* Clear the Tamper Flag */ |
<> | 149:156823d33999 | 1423 | __HAL_RTC_TAMPER_CLEAR_FLAG(hrtc,RTC_FLAG_TAMP1F); |
<> | 149:156823d33999 | 1424 | |
<> | 149:156823d33999 | 1425 | /* Change RTC state */ |
<> | 149:156823d33999 | 1426 | hrtc->State = HAL_RTC_STATE_READY; |
<> | 149:156823d33999 | 1427 | |
<> | 149:156823d33999 | 1428 | return HAL_OK; |
<> | 149:156823d33999 | 1429 | } |
<> | 149:156823d33999 | 1430 | |
<> | 149:156823d33999 | 1431 | #if defined(STM32L100xBA) || defined (STM32L151xBA) || defined (STM32L152xBA) || defined(STM32L100xC) || defined (STM32L151xC) || defined (STM32L152xC) || defined (STM32L162xC) || defined(STM32L151xCA) || defined (STM32L151xD) || defined (STM32L152xCA) || defined (STM32L152xD) || defined (STM32L162xCA) || defined (STM32L162xD) || defined(STM32L151xE) || defined(STM32L151xDX) || defined (STM32L152xE) || defined (STM32L152xDX) || defined (STM32L162xE) || defined (STM32L162xDX) |
<> | 149:156823d33999 | 1432 | /** |
<> | 149:156823d33999 | 1433 | * @brief This function handles Tamper2 Polling. |
<> | 149:156823d33999 | 1434 | * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains |
<> | 149:156823d33999 | 1435 | * the configuration information for RTC. |
<> | 149:156823d33999 | 1436 | * @param Timeout: Timeout duration |
<> | 149:156823d33999 | 1437 | * @retval HAL status |
<> | 149:156823d33999 | 1438 | */ |
<> | 149:156823d33999 | 1439 | HAL_StatusTypeDef HAL_RTCEx_PollForTamper2Event(RTC_HandleTypeDef *hrtc, uint32_t Timeout) |
<> | 149:156823d33999 | 1440 | { |
<> | 149:156823d33999 | 1441 | uint32_t tickstart = HAL_GetTick(); |
<> | 149:156823d33999 | 1442 | |
<> | 149:156823d33999 | 1443 | /* Get the status of the Interrupt */ |
<> | 149:156823d33999 | 1444 | while(__HAL_RTC_TAMPER_GET_FLAG(hrtc,RTC_FLAG_TAMP2F) == RESET) |
<> | 149:156823d33999 | 1445 | { |
<> | 149:156823d33999 | 1446 | if(Timeout != HAL_MAX_DELAY) |
<> | 149:156823d33999 | 1447 | { |
<> | 149:156823d33999 | 1448 | if((Timeout == 0)||((HAL_GetTick() - tickstart ) > Timeout)) |
<> | 149:156823d33999 | 1449 | { |
<> | 149:156823d33999 | 1450 | hrtc->State = HAL_RTC_STATE_TIMEOUT; |
<> | 149:156823d33999 | 1451 | return HAL_TIMEOUT; |
<> | 149:156823d33999 | 1452 | } |
<> | 149:156823d33999 | 1453 | } |
<> | 149:156823d33999 | 1454 | } |
<> | 149:156823d33999 | 1455 | |
<> | 149:156823d33999 | 1456 | /* Clear the Tamper Flag */ |
<> | 149:156823d33999 | 1457 | __HAL_RTC_TAMPER_CLEAR_FLAG(hrtc,RTC_FLAG_TAMP2F); |
<> | 149:156823d33999 | 1458 | |
<> | 149:156823d33999 | 1459 | /* Change RTC state */ |
<> | 149:156823d33999 | 1460 | hrtc->State = HAL_RTC_STATE_READY; |
<> | 149:156823d33999 | 1461 | |
<> | 149:156823d33999 | 1462 | return HAL_OK; |
<> | 149:156823d33999 | 1463 | } |
<> | 149:156823d33999 | 1464 | |
<> | 149:156823d33999 | 1465 | /** |
<> | 149:156823d33999 | 1466 | * @brief This function handles Tamper3 Polling. |
<> | 149:156823d33999 | 1467 | * @param hrtc: RTC handle |
<> | 149:156823d33999 | 1468 | * @param Timeout: Timeout duration |
<> | 149:156823d33999 | 1469 | * @retval HAL status |
<> | 149:156823d33999 | 1470 | */ |
<> | 149:156823d33999 | 1471 | HAL_StatusTypeDef HAL_RTCEx_PollForTamper3Event(RTC_HandleTypeDef *hrtc, uint32_t Timeout) |
<> | 149:156823d33999 | 1472 | { |
<> | 149:156823d33999 | 1473 | uint32_t tickstart = HAL_GetTick(); |
<> | 149:156823d33999 | 1474 | |
<> | 149:156823d33999 | 1475 | /* Get the status of the Interrupt */ |
<> | 149:156823d33999 | 1476 | while(__HAL_RTC_TAMPER_GET_FLAG(hrtc,RTC_FLAG_TAMP3F) == RESET) |
<> | 149:156823d33999 | 1477 | { |
<> | 149:156823d33999 | 1478 | if(Timeout != HAL_MAX_DELAY) |
<> | 149:156823d33999 | 1479 | { |
<> | 149:156823d33999 | 1480 | if((Timeout == 0)||((HAL_GetTick() - tickstart ) > Timeout)) |
<> | 149:156823d33999 | 1481 | { |
<> | 149:156823d33999 | 1482 | hrtc->State = HAL_RTC_STATE_TIMEOUT; |
<> | 149:156823d33999 | 1483 | return HAL_TIMEOUT; |
<> | 149:156823d33999 | 1484 | } |
<> | 149:156823d33999 | 1485 | } |
<> | 149:156823d33999 | 1486 | } |
<> | 149:156823d33999 | 1487 | |
<> | 149:156823d33999 | 1488 | /* Clear the Tamper Flag */ |
<> | 149:156823d33999 | 1489 | __HAL_RTC_TAMPER_CLEAR_FLAG(hrtc,RTC_FLAG_TAMP3F); |
<> | 149:156823d33999 | 1490 | |
<> | 149:156823d33999 | 1491 | /* Change RTC state */ |
<> | 149:156823d33999 | 1492 | hrtc->State = HAL_RTC_STATE_READY; |
<> | 149:156823d33999 | 1493 | |
<> | 149:156823d33999 | 1494 | return HAL_OK; |
<> | 149:156823d33999 | 1495 | } |
<> | 149:156823d33999 | 1496 | #endif /* STM32L100xBA || STM32L151xBA || STM32L152xBA || STM32L100xC || STM32L151xC || STM32L152xC || STM32L162xC || STM32L151xCA || STM32L151xD || STM32L152xCA || STM32L152xD || STM32L162xCA || STM32L162xD || STM32L151xE || STM32L151xDX || STM32L152xE || STM32L152xDX || STM32L162xE || STM32L162xDX */ |
<> | 149:156823d33999 | 1497 | |
<> | 149:156823d33999 | 1498 | /** |
<> | 149:156823d33999 | 1499 | * @} |
<> | 149:156823d33999 | 1500 | */ |
<> | 149:156823d33999 | 1501 | |
<> | 149:156823d33999 | 1502 | /** @defgroup RTCEx_Exported_Functions_Group5 RTC Wake-up functions |
<> | 149:156823d33999 | 1503 | * @brief RTC Wake-up functions |
<> | 149:156823d33999 | 1504 | * |
<> | 149:156823d33999 | 1505 | @verbatim |
<> | 149:156823d33999 | 1506 | =============================================================================== |
<> | 149:156823d33999 | 1507 | ##### RTC Wake-up functions ##### |
<> | 149:156823d33999 | 1508 | =============================================================================== |
<> | 149:156823d33999 | 1509 | |
<> | 149:156823d33999 | 1510 | [..] This section provides functions allowing to configure Wake-up feature |
<> | 149:156823d33999 | 1511 | |
<> | 149:156823d33999 | 1512 | @endverbatim |
<> | 149:156823d33999 | 1513 | * @{ |
<> | 149:156823d33999 | 1514 | */ |
<> | 149:156823d33999 | 1515 | |
<> | 149:156823d33999 | 1516 | /** |
<> | 149:156823d33999 | 1517 | * @brief Set wake up timer. |
<> | 149:156823d33999 | 1518 | * @param hrtc: RTC handle |
<> | 149:156823d33999 | 1519 | * @param WakeUpCounter: Wake up counter |
<> | 149:156823d33999 | 1520 | * @param WakeUpClock: Wake up clock |
<> | 149:156823d33999 | 1521 | * @retval HAL status |
<> | 149:156823d33999 | 1522 | */ |
<> | 149:156823d33999 | 1523 | HAL_StatusTypeDef HAL_RTCEx_SetWakeUpTimer(RTC_HandleTypeDef *hrtc, uint32_t WakeUpCounter, uint32_t WakeUpClock) |
<> | 149:156823d33999 | 1524 | { |
<> | 149:156823d33999 | 1525 | uint32_t tickstart = 0; |
<> | 149:156823d33999 | 1526 | |
<> | 149:156823d33999 | 1527 | /* Check the parameters */ |
<> | 149:156823d33999 | 1528 | assert_param(IS_RTC_WAKEUP_CLOCK(WakeUpClock)); |
<> | 149:156823d33999 | 1529 | assert_param(IS_RTC_WAKEUP_COUNTER(WakeUpCounter)); |
<> | 149:156823d33999 | 1530 | |
<> | 149:156823d33999 | 1531 | /* Process Locked */ |
<> | 149:156823d33999 | 1532 | __HAL_LOCK(hrtc); |
<> | 149:156823d33999 | 1533 | |
<> | 149:156823d33999 | 1534 | hrtc->State = HAL_RTC_STATE_BUSY; |
<> | 149:156823d33999 | 1535 | |
<> | 149:156823d33999 | 1536 | /* Disable the write protection for RTC registers */ |
<> | 149:156823d33999 | 1537 | __HAL_RTC_WRITEPROTECTION_DISABLE(hrtc); |
<> | 149:156823d33999 | 1538 | |
<> | 149:156823d33999 | 1539 | /*Check RTC WUTWF flag is reset only when wake up timer enabled*/ |
<> | 149:156823d33999 | 1540 | if((hrtc->Instance->CR & RTC_CR_WUTE) != RESET){ |
<> | 149:156823d33999 | 1541 | tickstart = HAL_GetTick(); |
<> | 149:156823d33999 | 1542 | |
<> | 149:156823d33999 | 1543 | /* Wait till RTC WUTWF flag is reset and if Time out is reached exit */ |
<> | 149:156823d33999 | 1544 | while(__HAL_RTC_WAKEUPTIMER_GET_FLAG(hrtc, RTC_FLAG_WUTWF) == SET) |
<> | 149:156823d33999 | 1545 | { |
<> | 149:156823d33999 | 1546 | if((HAL_GetTick() - tickstart ) > RTC_TIMEOUT_VALUE) |
<> | 149:156823d33999 | 1547 | { |
<> | 149:156823d33999 | 1548 | /* Enable the write protection for RTC registers */ |
<> | 149:156823d33999 | 1549 | __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc); |
<> | 149:156823d33999 | 1550 | |
<> | 149:156823d33999 | 1551 | hrtc->State = HAL_RTC_STATE_TIMEOUT; |
<> | 149:156823d33999 | 1552 | |
<> | 149:156823d33999 | 1553 | /* Process Unlocked */ |
<> | 149:156823d33999 | 1554 | __HAL_UNLOCK(hrtc); |
<> | 149:156823d33999 | 1555 | |
<> | 149:156823d33999 | 1556 | return HAL_TIMEOUT; |
<> | 149:156823d33999 | 1557 | } |
<> | 149:156823d33999 | 1558 | } |
<> | 149:156823d33999 | 1559 | } |
<> | 149:156823d33999 | 1560 | |
<> | 149:156823d33999 | 1561 | __HAL_RTC_WAKEUPTIMER_DISABLE(hrtc); |
<> | 149:156823d33999 | 1562 | |
<> | 149:156823d33999 | 1563 | tickstart = HAL_GetTick(); |
<> | 149:156823d33999 | 1564 | |
<> | 149:156823d33999 | 1565 | /* Wait till RTC WUTWF flag is set and if Time out is reached exit */ |
<> | 149:156823d33999 | 1566 | while(__HAL_RTC_WAKEUPTIMER_GET_FLAG(hrtc, RTC_FLAG_WUTWF) == RESET) |
<> | 149:156823d33999 | 1567 | { |
<> | 149:156823d33999 | 1568 | if((HAL_GetTick() - tickstart ) > RTC_TIMEOUT_VALUE) |
<> | 149:156823d33999 | 1569 | { |
<> | 149:156823d33999 | 1570 | /* Enable the write protection for RTC registers */ |
<> | 149:156823d33999 | 1571 | __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc); |
<> | 149:156823d33999 | 1572 | |
<> | 149:156823d33999 | 1573 | hrtc->State = HAL_RTC_STATE_TIMEOUT; |
<> | 149:156823d33999 | 1574 | |
<> | 149:156823d33999 | 1575 | /* Process Unlocked */ |
<> | 149:156823d33999 | 1576 | __HAL_UNLOCK(hrtc); |
<> | 149:156823d33999 | 1577 | |
<> | 149:156823d33999 | 1578 | return HAL_TIMEOUT; |
<> | 149:156823d33999 | 1579 | } |
<> | 149:156823d33999 | 1580 | } |
<> | 149:156823d33999 | 1581 | |
<> | 149:156823d33999 | 1582 | /* Clear the Wakeup Timer clock source bits in CR register */ |
<> | 149:156823d33999 | 1583 | hrtc->Instance->CR &= (uint32_t)~RTC_CR_WUCKSEL; |
<> | 149:156823d33999 | 1584 | |
<> | 149:156823d33999 | 1585 | /* Configure the clock source */ |
<> | 149:156823d33999 | 1586 | hrtc->Instance->CR |= (uint32_t)WakeUpClock; |
<> | 149:156823d33999 | 1587 | |
<> | 149:156823d33999 | 1588 | /* Configure the Wakeup Timer counter */ |
<> | 149:156823d33999 | 1589 | hrtc->Instance->WUTR = (uint32_t)WakeUpCounter; |
<> | 149:156823d33999 | 1590 | |
<> | 149:156823d33999 | 1591 | /* Enable the Wakeup Timer */ |
<> | 149:156823d33999 | 1592 | __HAL_RTC_WAKEUPTIMER_ENABLE(hrtc); |
<> | 149:156823d33999 | 1593 | |
<> | 149:156823d33999 | 1594 | /* Enable the write protection for RTC registers */ |
<> | 149:156823d33999 | 1595 | __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc); |
<> | 149:156823d33999 | 1596 | |
<> | 149:156823d33999 | 1597 | hrtc->State = HAL_RTC_STATE_READY; |
<> | 149:156823d33999 | 1598 | |
<> | 149:156823d33999 | 1599 | /* Process Unlocked */ |
<> | 149:156823d33999 | 1600 | __HAL_UNLOCK(hrtc); |
<> | 149:156823d33999 | 1601 | |
<> | 149:156823d33999 | 1602 | return HAL_OK; |
<> | 149:156823d33999 | 1603 | } |
<> | 149:156823d33999 | 1604 | |
<> | 149:156823d33999 | 1605 | /** |
<> | 149:156823d33999 | 1606 | * @brief Set wake up timer with interrupt. |
<> | 149:156823d33999 | 1607 | * @param hrtc: RTC handle |
<> | 149:156823d33999 | 1608 | * @param WakeUpCounter: Wake up counter |
<> | 149:156823d33999 | 1609 | * @param WakeUpClock: Wake up clock |
<> | 149:156823d33999 | 1610 | * @retval HAL status |
<> | 149:156823d33999 | 1611 | */ |
<> | 149:156823d33999 | 1612 | HAL_StatusTypeDef HAL_RTCEx_SetWakeUpTimer_IT(RTC_HandleTypeDef *hrtc, uint32_t WakeUpCounter, uint32_t WakeUpClock) |
<> | 149:156823d33999 | 1613 | { |
<> | 149:156823d33999 | 1614 | uint32_t tickstart = 0; |
<> | 149:156823d33999 | 1615 | |
<> | 149:156823d33999 | 1616 | /* Check the parameters */ |
<> | 149:156823d33999 | 1617 | assert_param(IS_RTC_WAKEUP_CLOCK(WakeUpClock)); |
<> | 149:156823d33999 | 1618 | assert_param(IS_RTC_WAKEUP_COUNTER(WakeUpCounter)); |
<> | 149:156823d33999 | 1619 | |
<> | 149:156823d33999 | 1620 | /* Process Locked */ |
<> | 149:156823d33999 | 1621 | __HAL_LOCK(hrtc); |
<> | 149:156823d33999 | 1622 | |
<> | 149:156823d33999 | 1623 | hrtc->State = HAL_RTC_STATE_BUSY; |
<> | 149:156823d33999 | 1624 | |
<> | 149:156823d33999 | 1625 | /* Disable the write protection for RTC registers */ |
<> | 149:156823d33999 | 1626 | __HAL_RTC_WRITEPROTECTION_DISABLE(hrtc); |
<> | 149:156823d33999 | 1627 | |
<> | 149:156823d33999 | 1628 | /*Check RTC WUTWF flag is reset only when wake up timer enabled*/ |
<> | 149:156823d33999 | 1629 | if((hrtc->Instance->CR & RTC_CR_WUTE) != RESET){ |
<> | 149:156823d33999 | 1630 | tickstart = HAL_GetTick(); |
<> | 149:156823d33999 | 1631 | |
<> | 149:156823d33999 | 1632 | /* Wait till RTC WUTWF flag is reset and if Time out is reached exit */ |
<> | 149:156823d33999 | 1633 | while(__HAL_RTC_WAKEUPTIMER_GET_FLAG(hrtc, RTC_FLAG_WUTWF) == SET) |
<> | 149:156823d33999 | 1634 | { |
<> | 149:156823d33999 | 1635 | if((HAL_GetTick() - tickstart ) > RTC_TIMEOUT_VALUE) |
<> | 149:156823d33999 | 1636 | { |
<> | 149:156823d33999 | 1637 | /* Enable the write protection for RTC registers */ |
<> | 149:156823d33999 | 1638 | __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc); |
<> | 149:156823d33999 | 1639 | |
<> | 149:156823d33999 | 1640 | hrtc->State = HAL_RTC_STATE_TIMEOUT; |
<> | 149:156823d33999 | 1641 | |
<> | 149:156823d33999 | 1642 | /* Process Unlocked */ |
<> | 149:156823d33999 | 1643 | __HAL_UNLOCK(hrtc); |
<> | 149:156823d33999 | 1644 | |
<> | 149:156823d33999 | 1645 | return HAL_TIMEOUT; |
<> | 149:156823d33999 | 1646 | } |
<> | 149:156823d33999 | 1647 | } |
<> | 149:156823d33999 | 1648 | } |
<> | 149:156823d33999 | 1649 | |
<> | 149:156823d33999 | 1650 | /* Disable the Wake-Up timer */ |
<> | 149:156823d33999 | 1651 | __HAL_RTC_WAKEUPTIMER_DISABLE(hrtc); |
<> | 149:156823d33999 | 1652 | |
<> | 149:156823d33999 | 1653 | /* Clear flag Wake-Up */ |
<> | 149:156823d33999 | 1654 | __HAL_RTC_WAKEUPTIMER_CLEAR_FLAG(hrtc, RTC_FLAG_WUTF); |
<> | 149:156823d33999 | 1655 | |
<> | 149:156823d33999 | 1656 | tickstart = HAL_GetTick(); |
<> | 149:156823d33999 | 1657 | |
<> | 149:156823d33999 | 1658 | /* Wait till RTC WUTWF flag is set and if Time out is reached exit */ |
<> | 149:156823d33999 | 1659 | while(__HAL_RTC_WAKEUPTIMER_GET_FLAG(hrtc, RTC_FLAG_WUTWF) == RESET) |
<> | 149:156823d33999 | 1660 | { |
<> | 149:156823d33999 | 1661 | if((HAL_GetTick() - tickstart ) > RTC_TIMEOUT_VALUE) |
<> | 149:156823d33999 | 1662 | { |
<> | 149:156823d33999 | 1663 | /* Enable the write protection for RTC registers */ |
<> | 149:156823d33999 | 1664 | __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc); |
<> | 149:156823d33999 | 1665 | |
<> | 149:156823d33999 | 1666 | hrtc->State = HAL_RTC_STATE_TIMEOUT; |
<> | 149:156823d33999 | 1667 | |
<> | 149:156823d33999 | 1668 | /* Process Unlocked */ |
<> | 149:156823d33999 | 1669 | __HAL_UNLOCK(hrtc); |
<> | 149:156823d33999 | 1670 | |
<> | 149:156823d33999 | 1671 | return HAL_TIMEOUT; |
<> | 149:156823d33999 | 1672 | } |
<> | 149:156823d33999 | 1673 | } |
<> | 149:156823d33999 | 1674 | |
<> | 149:156823d33999 | 1675 | /* Configure the Wakeup Timer counter */ |
<> | 149:156823d33999 | 1676 | hrtc->Instance->WUTR = (uint32_t)WakeUpCounter; |
<> | 149:156823d33999 | 1677 | |
<> | 149:156823d33999 | 1678 | /* Clear the Wakeup Timer clock source bits in CR register */ |
<> | 149:156823d33999 | 1679 | hrtc->Instance->CR &= (uint32_t)~RTC_CR_WUCKSEL; |
<> | 149:156823d33999 | 1680 | |
<> | 149:156823d33999 | 1681 | /* Configure the clock source */ |
<> | 149:156823d33999 | 1682 | hrtc->Instance->CR |= (uint32_t)WakeUpClock; |
<> | 149:156823d33999 | 1683 | |
<> | 149:156823d33999 | 1684 | /* RTC WakeUpTimer Interrupt Configuration: EXTI configuration */ |
<> | 149:156823d33999 | 1685 | __HAL_RTC_WAKEUPTIMER_EXTI_ENABLE_IT(); |
<> | 149:156823d33999 | 1686 | |
<> | 149:156823d33999 | 1687 | __HAL_RTC_WAKEUPTIMER_EXTI_ENABLE_RISING_EDGE(); |
<> | 149:156823d33999 | 1688 | |
<> | 149:156823d33999 | 1689 | /* Configure the Interrupt in the RTC_CR register */ |
<> | 149:156823d33999 | 1690 | __HAL_RTC_WAKEUPTIMER_ENABLE_IT(hrtc,RTC_IT_WUT); |
<> | 149:156823d33999 | 1691 | |
<> | 149:156823d33999 | 1692 | /* Enable the Wakeup Timer */ |
<> | 149:156823d33999 | 1693 | __HAL_RTC_WAKEUPTIMER_ENABLE(hrtc); |
<> | 149:156823d33999 | 1694 | |
<> | 149:156823d33999 | 1695 | /* Enable the write protection for RTC registers */ |
<> | 149:156823d33999 | 1696 | __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc); |
<> | 149:156823d33999 | 1697 | |
<> | 149:156823d33999 | 1698 | hrtc->State = HAL_RTC_STATE_READY; |
<> | 149:156823d33999 | 1699 | |
<> | 149:156823d33999 | 1700 | /* Process Unlocked */ |
<> | 149:156823d33999 | 1701 | __HAL_UNLOCK(hrtc); |
<> | 149:156823d33999 | 1702 | |
<> | 149:156823d33999 | 1703 | return HAL_OK; |
<> | 149:156823d33999 | 1704 | } |
<> | 149:156823d33999 | 1705 | |
<> | 149:156823d33999 | 1706 | /** |
<> | 149:156823d33999 | 1707 | * @brief Deactivates wake up timer counter. |
<> | 149:156823d33999 | 1708 | * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains |
<> | 149:156823d33999 | 1709 | * the configuration information for RTC. |
<> | 149:156823d33999 | 1710 | * @retval HAL status |
<> | 149:156823d33999 | 1711 | */ |
<> | 149:156823d33999 | 1712 | uint32_t HAL_RTCEx_DeactivateWakeUpTimer(RTC_HandleTypeDef *hrtc) |
<> | 149:156823d33999 | 1713 | { |
<> | 149:156823d33999 | 1714 | uint32_t tickstart = 0; |
<> | 149:156823d33999 | 1715 | |
<> | 149:156823d33999 | 1716 | /* Process Locked */ |
<> | 149:156823d33999 | 1717 | __HAL_LOCK(hrtc); |
<> | 149:156823d33999 | 1718 | |
<> | 149:156823d33999 | 1719 | hrtc->State = HAL_RTC_STATE_BUSY; |
<> | 149:156823d33999 | 1720 | |
<> | 149:156823d33999 | 1721 | /* Disable the write protection for RTC registers */ |
<> | 149:156823d33999 | 1722 | __HAL_RTC_WRITEPROTECTION_DISABLE(hrtc); |
<> | 149:156823d33999 | 1723 | |
<> | 149:156823d33999 | 1724 | /* Disable the Wakeup Timer */ |
<> | 149:156823d33999 | 1725 | __HAL_RTC_WAKEUPTIMER_DISABLE(hrtc); |
<> | 149:156823d33999 | 1726 | |
<> | 149:156823d33999 | 1727 | /* In case of interrupt mode is used, the interrupt source must disabled */ |
<> | 149:156823d33999 | 1728 | __HAL_RTC_WAKEUPTIMER_DISABLE_IT(hrtc,RTC_IT_WUT); |
<> | 149:156823d33999 | 1729 | |
<> | 149:156823d33999 | 1730 | tickstart = HAL_GetTick(); |
<> | 149:156823d33999 | 1731 | /* Wait till RTC WUTWF flag is set and if Time out is reached exit */ |
<> | 149:156823d33999 | 1732 | while(__HAL_RTC_WAKEUPTIMER_GET_FLAG(hrtc, RTC_FLAG_WUTWF) == RESET) |
<> | 149:156823d33999 | 1733 | { |
<> | 149:156823d33999 | 1734 | if((HAL_GetTick() - tickstart ) > RTC_TIMEOUT_VALUE) |
<> | 149:156823d33999 | 1735 | { |
<> | 149:156823d33999 | 1736 | /* Enable the write protection for RTC registers */ |
<> | 149:156823d33999 | 1737 | __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc); |
<> | 149:156823d33999 | 1738 | |
<> | 149:156823d33999 | 1739 | hrtc->State = HAL_RTC_STATE_TIMEOUT; |
<> | 149:156823d33999 | 1740 | |
<> | 149:156823d33999 | 1741 | /* Process Unlocked */ |
<> | 149:156823d33999 | 1742 | __HAL_UNLOCK(hrtc); |
<> | 149:156823d33999 | 1743 | |
<> | 149:156823d33999 | 1744 | return HAL_TIMEOUT; |
<> | 149:156823d33999 | 1745 | } |
<> | 149:156823d33999 | 1746 | } |
<> | 149:156823d33999 | 1747 | |
<> | 149:156823d33999 | 1748 | /* Enable the write protection for RTC registers */ |
<> | 149:156823d33999 | 1749 | __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc); |
<> | 149:156823d33999 | 1750 | |
<> | 149:156823d33999 | 1751 | hrtc->State = HAL_RTC_STATE_READY; |
<> | 149:156823d33999 | 1752 | |
<> | 149:156823d33999 | 1753 | /* Process Unlocked */ |
<> | 149:156823d33999 | 1754 | __HAL_UNLOCK(hrtc); |
<> | 149:156823d33999 | 1755 | |
<> | 149:156823d33999 | 1756 | return HAL_OK; |
<> | 149:156823d33999 | 1757 | } |
<> | 149:156823d33999 | 1758 | |
<> | 149:156823d33999 | 1759 | /** |
<> | 149:156823d33999 | 1760 | * @brief Gets wake up timer counter. |
<> | 149:156823d33999 | 1761 | * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains |
<> | 149:156823d33999 | 1762 | * the configuration information for RTC. |
<> | 149:156823d33999 | 1763 | * @retval Counter value |
<> | 149:156823d33999 | 1764 | */ |
<> | 149:156823d33999 | 1765 | uint32_t HAL_RTCEx_GetWakeUpTimer(RTC_HandleTypeDef *hrtc) |
<> | 149:156823d33999 | 1766 | { |
<> | 149:156823d33999 | 1767 | /* Get the counter value */ |
<> | 149:156823d33999 | 1768 | return ((uint32_t)(hrtc->Instance->WUTR & RTC_WUTR_WUT)); |
<> | 149:156823d33999 | 1769 | } |
<> | 149:156823d33999 | 1770 | |
<> | 149:156823d33999 | 1771 | /** |
<> | 149:156823d33999 | 1772 | * @brief This function handles Wake Up Timer interrupt request. |
<> | 149:156823d33999 | 1773 | * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains |
<> | 149:156823d33999 | 1774 | * the configuration information for RTC. |
<> | 149:156823d33999 | 1775 | * @retval None |
<> | 149:156823d33999 | 1776 | */ |
<> | 149:156823d33999 | 1777 | void HAL_RTCEx_WakeUpTimerIRQHandler(RTC_HandleTypeDef *hrtc) |
<> | 149:156823d33999 | 1778 | { |
<> | 149:156823d33999 | 1779 | /* Get the pending status of the WAKEUPTIMER Interrupt */ |
<> | 149:156823d33999 | 1780 | if(__HAL_RTC_WAKEUPTIMER_GET_FLAG(hrtc, RTC_FLAG_WUTF) != RESET) |
<> | 149:156823d33999 | 1781 | { |
<> | 149:156823d33999 | 1782 | /* WAKEUPTIMER callback */ |
<> | 149:156823d33999 | 1783 | HAL_RTCEx_WakeUpTimerEventCallback(hrtc); |
<> | 149:156823d33999 | 1784 | |
<> | 149:156823d33999 | 1785 | /* Clear the WAKEUPTIMER interrupt pending bit */ |
<> | 149:156823d33999 | 1786 | __HAL_RTC_WAKEUPTIMER_CLEAR_FLAG(hrtc, RTC_FLAG_WUTF); |
<> | 149:156823d33999 | 1787 | } |
<> | 149:156823d33999 | 1788 | |
<> | 149:156823d33999 | 1789 | |
<> | 149:156823d33999 | 1790 | /* Clear the EXTI's line Flag for RTC WakeUpTimer */ |
<> | 149:156823d33999 | 1791 | __HAL_RTC_WAKEUPTIMER_EXTI_CLEAR_FLAG(); |
<> | 149:156823d33999 | 1792 | |
<> | 149:156823d33999 | 1793 | /* Change RTC state */ |
<> | 149:156823d33999 | 1794 | hrtc->State = HAL_RTC_STATE_READY; |
<> | 149:156823d33999 | 1795 | } |
<> | 149:156823d33999 | 1796 | |
<> | 149:156823d33999 | 1797 | /** |
<> | 149:156823d33999 | 1798 | * @brief Wake Up Timer callback. |
<> | 149:156823d33999 | 1799 | * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains |
<> | 149:156823d33999 | 1800 | * the configuration information for RTC. |
<> | 149:156823d33999 | 1801 | * @retval None |
<> | 149:156823d33999 | 1802 | */ |
<> | 149:156823d33999 | 1803 | __weak void HAL_RTCEx_WakeUpTimerEventCallback(RTC_HandleTypeDef *hrtc) |
<> | 149:156823d33999 | 1804 | { |
<> | 149:156823d33999 | 1805 | /* Prevent unused argument(s) compilation warning */ |
<> | 149:156823d33999 | 1806 | UNUSED(hrtc); |
<> | 149:156823d33999 | 1807 | |
<> | 149:156823d33999 | 1808 | /* NOTE : This function Should not be modified, when the callback is needed, |
<> | 149:156823d33999 | 1809 | the HAL_RTCEx_WakeUpTimerEventCallback could be implemented in the user file |
<> | 149:156823d33999 | 1810 | */ |
<> | 149:156823d33999 | 1811 | } |
<> | 149:156823d33999 | 1812 | |
<> | 149:156823d33999 | 1813 | /** |
<> | 149:156823d33999 | 1814 | * @brief This function handles Wake Up Timer Polling. |
<> | 149:156823d33999 | 1815 | * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains |
<> | 149:156823d33999 | 1816 | * the configuration information for RTC. |
<> | 149:156823d33999 | 1817 | * @param Timeout: Timeout duration |
<> | 149:156823d33999 | 1818 | * @retval HAL status |
<> | 149:156823d33999 | 1819 | */ |
<> | 149:156823d33999 | 1820 | HAL_StatusTypeDef HAL_RTCEx_PollForWakeUpTimerEvent(RTC_HandleTypeDef *hrtc, uint32_t Timeout) |
<> | 149:156823d33999 | 1821 | { |
<> | 149:156823d33999 | 1822 | uint32_t tickstart = HAL_GetTick(); |
<> | 149:156823d33999 | 1823 | |
<> | 149:156823d33999 | 1824 | while(__HAL_RTC_WAKEUPTIMER_GET_FLAG(hrtc, RTC_FLAG_WUTF) == RESET) |
<> | 149:156823d33999 | 1825 | { |
<> | 149:156823d33999 | 1826 | if(Timeout != HAL_MAX_DELAY) |
<> | 149:156823d33999 | 1827 | { |
<> | 149:156823d33999 | 1828 | if((Timeout == 0)||((HAL_GetTick() - tickstart ) > Timeout)) |
<> | 149:156823d33999 | 1829 | { |
<> | 149:156823d33999 | 1830 | hrtc->State = HAL_RTC_STATE_TIMEOUT; |
<> | 149:156823d33999 | 1831 | |
<> | 149:156823d33999 | 1832 | return HAL_TIMEOUT; |
<> | 149:156823d33999 | 1833 | } |
<> | 149:156823d33999 | 1834 | } |
<> | 149:156823d33999 | 1835 | } |
<> | 149:156823d33999 | 1836 | |
<> | 149:156823d33999 | 1837 | /* Clear the WAKEUPTIMER Flag */ |
<> | 149:156823d33999 | 1838 | __HAL_RTC_WAKEUPTIMER_CLEAR_FLAG(hrtc, RTC_FLAG_WUTF); |
<> | 149:156823d33999 | 1839 | |
<> | 149:156823d33999 | 1840 | /* Change RTC state */ |
<> | 149:156823d33999 | 1841 | hrtc->State = HAL_RTC_STATE_READY; |
<> | 149:156823d33999 | 1842 | |
<> | 149:156823d33999 | 1843 | return HAL_OK; |
<> | 149:156823d33999 | 1844 | } |
<> | 149:156823d33999 | 1845 | |
<> | 149:156823d33999 | 1846 | /** |
<> | 149:156823d33999 | 1847 | * @} |
<> | 149:156823d33999 | 1848 | */ |
<> | 149:156823d33999 | 1849 | |
<> | 149:156823d33999 | 1850 | /** @defgroup RTCEx_Exported_Functions_Group7 Extended Peripheral Control functions |
<> | 149:156823d33999 | 1851 | * @brief Extended Peripheral Control functions |
<> | 149:156823d33999 | 1852 | * |
<> | 149:156823d33999 | 1853 | @verbatim |
<> | 149:156823d33999 | 1854 | =============================================================================== |
<> | 149:156823d33999 | 1855 | ##### Extension Peripheral Control functions ##### |
<> | 149:156823d33999 | 1856 | =============================================================================== |
<> | 149:156823d33999 | 1857 | [..] |
<> | 149:156823d33999 | 1858 | This subsection provides functions allowing to |
<> | 149:156823d33999 | 1859 | (+) Writes a data in a specified RTC Backup data register |
<> | 149:156823d33999 | 1860 | (+) Read a data in a specified RTC Backup data register |
<> | 149:156823d33999 | 1861 | (+) Sets the Coarse calibration parameters. |
<> | 149:156823d33999 | 1862 | (+) Deactivates the Coarse calibration parameters |
<> | 149:156823d33999 | 1863 | (+) Sets the Smooth calibration parameters. |
<> | 149:156823d33999 | 1864 | (+) Configures the Synchronization Shift Control Settings. |
<> | 149:156823d33999 | 1865 | (+) Configures the Calibration Pinout (RTC_CALIB) Selection (1Hz or 512Hz). |
<> | 149:156823d33999 | 1866 | (+) Deactivates the Calibration Pinout (RTC_CALIB) Selection (1Hz or 512Hz). |
<> | 149:156823d33999 | 1867 | (+) Enables the RTC reference clock detection. |
<> | 149:156823d33999 | 1868 | (+) Disable the RTC reference clock detection. |
<> | 149:156823d33999 | 1869 | (+) Enables the Bypass Shadow feature. |
<> | 149:156823d33999 | 1870 | (+) Disables the Bypass Shadow feature. |
<> | 149:156823d33999 | 1871 | |
<> | 149:156823d33999 | 1872 | @endverbatim |
<> | 149:156823d33999 | 1873 | * @{ |
<> | 149:156823d33999 | 1874 | */ |
<> | 149:156823d33999 | 1875 | |
<> | 149:156823d33999 | 1876 | /** |
<> | 149:156823d33999 | 1877 | * @brief Writes a data in a specified RTC Backup data register. |
<> | 149:156823d33999 | 1878 | * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains |
<> | 149:156823d33999 | 1879 | * the configuration information for RTC. |
<> | 149:156823d33999 | 1880 | * @param BackupRegister: RTC Backup data Register number. |
<> | 149:156823d33999 | 1881 | * This parameter can be: RTC_BKP_DRx where x can be from 0 to 19 to |
<> | 149:156823d33999 | 1882 | * specify the register. |
<> | 149:156823d33999 | 1883 | * @param Data: Data to be written in the specified RTC Backup data register. |
<> | 149:156823d33999 | 1884 | * @retval None |
<> | 149:156823d33999 | 1885 | */ |
<> | 149:156823d33999 | 1886 | void HAL_RTCEx_BKUPWrite(RTC_HandleTypeDef *hrtc, uint32_t BackupRegister, uint32_t Data) |
<> | 149:156823d33999 | 1887 | { |
<> | 149:156823d33999 | 1888 | uint32_t tmp = 0; |
<> | 149:156823d33999 | 1889 | |
<> | 149:156823d33999 | 1890 | /* Check the parameters */ |
<> | 149:156823d33999 | 1891 | assert_param(IS_RTC_BKP(BackupRegister)); |
<> | 149:156823d33999 | 1892 | |
<> | 149:156823d33999 | 1893 | tmp = (uint32_t)&(hrtc->Instance->BKP0R); |
<> | 149:156823d33999 | 1894 | tmp += (BackupRegister * 4); |
<> | 149:156823d33999 | 1895 | |
<> | 149:156823d33999 | 1896 | /* Write the specified register */ |
<> | 149:156823d33999 | 1897 | *(__IO uint32_t *)tmp = (uint32_t)Data; |
<> | 149:156823d33999 | 1898 | } |
<> | 149:156823d33999 | 1899 | |
<> | 149:156823d33999 | 1900 | /** |
<> | 149:156823d33999 | 1901 | * @brief Reads data from the specified RTC Backup data Register. |
<> | 149:156823d33999 | 1902 | * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains |
<> | 149:156823d33999 | 1903 | * the configuration information for RTC. |
<> | 149:156823d33999 | 1904 | * @param BackupRegister: RTC Backup data Register number. |
<> | 149:156823d33999 | 1905 | * This parameter can be: RTC_BKP_DRx where x can be from 0 to 19 to |
<> | 149:156823d33999 | 1906 | * specify the register. |
<> | 149:156823d33999 | 1907 | * @retval Read value |
<> | 149:156823d33999 | 1908 | */ |
<> | 149:156823d33999 | 1909 | uint32_t HAL_RTCEx_BKUPRead(RTC_HandleTypeDef *hrtc, uint32_t BackupRegister) |
<> | 149:156823d33999 | 1910 | { |
<> | 149:156823d33999 | 1911 | uint32_t tmp = 0; |
<> | 149:156823d33999 | 1912 | |
<> | 149:156823d33999 | 1913 | /* Check the parameters */ |
<> | 149:156823d33999 | 1914 | assert_param(IS_RTC_BKP(BackupRegister)); |
<> | 149:156823d33999 | 1915 | |
<> | 149:156823d33999 | 1916 | tmp = (uint32_t)&(hrtc->Instance->BKP0R); |
<> | 149:156823d33999 | 1917 | tmp += (BackupRegister * 4); |
<> | 149:156823d33999 | 1918 | |
<> | 149:156823d33999 | 1919 | /* Read the specified register */ |
<> | 149:156823d33999 | 1920 | return (*(__IO uint32_t *)tmp); |
<> | 149:156823d33999 | 1921 | } |
<> | 149:156823d33999 | 1922 | |
<> | 149:156823d33999 | 1923 | /** |
<> | 149:156823d33999 | 1924 | * @brief Sets the Coarse calibration parameters. |
<> | 149:156823d33999 | 1925 | * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains |
<> | 149:156823d33999 | 1926 | * the configuration information for RTC. |
<> | 149:156823d33999 | 1927 | * @param CalibSign: Specifies the sign of the coarse calibration value. |
<> | 149:156823d33999 | 1928 | * This parameter can be one of the following values : |
<> | 149:156823d33999 | 1929 | * @arg RTC_CALIBSIGN_POSITIVE: The value sign is positive |
<> | 149:156823d33999 | 1930 | * @arg RTC_CALIBSIGN_NEGATIVE: The value sign is negative |
<> | 149:156823d33999 | 1931 | * @param Value: value of coarse calibration expressed in ppm (coded on 5 bits). |
<> | 149:156823d33999 | 1932 | * |
<> | 149:156823d33999 | 1933 | * @note This Calibration value should be between 0 and 63 when using negative |
<> | 149:156823d33999 | 1934 | * sign with a 2-ppm step. |
<> | 149:156823d33999 | 1935 | * |
<> | 149:156823d33999 | 1936 | * @note This Calibration value should be between 0 and 126 when using positive |
<> | 149:156823d33999 | 1937 | * sign with a 4-ppm step. |
<> | 149:156823d33999 | 1938 | * @retval HAL status |
<> | 149:156823d33999 | 1939 | */ |
<> | 149:156823d33999 | 1940 | HAL_StatusTypeDef HAL_RTCEx_SetCoarseCalib(RTC_HandleTypeDef* hrtc, uint32_t CalibSign, uint32_t Value) |
<> | 149:156823d33999 | 1941 | { |
<> | 149:156823d33999 | 1942 | /* Check the parameters */ |
<> | 149:156823d33999 | 1943 | assert_param(IS_RTC_CALIB_SIGN(CalibSign)); |
<> | 149:156823d33999 | 1944 | assert_param(IS_RTC_CALIB_VALUE(Value)); |
<> | 149:156823d33999 | 1945 | |
<> | 149:156823d33999 | 1946 | /* Process Locked */ |
<> | 149:156823d33999 | 1947 | __HAL_LOCK(hrtc); |
<> | 149:156823d33999 | 1948 | |
<> | 149:156823d33999 | 1949 | hrtc->State = HAL_RTC_STATE_BUSY; |
<> | 149:156823d33999 | 1950 | |
<> | 149:156823d33999 | 1951 | /* Disable the write protection for RTC registers */ |
<> | 149:156823d33999 | 1952 | __HAL_RTC_WRITEPROTECTION_DISABLE(hrtc); |
<> | 149:156823d33999 | 1953 | |
<> | 149:156823d33999 | 1954 | /* Set Initialization mode */ |
<> | 149:156823d33999 | 1955 | if(RTC_EnterInitMode(hrtc) != HAL_OK) |
<> | 149:156823d33999 | 1956 | { |
<> | 149:156823d33999 | 1957 | /* Enable the write protection for RTC registers */ |
<> | 149:156823d33999 | 1958 | __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc); |
<> | 149:156823d33999 | 1959 | |
<> | 149:156823d33999 | 1960 | /* Set RTC state*/ |
<> | 149:156823d33999 | 1961 | hrtc->State = HAL_RTC_STATE_ERROR; |
<> | 149:156823d33999 | 1962 | |
<> | 149:156823d33999 | 1963 | /* Process Unlocked */ |
<> | 149:156823d33999 | 1964 | __HAL_UNLOCK(hrtc); |
<> | 149:156823d33999 | 1965 | |
<> | 149:156823d33999 | 1966 | return HAL_ERROR; |
<> | 149:156823d33999 | 1967 | } |
<> | 149:156823d33999 | 1968 | else |
<> | 149:156823d33999 | 1969 | { |
<> | 149:156823d33999 | 1970 | /* Enable the Coarse Calibration */ |
<> | 149:156823d33999 | 1971 | __HAL_RTC_COARSE_CALIB_ENABLE(hrtc); |
<> | 149:156823d33999 | 1972 | |
<> | 149:156823d33999 | 1973 | /* Set the coarse calibration value */ |
<> | 149:156823d33999 | 1974 | hrtc->Instance->CALIBR = (uint32_t)(CalibSign|Value); |
<> | 149:156823d33999 | 1975 | |
<> | 149:156823d33999 | 1976 | /* Exit Initialization mode */ |
<> | 149:156823d33999 | 1977 | hrtc->Instance->ISR &= (uint32_t)~RTC_ISR_INIT; |
<> | 149:156823d33999 | 1978 | } |
<> | 149:156823d33999 | 1979 | |
<> | 149:156823d33999 | 1980 | /* Enable the write protection for RTC registers */ |
<> | 149:156823d33999 | 1981 | __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc); |
<> | 149:156823d33999 | 1982 | |
<> | 149:156823d33999 | 1983 | /* Change state */ |
<> | 149:156823d33999 | 1984 | hrtc->State = HAL_RTC_STATE_READY; |
<> | 149:156823d33999 | 1985 | |
<> | 149:156823d33999 | 1986 | /* Process Unlocked */ |
<> | 149:156823d33999 | 1987 | __HAL_UNLOCK(hrtc); |
<> | 149:156823d33999 | 1988 | |
<> | 149:156823d33999 | 1989 | return HAL_OK; |
<> | 149:156823d33999 | 1990 | } |
<> | 149:156823d33999 | 1991 | |
<> | 149:156823d33999 | 1992 | /** |
<> | 149:156823d33999 | 1993 | * @brief Deactivates the Coarse calibration parameters. |
<> | 149:156823d33999 | 1994 | * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains |
<> | 149:156823d33999 | 1995 | * the configuration information for RTC. |
<> | 149:156823d33999 | 1996 | * @retval HAL status |
<> | 149:156823d33999 | 1997 | */ |
<> | 149:156823d33999 | 1998 | HAL_StatusTypeDef HAL_RTCEx_DeactivateCoarseCalib(RTC_HandleTypeDef* hrtc) |
<> | 149:156823d33999 | 1999 | { |
<> | 149:156823d33999 | 2000 | /* Process Locked */ |
<> | 149:156823d33999 | 2001 | __HAL_LOCK(hrtc); |
<> | 149:156823d33999 | 2002 | |
<> | 149:156823d33999 | 2003 | hrtc->State = HAL_RTC_STATE_BUSY; |
<> | 149:156823d33999 | 2004 | |
<> | 149:156823d33999 | 2005 | /* Disable the write protection for RTC registers */ |
<> | 149:156823d33999 | 2006 | __HAL_RTC_WRITEPROTECTION_DISABLE(hrtc); |
<> | 149:156823d33999 | 2007 | |
<> | 149:156823d33999 | 2008 | /* Set Initialization mode */ |
<> | 149:156823d33999 | 2009 | if(RTC_EnterInitMode(hrtc) != HAL_OK) |
<> | 149:156823d33999 | 2010 | { |
<> | 149:156823d33999 | 2011 | /* Enable the write protection for RTC registers */ |
<> | 149:156823d33999 | 2012 | __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc); |
<> | 149:156823d33999 | 2013 | |
<> | 149:156823d33999 | 2014 | /* Set RTC state*/ |
<> | 149:156823d33999 | 2015 | hrtc->State = HAL_RTC_STATE_ERROR; |
<> | 149:156823d33999 | 2016 | |
<> | 149:156823d33999 | 2017 | /* Process Unlocked */ |
<> | 149:156823d33999 | 2018 | __HAL_UNLOCK(hrtc); |
<> | 149:156823d33999 | 2019 | |
<> | 149:156823d33999 | 2020 | return HAL_ERROR; |
<> | 149:156823d33999 | 2021 | } |
<> | 149:156823d33999 | 2022 | else |
<> | 149:156823d33999 | 2023 | { |
<> | 149:156823d33999 | 2024 | /* Enable the Coarse Calibration */ |
<> | 149:156823d33999 | 2025 | __HAL_RTC_COARSE_CALIB_DISABLE(hrtc); |
<> | 149:156823d33999 | 2026 | |
<> | 149:156823d33999 | 2027 | /* Exit Initialization mode */ |
<> | 149:156823d33999 | 2028 | hrtc->Instance->ISR &= (uint32_t)~RTC_ISR_INIT; |
<> | 149:156823d33999 | 2029 | } |
<> | 149:156823d33999 | 2030 | |
<> | 149:156823d33999 | 2031 | /* Enable the write protection for RTC registers */ |
<> | 149:156823d33999 | 2032 | __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc); |
<> | 149:156823d33999 | 2033 | |
<> | 149:156823d33999 | 2034 | /* Change state */ |
<> | 149:156823d33999 | 2035 | hrtc->State = HAL_RTC_STATE_READY; |
<> | 149:156823d33999 | 2036 | |
<> | 149:156823d33999 | 2037 | /* Process Unlocked */ |
<> | 149:156823d33999 | 2038 | __HAL_UNLOCK(hrtc); |
<> | 149:156823d33999 | 2039 | |
<> | 149:156823d33999 | 2040 | return HAL_OK; |
<> | 149:156823d33999 | 2041 | } |
<> | 149:156823d33999 | 2042 | |
<> | 149:156823d33999 | 2043 | #if defined(STM32L100xBA) || defined (STM32L151xBA) || defined (STM32L152xBA) || defined(STM32L100xC) || defined (STM32L151xC) || defined (STM32L152xC) || defined (STM32L162xC) || defined(STM32L151xCA) || defined (STM32L151xD) || defined (STM32L152xCA) || defined (STM32L152xD) || defined (STM32L162xCA) || defined (STM32L162xD) || defined(STM32L151xE) || defined(STM32L151xDX) || defined (STM32L152xE) || defined (STM32L152xDX) || defined (STM32L162xE) || defined (STM32L162xDX) |
<> | 149:156823d33999 | 2044 | /** |
<> | 149:156823d33999 | 2045 | * @brief Sets the Smooth calibration parameters. |
<> | 149:156823d33999 | 2046 | * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains |
<> | 149:156823d33999 | 2047 | * the configuration information for RTC. |
<> | 149:156823d33999 | 2048 | * @param SmoothCalibPeriod: Select the Smooth Calibration Period. |
<> | 149:156823d33999 | 2049 | * This parameter can be can be one of the following values : |
<> | 149:156823d33999 | 2050 | * @arg RTC_SMOOTHCALIB_PERIOD_32SEC: The smooth calibration periode is 32s. |
<> | 149:156823d33999 | 2051 | * @arg RTC_SMOOTHCALIB_PERIOD_16SEC: The smooth calibration periode is 16s. |
<> | 149:156823d33999 | 2052 | * @arg RTC_SMOOTHCALIB_PERIOD_8SEC: The smooth calibartion periode is 8s. |
<> | 149:156823d33999 | 2053 | * @param SmoothCalibPlusPulses: Select to Set or reset the CALP bit. |
<> | 149:156823d33999 | 2054 | * This parameter can be one of the following values: |
<> | 149:156823d33999 | 2055 | * @arg RTC_SMOOTHCALIB_PLUSPULSES_SET: Add one RTCCLK puls every 2*11 pulses. |
<> | 149:156823d33999 | 2056 | * @arg RTC_SMOOTHCALIB_PLUSPULSES_RESET: No RTCCLK pulses are added. |
<> | 149:156823d33999 | 2057 | * @param SmoothCalibMinusPulsesValue: Select the value of CALM[8:0] bits. |
<> | 149:156823d33999 | 2058 | * This parameter can be one any value from 0 to 0x000001FF. |
<> | 149:156823d33999 | 2059 | * @note To deactivate the smooth calibration, the field SmoothCalibPlusPulses |
<> | 149:156823d33999 | 2060 | * must be equal to SMOOTHCALIB_PLUSPULSES_RESET and the field |
<> | 149:156823d33999 | 2061 | * SmoothCalibMinusPulsesValue mut be equal to 0. |
<> | 149:156823d33999 | 2062 | * @retval HAL status |
<> | 149:156823d33999 | 2063 | */ |
<> | 149:156823d33999 | 2064 | HAL_StatusTypeDef HAL_RTCEx_SetSmoothCalib(RTC_HandleTypeDef* hrtc, uint32_t SmoothCalibPeriod, uint32_t SmoothCalibPlusPulses, uint32_t SmoothCalibMinusPulsesValue) |
<> | 149:156823d33999 | 2065 | { |
<> | 149:156823d33999 | 2066 | uint32_t tickstart = 0; |
<> | 149:156823d33999 | 2067 | |
<> | 149:156823d33999 | 2068 | /* Check the parameters */ |
<> | 149:156823d33999 | 2069 | assert_param(IS_RTC_SMOOTH_CALIB_PERIOD(SmoothCalibPeriod)); |
<> | 149:156823d33999 | 2070 | assert_param(IS_RTC_SMOOTH_CALIB_PLUS(SmoothCalibPlusPulses)); |
<> | 149:156823d33999 | 2071 | assert_param(IS_RTC_SMOOTH_CALIB_MINUS(SmoothCalibMinusPulsesValue)); |
<> | 149:156823d33999 | 2072 | |
<> | 149:156823d33999 | 2073 | /* Process Locked */ |
<> | 149:156823d33999 | 2074 | __HAL_LOCK(hrtc); |
<> | 149:156823d33999 | 2075 | |
<> | 149:156823d33999 | 2076 | hrtc->State = HAL_RTC_STATE_BUSY; |
<> | 149:156823d33999 | 2077 | |
<> | 149:156823d33999 | 2078 | /* Disable the write protection for RTC registers */ |
<> | 149:156823d33999 | 2079 | __HAL_RTC_WRITEPROTECTION_DISABLE(hrtc); |
<> | 149:156823d33999 | 2080 | |
<> | 149:156823d33999 | 2081 | /* check if a calibration is pending*/ |
<> | 149:156823d33999 | 2082 | if((hrtc->Instance->ISR & RTC_ISR_RECALPF) != RESET) |
<> | 149:156823d33999 | 2083 | { |
<> | 149:156823d33999 | 2084 | tickstart = HAL_GetTick(); |
<> | 149:156823d33999 | 2085 | |
<> | 149:156823d33999 | 2086 | /* check if a calibration is pending*/ |
<> | 149:156823d33999 | 2087 | while((hrtc->Instance->ISR & RTC_ISR_RECALPF) != RESET) |
<> | 149:156823d33999 | 2088 | { |
<> | 149:156823d33999 | 2089 | if((HAL_GetTick() - tickstart ) > RTC_TIMEOUT_VALUE) |
<> | 149:156823d33999 | 2090 | { |
<> | 149:156823d33999 | 2091 | /* Enable the write protection for RTC registers */ |
<> | 149:156823d33999 | 2092 | __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc); |
<> | 149:156823d33999 | 2093 | |
<> | 149:156823d33999 | 2094 | /* Change RTC state */ |
<> | 149:156823d33999 | 2095 | hrtc->State = HAL_RTC_STATE_TIMEOUT; |
<> | 149:156823d33999 | 2096 | |
<> | 149:156823d33999 | 2097 | /* Process Unlocked */ |
<> | 149:156823d33999 | 2098 | __HAL_UNLOCK(hrtc); |
<> | 149:156823d33999 | 2099 | |
<> | 149:156823d33999 | 2100 | return HAL_TIMEOUT; |
<> | 149:156823d33999 | 2101 | } |
<> | 149:156823d33999 | 2102 | } |
<> | 149:156823d33999 | 2103 | } |
<> | 149:156823d33999 | 2104 | |
<> | 149:156823d33999 | 2105 | /* Configure the Smooth calibration settings */ |
<> | 149:156823d33999 | 2106 | hrtc->Instance->CALR = (uint32_t)((uint32_t)SmoothCalibPeriod | (uint32_t)SmoothCalibPlusPulses | (uint32_t)SmoothCalibMinusPulsesValue); |
<> | 149:156823d33999 | 2107 | |
<> | 149:156823d33999 | 2108 | /* Enable the write protection for RTC registers */ |
<> | 149:156823d33999 | 2109 | __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc); |
<> | 149:156823d33999 | 2110 | |
<> | 149:156823d33999 | 2111 | /* Change RTC state */ |
<> | 149:156823d33999 | 2112 | hrtc->State = HAL_RTC_STATE_READY; |
<> | 149:156823d33999 | 2113 | |
<> | 149:156823d33999 | 2114 | /* Process Unlocked */ |
<> | 149:156823d33999 | 2115 | __HAL_UNLOCK(hrtc); |
<> | 149:156823d33999 | 2116 | |
<> | 149:156823d33999 | 2117 | return HAL_OK; |
<> | 149:156823d33999 | 2118 | } |
<> | 149:156823d33999 | 2119 | |
<> | 149:156823d33999 | 2120 | /** |
<> | 149:156823d33999 | 2121 | * @brief Configures the Synchronization Shift Control Settings. |
<> | 149:156823d33999 | 2122 | * @note When REFCKON is set, firmware must not write to Shift control register. |
<> | 149:156823d33999 | 2123 | * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains |
<> | 149:156823d33999 | 2124 | * the configuration information for RTC. |
<> | 149:156823d33999 | 2125 | * @param ShiftAdd1S: Select to add or not 1 second to the time calendar. |
<> | 149:156823d33999 | 2126 | * This parameter can be one of the following values : |
<> | 149:156823d33999 | 2127 | * @arg RTC_SHIFTADD1S_SET: Add one second to the clock calendar. |
<> | 149:156823d33999 | 2128 | * @arg RTC_SHIFTADD1S_RESET: No effect. |
<> | 149:156823d33999 | 2129 | * @param ShiftSubFS: Select the number of Second Fractions to substitute. |
<> | 149:156823d33999 | 2130 | * This parameter can be one any value from 0 to 0x7FFF. |
<> | 149:156823d33999 | 2131 | * @retval HAL status |
<> | 149:156823d33999 | 2132 | */ |
<> | 149:156823d33999 | 2133 | HAL_StatusTypeDef HAL_RTCEx_SetSynchroShift(RTC_HandleTypeDef* hrtc, uint32_t ShiftAdd1S, uint32_t ShiftSubFS) |
<> | 149:156823d33999 | 2134 | { |
<> | 149:156823d33999 | 2135 | uint32_t tickstart = 0; |
<> | 149:156823d33999 | 2136 | |
<> | 149:156823d33999 | 2137 | /* Check the parameters */ |
<> | 149:156823d33999 | 2138 | assert_param(IS_RTC_SHIFT_ADD1S(ShiftAdd1S)); |
<> | 149:156823d33999 | 2139 | assert_param(IS_RTC_SHIFT_SUBFS(ShiftSubFS)); |
<> | 149:156823d33999 | 2140 | |
<> | 149:156823d33999 | 2141 | /* Process Locked */ |
<> | 149:156823d33999 | 2142 | __HAL_LOCK(hrtc); |
<> | 149:156823d33999 | 2143 | |
<> | 149:156823d33999 | 2144 | hrtc->State = HAL_RTC_STATE_BUSY; |
<> | 149:156823d33999 | 2145 | |
<> | 149:156823d33999 | 2146 | /* Disable the write protection for RTC registers */ |
<> | 149:156823d33999 | 2147 | __HAL_RTC_WRITEPROTECTION_DISABLE(hrtc); |
<> | 149:156823d33999 | 2148 | |
<> | 149:156823d33999 | 2149 | tickstart = HAL_GetTick(); |
<> | 149:156823d33999 | 2150 | |
<> | 149:156823d33999 | 2151 | /* Wait until the shift is completed*/ |
<> | 149:156823d33999 | 2152 | while((hrtc->Instance->ISR & RTC_ISR_SHPF) != RESET) |
<> | 149:156823d33999 | 2153 | { |
<> | 149:156823d33999 | 2154 | if((HAL_GetTick() - tickstart ) > RTC_TIMEOUT_VALUE) |
<> | 149:156823d33999 | 2155 | { |
<> | 149:156823d33999 | 2156 | /* Enable the write protection for RTC registers */ |
<> | 149:156823d33999 | 2157 | __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc); |
<> | 149:156823d33999 | 2158 | |
<> | 149:156823d33999 | 2159 | hrtc->State = HAL_RTC_STATE_TIMEOUT; |
<> | 149:156823d33999 | 2160 | |
<> | 149:156823d33999 | 2161 | /* Process Unlocked */ |
<> | 149:156823d33999 | 2162 | __HAL_UNLOCK(hrtc); |
<> | 149:156823d33999 | 2163 | |
<> | 149:156823d33999 | 2164 | return HAL_TIMEOUT; |
<> | 149:156823d33999 | 2165 | } |
<> | 149:156823d33999 | 2166 | } |
<> | 149:156823d33999 | 2167 | |
<> | 149:156823d33999 | 2168 | /* Check if the reference clock detection is disabled */ |
<> | 149:156823d33999 | 2169 | if((hrtc->Instance->CR & RTC_CR_REFCKON) == RESET) |
<> | 149:156823d33999 | 2170 | { |
<> | 149:156823d33999 | 2171 | /* Configure the Shift settings */ |
<> | 149:156823d33999 | 2172 | hrtc->Instance->SHIFTR = (uint32_t)(uint32_t)(ShiftSubFS) | (uint32_t)(ShiftAdd1S); |
<> | 149:156823d33999 | 2173 | |
<> | 149:156823d33999 | 2174 | /* Wait for synchro */ |
<> | 149:156823d33999 | 2175 | if(HAL_RTC_WaitForSynchro(hrtc) != HAL_OK) |
<> | 149:156823d33999 | 2176 | { |
<> | 149:156823d33999 | 2177 | /* Enable the write protection for RTC registers */ |
<> | 149:156823d33999 | 2178 | __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc); |
<> | 149:156823d33999 | 2179 | |
<> | 149:156823d33999 | 2180 | hrtc->State = HAL_RTC_STATE_ERROR; |
<> | 149:156823d33999 | 2181 | |
<> | 149:156823d33999 | 2182 | /* Process Unlocked */ |
<> | 149:156823d33999 | 2183 | __HAL_UNLOCK(hrtc); |
<> | 149:156823d33999 | 2184 | |
<> | 149:156823d33999 | 2185 | return HAL_ERROR; |
<> | 149:156823d33999 | 2186 | } |
<> | 149:156823d33999 | 2187 | } |
<> | 149:156823d33999 | 2188 | else |
<> | 149:156823d33999 | 2189 | { |
<> | 149:156823d33999 | 2190 | /* Enable the write protection for RTC registers */ |
<> | 149:156823d33999 | 2191 | __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc); |
<> | 149:156823d33999 | 2192 | |
<> | 149:156823d33999 | 2193 | /* Change RTC state */ |
<> | 149:156823d33999 | 2194 | hrtc->State = HAL_RTC_STATE_ERROR; |
<> | 149:156823d33999 | 2195 | |
<> | 149:156823d33999 | 2196 | /* Process Unlocked */ |
<> | 149:156823d33999 | 2197 | __HAL_UNLOCK(hrtc); |
<> | 149:156823d33999 | 2198 | |
<> | 149:156823d33999 | 2199 | return HAL_ERROR; |
<> | 149:156823d33999 | 2200 | } |
<> | 149:156823d33999 | 2201 | |
<> | 149:156823d33999 | 2202 | /* Enable the write protection for RTC registers */ |
<> | 149:156823d33999 | 2203 | __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc); |
<> | 149:156823d33999 | 2204 | |
<> | 149:156823d33999 | 2205 | /* Change RTC state */ |
<> | 149:156823d33999 | 2206 | hrtc->State = HAL_RTC_STATE_READY; |
<> | 149:156823d33999 | 2207 | |
<> | 149:156823d33999 | 2208 | /* Process Unlocked */ |
<> | 149:156823d33999 | 2209 | __HAL_UNLOCK(hrtc); |
<> | 149:156823d33999 | 2210 | |
<> | 149:156823d33999 | 2211 | return HAL_OK; |
<> | 149:156823d33999 | 2212 | } |
<> | 149:156823d33999 | 2213 | #endif /* STM32L100xBA || STM32L151xBA || STM32L152xBA || STM32L100xC || STM32L151xC || STM32L152xC || STM32L162xC || STM32L151xCA || STM32L151xD || STM32L152xCA || STM32L152xD || STM32L162xCA || STM32L162xD || STM32L151xE || STM32L151xDX || STM32L152xE || STM32L152xDX || STM32L162xE || STM32L162xDX */ |
<> | 149:156823d33999 | 2214 | |
<> | 149:156823d33999 | 2215 | |
<> | 149:156823d33999 | 2216 | #if defined(STM32L100xBA) || defined (STM32L151xBA) || defined (STM32L152xBA) || defined(STM32L100xC) || defined (STM32L151xC) || defined (STM32L152xC) || defined (STM32L162xC) || defined(STM32L151xCA) || defined (STM32L151xD) || defined (STM32L152xCA) || defined (STM32L152xD) || defined (STM32L162xCA) || defined (STM32L162xD) || defined(STM32L151xE) || defined(STM32L151xDX) || defined (STM32L152xE) || defined (STM32L152xDX) || defined (STM32L162xE) || defined (STM32L162xDX) |
<> | 149:156823d33999 | 2217 | /** |
<> | 149:156823d33999 | 2218 | * @brief Configures the Calibration Pinout (RTC_CALIB) Selection (1Hz or 512Hz). |
<> | 149:156823d33999 | 2219 | * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains |
<> | 149:156823d33999 | 2220 | * the configuration information for RTC. |
<> | 149:156823d33999 | 2221 | * @param CalibOutput : Select the Calibration output Selection . |
<> | 149:156823d33999 | 2222 | * This parameter can be one of the following values: |
<> | 149:156823d33999 | 2223 | * @arg RTC_CALIBOUTPUT_512HZ: A signal has a regular waveform at 512Hz. |
<> | 149:156823d33999 | 2224 | * @arg RTC_CALIBOUTPUT_1HZ: A signal has a regular waveform at 1Hz. |
<> | 149:156823d33999 | 2225 | * @retval HAL status |
<> | 149:156823d33999 | 2226 | */ |
<> | 149:156823d33999 | 2227 | HAL_StatusTypeDef HAL_RTCEx_SetCalibrationOutPut(RTC_HandleTypeDef* hrtc, uint32_t CalibOutput) |
<> | 149:156823d33999 | 2228 | #else |
<> | 149:156823d33999 | 2229 | /** |
<> | 149:156823d33999 | 2230 | * @brief Configure the Calibration Pinout (RTC_CALIB). |
<> | 149:156823d33999 | 2231 | * @param hrtc : RTC handle |
<> | 149:156823d33999 | 2232 | * @retval HAL status |
<> | 149:156823d33999 | 2233 | */ |
<> | 149:156823d33999 | 2234 | HAL_StatusTypeDef HAL_RTCEx_SetCalibrationOutPut(RTC_HandleTypeDef* hrtc) |
<> | 149:156823d33999 | 2235 | #endif /* STM32L100xBA || STM32L151xBA || STM32L152xBA || STM32L100xC || STM32L151xC || STM32L152xC || STM32L162xC || STM32L151xCA || STM32L151xD || STM32L152xCA || STM32L152xD || STM32L162xCA || STM32L162xD || STM32L151xE || STM32L151xDX || STM32L152xE || STM32L152xDX || STM32L162xE || STM32L162xDX */ |
<> | 149:156823d33999 | 2236 | { |
<> | 149:156823d33999 | 2237 | #if defined(STM32L100xBA) || defined (STM32L151xBA) || defined (STM32L152xBA) || defined(STM32L100xC) || defined (STM32L151xC) || defined (STM32L152xC) || defined (STM32L162xC) || defined(STM32L151xCA) || defined (STM32L151xD) || defined (STM32L152xCA) || defined (STM32L152xD) || defined (STM32L162xCA) || defined (STM32L162xD) || defined(STM32L151xE) || defined(STM32L151xDX) || defined (STM32L152xE) || defined (STM32L152xDX) || defined (STM32L162xE) || defined (STM32L162xDX) |
<> | 149:156823d33999 | 2238 | /* Check the parameters */ |
<> | 149:156823d33999 | 2239 | assert_param(IS_RTC_CALIB_OUTPUT(CalibOutput)); |
<> | 149:156823d33999 | 2240 | #endif /* STM32L100xBA || STM32L151xBA || STM32L152xBA || STM32L100xC || STM32L151xC || STM32L152xC || STM32L162xC || STM32L151xCA || STM32L151xD || STM32L152xCA || STM32L152xD || STM32L162xCA || STM32L162xD || STM32L151xE || STM32L151xDX || STM32L152xE || STM32L152xDX || STM32L162xE || STM32L162xDX */ |
<> | 149:156823d33999 | 2241 | |
<> | 149:156823d33999 | 2242 | /* Process Locked */ |
<> | 149:156823d33999 | 2243 | __HAL_LOCK(hrtc); |
<> | 149:156823d33999 | 2244 | |
<> | 149:156823d33999 | 2245 | hrtc->State = HAL_RTC_STATE_BUSY; |
<> | 149:156823d33999 | 2246 | |
<> | 149:156823d33999 | 2247 | /* Disable the write protection for RTC registers */ |
<> | 149:156823d33999 | 2248 | __HAL_RTC_WRITEPROTECTION_DISABLE(hrtc); |
<> | 149:156823d33999 | 2249 | |
<> | 149:156823d33999 | 2250 | #if defined(STM32L100xBA) || defined (STM32L151xBA) || defined (STM32L152xBA) || defined(STM32L100xC) || defined (STM32L151xC) || defined (STM32L152xC) || defined (STM32L162xC) || defined(STM32L151xCA) || defined (STM32L151xD) || defined (STM32L152xCA) || defined (STM32L152xD) || defined (STM32L162xCA) || defined (STM32L162xD) || defined(STM32L151xE) || defined(STM32L151xDX) || defined (STM32L152xE) || defined (STM32L152xDX) || defined (STM32L162xE) || defined (STM32L162xDX) |
<> | 149:156823d33999 | 2251 | /* Clear flags before config */ |
<> | 149:156823d33999 | 2252 | hrtc->Instance->CR &= (uint32_t)~RTC_CR_COSEL; |
<> | 149:156823d33999 | 2253 | |
<> | 149:156823d33999 | 2254 | /* Configure the RTC_CR register */ |
<> | 149:156823d33999 | 2255 | hrtc->Instance->CR |= (uint32_t)CalibOutput; |
<> | 149:156823d33999 | 2256 | #endif /* STM32L100xBA || STM32L151xBA || STM32L152xBA || STM32L100xC || STM32L151xC || STM32L152xC || STM32L162xC || STM32L151xCA || STM32L151xD || STM32L152xCA || STM32L152xD || STM32L162xCA || STM32L162xD || STM32L151xE || STM32L151xDX || STM32L152xE || STM32L152xDX || STM32L162xE || STM32L162xDX */ |
<> | 149:156823d33999 | 2257 | |
<> | 149:156823d33999 | 2258 | __HAL_RTC_CALIBRATION_OUTPUT_ENABLE(hrtc); |
<> | 149:156823d33999 | 2259 | |
<> | 149:156823d33999 | 2260 | /* Enable the write protection for RTC registers */ |
<> | 149:156823d33999 | 2261 | __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc); |
<> | 149:156823d33999 | 2262 | |
<> | 149:156823d33999 | 2263 | /* Change RTC state */ |
<> | 149:156823d33999 | 2264 | hrtc->State = HAL_RTC_STATE_READY; |
<> | 149:156823d33999 | 2265 | |
<> | 149:156823d33999 | 2266 | /* Process Unlocked */ |
<> | 149:156823d33999 | 2267 | __HAL_UNLOCK(hrtc); |
<> | 149:156823d33999 | 2268 | |
<> | 149:156823d33999 | 2269 | return HAL_OK; |
<> | 149:156823d33999 | 2270 | } |
<> | 149:156823d33999 | 2271 | |
<> | 149:156823d33999 | 2272 | /** |
<> | 149:156823d33999 | 2273 | * @brief Deactivates the Calibration Pinout (RTC_CALIB) Selection (1Hz or 512Hz). |
<> | 149:156823d33999 | 2274 | * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains |
<> | 149:156823d33999 | 2275 | * the configuration information for RTC. |
<> | 149:156823d33999 | 2276 | * @retval HAL status |
<> | 149:156823d33999 | 2277 | */ |
<> | 149:156823d33999 | 2278 | HAL_StatusTypeDef HAL_RTCEx_DeactivateCalibrationOutPut(RTC_HandleTypeDef* hrtc) |
<> | 149:156823d33999 | 2279 | { |
<> | 149:156823d33999 | 2280 | /* Process Locked */ |
<> | 149:156823d33999 | 2281 | __HAL_LOCK(hrtc); |
<> | 149:156823d33999 | 2282 | |
<> | 149:156823d33999 | 2283 | hrtc->State = HAL_RTC_STATE_BUSY; |
<> | 149:156823d33999 | 2284 | |
<> | 149:156823d33999 | 2285 | /* Disable the write protection for RTC registers */ |
<> | 149:156823d33999 | 2286 | __HAL_RTC_WRITEPROTECTION_DISABLE(hrtc); |
<> | 149:156823d33999 | 2287 | |
<> | 149:156823d33999 | 2288 | __HAL_RTC_CALIBRATION_OUTPUT_DISABLE(hrtc); |
<> | 149:156823d33999 | 2289 | |
<> | 149:156823d33999 | 2290 | /* Enable the write protection for RTC registers */ |
<> | 149:156823d33999 | 2291 | __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc); |
<> | 149:156823d33999 | 2292 | |
<> | 149:156823d33999 | 2293 | /* Change RTC state */ |
<> | 149:156823d33999 | 2294 | hrtc->State = HAL_RTC_STATE_READY; |
<> | 149:156823d33999 | 2295 | |
<> | 149:156823d33999 | 2296 | /* Process Unlocked */ |
<> | 149:156823d33999 | 2297 | __HAL_UNLOCK(hrtc); |
<> | 149:156823d33999 | 2298 | |
<> | 149:156823d33999 | 2299 | return HAL_OK; |
<> | 149:156823d33999 | 2300 | } |
<> | 149:156823d33999 | 2301 | |
<> | 149:156823d33999 | 2302 | /** |
<> | 149:156823d33999 | 2303 | * @brief Enables the RTC reference clock detection. |
<> | 149:156823d33999 | 2304 | * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains |
<> | 149:156823d33999 | 2305 | * the configuration information for RTC. |
<> | 149:156823d33999 | 2306 | * @retval HAL status |
<> | 149:156823d33999 | 2307 | */ |
<> | 149:156823d33999 | 2308 | HAL_StatusTypeDef HAL_RTCEx_SetRefClock(RTC_HandleTypeDef* hrtc) |
<> | 149:156823d33999 | 2309 | { |
<> | 149:156823d33999 | 2310 | /* Process Locked */ |
<> | 149:156823d33999 | 2311 | __HAL_LOCK(hrtc); |
<> | 149:156823d33999 | 2312 | |
<> | 149:156823d33999 | 2313 | hrtc->State = HAL_RTC_STATE_BUSY; |
<> | 149:156823d33999 | 2314 | |
<> | 149:156823d33999 | 2315 | /* Disable the write protection for RTC registers */ |
<> | 149:156823d33999 | 2316 | __HAL_RTC_WRITEPROTECTION_DISABLE(hrtc); |
<> | 149:156823d33999 | 2317 | |
<> | 149:156823d33999 | 2318 | /* Set Initialization mode */ |
<> | 149:156823d33999 | 2319 | if(RTC_EnterInitMode(hrtc) != HAL_OK) |
<> | 149:156823d33999 | 2320 | { |
<> | 149:156823d33999 | 2321 | /* Enable the write protection for RTC registers */ |
<> | 149:156823d33999 | 2322 | __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc); |
<> | 149:156823d33999 | 2323 | |
<> | 149:156823d33999 | 2324 | /* Set RTC state*/ |
<> | 149:156823d33999 | 2325 | hrtc->State = HAL_RTC_STATE_ERROR; |
<> | 149:156823d33999 | 2326 | |
<> | 149:156823d33999 | 2327 | /* Process Unlocked */ |
<> | 149:156823d33999 | 2328 | __HAL_UNLOCK(hrtc); |
<> | 149:156823d33999 | 2329 | |
<> | 149:156823d33999 | 2330 | return HAL_ERROR; |
<> | 149:156823d33999 | 2331 | } |
<> | 149:156823d33999 | 2332 | else |
<> | 149:156823d33999 | 2333 | { |
<> | 149:156823d33999 | 2334 | __HAL_RTC_CLOCKREF_DETECTION_ENABLE(hrtc); |
<> | 149:156823d33999 | 2335 | |
<> | 149:156823d33999 | 2336 | /* Exit Initialization mode */ |
<> | 149:156823d33999 | 2337 | hrtc->Instance->ISR &= (uint32_t)~RTC_ISR_INIT; |
<> | 149:156823d33999 | 2338 | } |
<> | 149:156823d33999 | 2339 | |
<> | 149:156823d33999 | 2340 | /* Enable the write protection for RTC registers */ |
<> | 149:156823d33999 | 2341 | __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc); |
<> | 149:156823d33999 | 2342 | |
<> | 149:156823d33999 | 2343 | /* Change RTC state */ |
<> | 149:156823d33999 | 2344 | hrtc->State = HAL_RTC_STATE_READY; |
<> | 149:156823d33999 | 2345 | |
<> | 149:156823d33999 | 2346 | /* Process Unlocked */ |
<> | 149:156823d33999 | 2347 | __HAL_UNLOCK(hrtc); |
<> | 149:156823d33999 | 2348 | |
<> | 149:156823d33999 | 2349 | return HAL_OK; |
<> | 149:156823d33999 | 2350 | } |
<> | 149:156823d33999 | 2351 | |
<> | 149:156823d33999 | 2352 | /** |
<> | 149:156823d33999 | 2353 | * @brief Disable the RTC reference clock detection. |
<> | 149:156823d33999 | 2354 | * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains |
<> | 149:156823d33999 | 2355 | * the configuration information for RTC. |
<> | 149:156823d33999 | 2356 | * @retval HAL status |
<> | 149:156823d33999 | 2357 | */ |
<> | 149:156823d33999 | 2358 | HAL_StatusTypeDef HAL_RTCEx_DeactivateRefClock(RTC_HandleTypeDef* hrtc) |
<> | 149:156823d33999 | 2359 | { |
<> | 149:156823d33999 | 2360 | /* Process Locked */ |
<> | 149:156823d33999 | 2361 | __HAL_LOCK(hrtc); |
<> | 149:156823d33999 | 2362 | |
<> | 149:156823d33999 | 2363 | hrtc->State = HAL_RTC_STATE_BUSY; |
<> | 149:156823d33999 | 2364 | |
<> | 149:156823d33999 | 2365 | /* Disable the write protection for RTC registers */ |
<> | 149:156823d33999 | 2366 | __HAL_RTC_WRITEPROTECTION_DISABLE(hrtc); |
<> | 149:156823d33999 | 2367 | |
<> | 149:156823d33999 | 2368 | /* Set Initialization mode */ |
<> | 149:156823d33999 | 2369 | if(RTC_EnterInitMode(hrtc) != HAL_OK) |
<> | 149:156823d33999 | 2370 | { |
<> | 149:156823d33999 | 2371 | /* Enable the write protection for RTC registers */ |
<> | 149:156823d33999 | 2372 | __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc); |
<> | 149:156823d33999 | 2373 | |
<> | 149:156823d33999 | 2374 | /* Set RTC state*/ |
<> | 149:156823d33999 | 2375 | hrtc->State = HAL_RTC_STATE_ERROR; |
<> | 149:156823d33999 | 2376 | |
<> | 149:156823d33999 | 2377 | /* Process Unlocked */ |
<> | 149:156823d33999 | 2378 | __HAL_UNLOCK(hrtc); |
<> | 149:156823d33999 | 2379 | |
<> | 149:156823d33999 | 2380 | return HAL_ERROR; |
<> | 149:156823d33999 | 2381 | } |
<> | 149:156823d33999 | 2382 | else |
<> | 149:156823d33999 | 2383 | { |
<> | 149:156823d33999 | 2384 | __HAL_RTC_CLOCKREF_DETECTION_DISABLE(hrtc); |
<> | 149:156823d33999 | 2385 | |
<> | 149:156823d33999 | 2386 | /* Exit Initialization mode */ |
<> | 149:156823d33999 | 2387 | hrtc->Instance->ISR &= (uint32_t)~RTC_ISR_INIT; |
<> | 149:156823d33999 | 2388 | } |
<> | 149:156823d33999 | 2389 | |
<> | 149:156823d33999 | 2390 | /* Enable the write protection for RTC registers */ |
<> | 149:156823d33999 | 2391 | __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc); |
<> | 149:156823d33999 | 2392 | |
<> | 149:156823d33999 | 2393 | /* Change RTC state */ |
<> | 149:156823d33999 | 2394 | hrtc->State = HAL_RTC_STATE_READY; |
<> | 149:156823d33999 | 2395 | |
<> | 149:156823d33999 | 2396 | /* Process Unlocked */ |
<> | 149:156823d33999 | 2397 | __HAL_UNLOCK(hrtc); |
<> | 149:156823d33999 | 2398 | |
<> | 149:156823d33999 | 2399 | return HAL_OK; |
<> | 149:156823d33999 | 2400 | } |
<> | 149:156823d33999 | 2401 | |
<> | 149:156823d33999 | 2402 | #if defined(STM32L100xBA) || defined (STM32L151xBA) || defined (STM32L152xBA) || defined(STM32L100xC) || defined (STM32L151xC) || defined (STM32L152xC) || defined (STM32L162xC) || defined(STM32L151xCA) || defined (STM32L151xD) || defined (STM32L152xCA) || defined (STM32L152xD) || defined (STM32L162xCA) || defined (STM32L162xD) || defined(STM32L151xE) || defined(STM32L151xDX) || defined (STM32L152xE) || defined (STM32L152xDX) || defined (STM32L162xE) || defined (STM32L162xDX) |
<> | 149:156823d33999 | 2403 | /** |
<> | 149:156823d33999 | 2404 | * @brief Enables the Bypass Shadow feature. |
<> | 149:156823d33999 | 2405 | * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains |
<> | 149:156823d33999 | 2406 | * the configuration information for RTC. |
<> | 149:156823d33999 | 2407 | * @note When the Bypass Shadow is enabled the calendar value are taken |
<> | 149:156823d33999 | 2408 | * directly from the Calendar counter. |
<> | 149:156823d33999 | 2409 | * @retval HAL status |
<> | 149:156823d33999 | 2410 | */ |
<> | 149:156823d33999 | 2411 | HAL_StatusTypeDef HAL_RTCEx_EnableBypassShadow(RTC_HandleTypeDef* hrtc) |
<> | 149:156823d33999 | 2412 | { |
<> | 149:156823d33999 | 2413 | /* Process Locked */ |
<> | 149:156823d33999 | 2414 | __HAL_LOCK(hrtc); |
<> | 149:156823d33999 | 2415 | |
<> | 149:156823d33999 | 2416 | hrtc->State = HAL_RTC_STATE_BUSY; |
<> | 149:156823d33999 | 2417 | |
<> | 149:156823d33999 | 2418 | /* Disable the write protection for RTC registers */ |
<> | 149:156823d33999 | 2419 | __HAL_RTC_WRITEPROTECTION_DISABLE(hrtc); |
<> | 149:156823d33999 | 2420 | |
<> | 149:156823d33999 | 2421 | /* Set the BYPSHAD bit */ |
<> | 149:156823d33999 | 2422 | hrtc->Instance->CR |= (uint8_t)RTC_CR_BYPSHAD; |
<> | 149:156823d33999 | 2423 | |
<> | 149:156823d33999 | 2424 | /* Enable the write protection for RTC registers */ |
<> | 149:156823d33999 | 2425 | __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc); |
<> | 149:156823d33999 | 2426 | |
<> | 149:156823d33999 | 2427 | /* Change RTC state */ |
<> | 149:156823d33999 | 2428 | hrtc->State = HAL_RTC_STATE_READY; |
<> | 149:156823d33999 | 2429 | |
<> | 149:156823d33999 | 2430 | /* Process Unlocked */ |
<> | 149:156823d33999 | 2431 | __HAL_UNLOCK(hrtc); |
<> | 149:156823d33999 | 2432 | |
<> | 149:156823d33999 | 2433 | return HAL_OK; |
<> | 149:156823d33999 | 2434 | } |
<> | 149:156823d33999 | 2435 | |
<> | 149:156823d33999 | 2436 | /** |
<> | 149:156823d33999 | 2437 | * @brief Disables the Bypass Shadow feature. |
<> | 149:156823d33999 | 2438 | * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains |
<> | 149:156823d33999 | 2439 | * the configuration information for RTC. |
<> | 149:156823d33999 | 2440 | * @note When the Bypass Shadow is enabled the calendar value are taken |
<> | 149:156823d33999 | 2441 | * directly from the Calendar counter. |
<> | 149:156823d33999 | 2442 | * @retval HAL status |
<> | 149:156823d33999 | 2443 | */ |
<> | 149:156823d33999 | 2444 | HAL_StatusTypeDef HAL_RTCEx_DisableBypassShadow(RTC_HandleTypeDef* hrtc) |
<> | 149:156823d33999 | 2445 | { |
<> | 149:156823d33999 | 2446 | /* Process Locked */ |
<> | 149:156823d33999 | 2447 | __HAL_LOCK(hrtc); |
<> | 149:156823d33999 | 2448 | |
<> | 149:156823d33999 | 2449 | hrtc->State = HAL_RTC_STATE_BUSY; |
<> | 149:156823d33999 | 2450 | |
<> | 149:156823d33999 | 2451 | /* Disable the write protection for RTC registers */ |
<> | 149:156823d33999 | 2452 | __HAL_RTC_WRITEPROTECTION_DISABLE(hrtc); |
<> | 149:156823d33999 | 2453 | |
<> | 149:156823d33999 | 2454 | /* Reset the BYPSHAD bit */ |
<> | 149:156823d33999 | 2455 | hrtc->Instance->CR &= (uint8_t)~RTC_CR_BYPSHAD; |
<> | 149:156823d33999 | 2456 | |
<> | 149:156823d33999 | 2457 | /* Enable the write protection for RTC registers */ |
<> | 149:156823d33999 | 2458 | __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc); |
<> | 149:156823d33999 | 2459 | |
<> | 149:156823d33999 | 2460 | /* Change RTC state */ |
<> | 149:156823d33999 | 2461 | hrtc->State = HAL_RTC_STATE_READY; |
<> | 149:156823d33999 | 2462 | |
<> | 149:156823d33999 | 2463 | /* Process Unlocked */ |
<> | 149:156823d33999 | 2464 | __HAL_UNLOCK(hrtc); |
<> | 149:156823d33999 | 2465 | |
<> | 149:156823d33999 | 2466 | return HAL_OK; |
<> | 149:156823d33999 | 2467 | } |
<> | 149:156823d33999 | 2468 | #endif /* STM32L100xBA || STM32L151xBA || STM32L152xBA || STM32L100xC || STM32L151xC || STM32L152xC || STM32L162xC || STM32L151xCA || STM32L151xD || STM32L152xCA || STM32L152xD || STM32L162xCA || STM32L162xD || STM32L151xE || STM32L151xDX || STM32L152xE || STM32L152xDX || STM32L162xE || STM32L162xDX */ |
<> | 149:156823d33999 | 2469 | |
<> | 149:156823d33999 | 2470 | /** |
<> | 149:156823d33999 | 2471 | * @} |
<> | 149:156823d33999 | 2472 | */ |
<> | 149:156823d33999 | 2473 | |
<> | 149:156823d33999 | 2474 | /** @defgroup RTCEx_Exported_Functions_Group8 Extended features functions |
<> | 149:156823d33999 | 2475 | * @brief Extended features functions |
<> | 149:156823d33999 | 2476 | * |
<> | 149:156823d33999 | 2477 | @verbatim |
<> | 149:156823d33999 | 2478 | =============================================================================== |
<> | 149:156823d33999 | 2479 | ##### Extended features functions ##### |
<> | 149:156823d33999 | 2480 | =============================================================================== |
<> | 149:156823d33999 | 2481 | [..] This section provides functions allowing to: |
<> | 149:156823d33999 | 2482 | (+) RTC Alram B callback |
<> | 149:156823d33999 | 2483 | (+) RTC Poll for Alarm B request |
<> | 149:156823d33999 | 2484 | |
<> | 149:156823d33999 | 2485 | @endverbatim |
<> | 149:156823d33999 | 2486 | * @{ |
<> | 149:156823d33999 | 2487 | */ |
<> | 149:156823d33999 | 2488 | |
<> | 149:156823d33999 | 2489 | /** |
<> | 149:156823d33999 | 2490 | * @brief Alarm B callback. |
<> | 149:156823d33999 | 2491 | * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains |
<> | 149:156823d33999 | 2492 | * the configuration information for RTC. |
<> | 149:156823d33999 | 2493 | * @retval None |
<> | 149:156823d33999 | 2494 | */ |
<> | 149:156823d33999 | 2495 | __weak void HAL_RTCEx_AlarmBEventCallback(RTC_HandleTypeDef *hrtc) |
<> | 149:156823d33999 | 2496 | { |
<> | 149:156823d33999 | 2497 | /* Prevent unused argument(s) compilation warning */ |
<> | 149:156823d33999 | 2498 | UNUSED(hrtc); |
<> | 149:156823d33999 | 2499 | |
<> | 149:156823d33999 | 2500 | /* NOTE : This function Should not be modified, when the callback is needed, |
<> | 149:156823d33999 | 2501 | the HAL_RTCEx_AlarmBEventCallback could be implemented in the user file |
<> | 149:156823d33999 | 2502 | */ |
<> | 149:156823d33999 | 2503 | } |
<> | 149:156823d33999 | 2504 | |
<> | 149:156823d33999 | 2505 | /** |
<> | 149:156823d33999 | 2506 | * @brief This function handles AlarmB Polling request. |
<> | 149:156823d33999 | 2507 | * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains |
<> | 149:156823d33999 | 2508 | * the configuration information for RTC. |
<> | 149:156823d33999 | 2509 | * @param Timeout: Timeout duration |
<> | 149:156823d33999 | 2510 | * @retval HAL status |
<> | 149:156823d33999 | 2511 | */ |
<> | 149:156823d33999 | 2512 | HAL_StatusTypeDef HAL_RTCEx_PollForAlarmBEvent(RTC_HandleTypeDef *hrtc, uint32_t Timeout) |
<> | 149:156823d33999 | 2513 | { |
<> | 149:156823d33999 | 2514 | uint32_t tickstart = HAL_GetTick(); |
<> | 149:156823d33999 | 2515 | |
<> | 149:156823d33999 | 2516 | while(__HAL_RTC_ALARM_GET_FLAG(hrtc, RTC_FLAG_ALRBF) == RESET) |
<> | 149:156823d33999 | 2517 | { |
<> | 149:156823d33999 | 2518 | if(Timeout != HAL_MAX_DELAY) |
<> | 149:156823d33999 | 2519 | { |
<> | 149:156823d33999 | 2520 | if((Timeout == 0)||((HAL_GetTick() - tickstart ) > Timeout)) |
<> | 149:156823d33999 | 2521 | { |
<> | 149:156823d33999 | 2522 | hrtc->State = HAL_RTC_STATE_TIMEOUT; |
<> | 149:156823d33999 | 2523 | return HAL_TIMEOUT; |
<> | 149:156823d33999 | 2524 | } |
<> | 149:156823d33999 | 2525 | } |
<> | 149:156823d33999 | 2526 | } |
<> | 149:156823d33999 | 2527 | |
<> | 149:156823d33999 | 2528 | /* Clear the Alarm Flag */ |
<> | 149:156823d33999 | 2529 | __HAL_RTC_ALARM_CLEAR_FLAG(hrtc, RTC_FLAG_ALRBF); |
<> | 149:156823d33999 | 2530 | |
<> | 149:156823d33999 | 2531 | /* Change RTC state */ |
<> | 149:156823d33999 | 2532 | hrtc->State = HAL_RTC_STATE_READY; |
<> | 149:156823d33999 | 2533 | |
<> | 149:156823d33999 | 2534 | return HAL_OK; |
<> | 149:156823d33999 | 2535 | } |
<> | 149:156823d33999 | 2536 | |
<> | 149:156823d33999 | 2537 | /** |
<> | 149:156823d33999 | 2538 | * @} |
<> | 149:156823d33999 | 2539 | */ |
<> | 149:156823d33999 | 2540 | |
<> | 149:156823d33999 | 2541 | /** |
<> | 149:156823d33999 | 2542 | * @} |
<> | 149:156823d33999 | 2543 | */ |
<> | 149:156823d33999 | 2544 | |
<> | 149:156823d33999 | 2545 | /** |
<> | 149:156823d33999 | 2546 | * @} |
<> | 149:156823d33999 | 2547 | */ |
<> | 149:156823d33999 | 2548 | |
<> | 149:156823d33999 | 2549 | #endif /* HAL_RTC_MODULE_ENABLED */ |
<> | 149:156823d33999 | 2550 | |
<> | 149:156823d33999 | 2551 | /** |
<> | 149:156823d33999 | 2552 | * @} |
<> | 149:156823d33999 | 2553 | */ |
<> | 149:156823d33999 | 2554 | |
<> | 149:156823d33999 | 2555 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ |