mbed library sources, include can_api for nucleo-f091rc

Dependents:   CanNucleoF0_example

Fork of mbed-src by mbed official

Committer:
ptpaterson
Date:
Thu Jan 07 05:49:05 2016 +0000
Revision:
645:13c87cbecd54
Parent:
610:813dcc80987e
corrected freeze on CAN_RECEIVE_IT

Who changed what in which revision?

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