fix LPC812 PWM
Fork of mbed-dev by
targets/cmsis/TARGET_STM/TARGET_STM32L0/stm32l0xx_hal_rtc_ex.c@0:9b334a45a8ff, 2015-10-01 (annotated)
- Committer:
- bogdanm
- Date:
- Thu Oct 01 15:25:22 2015 +0300
- Revision:
- 0:9b334a45a8ff
- Child:
- 113:b3775bf36a83
Initial commit on mbed-dev
Replaces mbed-src (now inactive)
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
bogdanm | 0:9b334a45a8ff | 1 | /** |
bogdanm | 0:9b334a45a8ff | 2 | ****************************************************************************** |
bogdanm | 0:9b334a45a8ff | 3 | * @file stm32l0xx_hal_rtc_ex.c |
bogdanm | 0:9b334a45a8ff | 4 | * @author MCD Application Team |
bogdanm | 0:9b334a45a8ff | 5 | * @version V1.2.0 |
bogdanm | 0:9b334a45a8ff | 6 | * @date 06-February-2015 |
bogdanm | 0:9b334a45a8ff | 7 | * @brief Extended RTC HAL module driver. |
bogdanm | 0:9b334a45a8ff | 8 | * |
bogdanm | 0:9b334a45a8ff | 9 | * This file provides firmware functions to manage the following |
bogdanm | 0:9b334a45a8ff | 10 | * functionalities of the Real Time Clock (RTC) Extended peripheral: |
bogdanm | 0:9b334a45a8ff | 11 | * + RTC Time Stamp functions |
bogdanm | 0:9b334a45a8ff | 12 | * + RTC Tamper functions |
bogdanm | 0:9b334a45a8ff | 13 | * + RTC Wake-up functions |
bogdanm | 0:9b334a45a8ff | 14 | * + Extended Control functions |
bogdanm | 0:9b334a45a8ff | 15 | * + Extended RTC features functions |
bogdanm | 0:9b334a45a8ff | 16 | * |
bogdanm | 0:9b334a45a8ff | 17 | @verbatim |
bogdanm | 0:9b334a45a8ff | 18 | ============================================================================== |
bogdanm | 0:9b334a45a8ff | 19 | ##### Backup Domain Operating Condition ##### |
bogdanm | 0:9b334a45a8ff | 20 | ============================================================================== |
bogdanm | 0:9b334a45a8ff | 21 | [..] As long as the supply voltage remains in the operating range, |
bogdanm | 0:9b334a45a8ff | 22 | the RTC never stops, regardless of the device status (Run mode, |
bogdanm | 0:9b334a45a8ff | 23 | low power modes or under reset). |
bogdanm | 0:9b334a45a8ff | 24 | |
bogdanm | 0:9b334a45a8ff | 25 | ##### Backup Domain Reset ##### |
bogdanm | 0:9b334a45a8ff | 26 | ================================================================== |
bogdanm | 0:9b334a45a8ff | 27 | [..] The backup domain reset sets all RTC registers and the RCC_CSR register |
bogdanm | 0:9b334a45a8ff | 28 | to their reset values. |
bogdanm | 0:9b334a45a8ff | 29 | [..] A backup domain reset is generated when one of the following events occurs: |
bogdanm | 0:9b334a45a8ff | 30 | (+) Software reset, triggered by setting the RTCRST bit in the |
bogdanm | 0:9b334a45a8ff | 31 | RCC Control Status register (RCC_CSR). |
bogdanm | 0:9b334a45a8ff | 32 | (+) Power reset (BOR/POR/PDR). |
bogdanm | 0:9b334a45a8ff | 33 | |
bogdanm | 0:9b334a45a8ff | 34 | ##### Backup Domain Access ##### |
bogdanm | 0:9b334a45a8ff | 35 | ================================================================== |
bogdanm | 0:9b334a45a8ff | 36 | [..] After reset, the backup domain (RTC registers and RTC backup data registers) |
bogdanm | 0:9b334a45a8ff | 37 | is protected against possible unwanted write accesses. |
bogdanm | 0:9b334a45a8ff | 38 | [..] To enable access to the RTC Domain and RTC registers, proceed as follows: |
bogdanm | 0:9b334a45a8ff | 39 | (+) Enable the Power Controller (PWR) APB1 interface clock using the |
bogdanm | 0:9b334a45a8ff | 40 | __HAL_RCC_PWR_CLK_ENABLE() function. |
bogdanm | 0:9b334a45a8ff | 41 | (+) Enable access to RTC domain using the HAL_PWR_EnableBkUpAccess() function. |
bogdanm | 0:9b334a45a8ff | 42 | (+) Select the RTC clock source using the __HAL_RCC_RTC_CONFIG() function. |
bogdanm | 0:9b334a45a8ff | 43 | (+) Enable RTC Clock using the __HAL_RCC_RTC_ENABLE() function. |
bogdanm | 0:9b334a45a8ff | 44 | |
bogdanm | 0:9b334a45a8ff | 45 | |
bogdanm | 0:9b334a45a8ff | 46 | ##### How to use this driver ##### |
bogdanm | 0:9b334a45a8ff | 47 | ============================================================================== |
bogdanm | 0:9b334a45a8ff | 48 | [..] |
bogdanm | 0:9b334a45a8ff | 49 | (+) Enable the RTC domain access. |
bogdanm | 0:9b334a45a8ff | 50 | (+) Configure the RTC Prescaler (Asynchronous and Synchronous) and RTC hour |
bogdanm | 0:9b334a45a8ff | 51 | format using the HAL_RTC_Init() function. |
bogdanm | 0:9b334a45a8ff | 52 | |
bogdanm | 0:9b334a45a8ff | 53 | *** Time and Date configuration *** |
bogdanm | 0:9b334a45a8ff | 54 | =================================== |
bogdanm | 0:9b334a45a8ff | 55 | [..] |
bogdanm | 0:9b334a45a8ff | 56 | (+) To configure the RTC Calendar (Time and Date) use the HAL_RTC_SetTime() |
bogdanm | 0:9b334a45a8ff | 57 | and HAL_RTC_SetDate() functions. |
bogdanm | 0:9b334a45a8ff | 58 | (+) To read the RTC Calendar, use the HAL_RTC_GetTime() and HAL_RTC_GetDate() functions. |
bogdanm | 0:9b334a45a8ff | 59 | |
bogdanm | 0:9b334a45a8ff | 60 | *** Alarm configuration *** |
bogdanm | 0:9b334a45a8ff | 61 | =========================== |
bogdanm | 0:9b334a45a8ff | 62 | [..] |
bogdanm | 0:9b334a45a8ff | 63 | (+) To configure the RTC Alarm use the HAL_RTC_SetAlarm() function. |
bogdanm | 0:9b334a45a8ff | 64 | You can also configure the RTC Alarm with interrupt mode using the HAL_RTC_SetAlarm_IT() function. |
bogdanm | 0:9b334a45a8ff | 65 | (+) To read the RTC Alarm, use the HAL_RTC_GetAlarm() function. |
bogdanm | 0:9b334a45a8ff | 66 | |
bogdanm | 0:9b334a45a8ff | 67 | *** RTC Wakeup configuration *** |
bogdanm | 0:9b334a45a8ff | 68 | ================================ |
bogdanm | 0:9b334a45a8ff | 69 | [..] |
bogdanm | 0:9b334a45a8ff | 70 | (+) To configure the RTC Wakeup Clock source and Counter use the HAL_RTCEx_SetWakeUpTimer() |
bogdanm | 0:9b334a45a8ff | 71 | function. You can also configure the RTC Wakeup timer with interrupt mode |
bogdanm | 0:9b334a45a8ff | 72 | using the HAL_RTCEx_SetWakeUpTimer_IT() function. |
bogdanm | 0:9b334a45a8ff | 73 | (+) To read the RTC WakeUp Counter register, use the HAL_RTCEx_GetWakeUpTimer() |
bogdanm | 0:9b334a45a8ff | 74 | function. |
bogdanm | 0:9b334a45a8ff | 75 | |
bogdanm | 0:9b334a45a8ff | 76 | *** Outputs configuration *** |
bogdanm | 0:9b334a45a8ff | 77 | ============================= |
bogdanm | 0:9b334a45a8ff | 78 | [..] The RTC has 2 different outputs: |
bogdanm | 0:9b334a45a8ff | 79 | (+) RTC_ALARM: this output is used to manage the RTC Alarm A, Alarm B |
bogdanm | 0:9b334a45a8ff | 80 | and WaKeUp signals. |
bogdanm | 0:9b334a45a8ff | 81 | To output the selected RTC signal, use the HAL_RTC_Init() function. |
bogdanm | 0:9b334a45a8ff | 82 | (+) RTC_CALIB: this output is 512Hz signal or 1Hz. |
bogdanm | 0:9b334a45a8ff | 83 | To enable the RTC_CALIB, use the HAL_RTCEx_SetCalibrationOutPut() function. |
bogdanm | 0:9b334a45a8ff | 84 | (+) Two pins can be used as RTC_ALARM or RTC_CALIB (PC13, PB14) managed on |
bogdanm | 0:9b334a45a8ff | 85 | the RTC_OR register. |
bogdanm | 0:9b334a45a8ff | 86 | (+) When the RTC_CALIB or RTC_ALARM output is selected, the RTC_OUT pin is |
bogdanm | 0:9b334a45a8ff | 87 | automatically configured in output alternate function. |
bogdanm | 0:9b334a45a8ff | 88 | |
bogdanm | 0:9b334a45a8ff | 89 | *** Smooth digital Calibration configuration *** |
bogdanm | 0:9b334a45a8ff | 90 | ================================================ |
bogdanm | 0:9b334a45a8ff | 91 | [..] |
bogdanm | 0:9b334a45a8ff | 92 | (+) Configure the RTC Original Digital Calibration Value and the corresponding |
bogdanm | 0:9b334a45a8ff | 93 | calibration cycle period (32s,16s and 8s) using the HAL_RTCEx_SetSmoothCalib() |
bogdanm | 0:9b334a45a8ff | 94 | function. |
bogdanm | 0:9b334a45a8ff | 95 | |
bogdanm | 0:9b334a45a8ff | 96 | *** TimeStamp configuration *** |
bogdanm | 0:9b334a45a8ff | 97 | =============================== |
bogdanm | 0:9b334a45a8ff | 98 | [..] |
bogdanm | 0:9b334a45a8ff | 99 | (+) Enables the RTC TimeStamp using the HAL_RTC_SetTimeStamp() function. |
bogdanm | 0:9b334a45a8ff | 100 | You can also configure the RTC TimeStamp with interrupt mode using the |
bogdanm | 0:9b334a45a8ff | 101 | HAL_RTC_SetTimeStamp_IT() function. |
bogdanm | 0:9b334a45a8ff | 102 | (+) To read the RTC TimeStamp Time and Date register, use the HAL_RTC_GetTimeStamp() |
bogdanm | 0:9b334a45a8ff | 103 | function. |
bogdanm | 0:9b334a45a8ff | 104 | |
bogdanm | 0:9b334a45a8ff | 105 | *** Tamper configuration *** |
bogdanm | 0:9b334a45a8ff | 106 | ============================ |
bogdanm | 0:9b334a45a8ff | 107 | [..] |
bogdanm | 0:9b334a45a8ff | 108 | (+) Enable the RTC Tamper and Configure the Tamper filter count, trigger Edge |
bogdanm | 0:9b334a45a8ff | 109 | or Level according to the Tamper filter (if equal to 0 Edge else Level) |
bogdanm | 0:9b334a45a8ff | 110 | value, sampling frequency, NoErase, MaskFlag, precharge or discharge and |
bogdanm | 0:9b334a45a8ff | 111 | Pull-UP using the HAL_RTC_SetTamper() function. You can configure RTC Tamper |
bogdanm | 0:9b334a45a8ff | 112 | with interrupt mode using HAL_RTC_SetTamper_IT() function. |
bogdanm | 0:9b334a45a8ff | 113 | (+) The default configuration of the Tamper erases the backup registers. To avoid |
bogdanm | 0:9b334a45a8ff | 114 | erase, enable the NoErase field on the RTC_TAMPCR register. |
bogdanm | 0:9b334a45a8ff | 115 | |
bogdanm | 0:9b334a45a8ff | 116 | *** Backup Data Registers configuration *** |
bogdanm | 0:9b334a45a8ff | 117 | =========================================== |
bogdanm | 0:9b334a45a8ff | 118 | [..] |
bogdanm | 0:9b334a45a8ff | 119 | (+) To write to the RTC Backup Data registers, use the HAL_RTC_BKUPWrite() |
bogdanm | 0:9b334a45a8ff | 120 | function. |
bogdanm | 0:9b334a45a8ff | 121 | (+) To read the RTC Backup Data registers, use the HAL_RTC_BKUPRead() |
bogdanm | 0:9b334a45a8ff | 122 | function. |
bogdanm | 0:9b334a45a8ff | 123 | (+) The backup registers are reset when a tamper detection event occurs |
bogdanm | 0:9b334a45a8ff | 124 | |
bogdanm | 0:9b334a45a8ff | 125 | |
bogdanm | 0:9b334a45a8ff | 126 | ##### RTC and low power modes ##### |
bogdanm | 0:9b334a45a8ff | 127 | ================================================================== |
bogdanm | 0:9b334a45a8ff | 128 | [..] The MCU can be woken up from a low power mode by an RTC alternate |
bogdanm | 0:9b334a45a8ff | 129 | function. |
bogdanm | 0:9b334a45a8ff | 130 | [..] The RTC alternate functions are the RTC alarms (Alarm A and Alarm B), |
bogdanm | 0:9b334a45a8ff | 131 | RTC wakeup, RTC tamper event detection and RTC time stamp event detection. |
bogdanm | 0:9b334a45a8ff | 132 | These RTC alternate functions can wake up the system from the Stop and |
bogdanm | 0:9b334a45a8ff | 133 | Standby low power modes. |
bogdanm | 0:9b334a45a8ff | 134 | [..] The system can also wake up from low power modes without depending |
bogdanm | 0:9b334a45a8ff | 135 | on an external interrupt (Auto-wakeup mode), by using the RTC alarm |
bogdanm | 0:9b334a45a8ff | 136 | or the RTC wakeup events. |
bogdanm | 0:9b334a45a8ff | 137 | [..] The RTC provides a programmable time base for waking up from the |
bogdanm | 0:9b334a45a8ff | 138 | Stop or Standby mode at regular intervals. |
bogdanm | 0:9b334a45a8ff | 139 | Wakeup from STOP and Standby modes is possible only when the RTC clock source |
bogdanm | 0:9b334a45a8ff | 140 | is LSE or LSI. |
bogdanm | 0:9b334a45a8ff | 141 | |
bogdanm | 0:9b334a45a8ff | 142 | @endverbatim |
bogdanm | 0:9b334a45a8ff | 143 | ****************************************************************************** |
bogdanm | 0:9b334a45a8ff | 144 | * @attention |
bogdanm | 0:9b334a45a8ff | 145 | * |
bogdanm | 0:9b334a45a8ff | 146 | * <h2><center>© COPYRIGHT(c) 2015 STMicroelectronics</center></h2> |
bogdanm | 0:9b334a45a8ff | 147 | * |
bogdanm | 0:9b334a45a8ff | 148 | * Redistribution and use in source and binary forms, with or without modification, |
bogdanm | 0:9b334a45a8ff | 149 | * are permitted provided that the following conditions are met: |
bogdanm | 0:9b334a45a8ff | 150 | * 1. Redistributions of source code must retain the above copyright notice, |
bogdanm | 0:9b334a45a8ff | 151 | * this list of conditions and the following disclaimer. |
bogdanm | 0:9b334a45a8ff | 152 | * 2. Redistributions in binary form must reproduce the above copyright notice, |
bogdanm | 0:9b334a45a8ff | 153 | * this list of conditions and the following disclaimer in the documentation |
bogdanm | 0:9b334a45a8ff | 154 | * and/or other materials provided with the distribution. |
bogdanm | 0:9b334a45a8ff | 155 | * 3. Neither the name of STMicroelectronics nor the names of its contributors |
bogdanm | 0:9b334a45a8ff | 156 | * may be used to endorse or promote products derived from this software |
bogdanm | 0:9b334a45a8ff | 157 | * without specific prior written permission. |
bogdanm | 0:9b334a45a8ff | 158 | * |
bogdanm | 0:9b334a45a8ff | 159 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
bogdanm | 0:9b334a45a8ff | 160 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
bogdanm | 0:9b334a45a8ff | 161 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
bogdanm | 0:9b334a45a8ff | 162 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE |
bogdanm | 0:9b334a45a8ff | 163 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
bogdanm | 0:9b334a45a8ff | 164 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |
bogdanm | 0:9b334a45a8ff | 165 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
bogdanm | 0:9b334a45a8ff | 166 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |
bogdanm | 0:9b334a45a8ff | 167 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
bogdanm | 0:9b334a45a8ff | 168 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
bogdanm | 0:9b334a45a8ff | 169 | * |
bogdanm | 0:9b334a45a8ff | 170 | ****************************************************************************** |
bogdanm | 0:9b334a45a8ff | 171 | */ |
bogdanm | 0:9b334a45a8ff | 172 | |
bogdanm | 0:9b334a45a8ff | 173 | /* Includes ------------------------------------------------------------------*/ |
bogdanm | 0:9b334a45a8ff | 174 | #include "stm32l0xx_hal.h" |
bogdanm | 0:9b334a45a8ff | 175 | |
bogdanm | 0:9b334a45a8ff | 176 | /** @addtogroup STM32L0xx_HAL_Driver |
bogdanm | 0:9b334a45a8ff | 177 | * @{ |
bogdanm | 0:9b334a45a8ff | 178 | */ |
bogdanm | 0:9b334a45a8ff | 179 | |
bogdanm | 0:9b334a45a8ff | 180 | /** @addtogroup RTCEx |
bogdanm | 0:9b334a45a8ff | 181 | * @brief RTC Extended HAL module driver |
bogdanm | 0:9b334a45a8ff | 182 | * @{ |
bogdanm | 0:9b334a45a8ff | 183 | */ |
bogdanm | 0:9b334a45a8ff | 184 | |
bogdanm | 0:9b334a45a8ff | 185 | #ifdef HAL_RTC_MODULE_ENABLED |
bogdanm | 0:9b334a45a8ff | 186 | |
bogdanm | 0:9b334a45a8ff | 187 | /* Private typedef -----------------------------------------------------------*/ |
bogdanm | 0:9b334a45a8ff | 188 | /* Private define ------------------------------------------------------------*/ |
bogdanm | 0:9b334a45a8ff | 189 | /* Private macro -------------------------------------------------------------*/ |
bogdanm | 0:9b334a45a8ff | 190 | /* Private variables ---------------------------------------------------------*/ |
bogdanm | 0:9b334a45a8ff | 191 | /* Private function prototypes -----------------------------------------------*/ |
bogdanm | 0:9b334a45a8ff | 192 | /* Exported functions --------------------------------------------------------*/ |
bogdanm | 0:9b334a45a8ff | 193 | |
bogdanm | 0:9b334a45a8ff | 194 | /** @addtogroup RTCEx_Exported_Functions |
bogdanm | 0:9b334a45a8ff | 195 | * @{ |
bogdanm | 0:9b334a45a8ff | 196 | */ |
bogdanm | 0:9b334a45a8ff | 197 | |
bogdanm | 0:9b334a45a8ff | 198 | |
bogdanm | 0:9b334a45a8ff | 199 | /** @addtogroup RTCEx_Exported_Functions_Group1 |
bogdanm | 0:9b334a45a8ff | 200 | * @brief RTC TimeStamp and Tamper functions |
bogdanm | 0:9b334a45a8ff | 201 | * |
bogdanm | 0:9b334a45a8ff | 202 | @verbatim |
bogdanm | 0:9b334a45a8ff | 203 | =============================================================================== |
bogdanm | 0:9b334a45a8ff | 204 | ##### RTC TimeStamp and Tamper functions ##### |
bogdanm | 0:9b334a45a8ff | 205 | =============================================================================== |
bogdanm | 0:9b334a45a8ff | 206 | |
bogdanm | 0:9b334a45a8ff | 207 | [..] This section provide functions allowing to configure TimeStamp feature |
bogdanm | 0:9b334a45a8ff | 208 | |
bogdanm | 0:9b334a45a8ff | 209 | @endverbatim |
bogdanm | 0:9b334a45a8ff | 210 | * @{ |
bogdanm | 0:9b334a45a8ff | 211 | */ |
bogdanm | 0:9b334a45a8ff | 212 | |
bogdanm | 0:9b334a45a8ff | 213 | /** |
bogdanm | 0:9b334a45a8ff | 214 | * @brief Sets TimeStamp. |
bogdanm | 0:9b334a45a8ff | 215 | * @note This API must be called before enabling the TimeStamp feature. |
bogdanm | 0:9b334a45a8ff | 216 | * @param hrtc: RTC handle |
bogdanm | 0:9b334a45a8ff | 217 | * @param TimeStampEdge: Specifies the pin edge on which the TimeStamp is |
bogdanm | 0:9b334a45a8ff | 218 | * activated. |
bogdanm | 0:9b334a45a8ff | 219 | * This parameter can be one of the following values: |
bogdanm | 0:9b334a45a8ff | 220 | * @arg RTC_TIMESTAMPEDGE_RISING: the Time stamp event occurs on the |
bogdanm | 0:9b334a45a8ff | 221 | * rising edge of the related pin. |
bogdanm | 0:9b334a45a8ff | 222 | * @arg RTC_TIMESTAMPEDGE_FALLING: the Time stamp event occurs on the |
bogdanm | 0:9b334a45a8ff | 223 | * falling edge of the related pin. |
bogdanm | 0:9b334a45a8ff | 224 | * @param RTC_TimeStampPin: specifies the RTC TimeStamp Pin. |
bogdanm | 0:9b334a45a8ff | 225 | * This parameter can be one of the following values: |
bogdanm | 0:9b334a45a8ff | 226 | * @arg RTC_TIMESTAMPPIN_PC13: PC13 is selected as RTC TimeStamp Pin. |
bogdanm | 0:9b334a45a8ff | 227 | * The RTC TimeStamp Pin is per default PC13, but for reasons of |
bogdanm | 0:9b334a45a8ff | 228 | * compatibility, this parameter is used. |
bogdanm | 0:9b334a45a8ff | 229 | * @retval HAL status |
bogdanm | 0:9b334a45a8ff | 230 | */ |
bogdanm | 0:9b334a45a8ff | 231 | HAL_StatusTypeDef HAL_RTCEx_SetTimeStamp(RTC_HandleTypeDef *hrtc, uint32_t TimeStampEdge, uint32_t RTC_TimeStampPin) |
bogdanm | 0:9b334a45a8ff | 232 | { |
bogdanm | 0:9b334a45a8ff | 233 | uint32_t tmpreg = 0; |
bogdanm | 0:9b334a45a8ff | 234 | |
bogdanm | 0:9b334a45a8ff | 235 | /* Check the parameters */ |
bogdanm | 0:9b334a45a8ff | 236 | assert_param(IS_TIMESTAMP_EDGE(TimeStampEdge)); |
bogdanm | 0:9b334a45a8ff | 237 | assert_param(IS_RTC_TIMESTAMP_PIN(RTC_TimeStampPin)); |
bogdanm | 0:9b334a45a8ff | 238 | |
bogdanm | 0:9b334a45a8ff | 239 | /* Process Locked */ |
bogdanm | 0:9b334a45a8ff | 240 | __HAL_LOCK(hrtc); |
bogdanm | 0:9b334a45a8ff | 241 | |
bogdanm | 0:9b334a45a8ff | 242 | hrtc->State = HAL_RTC_STATE_BUSY; |
bogdanm | 0:9b334a45a8ff | 243 | |
bogdanm | 0:9b334a45a8ff | 244 | /* Get the RTC_CR register and clear the bits to be configured */ |
bogdanm | 0:9b334a45a8ff | 245 | tmpreg = (uint32_t)(hrtc->Instance->CR & (uint32_t)~(RTC_CR_TSEDGE | RTC_CR_TSE)); |
bogdanm | 0:9b334a45a8ff | 246 | |
bogdanm | 0:9b334a45a8ff | 247 | tmpreg|= TimeStampEdge; |
bogdanm | 0:9b334a45a8ff | 248 | |
bogdanm | 0:9b334a45a8ff | 249 | /* Disable the write protection for RTC registers */ |
bogdanm | 0:9b334a45a8ff | 250 | __HAL_RTC_WRITEPROTECTION_DISABLE(hrtc); |
bogdanm | 0:9b334a45a8ff | 251 | |
bogdanm | 0:9b334a45a8ff | 252 | /* Configure the Time Stamp TSEDGE and Enable bits */ |
bogdanm | 0:9b334a45a8ff | 253 | hrtc->Instance->CR = (uint32_t)tmpreg; |
bogdanm | 0:9b334a45a8ff | 254 | |
bogdanm | 0:9b334a45a8ff | 255 | __HAL_RTC_TIMESTAMP_ENABLE(hrtc); |
bogdanm | 0:9b334a45a8ff | 256 | |
bogdanm | 0:9b334a45a8ff | 257 | /* Enable the write protection for RTC registers */ |
bogdanm | 0:9b334a45a8ff | 258 | __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc); |
bogdanm | 0:9b334a45a8ff | 259 | |
bogdanm | 0:9b334a45a8ff | 260 | /* Change RTC state */ |
bogdanm | 0:9b334a45a8ff | 261 | hrtc->State = HAL_RTC_STATE_READY; |
bogdanm | 0:9b334a45a8ff | 262 | |
bogdanm | 0:9b334a45a8ff | 263 | /* Process Unlocked */ |
bogdanm | 0:9b334a45a8ff | 264 | __HAL_UNLOCK(hrtc); |
bogdanm | 0:9b334a45a8ff | 265 | |
bogdanm | 0:9b334a45a8ff | 266 | return HAL_OK; |
bogdanm | 0:9b334a45a8ff | 267 | } |
bogdanm | 0:9b334a45a8ff | 268 | |
bogdanm | 0:9b334a45a8ff | 269 | /** |
bogdanm | 0:9b334a45a8ff | 270 | * @brief Sets TimeStamp with Interrupt. |
bogdanm | 0:9b334a45a8ff | 271 | * @param hrtc: RTC handle |
bogdanm | 0:9b334a45a8ff | 272 | * @note This API must be called before enabling the TimeStamp feature. |
bogdanm | 0:9b334a45a8ff | 273 | * @param TimeStampEdge: Specifies the pin edge on which the TimeStamp is |
bogdanm | 0:9b334a45a8ff | 274 | * activated. |
bogdanm | 0:9b334a45a8ff | 275 | * This parameter can be one of the following values: |
bogdanm | 0:9b334a45a8ff | 276 | * @arg RTC_TIMESTAMPEDGE_RISING: the Time stamp event occurs on the |
bogdanm | 0:9b334a45a8ff | 277 | * rising edge of the related pin. |
bogdanm | 0:9b334a45a8ff | 278 | * @arg RTC_TIMESTAMPEDGE_FALLING: the Time stamp event occurs on the |
bogdanm | 0:9b334a45a8ff | 279 | * falling edge of the related pin. |
bogdanm | 0:9b334a45a8ff | 280 | * @param RTC_TimeStampPin: Specifies the RTC TimeStamp Pin. |
bogdanm | 0:9b334a45a8ff | 281 | * This parameter can be one of the following values: |
bogdanm | 0:9b334a45a8ff | 282 | * @arg RTC_TIMESTAMPPIN_PC13: PC13 is selected as RTC TimeStamp Pin. |
bogdanm | 0:9b334a45a8ff | 283 | * The RTC TimeStamp Pin is per default PC13, but for reasons of |
bogdanm | 0:9b334a45a8ff | 284 | * compatibility, this parameter is used. |
bogdanm | 0:9b334a45a8ff | 285 | * @retval HAL status |
bogdanm | 0:9b334a45a8ff | 286 | */ |
bogdanm | 0:9b334a45a8ff | 287 | HAL_StatusTypeDef HAL_RTCEx_SetTimeStamp_IT(RTC_HandleTypeDef *hrtc, uint32_t TimeStampEdge, uint32_t RTC_TimeStampPin) |
bogdanm | 0:9b334a45a8ff | 288 | { |
bogdanm | 0:9b334a45a8ff | 289 | uint32_t tmpreg = 0; |
bogdanm | 0:9b334a45a8ff | 290 | |
bogdanm | 0:9b334a45a8ff | 291 | /* Check the parameters */ |
bogdanm | 0:9b334a45a8ff | 292 | assert_param(IS_TIMESTAMP_EDGE(TimeStampEdge)); |
bogdanm | 0:9b334a45a8ff | 293 | assert_param(IS_RTC_TIMESTAMP_PIN(RTC_TimeStampPin)); |
bogdanm | 0:9b334a45a8ff | 294 | |
bogdanm | 0:9b334a45a8ff | 295 | /* Process Locked */ |
bogdanm | 0:9b334a45a8ff | 296 | __HAL_LOCK(hrtc); |
bogdanm | 0:9b334a45a8ff | 297 | |
bogdanm | 0:9b334a45a8ff | 298 | hrtc->State = HAL_RTC_STATE_BUSY; |
bogdanm | 0:9b334a45a8ff | 299 | |
bogdanm | 0:9b334a45a8ff | 300 | /* Get the RTC_CR register and clear the bits to be configured */ |
bogdanm | 0:9b334a45a8ff | 301 | tmpreg = (uint32_t)(hrtc->Instance->CR & (uint32_t)~(RTC_CR_TSEDGE | RTC_CR_TSE)); |
bogdanm | 0:9b334a45a8ff | 302 | |
bogdanm | 0:9b334a45a8ff | 303 | tmpreg |= TimeStampEdge; |
bogdanm | 0:9b334a45a8ff | 304 | |
bogdanm | 0:9b334a45a8ff | 305 | /* Disable the write protection for RTC registers */ |
bogdanm | 0:9b334a45a8ff | 306 | __HAL_RTC_WRITEPROTECTION_DISABLE(hrtc); |
bogdanm | 0:9b334a45a8ff | 307 | |
bogdanm | 0:9b334a45a8ff | 308 | /* Configure the Time Stamp TSEDGE and Enable bits */ |
bogdanm | 0:9b334a45a8ff | 309 | hrtc->Instance->CR = (uint32_t)tmpreg; |
bogdanm | 0:9b334a45a8ff | 310 | |
bogdanm | 0:9b334a45a8ff | 311 | __HAL_RTC_TIMESTAMP_ENABLE(hrtc); |
bogdanm | 0:9b334a45a8ff | 312 | |
bogdanm | 0:9b334a45a8ff | 313 | /* Enable IT timestamp */ |
bogdanm | 0:9b334a45a8ff | 314 | __HAL_RTC_TIMESTAMP_ENABLE_IT(hrtc,RTC_IT_TS); |
bogdanm | 0:9b334a45a8ff | 315 | |
bogdanm | 0:9b334a45a8ff | 316 | /* RTC timestamp Interrupt Configuration: EXTI configuration */ |
bogdanm | 0:9b334a45a8ff | 317 | __HAL_RTC_TAMPER_TIMESTAMP_EXTI_ENABLE_IT(); |
bogdanm | 0:9b334a45a8ff | 318 | |
bogdanm | 0:9b334a45a8ff | 319 | __HAL_RTC_TAMPER_TIMESTAMP_EXTI_ENABLE_RISING_EDGE(); |
bogdanm | 0:9b334a45a8ff | 320 | |
bogdanm | 0:9b334a45a8ff | 321 | /* Enable the write protection for RTC registers */ |
bogdanm | 0:9b334a45a8ff | 322 | __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc); |
bogdanm | 0:9b334a45a8ff | 323 | |
bogdanm | 0:9b334a45a8ff | 324 | hrtc->State = HAL_RTC_STATE_READY; |
bogdanm | 0:9b334a45a8ff | 325 | |
bogdanm | 0:9b334a45a8ff | 326 | /* Process Unlocked */ |
bogdanm | 0:9b334a45a8ff | 327 | __HAL_UNLOCK(hrtc); |
bogdanm | 0:9b334a45a8ff | 328 | |
bogdanm | 0:9b334a45a8ff | 329 | return HAL_OK; |
bogdanm | 0:9b334a45a8ff | 330 | } |
bogdanm | 0:9b334a45a8ff | 331 | |
bogdanm | 0:9b334a45a8ff | 332 | /** |
bogdanm | 0:9b334a45a8ff | 333 | * @brief Deactivates TimeStamp. |
bogdanm | 0:9b334a45a8ff | 334 | * @param hrtc: RTC handle |
bogdanm | 0:9b334a45a8ff | 335 | * @retval HAL status |
bogdanm | 0:9b334a45a8ff | 336 | */ |
bogdanm | 0:9b334a45a8ff | 337 | HAL_StatusTypeDef HAL_RTCEx_DeactivateTimeStamp(RTC_HandleTypeDef *hrtc) |
bogdanm | 0:9b334a45a8ff | 338 | { |
bogdanm | 0:9b334a45a8ff | 339 | uint32_t tmpreg = 0; |
bogdanm | 0:9b334a45a8ff | 340 | |
bogdanm | 0:9b334a45a8ff | 341 | /* Process Locked */ |
bogdanm | 0:9b334a45a8ff | 342 | __HAL_LOCK(hrtc); |
bogdanm | 0:9b334a45a8ff | 343 | |
bogdanm | 0:9b334a45a8ff | 344 | hrtc->State = HAL_RTC_STATE_BUSY; |
bogdanm | 0:9b334a45a8ff | 345 | |
bogdanm | 0:9b334a45a8ff | 346 | /* Disable the write protection for RTC registers */ |
bogdanm | 0:9b334a45a8ff | 347 | __HAL_RTC_WRITEPROTECTION_DISABLE(hrtc); |
bogdanm | 0:9b334a45a8ff | 348 | |
bogdanm | 0:9b334a45a8ff | 349 | /* In case of interrupt mode is used, the interrupt source must disabled */ |
bogdanm | 0:9b334a45a8ff | 350 | __HAL_RTC_TIMESTAMP_DISABLE_IT(hrtc, RTC_IT_TS); |
bogdanm | 0:9b334a45a8ff | 351 | |
bogdanm | 0:9b334a45a8ff | 352 | /* Get the RTC_CR register and clear the bits to be configured */ |
bogdanm | 0:9b334a45a8ff | 353 | tmpreg = (uint32_t)(hrtc->Instance->CR & (uint32_t)~(RTC_CR_TSEDGE | RTC_CR_TSE)); |
bogdanm | 0:9b334a45a8ff | 354 | |
bogdanm | 0:9b334a45a8ff | 355 | /* Configure the Time Stamp TSEDGE and Enable bits */ |
bogdanm | 0:9b334a45a8ff | 356 | hrtc->Instance->CR = (uint32_t)tmpreg; |
bogdanm | 0:9b334a45a8ff | 357 | |
bogdanm | 0:9b334a45a8ff | 358 | /* Enable the write protection for RTC registers */ |
bogdanm | 0:9b334a45a8ff | 359 | __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc); |
bogdanm | 0:9b334a45a8ff | 360 | |
bogdanm | 0:9b334a45a8ff | 361 | hrtc->State = HAL_RTC_STATE_READY; |
bogdanm | 0:9b334a45a8ff | 362 | |
bogdanm | 0:9b334a45a8ff | 363 | /* Process Unlocked */ |
bogdanm | 0:9b334a45a8ff | 364 | __HAL_UNLOCK(hrtc); |
bogdanm | 0:9b334a45a8ff | 365 | |
bogdanm | 0:9b334a45a8ff | 366 | return HAL_OK; |
bogdanm | 0:9b334a45a8ff | 367 | } |
bogdanm | 0:9b334a45a8ff | 368 | |
bogdanm | 0:9b334a45a8ff | 369 | |
bogdanm | 0:9b334a45a8ff | 370 | /** |
bogdanm | 0:9b334a45a8ff | 371 | * @brief Gets the RTC TimeStamp value. |
bogdanm | 0:9b334a45a8ff | 372 | * @param hrtc: RTC handle |
bogdanm | 0:9b334a45a8ff | 373 | |
bogdanm | 0:9b334a45a8ff | 374 | * @param sTimeStamp: Pointer to Time structure |
bogdanm | 0:9b334a45a8ff | 375 | * @param sTimeStampDate: Pointer to Date structure |
bogdanm | 0:9b334a45a8ff | 376 | * @param Format: specifies the format of the entered parameters. |
bogdanm | 0:9b334a45a8ff | 377 | * This parameter can be one of the following values: |
bogdanm | 0:9b334a45a8ff | 378 | * RTC_FORMAT_BIN: Binary data format |
bogdanm | 0:9b334a45a8ff | 379 | * RTC_FORMAT_BCD |
bogdanm | 0:9b334a45a8ff | 380 | : BCD data format |
bogdanm | 0:9b334a45a8ff | 381 | * @retval HAL status |
bogdanm | 0:9b334a45a8ff | 382 | */ |
bogdanm | 0:9b334a45a8ff | 383 | HAL_StatusTypeDef HAL_RTCEx_GetTimeStamp(RTC_HandleTypeDef *hrtc, RTC_TimeTypeDef* sTimeStamp, RTC_DateTypeDef* sTimeStampDate, uint32_t Format) |
bogdanm | 0:9b334a45a8ff | 384 | { |
bogdanm | 0:9b334a45a8ff | 385 | uint32_t tmptime = 0, tmpdate = 0; |
bogdanm | 0:9b334a45a8ff | 386 | |
bogdanm | 0:9b334a45a8ff | 387 | /* Check the parameters */ |
bogdanm | 0:9b334a45a8ff | 388 | assert_param(IS_RTC_FORMAT(Format)); |
bogdanm | 0:9b334a45a8ff | 389 | |
bogdanm | 0:9b334a45a8ff | 390 | /* Get the TimeStamp time and date registers values */ |
bogdanm | 0:9b334a45a8ff | 391 | tmptime = (uint32_t)(hrtc->Instance->TSTR & RTC_TR_RESERVED_MASK); |
bogdanm | 0:9b334a45a8ff | 392 | tmpdate = (uint32_t)(hrtc->Instance->TSDR & RTC_DR_RESERVED_MASK); |
bogdanm | 0:9b334a45a8ff | 393 | |
bogdanm | 0:9b334a45a8ff | 394 | /* Fill the Time structure fields with the read parameters */ |
bogdanm | 0:9b334a45a8ff | 395 | sTimeStamp->Hours = (uint8_t)((tmptime & (RTC_TR_HT | RTC_TR_HU)) >> 16); |
bogdanm | 0:9b334a45a8ff | 396 | sTimeStamp->Minutes = (uint8_t)((tmptime & (RTC_TR_MNT | RTC_TR_MNU)) >> 8); |
bogdanm | 0:9b334a45a8ff | 397 | sTimeStamp->Seconds = (uint8_t)(tmptime & (RTC_TR_ST | RTC_TR_SU)); |
bogdanm | 0:9b334a45a8ff | 398 | sTimeStamp->TimeFormat = (uint8_t)((tmptime & (RTC_TR_PM)) >> 16); |
bogdanm | 0:9b334a45a8ff | 399 | sTimeStamp->SubSeconds = (uint32_t) hrtc->Instance->TSSSR; |
bogdanm | 0:9b334a45a8ff | 400 | |
bogdanm | 0:9b334a45a8ff | 401 | /* Fill the Date structure fields with the read parameters */ |
bogdanm | 0:9b334a45a8ff | 402 | sTimeStampDate->Year = 0; |
bogdanm | 0:9b334a45a8ff | 403 | sTimeStampDate->Month = (uint8_t)((tmpdate & (RTC_DR_MT | RTC_DR_MU)) >> 8); |
bogdanm | 0:9b334a45a8ff | 404 | sTimeStampDate->Date = (uint8_t)(tmpdate & (RTC_DR_DT | RTC_DR_DU)); |
bogdanm | 0:9b334a45a8ff | 405 | sTimeStampDate->WeekDay = (uint8_t)((tmpdate & (RTC_DR_WDU)) >> 13); |
bogdanm | 0:9b334a45a8ff | 406 | |
bogdanm | 0:9b334a45a8ff | 407 | /* Check the input parameters format */ |
bogdanm | 0:9b334a45a8ff | 408 | if(Format == RTC_FORMAT_BIN) |
bogdanm | 0:9b334a45a8ff | 409 | { |
bogdanm | 0:9b334a45a8ff | 410 | /* Convert the TimeStamp structure parameters to Binary format */ |
bogdanm | 0:9b334a45a8ff | 411 | sTimeStamp->Hours = (uint8_t)RTC_Bcd2ToByte(sTimeStamp->Hours); |
bogdanm | 0:9b334a45a8ff | 412 | sTimeStamp->Minutes = (uint8_t)RTC_Bcd2ToByte(sTimeStamp->Minutes); |
bogdanm | 0:9b334a45a8ff | 413 | sTimeStamp->Seconds = (uint8_t)RTC_Bcd2ToByte(sTimeStamp->Seconds); |
bogdanm | 0:9b334a45a8ff | 414 | |
bogdanm | 0:9b334a45a8ff | 415 | /* Convert the DateTimeStamp structure parameters to Binary format */ |
bogdanm | 0:9b334a45a8ff | 416 | sTimeStampDate->Month = (uint8_t)RTC_Bcd2ToByte(sTimeStampDate->Month); |
bogdanm | 0:9b334a45a8ff | 417 | sTimeStampDate->Date = (uint8_t)RTC_Bcd2ToByte(sTimeStampDate->Date); |
bogdanm | 0:9b334a45a8ff | 418 | sTimeStampDate->WeekDay = (uint8_t)RTC_Bcd2ToByte(sTimeStampDate->WeekDay); |
bogdanm | 0:9b334a45a8ff | 419 | } |
bogdanm | 0:9b334a45a8ff | 420 | |
bogdanm | 0:9b334a45a8ff | 421 | /* Clear the TIMESTAMP Flag */ |
bogdanm | 0:9b334a45a8ff | 422 | __HAL_RTC_TIMESTAMP_CLEAR_FLAG(hrtc, RTC_FLAG_TSF); |
bogdanm | 0:9b334a45a8ff | 423 | |
bogdanm | 0:9b334a45a8ff | 424 | return HAL_OK; |
bogdanm | 0:9b334a45a8ff | 425 | } |
bogdanm | 0:9b334a45a8ff | 426 | |
bogdanm | 0:9b334a45a8ff | 427 | /** |
bogdanm | 0:9b334a45a8ff | 428 | * @brief Sets Tamper |
bogdanm | 0:9b334a45a8ff | 429 | * @note By calling this API we disable the tamper interrupt for all tampers. |
bogdanm | 0:9b334a45a8ff | 430 | * @param hrtc: RTC handle |
bogdanm | 0:9b334a45a8ff | 431 | * @param sTamper: Pointer to Tamper Structure. |
bogdanm | 0:9b334a45a8ff | 432 | * @retval HAL status |
bogdanm | 0:9b334a45a8ff | 433 | */ |
bogdanm | 0:9b334a45a8ff | 434 | HAL_StatusTypeDef HAL_RTCEx_SetTamper(RTC_HandleTypeDef *hrtc, RTC_TamperTypeDef* sTamper) |
bogdanm | 0:9b334a45a8ff | 435 | { |
bogdanm | 0:9b334a45a8ff | 436 | uint32_t tmpreg = 0; |
bogdanm | 0:9b334a45a8ff | 437 | |
bogdanm | 0:9b334a45a8ff | 438 | /* Check the parameters */ |
bogdanm | 0:9b334a45a8ff | 439 | assert_param( IS_RTC_TAMPER(sTamper->Tamper)); |
bogdanm | 0:9b334a45a8ff | 440 | assert_param( IS_RTC_TAMPER_TRIGGER(sTamper->Trigger)); |
bogdanm | 0:9b334a45a8ff | 441 | assert_param(IS_RTC_TAMPER_ERASE_MODE(sTamper->NoErase)); |
bogdanm | 0:9b334a45a8ff | 442 | assert_param(IS_RTC_TAMPER_MASKFLAG_STATE(sTamper->MaskFlag)); |
bogdanm | 0:9b334a45a8ff | 443 | assert_param(IS_RTC_TAMPER_FILTER(sTamper->Filter)); |
bogdanm | 0:9b334a45a8ff | 444 | assert_param(IS_RTC_TAMPER_SAMPLING_FREQ(sTamper->SamplingFrequency)); |
bogdanm | 0:9b334a45a8ff | 445 | assert_param(IS_RTC_TAMPER_PRECHARGE_DURATION(sTamper->PrechargeDuration)); |
bogdanm | 0:9b334a45a8ff | 446 | assert_param(IS_RTC_TAMPER_PULLUP_STATE(sTamper->TamperPullUp)); |
bogdanm | 0:9b334a45a8ff | 447 | assert_param(IS_RTC_TAMPER_TIMESTAMPONTAMPER_DETECTION(sTamper->TimeStampOnTamperDetection)); |
bogdanm | 0:9b334a45a8ff | 448 | |
bogdanm | 0:9b334a45a8ff | 449 | /* Process Locked */ |
bogdanm | 0:9b334a45a8ff | 450 | __HAL_LOCK(hrtc); |
bogdanm | 0:9b334a45a8ff | 451 | |
bogdanm | 0:9b334a45a8ff | 452 | hrtc->State = HAL_RTC_STATE_BUSY; |
bogdanm | 0:9b334a45a8ff | 453 | |
bogdanm | 0:9b334a45a8ff | 454 | /* Configure the tamper trigger */ |
bogdanm | 0:9b334a45a8ff | 455 | if(sTamper->Trigger != RTC_TAMPERTRIGGER_RISINGEDGE) |
bogdanm | 0:9b334a45a8ff | 456 | { |
bogdanm | 0:9b334a45a8ff | 457 | sTamper->Trigger = (uint32_t)(sTamper->Tamper << 1); |
bogdanm | 0:9b334a45a8ff | 458 | } |
bogdanm | 0:9b334a45a8ff | 459 | |
bogdanm | 0:9b334a45a8ff | 460 | if(sTamper->NoErase != RTC_TAMPER_ERASE_BACKUP_ENABLE) |
bogdanm | 0:9b334a45a8ff | 461 | { |
bogdanm | 0:9b334a45a8ff | 462 | sTamper->NoErase = 0; |
bogdanm | 0:9b334a45a8ff | 463 | if((sTamper->Tamper & RTC_TAMPER_1) != 0) |
bogdanm | 0:9b334a45a8ff | 464 | { |
bogdanm | 0:9b334a45a8ff | 465 | sTamper->NoErase |= RTC_TAMPCR_TAMP1NOERASE; |
bogdanm | 0:9b334a45a8ff | 466 | } |
bogdanm | 0:9b334a45a8ff | 467 | if((sTamper->Tamper & RTC_TAMPER_2) != 0) |
bogdanm | 0:9b334a45a8ff | 468 | { |
bogdanm | 0:9b334a45a8ff | 469 | sTamper->NoErase |= RTC_TAMPCR_TAMP2NOERASE; |
bogdanm | 0:9b334a45a8ff | 470 | } |
bogdanm | 0:9b334a45a8ff | 471 | #if defined (STM32L083xx) || defined (STM32L082xx) || defined (STM32L081xx) || \ |
bogdanm | 0:9b334a45a8ff | 472 | defined (STM32L073xx) || defined (STM32L072xx) || defined (STM32L071xx) |
bogdanm | 0:9b334a45a8ff | 473 | |
bogdanm | 0:9b334a45a8ff | 474 | if((sTamper->Tamper & RTC_TAMPER_3) != 0) |
bogdanm | 0:9b334a45a8ff | 475 | { |
bogdanm | 0:9b334a45a8ff | 476 | sTamper->NoErase |= RTC_TAMPCR_TAMP3NOERASE; |
bogdanm | 0:9b334a45a8ff | 477 | } |
bogdanm | 0:9b334a45a8ff | 478 | |
bogdanm | 0:9b334a45a8ff | 479 | #endif /* (STM32L083xx) || (STM32L082xx) || (STM32L081xx) || |
bogdanm | 0:9b334a45a8ff | 480 | * (STM32L073xx) || (STM32L072xx) || (STM32L071xx) |
bogdanm | 0:9b334a45a8ff | 481 | */ |
bogdanm | 0:9b334a45a8ff | 482 | } |
bogdanm | 0:9b334a45a8ff | 483 | |
bogdanm | 0:9b334a45a8ff | 484 | if(sTamper->MaskFlag != RTC_TAMPERMASK_FLAG_DISABLE) |
bogdanm | 0:9b334a45a8ff | 485 | { |
bogdanm | 0:9b334a45a8ff | 486 | sTamper->MaskFlag = 0; |
bogdanm | 0:9b334a45a8ff | 487 | if((sTamper->Tamper & RTC_TAMPER_1) != 0) |
bogdanm | 0:9b334a45a8ff | 488 | { |
bogdanm | 0:9b334a45a8ff | 489 | sTamper->MaskFlag |= RTC_TAMPCR_TAMP1MF; |
bogdanm | 0:9b334a45a8ff | 490 | } |
bogdanm | 0:9b334a45a8ff | 491 | if((sTamper->Tamper & RTC_TAMPER_2) != 0) |
bogdanm | 0:9b334a45a8ff | 492 | { |
bogdanm | 0:9b334a45a8ff | 493 | sTamper->MaskFlag |= RTC_TAMPCR_TAMP2MF; |
bogdanm | 0:9b334a45a8ff | 494 | } |
bogdanm | 0:9b334a45a8ff | 495 | #if defined (STM32L083xx) || defined (STM32L082xx) || defined (STM32L081xx) || \ |
bogdanm | 0:9b334a45a8ff | 496 | defined (STM32L073xx) || defined (STM32L072xx) || defined (STM32L071xx) |
bogdanm | 0:9b334a45a8ff | 497 | |
bogdanm | 0:9b334a45a8ff | 498 | if((sTamper->Tamper & RTC_TAMPER_3) != 0) |
bogdanm | 0:9b334a45a8ff | 499 | { |
bogdanm | 0:9b334a45a8ff | 500 | sTamper->MaskFlag |= RTC_TAMPCR_TAMP3MF; |
bogdanm | 0:9b334a45a8ff | 501 | } |
bogdanm | 0:9b334a45a8ff | 502 | #endif /* (STM32L083xx) || (STM32L082xx) || (STM32L081xx) || |
bogdanm | 0:9b334a45a8ff | 503 | * (STM32L073xx) || (STM32L072xx) || (STM32L071xx) |
bogdanm | 0:9b334a45a8ff | 504 | */ |
bogdanm | 0:9b334a45a8ff | 505 | } |
bogdanm | 0:9b334a45a8ff | 506 | |
bogdanm | 0:9b334a45a8ff | 507 | /* Configure the RTC_TAMPCR register */ |
bogdanm | 0:9b334a45a8ff | 508 | tmpreg = (uint32_t)((uint32_t)sTamper->Tamper | (uint32_t)sTamper->Trigger | (uint32_t)sTamper->NoErase |\ |
bogdanm | 0:9b334a45a8ff | 509 | (uint32_t)sTamper->MaskFlag | (uint32_t)sTamper->Filter | (uint32_t)sTamper->SamplingFrequency |\ |
bogdanm | 0:9b334a45a8ff | 510 | (uint32_t)sTamper->PrechargeDuration | (uint32_t)sTamper->TamperPullUp | (uint32_t)sTamper->TimeStampOnTamperDetection); |
bogdanm | 0:9b334a45a8ff | 511 | |
bogdanm | 0:9b334a45a8ff | 512 | |
bogdanm | 0:9b334a45a8ff | 513 | #if defined (STM32L063xx) || defined (STM32L062xx) || defined (STM32L061xx) || \ |
bogdanm | 0:9b334a45a8ff | 514 | defined (STM32L053xx) || defined (STM32L052xx) || defined (STM32L051xx) |
bogdanm | 0:9b334a45a8ff | 515 | |
bogdanm | 0:9b334a45a8ff | 516 | hrtc->Instance->TAMPCR &= ((uint32_t)~((uint32_t)sTamper->Tamper | (uint32_t)(sTamper->Tamper << 1) | RTC_TAMPCR_TAMPTS |\ |
bogdanm | 0:9b334a45a8ff | 517 | RTC_TAMPCR_TAMPFREQ | RTC_TAMPCR_TAMPFLT | RTC_TAMPCR_TAMPPRCH |\ |
bogdanm | 0:9b334a45a8ff | 518 | RTC_TAMPCR_TAMPPUDIS | RTC_TAMPCR_TAMPIE | RTC_TAMPCR_TAMP1IE |\ |
bogdanm | 0:9b334a45a8ff | 519 | RTC_TAMPCR_TAMP2IE | RTC_TAMPCR_TAMP1NOERASE | RTC_TAMPCR_TAMP2NOERASE|\ |
bogdanm | 0:9b334a45a8ff | 520 | RTC_TAMPCR_TAMP1MF | RTC_TAMPCR_TAMP2MF)); |
bogdanm | 0:9b334a45a8ff | 521 | |
bogdanm | 0:9b334a45a8ff | 522 | #endif /* (STM32L063xx) || (STM32L062xx) || (STM32L061xx) || |
bogdanm | 0:9b334a45a8ff | 523 | * (STM32L053xx) || (STM32L052xx) || (STM32L051xx) |
bogdanm | 0:9b334a45a8ff | 524 | */ |
bogdanm | 0:9b334a45a8ff | 525 | |
bogdanm | 0:9b334a45a8ff | 526 | #if defined (STM32L083xx) || defined (STM32L082xx) || defined (STM32L081xx) || \ |
bogdanm | 0:9b334a45a8ff | 527 | defined (STM32L073xx) || defined (STM32L072xx) || defined (STM32L071xx) |
bogdanm | 0:9b334a45a8ff | 528 | |
bogdanm | 0:9b334a45a8ff | 529 | hrtc->Instance->TAMPCR &= ((uint32_t)~((uint32_t)sTamper->Tamper | (uint32_t)(sTamper->Tamper << 1) | RTC_TAMPCR_TAMPTS |\ |
bogdanm | 0:9b334a45a8ff | 530 | RTC_TAMPCR_TAMPFREQ | RTC_TAMPCR_TAMPFLT | RTC_TAMPCR_TAMPPRCH |\ |
bogdanm | 0:9b334a45a8ff | 531 | RTC_TAMPCR_TAMPPUDIS | RTC_TAMPCR_TAMPIE | RTC_TAMPCR_TAMP1IE |\ |
bogdanm | 0:9b334a45a8ff | 532 | RTC_TAMPCR_TAMP2IE | RTC_TAMPCR_TAMP3IE | RTC_TAMPCR_TAMP1NOERASE |\ |
bogdanm | 0:9b334a45a8ff | 533 | RTC_TAMPCR_TAMP2NOERASE | RTC_TAMPCR_TAMP3NOERASE | RTC_TAMPCR_TAMP1MF |\ |
bogdanm | 0:9b334a45a8ff | 534 | RTC_TAMPCR_TAMP2MF | RTC_TAMPCR_TAMP3MF)); |
bogdanm | 0:9b334a45a8ff | 535 | |
bogdanm | 0:9b334a45a8ff | 536 | #endif /* (STM32L083xx) || (STM32L082xx) || (STM32L081xx) || |
bogdanm | 0:9b334a45a8ff | 537 | * (STM32L073xx) || (STM32L072xx) || (STM32L071xx) |
bogdanm | 0:9b334a45a8ff | 538 | */ |
bogdanm | 0:9b334a45a8ff | 539 | |
bogdanm | 0:9b334a45a8ff | 540 | hrtc->Instance->TAMPCR |= tmpreg; |
bogdanm | 0:9b334a45a8ff | 541 | |
bogdanm | 0:9b334a45a8ff | 542 | hrtc->State = HAL_RTC_STATE_READY; |
bogdanm | 0:9b334a45a8ff | 543 | |
bogdanm | 0:9b334a45a8ff | 544 | /* Process Unlocked */ |
bogdanm | 0:9b334a45a8ff | 545 | __HAL_UNLOCK(hrtc); |
bogdanm | 0:9b334a45a8ff | 546 | |
bogdanm | 0:9b334a45a8ff | 547 | return HAL_OK; |
bogdanm | 0:9b334a45a8ff | 548 | } |
bogdanm | 0:9b334a45a8ff | 549 | |
bogdanm | 0:9b334a45a8ff | 550 | /** |
bogdanm | 0:9b334a45a8ff | 551 | * @brief Sets Tamper with interrupt. |
bogdanm | 0:9b334a45a8ff | 552 | * @note By calling this API we force the tamper interrupt for all tampers. |
bogdanm | 0:9b334a45a8ff | 553 | * @param hrtc: RTC handle |
bogdanm | 0:9b334a45a8ff | 554 | * @param sTamper: Pointer to RTC Tamper. |
bogdanm | 0:9b334a45a8ff | 555 | * @retval HAL status |
bogdanm | 0:9b334a45a8ff | 556 | */ |
bogdanm | 0:9b334a45a8ff | 557 | HAL_StatusTypeDef HAL_RTCEx_SetTamper_IT(RTC_HandleTypeDef *hrtc, RTC_TamperTypeDef* sTamper) |
bogdanm | 0:9b334a45a8ff | 558 | { |
bogdanm | 0:9b334a45a8ff | 559 | uint32_t tmpreg = 0; |
bogdanm | 0:9b334a45a8ff | 560 | |
bogdanm | 0:9b334a45a8ff | 561 | /* Check the parameters */ |
bogdanm | 0:9b334a45a8ff | 562 | assert_param( IS_RTC_TAMPER(sTamper->Tamper)); |
bogdanm | 0:9b334a45a8ff | 563 | assert_param(IS_RTC_TAMPER_INTERRUPT(sTamper->Interrupt)); |
bogdanm | 0:9b334a45a8ff | 564 | assert_param( IS_RTC_TAMPER_TRIGGER(sTamper->Trigger)); |
bogdanm | 0:9b334a45a8ff | 565 | assert_param(IS_RTC_TAMPER_ERASE_MODE(sTamper->NoErase)); |
bogdanm | 0:9b334a45a8ff | 566 | assert_param(IS_RTC_TAMPER_MASKFLAG_STATE(sTamper->MaskFlag)); |
bogdanm | 0:9b334a45a8ff | 567 | assert_param(IS_RTC_TAMPER_FILTER(sTamper->Filter)); |
bogdanm | 0:9b334a45a8ff | 568 | assert_param(IS_RTC_TAMPER_SAMPLING_FREQ(sTamper->SamplingFrequency)); |
bogdanm | 0:9b334a45a8ff | 569 | assert_param(IS_RTC_TAMPER_PRECHARGE_DURATION(sTamper->PrechargeDuration)); |
bogdanm | 0:9b334a45a8ff | 570 | assert_param(IS_RTC_TAMPER_PULLUP_STATE(sTamper->TamperPullUp)); |
bogdanm | 0:9b334a45a8ff | 571 | assert_param(IS_RTC_TAMPER_TIMESTAMPONTAMPER_DETECTION(sTamper->TimeStampOnTamperDetection)); |
bogdanm | 0:9b334a45a8ff | 572 | |
bogdanm | 0:9b334a45a8ff | 573 | /* Process Locked */ |
bogdanm | 0:9b334a45a8ff | 574 | __HAL_LOCK(hrtc); |
bogdanm | 0:9b334a45a8ff | 575 | |
bogdanm | 0:9b334a45a8ff | 576 | hrtc->State = HAL_RTC_STATE_BUSY; |
bogdanm | 0:9b334a45a8ff | 577 | |
bogdanm | 0:9b334a45a8ff | 578 | /* Configure the tamper trigger */ |
bogdanm | 0:9b334a45a8ff | 579 | if(sTamper->Trigger != RTC_TAMPERTRIGGER_RISINGEDGE) |
bogdanm | 0:9b334a45a8ff | 580 | { |
bogdanm | 0:9b334a45a8ff | 581 | sTamper->Trigger = (uint32_t)(sTamper->Tamper << 1); |
bogdanm | 0:9b334a45a8ff | 582 | } |
bogdanm | 0:9b334a45a8ff | 583 | |
bogdanm | 0:9b334a45a8ff | 584 | if(sTamper->NoErase != RTC_TAMPER_ERASE_BACKUP_ENABLE) |
bogdanm | 0:9b334a45a8ff | 585 | { |
bogdanm | 0:9b334a45a8ff | 586 | sTamper->NoErase = 0; |
bogdanm | 0:9b334a45a8ff | 587 | if((sTamper->Tamper & RTC_TAMPER_1) != 0) |
bogdanm | 0:9b334a45a8ff | 588 | { |
bogdanm | 0:9b334a45a8ff | 589 | sTamper->NoErase |= RTC_TAMPCR_TAMP1NOERASE; |
bogdanm | 0:9b334a45a8ff | 590 | } |
bogdanm | 0:9b334a45a8ff | 591 | if((sTamper->Tamper & RTC_TAMPER_2) != 0) |
bogdanm | 0:9b334a45a8ff | 592 | { |
bogdanm | 0:9b334a45a8ff | 593 | sTamper->NoErase |= RTC_TAMPCR_TAMP2NOERASE; |
bogdanm | 0:9b334a45a8ff | 594 | } |
bogdanm | 0:9b334a45a8ff | 595 | #if defined (STM32L083xx) || defined (STM32L082xx) || defined (STM32L081xx) || \ |
bogdanm | 0:9b334a45a8ff | 596 | defined (STM32L073xx) || defined (STM32L072xx) || defined (STM32L071xx) |
bogdanm | 0:9b334a45a8ff | 597 | |
bogdanm | 0:9b334a45a8ff | 598 | if((sTamper->Tamper & RTC_TAMPER_3) != 0) |
bogdanm | 0:9b334a45a8ff | 599 | { |
bogdanm | 0:9b334a45a8ff | 600 | sTamper->NoErase |= RTC_TAMPCR_TAMP3NOERASE; |
bogdanm | 0:9b334a45a8ff | 601 | } |
bogdanm | 0:9b334a45a8ff | 602 | #endif /* (STM32L083xx) || (STM32L082xx) || (STM32L081xx) || |
bogdanm | 0:9b334a45a8ff | 603 | * (STM32L073xx) || (STM32L072xx) || (STM32L071xx) |
bogdanm | 0:9b334a45a8ff | 604 | */ |
bogdanm | 0:9b334a45a8ff | 605 | } |
bogdanm | 0:9b334a45a8ff | 606 | |
bogdanm | 0:9b334a45a8ff | 607 | if(sTamper->MaskFlag != RTC_TAMPERMASK_FLAG_DISABLE) |
bogdanm | 0:9b334a45a8ff | 608 | { |
bogdanm | 0:9b334a45a8ff | 609 | sTamper->MaskFlag = 0; |
bogdanm | 0:9b334a45a8ff | 610 | if((sTamper->Tamper & RTC_TAMPER_1) != 0) |
bogdanm | 0:9b334a45a8ff | 611 | { |
bogdanm | 0:9b334a45a8ff | 612 | sTamper->MaskFlag |= RTC_TAMPCR_TAMP1MF; |
bogdanm | 0:9b334a45a8ff | 613 | } |
bogdanm | 0:9b334a45a8ff | 614 | if((sTamper->Tamper & RTC_TAMPER_2) != 0) |
bogdanm | 0:9b334a45a8ff | 615 | { |
bogdanm | 0:9b334a45a8ff | 616 | sTamper->MaskFlag |= RTC_TAMPCR_TAMP2MF; |
bogdanm | 0:9b334a45a8ff | 617 | } |
bogdanm | 0:9b334a45a8ff | 618 | #if defined (STM32L083xx) || defined (STM32L082xx) || defined (STM32L081xx) || \ |
bogdanm | 0:9b334a45a8ff | 619 | defined (STM32L073xx) || defined (STM32L072xx) || defined (STM32L071xx) |
bogdanm | 0:9b334a45a8ff | 620 | |
bogdanm | 0:9b334a45a8ff | 621 | if((sTamper->Tamper & RTC_TAMPER_3) != 0) |
bogdanm | 0:9b334a45a8ff | 622 | { |
bogdanm | 0:9b334a45a8ff | 623 | sTamper->MaskFlag |= RTC_TAMPCR_TAMP3MF; |
bogdanm | 0:9b334a45a8ff | 624 | } |
bogdanm | 0:9b334a45a8ff | 625 | #endif /* (STM32L083xx) || (STM32L082xx) || (STM32L081xx) || |
bogdanm | 0:9b334a45a8ff | 626 | * (STM32L073xx) || (STM32L072xx) || (STM32L071xx) |
bogdanm | 0:9b334a45a8ff | 627 | */ |
bogdanm | 0:9b334a45a8ff | 628 | } |
bogdanm | 0:9b334a45a8ff | 629 | |
bogdanm | 0:9b334a45a8ff | 630 | /* Configure the RTC_TAMPCR register */ |
bogdanm | 0:9b334a45a8ff | 631 | tmpreg = (uint32_t)((uint32_t)sTamper->Tamper | (uint32_t)sTamper->Interrupt | (uint32_t)sTamper->Trigger | (uint32_t)sTamper->NoErase |\ |
bogdanm | 0:9b334a45a8ff | 632 | (uint32_t)sTamper->MaskFlag | (uint32_t)sTamper->Filter | (uint32_t)sTamper->SamplingFrequency |\ |
bogdanm | 0:9b334a45a8ff | 633 | (uint32_t)sTamper->PrechargeDuration | (uint32_t)sTamper->TamperPullUp | (uint32_t)sTamper->TimeStampOnTamperDetection); |
bogdanm | 0:9b334a45a8ff | 634 | |
bogdanm | 0:9b334a45a8ff | 635 | |
bogdanm | 0:9b334a45a8ff | 636 | #if defined (STM32L063xx) || defined (STM32L062xx) || defined (STM32L061xx) || \ |
bogdanm | 0:9b334a45a8ff | 637 | defined (STM32L053xx) || defined (STM32L052xx) || defined (STM32L051xx) |
bogdanm | 0:9b334a45a8ff | 638 | |
bogdanm | 0:9b334a45a8ff | 639 | hrtc->Instance->TAMPCR &= (uint32_t)~((uint32_t)sTamper->Tamper | (uint32_t)(sTamper->Tamper << 1) | RTC_TAMPCR_TAMPTS |\ |
bogdanm | 0:9b334a45a8ff | 640 | RTC_TAMPCR_TAMPFREQ | RTC_TAMPCR_TAMPFLT | RTC_TAMPCR_TAMPPRCH |\ |
bogdanm | 0:9b334a45a8ff | 641 | RTC_TAMPCR_TAMPPUDIS | RTC_TAMPCR_TAMPIE | RTC_TAMPCR_TAMP1IE |\ |
bogdanm | 0:9b334a45a8ff | 642 | RTC_TAMPCR_TAMP2IE | RTC_TAMPCR_TAMP1NOERASE | RTC_TAMPCR_TAMP2NOERASE |\ |
bogdanm | 0:9b334a45a8ff | 643 | RTC_TAMPCR_TAMP1MF | RTC_TAMPCR_TAMP2MF); |
bogdanm | 0:9b334a45a8ff | 644 | |
bogdanm | 0:9b334a45a8ff | 645 | #endif /* (STM32L063xx) || (STM32L062xx) || (STM32L061xx) || |
bogdanm | 0:9b334a45a8ff | 646 | * (STM32L053xx) || (STM32L052xx) || (STM32L051xx) |
bogdanm | 0:9b334a45a8ff | 647 | */ |
bogdanm | 0:9b334a45a8ff | 648 | #if defined (STM32L083xx) || defined (STM32L082xx) || defined (STM32L081xx) || \ |
bogdanm | 0:9b334a45a8ff | 649 | defined (STM32L073xx) || defined (STM32L072xx) || defined (STM32L071xx) |
bogdanm | 0:9b334a45a8ff | 650 | |
bogdanm | 0:9b334a45a8ff | 651 | hrtc->Instance->TAMPCR &= (uint32_t)~((uint32_t)sTamper->Tamper | (uint32_t)(sTamper->Tamper << 1) | RTC_TAMPCR_TAMPTS |\ |
bogdanm | 0:9b334a45a8ff | 652 | RTC_TAMPCR_TAMPFREQ | RTC_TAMPCR_TAMPFLT | RTC_TAMPCR_TAMPPRCH |\ |
bogdanm | 0:9b334a45a8ff | 653 | RTC_TAMPCR_TAMPPUDIS | RTC_TAMPCR_TAMPIE | RTC_TAMPCR_TAMP1IE |\ |
bogdanm | 0:9b334a45a8ff | 654 | RTC_TAMPCR_TAMP2IE | RTC_TAMPCR_TAMP3IE | RTC_TAMPCR_TAMP1NOERASE |\ |
bogdanm | 0:9b334a45a8ff | 655 | RTC_TAMPCR_TAMP2NOERASE | RTC_TAMPCR_TAMP3NOERASE | RTC_TAMPCR_TAMP1MF |\ |
bogdanm | 0:9b334a45a8ff | 656 | RTC_TAMPCR_TAMP2MF | RTC_TAMPCR_TAMP3MF); |
bogdanm | 0:9b334a45a8ff | 657 | |
bogdanm | 0:9b334a45a8ff | 658 | #endif /* (STM32L083xx) || (STM32L082xx) || (STM32L081xx) || |
bogdanm | 0:9b334a45a8ff | 659 | * (STM32L073xx) || (STM32L072xx) || (STM32L071xx) |
bogdanm | 0:9b334a45a8ff | 660 | */ |
bogdanm | 0:9b334a45a8ff | 661 | |
bogdanm | 0:9b334a45a8ff | 662 | hrtc->Instance->TAMPCR |= tmpreg; |
bogdanm | 0:9b334a45a8ff | 663 | |
bogdanm | 0:9b334a45a8ff | 664 | /* RTC Tamper Interrupt Configuration: EXTI configuration */ |
bogdanm | 0:9b334a45a8ff | 665 | __HAL_RTC_TAMPER_TIMESTAMP_EXTI_ENABLE_IT(); |
bogdanm | 0:9b334a45a8ff | 666 | |
bogdanm | 0:9b334a45a8ff | 667 | __HAL_RTC_TAMPER_TIMESTAMP_EXTI_ENABLE_RISING_EDGE(); |
bogdanm | 0:9b334a45a8ff | 668 | |
bogdanm | 0:9b334a45a8ff | 669 | hrtc->State = HAL_RTC_STATE_READY; |
bogdanm | 0:9b334a45a8ff | 670 | |
bogdanm | 0:9b334a45a8ff | 671 | /* Process Unlocked */ |
bogdanm | 0:9b334a45a8ff | 672 | __HAL_UNLOCK(hrtc); |
bogdanm | 0:9b334a45a8ff | 673 | |
bogdanm | 0:9b334a45a8ff | 674 | return HAL_OK; |
bogdanm | 0:9b334a45a8ff | 675 | } |
bogdanm | 0:9b334a45a8ff | 676 | |
bogdanm | 0:9b334a45a8ff | 677 | /** |
bogdanm | 0:9b334a45a8ff | 678 | * @brief Deactivates Tamper. |
bogdanm | 0:9b334a45a8ff | 679 | * @param hrtc: RTC handle |
bogdanm | 0:9b334a45a8ff | 680 | * @param Tamper: Selected tamper pin. |
bogdanm | 0:9b334a45a8ff | 681 | * This parameter can be RTC_Tamper_1 and/or RTC_TAMPER_2 for NEMO. |
bogdanm | 0:9b334a45a8ff | 682 | * This parameter can be any combination of RTC_TAMPER_1, RTC_TAMPER_2 and RTC_TAMPER_3 for BIG NEMO. |
bogdanm | 0:9b334a45a8ff | 683 | * @retval HAL status |
bogdanm | 0:9b334a45a8ff | 684 | */ |
bogdanm | 0:9b334a45a8ff | 685 | HAL_StatusTypeDef HAL_RTCEx_DeactivateTamper(RTC_HandleTypeDef *hrtc, uint32_t Tamper) |
bogdanm | 0:9b334a45a8ff | 686 | { |
bogdanm | 0:9b334a45a8ff | 687 | assert_param( IS_RTC_TAMPER(Tamper)); |
bogdanm | 0:9b334a45a8ff | 688 | |
bogdanm | 0:9b334a45a8ff | 689 | /* Process Locked */ |
bogdanm | 0:9b334a45a8ff | 690 | __HAL_LOCK(hrtc); |
bogdanm | 0:9b334a45a8ff | 691 | |
bogdanm | 0:9b334a45a8ff | 692 | hrtc->State = HAL_RTC_STATE_BUSY; |
bogdanm | 0:9b334a45a8ff | 693 | |
bogdanm | 0:9b334a45a8ff | 694 | /* Disable the selected Tamper pin */ |
bogdanm | 0:9b334a45a8ff | 695 | hrtc->Instance->TAMPCR &= ((uint32_t)~Tamper); |
bogdanm | 0:9b334a45a8ff | 696 | |
bogdanm | 0:9b334a45a8ff | 697 | if ((Tamper & RTC_TAMPER_1) != 0) |
bogdanm | 0:9b334a45a8ff | 698 | { |
bogdanm | 0:9b334a45a8ff | 699 | /* Disable the Tamper1 interrupt */ |
bogdanm | 0:9b334a45a8ff | 700 | hrtc->Instance->TAMPCR &= ((uint32_t)~(RTC_IT_TAMP | RTC_IT_TAMP1)); |
bogdanm | 0:9b334a45a8ff | 701 | } |
bogdanm | 0:9b334a45a8ff | 702 | if ((Tamper & RTC_TAMPER_2) != 0) |
bogdanm | 0:9b334a45a8ff | 703 | { |
bogdanm | 0:9b334a45a8ff | 704 | /* Disable the Tamper2 interrupt */ |
bogdanm | 0:9b334a45a8ff | 705 | hrtc->Instance->TAMPCR &= ((uint32_t)~(RTC_IT_TAMP | RTC_IT_TAMP2)); |
bogdanm | 0:9b334a45a8ff | 706 | } |
bogdanm | 0:9b334a45a8ff | 707 | |
bogdanm | 0:9b334a45a8ff | 708 | #if defined (STM32L083xx) || defined (STM32L082xx) || defined (STM32L081xx) || \ |
bogdanm | 0:9b334a45a8ff | 709 | defined (STM32L073xx) || defined (STM32L072xx) || defined (STM32L071xx) |
bogdanm | 0:9b334a45a8ff | 710 | |
bogdanm | 0:9b334a45a8ff | 711 | if ((Tamper & RTC_TAMPER_3) != 0) |
bogdanm | 0:9b334a45a8ff | 712 | { |
bogdanm | 0:9b334a45a8ff | 713 | /* Disable the Tamper2 interrupt */ |
bogdanm | 0:9b334a45a8ff | 714 | hrtc->Instance->TAMPCR &= ((uint32_t)~(RTC_IT_TAMP | RTC_IT_TAMP3)); |
bogdanm | 0:9b334a45a8ff | 715 | } |
bogdanm | 0:9b334a45a8ff | 716 | |
bogdanm | 0:9b334a45a8ff | 717 | #endif /* (STM32L083xx) || (STM32L082xx) || (STM32L081xx) || |
bogdanm | 0:9b334a45a8ff | 718 | * (STM32L073xx) || (STM32L072xx) || (STM32L071xx) |
bogdanm | 0:9b334a45a8ff | 719 | */ |
bogdanm | 0:9b334a45a8ff | 720 | |
bogdanm | 0:9b334a45a8ff | 721 | hrtc->State = HAL_RTC_STATE_READY; |
bogdanm | 0:9b334a45a8ff | 722 | |
bogdanm | 0:9b334a45a8ff | 723 | /* Process Unlocked */ |
bogdanm | 0:9b334a45a8ff | 724 | __HAL_UNLOCK(hrtc); |
bogdanm | 0:9b334a45a8ff | 725 | |
bogdanm | 0:9b334a45a8ff | 726 | return HAL_OK; |
bogdanm | 0:9b334a45a8ff | 727 | } |
bogdanm | 0:9b334a45a8ff | 728 | |
bogdanm | 0:9b334a45a8ff | 729 | /** |
bogdanm | 0:9b334a45a8ff | 730 | * @brief This function handles TimeStamp interrupt request. |
bogdanm | 0:9b334a45a8ff | 731 | * @param hrtc: RTC handle |
bogdanm | 0:9b334a45a8ff | 732 | * @retval None |
bogdanm | 0:9b334a45a8ff | 733 | */ |
bogdanm | 0:9b334a45a8ff | 734 | void HAL_RTCEx_TamperTimeStampIRQHandler(RTC_HandleTypeDef *hrtc) |
bogdanm | 0:9b334a45a8ff | 735 | { |
bogdanm | 0:9b334a45a8ff | 736 | if(__HAL_RTC_TIMESTAMP_GET_IT(hrtc, RTC_IT_TS)) |
bogdanm | 0:9b334a45a8ff | 737 | { |
bogdanm | 0:9b334a45a8ff | 738 | /* Get the status of the Interrupt */ |
bogdanm | 0:9b334a45a8ff | 739 | if((uint32_t)(hrtc->Instance->CR & RTC_IT_TS) != (uint32_t)RESET) |
bogdanm | 0:9b334a45a8ff | 740 | { |
bogdanm | 0:9b334a45a8ff | 741 | /* TIMESTAMP callback */ |
bogdanm | 0:9b334a45a8ff | 742 | HAL_RTCEx_TimeStampEventCallback(hrtc); |
bogdanm | 0:9b334a45a8ff | 743 | |
bogdanm | 0:9b334a45a8ff | 744 | /* Clear the TIMESTAMP interrupt pending bit */ |
bogdanm | 0:9b334a45a8ff | 745 | __HAL_RTC_TIMESTAMP_CLEAR_FLAG(hrtc,RTC_FLAG_TSF); |
bogdanm | 0:9b334a45a8ff | 746 | } |
bogdanm | 0:9b334a45a8ff | 747 | } |
bogdanm | 0:9b334a45a8ff | 748 | |
bogdanm | 0:9b334a45a8ff | 749 | /* Get the status of the Interrupt */ |
bogdanm | 0:9b334a45a8ff | 750 | if(__HAL_RTC_TAMPER_GET_FLAG(hrtc, RTC_FLAG_TAMP1F)== SET) |
bogdanm | 0:9b334a45a8ff | 751 | { |
bogdanm | 0:9b334a45a8ff | 752 | /* Get the TAMPER Interrupt enable bit and pending bit */ |
bogdanm | 0:9b334a45a8ff | 753 | if((((hrtc->Instance->TAMPCR & RTC_TAMPCR_TAMPIE)) != (uint32_t)RESET) || \ |
bogdanm | 0:9b334a45a8ff | 754 | (((hrtc->Instance->TAMPCR & RTC_TAMPCR_TAMP1IE)) != (uint32_t)RESET)) |
bogdanm | 0:9b334a45a8ff | 755 | { |
bogdanm | 0:9b334a45a8ff | 756 | /* Tamper callback */ |
bogdanm | 0:9b334a45a8ff | 757 | HAL_RTCEx_Tamper1EventCallback(hrtc); |
bogdanm | 0:9b334a45a8ff | 758 | |
bogdanm | 0:9b334a45a8ff | 759 | /* Clear the Tamper interrupt pending bit */ |
bogdanm | 0:9b334a45a8ff | 760 | __HAL_RTC_TAMPER_CLEAR_FLAG(hrtc,RTC_FLAG_TAMP1F); |
bogdanm | 0:9b334a45a8ff | 761 | } |
bogdanm | 0:9b334a45a8ff | 762 | } |
bogdanm | 0:9b334a45a8ff | 763 | |
bogdanm | 0:9b334a45a8ff | 764 | /* Get the status of the Interrupt */ |
bogdanm | 0:9b334a45a8ff | 765 | if(__HAL_RTC_TAMPER_GET_FLAG(hrtc, RTC_FLAG_TAMP2F)== SET) |
bogdanm | 0:9b334a45a8ff | 766 | { |
bogdanm | 0:9b334a45a8ff | 767 | /* Get the TAMPER Interrupt enable bit and pending bit */ |
bogdanm | 0:9b334a45a8ff | 768 | if((((hrtc->Instance->TAMPCR & RTC_TAMPCR_TAMPIE)) != (uint32_t)RESET) || \ |
bogdanm | 0:9b334a45a8ff | 769 | (((hrtc->Instance->TAMPCR & RTC_TAMPCR_TAMP2IE)) != (uint32_t)RESET)) |
bogdanm | 0:9b334a45a8ff | 770 | { |
bogdanm | 0:9b334a45a8ff | 771 | /* Tamper callback */ |
bogdanm | 0:9b334a45a8ff | 772 | HAL_RTCEx_Tamper2EventCallback(hrtc); |
bogdanm | 0:9b334a45a8ff | 773 | |
bogdanm | 0:9b334a45a8ff | 774 | /* Clear the Tamper interrupt pending bit */ |
bogdanm | 0:9b334a45a8ff | 775 | __HAL_RTC_TAMPER_CLEAR_FLAG(hrtc, RTC_FLAG_TAMP2F); |
bogdanm | 0:9b334a45a8ff | 776 | } |
bogdanm | 0:9b334a45a8ff | 777 | } |
bogdanm | 0:9b334a45a8ff | 778 | |
bogdanm | 0:9b334a45a8ff | 779 | #if defined (STM32L083xx) || defined (STM32L082xx) || defined (STM32L081xx) || \ |
bogdanm | 0:9b334a45a8ff | 780 | defined (STM32L073xx) || defined (STM32L072xx) || defined (STM32L071xx) |
bogdanm | 0:9b334a45a8ff | 781 | |
bogdanm | 0:9b334a45a8ff | 782 | /* Get the status of the Interrupt */ |
bogdanm | 0:9b334a45a8ff | 783 | if(__HAL_RTC_TAMPER_GET_FLAG(hrtc, RTC_FLAG_TAMP3F)== SET) |
bogdanm | 0:9b334a45a8ff | 784 | { |
bogdanm | 0:9b334a45a8ff | 785 | /* Get the TAMPER Interrupt enable bit and pending bit */ |
bogdanm | 0:9b334a45a8ff | 786 | if((((hrtc->Instance->TAMPCR & RTC_TAMPCR_TAMPIE)) != (uint32_t)RESET) || \ |
bogdanm | 0:9b334a45a8ff | 787 | (((hrtc->Instance->TAMPCR & RTC_TAMPCR_TAMP3IE)) != (uint32_t)RESET)) |
bogdanm | 0:9b334a45a8ff | 788 | { |
bogdanm | 0:9b334a45a8ff | 789 | /* Tamper callback */ |
bogdanm | 0:9b334a45a8ff | 790 | HAL_RTCEx_Tamper3EventCallback(hrtc); |
bogdanm | 0:9b334a45a8ff | 791 | |
bogdanm | 0:9b334a45a8ff | 792 | /* Clear the Tamper interrupt pending bit */ |
bogdanm | 0:9b334a45a8ff | 793 | __HAL_RTC_TAMPER_CLEAR_FLAG(hrtc, RTC_FLAG_TAMP3F); |
bogdanm | 0:9b334a45a8ff | 794 | } |
bogdanm | 0:9b334a45a8ff | 795 | } |
bogdanm | 0:9b334a45a8ff | 796 | |
bogdanm | 0:9b334a45a8ff | 797 | #endif /* (STM32L083xx) || (STM32L082xx) || (STM32L081xx) || |
bogdanm | 0:9b334a45a8ff | 798 | * (STM32L073xx) || (STM32L072xx) || (STM32L071xx) |
bogdanm | 0:9b334a45a8ff | 799 | */ |
bogdanm | 0:9b334a45a8ff | 800 | |
bogdanm | 0:9b334a45a8ff | 801 | /* Clear the EXTI's Flag for RTC TimeStamp and Tamper */ |
bogdanm | 0:9b334a45a8ff | 802 | __HAL_RTC_TAMPER_TIMESTAMP_EXTI_CLEAR_FLAG(); |
bogdanm | 0:9b334a45a8ff | 803 | |
bogdanm | 0:9b334a45a8ff | 804 | /* Change RTC state */ |
bogdanm | 0:9b334a45a8ff | 805 | hrtc->State = HAL_RTC_STATE_READY; |
bogdanm | 0:9b334a45a8ff | 806 | } |
bogdanm | 0:9b334a45a8ff | 807 | |
bogdanm | 0:9b334a45a8ff | 808 | /** |
bogdanm | 0:9b334a45a8ff | 809 | * @brief TimeStamp callback. |
bogdanm | 0:9b334a45a8ff | 810 | * @param hrtc: RTC handle |
bogdanm | 0:9b334a45a8ff | 811 | * @retval None |
bogdanm | 0:9b334a45a8ff | 812 | */ |
bogdanm | 0:9b334a45a8ff | 813 | __weak void HAL_RTCEx_TimeStampEventCallback(RTC_HandleTypeDef *hrtc) |
bogdanm | 0:9b334a45a8ff | 814 | { |
bogdanm | 0:9b334a45a8ff | 815 | /* NOTE : This function Should not be modified, when the callback is needed, |
bogdanm | 0:9b334a45a8ff | 816 | the HAL_RTCEx_TimeStampEventCallback could be implemented in the user file |
bogdanm | 0:9b334a45a8ff | 817 | */ |
bogdanm | 0:9b334a45a8ff | 818 | } |
bogdanm | 0:9b334a45a8ff | 819 | |
bogdanm | 0:9b334a45a8ff | 820 | /** |
bogdanm | 0:9b334a45a8ff | 821 | * @brief Tamper 1 callback. |
bogdanm | 0:9b334a45a8ff | 822 | * @param hrtc: RTC handle |
bogdanm | 0:9b334a45a8ff | 823 | * @retval None |
bogdanm | 0:9b334a45a8ff | 824 | */ |
bogdanm | 0:9b334a45a8ff | 825 | __weak void HAL_RTCEx_Tamper1EventCallback(RTC_HandleTypeDef *hrtc) |
bogdanm | 0:9b334a45a8ff | 826 | { |
bogdanm | 0:9b334a45a8ff | 827 | /* NOTE : This function Should not be modified, when the callback is needed, |
bogdanm | 0:9b334a45a8ff | 828 | the HAL_RTCEx_Tamper1EventCallback could be implemented in the user file |
bogdanm | 0:9b334a45a8ff | 829 | */ |
bogdanm | 0:9b334a45a8ff | 830 | } |
bogdanm | 0:9b334a45a8ff | 831 | |
bogdanm | 0:9b334a45a8ff | 832 | /** |
bogdanm | 0:9b334a45a8ff | 833 | * @brief Tamper 2 callback. |
bogdanm | 0:9b334a45a8ff | 834 | * @param hrtc: RTC handle |
bogdanm | 0:9b334a45a8ff | 835 | * @retval None |
bogdanm | 0:9b334a45a8ff | 836 | */ |
bogdanm | 0:9b334a45a8ff | 837 | __weak void HAL_RTCEx_Tamper2EventCallback(RTC_HandleTypeDef *hrtc) |
bogdanm | 0:9b334a45a8ff | 838 | { |
bogdanm | 0:9b334a45a8ff | 839 | /* NOTE : This function Should not be modified, when the callback is needed, |
bogdanm | 0:9b334a45a8ff | 840 | the HAL_RTCEx_Tamper2EventCallback could be implemented in the user file |
bogdanm | 0:9b334a45a8ff | 841 | */ |
bogdanm | 0:9b334a45a8ff | 842 | } |
bogdanm | 0:9b334a45a8ff | 843 | |
bogdanm | 0:9b334a45a8ff | 844 | |
bogdanm | 0:9b334a45a8ff | 845 | #if defined (STM32L083xx) || defined (STM32L082xx) || defined (STM32L081xx) || \ |
bogdanm | 0:9b334a45a8ff | 846 | defined (STM32L073xx) || defined (STM32L072xx) || defined (STM32L071xx) |
bogdanm | 0:9b334a45a8ff | 847 | |
bogdanm | 0:9b334a45a8ff | 848 | /** |
bogdanm | 0:9b334a45a8ff | 849 | * @brief Tamper 3 callback. |
bogdanm | 0:9b334a45a8ff | 850 | * @param hrtc: RTC handle |
bogdanm | 0:9b334a45a8ff | 851 | * @retval None |
bogdanm | 0:9b334a45a8ff | 852 | */ |
bogdanm | 0:9b334a45a8ff | 853 | __weak void HAL_RTCEx_Tamper3EventCallback(RTC_HandleTypeDef *hrtc) |
bogdanm | 0:9b334a45a8ff | 854 | { |
bogdanm | 0:9b334a45a8ff | 855 | /* NOTE : This function Should not be modified, when the callback is needed, |
bogdanm | 0:9b334a45a8ff | 856 | the HAL_RTCEx_Tamper3EventCallback could be implemented in the user file |
bogdanm | 0:9b334a45a8ff | 857 | */ |
bogdanm | 0:9b334a45a8ff | 858 | } |
bogdanm | 0:9b334a45a8ff | 859 | |
bogdanm | 0:9b334a45a8ff | 860 | #endif /* (STM32L083xx) || (STM32L082xx) || (STM32L081xx) || |
bogdanm | 0:9b334a45a8ff | 861 | * (STM32L073xx) || (STM32L072xx) || (STM32L071xx) |
bogdanm | 0:9b334a45a8ff | 862 | */ |
bogdanm | 0:9b334a45a8ff | 863 | |
bogdanm | 0:9b334a45a8ff | 864 | |
bogdanm | 0:9b334a45a8ff | 865 | /** |
bogdanm | 0:9b334a45a8ff | 866 | * @brief This function handles TimeStamp polling request. |
bogdanm | 0:9b334a45a8ff | 867 | * @param hrtc: RTC handle |
bogdanm | 0:9b334a45a8ff | 868 | * @param Timeout: Timeout duration |
bogdanm | 0:9b334a45a8ff | 869 | * @retval HAL status |
bogdanm | 0:9b334a45a8ff | 870 | */ |
bogdanm | 0:9b334a45a8ff | 871 | HAL_StatusTypeDef HAL_RTCEx_PollForTimeStampEvent(RTC_HandleTypeDef *hrtc, uint32_t Timeout) |
bogdanm | 0:9b334a45a8ff | 872 | { |
bogdanm | 0:9b334a45a8ff | 873 | uint32_t tickstart = HAL_GetTick(); |
bogdanm | 0:9b334a45a8ff | 874 | |
bogdanm | 0:9b334a45a8ff | 875 | while(__HAL_RTC_TIMESTAMP_GET_FLAG(hrtc, RTC_FLAG_TSF) == RESET) |
bogdanm | 0:9b334a45a8ff | 876 | { |
bogdanm | 0:9b334a45a8ff | 877 | if(__HAL_RTC_TIMESTAMP_GET_FLAG(hrtc, RTC_FLAG_TSOVF) != RESET) |
bogdanm | 0:9b334a45a8ff | 878 | { |
bogdanm | 0:9b334a45a8ff | 879 | /* Clear the TIMESTAMP OverRun Flag */ |
bogdanm | 0:9b334a45a8ff | 880 | __HAL_RTC_TIMESTAMP_CLEAR_FLAG(hrtc, RTC_FLAG_TSOVF); |
bogdanm | 0:9b334a45a8ff | 881 | |
bogdanm | 0:9b334a45a8ff | 882 | /* Change TIMESTAMP state */ |
bogdanm | 0:9b334a45a8ff | 883 | hrtc->State = HAL_RTC_STATE_ERROR; |
bogdanm | 0:9b334a45a8ff | 884 | |
bogdanm | 0:9b334a45a8ff | 885 | return HAL_ERROR; |
bogdanm | 0:9b334a45a8ff | 886 | } |
bogdanm | 0:9b334a45a8ff | 887 | |
bogdanm | 0:9b334a45a8ff | 888 | if(Timeout != HAL_MAX_DELAY) |
bogdanm | 0:9b334a45a8ff | 889 | { |
bogdanm | 0:9b334a45a8ff | 890 | if((Timeout == 0)||((HAL_GetTick() - tickstart ) > Timeout)) |
bogdanm | 0:9b334a45a8ff | 891 | { |
bogdanm | 0:9b334a45a8ff | 892 | hrtc->State = HAL_RTC_STATE_TIMEOUT; |
bogdanm | 0:9b334a45a8ff | 893 | return HAL_TIMEOUT; |
bogdanm | 0:9b334a45a8ff | 894 | } |
bogdanm | 0:9b334a45a8ff | 895 | } |
bogdanm | 0:9b334a45a8ff | 896 | } |
bogdanm | 0:9b334a45a8ff | 897 | |
bogdanm | 0:9b334a45a8ff | 898 | /* Change RTC state */ |
bogdanm | 0:9b334a45a8ff | 899 | hrtc->State = HAL_RTC_STATE_READY; |
bogdanm | 0:9b334a45a8ff | 900 | |
bogdanm | 0:9b334a45a8ff | 901 | return HAL_OK; |
bogdanm | 0:9b334a45a8ff | 902 | } |
bogdanm | 0:9b334a45a8ff | 903 | |
bogdanm | 0:9b334a45a8ff | 904 | /** |
bogdanm | 0:9b334a45a8ff | 905 | * @brief This function handles Tamper1 Polling. |
bogdanm | 0:9b334a45a8ff | 906 | * @param hrtc: RTC handle |
bogdanm | 0:9b334a45a8ff | 907 | * @param Timeout: Timeout duration |
bogdanm | 0:9b334a45a8ff | 908 | * @retval HAL status |
bogdanm | 0:9b334a45a8ff | 909 | */ |
bogdanm | 0:9b334a45a8ff | 910 | HAL_StatusTypeDef HAL_RTCEx_PollForTamper1Event(RTC_HandleTypeDef *hrtc, uint32_t Timeout) |
bogdanm | 0:9b334a45a8ff | 911 | { |
bogdanm | 0:9b334a45a8ff | 912 | uint32_t tickstart = HAL_GetTick(); |
bogdanm | 0:9b334a45a8ff | 913 | |
bogdanm | 0:9b334a45a8ff | 914 | /* Get the status of the Interrupt */ |
bogdanm | 0:9b334a45a8ff | 915 | while(__HAL_RTC_TAMPER_GET_FLAG(hrtc, RTC_FLAG_TAMP1F)== RESET) |
bogdanm | 0:9b334a45a8ff | 916 | { |
bogdanm | 0:9b334a45a8ff | 917 | if(Timeout != HAL_MAX_DELAY) |
bogdanm | 0:9b334a45a8ff | 918 | { |
bogdanm | 0:9b334a45a8ff | 919 | if((Timeout == 0)||((HAL_GetTick() - tickstart ) > Timeout)) |
bogdanm | 0:9b334a45a8ff | 920 | { |
bogdanm | 0:9b334a45a8ff | 921 | hrtc->State = HAL_RTC_STATE_TIMEOUT; |
bogdanm | 0:9b334a45a8ff | 922 | return HAL_TIMEOUT; |
bogdanm | 0:9b334a45a8ff | 923 | } |
bogdanm | 0:9b334a45a8ff | 924 | } |
bogdanm | 0:9b334a45a8ff | 925 | } |
bogdanm | 0:9b334a45a8ff | 926 | |
bogdanm | 0:9b334a45a8ff | 927 | /* Clear the Tamper Flag */ |
bogdanm | 0:9b334a45a8ff | 928 | __HAL_RTC_TAMPER_CLEAR_FLAG(hrtc,RTC_FLAG_TAMP1F); |
bogdanm | 0:9b334a45a8ff | 929 | |
bogdanm | 0:9b334a45a8ff | 930 | /* Change RTC state */ |
bogdanm | 0:9b334a45a8ff | 931 | hrtc->State = HAL_RTC_STATE_READY; |
bogdanm | 0:9b334a45a8ff | 932 | |
bogdanm | 0:9b334a45a8ff | 933 | return HAL_OK; |
bogdanm | 0:9b334a45a8ff | 934 | } |
bogdanm | 0:9b334a45a8ff | 935 | |
bogdanm | 0:9b334a45a8ff | 936 | /** |
bogdanm | 0:9b334a45a8ff | 937 | * @brief This function handles Tamper2 Polling. |
bogdanm | 0:9b334a45a8ff | 938 | * @param hrtc: RTC handle |
bogdanm | 0:9b334a45a8ff | 939 | * @param Timeout: Timeout duration |
bogdanm | 0:9b334a45a8ff | 940 | * @retval HAL status |
bogdanm | 0:9b334a45a8ff | 941 | */ |
bogdanm | 0:9b334a45a8ff | 942 | HAL_StatusTypeDef HAL_RTCEx_PollForTamper2Event(RTC_HandleTypeDef *hrtc, uint32_t Timeout) |
bogdanm | 0:9b334a45a8ff | 943 | { |
bogdanm | 0:9b334a45a8ff | 944 | uint32_t tickstart = HAL_GetTick(); |
bogdanm | 0:9b334a45a8ff | 945 | |
bogdanm | 0:9b334a45a8ff | 946 | /* Get the status of the Interrupt */ |
bogdanm | 0:9b334a45a8ff | 947 | while(__HAL_RTC_TAMPER_GET_FLAG(hrtc, RTC_FLAG_TAMP2F) == RESET) |
bogdanm | 0:9b334a45a8ff | 948 | { |
bogdanm | 0:9b334a45a8ff | 949 | if(Timeout != HAL_MAX_DELAY) |
bogdanm | 0:9b334a45a8ff | 950 | { |
bogdanm | 0:9b334a45a8ff | 951 | if((Timeout == 0)||((HAL_GetTick() - tickstart ) > Timeout)) |
bogdanm | 0:9b334a45a8ff | 952 | { |
bogdanm | 0:9b334a45a8ff | 953 | hrtc->State = HAL_RTC_STATE_TIMEOUT; |
bogdanm | 0:9b334a45a8ff | 954 | return HAL_TIMEOUT; |
bogdanm | 0:9b334a45a8ff | 955 | } |
bogdanm | 0:9b334a45a8ff | 956 | } |
bogdanm | 0:9b334a45a8ff | 957 | } |
bogdanm | 0:9b334a45a8ff | 958 | |
bogdanm | 0:9b334a45a8ff | 959 | /* Clear the Tamper Flag */ |
bogdanm | 0:9b334a45a8ff | 960 | __HAL_RTC_TAMPER_CLEAR_FLAG(hrtc,RTC_FLAG_TAMP2F); |
bogdanm | 0:9b334a45a8ff | 961 | |
bogdanm | 0:9b334a45a8ff | 962 | /* Change RTC state */ |
bogdanm | 0:9b334a45a8ff | 963 | hrtc->State = HAL_RTC_STATE_READY; |
bogdanm | 0:9b334a45a8ff | 964 | |
bogdanm | 0:9b334a45a8ff | 965 | return HAL_OK; |
bogdanm | 0:9b334a45a8ff | 966 | } |
bogdanm | 0:9b334a45a8ff | 967 | |
bogdanm | 0:9b334a45a8ff | 968 | |
bogdanm | 0:9b334a45a8ff | 969 | #if defined (STM32L083xx) || defined (STM32L082xx) || defined (STM32L081xx) || \ |
bogdanm | 0:9b334a45a8ff | 970 | defined (STM32L073xx) || defined (STM32L072xx) || defined (STM32L071xx) |
bogdanm | 0:9b334a45a8ff | 971 | |
bogdanm | 0:9b334a45a8ff | 972 | /** |
bogdanm | 0:9b334a45a8ff | 973 | * @brief This function handles Tamper3 Polling. |
bogdanm | 0:9b334a45a8ff | 974 | * @param hrtc: RTC handle |
bogdanm | 0:9b334a45a8ff | 975 | * @param Timeout: Timeout duration |
bogdanm | 0:9b334a45a8ff | 976 | * @retval HAL status |
bogdanm | 0:9b334a45a8ff | 977 | */ |
bogdanm | 0:9b334a45a8ff | 978 | HAL_StatusTypeDef HAL_RTCEx_PollForTamper3Event(RTC_HandleTypeDef *hrtc, uint32_t Timeout) |
bogdanm | 0:9b334a45a8ff | 979 | { |
bogdanm | 0:9b334a45a8ff | 980 | uint32_t tickstart = HAL_GetTick(); |
bogdanm | 0:9b334a45a8ff | 981 | |
bogdanm | 0:9b334a45a8ff | 982 | /* Get the status of the Interrupt */ |
bogdanm | 0:9b334a45a8ff | 983 | while(__HAL_RTC_TAMPER_GET_FLAG(hrtc,RTC_FLAG_TAMP3F) == RESET) |
bogdanm | 0:9b334a45a8ff | 984 | { |
bogdanm | 0:9b334a45a8ff | 985 | if(Timeout != HAL_MAX_DELAY) |
bogdanm | 0:9b334a45a8ff | 986 | { |
bogdanm | 0:9b334a45a8ff | 987 | if((Timeout == 0) || ((HAL_GetTick()-tickstart) > Timeout)) |
bogdanm | 0:9b334a45a8ff | 988 | { |
bogdanm | 0:9b334a45a8ff | 989 | hrtc->State = HAL_RTC_STATE_TIMEOUT; |
bogdanm | 0:9b334a45a8ff | 990 | return HAL_TIMEOUT; |
bogdanm | 0:9b334a45a8ff | 991 | } |
bogdanm | 0:9b334a45a8ff | 992 | } |
bogdanm | 0:9b334a45a8ff | 993 | } |
bogdanm | 0:9b334a45a8ff | 994 | |
bogdanm | 0:9b334a45a8ff | 995 | /* Clear the Tamper Flag */ |
bogdanm | 0:9b334a45a8ff | 996 | __HAL_RTC_TAMPER_CLEAR_FLAG(hrtc,RTC_FLAG_TAMP3F); |
bogdanm | 0:9b334a45a8ff | 997 | |
bogdanm | 0:9b334a45a8ff | 998 | /* Change RTC state */ |
bogdanm | 0:9b334a45a8ff | 999 | hrtc->State = HAL_RTC_STATE_READY; |
bogdanm | 0:9b334a45a8ff | 1000 | |
bogdanm | 0:9b334a45a8ff | 1001 | return HAL_OK; |
bogdanm | 0:9b334a45a8ff | 1002 | } |
bogdanm | 0:9b334a45a8ff | 1003 | #endif /* (STM32L083xx) || (STM32L082xx) || (STM32L081xx) || |
bogdanm | 0:9b334a45a8ff | 1004 | * (STM32L073xx) || (STM32L072xx) || (STM32L071xx) |
bogdanm | 0:9b334a45a8ff | 1005 | */ |
bogdanm | 0:9b334a45a8ff | 1006 | |
bogdanm | 0:9b334a45a8ff | 1007 | /** |
bogdanm | 0:9b334a45a8ff | 1008 | * @} |
bogdanm | 0:9b334a45a8ff | 1009 | */ |
bogdanm | 0:9b334a45a8ff | 1010 | |
bogdanm | 0:9b334a45a8ff | 1011 | /** @addtogroup RTCEx_Exported_Functions_Group2 |
bogdanm | 0:9b334a45a8ff | 1012 | * @brief RTC Wake-up functions |
bogdanm | 0:9b334a45a8ff | 1013 | * |
bogdanm | 0:9b334a45a8ff | 1014 | @verbatim |
bogdanm | 0:9b334a45a8ff | 1015 | =============================================================================== |
bogdanm | 0:9b334a45a8ff | 1016 | ##### RTC Wake-up functions ##### |
bogdanm | 0:9b334a45a8ff | 1017 | =============================================================================== |
bogdanm | 0:9b334a45a8ff | 1018 | |
bogdanm | 0:9b334a45a8ff | 1019 | [..] This section provide functions allowing to configure Wake-up feature |
bogdanm | 0:9b334a45a8ff | 1020 | |
bogdanm | 0:9b334a45a8ff | 1021 | @endverbatim |
bogdanm | 0:9b334a45a8ff | 1022 | * @{ |
bogdanm | 0:9b334a45a8ff | 1023 | */ |
bogdanm | 0:9b334a45a8ff | 1024 | |
bogdanm | 0:9b334a45a8ff | 1025 | /** |
bogdanm | 0:9b334a45a8ff | 1026 | * @brief Sets wake up timer. |
bogdanm | 0:9b334a45a8ff | 1027 | * @param hrtc: RTC handle |
bogdanm | 0:9b334a45a8ff | 1028 | * @param WakeUpCounter: Wake up counter |
bogdanm | 0:9b334a45a8ff | 1029 | * @param WakeUpClock: Wake up clock |
bogdanm | 0:9b334a45a8ff | 1030 | * @retval HAL status |
bogdanm | 0:9b334a45a8ff | 1031 | */ |
bogdanm | 0:9b334a45a8ff | 1032 | HAL_StatusTypeDef HAL_RTCEx_SetWakeUpTimer(RTC_HandleTypeDef *hrtc, uint32_t WakeUpCounter, uint32_t WakeUpClock) |
bogdanm | 0:9b334a45a8ff | 1033 | { |
bogdanm | 0:9b334a45a8ff | 1034 | uint32_t tickstart = 0; |
bogdanm | 0:9b334a45a8ff | 1035 | |
bogdanm | 0:9b334a45a8ff | 1036 | /* Check the parameters */ |
bogdanm | 0:9b334a45a8ff | 1037 | assert_param(IS_RTC_WAKEUP_CLOCK(WakeUpClock)); |
bogdanm | 0:9b334a45a8ff | 1038 | assert_param(IS_RTC_WAKEUP_COUNTER(WakeUpCounter)); |
bogdanm | 0:9b334a45a8ff | 1039 | |
bogdanm | 0:9b334a45a8ff | 1040 | /* Process Locked */ |
bogdanm | 0:9b334a45a8ff | 1041 | __HAL_LOCK(hrtc); |
bogdanm | 0:9b334a45a8ff | 1042 | |
bogdanm | 0:9b334a45a8ff | 1043 | hrtc->State = HAL_RTC_STATE_BUSY; |
bogdanm | 0:9b334a45a8ff | 1044 | |
bogdanm | 0:9b334a45a8ff | 1045 | /* Disable the write protection for RTC registers */ |
bogdanm | 0:9b334a45a8ff | 1046 | __HAL_RTC_WRITEPROTECTION_DISABLE(hrtc); |
bogdanm | 0:9b334a45a8ff | 1047 | |
bogdanm | 0:9b334a45a8ff | 1048 | __HAL_RTC_WAKEUPTIMER_DISABLE(hrtc); |
bogdanm | 0:9b334a45a8ff | 1049 | |
bogdanm | 0:9b334a45a8ff | 1050 | tickstart = HAL_GetTick(); |
bogdanm | 0:9b334a45a8ff | 1051 | |
bogdanm | 0:9b334a45a8ff | 1052 | /* Wait till RTC WUTWF flag is set and if Time out is reached exit */ |
bogdanm | 0:9b334a45a8ff | 1053 | while(__HAL_RTC_WAKEUPTIMER_GET_FLAG(hrtc, RTC_FLAG_WUTWF) == RESET) |
bogdanm | 0:9b334a45a8ff | 1054 | { |
bogdanm | 0:9b334a45a8ff | 1055 | if((HAL_GetTick() - tickstart ) > RTC_TIMEOUT_VALUE) |
bogdanm | 0:9b334a45a8ff | 1056 | { |
bogdanm | 0:9b334a45a8ff | 1057 | /* Enable the write protection for RTC registers */ |
bogdanm | 0:9b334a45a8ff | 1058 | __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc); |
bogdanm | 0:9b334a45a8ff | 1059 | |
bogdanm | 0:9b334a45a8ff | 1060 | hrtc->State = HAL_RTC_STATE_TIMEOUT; |
bogdanm | 0:9b334a45a8ff | 1061 | |
bogdanm | 0:9b334a45a8ff | 1062 | /* Process Unlocked */ |
bogdanm | 0:9b334a45a8ff | 1063 | __HAL_UNLOCK(hrtc); |
bogdanm | 0:9b334a45a8ff | 1064 | |
bogdanm | 0:9b334a45a8ff | 1065 | return HAL_TIMEOUT; |
bogdanm | 0:9b334a45a8ff | 1066 | } |
bogdanm | 0:9b334a45a8ff | 1067 | } |
bogdanm | 0:9b334a45a8ff | 1068 | |
bogdanm | 0:9b334a45a8ff | 1069 | /* Clear the Wakeup Timer clock source bits in CR register */ |
bogdanm | 0:9b334a45a8ff | 1070 | hrtc->Instance->CR &= (uint32_t)~RTC_CR_WUCKSEL; |
bogdanm | 0:9b334a45a8ff | 1071 | |
bogdanm | 0:9b334a45a8ff | 1072 | /* Configure the clock source */ |
bogdanm | 0:9b334a45a8ff | 1073 | hrtc->Instance->CR |= (uint32_t)WakeUpClock; |
bogdanm | 0:9b334a45a8ff | 1074 | |
bogdanm | 0:9b334a45a8ff | 1075 | /* Configure the Wakeup Timer counter */ |
bogdanm | 0:9b334a45a8ff | 1076 | hrtc->Instance->WUTR = (uint32_t)WakeUpCounter; |
bogdanm | 0:9b334a45a8ff | 1077 | |
bogdanm | 0:9b334a45a8ff | 1078 | /* Enable the Wakeup Timer */ |
bogdanm | 0:9b334a45a8ff | 1079 | __HAL_RTC_WAKEUPTIMER_ENABLE(hrtc); |
bogdanm | 0:9b334a45a8ff | 1080 | |
bogdanm | 0:9b334a45a8ff | 1081 | /* Enable the write protection for RTC registers */ |
bogdanm | 0:9b334a45a8ff | 1082 | __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc); |
bogdanm | 0:9b334a45a8ff | 1083 | |
bogdanm | 0:9b334a45a8ff | 1084 | hrtc->State = HAL_RTC_STATE_READY; |
bogdanm | 0:9b334a45a8ff | 1085 | |
bogdanm | 0:9b334a45a8ff | 1086 | /* Process Unlocked */ |
bogdanm | 0:9b334a45a8ff | 1087 | __HAL_UNLOCK(hrtc); |
bogdanm | 0:9b334a45a8ff | 1088 | |
bogdanm | 0:9b334a45a8ff | 1089 | return HAL_OK; |
bogdanm | 0:9b334a45a8ff | 1090 | } |
bogdanm | 0:9b334a45a8ff | 1091 | |
bogdanm | 0:9b334a45a8ff | 1092 | /** |
bogdanm | 0:9b334a45a8ff | 1093 | * @brief Sets wake up timer with interrupt |
bogdanm | 0:9b334a45a8ff | 1094 | * @param hrtc: RTC handle |
bogdanm | 0:9b334a45a8ff | 1095 | * @param WakeUpCounter: Wake up counter |
bogdanm | 0:9b334a45a8ff | 1096 | * @param WakeUpClock: Wake up clock |
bogdanm | 0:9b334a45a8ff | 1097 | * @retval HAL status |
bogdanm | 0:9b334a45a8ff | 1098 | */ |
bogdanm | 0:9b334a45a8ff | 1099 | HAL_StatusTypeDef HAL_RTCEx_SetWakeUpTimer_IT(RTC_HandleTypeDef *hrtc, uint32_t WakeUpCounter, uint32_t WakeUpClock) |
bogdanm | 0:9b334a45a8ff | 1100 | { |
bogdanm | 0:9b334a45a8ff | 1101 | uint32_t tickstart = 0; |
bogdanm | 0:9b334a45a8ff | 1102 | |
bogdanm | 0:9b334a45a8ff | 1103 | /* Check the parameters */ |
bogdanm | 0:9b334a45a8ff | 1104 | assert_param(IS_RTC_WAKEUP_CLOCK(WakeUpClock)); |
bogdanm | 0:9b334a45a8ff | 1105 | assert_param(IS_RTC_WAKEUP_COUNTER(WakeUpCounter)); |
bogdanm | 0:9b334a45a8ff | 1106 | |
bogdanm | 0:9b334a45a8ff | 1107 | /* Process Locked */ |
bogdanm | 0:9b334a45a8ff | 1108 | __HAL_LOCK(hrtc); |
bogdanm | 0:9b334a45a8ff | 1109 | |
bogdanm | 0:9b334a45a8ff | 1110 | hrtc->State = HAL_RTC_STATE_BUSY; |
bogdanm | 0:9b334a45a8ff | 1111 | |
bogdanm | 0:9b334a45a8ff | 1112 | /* Disable the write protection for RTC registers */ |
bogdanm | 0:9b334a45a8ff | 1113 | __HAL_RTC_WRITEPROTECTION_DISABLE(hrtc); |
bogdanm | 0:9b334a45a8ff | 1114 | |
bogdanm | 0:9b334a45a8ff | 1115 | __HAL_RTC_WAKEUPTIMER_DISABLE(hrtc); |
bogdanm | 0:9b334a45a8ff | 1116 | |
bogdanm | 0:9b334a45a8ff | 1117 | tickstart = HAL_GetTick(); |
bogdanm | 0:9b334a45a8ff | 1118 | |
bogdanm | 0:9b334a45a8ff | 1119 | /* Wait till RTC WUTWF flag is set and if Time out is reached exit */ |
bogdanm | 0:9b334a45a8ff | 1120 | while(__HAL_RTC_WAKEUPTIMER_GET_FLAG(hrtc, RTC_FLAG_WUTWF) == RESET) |
bogdanm | 0:9b334a45a8ff | 1121 | { |
bogdanm | 0:9b334a45a8ff | 1122 | if((HAL_GetTick() - tickstart ) > RTC_TIMEOUT_VALUE) |
bogdanm | 0:9b334a45a8ff | 1123 | { |
bogdanm | 0:9b334a45a8ff | 1124 | /* Enable the write protection for RTC registers */ |
bogdanm | 0:9b334a45a8ff | 1125 | __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc); |
bogdanm | 0:9b334a45a8ff | 1126 | |
bogdanm | 0:9b334a45a8ff | 1127 | hrtc->State = HAL_RTC_STATE_TIMEOUT; |
bogdanm | 0:9b334a45a8ff | 1128 | |
bogdanm | 0:9b334a45a8ff | 1129 | /* Process Unlocked */ |
bogdanm | 0:9b334a45a8ff | 1130 | __HAL_UNLOCK(hrtc); |
bogdanm | 0:9b334a45a8ff | 1131 | |
bogdanm | 0:9b334a45a8ff | 1132 | return HAL_TIMEOUT; |
bogdanm | 0:9b334a45a8ff | 1133 | } |
bogdanm | 0:9b334a45a8ff | 1134 | } |
bogdanm | 0:9b334a45a8ff | 1135 | |
bogdanm | 0:9b334a45a8ff | 1136 | /* Configure the Wakeup Timer counter */ |
bogdanm | 0:9b334a45a8ff | 1137 | hrtc->Instance->WUTR = (uint32_t)WakeUpCounter; |
bogdanm | 0:9b334a45a8ff | 1138 | |
bogdanm | 0:9b334a45a8ff | 1139 | /* Clear the Wakeup Timer clock source bits in CR register */ |
bogdanm | 0:9b334a45a8ff | 1140 | hrtc->Instance->CR &= (uint32_t)~RTC_CR_WUCKSEL; |
bogdanm | 0:9b334a45a8ff | 1141 | |
bogdanm | 0:9b334a45a8ff | 1142 | /* Configure the clock source */ |
bogdanm | 0:9b334a45a8ff | 1143 | hrtc->Instance->CR |= (uint32_t)WakeUpClock; |
bogdanm | 0:9b334a45a8ff | 1144 | |
bogdanm | 0:9b334a45a8ff | 1145 | /* RTC WakeUpTimer Interrupt Configuration: EXTI configuration */ |
bogdanm | 0:9b334a45a8ff | 1146 | __HAL_RTC_WAKEUPTIMER_EXTI_ENABLE_IT(); |
bogdanm | 0:9b334a45a8ff | 1147 | |
bogdanm | 0:9b334a45a8ff | 1148 | __HAL_RTC_WAKEUPTIMER_EXTI_ENABLE_RISING_EDGE(); |
bogdanm | 0:9b334a45a8ff | 1149 | |
bogdanm | 0:9b334a45a8ff | 1150 | /* Configure the Interrupt in the RTC_CR register */ |
bogdanm | 0:9b334a45a8ff | 1151 | __HAL_RTC_WAKEUPTIMER_ENABLE_IT(hrtc,RTC_IT_WUT); |
bogdanm | 0:9b334a45a8ff | 1152 | |
bogdanm | 0:9b334a45a8ff | 1153 | /* Enable the Wakeup Timer */ |
bogdanm | 0:9b334a45a8ff | 1154 | __HAL_RTC_WAKEUPTIMER_ENABLE(hrtc); |
bogdanm | 0:9b334a45a8ff | 1155 | |
bogdanm | 0:9b334a45a8ff | 1156 | /* Enable the write protection for RTC registers */ |
bogdanm | 0:9b334a45a8ff | 1157 | __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc); |
bogdanm | 0:9b334a45a8ff | 1158 | |
bogdanm | 0:9b334a45a8ff | 1159 | hrtc->State = HAL_RTC_STATE_READY; |
bogdanm | 0:9b334a45a8ff | 1160 | |
bogdanm | 0:9b334a45a8ff | 1161 | /* Process Unlocked */ |
bogdanm | 0:9b334a45a8ff | 1162 | __HAL_UNLOCK(hrtc); |
bogdanm | 0:9b334a45a8ff | 1163 | |
bogdanm | 0:9b334a45a8ff | 1164 | return HAL_OK; |
bogdanm | 0:9b334a45a8ff | 1165 | } |
bogdanm | 0:9b334a45a8ff | 1166 | |
bogdanm | 0:9b334a45a8ff | 1167 | /** |
bogdanm | 0:9b334a45a8ff | 1168 | * @brief Deactivates wake up timer counter. |
bogdanm | 0:9b334a45a8ff | 1169 | * @param hrtc: RTC handle |
bogdanm | 0:9b334a45a8ff | 1170 | * @retval HAL status |
bogdanm | 0:9b334a45a8ff | 1171 | */ |
bogdanm | 0:9b334a45a8ff | 1172 | uint32_t HAL_RTCEx_DeactivateWakeUpTimer(RTC_HandleTypeDef *hrtc) |
bogdanm | 0:9b334a45a8ff | 1173 | { |
bogdanm | 0:9b334a45a8ff | 1174 | uint32_t tickstart = 0; |
bogdanm | 0:9b334a45a8ff | 1175 | |
bogdanm | 0:9b334a45a8ff | 1176 | /* Process Locked */ |
bogdanm | 0:9b334a45a8ff | 1177 | __HAL_LOCK(hrtc); |
bogdanm | 0:9b334a45a8ff | 1178 | |
bogdanm | 0:9b334a45a8ff | 1179 | hrtc->State = HAL_RTC_STATE_BUSY; |
bogdanm | 0:9b334a45a8ff | 1180 | |
bogdanm | 0:9b334a45a8ff | 1181 | /* Disable the write protection for RTC registers */ |
bogdanm | 0:9b334a45a8ff | 1182 | __HAL_RTC_WRITEPROTECTION_DISABLE(hrtc); |
bogdanm | 0:9b334a45a8ff | 1183 | |
bogdanm | 0:9b334a45a8ff | 1184 | /* Disable the Wakeup Timer */ |
bogdanm | 0:9b334a45a8ff | 1185 | __HAL_RTC_WAKEUPTIMER_DISABLE(hrtc); |
bogdanm | 0:9b334a45a8ff | 1186 | |
bogdanm | 0:9b334a45a8ff | 1187 | /* In case of interrupt mode is used, the interrupt source must disabled */ |
bogdanm | 0:9b334a45a8ff | 1188 | __HAL_RTC_WAKEUPTIMER_DISABLE_IT(hrtc,RTC_IT_WUT); |
bogdanm | 0:9b334a45a8ff | 1189 | |
bogdanm | 0:9b334a45a8ff | 1190 | tickstart = HAL_GetTick(); |
bogdanm | 0:9b334a45a8ff | 1191 | /* Wait till RTC WUTWF flag is set and if Time out is reached exit */ |
bogdanm | 0:9b334a45a8ff | 1192 | while(__HAL_RTC_WAKEUPTIMER_GET_FLAG(hrtc, RTC_FLAG_WUTWF) == RESET) |
bogdanm | 0:9b334a45a8ff | 1193 | { |
bogdanm | 0:9b334a45a8ff | 1194 | if((HAL_GetTick() - tickstart ) > RTC_TIMEOUT_VALUE) |
bogdanm | 0:9b334a45a8ff | 1195 | { |
bogdanm | 0:9b334a45a8ff | 1196 | /* Enable the write protection for RTC registers */ |
bogdanm | 0:9b334a45a8ff | 1197 | __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc); |
bogdanm | 0:9b334a45a8ff | 1198 | |
bogdanm | 0:9b334a45a8ff | 1199 | hrtc->State = HAL_RTC_STATE_TIMEOUT; |
bogdanm | 0:9b334a45a8ff | 1200 | |
bogdanm | 0:9b334a45a8ff | 1201 | /* Process Unlocked */ |
bogdanm | 0:9b334a45a8ff | 1202 | __HAL_UNLOCK(hrtc); |
bogdanm | 0:9b334a45a8ff | 1203 | |
bogdanm | 0:9b334a45a8ff | 1204 | return HAL_TIMEOUT; |
bogdanm | 0:9b334a45a8ff | 1205 | } |
bogdanm | 0:9b334a45a8ff | 1206 | } |
bogdanm | 0:9b334a45a8ff | 1207 | |
bogdanm | 0:9b334a45a8ff | 1208 | /* Enable the write protection for RTC registers */ |
bogdanm | 0:9b334a45a8ff | 1209 | __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc); |
bogdanm | 0:9b334a45a8ff | 1210 | |
bogdanm | 0:9b334a45a8ff | 1211 | hrtc->State = HAL_RTC_STATE_READY; |
bogdanm | 0:9b334a45a8ff | 1212 | |
bogdanm | 0:9b334a45a8ff | 1213 | /* Process Unlocked */ |
bogdanm | 0:9b334a45a8ff | 1214 | __HAL_UNLOCK(hrtc); |
bogdanm | 0:9b334a45a8ff | 1215 | |
bogdanm | 0:9b334a45a8ff | 1216 | return HAL_OK; |
bogdanm | 0:9b334a45a8ff | 1217 | } |
bogdanm | 0:9b334a45a8ff | 1218 | |
bogdanm | 0:9b334a45a8ff | 1219 | /** |
bogdanm | 0:9b334a45a8ff | 1220 | * @brief Gets wake up timer counter. |
bogdanm | 0:9b334a45a8ff | 1221 | * @param hrtc: RTC handle |
bogdanm | 0:9b334a45a8ff | 1222 | * @retval Counter value |
bogdanm | 0:9b334a45a8ff | 1223 | */ |
bogdanm | 0:9b334a45a8ff | 1224 | uint32_t HAL_RTCEx_GetWakeUpTimer(RTC_HandleTypeDef *hrtc) |
bogdanm | 0:9b334a45a8ff | 1225 | { |
bogdanm | 0:9b334a45a8ff | 1226 | /* Get the counter value */ |
bogdanm | 0:9b334a45a8ff | 1227 | return ((uint32_t)(hrtc->Instance->WUTR & RTC_WUTR_WUT)); |
bogdanm | 0:9b334a45a8ff | 1228 | } |
bogdanm | 0:9b334a45a8ff | 1229 | |
bogdanm | 0:9b334a45a8ff | 1230 | /** |
bogdanm | 0:9b334a45a8ff | 1231 | * @brief This function handles Wake Up Timer interrupt request. |
bogdanm | 0:9b334a45a8ff | 1232 | * @param hrtc: RTC handle |
bogdanm | 0:9b334a45a8ff | 1233 | * @retval None |
bogdanm | 0:9b334a45a8ff | 1234 | */ |
bogdanm | 0:9b334a45a8ff | 1235 | void HAL_RTCEx_WakeUpTimerIRQHandler(RTC_HandleTypeDef *hrtc) |
bogdanm | 0:9b334a45a8ff | 1236 | { |
bogdanm | 0:9b334a45a8ff | 1237 | if(__HAL_RTC_WAKEUPTIMER_GET_IT(hrtc, RTC_IT_WUT)) |
bogdanm | 0:9b334a45a8ff | 1238 | { |
bogdanm | 0:9b334a45a8ff | 1239 | /* Get the status of the Interrupt */ |
bogdanm | 0:9b334a45a8ff | 1240 | if((uint32_t)(hrtc->Instance->CR & RTC_IT_WUT) != (uint32_t)RESET) |
bogdanm | 0:9b334a45a8ff | 1241 | { |
bogdanm | 0:9b334a45a8ff | 1242 | /* WAKEUPTIMER callback */ |
bogdanm | 0:9b334a45a8ff | 1243 | HAL_RTCEx_WakeUpTimerEventCallback(hrtc); |
bogdanm | 0:9b334a45a8ff | 1244 | |
bogdanm | 0:9b334a45a8ff | 1245 | /* Clear the WAKEUPTIMER interrupt pending bit */ |
bogdanm | 0:9b334a45a8ff | 1246 | __HAL_RTC_WAKEUPTIMER_CLEAR_FLAG(hrtc, RTC_FLAG_WUTF); |
bogdanm | 0:9b334a45a8ff | 1247 | } |
bogdanm | 0:9b334a45a8ff | 1248 | } |
bogdanm | 0:9b334a45a8ff | 1249 | |
bogdanm | 0:9b334a45a8ff | 1250 | /* Clear the EXTI's line Flag for RTC WakeUpTimer */ |
bogdanm | 0:9b334a45a8ff | 1251 | __HAL_RTC_WAKEUPTIMER_EXTI_CLEAR_FLAG(); |
bogdanm | 0:9b334a45a8ff | 1252 | |
bogdanm | 0:9b334a45a8ff | 1253 | /* Change RTC state */ |
bogdanm | 0:9b334a45a8ff | 1254 | hrtc->State = HAL_RTC_STATE_READY; |
bogdanm | 0:9b334a45a8ff | 1255 | } |
bogdanm | 0:9b334a45a8ff | 1256 | |
bogdanm | 0:9b334a45a8ff | 1257 | /** |
bogdanm | 0:9b334a45a8ff | 1258 | * @brief Wake Up Timer callback. |
bogdanm | 0:9b334a45a8ff | 1259 | * @param hrtc: RTC handle |
bogdanm | 0:9b334a45a8ff | 1260 | * @retval None |
bogdanm | 0:9b334a45a8ff | 1261 | */ |
bogdanm | 0:9b334a45a8ff | 1262 | __weak void HAL_RTCEx_WakeUpTimerEventCallback(RTC_HandleTypeDef *hrtc) |
bogdanm | 0:9b334a45a8ff | 1263 | { |
bogdanm | 0:9b334a45a8ff | 1264 | /* NOTE : This function Should not be modified, when the callback is needed, |
bogdanm | 0:9b334a45a8ff | 1265 | the HAL_RTCEx_WakeUpTimerEventCallback could be implemented in the user file |
bogdanm | 0:9b334a45a8ff | 1266 | */ |
bogdanm | 0:9b334a45a8ff | 1267 | } |
bogdanm | 0:9b334a45a8ff | 1268 | |
bogdanm | 0:9b334a45a8ff | 1269 | |
bogdanm | 0:9b334a45a8ff | 1270 | /** |
bogdanm | 0:9b334a45a8ff | 1271 | * @brief This function handles Wake Up Timer Polling. |
bogdanm | 0:9b334a45a8ff | 1272 | * @param hrtc: RTC handle |
bogdanm | 0:9b334a45a8ff | 1273 | * @param Timeout: Timeout duration |
bogdanm | 0:9b334a45a8ff | 1274 | * @retval HAL status |
bogdanm | 0:9b334a45a8ff | 1275 | */ |
bogdanm | 0:9b334a45a8ff | 1276 | HAL_StatusTypeDef HAL_RTCEx_PollForWakeUpTimerEvent(RTC_HandleTypeDef *hrtc, uint32_t Timeout) |
bogdanm | 0:9b334a45a8ff | 1277 | { |
bogdanm | 0:9b334a45a8ff | 1278 | uint32_t tickstart = HAL_GetTick(); |
bogdanm | 0:9b334a45a8ff | 1279 | |
bogdanm | 0:9b334a45a8ff | 1280 | while(__HAL_RTC_WAKEUPTIMER_GET_FLAG(hrtc, RTC_FLAG_WUTF) == RESET) |
bogdanm | 0:9b334a45a8ff | 1281 | { |
bogdanm | 0:9b334a45a8ff | 1282 | if(Timeout != HAL_MAX_DELAY) |
bogdanm | 0:9b334a45a8ff | 1283 | { |
bogdanm | 0:9b334a45a8ff | 1284 | if((Timeout == 0)||((HAL_GetTick() - tickstart ) > Timeout)) |
bogdanm | 0:9b334a45a8ff | 1285 | { |
bogdanm | 0:9b334a45a8ff | 1286 | hrtc->State = HAL_RTC_STATE_TIMEOUT; |
bogdanm | 0:9b334a45a8ff | 1287 | |
bogdanm | 0:9b334a45a8ff | 1288 | return HAL_TIMEOUT; |
bogdanm | 0:9b334a45a8ff | 1289 | } |
bogdanm | 0:9b334a45a8ff | 1290 | } |
bogdanm | 0:9b334a45a8ff | 1291 | } |
bogdanm | 0:9b334a45a8ff | 1292 | |
bogdanm | 0:9b334a45a8ff | 1293 | /* Clear the WAKEUPTIMER Flag */ |
bogdanm | 0:9b334a45a8ff | 1294 | __HAL_RTC_WAKEUPTIMER_CLEAR_FLAG(hrtc, RTC_FLAG_WUTF); |
bogdanm | 0:9b334a45a8ff | 1295 | |
bogdanm | 0:9b334a45a8ff | 1296 | /* Change RTC state */ |
bogdanm | 0:9b334a45a8ff | 1297 | hrtc->State = HAL_RTC_STATE_READY; |
bogdanm | 0:9b334a45a8ff | 1298 | |
bogdanm | 0:9b334a45a8ff | 1299 | return HAL_OK; |
bogdanm | 0:9b334a45a8ff | 1300 | } |
bogdanm | 0:9b334a45a8ff | 1301 | |
bogdanm | 0:9b334a45a8ff | 1302 | /** |
bogdanm | 0:9b334a45a8ff | 1303 | * @} |
bogdanm | 0:9b334a45a8ff | 1304 | */ |
bogdanm | 0:9b334a45a8ff | 1305 | |
bogdanm | 0:9b334a45a8ff | 1306 | |
bogdanm | 0:9b334a45a8ff | 1307 | /** @addtogroup RTCEx_Exported_Functions_Group3 |
bogdanm | 0:9b334a45a8ff | 1308 | * @brief Extended Peripheral Control functions |
bogdanm | 0:9b334a45a8ff | 1309 | * |
bogdanm | 0:9b334a45a8ff | 1310 | @verbatim |
bogdanm | 0:9b334a45a8ff | 1311 | =============================================================================== |
bogdanm | 0:9b334a45a8ff | 1312 | ##### Extended Peripheral Control functions ##### |
bogdanm | 0:9b334a45a8ff | 1313 | =============================================================================== |
bogdanm | 0:9b334a45a8ff | 1314 | [..] |
bogdanm | 0:9b334a45a8ff | 1315 | This subsection provides functions allowing to |
bogdanm | 0:9b334a45a8ff | 1316 | (+) Writes a data in a specified RTC Backup data register |
bogdanm | 0:9b334a45a8ff | 1317 | (+) Read a data in a specified RTC Backup data register |
bogdanm | 0:9b334a45a8ff | 1318 | (+) Sets the Coarse calibration parameters. |
bogdanm | 0:9b334a45a8ff | 1319 | (+) Deactivates the Coarse calibration parameters |
bogdanm | 0:9b334a45a8ff | 1320 | (+) Sets the Smooth calibration parameters. |
bogdanm | 0:9b334a45a8ff | 1321 | (+) Configures the Synchronization Shift Control Settings. |
bogdanm | 0:9b334a45a8ff | 1322 | (+) Configures the Calibration Pinout (RTC_CALIB) Selection (1Hz or 512Hz). |
bogdanm | 0:9b334a45a8ff | 1323 | (+) Deactivates the Calibration Pinout (RTC_CALIB) Selection (1Hz or 512Hz). |
bogdanm | 0:9b334a45a8ff | 1324 | (+) Enables the RTC reference clock detection. |
bogdanm | 0:9b334a45a8ff | 1325 | (+) Disable the RTC reference clock detection. |
bogdanm | 0:9b334a45a8ff | 1326 | (+) Enables the Bypass Shadow feature. |
bogdanm | 0:9b334a45a8ff | 1327 | (+) Disables the Bypass Shadow feature. |
bogdanm | 0:9b334a45a8ff | 1328 | |
bogdanm | 0:9b334a45a8ff | 1329 | @endverbatim |
bogdanm | 0:9b334a45a8ff | 1330 | * @{ |
bogdanm | 0:9b334a45a8ff | 1331 | */ |
bogdanm | 0:9b334a45a8ff | 1332 | |
bogdanm | 0:9b334a45a8ff | 1333 | /** |
bogdanm | 0:9b334a45a8ff | 1334 | * @brief Writes a data in a specified RTC Backup data register. |
bogdanm | 0:9b334a45a8ff | 1335 | * @param hrtc: RTC handle |
bogdanm | 0:9b334a45a8ff | 1336 | * @param BackupRegister: RTC Backup data Register number. |
bogdanm | 0:9b334a45a8ff | 1337 | * This parameter can be: RTC_BKP_DRx where x can be from 0 to 19 to |
bogdanm | 0:9b334a45a8ff | 1338 | * specify the register. |
bogdanm | 0:9b334a45a8ff | 1339 | * @param Data: Data to be written in the specified RTC Backup data register. |
bogdanm | 0:9b334a45a8ff | 1340 | * @retval None |
bogdanm | 0:9b334a45a8ff | 1341 | */ |
bogdanm | 0:9b334a45a8ff | 1342 | void HAL_RTCEx_BKUPWrite(RTC_HandleTypeDef *hrtc, uint32_t BackupRegister, uint32_t Data) |
bogdanm | 0:9b334a45a8ff | 1343 | { |
bogdanm | 0:9b334a45a8ff | 1344 | uint32_t tmp = 0; |
bogdanm | 0:9b334a45a8ff | 1345 | |
bogdanm | 0:9b334a45a8ff | 1346 | /* Check the parameters */ |
bogdanm | 0:9b334a45a8ff | 1347 | assert_param(IS_RTC_BKP(BackupRegister)); |
bogdanm | 0:9b334a45a8ff | 1348 | |
bogdanm | 0:9b334a45a8ff | 1349 | tmp = (uint32_t)&(hrtc->Instance->BKP0R); |
bogdanm | 0:9b334a45a8ff | 1350 | tmp += (BackupRegister * 4); |
bogdanm | 0:9b334a45a8ff | 1351 | |
bogdanm | 0:9b334a45a8ff | 1352 | /* Write the specified register */ |
bogdanm | 0:9b334a45a8ff | 1353 | *(__IO uint32_t *)tmp = (uint32_t)Data; |
bogdanm | 0:9b334a45a8ff | 1354 | } |
bogdanm | 0:9b334a45a8ff | 1355 | |
bogdanm | 0:9b334a45a8ff | 1356 | /** |
bogdanm | 0:9b334a45a8ff | 1357 | * @brief Reads data from the specified RTC Backup data Register. |
bogdanm | 0:9b334a45a8ff | 1358 | * @param hrtc: RTC handle |
bogdanm | 0:9b334a45a8ff | 1359 | * @param BackupRegister: RTC Backup data Register number. |
bogdanm | 0:9b334a45a8ff | 1360 | * This parameter can be: RTC_BKP_DRx where x can be from 0 to 19 to |
bogdanm | 0:9b334a45a8ff | 1361 | * specify the register. |
bogdanm | 0:9b334a45a8ff | 1362 | * @retval Read value |
bogdanm | 0:9b334a45a8ff | 1363 | */ |
bogdanm | 0:9b334a45a8ff | 1364 | uint32_t HAL_RTCEx_BKUPRead(RTC_HandleTypeDef *hrtc, uint32_t BackupRegister) |
bogdanm | 0:9b334a45a8ff | 1365 | { |
bogdanm | 0:9b334a45a8ff | 1366 | uint32_t tmp = 0; |
bogdanm | 0:9b334a45a8ff | 1367 | |
bogdanm | 0:9b334a45a8ff | 1368 | /* Check the parameters */ |
bogdanm | 0:9b334a45a8ff | 1369 | assert_param(IS_RTC_BKP(BackupRegister)); |
bogdanm | 0:9b334a45a8ff | 1370 | |
bogdanm | 0:9b334a45a8ff | 1371 | tmp = (uint32_t)&(hrtc->Instance->BKP0R); |
bogdanm | 0:9b334a45a8ff | 1372 | tmp += (BackupRegister * 4); |
bogdanm | 0:9b334a45a8ff | 1373 | |
bogdanm | 0:9b334a45a8ff | 1374 | /* Read the specified register */ |
bogdanm | 0:9b334a45a8ff | 1375 | return (*(__IO uint32_t *)tmp); |
bogdanm | 0:9b334a45a8ff | 1376 | } |
bogdanm | 0:9b334a45a8ff | 1377 | |
bogdanm | 0:9b334a45a8ff | 1378 | /** |
bogdanm | 0:9b334a45a8ff | 1379 | * @brief Sets the Smooth calibration parameters. |
bogdanm | 0:9b334a45a8ff | 1380 | * @param hrtc: RTC handle |
bogdanm | 0:9b334a45a8ff | 1381 | * @param SmoothCalibPeriod: Select the Smooth Calibration Period. |
bogdanm | 0:9b334a45a8ff | 1382 | * This parameter can be can be one of the following values : |
bogdanm | 0:9b334a45a8ff | 1383 | * @arg RTC_SMOOTHCALIB_PERIOD_32SEC: The smooth calibration periode is 32s. |
bogdanm | 0:9b334a45a8ff | 1384 | * @arg RTC_SMOOTHCALIB_PERIOD_16SEC: The smooth calibration periode is 16s. |
bogdanm | 0:9b334a45a8ff | 1385 | * @arg RTC_SMOOTHCALIB_PERIOD_8SEC: The smooth calibartion periode is 8s. |
bogdanm | 0:9b334a45a8ff | 1386 | * @param SmoothCalibPlusPulses: Select to Set or reset the CALP bit. |
bogdanm | 0:9b334a45a8ff | 1387 | * This parameter can be one of the following values: |
bogdanm | 0:9b334a45a8ff | 1388 | * @arg RTC_SMOOTHCALIB_PLUSPULSES_SET: Add one RTCCLK puls every 2*11 pulses. |
bogdanm | 0:9b334a45a8ff | 1389 | * @arg RTC_SMOOTHCALIB_PLUSPULSES_RESET: No RTCCLK pulses are added. |
bogdanm | 0:9b334a45a8ff | 1390 | * @param SmoothCalibMinusPulsesValue: Select the value of CALM[8:0] bits. |
bogdanm | 0:9b334a45a8ff | 1391 | * This parameter can be one any value from 0 to 0x000001FF. |
bogdanm | 0:9b334a45a8ff | 1392 | * @note To deactivate the smooth calibration, the field SmoothCalibPlusPulses |
bogdanm | 0:9b334a45a8ff | 1393 | * must be equal to SMOOTHCALIB_PLUSPULSES_RESET and the field |
bogdanm | 0:9b334a45a8ff | 1394 | * SmoothCalibMinusPulsesValue mut be equal to 0. |
bogdanm | 0:9b334a45a8ff | 1395 | * @retval HAL status |
bogdanm | 0:9b334a45a8ff | 1396 | */ |
bogdanm | 0:9b334a45a8ff | 1397 | HAL_StatusTypeDef HAL_RTCEx_SetSmoothCalib(RTC_HandleTypeDef* hrtc, uint32_t SmoothCalibPeriod, uint32_t SmoothCalibPlusPulses, uint32_t SmoothCalibMinusPulsesValue) |
bogdanm | 0:9b334a45a8ff | 1398 | { |
bogdanm | 0:9b334a45a8ff | 1399 | uint32_t tickstart = 0; |
bogdanm | 0:9b334a45a8ff | 1400 | |
bogdanm | 0:9b334a45a8ff | 1401 | /* Check the parameters */ |
bogdanm | 0:9b334a45a8ff | 1402 | assert_param(IS_RTC_SMOOTH_CALIB_PERIOD(SmoothCalibPeriod)); |
bogdanm | 0:9b334a45a8ff | 1403 | assert_param(IS_RTC_SMOOTH_CALIB_PLUS(SmoothCalibPlusPulses)); |
bogdanm | 0:9b334a45a8ff | 1404 | assert_param(IS_RTC_SMOOTH_CALIB_MINUS(SmoothCalibMinusPulsesValue)); |
bogdanm | 0:9b334a45a8ff | 1405 | |
bogdanm | 0:9b334a45a8ff | 1406 | /* Process Locked */ |
bogdanm | 0:9b334a45a8ff | 1407 | __HAL_LOCK(hrtc); |
bogdanm | 0:9b334a45a8ff | 1408 | |
bogdanm | 0:9b334a45a8ff | 1409 | hrtc->State = HAL_RTC_STATE_BUSY; |
bogdanm | 0:9b334a45a8ff | 1410 | |
bogdanm | 0:9b334a45a8ff | 1411 | /* Disable the write protection for RTC registers */ |
bogdanm | 0:9b334a45a8ff | 1412 | __HAL_RTC_WRITEPROTECTION_DISABLE(hrtc); |
bogdanm | 0:9b334a45a8ff | 1413 | |
bogdanm | 0:9b334a45a8ff | 1414 | /* check if a calibration is pending*/ |
bogdanm | 0:9b334a45a8ff | 1415 | if((hrtc->Instance->ISR & RTC_ISR_RECALPF) != RESET) |
bogdanm | 0:9b334a45a8ff | 1416 | { |
bogdanm | 0:9b334a45a8ff | 1417 | tickstart = HAL_GetTick(); |
bogdanm | 0:9b334a45a8ff | 1418 | |
bogdanm | 0:9b334a45a8ff | 1419 | /* check if a calibration is pending*/ |
bogdanm | 0:9b334a45a8ff | 1420 | while((hrtc->Instance->ISR & RTC_ISR_RECALPF) != RESET) |
bogdanm | 0:9b334a45a8ff | 1421 | { |
bogdanm | 0:9b334a45a8ff | 1422 | if((HAL_GetTick() - tickstart ) > RTC_TIMEOUT_VALUE) |
bogdanm | 0:9b334a45a8ff | 1423 | { |
bogdanm | 0:9b334a45a8ff | 1424 | /* Enable the write protection for RTC registers */ |
bogdanm | 0:9b334a45a8ff | 1425 | __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc); |
bogdanm | 0:9b334a45a8ff | 1426 | |
bogdanm | 0:9b334a45a8ff | 1427 | /* Change RTC state */ |
bogdanm | 0:9b334a45a8ff | 1428 | hrtc->State = HAL_RTC_STATE_TIMEOUT; |
bogdanm | 0:9b334a45a8ff | 1429 | |
bogdanm | 0:9b334a45a8ff | 1430 | /* Process Unlocked */ |
bogdanm | 0:9b334a45a8ff | 1431 | __HAL_UNLOCK(hrtc); |
bogdanm | 0:9b334a45a8ff | 1432 | |
bogdanm | 0:9b334a45a8ff | 1433 | return HAL_TIMEOUT; |
bogdanm | 0:9b334a45a8ff | 1434 | } |
bogdanm | 0:9b334a45a8ff | 1435 | } |
bogdanm | 0:9b334a45a8ff | 1436 | } |
bogdanm | 0:9b334a45a8ff | 1437 | |
bogdanm | 0:9b334a45a8ff | 1438 | /* Configure the Smooth calibration settings */ |
bogdanm | 0:9b334a45a8ff | 1439 | hrtc->Instance->CALR = (uint32_t)((uint32_t)SmoothCalibPeriod | (uint32_t)SmoothCalibPlusPulses | (uint32_t)SmoothCalibMinusPulsesValue); |
bogdanm | 0:9b334a45a8ff | 1440 | |
bogdanm | 0:9b334a45a8ff | 1441 | /* Enable the write protection for RTC registers */ |
bogdanm | 0:9b334a45a8ff | 1442 | __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc); |
bogdanm | 0:9b334a45a8ff | 1443 | |
bogdanm | 0:9b334a45a8ff | 1444 | /* Change RTC state */ |
bogdanm | 0:9b334a45a8ff | 1445 | hrtc->State = HAL_RTC_STATE_READY; |
bogdanm | 0:9b334a45a8ff | 1446 | |
bogdanm | 0:9b334a45a8ff | 1447 | /* Process Unlocked */ |
bogdanm | 0:9b334a45a8ff | 1448 | __HAL_UNLOCK(hrtc); |
bogdanm | 0:9b334a45a8ff | 1449 | |
bogdanm | 0:9b334a45a8ff | 1450 | return HAL_OK; |
bogdanm | 0:9b334a45a8ff | 1451 | } |
bogdanm | 0:9b334a45a8ff | 1452 | |
bogdanm | 0:9b334a45a8ff | 1453 | /** |
bogdanm | 0:9b334a45a8ff | 1454 | * @brief Configures the Synchronization Shift Control Settings. |
bogdanm | 0:9b334a45a8ff | 1455 | * @note When REFCKON is set, firmware must not write to Shift control register. |
bogdanm | 0:9b334a45a8ff | 1456 | * @param hrtc: RTC handle |
bogdanm | 0:9b334a45a8ff | 1457 | * @param ShiftAdd1S: Select to add or not 1 second to the time calendar. |
bogdanm | 0:9b334a45a8ff | 1458 | * This parameter can be one of the following values : |
bogdanm | 0:9b334a45a8ff | 1459 | * @arg RTC_SHIFTADD1S_SET: Add one second to the clock calendar. |
bogdanm | 0:9b334a45a8ff | 1460 | * @arg RTC_SHIFTADD1S_RESET: No effect. |
bogdanm | 0:9b334a45a8ff | 1461 | * @param ShiftSubFS: Select the number of Second Fractions to substitute. |
bogdanm | 0:9b334a45a8ff | 1462 | * This parameter can be one any value from 0 to 0x7FFF. |
bogdanm | 0:9b334a45a8ff | 1463 | * @retval HAL status |
bogdanm | 0:9b334a45a8ff | 1464 | */ |
bogdanm | 0:9b334a45a8ff | 1465 | HAL_StatusTypeDef HAL_RTCEx_SetSynchroShift(RTC_HandleTypeDef* hrtc, uint32_t ShiftAdd1S, uint32_t ShiftSubFS) |
bogdanm | 0:9b334a45a8ff | 1466 | { |
bogdanm | 0:9b334a45a8ff | 1467 | uint32_t tickstart = 0; |
bogdanm | 0:9b334a45a8ff | 1468 | |
bogdanm | 0:9b334a45a8ff | 1469 | /* Check the parameters */ |
bogdanm | 0:9b334a45a8ff | 1470 | assert_param(IS_RTC_SHIFT_ADD1S(ShiftAdd1S)); |
bogdanm | 0:9b334a45a8ff | 1471 | assert_param(IS_RTC_SHIFT_SUBFS(ShiftSubFS)); |
bogdanm | 0:9b334a45a8ff | 1472 | |
bogdanm | 0:9b334a45a8ff | 1473 | /* Process Locked */ |
bogdanm | 0:9b334a45a8ff | 1474 | __HAL_LOCK(hrtc); |
bogdanm | 0:9b334a45a8ff | 1475 | |
bogdanm | 0:9b334a45a8ff | 1476 | hrtc->State = HAL_RTC_STATE_BUSY; |
bogdanm | 0:9b334a45a8ff | 1477 | |
bogdanm | 0:9b334a45a8ff | 1478 | /* Disable the write protection for RTC registers */ |
bogdanm | 0:9b334a45a8ff | 1479 | __HAL_RTC_WRITEPROTECTION_DISABLE(hrtc); |
bogdanm | 0:9b334a45a8ff | 1480 | |
bogdanm | 0:9b334a45a8ff | 1481 | tickstart = HAL_GetTick(); |
bogdanm | 0:9b334a45a8ff | 1482 | |
bogdanm | 0:9b334a45a8ff | 1483 | /* Wait until the shift is completed*/ |
bogdanm | 0:9b334a45a8ff | 1484 | while((hrtc->Instance->ISR & RTC_ISR_SHPF) != RESET) |
bogdanm | 0:9b334a45a8ff | 1485 | { |
bogdanm | 0:9b334a45a8ff | 1486 | if((HAL_GetTick() - tickstart ) > RTC_TIMEOUT_VALUE) |
bogdanm | 0:9b334a45a8ff | 1487 | { |
bogdanm | 0:9b334a45a8ff | 1488 | /* Enable the write protection for RTC registers */ |
bogdanm | 0:9b334a45a8ff | 1489 | __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc); |
bogdanm | 0:9b334a45a8ff | 1490 | |
bogdanm | 0:9b334a45a8ff | 1491 | hrtc->State = HAL_RTC_STATE_TIMEOUT; |
bogdanm | 0:9b334a45a8ff | 1492 | |
bogdanm | 0:9b334a45a8ff | 1493 | /* Process Unlocked */ |
bogdanm | 0:9b334a45a8ff | 1494 | __HAL_UNLOCK(hrtc); |
bogdanm | 0:9b334a45a8ff | 1495 | |
bogdanm | 0:9b334a45a8ff | 1496 | return HAL_TIMEOUT; |
bogdanm | 0:9b334a45a8ff | 1497 | } |
bogdanm | 0:9b334a45a8ff | 1498 | } |
bogdanm | 0:9b334a45a8ff | 1499 | |
bogdanm | 0:9b334a45a8ff | 1500 | /* Check if the reference clock detection is disabled */ |
bogdanm | 0:9b334a45a8ff | 1501 | if((hrtc->Instance->CR & RTC_CR_REFCKON) == RESET) |
bogdanm | 0:9b334a45a8ff | 1502 | { |
bogdanm | 0:9b334a45a8ff | 1503 | /* Configure the Shift settings */ |
bogdanm | 0:9b334a45a8ff | 1504 | hrtc->Instance->SHIFTR = (uint32_t)(uint32_t)(ShiftSubFS) | (uint32_t)(ShiftAdd1S); |
bogdanm | 0:9b334a45a8ff | 1505 | |
bogdanm | 0:9b334a45a8ff | 1506 | /* If RTC_CR_BYPSHAD bit = 0, wait for synchro else this check is not needed */ |
bogdanm | 0:9b334a45a8ff | 1507 | if((hrtc->Instance->CR & RTC_CR_BYPSHAD) == RESET) |
bogdanm | 0:9b334a45a8ff | 1508 | { |
bogdanm | 0:9b334a45a8ff | 1509 | if(HAL_RTC_WaitForSynchro(hrtc) != HAL_OK) |
bogdanm | 0:9b334a45a8ff | 1510 | { |
bogdanm | 0:9b334a45a8ff | 1511 | /* Enable the write protection for RTC registers */ |
bogdanm | 0:9b334a45a8ff | 1512 | __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc); |
bogdanm | 0:9b334a45a8ff | 1513 | |
bogdanm | 0:9b334a45a8ff | 1514 | hrtc->State = HAL_RTC_STATE_ERROR; |
bogdanm | 0:9b334a45a8ff | 1515 | |
bogdanm | 0:9b334a45a8ff | 1516 | /* Process Unlocked */ |
bogdanm | 0:9b334a45a8ff | 1517 | __HAL_UNLOCK(hrtc); |
bogdanm | 0:9b334a45a8ff | 1518 | |
bogdanm | 0:9b334a45a8ff | 1519 | return HAL_ERROR; |
bogdanm | 0:9b334a45a8ff | 1520 | } |
bogdanm | 0:9b334a45a8ff | 1521 | } |
bogdanm | 0:9b334a45a8ff | 1522 | } |
bogdanm | 0:9b334a45a8ff | 1523 | else |
bogdanm | 0:9b334a45a8ff | 1524 | { |
bogdanm | 0:9b334a45a8ff | 1525 | /* Enable the write protection for RTC registers */ |
bogdanm | 0:9b334a45a8ff | 1526 | __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc); |
bogdanm | 0:9b334a45a8ff | 1527 | |
bogdanm | 0:9b334a45a8ff | 1528 | /* Change RTC state */ |
bogdanm | 0:9b334a45a8ff | 1529 | hrtc->State = HAL_RTC_STATE_ERROR; |
bogdanm | 0:9b334a45a8ff | 1530 | |
bogdanm | 0:9b334a45a8ff | 1531 | /* Process Unlocked */ |
bogdanm | 0:9b334a45a8ff | 1532 | __HAL_UNLOCK(hrtc); |
bogdanm | 0:9b334a45a8ff | 1533 | |
bogdanm | 0:9b334a45a8ff | 1534 | return HAL_ERROR; |
bogdanm | 0:9b334a45a8ff | 1535 | } |
bogdanm | 0:9b334a45a8ff | 1536 | |
bogdanm | 0:9b334a45a8ff | 1537 | /* Enable the write protection for RTC registers */ |
bogdanm | 0:9b334a45a8ff | 1538 | __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc); |
bogdanm | 0:9b334a45a8ff | 1539 | |
bogdanm | 0:9b334a45a8ff | 1540 | /* Change RTC state */ |
bogdanm | 0:9b334a45a8ff | 1541 | hrtc->State = HAL_RTC_STATE_READY; |
bogdanm | 0:9b334a45a8ff | 1542 | |
bogdanm | 0:9b334a45a8ff | 1543 | /* Process Unlocked */ |
bogdanm | 0:9b334a45a8ff | 1544 | __HAL_UNLOCK(hrtc); |
bogdanm | 0:9b334a45a8ff | 1545 | |
bogdanm | 0:9b334a45a8ff | 1546 | return HAL_OK; |
bogdanm | 0:9b334a45a8ff | 1547 | } |
bogdanm | 0:9b334a45a8ff | 1548 | |
bogdanm | 0:9b334a45a8ff | 1549 | /** |
bogdanm | 0:9b334a45a8ff | 1550 | * @brief Configures the Calibration Pinout (RTC_CALIB) Selection (1Hz or 512Hz). |
bogdanm | 0:9b334a45a8ff | 1551 | * @param hrtc: RTC handle |
bogdanm | 0:9b334a45a8ff | 1552 | * @param CalibOutput : Select the Calibration output Selection . |
bogdanm | 0:9b334a45a8ff | 1553 | * This parameter can be one of the following values: |
bogdanm | 0:9b334a45a8ff | 1554 | * @arg RTC_CALIBOUTPUT_512HZ: A signal has a regular waveform at 512Hz. |
bogdanm | 0:9b334a45a8ff | 1555 | * @arg RTC_CALIBOUTPUT_1HZ: A signal has a regular waveform at 1Hz. |
bogdanm | 0:9b334a45a8ff | 1556 | * @retval HAL status |
bogdanm | 0:9b334a45a8ff | 1557 | */ |
bogdanm | 0:9b334a45a8ff | 1558 | HAL_StatusTypeDef HAL_RTCEx_SetCalibrationOutPut(RTC_HandleTypeDef* hrtc, uint32_t CalibOutput) |
bogdanm | 0:9b334a45a8ff | 1559 | { |
bogdanm | 0:9b334a45a8ff | 1560 | /* Check the parameters */ |
bogdanm | 0:9b334a45a8ff | 1561 | assert_param(IS_RTC_CALIB_OUTPUT(CalibOutput)); |
bogdanm | 0:9b334a45a8ff | 1562 | |
bogdanm | 0:9b334a45a8ff | 1563 | /* Process Locked */ |
bogdanm | 0:9b334a45a8ff | 1564 | __HAL_LOCK(hrtc); |
bogdanm | 0:9b334a45a8ff | 1565 | |
bogdanm | 0:9b334a45a8ff | 1566 | hrtc->State = HAL_RTC_STATE_BUSY; |
bogdanm | 0:9b334a45a8ff | 1567 | |
bogdanm | 0:9b334a45a8ff | 1568 | /* Disable the write protection for RTC registers */ |
bogdanm | 0:9b334a45a8ff | 1569 | __HAL_RTC_WRITEPROTECTION_DISABLE(hrtc); |
bogdanm | 0:9b334a45a8ff | 1570 | |
bogdanm | 0:9b334a45a8ff | 1571 | /* Clear flags before config */ |
bogdanm | 0:9b334a45a8ff | 1572 | hrtc->Instance->CR &= (uint32_t)~RTC_CR_COSEL; |
bogdanm | 0:9b334a45a8ff | 1573 | |
bogdanm | 0:9b334a45a8ff | 1574 | /* Configure the RTC_CR register */ |
bogdanm | 0:9b334a45a8ff | 1575 | hrtc->Instance->CR |= (uint32_t)CalibOutput; |
bogdanm | 0:9b334a45a8ff | 1576 | |
bogdanm | 0:9b334a45a8ff | 1577 | __HAL_RTC_CALIBRATION_OUTPUT_ENABLE(hrtc); |
bogdanm | 0:9b334a45a8ff | 1578 | |
bogdanm | 0:9b334a45a8ff | 1579 | /* Enable the write protection for RTC registers */ |
bogdanm | 0:9b334a45a8ff | 1580 | __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc); |
bogdanm | 0:9b334a45a8ff | 1581 | |
bogdanm | 0:9b334a45a8ff | 1582 | /* Change RTC state */ |
bogdanm | 0:9b334a45a8ff | 1583 | hrtc->State = HAL_RTC_STATE_READY; |
bogdanm | 0:9b334a45a8ff | 1584 | |
bogdanm | 0:9b334a45a8ff | 1585 | /* Process Unlocked */ |
bogdanm | 0:9b334a45a8ff | 1586 | __HAL_UNLOCK(hrtc); |
bogdanm | 0:9b334a45a8ff | 1587 | |
bogdanm | 0:9b334a45a8ff | 1588 | return HAL_OK; |
bogdanm | 0:9b334a45a8ff | 1589 | } |
bogdanm | 0:9b334a45a8ff | 1590 | |
bogdanm | 0:9b334a45a8ff | 1591 | /** |
bogdanm | 0:9b334a45a8ff | 1592 | * @brief Deactivates the Calibration Pinout (RTC_CALIB) Selection (1Hz or 512Hz). |
bogdanm | 0:9b334a45a8ff | 1593 | * @param hrtc: RTC handle |
bogdanm | 0:9b334a45a8ff | 1594 | * @retval HAL status |
bogdanm | 0:9b334a45a8ff | 1595 | */ |
bogdanm | 0:9b334a45a8ff | 1596 | HAL_StatusTypeDef HAL_RTCEx_DeactivateCalibrationOutPut(RTC_HandleTypeDef* hrtc) |
bogdanm | 0:9b334a45a8ff | 1597 | { |
bogdanm | 0:9b334a45a8ff | 1598 | /* Process Locked */ |
bogdanm | 0:9b334a45a8ff | 1599 | __HAL_LOCK(hrtc); |
bogdanm | 0:9b334a45a8ff | 1600 | |
bogdanm | 0:9b334a45a8ff | 1601 | hrtc->State = HAL_RTC_STATE_BUSY; |
bogdanm | 0:9b334a45a8ff | 1602 | |
bogdanm | 0:9b334a45a8ff | 1603 | /* Disable the write protection for RTC registers */ |
bogdanm | 0:9b334a45a8ff | 1604 | __HAL_RTC_WRITEPROTECTION_DISABLE(hrtc); |
bogdanm | 0:9b334a45a8ff | 1605 | |
bogdanm | 0:9b334a45a8ff | 1606 | __HAL_RTC_CALIBRATION_OUTPUT_DISABLE(hrtc); |
bogdanm | 0:9b334a45a8ff | 1607 | |
bogdanm | 0:9b334a45a8ff | 1608 | /* Enable the write protection for RTC registers */ |
bogdanm | 0:9b334a45a8ff | 1609 | __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc); |
bogdanm | 0:9b334a45a8ff | 1610 | |
bogdanm | 0:9b334a45a8ff | 1611 | /* Change RTC state */ |
bogdanm | 0:9b334a45a8ff | 1612 | hrtc->State = HAL_RTC_STATE_READY; |
bogdanm | 0:9b334a45a8ff | 1613 | |
bogdanm | 0:9b334a45a8ff | 1614 | /* Process Unlocked */ |
bogdanm | 0:9b334a45a8ff | 1615 | __HAL_UNLOCK(hrtc); |
bogdanm | 0:9b334a45a8ff | 1616 | |
bogdanm | 0:9b334a45a8ff | 1617 | return HAL_OK; |
bogdanm | 0:9b334a45a8ff | 1618 | } |
bogdanm | 0:9b334a45a8ff | 1619 | |
bogdanm | 0:9b334a45a8ff | 1620 | /** |
bogdanm | 0:9b334a45a8ff | 1621 | * @brief Enables the RTC reference clock detection. |
bogdanm | 0:9b334a45a8ff | 1622 | * @param hrtc: RTC handle |
bogdanm | 0:9b334a45a8ff | 1623 | * @retval HAL status |
bogdanm | 0:9b334a45a8ff | 1624 | */ |
bogdanm | 0:9b334a45a8ff | 1625 | HAL_StatusTypeDef HAL_RTCEx_SetRefClock(RTC_HandleTypeDef* hrtc) |
bogdanm | 0:9b334a45a8ff | 1626 | { |
bogdanm | 0:9b334a45a8ff | 1627 | /* Process Locked */ |
bogdanm | 0:9b334a45a8ff | 1628 | __HAL_LOCK(hrtc); |
bogdanm | 0:9b334a45a8ff | 1629 | |
bogdanm | 0:9b334a45a8ff | 1630 | hrtc->State = HAL_RTC_STATE_BUSY; |
bogdanm | 0:9b334a45a8ff | 1631 | |
bogdanm | 0:9b334a45a8ff | 1632 | /* Disable the write protection for RTC registers */ |
bogdanm | 0:9b334a45a8ff | 1633 | __HAL_RTC_WRITEPROTECTION_DISABLE(hrtc); |
bogdanm | 0:9b334a45a8ff | 1634 | |
bogdanm | 0:9b334a45a8ff | 1635 | /* Set Initialization mode */ |
bogdanm | 0:9b334a45a8ff | 1636 | if(RTC_EnterInitMode(hrtc) != HAL_OK) |
bogdanm | 0:9b334a45a8ff | 1637 | { |
bogdanm | 0:9b334a45a8ff | 1638 | /* Enable the write protection for RTC registers */ |
bogdanm | 0:9b334a45a8ff | 1639 | __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc); |
bogdanm | 0:9b334a45a8ff | 1640 | |
bogdanm | 0:9b334a45a8ff | 1641 | /* Set RTC state*/ |
bogdanm | 0:9b334a45a8ff | 1642 | hrtc->State = HAL_RTC_STATE_ERROR; |
bogdanm | 0:9b334a45a8ff | 1643 | |
bogdanm | 0:9b334a45a8ff | 1644 | /* Process Unlocked */ |
bogdanm | 0:9b334a45a8ff | 1645 | __HAL_UNLOCK(hrtc); |
bogdanm | 0:9b334a45a8ff | 1646 | |
bogdanm | 0:9b334a45a8ff | 1647 | return HAL_ERROR; |
bogdanm | 0:9b334a45a8ff | 1648 | } |
bogdanm | 0:9b334a45a8ff | 1649 | else |
bogdanm | 0:9b334a45a8ff | 1650 | { |
bogdanm | 0:9b334a45a8ff | 1651 | __HAL_RTC_CLOCKREF_DETECTION_ENABLE(hrtc); |
bogdanm | 0:9b334a45a8ff | 1652 | |
bogdanm | 0:9b334a45a8ff | 1653 | /* Exit Initialization mode */ |
bogdanm | 0:9b334a45a8ff | 1654 | hrtc->Instance->ISR &= (uint32_t)~RTC_ISR_INIT; |
bogdanm | 0:9b334a45a8ff | 1655 | } |
bogdanm | 0:9b334a45a8ff | 1656 | |
bogdanm | 0:9b334a45a8ff | 1657 | /* Enable the write protection for RTC registers */ |
bogdanm | 0:9b334a45a8ff | 1658 | __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc); |
bogdanm | 0:9b334a45a8ff | 1659 | |
bogdanm | 0:9b334a45a8ff | 1660 | /* Change RTC state */ |
bogdanm | 0:9b334a45a8ff | 1661 | hrtc->State = HAL_RTC_STATE_READY; |
bogdanm | 0:9b334a45a8ff | 1662 | |
bogdanm | 0:9b334a45a8ff | 1663 | /* Process Unlocked */ |
bogdanm | 0:9b334a45a8ff | 1664 | __HAL_UNLOCK(hrtc); |
bogdanm | 0:9b334a45a8ff | 1665 | |
bogdanm | 0:9b334a45a8ff | 1666 | return HAL_OK; |
bogdanm | 0:9b334a45a8ff | 1667 | } |
bogdanm | 0:9b334a45a8ff | 1668 | |
bogdanm | 0:9b334a45a8ff | 1669 | /** |
bogdanm | 0:9b334a45a8ff | 1670 | * @brief Disable the RTC reference clock detection. |
bogdanm | 0:9b334a45a8ff | 1671 | * @param hrtc: RTC handle |
bogdanm | 0:9b334a45a8ff | 1672 | * @retval HAL status |
bogdanm | 0:9b334a45a8ff | 1673 | */ |
bogdanm | 0:9b334a45a8ff | 1674 | HAL_StatusTypeDef HAL_RTCEx_DeactivateRefClock(RTC_HandleTypeDef* hrtc) |
bogdanm | 0:9b334a45a8ff | 1675 | { |
bogdanm | 0:9b334a45a8ff | 1676 | /* Process Locked */ |
bogdanm | 0:9b334a45a8ff | 1677 | __HAL_LOCK(hrtc); |
bogdanm | 0:9b334a45a8ff | 1678 | |
bogdanm | 0:9b334a45a8ff | 1679 | hrtc->State = HAL_RTC_STATE_BUSY; |
bogdanm | 0:9b334a45a8ff | 1680 | |
bogdanm | 0:9b334a45a8ff | 1681 | /* Disable the write protection for RTC registers */ |
bogdanm | 0:9b334a45a8ff | 1682 | __HAL_RTC_WRITEPROTECTION_DISABLE(hrtc); |
bogdanm | 0:9b334a45a8ff | 1683 | |
bogdanm | 0:9b334a45a8ff | 1684 | /* Set Initialization mode */ |
bogdanm | 0:9b334a45a8ff | 1685 | if(RTC_EnterInitMode(hrtc) != HAL_OK) |
bogdanm | 0:9b334a45a8ff | 1686 | { |
bogdanm | 0:9b334a45a8ff | 1687 | /* Enable the write protection for RTC registers */ |
bogdanm | 0:9b334a45a8ff | 1688 | __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc); |
bogdanm | 0:9b334a45a8ff | 1689 | |
bogdanm | 0:9b334a45a8ff | 1690 | /* Set RTC state*/ |
bogdanm | 0:9b334a45a8ff | 1691 | hrtc->State = HAL_RTC_STATE_ERROR; |
bogdanm | 0:9b334a45a8ff | 1692 | |
bogdanm | 0:9b334a45a8ff | 1693 | /* Process Unlocked */ |
bogdanm | 0:9b334a45a8ff | 1694 | __HAL_UNLOCK(hrtc); |
bogdanm | 0:9b334a45a8ff | 1695 | |
bogdanm | 0:9b334a45a8ff | 1696 | return HAL_ERROR; |
bogdanm | 0:9b334a45a8ff | 1697 | } |
bogdanm | 0:9b334a45a8ff | 1698 | else |
bogdanm | 0:9b334a45a8ff | 1699 | { |
bogdanm | 0:9b334a45a8ff | 1700 | __HAL_RTC_CLOCKREF_DETECTION_DISABLE(hrtc); |
bogdanm | 0:9b334a45a8ff | 1701 | |
bogdanm | 0:9b334a45a8ff | 1702 | /* Exit Initialization mode */ |
bogdanm | 0:9b334a45a8ff | 1703 | hrtc->Instance->ISR &= (uint32_t)~RTC_ISR_INIT; |
bogdanm | 0:9b334a45a8ff | 1704 | } |
bogdanm | 0:9b334a45a8ff | 1705 | |
bogdanm | 0:9b334a45a8ff | 1706 | /* Enable the write protection for RTC registers */ |
bogdanm | 0:9b334a45a8ff | 1707 | __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc); |
bogdanm | 0:9b334a45a8ff | 1708 | |
bogdanm | 0:9b334a45a8ff | 1709 | /* Change RTC state */ |
bogdanm | 0:9b334a45a8ff | 1710 | hrtc->State = HAL_RTC_STATE_READY; |
bogdanm | 0:9b334a45a8ff | 1711 | |
bogdanm | 0:9b334a45a8ff | 1712 | /* Process Unlocked */ |
bogdanm | 0:9b334a45a8ff | 1713 | __HAL_UNLOCK(hrtc); |
bogdanm | 0:9b334a45a8ff | 1714 | |
bogdanm | 0:9b334a45a8ff | 1715 | return HAL_OK; |
bogdanm | 0:9b334a45a8ff | 1716 | } |
bogdanm | 0:9b334a45a8ff | 1717 | |
bogdanm | 0:9b334a45a8ff | 1718 | /** |
bogdanm | 0:9b334a45a8ff | 1719 | * @brief Enables the Bypass Shadow feature. |
bogdanm | 0:9b334a45a8ff | 1720 | * @param hrtc: RTC handle |
bogdanm | 0:9b334a45a8ff | 1721 | * @note When the Bypass Shadow is enabled the calendar value are taken |
bogdanm | 0:9b334a45a8ff | 1722 | * directly from the Calendar counter. |
bogdanm | 0:9b334a45a8ff | 1723 | * @retval HAL status |
bogdanm | 0:9b334a45a8ff | 1724 | */ |
bogdanm | 0:9b334a45a8ff | 1725 | HAL_StatusTypeDef HAL_RTCEx_EnableBypassShadow(RTC_HandleTypeDef* hrtc) |
bogdanm | 0:9b334a45a8ff | 1726 | { |
bogdanm | 0:9b334a45a8ff | 1727 | /* Process Locked */ |
bogdanm | 0:9b334a45a8ff | 1728 | __HAL_LOCK(hrtc); |
bogdanm | 0:9b334a45a8ff | 1729 | |
bogdanm | 0:9b334a45a8ff | 1730 | hrtc->State = HAL_RTC_STATE_BUSY; |
bogdanm | 0:9b334a45a8ff | 1731 | |
bogdanm | 0:9b334a45a8ff | 1732 | /* Disable the write protection for RTC registers */ |
bogdanm | 0:9b334a45a8ff | 1733 | __HAL_RTC_WRITEPROTECTION_DISABLE(hrtc); |
bogdanm | 0:9b334a45a8ff | 1734 | |
bogdanm | 0:9b334a45a8ff | 1735 | /* Set the BYPSHAD bit */ |
bogdanm | 0:9b334a45a8ff | 1736 | hrtc->Instance->CR |= (uint8_t)RTC_CR_BYPSHAD; |
bogdanm | 0:9b334a45a8ff | 1737 | |
bogdanm | 0:9b334a45a8ff | 1738 | /* Enable the write protection for RTC registers */ |
bogdanm | 0:9b334a45a8ff | 1739 | __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc); |
bogdanm | 0:9b334a45a8ff | 1740 | |
bogdanm | 0:9b334a45a8ff | 1741 | /* Change RTC state */ |
bogdanm | 0:9b334a45a8ff | 1742 | hrtc->State = HAL_RTC_STATE_READY; |
bogdanm | 0:9b334a45a8ff | 1743 | |
bogdanm | 0:9b334a45a8ff | 1744 | /* Process Unlocked */ |
bogdanm | 0:9b334a45a8ff | 1745 | __HAL_UNLOCK(hrtc); |
bogdanm | 0:9b334a45a8ff | 1746 | |
bogdanm | 0:9b334a45a8ff | 1747 | return HAL_OK; |
bogdanm | 0:9b334a45a8ff | 1748 | } |
bogdanm | 0:9b334a45a8ff | 1749 | |
bogdanm | 0:9b334a45a8ff | 1750 | /** |
bogdanm | 0:9b334a45a8ff | 1751 | * @brief Disables the Bypass Shadow feature. |
bogdanm | 0:9b334a45a8ff | 1752 | * @param hrtc: RTC handle |
bogdanm | 0:9b334a45a8ff | 1753 | * @note When the Bypass Shadow is enabled the calendar value are taken |
bogdanm | 0:9b334a45a8ff | 1754 | * directly from the Calendar counter. |
bogdanm | 0:9b334a45a8ff | 1755 | * @retval HAL status |
bogdanm | 0:9b334a45a8ff | 1756 | */ |
bogdanm | 0:9b334a45a8ff | 1757 | HAL_StatusTypeDef HAL_RTCEx_DisableBypassShadow(RTC_HandleTypeDef* hrtc) |
bogdanm | 0:9b334a45a8ff | 1758 | { |
bogdanm | 0:9b334a45a8ff | 1759 | /* Process Locked */ |
bogdanm | 0:9b334a45a8ff | 1760 | __HAL_LOCK(hrtc); |
bogdanm | 0:9b334a45a8ff | 1761 | |
bogdanm | 0:9b334a45a8ff | 1762 | hrtc->State = HAL_RTC_STATE_BUSY; |
bogdanm | 0:9b334a45a8ff | 1763 | |
bogdanm | 0:9b334a45a8ff | 1764 | /* Disable the write protection for RTC registers */ |
bogdanm | 0:9b334a45a8ff | 1765 | __HAL_RTC_WRITEPROTECTION_DISABLE(hrtc); |
bogdanm | 0:9b334a45a8ff | 1766 | |
bogdanm | 0:9b334a45a8ff | 1767 | /* Reset the BYPSHAD bit */ |
bogdanm | 0:9b334a45a8ff | 1768 | hrtc->Instance->CR &= ((uint8_t)~RTC_CR_BYPSHAD); |
bogdanm | 0:9b334a45a8ff | 1769 | |
bogdanm | 0:9b334a45a8ff | 1770 | /* Enable the write protection for RTC registers */ |
bogdanm | 0:9b334a45a8ff | 1771 | __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc); |
bogdanm | 0:9b334a45a8ff | 1772 | |
bogdanm | 0:9b334a45a8ff | 1773 | /* Change RTC state */ |
bogdanm | 0:9b334a45a8ff | 1774 | hrtc->State = HAL_RTC_STATE_READY; |
bogdanm | 0:9b334a45a8ff | 1775 | |
bogdanm | 0:9b334a45a8ff | 1776 | /* Process Unlocked */ |
bogdanm | 0:9b334a45a8ff | 1777 | __HAL_UNLOCK(hrtc); |
bogdanm | 0:9b334a45a8ff | 1778 | |
bogdanm | 0:9b334a45a8ff | 1779 | return HAL_OK; |
bogdanm | 0:9b334a45a8ff | 1780 | } |
bogdanm | 0:9b334a45a8ff | 1781 | |
bogdanm | 0:9b334a45a8ff | 1782 | /** |
bogdanm | 0:9b334a45a8ff | 1783 | * @} |
bogdanm | 0:9b334a45a8ff | 1784 | */ |
bogdanm | 0:9b334a45a8ff | 1785 | |
bogdanm | 0:9b334a45a8ff | 1786 | /** @addtogroup RTCEx_Exported_Functions_Group4 |
bogdanm | 0:9b334a45a8ff | 1787 | * @brief Extended features functions |
bogdanm | 0:9b334a45a8ff | 1788 | * |
bogdanm | 0:9b334a45a8ff | 1789 | @verbatim |
bogdanm | 0:9b334a45a8ff | 1790 | =============================================================================== |
bogdanm | 0:9b334a45a8ff | 1791 | ##### Extended features functions ##### |
bogdanm | 0:9b334a45a8ff | 1792 | =============================================================================== |
bogdanm | 0:9b334a45a8ff | 1793 | [..] This section provides functions allowing to: |
bogdanm | 0:9b334a45a8ff | 1794 | (+) RTC Alram B callback |
bogdanm | 0:9b334a45a8ff | 1795 | (+) RTC Poll for Alarm B request |
bogdanm | 0:9b334a45a8ff | 1796 | |
bogdanm | 0:9b334a45a8ff | 1797 | @endverbatim |
bogdanm | 0:9b334a45a8ff | 1798 | * @{ |
bogdanm | 0:9b334a45a8ff | 1799 | */ |
bogdanm | 0:9b334a45a8ff | 1800 | |
bogdanm | 0:9b334a45a8ff | 1801 | /** |
bogdanm | 0:9b334a45a8ff | 1802 | * @brief Alarm B callback. |
bogdanm | 0:9b334a45a8ff | 1803 | * @param hrtc: RTC handle |
bogdanm | 0:9b334a45a8ff | 1804 | * @retval None |
bogdanm | 0:9b334a45a8ff | 1805 | */ |
bogdanm | 0:9b334a45a8ff | 1806 | __weak void HAL_RTCEx_AlarmBEventCallback(RTC_HandleTypeDef *hrtc) |
bogdanm | 0:9b334a45a8ff | 1807 | { |
bogdanm | 0:9b334a45a8ff | 1808 | /* NOTE : This function Should not be modified, when the callback is needed, |
bogdanm | 0:9b334a45a8ff | 1809 | the HAL_RTC_AlarmBEventCallback could be implemented in the user file |
bogdanm | 0:9b334a45a8ff | 1810 | */ |
bogdanm | 0:9b334a45a8ff | 1811 | } |
bogdanm | 0:9b334a45a8ff | 1812 | |
bogdanm | 0:9b334a45a8ff | 1813 | |
bogdanm | 0:9b334a45a8ff | 1814 | /** |
bogdanm | 0:9b334a45a8ff | 1815 | * @brief This function handles AlarmB Polling request. |
bogdanm | 0:9b334a45a8ff | 1816 | * @param hrtc: RTC handle |
bogdanm | 0:9b334a45a8ff | 1817 | * @param Timeout: Timeout duration |
bogdanm | 0:9b334a45a8ff | 1818 | * @retval HAL status |
bogdanm | 0:9b334a45a8ff | 1819 | */ |
bogdanm | 0:9b334a45a8ff | 1820 | HAL_StatusTypeDef HAL_RTCEx_PollForAlarmBEvent(RTC_HandleTypeDef *hrtc, uint32_t Timeout) |
bogdanm | 0:9b334a45a8ff | 1821 | { |
bogdanm | 0:9b334a45a8ff | 1822 | uint32_t tickstart = HAL_GetTick(); |
bogdanm | 0:9b334a45a8ff | 1823 | |
bogdanm | 0:9b334a45a8ff | 1824 | while(__HAL_RTC_ALARM_GET_FLAG(hrtc, RTC_FLAG_ALRBF) == RESET) |
bogdanm | 0:9b334a45a8ff | 1825 | { |
bogdanm | 0:9b334a45a8ff | 1826 | if(Timeout != HAL_MAX_DELAY) |
bogdanm | 0:9b334a45a8ff | 1827 | { |
bogdanm | 0:9b334a45a8ff | 1828 | if((Timeout == 0)||((HAL_GetTick() - tickstart ) > Timeout)) |
bogdanm | 0:9b334a45a8ff | 1829 | { |
bogdanm | 0:9b334a45a8ff | 1830 | hrtc->State = HAL_RTC_STATE_TIMEOUT; |
bogdanm | 0:9b334a45a8ff | 1831 | return HAL_TIMEOUT; |
bogdanm | 0:9b334a45a8ff | 1832 | } |
bogdanm | 0:9b334a45a8ff | 1833 | } |
bogdanm | 0:9b334a45a8ff | 1834 | } |
bogdanm | 0:9b334a45a8ff | 1835 | |
bogdanm | 0:9b334a45a8ff | 1836 | /* Clear the Alarm Flag */ |
bogdanm | 0:9b334a45a8ff | 1837 | __HAL_RTC_ALARM_CLEAR_FLAG(hrtc, RTC_FLAG_ALRBF); |
bogdanm | 0:9b334a45a8ff | 1838 | |
bogdanm | 0:9b334a45a8ff | 1839 | /* Change RTC state */ |
bogdanm | 0:9b334a45a8ff | 1840 | hrtc->State = HAL_RTC_STATE_READY; |
bogdanm | 0:9b334a45a8ff | 1841 | |
bogdanm | 0:9b334a45a8ff | 1842 | return HAL_OK; |
bogdanm | 0:9b334a45a8ff | 1843 | } |
bogdanm | 0:9b334a45a8ff | 1844 | |
bogdanm | 0:9b334a45a8ff | 1845 | /** |
bogdanm | 0:9b334a45a8ff | 1846 | * @} |
bogdanm | 0:9b334a45a8ff | 1847 | */ |
bogdanm | 0:9b334a45a8ff | 1848 | |
bogdanm | 0:9b334a45a8ff | 1849 | /** |
bogdanm | 0:9b334a45a8ff | 1850 | * @} |
bogdanm | 0:9b334a45a8ff | 1851 | */ |
bogdanm | 0:9b334a45a8ff | 1852 | |
bogdanm | 0:9b334a45a8ff | 1853 | #endif /* HAL_RTC_MODULE_ENABLED */ |
bogdanm | 0:9b334a45a8ff | 1854 | /** |
bogdanm | 0:9b334a45a8ff | 1855 | * @} |
bogdanm | 0:9b334a45a8ff | 1856 | */ |
bogdanm | 0:9b334a45a8ff | 1857 | |
bogdanm | 0:9b334a45a8ff | 1858 | /** |
bogdanm | 0:9b334a45a8ff | 1859 | * @} |
bogdanm | 0:9b334a45a8ff | 1860 | */ |
bogdanm | 0:9b334a45a8ff | 1861 | |
bogdanm | 0:9b334a45a8ff | 1862 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ |
bogdanm | 0:9b334a45a8ff | 1863 |