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