Initial commit

Dependencies:   FastPWM

Committer:
lypinator
Date:
Wed Sep 16 01:11:49 2020 +0000
Revision:
0:bb348c97df44
Added PWM

Who changed what in which revision?

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