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:
Mon Sep 28 10:45:10 2015 +0100
Revision:
630:825f75ca301e
Parent:
441:d2c15dda23c1
Synchronized with git revision 54fbe4144faf309c37205a5d39fa665daa919f10

Full URL: https://github.com/mbedmicro/mbed/commit/54fbe4144faf309c37205a5d39fa665daa919f10/

NUCLEO_F031K6 : Add new target

Who changed what in which revision?

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