mbed library sources

Dependents:   frdm_kl05z_gpio_test

Fork of mbed-src by mbed official

Committer:
shaoziyang
Date:
Sat Sep 13 14:25:46 2014 +0000
Revision:
323:9e901b0a5aa1
Parent:
226:b062af740e40
test with CLOCK_SETUP = 0

Who changed what in which revision?

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