mbed library sources

Dependents:   Encrypted my_mbed lklk CyaSSL_DTLS_Cellular ... more

Superseded

This library was superseded by mbed-dev - https://os.mbed.com/users/mbed_official/code/mbed-dev/.

Development branch of the mbed library sources. This library is kept in synch with the latest changes from the mbed SDK and it is not guaranteed to work.

If you are looking for a stable and tested release, please import one of the official mbed library releases:

Import librarymbed

The official Mbed 2 C/C++ SDK provides the software platform and libraries to build your applications.

Committer:
mbed_official
Date:
Wed Jul 01 09:45:11 2015 +0100
Revision:
579:53297373a894
Parent:
573:ad23fe03a082
Child:
610:813dcc80987e
Synchronized with git revision d5b4d2ab9c47edb4dc5776e7177b0c2263459081

Full URL: https://github.com/mbedmicro/mbed/commit/d5b4d2ab9c47edb4dc5776e7177b0c2263459081/

Initial version of drivers for SAMR21

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 573:ad23fe03a082 5 * @version V1.0.0
mbed_official 573:ad23fe03a082 6 * @date 12-May-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 573:ad23fe03a082 968 /* Wait till RTC WUTWF flag is set and if Time out is reached exit */
mbed_official 573:ad23fe03a082 969 while(__HAL_RTC_WAKEUPTIMER_GET_FLAG(hrtc, RTC_FLAG_WUTWF) == RESET)
mbed_official 573:ad23fe03a082 970 {
mbed_official 573:ad23fe03a082 971 if((HAL_GetTick() - tickstart ) > RTC_TIMEOUT_VALUE)
mbed_official 573:ad23fe03a082 972 {
mbed_official 573:ad23fe03a082 973 /* Enable the write protection for RTC registers */
mbed_official 573:ad23fe03a082 974 __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc);
mbed_official 573:ad23fe03a082 975
mbed_official 573:ad23fe03a082 976 hrtc->State = HAL_RTC_STATE_TIMEOUT;
mbed_official 573:ad23fe03a082 977
mbed_official 573:ad23fe03a082 978 /* Process Unlocked */
mbed_official 573:ad23fe03a082 979 __HAL_UNLOCK(hrtc);
mbed_official 573:ad23fe03a082 980
mbed_official 573:ad23fe03a082 981 return HAL_TIMEOUT;
mbed_official 573:ad23fe03a082 982 }
mbed_official 573:ad23fe03a082 983 }
mbed_official 573:ad23fe03a082 984
mbed_official 573:ad23fe03a082 985 /* Clear the Wakeup Timer clock source bits in CR register */
mbed_official 573:ad23fe03a082 986 hrtc->Instance->CR &= (uint32_t)~RTC_CR_WUCKSEL;
mbed_official 573:ad23fe03a082 987
mbed_official 573:ad23fe03a082 988 /* Configure the clock source */
mbed_official 573:ad23fe03a082 989 hrtc->Instance->CR |= (uint32_t)WakeUpClock;
mbed_official 573:ad23fe03a082 990
mbed_official 573:ad23fe03a082 991 /* Configure the Wakeup Timer counter */
mbed_official 573:ad23fe03a082 992 hrtc->Instance->WUTR = (uint32_t)WakeUpCounter;
mbed_official 573:ad23fe03a082 993
mbed_official 573:ad23fe03a082 994 /* Enable the Wakeup Timer */
mbed_official 573:ad23fe03a082 995 __HAL_RTC_WAKEUPTIMER_ENABLE(hrtc);
mbed_official 573:ad23fe03a082 996
mbed_official 573:ad23fe03a082 997 /* Enable the write protection for RTC registers */
mbed_official 573:ad23fe03a082 998 __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc);
mbed_official 573:ad23fe03a082 999
mbed_official 573:ad23fe03a082 1000 hrtc->State = HAL_RTC_STATE_READY;
mbed_official 573:ad23fe03a082 1001
mbed_official 573:ad23fe03a082 1002 /* Process Unlocked */
mbed_official 573:ad23fe03a082 1003 __HAL_UNLOCK(hrtc);
mbed_official 573:ad23fe03a082 1004
mbed_official 573:ad23fe03a082 1005 return HAL_OK;
mbed_official 573:ad23fe03a082 1006 }
mbed_official 573:ad23fe03a082 1007
mbed_official 573:ad23fe03a082 1008 /**
mbed_official 573:ad23fe03a082 1009 * @brief Sets wake up timer with interrupt
mbed_official 573:ad23fe03a082 1010 * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains
mbed_official 573:ad23fe03a082 1011 * the configuration information for RTC.
mbed_official 573:ad23fe03a082 1012 * @param WakeUpCounter: Wake up counter
mbed_official 573:ad23fe03a082 1013 * @param WakeUpClock: Wake up clock
mbed_official 573:ad23fe03a082 1014 * @retval HAL status
mbed_official 573:ad23fe03a082 1015 */
mbed_official 573:ad23fe03a082 1016 HAL_StatusTypeDef HAL_RTCEx_SetWakeUpTimer_IT(RTC_HandleTypeDef *hrtc, uint32_t WakeUpCounter, uint32_t WakeUpClock)
mbed_official 573:ad23fe03a082 1017 {
mbed_official 573:ad23fe03a082 1018 uint32_t tickstart = 0;
mbed_official 573:ad23fe03a082 1019
mbed_official 573:ad23fe03a082 1020 /* Check the parameters */
mbed_official 573:ad23fe03a082 1021 assert_param(IS_RTC_WAKEUP_CLOCK(WakeUpClock));
mbed_official 573:ad23fe03a082 1022 assert_param(IS_RTC_WAKEUP_COUNTER(WakeUpCounter));
mbed_official 573:ad23fe03a082 1023
mbed_official 573:ad23fe03a082 1024 /* Process Locked */
mbed_official 573:ad23fe03a082 1025 __HAL_LOCK(hrtc);
mbed_official 573:ad23fe03a082 1026
mbed_official 573:ad23fe03a082 1027 hrtc->State = HAL_RTC_STATE_BUSY;
mbed_official 573:ad23fe03a082 1028
mbed_official 573:ad23fe03a082 1029 /* Disable the write protection for RTC registers */
mbed_official 573:ad23fe03a082 1030 __HAL_RTC_WRITEPROTECTION_DISABLE(hrtc);
mbed_official 573:ad23fe03a082 1031
mbed_official 573:ad23fe03a082 1032 __HAL_RTC_WAKEUPTIMER_DISABLE(hrtc);
mbed_official 573:ad23fe03a082 1033
mbed_official 573:ad23fe03a082 1034 /* Get tick */
mbed_official 573:ad23fe03a082 1035 tickstart = HAL_GetTick();
mbed_official 573:ad23fe03a082 1036
mbed_official 573:ad23fe03a082 1037 /* Wait till RTC WUTWF flag is set and if Time out is reached exit */
mbed_official 573:ad23fe03a082 1038 while(__HAL_RTC_WAKEUPTIMER_GET_FLAG(hrtc, RTC_FLAG_WUTWF) == RESET)
mbed_official 573:ad23fe03a082 1039 {
mbed_official 573:ad23fe03a082 1040 if((HAL_GetTick() - tickstart ) > RTC_TIMEOUT_VALUE)
mbed_official 573:ad23fe03a082 1041 {
mbed_official 573:ad23fe03a082 1042 /* Enable the write protection for RTC registers */
mbed_official 573:ad23fe03a082 1043 __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc);
mbed_official 573:ad23fe03a082 1044
mbed_official 573:ad23fe03a082 1045 hrtc->State = HAL_RTC_STATE_TIMEOUT;
mbed_official 573:ad23fe03a082 1046
mbed_official 573:ad23fe03a082 1047 /* Process Unlocked */
mbed_official 573:ad23fe03a082 1048 __HAL_UNLOCK(hrtc);
mbed_official 573:ad23fe03a082 1049
mbed_official 573:ad23fe03a082 1050 return HAL_TIMEOUT;
mbed_official 573:ad23fe03a082 1051 }
mbed_official 573:ad23fe03a082 1052 }
mbed_official 573:ad23fe03a082 1053
mbed_official 573:ad23fe03a082 1054 /* Configure the Wakeup Timer counter */
mbed_official 573:ad23fe03a082 1055 hrtc->Instance->WUTR = (uint32_t)WakeUpCounter;
mbed_official 573:ad23fe03a082 1056
mbed_official 573:ad23fe03a082 1057 /* Clear the Wakeup Timer clock source bits in CR register */
mbed_official 573:ad23fe03a082 1058 hrtc->Instance->CR &= (uint32_t)~RTC_CR_WUCKSEL;
mbed_official 573:ad23fe03a082 1059
mbed_official 573:ad23fe03a082 1060 /* Configure the clock source */
mbed_official 573:ad23fe03a082 1061 hrtc->Instance->CR |= (uint32_t)WakeUpClock;
mbed_official 573:ad23fe03a082 1062
mbed_official 573:ad23fe03a082 1063 /* RTC WakeUpTimer Interrupt Configuration: EXTI configuration */
mbed_official 573:ad23fe03a082 1064 __HAL_RTC_WAKEUPTIMER_EXTI_ENABLE_IT();
mbed_official 573:ad23fe03a082 1065
mbed_official 573:ad23fe03a082 1066 EXTI->RTSR |= RTC_EXTI_LINE_WAKEUPTIMER_EVENT;
mbed_official 573:ad23fe03a082 1067
mbed_official 573:ad23fe03a082 1068 /* Configure the Interrupt in the RTC_CR register */
mbed_official 573:ad23fe03a082 1069 __HAL_RTC_WAKEUPTIMER_ENABLE_IT(hrtc,RTC_IT_WUT);
mbed_official 573:ad23fe03a082 1070
mbed_official 573:ad23fe03a082 1071 /* Enable the Wakeup Timer */
mbed_official 573:ad23fe03a082 1072 __HAL_RTC_WAKEUPTIMER_ENABLE(hrtc);
mbed_official 573:ad23fe03a082 1073
mbed_official 573:ad23fe03a082 1074 /* Enable the write protection for RTC registers */
mbed_official 573:ad23fe03a082 1075 __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc);
mbed_official 573:ad23fe03a082 1076
mbed_official 573:ad23fe03a082 1077 hrtc->State = HAL_RTC_STATE_READY;
mbed_official 573:ad23fe03a082 1078
mbed_official 573:ad23fe03a082 1079 /* Process Unlocked */
mbed_official 573:ad23fe03a082 1080 __HAL_UNLOCK(hrtc);
mbed_official 573:ad23fe03a082 1081
mbed_official 573:ad23fe03a082 1082 return HAL_OK;
mbed_official 573:ad23fe03a082 1083 }
mbed_official 573:ad23fe03a082 1084
mbed_official 573:ad23fe03a082 1085 /**
mbed_official 573:ad23fe03a082 1086 * @brief Deactivates wake up timer counter.
mbed_official 573:ad23fe03a082 1087 * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains
mbed_official 573:ad23fe03a082 1088 * the configuration information for RTC.
mbed_official 573:ad23fe03a082 1089 * @retval HAL status
mbed_official 573:ad23fe03a082 1090 */
mbed_official 573:ad23fe03a082 1091 uint32_t HAL_RTCEx_DeactivateWakeUpTimer(RTC_HandleTypeDef *hrtc)
mbed_official 573:ad23fe03a082 1092 {
mbed_official 573:ad23fe03a082 1093 uint32_t tickstart = 0;
mbed_official 573:ad23fe03a082 1094
mbed_official 573:ad23fe03a082 1095 /* Process Locked */
mbed_official 573:ad23fe03a082 1096 __HAL_LOCK(hrtc);
mbed_official 573:ad23fe03a082 1097
mbed_official 573:ad23fe03a082 1098 hrtc->State = HAL_RTC_STATE_BUSY;
mbed_official 573:ad23fe03a082 1099
mbed_official 573:ad23fe03a082 1100 /* Disable the write protection for RTC registers */
mbed_official 573:ad23fe03a082 1101 __HAL_RTC_WRITEPROTECTION_DISABLE(hrtc);
mbed_official 573:ad23fe03a082 1102
mbed_official 573:ad23fe03a082 1103 /* Disable the Wakeup Timer */
mbed_official 573:ad23fe03a082 1104 __HAL_RTC_WAKEUPTIMER_DISABLE(hrtc);
mbed_official 573:ad23fe03a082 1105
mbed_official 573:ad23fe03a082 1106 /* In case of interrupt mode is used, the interrupt source must disabled */
mbed_official 573:ad23fe03a082 1107 __HAL_RTC_WAKEUPTIMER_DISABLE_IT(hrtc,RTC_IT_WUT);
mbed_official 573:ad23fe03a082 1108
mbed_official 573:ad23fe03a082 1109 /* Get tick */
mbed_official 573:ad23fe03a082 1110 tickstart = HAL_GetTick();
mbed_official 573:ad23fe03a082 1111
mbed_official 573:ad23fe03a082 1112 /* Wait till RTC WUTWF flag is set and if Time out is reached exit */
mbed_official 573:ad23fe03a082 1113 while(__HAL_RTC_WAKEUPTIMER_GET_FLAG(hrtc, RTC_FLAG_WUTWF) == RESET)
mbed_official 573:ad23fe03a082 1114 {
mbed_official 573:ad23fe03a082 1115 if((HAL_GetTick() - tickstart ) > RTC_TIMEOUT_VALUE)
mbed_official 573:ad23fe03a082 1116 {
mbed_official 573:ad23fe03a082 1117 /* Enable the write protection for RTC registers */
mbed_official 573:ad23fe03a082 1118 __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc);
mbed_official 573:ad23fe03a082 1119
mbed_official 573:ad23fe03a082 1120 hrtc->State = HAL_RTC_STATE_TIMEOUT;
mbed_official 573:ad23fe03a082 1121
mbed_official 573:ad23fe03a082 1122 /* Process Unlocked */
mbed_official 573:ad23fe03a082 1123 __HAL_UNLOCK(hrtc);
mbed_official 573:ad23fe03a082 1124
mbed_official 573:ad23fe03a082 1125 return HAL_TIMEOUT;
mbed_official 573:ad23fe03a082 1126 }
mbed_official 573:ad23fe03a082 1127 }
mbed_official 573:ad23fe03a082 1128
mbed_official 573:ad23fe03a082 1129 /* Enable the write protection for RTC registers */
mbed_official 573:ad23fe03a082 1130 __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc);
mbed_official 573:ad23fe03a082 1131
mbed_official 573:ad23fe03a082 1132 hrtc->State = HAL_RTC_STATE_READY;
mbed_official 573:ad23fe03a082 1133
mbed_official 573:ad23fe03a082 1134 /* Process Unlocked */
mbed_official 573:ad23fe03a082 1135 __HAL_UNLOCK(hrtc);
mbed_official 573:ad23fe03a082 1136
mbed_official 573:ad23fe03a082 1137 return HAL_OK;
mbed_official 573:ad23fe03a082 1138 }
mbed_official 573:ad23fe03a082 1139
mbed_official 573:ad23fe03a082 1140 /**
mbed_official 573:ad23fe03a082 1141 * @brief Gets wake up timer counter.
mbed_official 573:ad23fe03a082 1142 * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains
mbed_official 573:ad23fe03a082 1143 * the configuration information for RTC.
mbed_official 573:ad23fe03a082 1144 * @retval Counter value
mbed_official 573:ad23fe03a082 1145 */
mbed_official 573:ad23fe03a082 1146 uint32_t HAL_RTCEx_GetWakeUpTimer(RTC_HandleTypeDef *hrtc)
mbed_official 573:ad23fe03a082 1147 {
mbed_official 573:ad23fe03a082 1148 /* Get the counter value */
mbed_official 573:ad23fe03a082 1149 return ((uint32_t)(hrtc->Instance->WUTR & RTC_WUTR_WUT));
mbed_official 573:ad23fe03a082 1150 }
mbed_official 573:ad23fe03a082 1151
mbed_official 573:ad23fe03a082 1152 /**
mbed_official 573:ad23fe03a082 1153 * @brief This function handles Wake Up Timer interrupt request.
mbed_official 573:ad23fe03a082 1154 * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains
mbed_official 573:ad23fe03a082 1155 * the configuration information for RTC.
mbed_official 573:ad23fe03a082 1156 * @retval None
mbed_official 573:ad23fe03a082 1157 */
mbed_official 573:ad23fe03a082 1158 void HAL_RTCEx_WakeUpTimerIRQHandler(RTC_HandleTypeDef *hrtc)
mbed_official 573:ad23fe03a082 1159 {
mbed_official 573:ad23fe03a082 1160 if(__HAL_RTC_WAKEUPTIMER_GET_IT(hrtc, RTC_IT_WUT))
mbed_official 573:ad23fe03a082 1161 {
mbed_official 573:ad23fe03a082 1162 /* Get the status of the Interrupt */
mbed_official 573:ad23fe03a082 1163 if((uint32_t)(hrtc->Instance->CR & RTC_IT_WUT) != (uint32_t)RESET)
mbed_official 573:ad23fe03a082 1164 {
mbed_official 573:ad23fe03a082 1165 /* WAKEUPTIMER callback */
mbed_official 573:ad23fe03a082 1166 HAL_RTCEx_WakeUpTimerEventCallback(hrtc);
mbed_official 573:ad23fe03a082 1167
mbed_official 573:ad23fe03a082 1168 /* Clear the WAKEUPTIMER interrupt pending bit */
mbed_official 573:ad23fe03a082 1169 __HAL_RTC_WAKEUPTIMER_CLEAR_FLAG(hrtc, RTC_FLAG_WUTF);
mbed_official 573:ad23fe03a082 1170 }
mbed_official 573:ad23fe03a082 1171 }
mbed_official 573:ad23fe03a082 1172
mbed_official 573:ad23fe03a082 1173 /* Clear the EXTI's line Flag for RTC WakeUpTimer */
mbed_official 573:ad23fe03a082 1174 __HAL_RTC_WAKEUPTIMER_EXTI_CLEAR_FLAG();
mbed_official 573:ad23fe03a082 1175
mbed_official 573:ad23fe03a082 1176 /* Change RTC state */
mbed_official 573:ad23fe03a082 1177 hrtc->State = HAL_RTC_STATE_READY;
mbed_official 573:ad23fe03a082 1178 }
mbed_official 573:ad23fe03a082 1179
mbed_official 573:ad23fe03a082 1180 /**
mbed_official 573:ad23fe03a082 1181 * @brief Wake Up Timer callback.
mbed_official 573:ad23fe03a082 1182 * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains
mbed_official 573:ad23fe03a082 1183 * the configuration information for RTC.
mbed_official 573:ad23fe03a082 1184 * @retval None
mbed_official 573:ad23fe03a082 1185 */
mbed_official 573:ad23fe03a082 1186 __weak void HAL_RTCEx_WakeUpTimerEventCallback(RTC_HandleTypeDef *hrtc)
mbed_official 573:ad23fe03a082 1187 {
mbed_official 573:ad23fe03a082 1188 /* NOTE : This function Should not be modified, when the callback is needed,
mbed_official 573:ad23fe03a082 1189 the HAL_RTC_WakeUpTimerEventCallback could be implemented in the user file
mbed_official 573:ad23fe03a082 1190 */
mbed_official 573:ad23fe03a082 1191 }
mbed_official 573:ad23fe03a082 1192
mbed_official 573:ad23fe03a082 1193 /**
mbed_official 573:ad23fe03a082 1194 * @brief This function handles Wake Up Timer Polling.
mbed_official 573:ad23fe03a082 1195 * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains
mbed_official 573:ad23fe03a082 1196 * the configuration information for RTC.
mbed_official 573:ad23fe03a082 1197 * @param Timeout: Timeout duration
mbed_official 573:ad23fe03a082 1198 * @retval HAL status
mbed_official 573:ad23fe03a082 1199 */
mbed_official 573:ad23fe03a082 1200 HAL_StatusTypeDef HAL_RTCEx_PollForWakeUpTimerEvent(RTC_HandleTypeDef *hrtc, uint32_t Timeout)
mbed_official 573:ad23fe03a082 1201 {
mbed_official 573:ad23fe03a082 1202 uint32_t tickstart = 0;
mbed_official 573:ad23fe03a082 1203
mbed_official 573:ad23fe03a082 1204 /* Get tick */
mbed_official 573:ad23fe03a082 1205 tickstart = HAL_GetTick();
mbed_official 573:ad23fe03a082 1206
mbed_official 573:ad23fe03a082 1207 while(__HAL_RTC_WAKEUPTIMER_GET_FLAG(hrtc, RTC_FLAG_WUTF) == RESET)
mbed_official 573:ad23fe03a082 1208 {
mbed_official 573:ad23fe03a082 1209 if(Timeout != HAL_MAX_DELAY)
mbed_official 573:ad23fe03a082 1210 {
mbed_official 573:ad23fe03a082 1211 if((Timeout == 0)||((HAL_GetTick() - tickstart ) > Timeout))
mbed_official 573:ad23fe03a082 1212 {
mbed_official 573:ad23fe03a082 1213 hrtc->State = HAL_RTC_STATE_TIMEOUT;
mbed_official 573:ad23fe03a082 1214
mbed_official 573:ad23fe03a082 1215 return HAL_TIMEOUT;
mbed_official 573:ad23fe03a082 1216 }
mbed_official 573:ad23fe03a082 1217 }
mbed_official 573:ad23fe03a082 1218 }
mbed_official 573:ad23fe03a082 1219
mbed_official 573:ad23fe03a082 1220 /* Clear the WAKEUPTIMER Flag */
mbed_official 573:ad23fe03a082 1221 __HAL_RTC_WAKEUPTIMER_CLEAR_FLAG(hrtc, RTC_FLAG_WUTF);
mbed_official 573:ad23fe03a082 1222
mbed_official 573:ad23fe03a082 1223 /* Change RTC state */
mbed_official 573:ad23fe03a082 1224 hrtc->State = HAL_RTC_STATE_READY;
mbed_official 573:ad23fe03a082 1225
mbed_official 573:ad23fe03a082 1226 return HAL_OK;
mbed_official 573:ad23fe03a082 1227 }
mbed_official 573:ad23fe03a082 1228
mbed_official 573:ad23fe03a082 1229 /**
mbed_official 573:ad23fe03a082 1230 * @}
mbed_official 573:ad23fe03a082 1231 */
mbed_official 573:ad23fe03a082 1232
mbed_official 573:ad23fe03a082 1233
mbed_official 573:ad23fe03a082 1234 /** @defgroup RTCEx_Group3 Extension Peripheral Control functions
mbed_official 573:ad23fe03a082 1235 * @brief Extension Peripheral Control functions
mbed_official 573:ad23fe03a082 1236 *
mbed_official 573:ad23fe03a082 1237 @verbatim
mbed_official 573:ad23fe03a082 1238 ===============================================================================
mbed_official 573:ad23fe03a082 1239 ##### Extension Peripheral Control functions #####
mbed_official 573:ad23fe03a082 1240 ===============================================================================
mbed_official 573:ad23fe03a082 1241 [..]
mbed_official 573:ad23fe03a082 1242 This subsection provides functions allowing to
mbed_official 573:ad23fe03a082 1243 (+) Write a data in a specified RTC Backup data register
mbed_official 573:ad23fe03a082 1244 (+) Read a data in a specified RTC Backup data register
mbed_official 573:ad23fe03a082 1245 (+) Set the Coarse calibration parameters.
mbed_official 573:ad23fe03a082 1246 (+) Deactivate the Coarse calibration parameters
mbed_official 573:ad23fe03a082 1247 (+) Set the Smooth calibration parameters.
mbed_official 573:ad23fe03a082 1248 (+) Configure the Synchronization Shift Control Settings.
mbed_official 573:ad23fe03a082 1249 (+) Configure the Calibration Pinout (RTC_CALIB) Selection (1Hz or 512Hz).
mbed_official 573:ad23fe03a082 1250 (+) Deactivate the Calibration Pinout (RTC_CALIB) Selection (1Hz or 512Hz).
mbed_official 573:ad23fe03a082 1251 (+) Enable the RTC reference clock detection.
mbed_official 573:ad23fe03a082 1252 (+) Disable the RTC reference clock detection.
mbed_official 573:ad23fe03a082 1253 (+) Enable the Bypass Shadow feature.
mbed_official 573:ad23fe03a082 1254 (+) Disable the Bypass Shadow feature.
mbed_official 573:ad23fe03a082 1255
mbed_official 573:ad23fe03a082 1256 @endverbatim
mbed_official 573:ad23fe03a082 1257 * @{
mbed_official 573:ad23fe03a082 1258 */
mbed_official 573:ad23fe03a082 1259
mbed_official 573:ad23fe03a082 1260 /**
mbed_official 573:ad23fe03a082 1261 * @brief Writes a data in a specified RTC Backup data register.
mbed_official 573:ad23fe03a082 1262 * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains
mbed_official 573:ad23fe03a082 1263 * the configuration information for RTC.
mbed_official 573:ad23fe03a082 1264 * @param BackupRegister: RTC Backup data Register number.
mbed_official 573:ad23fe03a082 1265 * This parameter can be: RTC_BKP_DRx where x can be from 0 to 19 to
mbed_official 573:ad23fe03a082 1266 * specify the register.
mbed_official 573:ad23fe03a082 1267 * @param Data: Data to be written in the specified RTC Backup data register.
mbed_official 573:ad23fe03a082 1268 * @retval None
mbed_official 573:ad23fe03a082 1269 */
mbed_official 573:ad23fe03a082 1270 void HAL_RTCEx_BKUPWrite(RTC_HandleTypeDef *hrtc, uint32_t BackupRegister, uint32_t Data)
mbed_official 573:ad23fe03a082 1271 {
mbed_official 573:ad23fe03a082 1272 uint32_t tmp = 0;
mbed_official 573:ad23fe03a082 1273
mbed_official 573:ad23fe03a082 1274 /* Check the parameters */
mbed_official 573:ad23fe03a082 1275 assert_param(IS_RTC_BKP(BackupRegister));
mbed_official 573:ad23fe03a082 1276
mbed_official 573:ad23fe03a082 1277 tmp = (uint32_t)&(hrtc->Instance->BKP0R);
mbed_official 573:ad23fe03a082 1278 tmp += (BackupRegister * 4);
mbed_official 573:ad23fe03a082 1279
mbed_official 573:ad23fe03a082 1280 /* Write the specified register */
mbed_official 573:ad23fe03a082 1281 *(__IO uint32_t *)tmp = (uint32_t)Data;
mbed_official 573:ad23fe03a082 1282 }
mbed_official 573:ad23fe03a082 1283
mbed_official 573:ad23fe03a082 1284 /**
mbed_official 573:ad23fe03a082 1285 * @brief Reads data from the specified RTC Backup data Register.
mbed_official 573:ad23fe03a082 1286 * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains
mbed_official 573:ad23fe03a082 1287 * the configuration information for RTC.
mbed_official 573:ad23fe03a082 1288 * @param BackupRegister: RTC Backup data Register number.
mbed_official 573:ad23fe03a082 1289 * This parameter can be: RTC_BKP_DRx where x can be from 0 to 19 to
mbed_official 573:ad23fe03a082 1290 * specify the register.
mbed_official 573:ad23fe03a082 1291 * @retval Read value
mbed_official 573:ad23fe03a082 1292 */
mbed_official 573:ad23fe03a082 1293 uint32_t HAL_RTCEx_BKUPRead(RTC_HandleTypeDef *hrtc, uint32_t BackupRegister)
mbed_official 573:ad23fe03a082 1294 {
mbed_official 573:ad23fe03a082 1295 uint32_t tmp = 0;
mbed_official 573:ad23fe03a082 1296
mbed_official 573:ad23fe03a082 1297 /* Check the parameters */
mbed_official 573:ad23fe03a082 1298 assert_param(IS_RTC_BKP(BackupRegister));
mbed_official 573:ad23fe03a082 1299
mbed_official 573:ad23fe03a082 1300 tmp = (uint32_t)&(hrtc->Instance->BKP0R);
mbed_official 573:ad23fe03a082 1301 tmp += (BackupRegister * 4);
mbed_official 573:ad23fe03a082 1302
mbed_official 573:ad23fe03a082 1303 /* Read the specified register */
mbed_official 573:ad23fe03a082 1304 return (*(__IO uint32_t *)tmp);
mbed_official 573:ad23fe03a082 1305 }
mbed_official 573:ad23fe03a082 1306
mbed_official 573:ad23fe03a082 1307 /**
mbed_official 573:ad23fe03a082 1308 * @brief Sets the Smooth calibration parameters.
mbed_official 573:ad23fe03a082 1309 * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains
mbed_official 573:ad23fe03a082 1310 * the configuration information for RTC.
mbed_official 573:ad23fe03a082 1311 * @param SmoothCalibPeriod: Select the Smooth Calibration Period.
mbed_official 573:ad23fe03a082 1312 * This parameter can be can be one of the following values :
mbed_official 573:ad23fe03a082 1313 * @arg RTC_SMOOTHCALIB_PERIOD_32SEC: The smooth calibration period is 32s.
mbed_official 573:ad23fe03a082 1314 * @arg RTC_SMOOTHCALIB_PERIOD_16SEC: The smooth calibration period is 16s.
mbed_official 573:ad23fe03a082 1315 * @arg RTC_SMOOTHCALIB_PERIOD_8SEC: The smooth calibration period is 8s.
mbed_official 573:ad23fe03a082 1316 * @param SmoothCalibPlusPulses: Select to Set or reset the CALP bit.
mbed_official 573:ad23fe03a082 1317 * This parameter can be one of the following values:
mbed_official 573:ad23fe03a082 1318 * @arg RTC_SMOOTHCALIB_PLUSPULSES_SET: Add one RTCCLK pulses every 2*11 pulses.
mbed_official 573:ad23fe03a082 1319 * @arg RTC_SMOOTHCALIB_PLUSPULSES_RESET: No RTCCLK pulses are added.
mbed_official 573:ad23fe03a082 1320 * @param SmouthCalibMinusPulsesValue: Select the value of CALM[8:0] bits.
mbed_official 573:ad23fe03a082 1321 * This parameter can be one any value from 0 to 0x000001FF.
mbed_official 573:ad23fe03a082 1322 * @note To deactivate the smooth calibration, the field SmoothCalibPlusPulses
mbed_official 573:ad23fe03a082 1323 * must be equal to SMOOTHCALIB_PLUSPULSES_RESET and the field
mbed_official 573:ad23fe03a082 1324 * SmouthCalibMinusPulsesValue must be equal to 0.
mbed_official 573:ad23fe03a082 1325 * @retval HAL status
mbed_official 573:ad23fe03a082 1326 */
mbed_official 573:ad23fe03a082 1327 HAL_StatusTypeDef HAL_RTCEx_SetSmoothCalib(RTC_HandleTypeDef* hrtc, uint32_t SmoothCalibPeriod, uint32_t SmoothCalibPlusPulses, uint32_t SmouthCalibMinusPulsesValue)
mbed_official 573:ad23fe03a082 1328 {
mbed_official 573:ad23fe03a082 1329 uint32_t tickstart = 0;
mbed_official 573:ad23fe03a082 1330
mbed_official 573:ad23fe03a082 1331 /* Check the parameters */
mbed_official 573:ad23fe03a082 1332 assert_param(IS_RTC_SMOOTH_CALIB_PERIOD(SmoothCalibPeriod));
mbed_official 573:ad23fe03a082 1333 assert_param(IS_RTC_SMOOTH_CALIB_PLUS(SmoothCalibPlusPulses));
mbed_official 573:ad23fe03a082 1334 assert_param(IS_RTC_SMOOTH_CALIB_MINUS(SmouthCalibMinusPulsesValue));
mbed_official 573:ad23fe03a082 1335
mbed_official 573:ad23fe03a082 1336 /* Process Locked */
mbed_official 573:ad23fe03a082 1337 __HAL_LOCK(hrtc);
mbed_official 573:ad23fe03a082 1338
mbed_official 573:ad23fe03a082 1339 hrtc->State = HAL_RTC_STATE_BUSY;
mbed_official 573:ad23fe03a082 1340
mbed_official 573:ad23fe03a082 1341 /* Disable the write protection for RTC registers */
mbed_official 573:ad23fe03a082 1342 __HAL_RTC_WRITEPROTECTION_DISABLE(hrtc);
mbed_official 573:ad23fe03a082 1343
mbed_official 573:ad23fe03a082 1344 /* check if a calibration is pending*/
mbed_official 573:ad23fe03a082 1345 if((hrtc->Instance->ISR & RTC_ISR_RECALPF) != RESET)
mbed_official 573:ad23fe03a082 1346 {
mbed_official 573:ad23fe03a082 1347 /* Get tick */
mbed_official 573:ad23fe03a082 1348 tickstart = HAL_GetTick();
mbed_official 573:ad23fe03a082 1349
mbed_official 573:ad23fe03a082 1350 /* check if a calibration is pending*/
mbed_official 573:ad23fe03a082 1351 while((hrtc->Instance->ISR & RTC_ISR_RECALPF) != RESET)
mbed_official 573:ad23fe03a082 1352 {
mbed_official 573:ad23fe03a082 1353 if((HAL_GetTick() - tickstart ) > RTC_TIMEOUT_VALUE)
mbed_official 573:ad23fe03a082 1354 {
mbed_official 573:ad23fe03a082 1355 /* Enable the write protection for RTC registers */
mbed_official 573:ad23fe03a082 1356 __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc);
mbed_official 573:ad23fe03a082 1357
mbed_official 573:ad23fe03a082 1358 /* Change RTC state */
mbed_official 573:ad23fe03a082 1359 hrtc->State = HAL_RTC_STATE_TIMEOUT;
mbed_official 573:ad23fe03a082 1360
mbed_official 573:ad23fe03a082 1361 /* Process Unlocked */
mbed_official 573:ad23fe03a082 1362 __HAL_UNLOCK(hrtc);
mbed_official 573:ad23fe03a082 1363
mbed_official 573:ad23fe03a082 1364 return HAL_TIMEOUT;
mbed_official 573:ad23fe03a082 1365 }
mbed_official 573:ad23fe03a082 1366 }
mbed_official 573:ad23fe03a082 1367 }
mbed_official 573:ad23fe03a082 1368
mbed_official 573:ad23fe03a082 1369 /* Configure the Smooth calibration settings */
mbed_official 573:ad23fe03a082 1370 hrtc->Instance->CALR = (uint32_t)((uint32_t)SmoothCalibPeriod | (uint32_t)SmoothCalibPlusPulses | (uint32_t)SmouthCalibMinusPulsesValue);
mbed_official 573:ad23fe03a082 1371
mbed_official 573:ad23fe03a082 1372 /* Enable the write protection for RTC registers */
mbed_official 573:ad23fe03a082 1373 __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc);
mbed_official 573:ad23fe03a082 1374
mbed_official 573:ad23fe03a082 1375 /* Change RTC state */
mbed_official 573:ad23fe03a082 1376 hrtc->State = HAL_RTC_STATE_READY;
mbed_official 573:ad23fe03a082 1377
mbed_official 573:ad23fe03a082 1378 /* Process Unlocked */
mbed_official 573:ad23fe03a082 1379 __HAL_UNLOCK(hrtc);
mbed_official 573:ad23fe03a082 1380
mbed_official 573:ad23fe03a082 1381 return HAL_OK;
mbed_official 573:ad23fe03a082 1382 }
mbed_official 573:ad23fe03a082 1383
mbed_official 573:ad23fe03a082 1384 /**
mbed_official 573:ad23fe03a082 1385 * @brief Configures the Synchronization Shift Control Settings.
mbed_official 573:ad23fe03a082 1386 * @note When REFCKON is set, firmware must not write to Shift control register.
mbed_official 573:ad23fe03a082 1387 * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains
mbed_official 573:ad23fe03a082 1388 * the configuration information for RTC.
mbed_official 573:ad23fe03a082 1389 * @param ShiftAdd1S: Select to add or not 1 second to the time calendar.
mbed_official 573:ad23fe03a082 1390 * This parameter can be one of the following values :
mbed_official 573:ad23fe03a082 1391 * @arg RTC_SHIFTADD1S_SET: Add one second to the clock calendar.
mbed_official 573:ad23fe03a082 1392 * @arg RTC_SHIFTADD1S_RESET: No effect.
mbed_official 573:ad23fe03a082 1393 * @param ShiftSubFS: Select the number of Second Fractions to substitute.
mbed_official 573:ad23fe03a082 1394 * This parameter can be one any value from 0 to 0x7FFF.
mbed_official 573:ad23fe03a082 1395 * @retval HAL status
mbed_official 573:ad23fe03a082 1396 */
mbed_official 573:ad23fe03a082 1397 HAL_StatusTypeDef HAL_RTCEx_SetSynchroShift(RTC_HandleTypeDef* hrtc, uint32_t ShiftAdd1S, uint32_t ShiftSubFS)
mbed_official 573:ad23fe03a082 1398 {
mbed_official 573:ad23fe03a082 1399 uint32_t tickstart = 0;
mbed_official 573:ad23fe03a082 1400
mbed_official 573:ad23fe03a082 1401 /* Check the parameters */
mbed_official 573:ad23fe03a082 1402 assert_param(IS_RTC_SHIFT_ADD1S(ShiftAdd1S));
mbed_official 573:ad23fe03a082 1403 assert_param(IS_RTC_SHIFT_SUBFS(ShiftSubFS));
mbed_official 573:ad23fe03a082 1404
mbed_official 573:ad23fe03a082 1405 /* Process Locked */
mbed_official 573:ad23fe03a082 1406 __HAL_LOCK(hrtc);
mbed_official 573:ad23fe03a082 1407
mbed_official 573:ad23fe03a082 1408 hrtc->State = HAL_RTC_STATE_BUSY;
mbed_official 573:ad23fe03a082 1409
mbed_official 573:ad23fe03a082 1410 /* Disable the write protection for RTC registers */
mbed_official 573:ad23fe03a082 1411 __HAL_RTC_WRITEPROTECTION_DISABLE(hrtc);
mbed_official 573:ad23fe03a082 1412
mbed_official 573:ad23fe03a082 1413 /* Get tick */
mbed_official 573:ad23fe03a082 1414 tickstart = HAL_GetTick();
mbed_official 573:ad23fe03a082 1415
mbed_official 573:ad23fe03a082 1416 /* Wait until the shift is completed*/
mbed_official 573:ad23fe03a082 1417 while((hrtc->Instance->ISR & RTC_ISR_SHPF) != RESET)
mbed_official 573:ad23fe03a082 1418 {
mbed_official 573:ad23fe03a082 1419 if((HAL_GetTick() - tickstart ) > RTC_TIMEOUT_VALUE)
mbed_official 573:ad23fe03a082 1420 {
mbed_official 573:ad23fe03a082 1421 /* Enable the write protection for RTC registers */
mbed_official 573:ad23fe03a082 1422 __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc);
mbed_official 573:ad23fe03a082 1423
mbed_official 573:ad23fe03a082 1424 hrtc->State = HAL_RTC_STATE_TIMEOUT;
mbed_official 573:ad23fe03a082 1425
mbed_official 573:ad23fe03a082 1426 /* Process Unlocked */
mbed_official 573:ad23fe03a082 1427 __HAL_UNLOCK(hrtc);
mbed_official 573:ad23fe03a082 1428
mbed_official 573:ad23fe03a082 1429 return HAL_TIMEOUT;
mbed_official 573:ad23fe03a082 1430 }
mbed_official 573:ad23fe03a082 1431 }
mbed_official 573:ad23fe03a082 1432
mbed_official 573:ad23fe03a082 1433 /* Check if the reference clock detection is disabled */
mbed_official 573:ad23fe03a082 1434 if((hrtc->Instance->CR & RTC_CR_REFCKON) == RESET)
mbed_official 573:ad23fe03a082 1435 {
mbed_official 573:ad23fe03a082 1436 /* Configure the Shift settings */
mbed_official 573:ad23fe03a082 1437 hrtc->Instance->SHIFTR = (uint32_t)(uint32_t)(ShiftSubFS) | (uint32_t)(ShiftAdd1S);
mbed_official 573:ad23fe03a082 1438
mbed_official 573:ad23fe03a082 1439 /* If RTC_CR_BYPSHAD bit = 0, wait for synchro else this check is not needed */
mbed_official 573:ad23fe03a082 1440 if((hrtc->Instance->CR & RTC_CR_BYPSHAD) == RESET)
mbed_official 573:ad23fe03a082 1441 {
mbed_official 573:ad23fe03a082 1442 if(HAL_RTC_WaitForSynchro(hrtc) != HAL_OK)
mbed_official 573:ad23fe03a082 1443 {
mbed_official 573:ad23fe03a082 1444 /* Enable the write protection for RTC registers */
mbed_official 573:ad23fe03a082 1445 __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc);
mbed_official 573:ad23fe03a082 1446
mbed_official 573:ad23fe03a082 1447 hrtc->State = HAL_RTC_STATE_ERROR;
mbed_official 573:ad23fe03a082 1448
mbed_official 573:ad23fe03a082 1449 /* Process Unlocked */
mbed_official 573:ad23fe03a082 1450 __HAL_UNLOCK(hrtc);
mbed_official 573:ad23fe03a082 1451
mbed_official 573:ad23fe03a082 1452 return HAL_ERROR;
mbed_official 573:ad23fe03a082 1453 }
mbed_official 573:ad23fe03a082 1454 }
mbed_official 573:ad23fe03a082 1455 }
mbed_official 573:ad23fe03a082 1456 else
mbed_official 573:ad23fe03a082 1457 {
mbed_official 573:ad23fe03a082 1458 /* Enable the write protection for RTC registers */
mbed_official 573:ad23fe03a082 1459 __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc);
mbed_official 573:ad23fe03a082 1460
mbed_official 573:ad23fe03a082 1461 /* Change RTC state */
mbed_official 573:ad23fe03a082 1462 hrtc->State = HAL_RTC_STATE_ERROR;
mbed_official 573:ad23fe03a082 1463
mbed_official 573:ad23fe03a082 1464 /* Process Unlocked */
mbed_official 573:ad23fe03a082 1465 __HAL_UNLOCK(hrtc);
mbed_official 573:ad23fe03a082 1466
mbed_official 573:ad23fe03a082 1467 return HAL_ERROR;
mbed_official 573:ad23fe03a082 1468 }
mbed_official 573:ad23fe03a082 1469
mbed_official 573:ad23fe03a082 1470 /* Enable the write protection for RTC registers */
mbed_official 573:ad23fe03a082 1471 __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc);
mbed_official 573:ad23fe03a082 1472
mbed_official 573:ad23fe03a082 1473 /* Change RTC state */
mbed_official 573:ad23fe03a082 1474 hrtc->State = HAL_RTC_STATE_READY;
mbed_official 573:ad23fe03a082 1475
mbed_official 573:ad23fe03a082 1476 /* Process Unlocked */
mbed_official 573:ad23fe03a082 1477 __HAL_UNLOCK(hrtc);
mbed_official 573:ad23fe03a082 1478
mbed_official 573:ad23fe03a082 1479 return HAL_OK;
mbed_official 573:ad23fe03a082 1480 }
mbed_official 573:ad23fe03a082 1481
mbed_official 573:ad23fe03a082 1482 /**
mbed_official 573:ad23fe03a082 1483 * @brief Configures the Calibration Pinout (RTC_CALIB) Selection (1Hz or 512Hz).
mbed_official 573:ad23fe03a082 1484 * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains
mbed_official 573:ad23fe03a082 1485 * the configuration information for RTC.
mbed_official 573:ad23fe03a082 1486 * @param CalibOutput: Select the Calibration output Selection .
mbed_official 573:ad23fe03a082 1487 * This parameter can be one of the following values:
mbed_official 573:ad23fe03a082 1488 * @arg RTC_CALIBOUTPUT_512HZ: A signal has a regular waveform at 512Hz.
mbed_official 573:ad23fe03a082 1489 * @arg RTC_CALIBOUTPUT_1HZ: A signal has a regular waveform at 1Hz.
mbed_official 573:ad23fe03a082 1490 * @retval HAL status
mbed_official 573:ad23fe03a082 1491 */
mbed_official 573:ad23fe03a082 1492 HAL_StatusTypeDef HAL_RTCEx_SetCalibrationOutPut(RTC_HandleTypeDef* hrtc, uint32_t CalibOutput)
mbed_official 573:ad23fe03a082 1493 {
mbed_official 573:ad23fe03a082 1494 /* Check the parameters */
mbed_official 573:ad23fe03a082 1495 assert_param(IS_RTC_CALIB_OUTPUT(CalibOutput));
mbed_official 573:ad23fe03a082 1496
mbed_official 573:ad23fe03a082 1497 /* Process Locked */
mbed_official 573:ad23fe03a082 1498 __HAL_LOCK(hrtc);
mbed_official 573:ad23fe03a082 1499
mbed_official 573:ad23fe03a082 1500 hrtc->State = HAL_RTC_STATE_BUSY;
mbed_official 573:ad23fe03a082 1501
mbed_official 573:ad23fe03a082 1502 /* Disable the write protection for RTC registers */
mbed_official 573:ad23fe03a082 1503 __HAL_RTC_WRITEPROTECTION_DISABLE(hrtc);
mbed_official 573:ad23fe03a082 1504
mbed_official 573:ad23fe03a082 1505 /* Clear flags before config */
mbed_official 573:ad23fe03a082 1506 hrtc->Instance->CR &= (uint32_t)~RTC_CR_COSEL;
mbed_official 573:ad23fe03a082 1507
mbed_official 573:ad23fe03a082 1508 /* Configure the RTC_CR register */
mbed_official 573:ad23fe03a082 1509 hrtc->Instance->CR |= (uint32_t)CalibOutput;
mbed_official 573:ad23fe03a082 1510
mbed_official 573:ad23fe03a082 1511 __HAL_RTC_CALIBRATION_OUTPUT_ENABLE(hrtc);
mbed_official 573:ad23fe03a082 1512
mbed_official 573:ad23fe03a082 1513 /* Enable the write protection for RTC registers */
mbed_official 573:ad23fe03a082 1514 __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc);
mbed_official 573:ad23fe03a082 1515
mbed_official 573:ad23fe03a082 1516 /* Change RTC state */
mbed_official 573:ad23fe03a082 1517 hrtc->State = HAL_RTC_STATE_READY;
mbed_official 573:ad23fe03a082 1518
mbed_official 573:ad23fe03a082 1519 /* Process Unlocked */
mbed_official 573:ad23fe03a082 1520 __HAL_UNLOCK(hrtc);
mbed_official 573:ad23fe03a082 1521
mbed_official 573:ad23fe03a082 1522 return HAL_OK;
mbed_official 573:ad23fe03a082 1523 }
mbed_official 573:ad23fe03a082 1524
mbed_official 573:ad23fe03a082 1525 /**
mbed_official 573:ad23fe03a082 1526 * @brief Deactivates the Calibration Pinout (RTC_CALIB) Selection (1Hz or 512Hz).
mbed_official 573:ad23fe03a082 1527 * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains
mbed_official 573:ad23fe03a082 1528 * the configuration information for RTC.
mbed_official 573:ad23fe03a082 1529 * @retval HAL status
mbed_official 573:ad23fe03a082 1530 */
mbed_official 573:ad23fe03a082 1531 HAL_StatusTypeDef HAL_RTCEx_DeactivateCalibrationOutPut(RTC_HandleTypeDef* hrtc)
mbed_official 573:ad23fe03a082 1532 {
mbed_official 573:ad23fe03a082 1533 /* Process Locked */
mbed_official 573:ad23fe03a082 1534 __HAL_LOCK(hrtc);
mbed_official 573:ad23fe03a082 1535
mbed_official 573:ad23fe03a082 1536 hrtc->State = HAL_RTC_STATE_BUSY;
mbed_official 573:ad23fe03a082 1537
mbed_official 573:ad23fe03a082 1538 /* Disable the write protection for RTC registers */
mbed_official 573:ad23fe03a082 1539 __HAL_RTC_WRITEPROTECTION_DISABLE(hrtc);
mbed_official 573:ad23fe03a082 1540
mbed_official 573:ad23fe03a082 1541 __HAL_RTC_CALIBRATION_OUTPUT_DISABLE(hrtc);
mbed_official 573:ad23fe03a082 1542
mbed_official 573:ad23fe03a082 1543 /* Enable the write protection for RTC registers */
mbed_official 573:ad23fe03a082 1544 __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc);
mbed_official 573:ad23fe03a082 1545
mbed_official 573:ad23fe03a082 1546 /* Change RTC state */
mbed_official 573:ad23fe03a082 1547 hrtc->State = HAL_RTC_STATE_READY;
mbed_official 573:ad23fe03a082 1548
mbed_official 573:ad23fe03a082 1549 /* Process Unlocked */
mbed_official 573:ad23fe03a082 1550 __HAL_UNLOCK(hrtc);
mbed_official 573:ad23fe03a082 1551
mbed_official 573:ad23fe03a082 1552 return HAL_OK;
mbed_official 573:ad23fe03a082 1553 }
mbed_official 573:ad23fe03a082 1554
mbed_official 573:ad23fe03a082 1555 /**
mbed_official 573:ad23fe03a082 1556 * @brief Enables the RTC reference clock detection.
mbed_official 573:ad23fe03a082 1557 * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains
mbed_official 573:ad23fe03a082 1558 * the configuration information for RTC.
mbed_official 573:ad23fe03a082 1559 * @retval HAL status
mbed_official 573:ad23fe03a082 1560 */
mbed_official 573:ad23fe03a082 1561 HAL_StatusTypeDef HAL_RTCEx_SetRefClock(RTC_HandleTypeDef* hrtc)
mbed_official 573:ad23fe03a082 1562 {
mbed_official 573:ad23fe03a082 1563 /* Process Locked */
mbed_official 573:ad23fe03a082 1564 __HAL_LOCK(hrtc);
mbed_official 573:ad23fe03a082 1565
mbed_official 573:ad23fe03a082 1566 hrtc->State = HAL_RTC_STATE_BUSY;
mbed_official 573:ad23fe03a082 1567
mbed_official 573:ad23fe03a082 1568 /* Disable the write protection for RTC registers */
mbed_official 573:ad23fe03a082 1569 __HAL_RTC_WRITEPROTECTION_DISABLE(hrtc);
mbed_official 573:ad23fe03a082 1570
mbed_official 573:ad23fe03a082 1571 /* Set Initialization mode */
mbed_official 573:ad23fe03a082 1572 if(RTC_EnterInitMode(hrtc) != HAL_OK)
mbed_official 573:ad23fe03a082 1573 {
mbed_official 573:ad23fe03a082 1574 /* Enable the write protection for RTC registers */
mbed_official 573:ad23fe03a082 1575 __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc);
mbed_official 573:ad23fe03a082 1576
mbed_official 573:ad23fe03a082 1577 /* Set RTC state*/
mbed_official 573:ad23fe03a082 1578 hrtc->State = HAL_RTC_STATE_ERROR;
mbed_official 573:ad23fe03a082 1579
mbed_official 573:ad23fe03a082 1580 /* Process Unlocked */
mbed_official 573:ad23fe03a082 1581 __HAL_UNLOCK(hrtc);
mbed_official 573:ad23fe03a082 1582
mbed_official 573:ad23fe03a082 1583 return HAL_ERROR;
mbed_official 573:ad23fe03a082 1584 }
mbed_official 573:ad23fe03a082 1585 else
mbed_official 573:ad23fe03a082 1586 {
mbed_official 573:ad23fe03a082 1587 __HAL_RTC_CLOCKREF_DETECTION_ENABLE(hrtc);
mbed_official 573:ad23fe03a082 1588
mbed_official 573:ad23fe03a082 1589 /* Exit Initialization mode */
mbed_official 573:ad23fe03a082 1590 hrtc->Instance->ISR &= (uint32_t)~RTC_ISR_INIT;
mbed_official 573:ad23fe03a082 1591 }
mbed_official 573:ad23fe03a082 1592
mbed_official 573:ad23fe03a082 1593 /* Enable the write protection for RTC registers */
mbed_official 573:ad23fe03a082 1594 __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc);
mbed_official 573:ad23fe03a082 1595
mbed_official 573:ad23fe03a082 1596 /* Change RTC state */
mbed_official 573:ad23fe03a082 1597 hrtc->State = HAL_RTC_STATE_READY;
mbed_official 573:ad23fe03a082 1598
mbed_official 573:ad23fe03a082 1599 /* Process Unlocked */
mbed_official 573:ad23fe03a082 1600 __HAL_UNLOCK(hrtc);
mbed_official 573:ad23fe03a082 1601
mbed_official 573:ad23fe03a082 1602 return HAL_OK;
mbed_official 573:ad23fe03a082 1603 }
mbed_official 573:ad23fe03a082 1604
mbed_official 573:ad23fe03a082 1605 /**
mbed_official 573:ad23fe03a082 1606 * @brief Disable the RTC reference clock detection.
mbed_official 573:ad23fe03a082 1607 * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains
mbed_official 573:ad23fe03a082 1608 * the configuration information for RTC.
mbed_official 573:ad23fe03a082 1609 * @retval HAL status
mbed_official 573:ad23fe03a082 1610 */
mbed_official 573:ad23fe03a082 1611 HAL_StatusTypeDef HAL_RTCEx_DeactivateRefClock(RTC_HandleTypeDef* hrtc)
mbed_official 573:ad23fe03a082 1612 {
mbed_official 573:ad23fe03a082 1613 /* Process Locked */
mbed_official 573:ad23fe03a082 1614 __HAL_LOCK(hrtc);
mbed_official 573:ad23fe03a082 1615
mbed_official 573:ad23fe03a082 1616 hrtc->State = HAL_RTC_STATE_BUSY;
mbed_official 573:ad23fe03a082 1617
mbed_official 573:ad23fe03a082 1618 /* Disable the write protection for RTC registers */
mbed_official 573:ad23fe03a082 1619 __HAL_RTC_WRITEPROTECTION_DISABLE(hrtc);
mbed_official 573:ad23fe03a082 1620
mbed_official 573:ad23fe03a082 1621 /* Set Initialization mode */
mbed_official 573:ad23fe03a082 1622 if(RTC_EnterInitMode(hrtc) != HAL_OK)
mbed_official 573:ad23fe03a082 1623 {
mbed_official 573:ad23fe03a082 1624 /* Enable the write protection for RTC registers */
mbed_official 573:ad23fe03a082 1625 __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc);
mbed_official 573:ad23fe03a082 1626
mbed_official 573:ad23fe03a082 1627 /* Set RTC state*/
mbed_official 573:ad23fe03a082 1628 hrtc->State = HAL_RTC_STATE_ERROR;
mbed_official 573:ad23fe03a082 1629
mbed_official 573:ad23fe03a082 1630 /* Process Unlocked */
mbed_official 573:ad23fe03a082 1631 __HAL_UNLOCK(hrtc);
mbed_official 573:ad23fe03a082 1632
mbed_official 573:ad23fe03a082 1633 return HAL_ERROR;
mbed_official 573:ad23fe03a082 1634 }
mbed_official 573:ad23fe03a082 1635 else
mbed_official 573:ad23fe03a082 1636 {
mbed_official 573:ad23fe03a082 1637 __HAL_RTC_CLOCKREF_DETECTION_DISABLE(hrtc);
mbed_official 573:ad23fe03a082 1638
mbed_official 573:ad23fe03a082 1639 /* Exit Initialization mode */
mbed_official 573:ad23fe03a082 1640 hrtc->Instance->ISR &= (uint32_t)~RTC_ISR_INIT;
mbed_official 573:ad23fe03a082 1641 }
mbed_official 573:ad23fe03a082 1642
mbed_official 573:ad23fe03a082 1643 /* Enable the write protection for RTC registers */
mbed_official 573:ad23fe03a082 1644 __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc);
mbed_official 573:ad23fe03a082 1645
mbed_official 573:ad23fe03a082 1646 /* Change RTC state */
mbed_official 573:ad23fe03a082 1647 hrtc->State = HAL_RTC_STATE_READY;
mbed_official 573:ad23fe03a082 1648
mbed_official 573:ad23fe03a082 1649 /* Process Unlocked */
mbed_official 573:ad23fe03a082 1650 __HAL_UNLOCK(hrtc);
mbed_official 573:ad23fe03a082 1651
mbed_official 573:ad23fe03a082 1652 return HAL_OK;
mbed_official 573:ad23fe03a082 1653 }
mbed_official 573:ad23fe03a082 1654
mbed_official 573:ad23fe03a082 1655 /**
mbed_official 573:ad23fe03a082 1656 * @brief Enables the Bypass Shadow feature.
mbed_official 573:ad23fe03a082 1657 * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains
mbed_official 573:ad23fe03a082 1658 * the configuration information for RTC.
mbed_official 573:ad23fe03a082 1659 * @note When the Bypass Shadow is enabled the calendar value are taken
mbed_official 573:ad23fe03a082 1660 * directly from the Calendar counter.
mbed_official 573:ad23fe03a082 1661 * @retval HAL status
mbed_official 573:ad23fe03a082 1662 */
mbed_official 573:ad23fe03a082 1663 HAL_StatusTypeDef HAL_RTCEx_EnableBypassShadow(RTC_HandleTypeDef* hrtc)
mbed_official 573:ad23fe03a082 1664 {
mbed_official 573:ad23fe03a082 1665 /* Process Locked */
mbed_official 573:ad23fe03a082 1666 __HAL_LOCK(hrtc);
mbed_official 573:ad23fe03a082 1667
mbed_official 573:ad23fe03a082 1668 hrtc->State = HAL_RTC_STATE_BUSY;
mbed_official 573:ad23fe03a082 1669
mbed_official 573:ad23fe03a082 1670 /* Disable the write protection for RTC registers */
mbed_official 573:ad23fe03a082 1671 __HAL_RTC_WRITEPROTECTION_DISABLE(hrtc);
mbed_official 573:ad23fe03a082 1672
mbed_official 573:ad23fe03a082 1673 /* Set the BYPSHAD bit */
mbed_official 573:ad23fe03a082 1674 hrtc->Instance->CR |= (uint8_t)RTC_CR_BYPSHAD;
mbed_official 573:ad23fe03a082 1675
mbed_official 573:ad23fe03a082 1676 /* Enable the write protection for RTC registers */
mbed_official 573:ad23fe03a082 1677 __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc);
mbed_official 573:ad23fe03a082 1678
mbed_official 573:ad23fe03a082 1679 /* Change RTC state */
mbed_official 573:ad23fe03a082 1680 hrtc->State = HAL_RTC_STATE_READY;
mbed_official 573:ad23fe03a082 1681
mbed_official 573:ad23fe03a082 1682 /* Process Unlocked */
mbed_official 573:ad23fe03a082 1683 __HAL_UNLOCK(hrtc);
mbed_official 573:ad23fe03a082 1684
mbed_official 573:ad23fe03a082 1685 return HAL_OK;
mbed_official 573:ad23fe03a082 1686 }
mbed_official 573:ad23fe03a082 1687
mbed_official 573:ad23fe03a082 1688 /**
mbed_official 573:ad23fe03a082 1689 * @brief Disables the Bypass Shadow feature.
mbed_official 573:ad23fe03a082 1690 * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains
mbed_official 573:ad23fe03a082 1691 * the configuration information for RTC.
mbed_official 573:ad23fe03a082 1692 * @note When the Bypass Shadow is enabled the calendar value are taken
mbed_official 573:ad23fe03a082 1693 * directly from the Calendar counter.
mbed_official 573:ad23fe03a082 1694 * @retval HAL status
mbed_official 573:ad23fe03a082 1695 */
mbed_official 573:ad23fe03a082 1696 HAL_StatusTypeDef HAL_RTCEx_DisableBypassShadow(RTC_HandleTypeDef* hrtc)
mbed_official 573:ad23fe03a082 1697 {
mbed_official 573:ad23fe03a082 1698 /* Process Locked */
mbed_official 573:ad23fe03a082 1699 __HAL_LOCK(hrtc);
mbed_official 573:ad23fe03a082 1700
mbed_official 573:ad23fe03a082 1701 hrtc->State = HAL_RTC_STATE_BUSY;
mbed_official 573:ad23fe03a082 1702
mbed_official 573:ad23fe03a082 1703 /* Disable the write protection for RTC registers */
mbed_official 573:ad23fe03a082 1704 __HAL_RTC_WRITEPROTECTION_DISABLE(hrtc);
mbed_official 573:ad23fe03a082 1705
mbed_official 573:ad23fe03a082 1706 /* Reset the BYPSHAD bit */
mbed_official 573:ad23fe03a082 1707 hrtc->Instance->CR &= (uint8_t)~RTC_CR_BYPSHAD;
mbed_official 573:ad23fe03a082 1708
mbed_official 573:ad23fe03a082 1709 /* Enable the write protection for RTC registers */
mbed_official 573:ad23fe03a082 1710 __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc);
mbed_official 573:ad23fe03a082 1711
mbed_official 573:ad23fe03a082 1712 /* Change RTC state */
mbed_official 573:ad23fe03a082 1713 hrtc->State = HAL_RTC_STATE_READY;
mbed_official 573:ad23fe03a082 1714
mbed_official 573:ad23fe03a082 1715 /* Process Unlocked */
mbed_official 573:ad23fe03a082 1716 __HAL_UNLOCK(hrtc);
mbed_official 573:ad23fe03a082 1717
mbed_official 573:ad23fe03a082 1718 return HAL_OK;
mbed_official 573:ad23fe03a082 1719 }
mbed_official 573:ad23fe03a082 1720
mbed_official 573:ad23fe03a082 1721 /**
mbed_official 573:ad23fe03a082 1722 * @}
mbed_official 573:ad23fe03a082 1723 */
mbed_official 573:ad23fe03a082 1724
mbed_official 573:ad23fe03a082 1725 /** @defgroup RTCEx_Group4 Extended features functions
mbed_official 573:ad23fe03a082 1726 * @brief Extended features functions
mbed_official 573:ad23fe03a082 1727 *
mbed_official 573:ad23fe03a082 1728 @verbatim
mbed_official 573:ad23fe03a082 1729 ===============================================================================
mbed_official 573:ad23fe03a082 1730 ##### Extended features functions #####
mbed_official 573:ad23fe03a082 1731 ===============================================================================
mbed_official 573:ad23fe03a082 1732 [..] This section provides functions allowing to:
mbed_official 573:ad23fe03a082 1733 (+) RTC Alram B callback
mbed_official 573:ad23fe03a082 1734 (+) RTC Poll for Alarm B request
mbed_official 573:ad23fe03a082 1735
mbed_official 573:ad23fe03a082 1736 @endverbatim
mbed_official 573:ad23fe03a082 1737 * @{
mbed_official 573:ad23fe03a082 1738 */
mbed_official 573:ad23fe03a082 1739
mbed_official 573:ad23fe03a082 1740 /**
mbed_official 573:ad23fe03a082 1741 * @brief Alarm B callback.
mbed_official 573:ad23fe03a082 1742 * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains
mbed_official 573:ad23fe03a082 1743 * the configuration information for RTC.
mbed_official 573:ad23fe03a082 1744 * @retval None
mbed_official 573:ad23fe03a082 1745 */
mbed_official 573:ad23fe03a082 1746 __weak void HAL_RTCEx_AlarmBEventCallback(RTC_HandleTypeDef *hrtc)
mbed_official 573:ad23fe03a082 1747 {
mbed_official 573:ad23fe03a082 1748 /* NOTE : This function Should not be modified, when the callback is needed,
mbed_official 573:ad23fe03a082 1749 the HAL_RTC_AlarmBEventCallback could be implemented in the user file
mbed_official 573:ad23fe03a082 1750 */
mbed_official 573:ad23fe03a082 1751 }
mbed_official 573:ad23fe03a082 1752
mbed_official 573:ad23fe03a082 1753 /**
mbed_official 573:ad23fe03a082 1754 * @brief This function handles AlarmB Polling request.
mbed_official 573:ad23fe03a082 1755 * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains
mbed_official 573:ad23fe03a082 1756 * the configuration information for RTC.
mbed_official 573:ad23fe03a082 1757 * @param Timeout: Timeout duration
mbed_official 573:ad23fe03a082 1758 * @retval HAL status
mbed_official 573:ad23fe03a082 1759 */
mbed_official 573:ad23fe03a082 1760 HAL_StatusTypeDef HAL_RTCEx_PollForAlarmBEvent(RTC_HandleTypeDef *hrtc, uint32_t Timeout)
mbed_official 573:ad23fe03a082 1761 {
mbed_official 573:ad23fe03a082 1762 uint32_t tickstart = 0;
mbed_official 573:ad23fe03a082 1763
mbed_official 573:ad23fe03a082 1764 /* Get tick */
mbed_official 573:ad23fe03a082 1765 tickstart = HAL_GetTick();
mbed_official 573:ad23fe03a082 1766
mbed_official 573:ad23fe03a082 1767 while(__HAL_RTC_ALARM_GET_FLAG(hrtc, RTC_FLAG_ALRBF) == RESET)
mbed_official 573:ad23fe03a082 1768 {
mbed_official 573:ad23fe03a082 1769 if(Timeout != HAL_MAX_DELAY)
mbed_official 573:ad23fe03a082 1770 {
mbed_official 573:ad23fe03a082 1771 if((Timeout == 0)||((HAL_GetTick() - tickstart ) > Timeout))
mbed_official 573:ad23fe03a082 1772 {
mbed_official 573:ad23fe03a082 1773 hrtc->State = HAL_RTC_STATE_TIMEOUT;
mbed_official 573:ad23fe03a082 1774 return HAL_TIMEOUT;
mbed_official 573:ad23fe03a082 1775 }
mbed_official 573:ad23fe03a082 1776 }
mbed_official 573:ad23fe03a082 1777 }
mbed_official 573:ad23fe03a082 1778
mbed_official 573:ad23fe03a082 1779 /* Clear the Alarm Flag */
mbed_official 573:ad23fe03a082 1780 __HAL_RTC_ALARM_CLEAR_FLAG(hrtc, RTC_FLAG_ALRBF);
mbed_official 573:ad23fe03a082 1781
mbed_official 573:ad23fe03a082 1782 /* Change RTC state */
mbed_official 573:ad23fe03a082 1783 hrtc->State = HAL_RTC_STATE_READY;
mbed_official 573:ad23fe03a082 1784
mbed_official 573:ad23fe03a082 1785 return HAL_OK;
mbed_official 573:ad23fe03a082 1786 }
mbed_official 573:ad23fe03a082 1787
mbed_official 573:ad23fe03a082 1788 /**
mbed_official 573:ad23fe03a082 1789 * @}
mbed_official 573:ad23fe03a082 1790 */
mbed_official 573:ad23fe03a082 1791
mbed_official 573:ad23fe03a082 1792 /**
mbed_official 573:ad23fe03a082 1793 * @}
mbed_official 573:ad23fe03a082 1794 */
mbed_official 573:ad23fe03a082 1795
mbed_official 573:ad23fe03a082 1796 #endif /* HAL_RTC_MODULE_ENABLED */
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
mbed_official 573:ad23fe03a082 1805 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/