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:
Thu Aug 20 10:45:13 2015 +0100
Revision:
613:bc40b8d2aec4
Parent:
532:fe11edbda85c
Synchronized with git revision 92ca8c7b60a283b6bb60eb65b183dac1599f0ade

Full URL: https://github.com/mbedmicro/mbed/commit/92ca8c7b60a283b6bb60eb65b183dac1599f0ade/

Nordic: update application start address in GCC linker script

Who changed what in which revision?

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