inport from local

Dependents:   Hobbyking_Cheetah_0511

Committer:
NYX
Date:
Mon Mar 16 06:35:48 2020 +0000
Revision:
0:85b3fd62ea1a
reinport to mbed;

Who changed what in which revision?

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