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