mbed library sources

Fork of mbed-src by mbed official

Committer:
moirans2
Date:
Wed Jan 14 20:53:08 2015 +0000
Revision:
445:9a3ffe6cfa19
Parent:
441:d2c15dda23c1
internal clock stm32L051

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 441:d2c15dda23c1 5 * @version V1.2.0
mbed_official 441:d2c15dda23c1 6 * @date 11-December-2014
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 340:28d1f895c6fe 9 * functionalities of the Real Time Clock (RTC) Extension peripheral:
mbed_official 441:d2c15dda23c1 10 * + RTC TimeStamp functions
mbed_official 441:d2c15dda23c1 11 * + RTC Tamper functions
mbed_official 441:d2c15dda23c1 12 * + RTC Wake-up functions
mbed_official 340:28d1f895c6fe 13 * + Extension Control functions
mbed_official 340:28d1f895c6fe 14 * + Extension 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 340:28d1f895c6fe 21 (+) Enable the RTC domain access (see description in the section above).
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 441:d2c15dda23c1 28 (+) To configure the RTC Wake-up Clock source and Counter use the HAL_RTCEx_SetWakeUpTimer()
mbed_official 441:d2c15dda23c1 29 function. You can also configure the RTC Wake-up timer in interrupt mode
mbed_official 340:28d1f895c6fe 30 using the HAL_RTCEx_SetWakeUpTimer_IT() function.
mbed_official 441:d2c15dda23c1 31 (+) To read the RTC Wake-up Counter register, use the HAL_RTCEx_GetWakeUpTimer()
mbed_official 340:28d1f895c6fe 32 function.
mbed_official 441:d2c15dda23c1 33 (@) Not available on F030x6/x8/xC and F070x6/xB
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 441:d2c15dda23c1 60 (@) Not available on F030x6/x8/xC and F070x6/xB
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 340:28d1f895c6fe 67 * <h2><center>&copy; COPYRIGHT(c) 2014 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 340:28d1f895c6fe 101 /** @defgroup RTCEx RTCEx Extended HAL module driver
mbed_official 340:28d1f895c6fe 102 * @brief RTCEx Extended HAL module driver
mbed_official 340:28d1f895c6fe 103 * @{
mbed_official 340:28d1f895c6fe 104 */
mbed_official 340:28d1f895c6fe 105
mbed_official 340:28d1f895c6fe 106 #ifdef HAL_RTC_MODULE_ENABLED
mbed_official 340:28d1f895c6fe 107
mbed_official 340:28d1f895c6fe 108 /* Private typedef -----------------------------------------------------------*/
mbed_official 340:28d1f895c6fe 109 /* Private define ------------------------------------------------------------*/
mbed_official 340:28d1f895c6fe 110 /* Private macro -------------------------------------------------------------*/
mbed_official 340:28d1f895c6fe 111 /* Private variables ---------------------------------------------------------*/
mbed_official 340:28d1f895c6fe 112 /* Private function prototypes -----------------------------------------------*/
mbed_official 340:28d1f895c6fe 113 /* Exported functions ---------------------------------------------------------*/
mbed_official 340:28d1f895c6fe 114
mbed_official 340:28d1f895c6fe 115 /** @defgroup RTCEx_Exported_Functions RTCEx Exported Functions
mbed_official 340:28d1f895c6fe 116 * @{
mbed_official 340:28d1f895c6fe 117 */
mbed_official 340:28d1f895c6fe 118
mbed_official 340:28d1f895c6fe 119 /** @defgroup RTCEx_Exported_Functions_Group1 RTC TimeStamp and Tamper functions
mbed_official 340:28d1f895c6fe 120 * @brief RTC TimeStamp and Tamper functions
mbed_official 340:28d1f895c6fe 121 *
mbed_official 340:28d1f895c6fe 122 @verbatim
mbed_official 340:28d1f895c6fe 123 ===============================================================================
mbed_official 340:28d1f895c6fe 124 ##### RTC TimeStamp and Tamper functions #####
mbed_official 340:28d1f895c6fe 125 ===============================================================================
mbed_official 340:28d1f895c6fe 126
mbed_official 441:d2c15dda23c1 127 [..] This section provides functions allowing to configure TimeStamp feature
mbed_official 340:28d1f895c6fe 128
mbed_official 340:28d1f895c6fe 129 @endverbatim
mbed_official 340:28d1f895c6fe 130 * @{
mbed_official 340:28d1f895c6fe 131 */
mbed_official 340:28d1f895c6fe 132
mbed_official 340:28d1f895c6fe 133 /**
mbed_official 340:28d1f895c6fe 134 * @brief Sets TimeStamp.
mbed_official 340:28d1f895c6fe 135 * @note This API must be called before enabling the TimeStamp feature.
mbed_official 441:d2c15dda23c1 136 * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains
mbed_official 441:d2c15dda23c1 137 * the configuration information for RTC.
mbed_official 340:28d1f895c6fe 138 * @param TimeStampEdge: Specifies the pin edge on which the TimeStamp is
mbed_official 340:28d1f895c6fe 139 * activated.
mbed_official 441:d2c15dda23c1 140 * This parameter can be one of the following values:
mbed_official 441:d2c15dda23c1 141 * @arg RTC_TIMESTAMPEDGE_RISING: the Time stamp event occurs on the
mbed_official 340:28d1f895c6fe 142 * rising edge of the related pin.
mbed_official 441:d2c15dda23c1 143 * @arg RTC_TIMESTAMPEDGE_FALLING: the Time stamp event occurs on the
mbed_official 340:28d1f895c6fe 144 * falling edge of the related pin.
mbed_official 340:28d1f895c6fe 145 * @param RTC_TimeStampPin: specifies the RTC TimeStamp Pin.
mbed_official 340:28d1f895c6fe 146 * This parameter can be one of the following values:
mbed_official 340:28d1f895c6fe 147 * @arg RTC_TIMESTAMPPIN_PC13: PC13 is selected as RTC TimeStamp Pin.
mbed_official 340:28d1f895c6fe 148 * @retval HAL status
mbed_official 340:28d1f895c6fe 149 */
mbed_official 340:28d1f895c6fe 150 HAL_StatusTypeDef HAL_RTCEx_SetTimeStamp(RTC_HandleTypeDef *hrtc, uint32_t TimeStampEdge, uint32_t RTC_TimeStampPin)
mbed_official 340:28d1f895c6fe 151 {
mbed_official 340:28d1f895c6fe 152 uint32_t tmpreg = 0;
mbed_official 340:28d1f895c6fe 153
mbed_official 340:28d1f895c6fe 154 /* Check the parameters */
mbed_official 340:28d1f895c6fe 155 assert_param(IS_TIMESTAMP_EDGE(TimeStampEdge));
mbed_official 340:28d1f895c6fe 156 assert_param(IS_RTC_TIMESTAMP_PIN(RTC_TimeStampPin));
mbed_official 340:28d1f895c6fe 157
mbed_official 340:28d1f895c6fe 158 /* Process Locked */
mbed_official 340:28d1f895c6fe 159 __HAL_LOCK(hrtc);
mbed_official 340:28d1f895c6fe 160
mbed_official 340:28d1f895c6fe 161 hrtc->State = HAL_RTC_STATE_BUSY;
mbed_official 340:28d1f895c6fe 162
mbed_official 340:28d1f895c6fe 163 /* Get the RTC_CR register and clear the bits to be configured */
mbed_official 340:28d1f895c6fe 164 tmpreg = (uint32_t)(hrtc->Instance->CR & (uint32_t)~(RTC_CR_TSEDGE | RTC_CR_TSE));
mbed_official 340:28d1f895c6fe 165
mbed_official 340:28d1f895c6fe 166 tmpreg|= TimeStampEdge;
mbed_official 340:28d1f895c6fe 167
mbed_official 340:28d1f895c6fe 168 /* Disable the write protection for RTC registers */
mbed_official 340:28d1f895c6fe 169 __HAL_RTC_WRITEPROTECTION_DISABLE(hrtc);
mbed_official 340:28d1f895c6fe 170
mbed_official 340:28d1f895c6fe 171 /* Configure the Time Stamp TSEDGE and Enable bits */
mbed_official 340:28d1f895c6fe 172 hrtc->Instance->CR = (uint32_t)tmpreg;
mbed_official 340:28d1f895c6fe 173
mbed_official 340:28d1f895c6fe 174 __HAL_RTC_TIMESTAMP_ENABLE(hrtc);
mbed_official 340:28d1f895c6fe 175
mbed_official 340:28d1f895c6fe 176 /* Enable the write protection for RTC registers */
mbed_official 340:28d1f895c6fe 177 __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc);
mbed_official 340:28d1f895c6fe 178
mbed_official 340:28d1f895c6fe 179 /* Change RTC state */
mbed_official 340:28d1f895c6fe 180 hrtc->State = HAL_RTC_STATE_READY;
mbed_official 340:28d1f895c6fe 181
mbed_official 340:28d1f895c6fe 182 /* Process Unlocked */
mbed_official 340:28d1f895c6fe 183 __HAL_UNLOCK(hrtc);
mbed_official 340:28d1f895c6fe 184
mbed_official 340:28d1f895c6fe 185 return HAL_OK;
mbed_official 340:28d1f895c6fe 186 }
mbed_official 340:28d1f895c6fe 187
mbed_official 340:28d1f895c6fe 188 /**
mbed_official 340:28d1f895c6fe 189 * @brief Sets TimeStamp with Interrupt.
mbed_official 441:d2c15dda23c1 190 * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains
mbed_official 441:d2c15dda23c1 191 * the configuration information for RTC.
mbed_official 340:28d1f895c6fe 192 * @note This API must be called before enabling the TimeStamp feature.
mbed_official 340:28d1f895c6fe 193 * @param TimeStampEdge: Specifies the pin edge on which the TimeStamp is
mbed_official 340:28d1f895c6fe 194 * activated.
mbed_official 441:d2c15dda23c1 195 * This parameter can be one of the following values:
mbed_official 441:d2c15dda23c1 196 * @arg RTC_TIMESTAMPEDGE_RISING: the Time stamp event occurs on the
mbed_official 340:28d1f895c6fe 197 * rising edge of the related pin.
mbed_official 441:d2c15dda23c1 198 * @arg RTC_TIMESTAMPEDGE_FALLING: the Time stamp event occurs on the
mbed_official 340:28d1f895c6fe 199 * falling edge of the related pin.
mbed_official 340:28d1f895c6fe 200 * @param RTC_TimeStampPin: Specifies the RTC TimeStamp Pin.
mbed_official 340:28d1f895c6fe 201 * This parameter can be one of the following values:
mbed_official 340:28d1f895c6fe 202 * @arg RTC_TIMESTAMPPIN_PC13: PC13 is selected as RTC TimeStamp Pin.
mbed_official 340:28d1f895c6fe 203 * @retval HAL status
mbed_official 340:28d1f895c6fe 204 */
mbed_official 340:28d1f895c6fe 205 HAL_StatusTypeDef HAL_RTCEx_SetTimeStamp_IT(RTC_HandleTypeDef *hrtc, uint32_t TimeStampEdge, uint32_t RTC_TimeStampPin)
mbed_official 340:28d1f895c6fe 206 {
mbed_official 340:28d1f895c6fe 207 uint32_t tmpreg = 0;
mbed_official 340:28d1f895c6fe 208
mbed_official 340:28d1f895c6fe 209 /* Check the parameters */
mbed_official 340:28d1f895c6fe 210 assert_param(IS_TIMESTAMP_EDGE(TimeStampEdge));
mbed_official 340:28d1f895c6fe 211 assert_param(IS_RTC_TIMESTAMP_PIN(RTC_TimeStampPin));
mbed_official 340:28d1f895c6fe 212
mbed_official 340:28d1f895c6fe 213 /* Process Locked */
mbed_official 340:28d1f895c6fe 214 __HAL_LOCK(hrtc);
mbed_official 340:28d1f895c6fe 215
mbed_official 340:28d1f895c6fe 216 hrtc->State = HAL_RTC_STATE_BUSY;
mbed_official 340:28d1f895c6fe 217
mbed_official 340:28d1f895c6fe 218 /* Get the RTC_CR register and clear the bits to be configured */
mbed_official 340:28d1f895c6fe 219 tmpreg = (uint32_t)(hrtc->Instance->CR & (uint32_t)~(RTC_CR_TSEDGE | RTC_CR_TSE));
mbed_official 340:28d1f895c6fe 220
mbed_official 340:28d1f895c6fe 221 tmpreg |= TimeStampEdge;
mbed_official 340:28d1f895c6fe 222
mbed_official 340:28d1f895c6fe 223 /* Disable the write protection for RTC registers */
mbed_official 340:28d1f895c6fe 224 __HAL_RTC_WRITEPROTECTION_DISABLE(hrtc);
mbed_official 340:28d1f895c6fe 225
mbed_official 340:28d1f895c6fe 226 /* Configure the Time Stamp TSEDGE and Enable bits */
mbed_official 340:28d1f895c6fe 227 hrtc->Instance->CR = (uint32_t)tmpreg;
mbed_official 340:28d1f895c6fe 228
mbed_official 340:28d1f895c6fe 229 __HAL_RTC_TIMESTAMP_ENABLE(hrtc);
mbed_official 340:28d1f895c6fe 230
mbed_official 340:28d1f895c6fe 231 /* Enable IT timestamp */
mbed_official 340:28d1f895c6fe 232 __HAL_RTC_TIMESTAMP_ENABLE_IT(hrtc,RTC_IT_TS);
mbed_official 340:28d1f895c6fe 233
mbed_official 340:28d1f895c6fe 234 /* RTC timestamp Interrupt Configuration: EXTI configuration */
mbed_official 340:28d1f895c6fe 235 __HAL_RTC_EXTI_ENABLE_IT(RTC_EXTI_LINE_TAMPER_TIMESTAMP_EVENT);
mbed_official 340:28d1f895c6fe 236
mbed_official 340:28d1f895c6fe 237 EXTI->RTSR |= RTC_EXTI_LINE_TAMPER_TIMESTAMP_EVENT;
mbed_official 340:28d1f895c6fe 238
mbed_official 340:28d1f895c6fe 239 /* Enable the write protection for RTC registers */
mbed_official 340:28d1f895c6fe 240 __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc);
mbed_official 340:28d1f895c6fe 241
mbed_official 340:28d1f895c6fe 242 hrtc->State = HAL_RTC_STATE_READY;
mbed_official 340:28d1f895c6fe 243
mbed_official 340:28d1f895c6fe 244 /* Process Unlocked */
mbed_official 340:28d1f895c6fe 245 __HAL_UNLOCK(hrtc);
mbed_official 340:28d1f895c6fe 246
mbed_official 340:28d1f895c6fe 247 return HAL_OK;
mbed_official 340:28d1f895c6fe 248 }
mbed_official 340:28d1f895c6fe 249
mbed_official 340:28d1f895c6fe 250 /**
mbed_official 340:28d1f895c6fe 251 * @brief Deactivates TimeStamp.
mbed_official 441:d2c15dda23c1 252 * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains
mbed_official 441:d2c15dda23c1 253 * the configuration information for RTC.
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 340:28d1f895c6fe 289 * @brief Gets the RTC TimeStamp value.
mbed_official 441:d2c15dda23c1 290 * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains
mbed_official 441:d2c15dda23c1 291 * the configuration information for RTC.
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 441:d2c15dda23c1 296 * @arg FORMAT_BIN: Binary data format
mbed_official 441:d2c15dda23c1 297 * @arg 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 340:28d1f895c6fe 325 if(Format == 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 340:28d1f895c6fe 345 * @brief Sets Tamper
mbed_official 340:28d1f895c6fe 346 * @note By calling this API we disable the tamper interrupt for all tampers.
mbed_official 441:d2c15dda23c1 347 * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains
mbed_official 441:d2c15dda23c1 348 * the configuration information for RTC.
mbed_official 340:28d1f895c6fe 349 * @param sTamper: Pointer to Tamper Structure.
mbed_official 340:28d1f895c6fe 350 * @retval HAL status
mbed_official 340:28d1f895c6fe 351 */
mbed_official 340:28d1f895c6fe 352 HAL_StatusTypeDef HAL_RTCEx_SetTamper(RTC_HandleTypeDef *hrtc, RTC_TamperTypeDef* sTamper)
mbed_official 340:28d1f895c6fe 353 {
mbed_official 340:28d1f895c6fe 354 uint32_t tmpreg = 0;
mbed_official 340:28d1f895c6fe 355
mbed_official 340:28d1f895c6fe 356 /* Check the parameters */
mbed_official 340:28d1f895c6fe 357 assert_param(IS_TAMPER(sTamper->Tamper));
mbed_official 340:28d1f895c6fe 358 assert_param(IS_TAMPER_TRIGGER(sTamper->Trigger));
mbed_official 340:28d1f895c6fe 359 assert_param(IS_TAMPER_FILTER(sTamper->Filter));
mbed_official 340:28d1f895c6fe 360 assert_param(IS_TAMPER_SAMPLING_FREQ(sTamper->SamplingFrequency));
mbed_official 340:28d1f895c6fe 361 assert_param(IS_TAMPER_PRECHARGE_DURATION(sTamper->PrechargeDuration));
mbed_official 340:28d1f895c6fe 362 assert_param(IS_TAMPER_PULLUP_STATE(sTamper->TamperPullUp));
mbed_official 340:28d1f895c6fe 363 assert_param(IS_TAMPER_TIMESTAMPONTAMPER_DETECTION(sTamper->TimeStampOnTamperDetection));
mbed_official 340:28d1f895c6fe 364
mbed_official 340:28d1f895c6fe 365 /* Process Locked */
mbed_official 340:28d1f895c6fe 366 __HAL_LOCK(hrtc);
mbed_official 340:28d1f895c6fe 367
mbed_official 340:28d1f895c6fe 368 hrtc->State = HAL_RTC_STATE_BUSY;
mbed_official 340:28d1f895c6fe 369
mbed_official 340:28d1f895c6fe 370 if(sTamper->Trigger != RTC_TAMPERTRIGGER_RISINGEDGE)
mbed_official 340:28d1f895c6fe 371 {
mbed_official 340:28d1f895c6fe 372 sTamper->Trigger = (uint32_t)(sTamper->Tamper << 1);
mbed_official 340:28d1f895c6fe 373 }
mbed_official 340:28d1f895c6fe 374
mbed_official 340:28d1f895c6fe 375 tmpreg = ((uint32_t)sTamper->Tamper | (uint32_t)sTamper->Trigger | (uint32_t)sTamper->Filter |\
mbed_official 340:28d1f895c6fe 376 (uint32_t)sTamper->SamplingFrequency | (uint32_t)sTamper->PrechargeDuration |\
mbed_official 340:28d1f895c6fe 377 (uint32_t)sTamper->TamperPullUp | sTamper->TimeStampOnTamperDetection);
mbed_official 340:28d1f895c6fe 378
mbed_official 340:28d1f895c6fe 379 hrtc->Instance->TAFCR &= (uint32_t)~((uint32_t)sTamper->Tamper | (uint32_t)(sTamper->Tamper << 1) | (uint32_t)RTC_TAFCR_TAMPTS |\
mbed_official 340:28d1f895c6fe 380 (uint32_t)RTC_TAFCR_TAMPFREQ | (uint32_t)RTC_TAFCR_TAMPFLT | (uint32_t)RTC_TAFCR_TAMPPRCH |\
mbed_official 340:28d1f895c6fe 381 (uint32_t)RTC_TAFCR_TAMPPUDIS | (uint32_t)RTC_TAFCR_TAMPIE);
mbed_official 340:28d1f895c6fe 382
mbed_official 340:28d1f895c6fe 383 hrtc->Instance->TAFCR |= tmpreg;
mbed_official 340:28d1f895c6fe 384
mbed_official 340:28d1f895c6fe 385 hrtc->State = HAL_RTC_STATE_READY;
mbed_official 340:28d1f895c6fe 386
mbed_official 340:28d1f895c6fe 387 /* Process Unlocked */
mbed_official 340:28d1f895c6fe 388 __HAL_UNLOCK(hrtc);
mbed_official 340:28d1f895c6fe 389
mbed_official 340:28d1f895c6fe 390 return HAL_OK;
mbed_official 340:28d1f895c6fe 391 }
mbed_official 340:28d1f895c6fe 392
mbed_official 340:28d1f895c6fe 393 /**
mbed_official 340:28d1f895c6fe 394 * @brief Sets Tamper with interrupt.
mbed_official 340:28d1f895c6fe 395 * @note By calling this API we force the tamper interrupt for all tampers.
mbed_official 441:d2c15dda23c1 396 * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains
mbed_official 441:d2c15dda23c1 397 * the configuration information for RTC.
mbed_official 340:28d1f895c6fe 398 * @param sTamper: Pointer to RTC Tamper.
mbed_official 340:28d1f895c6fe 399 * @retval HAL status
mbed_official 340:28d1f895c6fe 400 */
mbed_official 340:28d1f895c6fe 401 HAL_StatusTypeDef HAL_RTCEx_SetTamper_IT(RTC_HandleTypeDef *hrtc, RTC_TamperTypeDef* sTamper)
mbed_official 340:28d1f895c6fe 402 {
mbed_official 340:28d1f895c6fe 403 uint32_t tmpreg = 0;
mbed_official 340:28d1f895c6fe 404
mbed_official 340:28d1f895c6fe 405 /* Check the parameters */
mbed_official 340:28d1f895c6fe 406 assert_param(IS_TAMPER(sTamper->Tamper));
mbed_official 340:28d1f895c6fe 407 assert_param(IS_TAMPER_TRIGGER(sTamper->Trigger));
mbed_official 340:28d1f895c6fe 408 assert_param(IS_TAMPER_FILTER(sTamper->Filter));
mbed_official 340:28d1f895c6fe 409 assert_param(IS_TAMPER_SAMPLING_FREQ(sTamper->SamplingFrequency));
mbed_official 340:28d1f895c6fe 410 assert_param(IS_TAMPER_PRECHARGE_DURATION(sTamper->PrechargeDuration));
mbed_official 340:28d1f895c6fe 411 assert_param(IS_TAMPER_PULLUP_STATE(sTamper->TamperPullUp));
mbed_official 340:28d1f895c6fe 412 assert_param(IS_TAMPER_TIMESTAMPONTAMPER_DETECTION(sTamper->TimeStampOnTamperDetection));
mbed_official 340:28d1f895c6fe 413
mbed_official 340:28d1f895c6fe 414 /* Process Locked */
mbed_official 340:28d1f895c6fe 415 __HAL_LOCK(hrtc);
mbed_official 340:28d1f895c6fe 416
mbed_official 340:28d1f895c6fe 417 hrtc->State = HAL_RTC_STATE_BUSY;
mbed_official 340:28d1f895c6fe 418
mbed_official 340:28d1f895c6fe 419 /* Configure the tamper trigger */
mbed_official 340:28d1f895c6fe 420 if(sTamper->Trigger != RTC_TAMPERTRIGGER_RISINGEDGE)
mbed_official 340:28d1f895c6fe 421 {
mbed_official 340:28d1f895c6fe 422 sTamper->Trigger = (uint32_t)(sTamper->Tamper << 1);
mbed_official 340:28d1f895c6fe 423 }
mbed_official 340:28d1f895c6fe 424
mbed_official 340:28d1f895c6fe 425 tmpreg = ((uint32_t)sTamper->Tamper | (uint32_t)sTamper->Trigger | (uint32_t)sTamper->Filter |\
mbed_official 340:28d1f895c6fe 426 (uint32_t)sTamper->SamplingFrequency | (uint32_t)sTamper->PrechargeDuration |\
mbed_official 340:28d1f895c6fe 427 (uint32_t)sTamper->TamperPullUp | sTamper->TimeStampOnTamperDetection);
mbed_official 340:28d1f895c6fe 428
mbed_official 340:28d1f895c6fe 429 hrtc->Instance->TAFCR &= (uint32_t)~((uint32_t)sTamper->Tamper | (uint32_t)(sTamper->Tamper << 1) | (uint32_t)RTC_TAFCR_TAMPTS |\
mbed_official 340:28d1f895c6fe 430 (uint32_t)RTC_TAFCR_TAMPFREQ | (uint32_t)RTC_TAFCR_TAMPFLT | (uint32_t)RTC_TAFCR_TAMPPRCH |\
mbed_official 340:28d1f895c6fe 431 (uint32_t)RTC_TAFCR_TAMPPUDIS);
mbed_official 340:28d1f895c6fe 432
mbed_official 340:28d1f895c6fe 433 hrtc->Instance->TAFCR |= tmpreg;
mbed_official 340:28d1f895c6fe 434
mbed_official 340:28d1f895c6fe 435 /* Configure the Tamper Interrupt in the RTC_TAFCR */
mbed_official 340:28d1f895c6fe 436 hrtc->Instance->TAFCR |= (uint32_t)RTC_TAFCR_TAMPIE;
mbed_official 340:28d1f895c6fe 437
mbed_official 340:28d1f895c6fe 438 /* RTC Tamper Interrupt Configuration: EXTI configuration */
mbed_official 340:28d1f895c6fe 439 __HAL_RTC_EXTI_ENABLE_IT(RTC_EXTI_LINE_TAMPER_TIMESTAMP_EVENT);
mbed_official 340:28d1f895c6fe 440
mbed_official 340:28d1f895c6fe 441 EXTI->RTSR |= RTC_EXTI_LINE_TAMPER_TIMESTAMP_EVENT;
mbed_official 340:28d1f895c6fe 442
mbed_official 340:28d1f895c6fe 443 hrtc->State = HAL_RTC_STATE_READY;
mbed_official 340:28d1f895c6fe 444
mbed_official 340:28d1f895c6fe 445 /* Process Unlocked */
mbed_official 340:28d1f895c6fe 446 __HAL_UNLOCK(hrtc);
mbed_official 340:28d1f895c6fe 447
mbed_official 340:28d1f895c6fe 448 return HAL_OK;
mbed_official 340:28d1f895c6fe 449 }
mbed_official 340:28d1f895c6fe 450
mbed_official 340:28d1f895c6fe 451 /**
mbed_official 340:28d1f895c6fe 452 * @brief Deactivates Tamper.
mbed_official 441:d2c15dda23c1 453 * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains
mbed_official 441:d2c15dda23c1 454 * the configuration information for RTC.
mbed_official 340:28d1f895c6fe 455 * @param Tamper: Selected tamper pin.
mbed_official 340:28d1f895c6fe 456 * This parameter can be any combination of RTC_TAMPER_1, RTC_TAMPER_2 and RTC_TAMPER_3.
mbed_official 340:28d1f895c6fe 457 * @retval HAL status
mbed_official 340:28d1f895c6fe 458 */
mbed_official 340:28d1f895c6fe 459 HAL_StatusTypeDef HAL_RTCEx_DeactivateTamper(RTC_HandleTypeDef *hrtc, uint32_t Tamper)
mbed_official 340:28d1f895c6fe 460 {
mbed_official 340:28d1f895c6fe 461 assert_param(IS_TAMPER(Tamper));
mbed_official 340:28d1f895c6fe 462
mbed_official 340:28d1f895c6fe 463 /* Process Locked */
mbed_official 340:28d1f895c6fe 464 __HAL_LOCK(hrtc);
mbed_official 340:28d1f895c6fe 465
mbed_official 340:28d1f895c6fe 466 hrtc->State = HAL_RTC_STATE_BUSY;
mbed_official 340:28d1f895c6fe 467
mbed_official 340:28d1f895c6fe 468 /* Disable the selected Tamper pin */
mbed_official 340:28d1f895c6fe 469 hrtc->Instance->TAFCR &= (uint32_t)~Tamper;
mbed_official 340:28d1f895c6fe 470
mbed_official 340:28d1f895c6fe 471 hrtc->State = HAL_RTC_STATE_READY;
mbed_official 340:28d1f895c6fe 472
mbed_official 340:28d1f895c6fe 473 /* Process Unlocked */
mbed_official 340:28d1f895c6fe 474 __HAL_UNLOCK(hrtc);
mbed_official 340:28d1f895c6fe 475
mbed_official 340:28d1f895c6fe 476 return HAL_OK;
mbed_official 340:28d1f895c6fe 477 }
mbed_official 340:28d1f895c6fe 478
mbed_official 340:28d1f895c6fe 479 /**
mbed_official 340:28d1f895c6fe 480 * @brief This function handles TimeStamp interrupt request.
mbed_official 441:d2c15dda23c1 481 * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains
mbed_official 441:d2c15dda23c1 482 * the configuration information for RTC.
mbed_official 340:28d1f895c6fe 483 * @retval None
mbed_official 340:28d1f895c6fe 484 */
mbed_official 340:28d1f895c6fe 485 void HAL_RTCEx_TamperTimeStampIRQHandler(RTC_HandleTypeDef *hrtc)
mbed_official 340:28d1f895c6fe 486 {
mbed_official 340:28d1f895c6fe 487 if(__HAL_RTC_TIMESTAMP_GET_IT(hrtc, RTC_IT_TS))
mbed_official 340:28d1f895c6fe 488 {
mbed_official 340:28d1f895c6fe 489 /* Get the status of the Interrupt */
mbed_official 340:28d1f895c6fe 490 if((uint32_t)(hrtc->Instance->CR & RTC_IT_TS) != (uint32_t)RESET)
mbed_official 340:28d1f895c6fe 491 {
mbed_official 340:28d1f895c6fe 492 /* TIMESTAMP callback */
mbed_official 340:28d1f895c6fe 493 HAL_RTCEx_TimeStampEventCallback(hrtc);
mbed_official 340:28d1f895c6fe 494
mbed_official 340:28d1f895c6fe 495 /* Clear the TIMESTAMP interrupt pending bit */
mbed_official 340:28d1f895c6fe 496 __HAL_RTC_TIMESTAMP_CLEAR_FLAG(hrtc,RTC_FLAG_TSF);
mbed_official 340:28d1f895c6fe 497 }
mbed_official 340:28d1f895c6fe 498 }
mbed_official 340:28d1f895c6fe 499
mbed_official 340:28d1f895c6fe 500 /* Get the status of the Interrupt */
mbed_official 340:28d1f895c6fe 501 if(__HAL_RTC_TAMPER_GET_IT(hrtc,RTC_IT_TAMP1))
mbed_official 340:28d1f895c6fe 502 {
mbed_official 340:28d1f895c6fe 503 /* Get the TAMPER Interrupt enable bit and pending bit */
mbed_official 340:28d1f895c6fe 504 if(((hrtc->Instance->TAFCR & (RTC_TAFCR_TAMPIE))) != (uint32_t)RESET)
mbed_official 340:28d1f895c6fe 505 {
mbed_official 340:28d1f895c6fe 506 /* Tamper callback */
mbed_official 340:28d1f895c6fe 507 HAL_RTCEx_Tamper1EventCallback(hrtc);
mbed_official 340:28d1f895c6fe 508
mbed_official 340:28d1f895c6fe 509 /* Clear the Tamper interrupt pending bit */
mbed_official 340:28d1f895c6fe 510 __HAL_RTC_TAMPER_CLEAR_FLAG(hrtc,RTC_FLAG_TAMP1F);
mbed_official 340:28d1f895c6fe 511 }
mbed_official 340:28d1f895c6fe 512 }
mbed_official 340:28d1f895c6fe 513
mbed_official 340:28d1f895c6fe 514 /* Get the status of the Interrupt */
mbed_official 340:28d1f895c6fe 515 if(__HAL_RTC_TAMPER_GET_IT(hrtc, RTC_IT_TAMP2))
mbed_official 340:28d1f895c6fe 516 {
mbed_official 340:28d1f895c6fe 517 /* Get the TAMPER Interrupt enable bit and pending bit */
mbed_official 340:28d1f895c6fe 518 if(((hrtc->Instance->TAFCR & RTC_TAFCR_TAMPIE)) != (uint32_t)RESET)
mbed_official 340:28d1f895c6fe 519 {
mbed_official 340:28d1f895c6fe 520 /* Tamper callback */
mbed_official 340:28d1f895c6fe 521 HAL_RTCEx_Tamper2EventCallback(hrtc);
mbed_official 340:28d1f895c6fe 522
mbed_official 340:28d1f895c6fe 523 /* Clear the Tamper interrupt pending bit */
mbed_official 340:28d1f895c6fe 524 __HAL_RTC_TAMPER_CLEAR_FLAG(hrtc, RTC_FLAG_TAMP2F);
mbed_official 340:28d1f895c6fe 525 }
mbed_official 340:28d1f895c6fe 526 }
mbed_official 340:28d1f895c6fe 527
mbed_official 340:28d1f895c6fe 528 #if defined(STM32F071xB) || defined(STM32F072xB) || defined(STM32F078xx) || defined(STM32F091xC) || defined(STM32F098xx)
mbed_official 340:28d1f895c6fe 529 /* Get the status of the Interrupt */
mbed_official 340:28d1f895c6fe 530 if(__HAL_RTC_TAMPER_GET_IT(hrtc, RTC_IT_TAMP3))
mbed_official 340:28d1f895c6fe 531 {
mbed_official 340:28d1f895c6fe 532 /* Get the TAMPER Interrupt enable bit and pending bit */
mbed_official 340:28d1f895c6fe 533 if(((hrtc->Instance->TAFCR & RTC_TAFCR_TAMPIE)) != (uint32_t)RESET)
mbed_official 340:28d1f895c6fe 534 {
mbed_official 340:28d1f895c6fe 535 /* Tamper callback */
mbed_official 340:28d1f895c6fe 536 HAL_RTCEx_Tamper3EventCallback(hrtc);
mbed_official 340:28d1f895c6fe 537
mbed_official 340:28d1f895c6fe 538 /* Clear the Tamper interrupt pending bit */
mbed_official 340:28d1f895c6fe 539 __HAL_RTC_TAMPER_CLEAR_FLAG(hrtc, RTC_FLAG_TAMP3F);
mbed_official 340:28d1f895c6fe 540 }
mbed_official 340:28d1f895c6fe 541 }
mbed_official 340:28d1f895c6fe 542 #endif
mbed_official 340:28d1f895c6fe 543
mbed_official 340:28d1f895c6fe 544 /* Clear the EXTI's Flag for RTC TimeStamp and Tamper */
mbed_official 340:28d1f895c6fe 545 __HAL_RTC_EXTI_CLEAR_FLAG(RTC_EXTI_LINE_TAMPER_TIMESTAMP_EVENT);
mbed_official 340:28d1f895c6fe 546
mbed_official 340:28d1f895c6fe 547 /* Change RTC state */
mbed_official 340:28d1f895c6fe 548 hrtc->State = HAL_RTC_STATE_READY;
mbed_official 340:28d1f895c6fe 549 }
mbed_official 340:28d1f895c6fe 550
mbed_official 340:28d1f895c6fe 551 /**
mbed_official 340:28d1f895c6fe 552 * @brief TimeStamp callback.
mbed_official 441:d2c15dda23c1 553 * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains
mbed_official 441:d2c15dda23c1 554 * the configuration information for RTC.
mbed_official 340:28d1f895c6fe 555 * @retval None
mbed_official 340:28d1f895c6fe 556 */
mbed_official 340:28d1f895c6fe 557 __weak void HAL_RTCEx_TimeStampEventCallback(RTC_HandleTypeDef *hrtc)
mbed_official 340:28d1f895c6fe 558 {
mbed_official 340:28d1f895c6fe 559 /* NOTE : This function Should not be modified, when the callback is needed,
mbed_official 340:28d1f895c6fe 560 the HAL_RTCEx_TimeStampEventCallback could be implemented in the user file
mbed_official 340:28d1f895c6fe 561 */
mbed_official 340:28d1f895c6fe 562 }
mbed_official 340:28d1f895c6fe 563
mbed_official 340:28d1f895c6fe 564 /**
mbed_official 340:28d1f895c6fe 565 * @brief Tamper 1 callback.
mbed_official 441:d2c15dda23c1 566 * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains
mbed_official 441:d2c15dda23c1 567 * the configuration information for RTC.
mbed_official 340:28d1f895c6fe 568 * @retval None
mbed_official 340:28d1f895c6fe 569 */
mbed_official 340:28d1f895c6fe 570 __weak void HAL_RTCEx_Tamper1EventCallback(RTC_HandleTypeDef *hrtc)
mbed_official 340:28d1f895c6fe 571 {
mbed_official 340:28d1f895c6fe 572 /* NOTE : This function Should not be modified, when the callback is needed,
mbed_official 340:28d1f895c6fe 573 the HAL_RTCEx_Tamper1EventCallback could be implemented in the user file
mbed_official 340:28d1f895c6fe 574 */
mbed_official 340:28d1f895c6fe 575 }
mbed_official 340:28d1f895c6fe 576
mbed_official 340:28d1f895c6fe 577 /**
mbed_official 340:28d1f895c6fe 578 * @brief Tamper 2 callback.
mbed_official 441:d2c15dda23c1 579 * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains
mbed_official 441:d2c15dda23c1 580 * the configuration information for RTC.
mbed_official 340:28d1f895c6fe 581 * @retval None
mbed_official 340:28d1f895c6fe 582 */
mbed_official 340:28d1f895c6fe 583 __weak void HAL_RTCEx_Tamper2EventCallback(RTC_HandleTypeDef *hrtc)
mbed_official 340:28d1f895c6fe 584 {
mbed_official 340:28d1f895c6fe 585 /* NOTE : This function Should not be modified, when the callback is needed,
mbed_official 340:28d1f895c6fe 586 the HAL_RTCEx_Tamper2EventCallback could be implemented in the user file
mbed_official 340:28d1f895c6fe 587 */
mbed_official 340:28d1f895c6fe 588 }
mbed_official 340:28d1f895c6fe 589
mbed_official 441:d2c15dda23c1 590 #if defined(STM32F071xB) || defined(STM32F072xB) || defined(STM32F078xx) || defined(STM32F091xC) || defined(STM32F098xx) || defined(STM32F070xB) || defined(STM32F030xC)
mbed_official 340:28d1f895c6fe 591 /**
mbed_official 340:28d1f895c6fe 592 * @brief Tamper 3 callback.
mbed_official 340:28d1f895c6fe 593 * @param hrtc: RTC handle
mbed_official 340:28d1f895c6fe 594 * @retval None
mbed_official 340:28d1f895c6fe 595 */
mbed_official 340:28d1f895c6fe 596 __weak void HAL_RTCEx_Tamper3EventCallback(RTC_HandleTypeDef *hrtc)
mbed_official 340:28d1f895c6fe 597 {
mbed_official 340:28d1f895c6fe 598 /* NOTE : This function Should not be modified, when the callback is needed,
mbed_official 340:28d1f895c6fe 599 the HAL_RTCEx_Tamper3EventCallback could be implemented in the user file
mbed_official 340:28d1f895c6fe 600 */
mbed_official 340:28d1f895c6fe 601 }
mbed_official 340:28d1f895c6fe 602 #endif
mbed_official 340:28d1f895c6fe 603
mbed_official 340:28d1f895c6fe 604 /**
mbed_official 340:28d1f895c6fe 605 * @brief This function handles TimeStamp polling request.
mbed_official 441:d2c15dda23c1 606 * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains
mbed_official 441:d2c15dda23c1 607 * the configuration information for RTC.
mbed_official 340:28d1f895c6fe 608 * @param Timeout: Timeout duration
mbed_official 340:28d1f895c6fe 609 * @retval HAL status
mbed_official 340:28d1f895c6fe 610 */
mbed_official 340:28d1f895c6fe 611 HAL_StatusTypeDef HAL_RTCEx_PollForTimeStampEvent(RTC_HandleTypeDef *hrtc, uint32_t Timeout)
mbed_official 340:28d1f895c6fe 612 {
mbed_official 340:28d1f895c6fe 613 uint32_t tickstart = 0;
mbed_official 340:28d1f895c6fe 614
mbed_official 441:d2c15dda23c1 615 /* Get tick */
mbed_official 340:28d1f895c6fe 616 tickstart = HAL_GetTick();
mbed_official 340:28d1f895c6fe 617
mbed_official 340:28d1f895c6fe 618 while(__HAL_RTC_TIMESTAMP_GET_FLAG(hrtc, RTC_FLAG_TSF) == RESET)
mbed_official 340:28d1f895c6fe 619 {
mbed_official 340:28d1f895c6fe 620 if(__HAL_RTC_TIMESTAMP_GET_FLAG(hrtc, RTC_FLAG_TSOVF) != RESET)
mbed_official 340:28d1f895c6fe 621 {
mbed_official 441:d2c15dda23c1 622 /* Clear the TIMESTAMP Overrun Flag */
mbed_official 340:28d1f895c6fe 623 __HAL_RTC_TIMESTAMP_CLEAR_FLAG(hrtc, RTC_FLAG_TSOVF);
mbed_official 340:28d1f895c6fe 624
mbed_official 340:28d1f895c6fe 625 /* Change TIMESTAMP state */
mbed_official 340:28d1f895c6fe 626 hrtc->State = HAL_RTC_STATE_ERROR;
mbed_official 340:28d1f895c6fe 627
mbed_official 340:28d1f895c6fe 628 return HAL_ERROR;
mbed_official 340:28d1f895c6fe 629 }
mbed_official 340:28d1f895c6fe 630
mbed_official 340:28d1f895c6fe 631 if(Timeout != HAL_MAX_DELAY)
mbed_official 340:28d1f895c6fe 632 {
mbed_official 340:28d1f895c6fe 633 if((Timeout == 0) || ((HAL_GetTick() - tickstart) > Timeout))
mbed_official 340:28d1f895c6fe 634 {
mbed_official 340:28d1f895c6fe 635 hrtc->State = HAL_RTC_STATE_TIMEOUT;
mbed_official 340:28d1f895c6fe 636 return HAL_TIMEOUT;
mbed_official 340:28d1f895c6fe 637 }
mbed_official 340:28d1f895c6fe 638 }
mbed_official 340:28d1f895c6fe 639 }
mbed_official 340:28d1f895c6fe 640
mbed_official 340:28d1f895c6fe 641 /* Change RTC state */
mbed_official 340:28d1f895c6fe 642 hrtc->State = HAL_RTC_STATE_READY;
mbed_official 340:28d1f895c6fe 643
mbed_official 340:28d1f895c6fe 644 return HAL_OK;
mbed_official 340:28d1f895c6fe 645 }
mbed_official 340:28d1f895c6fe 646
mbed_official 340:28d1f895c6fe 647 /**
mbed_official 340:28d1f895c6fe 648 * @brief This function handles Tamper1 Polling.
mbed_official 441:d2c15dda23c1 649 * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains
mbed_official 441:d2c15dda23c1 650 * the configuration information for RTC.
mbed_official 340:28d1f895c6fe 651 * @param Timeout: Timeout duration
mbed_official 340:28d1f895c6fe 652 * @retval HAL status
mbed_official 340:28d1f895c6fe 653 */
mbed_official 340:28d1f895c6fe 654 HAL_StatusTypeDef HAL_RTCEx_PollForTamper1Event(RTC_HandleTypeDef *hrtc, uint32_t Timeout)
mbed_official 340:28d1f895c6fe 655 {
mbed_official 340:28d1f895c6fe 656 uint32_t tickstart = 0;
mbed_official 340:28d1f895c6fe 657
mbed_official 441:d2c15dda23c1 658 /* Get tick */
mbed_official 340:28d1f895c6fe 659 tickstart = HAL_GetTick();
mbed_official 340:28d1f895c6fe 660
mbed_official 340:28d1f895c6fe 661 /* Get the status of the Interrupt */
mbed_official 340:28d1f895c6fe 662 while(__HAL_RTC_TAMPER_GET_FLAG(hrtc,RTC_FLAG_TAMP1F)== RESET)
mbed_official 340:28d1f895c6fe 663 {
mbed_official 340:28d1f895c6fe 664 if(Timeout != HAL_MAX_DELAY)
mbed_official 340:28d1f895c6fe 665 {
mbed_official 340:28d1f895c6fe 666 if((Timeout == 0) || ((HAL_GetTick() - tickstart) > Timeout))
mbed_official 340:28d1f895c6fe 667 {
mbed_official 340:28d1f895c6fe 668 hrtc->State = HAL_RTC_STATE_TIMEOUT;
mbed_official 340:28d1f895c6fe 669 return HAL_TIMEOUT;
mbed_official 340:28d1f895c6fe 670 }
mbed_official 340:28d1f895c6fe 671 }
mbed_official 340:28d1f895c6fe 672 }
mbed_official 340:28d1f895c6fe 673
mbed_official 340:28d1f895c6fe 674 /* Clear the Tamper Flag */
mbed_official 340:28d1f895c6fe 675 __HAL_RTC_TAMPER_CLEAR_FLAG(hrtc,RTC_FLAG_TAMP1F);
mbed_official 340:28d1f895c6fe 676
mbed_official 340:28d1f895c6fe 677 /* Change RTC state */
mbed_official 340:28d1f895c6fe 678 hrtc->State = HAL_RTC_STATE_READY;
mbed_official 340:28d1f895c6fe 679
mbed_official 340:28d1f895c6fe 680 return HAL_OK;
mbed_official 340:28d1f895c6fe 681 }
mbed_official 340:28d1f895c6fe 682
mbed_official 340:28d1f895c6fe 683 /**
mbed_official 340:28d1f895c6fe 684 * @brief This function handles Tamper2 Polling.
mbed_official 441:d2c15dda23c1 685 * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains
mbed_official 441:d2c15dda23c1 686 * the configuration information for RTC.
mbed_official 340:28d1f895c6fe 687 * @param Timeout: Timeout duration
mbed_official 340:28d1f895c6fe 688 * @retval HAL status
mbed_official 340:28d1f895c6fe 689 */
mbed_official 340:28d1f895c6fe 690 HAL_StatusTypeDef HAL_RTCEx_PollForTamper2Event(RTC_HandleTypeDef *hrtc, uint32_t Timeout)
mbed_official 340:28d1f895c6fe 691 {
mbed_official 340:28d1f895c6fe 692 uint32_t tickstart = 0;
mbed_official 340:28d1f895c6fe 693
mbed_official 441:d2c15dda23c1 694 /* Get tick */
mbed_official 340:28d1f895c6fe 695 tickstart = HAL_GetTick();
mbed_official 340:28d1f895c6fe 696
mbed_official 340:28d1f895c6fe 697 /* Get the status of the Interrupt */
mbed_official 340:28d1f895c6fe 698 while(__HAL_RTC_TAMPER_GET_FLAG(hrtc,RTC_FLAG_TAMP2F) == RESET)
mbed_official 340:28d1f895c6fe 699 {
mbed_official 340:28d1f895c6fe 700 if(Timeout != HAL_MAX_DELAY)
mbed_official 340:28d1f895c6fe 701 {
mbed_official 340:28d1f895c6fe 702 if((Timeout == 0) || ((HAL_GetTick() - tickstart) > Timeout))
mbed_official 340:28d1f895c6fe 703 {
mbed_official 340:28d1f895c6fe 704 hrtc->State = HAL_RTC_STATE_TIMEOUT;
mbed_official 340:28d1f895c6fe 705 return HAL_TIMEOUT;
mbed_official 340:28d1f895c6fe 706 }
mbed_official 340:28d1f895c6fe 707 }
mbed_official 340:28d1f895c6fe 708 }
mbed_official 340:28d1f895c6fe 709
mbed_official 340:28d1f895c6fe 710 /* Clear the Tamper Flag */
mbed_official 340:28d1f895c6fe 711 __HAL_RTC_TAMPER_CLEAR_FLAG(hrtc,RTC_FLAG_TAMP2F);
mbed_official 340:28d1f895c6fe 712
mbed_official 340:28d1f895c6fe 713 /* Change RTC state */
mbed_official 340:28d1f895c6fe 714 hrtc->State = HAL_RTC_STATE_READY;
mbed_official 340:28d1f895c6fe 715
mbed_official 340:28d1f895c6fe 716 return HAL_OK;
mbed_official 340:28d1f895c6fe 717 }
mbed_official 340:28d1f895c6fe 718
mbed_official 340:28d1f895c6fe 719 #if defined(STM32F071xB) || defined(STM32F072xB) || defined(STM32F078xx) || defined(STM32F091xC) || defined(STM32F098xx)
mbed_official 340:28d1f895c6fe 720 /**
mbed_official 340:28d1f895c6fe 721 * @brief This function handles Tamper3 Polling.
mbed_official 441:d2c15dda23c1 722 * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains
mbed_official 441:d2c15dda23c1 723 * the configuration information for RTC.
mbed_official 340:28d1f895c6fe 724 * @param Timeout: Timeout duration
mbed_official 340:28d1f895c6fe 725 * @retval HAL status
mbed_official 340:28d1f895c6fe 726 */
mbed_official 340:28d1f895c6fe 727 HAL_StatusTypeDef HAL_RTCEx_PollForTamper3Event(RTC_HandleTypeDef *hrtc, uint32_t Timeout)
mbed_official 340:28d1f895c6fe 728 {
mbed_official 340:28d1f895c6fe 729 uint32_t tickstart = 0;
mbed_official 340:28d1f895c6fe 730
mbed_official 441:d2c15dda23c1 731 /* Get tick */
mbed_official 340:28d1f895c6fe 732 tickstart = HAL_GetTick();
mbed_official 340:28d1f895c6fe 733
mbed_official 340:28d1f895c6fe 734 /* Get the status of the Interrupt */
mbed_official 340:28d1f895c6fe 735 while(__HAL_RTC_TAMPER_GET_FLAG(hrtc,RTC_FLAG_TAMP3F) == RESET)
mbed_official 340:28d1f895c6fe 736 {
mbed_official 340:28d1f895c6fe 737 if(Timeout != HAL_MAX_DELAY)
mbed_official 340:28d1f895c6fe 738 {
mbed_official 340:28d1f895c6fe 739 if((Timeout == 0) || ((HAL_GetTick() - tickstart) > Timeout))
mbed_official 340:28d1f895c6fe 740 {
mbed_official 340:28d1f895c6fe 741 hrtc->State = HAL_RTC_STATE_TIMEOUT;
mbed_official 340:28d1f895c6fe 742 return HAL_TIMEOUT;
mbed_official 340:28d1f895c6fe 743 }
mbed_official 340:28d1f895c6fe 744 }
mbed_official 340:28d1f895c6fe 745 }
mbed_official 340:28d1f895c6fe 746
mbed_official 340:28d1f895c6fe 747 /* Clear the Tamper Flag */
mbed_official 340:28d1f895c6fe 748 __HAL_RTC_TAMPER_CLEAR_FLAG(hrtc,RTC_FLAG_TAMP3F);
mbed_official 340:28d1f895c6fe 749
mbed_official 340:28d1f895c6fe 750 /* Change RTC state */
mbed_official 340:28d1f895c6fe 751 hrtc->State = HAL_RTC_STATE_READY;
mbed_official 340:28d1f895c6fe 752
mbed_official 340:28d1f895c6fe 753 return HAL_OK;
mbed_official 340:28d1f895c6fe 754 }
mbed_official 340:28d1f895c6fe 755 #endif
mbed_official 340:28d1f895c6fe 756
mbed_official 340:28d1f895c6fe 757 /**
mbed_official 340:28d1f895c6fe 758 * @}
mbed_official 340:28d1f895c6fe 759 */
mbed_official 340:28d1f895c6fe 760
mbed_official 340:28d1f895c6fe 761 #if defined(STM32F071xB) || defined(STM32F072xB) || defined(STM32F078xx) || defined(STM32F091xC) || defined(STM32F098xx)
mbed_official 340:28d1f895c6fe 762 /** @defgroup RTCEx_Exported_Functions_Group2 RTC Wake-up functions
mbed_official 340:28d1f895c6fe 763 * @brief RTC Wake-up functions
mbed_official 340:28d1f895c6fe 764 *
mbed_official 340:28d1f895c6fe 765 @verbatim
mbed_official 340:28d1f895c6fe 766 ===============================================================================
mbed_official 340:28d1f895c6fe 767 ##### RTC Wake-up functions #####
mbed_official 340:28d1f895c6fe 768 ===============================================================================
mbed_official 340:28d1f895c6fe 769
mbed_official 441:d2c15dda23c1 770 [..] This section provides functions allowing to configure Wake-up feature
mbed_official 340:28d1f895c6fe 771
mbed_official 340:28d1f895c6fe 772 @endverbatim
mbed_official 340:28d1f895c6fe 773 * @{
mbed_official 340:28d1f895c6fe 774 */
mbed_official 340:28d1f895c6fe 775
mbed_official 340:28d1f895c6fe 776 /**
mbed_official 340:28d1f895c6fe 777 * @brief Sets wake up timer.
mbed_official 441:d2c15dda23c1 778 * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains
mbed_official 441:d2c15dda23c1 779 * the configuration information for RTC.
mbed_official 340:28d1f895c6fe 780 * @param WakeUpCounter: Wake up counter
mbed_official 340:28d1f895c6fe 781 * @param WakeUpClock: Wake up clock
mbed_official 340:28d1f895c6fe 782 * @retval HAL status
mbed_official 340:28d1f895c6fe 783 */
mbed_official 340:28d1f895c6fe 784 HAL_StatusTypeDef HAL_RTCEx_SetWakeUpTimer(RTC_HandleTypeDef *hrtc, uint32_t WakeUpCounter, uint32_t WakeUpClock)
mbed_official 340:28d1f895c6fe 785 {
mbed_official 340:28d1f895c6fe 786 uint32_t tickstart = 0;
mbed_official 340:28d1f895c6fe 787
mbed_official 340:28d1f895c6fe 788 /* Check the parameters */
mbed_official 340:28d1f895c6fe 789 assert_param(IS_WAKEUP_CLOCK(WakeUpClock));
mbed_official 340:28d1f895c6fe 790 assert_param(IS_WAKEUP_COUNTER(WakeUpCounter));
mbed_official 340:28d1f895c6fe 791
mbed_official 340:28d1f895c6fe 792 /* Process Locked */
mbed_official 340:28d1f895c6fe 793 __HAL_LOCK(hrtc);
mbed_official 340:28d1f895c6fe 794
mbed_official 340:28d1f895c6fe 795 hrtc->State = HAL_RTC_STATE_BUSY;
mbed_official 340:28d1f895c6fe 796
mbed_official 340:28d1f895c6fe 797 /* Disable the write protection for RTC registers */
mbed_official 340:28d1f895c6fe 798 __HAL_RTC_WRITEPROTECTION_DISABLE(hrtc);
mbed_official 340:28d1f895c6fe 799
mbed_official 340:28d1f895c6fe 800 __HAL_RTC_WAKEUPTIMER_DISABLE(hrtc);
mbed_official 340:28d1f895c6fe 801
mbed_official 441:d2c15dda23c1 802 /* Get tick */
mbed_official 340:28d1f895c6fe 803 tickstart = HAL_GetTick();
mbed_official 340:28d1f895c6fe 804
mbed_official 340:28d1f895c6fe 805 /* Wait till RTC WUTWF flag is set and if Time out is reached exit */
mbed_official 340:28d1f895c6fe 806 while(__HAL_RTC_WAKEUPTIMER_GET_FLAG(hrtc, RTC_FLAG_WUTWF) == RESET)
mbed_official 340:28d1f895c6fe 807 {
mbed_official 340:28d1f895c6fe 808 if((HAL_GetTick()-tickstart) > RTC_TIMEOUT_VALUE)
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_TIMEOUT;
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_TIMEOUT;
mbed_official 340:28d1f895c6fe 819 }
mbed_official 340:28d1f895c6fe 820 }
mbed_official 340:28d1f895c6fe 821
mbed_official 441:d2c15dda23c1 822 /* Clear the Wake-up Timer clock source bits in CR register */
mbed_official 340:28d1f895c6fe 823 hrtc->Instance->CR &= (uint32_t)~RTC_CR_WUCKSEL;
mbed_official 340:28d1f895c6fe 824
mbed_official 340:28d1f895c6fe 825 /* Configure the clock source */
mbed_official 340:28d1f895c6fe 826 hrtc->Instance->CR |= (uint32_t)WakeUpClock;
mbed_official 340:28d1f895c6fe 827
mbed_official 441:d2c15dda23c1 828 /* Configure the Wake-up Timer counter */
mbed_official 340:28d1f895c6fe 829 hrtc->Instance->WUTR = (uint32_t)WakeUpCounter;
mbed_official 340:28d1f895c6fe 830
mbed_official 441:d2c15dda23c1 831 /* Enable the Wake-up Timer */
mbed_official 340:28d1f895c6fe 832 __HAL_RTC_WAKEUPTIMER_ENABLE(hrtc);
mbed_official 340:28d1f895c6fe 833
mbed_official 340:28d1f895c6fe 834 /* Enable the write protection for RTC registers */
mbed_official 340:28d1f895c6fe 835 __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc);
mbed_official 340:28d1f895c6fe 836
mbed_official 340:28d1f895c6fe 837 hrtc->State = HAL_RTC_STATE_READY;
mbed_official 340:28d1f895c6fe 838
mbed_official 340:28d1f895c6fe 839 /* Process Unlocked */
mbed_official 340:28d1f895c6fe 840 __HAL_UNLOCK(hrtc);
mbed_official 340:28d1f895c6fe 841
mbed_official 340:28d1f895c6fe 842 return HAL_OK;
mbed_official 340:28d1f895c6fe 843 }
mbed_official 340:28d1f895c6fe 844
mbed_official 340:28d1f895c6fe 845 /**
mbed_official 340:28d1f895c6fe 846 * @brief Sets wake up timer with interrupt
mbed_official 441:d2c15dda23c1 847 * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains
mbed_official 441:d2c15dda23c1 848 * the configuration information for RTC.
mbed_official 441:d2c15dda23c1 849 * @param WakeUpCounter: Wake up counter
mbed_official 441:d2c15dda23c1 850 * @param WakeUpClock: Wake up clock
mbed_official 340:28d1f895c6fe 851 * @retval HAL status
mbed_official 340:28d1f895c6fe 852 */
mbed_official 340:28d1f895c6fe 853 HAL_StatusTypeDef HAL_RTCEx_SetWakeUpTimer_IT(RTC_HandleTypeDef *hrtc, uint32_t WakeUpCounter, uint32_t WakeUpClock)
mbed_official 340:28d1f895c6fe 854 {
mbed_official 340:28d1f895c6fe 855 uint32_t tickstart = 0;
mbed_official 340:28d1f895c6fe 856
mbed_official 340:28d1f895c6fe 857 /* Check the parameters */
mbed_official 340:28d1f895c6fe 858 assert_param(IS_WAKEUP_CLOCK(WakeUpClock));
mbed_official 340:28d1f895c6fe 859 assert_param(IS_WAKEUP_COUNTER(WakeUpCounter));
mbed_official 340:28d1f895c6fe 860
mbed_official 340:28d1f895c6fe 861 /* Process Locked */
mbed_official 340:28d1f895c6fe 862 __HAL_LOCK(hrtc);
mbed_official 340:28d1f895c6fe 863
mbed_official 340:28d1f895c6fe 864 hrtc->State = HAL_RTC_STATE_BUSY;
mbed_official 340:28d1f895c6fe 865
mbed_official 340:28d1f895c6fe 866 /* Disable the write protection for RTC registers */
mbed_official 340:28d1f895c6fe 867 __HAL_RTC_WRITEPROTECTION_DISABLE(hrtc);
mbed_official 340:28d1f895c6fe 868
mbed_official 340:28d1f895c6fe 869 __HAL_RTC_WAKEUPTIMER_DISABLE(hrtc);
mbed_official 340:28d1f895c6fe 870
mbed_official 441:d2c15dda23c1 871 /* Get tick */
mbed_official 340:28d1f895c6fe 872 tickstart = HAL_GetTick();
mbed_official 340:28d1f895c6fe 873
mbed_official 340:28d1f895c6fe 874 /* Wait till RTC WUTWF flag is set and if Time out is reached exit */
mbed_official 340:28d1f895c6fe 875 while(__HAL_RTC_WAKEUPTIMER_GET_FLAG(hrtc, RTC_FLAG_WUTWF) == RESET)
mbed_official 340:28d1f895c6fe 876 {
mbed_official 340:28d1f895c6fe 877 if((HAL_GetTick()-tickstart) > RTC_TIMEOUT_VALUE)
mbed_official 340:28d1f895c6fe 878 {
mbed_official 340:28d1f895c6fe 879 /* Enable the write protection for RTC registers */
mbed_official 340:28d1f895c6fe 880 __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc);
mbed_official 340:28d1f895c6fe 881
mbed_official 340:28d1f895c6fe 882 hrtc->State = HAL_RTC_STATE_TIMEOUT;
mbed_official 340:28d1f895c6fe 883
mbed_official 340:28d1f895c6fe 884 /* Process Unlocked */
mbed_official 340:28d1f895c6fe 885 __HAL_UNLOCK(hrtc);
mbed_official 340:28d1f895c6fe 886
mbed_official 340:28d1f895c6fe 887 return HAL_TIMEOUT;
mbed_official 340:28d1f895c6fe 888 }
mbed_official 340:28d1f895c6fe 889 }
mbed_official 340:28d1f895c6fe 890
mbed_official 441:d2c15dda23c1 891 /* Configure the Wake-up Timer counter */
mbed_official 340:28d1f895c6fe 892 hrtc->Instance->WUTR = (uint32_t)WakeUpCounter;
mbed_official 340:28d1f895c6fe 893
mbed_official 441:d2c15dda23c1 894 /* Clear the Wake-up Timer clock source bits in CR register */
mbed_official 340:28d1f895c6fe 895 hrtc->Instance->CR &= (uint32_t)~RTC_CR_WUCKSEL;
mbed_official 340:28d1f895c6fe 896
mbed_official 340:28d1f895c6fe 897 /* Configure the clock source */
mbed_official 340:28d1f895c6fe 898 hrtc->Instance->CR |= (uint32_t)WakeUpClock;
mbed_official 340:28d1f895c6fe 899
mbed_official 340:28d1f895c6fe 900 /* RTC WakeUpTimer Interrupt Configuration: EXTI configuration */
mbed_official 340:28d1f895c6fe 901 __HAL_RTC_EXTI_ENABLE_IT(RTC_EXTI_LINE_WAKEUPTIMER_EVENT);
mbed_official 340:28d1f895c6fe 902
mbed_official 340:28d1f895c6fe 903 EXTI->RTSR |= RTC_EXTI_LINE_WAKEUPTIMER_EVENT;
mbed_official 340:28d1f895c6fe 904
mbed_official 340:28d1f895c6fe 905 /* Configure the Interrupt in the RTC_CR register */
mbed_official 340:28d1f895c6fe 906 __HAL_RTC_WAKEUPTIMER_ENABLE_IT(hrtc,RTC_IT_WUT);
mbed_official 340:28d1f895c6fe 907
mbed_official 441:d2c15dda23c1 908 /* Enable the Wake-up Timer */
mbed_official 340:28d1f895c6fe 909 __HAL_RTC_WAKEUPTIMER_ENABLE(hrtc);
mbed_official 340:28d1f895c6fe 910
mbed_official 340:28d1f895c6fe 911 /* Enable the write protection for RTC registers */
mbed_official 340:28d1f895c6fe 912 __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc);
mbed_official 340:28d1f895c6fe 913
mbed_official 340:28d1f895c6fe 914 hrtc->State = HAL_RTC_STATE_READY;
mbed_official 340:28d1f895c6fe 915
mbed_official 340:28d1f895c6fe 916 /* Process Unlocked */
mbed_official 340:28d1f895c6fe 917 __HAL_UNLOCK(hrtc);
mbed_official 340:28d1f895c6fe 918
mbed_official 340:28d1f895c6fe 919 return HAL_OK;
mbed_official 340:28d1f895c6fe 920 }
mbed_official 340:28d1f895c6fe 921
mbed_official 340:28d1f895c6fe 922 /**
mbed_official 340:28d1f895c6fe 923 * @brief Deactivates wake up timer counter.
mbed_official 441:d2c15dda23c1 924 * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains
mbed_official 441:d2c15dda23c1 925 * the configuration information for RTC.
mbed_official 340:28d1f895c6fe 926 * @retval HAL status
mbed_official 340:28d1f895c6fe 927 */
mbed_official 340:28d1f895c6fe 928 uint32_t HAL_RTCEx_DeactivateWakeUpTimer(RTC_HandleTypeDef *hrtc)
mbed_official 340:28d1f895c6fe 929 {
mbed_official 340:28d1f895c6fe 930 uint32_t tickstart = 0;
mbed_official 340:28d1f895c6fe 931
mbed_official 340:28d1f895c6fe 932 /* Process Locked */
mbed_official 340:28d1f895c6fe 933 __HAL_LOCK(hrtc);
mbed_official 340:28d1f895c6fe 934
mbed_official 340:28d1f895c6fe 935 hrtc->State = HAL_RTC_STATE_BUSY;
mbed_official 340:28d1f895c6fe 936
mbed_official 340:28d1f895c6fe 937 /* Disable the write protection for RTC registers */
mbed_official 340:28d1f895c6fe 938 __HAL_RTC_WRITEPROTECTION_DISABLE(hrtc);
mbed_official 340:28d1f895c6fe 939
mbed_official 441:d2c15dda23c1 940 /* Disable the Wake-up Timer */
mbed_official 340:28d1f895c6fe 941 __HAL_RTC_WAKEUPTIMER_DISABLE(hrtc);
mbed_official 340:28d1f895c6fe 942
mbed_official 340:28d1f895c6fe 943 /* In case of interrupt mode is used, the interrupt source must disabled */
mbed_official 340:28d1f895c6fe 944 __HAL_RTC_WAKEUPTIMER_DISABLE_IT(hrtc,RTC_IT_WUT);
mbed_official 340:28d1f895c6fe 945
mbed_official 441:d2c15dda23c1 946 /* Get tick */
mbed_official 340:28d1f895c6fe 947 tickstart = HAL_GetTick();
mbed_official 340:28d1f895c6fe 948
mbed_official 340:28d1f895c6fe 949 /* Wait till RTC WUTWF flag is set and if Time out is reached exit */
mbed_official 340:28d1f895c6fe 950 while(__HAL_RTC_WAKEUPTIMER_GET_FLAG(hrtc, RTC_FLAG_WUTWF) == RESET)
mbed_official 340:28d1f895c6fe 951 {
mbed_official 340:28d1f895c6fe 952 if((HAL_GetTick()-tickstart) > RTC_TIMEOUT_VALUE)
mbed_official 340:28d1f895c6fe 953 {
mbed_official 340:28d1f895c6fe 954 /* Enable the write protection for RTC registers */
mbed_official 340:28d1f895c6fe 955 __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc);
mbed_official 340:28d1f895c6fe 956
mbed_official 340:28d1f895c6fe 957 hrtc->State = HAL_RTC_STATE_TIMEOUT;
mbed_official 340:28d1f895c6fe 958
mbed_official 340:28d1f895c6fe 959 /* Process Unlocked */
mbed_official 340:28d1f895c6fe 960 __HAL_UNLOCK(hrtc);
mbed_official 340:28d1f895c6fe 961
mbed_official 340:28d1f895c6fe 962 return HAL_TIMEOUT;
mbed_official 340:28d1f895c6fe 963 }
mbed_official 340:28d1f895c6fe 964 }
mbed_official 340:28d1f895c6fe 965
mbed_official 340:28d1f895c6fe 966 /* Enable the write protection for RTC registers */
mbed_official 340:28d1f895c6fe 967 __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc);
mbed_official 340:28d1f895c6fe 968
mbed_official 340:28d1f895c6fe 969 hrtc->State = HAL_RTC_STATE_READY;
mbed_official 340:28d1f895c6fe 970
mbed_official 340:28d1f895c6fe 971 /* Process Unlocked */
mbed_official 340:28d1f895c6fe 972 __HAL_UNLOCK(hrtc);
mbed_official 340:28d1f895c6fe 973
mbed_official 340:28d1f895c6fe 974 return HAL_OK;
mbed_official 340:28d1f895c6fe 975 }
mbed_official 340:28d1f895c6fe 976
mbed_official 340:28d1f895c6fe 977 /**
mbed_official 340:28d1f895c6fe 978 * @brief Gets wake up timer counter.
mbed_official 441:d2c15dda23c1 979 * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains
mbed_official 441:d2c15dda23c1 980 * the configuration information for RTC.
mbed_official 340:28d1f895c6fe 981 * @retval Counter value
mbed_official 340:28d1f895c6fe 982 */
mbed_official 340:28d1f895c6fe 983 uint32_t HAL_RTCEx_GetWakeUpTimer(RTC_HandleTypeDef *hrtc)
mbed_official 340:28d1f895c6fe 984 {
mbed_official 340:28d1f895c6fe 985 /* Get the counter value */
mbed_official 340:28d1f895c6fe 986 return ((uint32_t)(hrtc->Instance->WUTR & RTC_WUTR_WUT));
mbed_official 340:28d1f895c6fe 987 }
mbed_official 340:28d1f895c6fe 988
mbed_official 340:28d1f895c6fe 989 /**
mbed_official 340:28d1f895c6fe 990 * @brief This function handles Wake Up Timer interrupt request.
mbed_official 441:d2c15dda23c1 991 * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains
mbed_official 441:d2c15dda23c1 992 * the configuration information for RTC.
mbed_official 340:28d1f895c6fe 993 * @retval None
mbed_official 340:28d1f895c6fe 994 */
mbed_official 340:28d1f895c6fe 995 void HAL_RTCEx_WakeUpTimerIRQHandler(RTC_HandleTypeDef *hrtc)
mbed_official 340:28d1f895c6fe 996 {
mbed_official 340:28d1f895c6fe 997 if(__HAL_RTC_WAKEUPTIMER_GET_IT(hrtc, RTC_IT_WUT))
mbed_official 340:28d1f895c6fe 998 {
mbed_official 340:28d1f895c6fe 999 /* Get the status of the Interrupt */
mbed_official 340:28d1f895c6fe 1000 if((uint32_t)(hrtc->Instance->CR & RTC_IT_WUT) != (uint32_t)RESET)
mbed_official 340:28d1f895c6fe 1001 {
mbed_official 340:28d1f895c6fe 1002 /* WAKEUPTIMER callback */
mbed_official 340:28d1f895c6fe 1003 HAL_RTCEx_WakeUpTimerEventCallback(hrtc);
mbed_official 340:28d1f895c6fe 1004
mbed_official 340:28d1f895c6fe 1005 /* Clear the WAKEUPTIMER interrupt pending bit */
mbed_official 340:28d1f895c6fe 1006 __HAL_RTC_WAKEUPTIMER_CLEAR_FLAG(hrtc, RTC_FLAG_WUTF);
mbed_official 340:28d1f895c6fe 1007 }
mbed_official 340:28d1f895c6fe 1008 }
mbed_official 340:28d1f895c6fe 1009
mbed_official 340:28d1f895c6fe 1010 /* Clear the EXTI's line Flag for RTC WakeUpTimer */
mbed_official 340:28d1f895c6fe 1011 __HAL_RTC_EXTI_CLEAR_FLAG(RTC_EXTI_LINE_WAKEUPTIMER_EVENT);
mbed_official 340:28d1f895c6fe 1012
mbed_official 340:28d1f895c6fe 1013 /* Change RTC state */
mbed_official 340:28d1f895c6fe 1014 hrtc->State = HAL_RTC_STATE_READY;
mbed_official 340:28d1f895c6fe 1015 }
mbed_official 340:28d1f895c6fe 1016
mbed_official 340:28d1f895c6fe 1017 /**
mbed_official 340:28d1f895c6fe 1018 * @brief Wake Up Timer callback.
mbed_official 441:d2c15dda23c1 1019 * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains
mbed_official 441:d2c15dda23c1 1020 * the configuration information for RTC.
mbed_official 340:28d1f895c6fe 1021 * @retval None
mbed_official 340:28d1f895c6fe 1022 */
mbed_official 340:28d1f895c6fe 1023 __weak void HAL_RTCEx_WakeUpTimerEventCallback(RTC_HandleTypeDef *hrtc)
mbed_official 340:28d1f895c6fe 1024 {
mbed_official 340:28d1f895c6fe 1025 /* NOTE : This function Should not be modified, when the callback is needed,
mbed_official 340:28d1f895c6fe 1026 the HAL_RTCEx_WakeUpTimerEventCallback could be implemented in the user file
mbed_official 340:28d1f895c6fe 1027 */
mbed_official 340:28d1f895c6fe 1028 }
mbed_official 340:28d1f895c6fe 1029
mbed_official 340:28d1f895c6fe 1030 /**
mbed_official 340:28d1f895c6fe 1031 * @brief This function handles Wake Up Timer Polling.
mbed_official 441:d2c15dda23c1 1032 * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains
mbed_official 441:d2c15dda23c1 1033 * the configuration information for RTC.
mbed_official 340:28d1f895c6fe 1034 * @param Timeout: Timeout duration
mbed_official 340:28d1f895c6fe 1035 * @retval HAL status
mbed_official 340:28d1f895c6fe 1036 */
mbed_official 340:28d1f895c6fe 1037 HAL_StatusTypeDef HAL_RTCEx_PollForWakeUpTimerEvent(RTC_HandleTypeDef *hrtc, uint32_t Timeout)
mbed_official 340:28d1f895c6fe 1038 {
mbed_official 340:28d1f895c6fe 1039 uint32_t tickstart = 0;
mbed_official 340:28d1f895c6fe 1040
mbed_official 441:d2c15dda23c1 1041 /* Get tick */
mbed_official 340:28d1f895c6fe 1042 tickstart = HAL_GetTick();
mbed_official 340:28d1f895c6fe 1043
mbed_official 340:28d1f895c6fe 1044 while(__HAL_RTC_WAKEUPTIMER_GET_FLAG(hrtc, RTC_FLAG_WUTF) == RESET)
mbed_official 340:28d1f895c6fe 1045 {
mbed_official 340:28d1f895c6fe 1046 if(Timeout != HAL_MAX_DELAY)
mbed_official 340:28d1f895c6fe 1047 {
mbed_official 340:28d1f895c6fe 1048 if((Timeout == 0) || ((HAL_GetTick() - tickstart) > Timeout))
mbed_official 340:28d1f895c6fe 1049 {
mbed_official 340:28d1f895c6fe 1050 hrtc->State = HAL_RTC_STATE_TIMEOUT;
mbed_official 340:28d1f895c6fe 1051
mbed_official 340:28d1f895c6fe 1052 return HAL_TIMEOUT;
mbed_official 340:28d1f895c6fe 1053 }
mbed_official 340:28d1f895c6fe 1054 }
mbed_official 340:28d1f895c6fe 1055 }
mbed_official 340:28d1f895c6fe 1056
mbed_official 340:28d1f895c6fe 1057 /* Clear the WAKEUPTIMER Flag */
mbed_official 340:28d1f895c6fe 1058 __HAL_RTC_WAKEUPTIMER_CLEAR_FLAG(hrtc, RTC_FLAG_WUTF);
mbed_official 340:28d1f895c6fe 1059
mbed_official 340:28d1f895c6fe 1060 /* Change RTC state */
mbed_official 340:28d1f895c6fe 1061 hrtc->State = HAL_RTC_STATE_READY;
mbed_official 340:28d1f895c6fe 1062
mbed_official 340:28d1f895c6fe 1063 return HAL_OK;
mbed_official 340:28d1f895c6fe 1064 }
mbed_official 340:28d1f895c6fe 1065
mbed_official 340:28d1f895c6fe 1066 /**
mbed_official 340:28d1f895c6fe 1067 * @}
mbed_official 340:28d1f895c6fe 1068 */
mbed_official 340:28d1f895c6fe 1069 #endif /* defined(STM32F071xB) || defined(STM32F072xB) || defined(STM32F078xx) || defined(STM32F091xC) || defined(STM32F098xx) */
mbed_official 340:28d1f895c6fe 1070
mbed_official 340:28d1f895c6fe 1071 /** @defgroup RTCEx_Exported_Functions_Group3 Extension Peripheral Control functions
mbed_official 340:28d1f895c6fe 1072 * @brief Extension Peripheral Control functions
mbed_official 340:28d1f895c6fe 1073 *
mbed_official 340:28d1f895c6fe 1074 @verbatim
mbed_official 340:28d1f895c6fe 1075 ===============================================================================
mbed_official 340:28d1f895c6fe 1076 ##### Extension Peripheral Control functions #####
mbed_official 340:28d1f895c6fe 1077 ===============================================================================
mbed_official 340:28d1f895c6fe 1078 [..]
mbed_official 340:28d1f895c6fe 1079 This subsection provides functions allowing to
mbed_official 441:d2c15dda23c1 1080 (+) Write a data in a specified RTC Backup data register
mbed_official 340:28d1f895c6fe 1081 (+) Read a data in a specified RTC Backup data register
mbed_official 441:d2c15dda23c1 1082 (+) Set the Coarse calibration parameters.
mbed_official 441:d2c15dda23c1 1083 (+) Deactivate the Coarse calibration parameters
mbed_official 441:d2c15dda23c1 1084 (+) Set the Smooth calibration parameters.
mbed_official 441:d2c15dda23c1 1085 (+) Configure the Synchronization Shift Control Settings.
mbed_official 441:d2c15dda23c1 1086 (+) Configure the Calibration Pinout (RTC_CALIB) Selection (1Hz or 512Hz).
mbed_official 441:d2c15dda23c1 1087 (+) Deactivate the Calibration Pinout (RTC_CALIB) Selection (1Hz or 512Hz).
mbed_official 441:d2c15dda23c1 1088 (+) Enable the RTC reference clock detection.
mbed_official 340:28d1f895c6fe 1089 (+) Disable the RTC reference clock detection.
mbed_official 441:d2c15dda23c1 1090 (+) Enable the Bypass Shadow feature.
mbed_official 441:d2c15dda23c1 1091 (+) Disable the Bypass Shadow feature.
mbed_official 340:28d1f895c6fe 1092
mbed_official 340:28d1f895c6fe 1093 @endverbatim
mbed_official 340:28d1f895c6fe 1094 * @{
mbed_official 340:28d1f895c6fe 1095 */
mbed_official 340:28d1f895c6fe 1096
mbed_official 441:d2c15dda23c1 1097 #if !defined(STM32F030x6) && !defined(STM32F030x8) && !defined(STM32F070x6) && !defined(STM32F070xB) && !defined(STM32F030xC)
mbed_official 340:28d1f895c6fe 1098 /**
mbed_official 340:28d1f895c6fe 1099 * @brief Writes a data in a specified RTC Backup data register.
mbed_official 441:d2c15dda23c1 1100 * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains
mbed_official 441:d2c15dda23c1 1101 * the configuration information for RTC.
mbed_official 340:28d1f895c6fe 1102 * @param BackupRegister: RTC Backup data Register number.
mbed_official 340:28d1f895c6fe 1103 * This parameter can be: RTC_BKP_DRx where x can be from 0 to 4 to
mbed_official 340:28d1f895c6fe 1104 * specify the register.
mbed_official 340:28d1f895c6fe 1105 * @param Data: Data to be written in the specified RTC Backup data register.
mbed_official 340:28d1f895c6fe 1106 * @retval None
mbed_official 340:28d1f895c6fe 1107 */
mbed_official 340:28d1f895c6fe 1108 void HAL_RTCEx_BKUPWrite(RTC_HandleTypeDef *hrtc, uint32_t BackupRegister, uint32_t Data)
mbed_official 340:28d1f895c6fe 1109 {
mbed_official 340:28d1f895c6fe 1110 uint32_t tmp = 0;
mbed_official 340:28d1f895c6fe 1111
mbed_official 340:28d1f895c6fe 1112 /* Check the parameters */
mbed_official 340:28d1f895c6fe 1113 assert_param(IS_RTC_BKP(BackupRegister));
mbed_official 340:28d1f895c6fe 1114
mbed_official 340:28d1f895c6fe 1115 tmp = (uint32_t)&(hrtc->Instance->BKP0R);
mbed_official 340:28d1f895c6fe 1116 tmp += (BackupRegister * 4);
mbed_official 340:28d1f895c6fe 1117
mbed_official 340:28d1f895c6fe 1118 /* Write the specified register */
mbed_official 340:28d1f895c6fe 1119 *(__IO uint32_t *)tmp = (uint32_t)Data;
mbed_official 340:28d1f895c6fe 1120 }
mbed_official 340:28d1f895c6fe 1121
mbed_official 340:28d1f895c6fe 1122 /**
mbed_official 340:28d1f895c6fe 1123 * @brief Reads data from the specified RTC Backup data Register.
mbed_official 441:d2c15dda23c1 1124 * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains
mbed_official 441:d2c15dda23c1 1125 * the configuration information for RTC.
mbed_official 340:28d1f895c6fe 1126 * @param BackupRegister: RTC Backup data Register number.
mbed_official 340:28d1f895c6fe 1127 * This parameter can be: RTC_BKP_DRx where x can be from 0 to 4 to
mbed_official 340:28d1f895c6fe 1128 * specify the register.
mbed_official 340:28d1f895c6fe 1129 * @retval Read value
mbed_official 340:28d1f895c6fe 1130 */
mbed_official 340:28d1f895c6fe 1131 uint32_t HAL_RTCEx_BKUPRead(RTC_HandleTypeDef *hrtc, uint32_t BackupRegister)
mbed_official 340:28d1f895c6fe 1132 {
mbed_official 340:28d1f895c6fe 1133 uint32_t tmp = 0;
mbed_official 340:28d1f895c6fe 1134
mbed_official 340:28d1f895c6fe 1135 /* Check the parameters */
mbed_official 340:28d1f895c6fe 1136 assert_param(IS_RTC_BKP(BackupRegister));
mbed_official 340:28d1f895c6fe 1137
mbed_official 340:28d1f895c6fe 1138 tmp = (uint32_t)&(hrtc->Instance->BKP0R);
mbed_official 340:28d1f895c6fe 1139 tmp += (BackupRegister * 4);
mbed_official 340:28d1f895c6fe 1140
mbed_official 340:28d1f895c6fe 1141 /* Read the specified register */
mbed_official 340:28d1f895c6fe 1142 return (*(__IO uint32_t *)tmp);
mbed_official 340:28d1f895c6fe 1143 }
mbed_official 441:d2c15dda23c1 1144 #endif /* !defined(STM32F030x6) && !defined(STM32F030x8) && !defined(STM32F070x6) && !defined(STM32F070xB) && !defined(STM32F030xC) */
mbed_official 340:28d1f895c6fe 1145
mbed_official 340:28d1f895c6fe 1146 /**
mbed_official 340:28d1f895c6fe 1147 * @brief Sets the Smooth calibration parameters.
mbed_official 441:d2c15dda23c1 1148 * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains
mbed_official 441:d2c15dda23c1 1149 * the configuration information for RTC.
mbed_official 340:28d1f895c6fe 1150 * @param SmoothCalibPeriod: Select the Smooth Calibration Period.
mbed_official 340:28d1f895c6fe 1151 * This parameter can be can be one of the following values :
mbed_official 441:d2c15dda23c1 1152 * @arg RTC_SMOOTHCALIB_PERIOD_32SEC: The smooth calibration period is 32s.
mbed_official 441:d2c15dda23c1 1153 * @arg RTC_SMOOTHCALIB_PERIOD_16SEC: The smooth calibration period is 16s.
mbed_official 441:d2c15dda23c1 1154 * @arg RTC_SMOOTHCALIB_PERIOD_8SEC: The smooth calibration period is 8s.
mbed_official 340:28d1f895c6fe 1155 * @param SmoothCalibPlusPulses: Select to Set or reset the CALP bit.
mbed_official 340:28d1f895c6fe 1156 * This parameter can be one of the following values:
mbed_official 441:d2c15dda23c1 1157 * @arg RTC_SMOOTHCALIB_PLUSPULSES_SET: Add one RTCCLK pulse every 2*11 pulses.
mbed_official 340:28d1f895c6fe 1158 * @arg RTC_SMOOTHCALIB_PLUSPULSES_RESET: No RTCCLK pulses are added.
mbed_official 340:28d1f895c6fe 1159 * @param SmouthCalibMinusPulsesValue: Select the value of CALM[8:0] bits.
mbed_official 340:28d1f895c6fe 1160 * This parameter can be one any value from 0 to 0x000001FF.
mbed_official 340:28d1f895c6fe 1161 * @note To deactivate the smooth calibration, the field SmoothCalibPlusPulses
mbed_official 340:28d1f895c6fe 1162 * must be equal to SMOOTHCALIB_PLUSPULSES_RESET and the field
mbed_official 441:d2c15dda23c1 1163 * SmouthCalibMinusPulsesValue must be equal to 0.
mbed_official 340:28d1f895c6fe 1164 * @retval HAL status
mbed_official 340:28d1f895c6fe 1165 */
mbed_official 340:28d1f895c6fe 1166 HAL_StatusTypeDef HAL_RTCEx_SetSmoothCalib(RTC_HandleTypeDef* hrtc, uint32_t SmoothCalibPeriod, uint32_t SmoothCalibPlusPulses, uint32_t SmouthCalibMinusPulsesValue)
mbed_official 340:28d1f895c6fe 1167 {
mbed_official 340:28d1f895c6fe 1168 uint32_t tickstart = 0;
mbed_official 340:28d1f895c6fe 1169
mbed_official 340:28d1f895c6fe 1170 /* Check the parameters */
mbed_official 340:28d1f895c6fe 1171 assert_param(IS_RTC_SMOOTH_CALIB_PERIOD(SmoothCalibPeriod));
mbed_official 340:28d1f895c6fe 1172 assert_param(IS_RTC_SMOOTH_CALIB_PLUS(SmoothCalibPlusPulses));
mbed_official 340:28d1f895c6fe 1173 assert_param(IS_RTC_SMOOTH_CALIB_MINUS(SmouthCalibMinusPulsesValue));
mbed_official 340:28d1f895c6fe 1174
mbed_official 340:28d1f895c6fe 1175 /* Process Locked */
mbed_official 340:28d1f895c6fe 1176 __HAL_LOCK(hrtc);
mbed_official 340:28d1f895c6fe 1177
mbed_official 340:28d1f895c6fe 1178 hrtc->State = HAL_RTC_STATE_BUSY;
mbed_official 340:28d1f895c6fe 1179
mbed_official 340:28d1f895c6fe 1180 /* Disable the write protection for RTC registers */
mbed_official 340:28d1f895c6fe 1181 __HAL_RTC_WRITEPROTECTION_DISABLE(hrtc);
mbed_official 340:28d1f895c6fe 1182
mbed_official 340:28d1f895c6fe 1183 /* check if a calibration is pending*/
mbed_official 340:28d1f895c6fe 1184 if((hrtc->Instance->ISR & RTC_ISR_RECALPF) != RESET)
mbed_official 340:28d1f895c6fe 1185 {
mbed_official 441:d2c15dda23c1 1186 /* Get tick */
mbed_official 340:28d1f895c6fe 1187 tickstart = HAL_GetTick();
mbed_official 340:28d1f895c6fe 1188
mbed_official 340:28d1f895c6fe 1189 /* check if a calibration is pending*/
mbed_official 340:28d1f895c6fe 1190 while((hrtc->Instance->ISR & RTC_ISR_RECALPF) != RESET)
mbed_official 340:28d1f895c6fe 1191 {
mbed_official 340:28d1f895c6fe 1192 if((HAL_GetTick()-tickstart) > RTC_TIMEOUT_VALUE)
mbed_official 340:28d1f895c6fe 1193 {
mbed_official 340:28d1f895c6fe 1194 /* Enable the write protection for RTC registers */
mbed_official 340:28d1f895c6fe 1195 __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc);
mbed_official 340:28d1f895c6fe 1196
mbed_official 340:28d1f895c6fe 1197 /* Change RTC state */
mbed_official 340:28d1f895c6fe 1198 hrtc->State = HAL_RTC_STATE_TIMEOUT;
mbed_official 340:28d1f895c6fe 1199
mbed_official 340:28d1f895c6fe 1200 /* Process Unlocked */
mbed_official 340:28d1f895c6fe 1201 __HAL_UNLOCK(hrtc);
mbed_official 340:28d1f895c6fe 1202
mbed_official 340:28d1f895c6fe 1203 return HAL_TIMEOUT;
mbed_official 340:28d1f895c6fe 1204 }
mbed_official 340:28d1f895c6fe 1205 }
mbed_official 340:28d1f895c6fe 1206 }
mbed_official 340:28d1f895c6fe 1207
mbed_official 340:28d1f895c6fe 1208 /* Configure the Smooth calibration settings */
mbed_official 340:28d1f895c6fe 1209 hrtc->Instance->CALR = (uint32_t)((uint32_t)SmoothCalibPeriod | (uint32_t)SmoothCalibPlusPulses | (uint32_t)SmouthCalibMinusPulsesValue);
mbed_official 340:28d1f895c6fe 1210
mbed_official 340:28d1f895c6fe 1211 /* Enable the write protection for RTC registers */
mbed_official 340:28d1f895c6fe 1212 __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc);
mbed_official 340:28d1f895c6fe 1213
mbed_official 340:28d1f895c6fe 1214 /* Change RTC state */
mbed_official 340:28d1f895c6fe 1215 hrtc->State = HAL_RTC_STATE_READY;
mbed_official 340:28d1f895c6fe 1216
mbed_official 340:28d1f895c6fe 1217 /* Process Unlocked */
mbed_official 340:28d1f895c6fe 1218 __HAL_UNLOCK(hrtc);
mbed_official 340:28d1f895c6fe 1219
mbed_official 340:28d1f895c6fe 1220 return HAL_OK;
mbed_official 340:28d1f895c6fe 1221 }
mbed_official 340:28d1f895c6fe 1222
mbed_official 340:28d1f895c6fe 1223 /**
mbed_official 340:28d1f895c6fe 1224 * @brief Configures the Synchronization Shift Control Settings.
mbed_official 340:28d1f895c6fe 1225 * @note When REFCKON is set, firmware must not write to Shift control register.
mbed_official 441:d2c15dda23c1 1226 * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains
mbed_official 441:d2c15dda23c1 1227 * the configuration information for RTC.
mbed_official 340:28d1f895c6fe 1228 * @param ShiftAdd1S: Select to add or not 1 second to the time calendar.
mbed_official 340:28d1f895c6fe 1229 * This parameter can be one of the following values :
mbed_official 340:28d1f895c6fe 1230 * @arg RTC_SHIFTADD1S_SET: Add one second to the clock calendar.
mbed_official 340:28d1f895c6fe 1231 * @arg RTC_SHIFTADD1S_RESET: No effect.
mbed_official 340:28d1f895c6fe 1232 * @param ShiftSubFS: Select the number of Second Fractions to substitute.
mbed_official 340:28d1f895c6fe 1233 * This parameter can be one any value from 0 to 0x7FFF.
mbed_official 340:28d1f895c6fe 1234 * @retval HAL status
mbed_official 340:28d1f895c6fe 1235 */
mbed_official 340:28d1f895c6fe 1236 HAL_StatusTypeDef HAL_RTCEx_SetSynchroShift(RTC_HandleTypeDef* hrtc, uint32_t ShiftAdd1S, uint32_t ShiftSubFS)
mbed_official 340:28d1f895c6fe 1237 {
mbed_official 340:28d1f895c6fe 1238 uint32_t tickstart = 0;
mbed_official 340:28d1f895c6fe 1239
mbed_official 340:28d1f895c6fe 1240 /* Check the parameters */
mbed_official 340:28d1f895c6fe 1241 assert_param(IS_RTC_SHIFT_ADD1S(ShiftAdd1S));
mbed_official 340:28d1f895c6fe 1242 assert_param(IS_RTC_SHIFT_SUBFS(ShiftSubFS));
mbed_official 340:28d1f895c6fe 1243
mbed_official 340:28d1f895c6fe 1244 /* Process Locked */
mbed_official 340:28d1f895c6fe 1245 __HAL_LOCK(hrtc);
mbed_official 340:28d1f895c6fe 1246
mbed_official 340:28d1f895c6fe 1247 hrtc->State = HAL_RTC_STATE_BUSY;
mbed_official 340:28d1f895c6fe 1248
mbed_official 340:28d1f895c6fe 1249 /* Disable the write protection for RTC registers */
mbed_official 340:28d1f895c6fe 1250 __HAL_RTC_WRITEPROTECTION_DISABLE(hrtc);
mbed_official 340:28d1f895c6fe 1251
mbed_official 441:d2c15dda23c1 1252 /* Get tick */
mbed_official 340:28d1f895c6fe 1253 tickstart = HAL_GetTick();
mbed_official 340:28d1f895c6fe 1254
mbed_official 340:28d1f895c6fe 1255 /* Wait until the shift is completed*/
mbed_official 340:28d1f895c6fe 1256 while((hrtc->Instance->ISR & RTC_ISR_SHPF) != RESET)
mbed_official 340:28d1f895c6fe 1257 {
mbed_official 340:28d1f895c6fe 1258 if((HAL_GetTick()-tickstart) > RTC_TIMEOUT_VALUE)
mbed_official 340:28d1f895c6fe 1259 {
mbed_official 340:28d1f895c6fe 1260 /* Enable the write protection for RTC registers */
mbed_official 340:28d1f895c6fe 1261 __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc);
mbed_official 340:28d1f895c6fe 1262
mbed_official 340:28d1f895c6fe 1263 hrtc->State = HAL_RTC_STATE_TIMEOUT;
mbed_official 340:28d1f895c6fe 1264
mbed_official 340:28d1f895c6fe 1265 /* Process Unlocked */
mbed_official 340:28d1f895c6fe 1266 __HAL_UNLOCK(hrtc);
mbed_official 340:28d1f895c6fe 1267
mbed_official 340:28d1f895c6fe 1268 return HAL_TIMEOUT;
mbed_official 340:28d1f895c6fe 1269 }
mbed_official 340:28d1f895c6fe 1270 }
mbed_official 340:28d1f895c6fe 1271
mbed_official 340:28d1f895c6fe 1272 /* Check if the reference clock detection is disabled */
mbed_official 340:28d1f895c6fe 1273 if((hrtc->Instance->CR & RTC_CR_REFCKON) == RESET)
mbed_official 340:28d1f895c6fe 1274 {
mbed_official 340:28d1f895c6fe 1275 /* Configure the Shift settings */
mbed_official 340:28d1f895c6fe 1276 hrtc->Instance->SHIFTR = (uint32_t)(uint32_t)(ShiftSubFS) | (uint32_t)(ShiftAdd1S);
mbed_official 340:28d1f895c6fe 1277
mbed_official 340:28d1f895c6fe 1278 /* If RTC_CR_BYPSHAD bit = 0, wait for synchro else this check is not needed */
mbed_official 340:28d1f895c6fe 1279 if((hrtc->Instance->CR & RTC_CR_BYPSHAD) == RESET)
mbed_official 340:28d1f895c6fe 1280 {
mbed_official 340:28d1f895c6fe 1281 if(HAL_RTC_WaitForSynchro(hrtc) != HAL_OK)
mbed_official 340:28d1f895c6fe 1282 {
mbed_official 340:28d1f895c6fe 1283 /* Enable the write protection for RTC registers */
mbed_official 340:28d1f895c6fe 1284 __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc);
mbed_official 340:28d1f895c6fe 1285
mbed_official 340:28d1f895c6fe 1286 hrtc->State = HAL_RTC_STATE_ERROR;
mbed_official 340:28d1f895c6fe 1287
mbed_official 340:28d1f895c6fe 1288 /* Process Unlocked */
mbed_official 340:28d1f895c6fe 1289 __HAL_UNLOCK(hrtc);
mbed_official 340:28d1f895c6fe 1290
mbed_official 340:28d1f895c6fe 1291 return HAL_ERROR;
mbed_official 340:28d1f895c6fe 1292 }
mbed_official 340:28d1f895c6fe 1293 }
mbed_official 340:28d1f895c6fe 1294 }
mbed_official 340:28d1f895c6fe 1295 else
mbed_official 340:28d1f895c6fe 1296 {
mbed_official 340:28d1f895c6fe 1297 /* Enable the write protection for RTC registers */
mbed_official 340:28d1f895c6fe 1298 __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc);
mbed_official 340:28d1f895c6fe 1299
mbed_official 340:28d1f895c6fe 1300 /* Change RTC state */
mbed_official 340:28d1f895c6fe 1301 hrtc->State = HAL_RTC_STATE_ERROR;
mbed_official 340:28d1f895c6fe 1302
mbed_official 340:28d1f895c6fe 1303 /* Process Unlocked */
mbed_official 340:28d1f895c6fe 1304 __HAL_UNLOCK(hrtc);
mbed_official 340:28d1f895c6fe 1305
mbed_official 340:28d1f895c6fe 1306 return HAL_ERROR;
mbed_official 340:28d1f895c6fe 1307 }
mbed_official 340:28d1f895c6fe 1308
mbed_official 340:28d1f895c6fe 1309 /* Enable the write protection for RTC registers */
mbed_official 340:28d1f895c6fe 1310 __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc);
mbed_official 340:28d1f895c6fe 1311
mbed_official 340:28d1f895c6fe 1312 /* Change RTC state */
mbed_official 340:28d1f895c6fe 1313 hrtc->State = HAL_RTC_STATE_READY;
mbed_official 340:28d1f895c6fe 1314
mbed_official 340:28d1f895c6fe 1315 /* Process Unlocked */
mbed_official 340:28d1f895c6fe 1316 __HAL_UNLOCK(hrtc);
mbed_official 340:28d1f895c6fe 1317
mbed_official 340:28d1f895c6fe 1318 return HAL_OK;
mbed_official 340:28d1f895c6fe 1319 }
mbed_official 340:28d1f895c6fe 1320
mbed_official 340:28d1f895c6fe 1321 /**
mbed_official 340:28d1f895c6fe 1322 * @brief Configures the Calibration Pinout (RTC_CALIB) Selection (1Hz or 512Hz).
mbed_official 441:d2c15dda23c1 1323 * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains
mbed_official 441:d2c15dda23c1 1324 * the configuration information for RTC.
mbed_official 340:28d1f895c6fe 1325 * @param CalibOutput : Select the Calibration output Selection .
mbed_official 340:28d1f895c6fe 1326 * This parameter can be one of the following values:
mbed_official 340:28d1f895c6fe 1327 * @arg RTC_CALIBOUTPUT_512HZ: A signal has a regular waveform at 512Hz.
mbed_official 340:28d1f895c6fe 1328 * @arg RTC_CALIBOUTPUT_1HZ: A signal has a regular waveform at 1Hz.
mbed_official 340:28d1f895c6fe 1329 * @retval HAL status
mbed_official 340:28d1f895c6fe 1330 */
mbed_official 340:28d1f895c6fe 1331 HAL_StatusTypeDef HAL_RTCEx_SetCalibrationOutPut(RTC_HandleTypeDef* hrtc, uint32_t CalibOutput)
mbed_official 340:28d1f895c6fe 1332 {
mbed_official 340:28d1f895c6fe 1333 /* Check the parameters */
mbed_official 340:28d1f895c6fe 1334 assert_param(IS_RTC_CALIB_OUTPUT(CalibOutput));
mbed_official 340:28d1f895c6fe 1335
mbed_official 340:28d1f895c6fe 1336 /* Process Locked */
mbed_official 340:28d1f895c6fe 1337 __HAL_LOCK(hrtc);
mbed_official 340:28d1f895c6fe 1338
mbed_official 340:28d1f895c6fe 1339 hrtc->State = HAL_RTC_STATE_BUSY;
mbed_official 340:28d1f895c6fe 1340
mbed_official 340:28d1f895c6fe 1341 /* Disable the write protection for RTC registers */
mbed_official 340:28d1f895c6fe 1342 __HAL_RTC_WRITEPROTECTION_DISABLE(hrtc);
mbed_official 340:28d1f895c6fe 1343
mbed_official 340:28d1f895c6fe 1344 /* Clear flags before config */
mbed_official 340:28d1f895c6fe 1345 hrtc->Instance->CR &= (uint32_t)~RTC_CR_COSEL;
mbed_official 340:28d1f895c6fe 1346
mbed_official 340:28d1f895c6fe 1347 /* Configure the RTC_CR register */
mbed_official 340:28d1f895c6fe 1348 hrtc->Instance->CR |= (uint32_t)CalibOutput;
mbed_official 340:28d1f895c6fe 1349
mbed_official 340:28d1f895c6fe 1350 __HAL_RTC_CALIBRATION_OUTPUT_ENABLE(hrtc);
mbed_official 340:28d1f895c6fe 1351
mbed_official 340:28d1f895c6fe 1352 /* Enable the write protection for RTC registers */
mbed_official 340:28d1f895c6fe 1353 __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc);
mbed_official 340:28d1f895c6fe 1354
mbed_official 340:28d1f895c6fe 1355 /* Change RTC state */
mbed_official 340:28d1f895c6fe 1356 hrtc->State = HAL_RTC_STATE_READY;
mbed_official 340:28d1f895c6fe 1357
mbed_official 340:28d1f895c6fe 1358 /* Process Unlocked */
mbed_official 340:28d1f895c6fe 1359 __HAL_UNLOCK(hrtc);
mbed_official 340:28d1f895c6fe 1360
mbed_official 340:28d1f895c6fe 1361 return HAL_OK;
mbed_official 340:28d1f895c6fe 1362 }
mbed_official 340:28d1f895c6fe 1363
mbed_official 340:28d1f895c6fe 1364 /**
mbed_official 340:28d1f895c6fe 1365 * @brief Deactivates the Calibration Pinout (RTC_CALIB) Selection (1Hz or 512Hz).
mbed_official 441:d2c15dda23c1 1366 * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains
mbed_official 441:d2c15dda23c1 1367 * the configuration information for RTC.
mbed_official 340:28d1f895c6fe 1368 * @retval HAL status
mbed_official 340:28d1f895c6fe 1369 */
mbed_official 340:28d1f895c6fe 1370 HAL_StatusTypeDef HAL_RTCEx_DeactivateCalibrationOutPut(RTC_HandleTypeDef* hrtc)
mbed_official 340:28d1f895c6fe 1371 {
mbed_official 340:28d1f895c6fe 1372 /* Process Locked */
mbed_official 340:28d1f895c6fe 1373 __HAL_LOCK(hrtc);
mbed_official 340:28d1f895c6fe 1374
mbed_official 340:28d1f895c6fe 1375 hrtc->State = HAL_RTC_STATE_BUSY;
mbed_official 340:28d1f895c6fe 1376
mbed_official 340:28d1f895c6fe 1377 /* Disable the write protection for RTC registers */
mbed_official 340:28d1f895c6fe 1378 __HAL_RTC_WRITEPROTECTION_DISABLE(hrtc);
mbed_official 340:28d1f895c6fe 1379
mbed_official 340:28d1f895c6fe 1380 __HAL_RTC_CALIBRATION_OUTPUT_DISABLE(hrtc);
mbed_official 340:28d1f895c6fe 1381
mbed_official 340:28d1f895c6fe 1382 /* Enable the write protection for RTC registers */
mbed_official 340:28d1f895c6fe 1383 __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc);
mbed_official 340:28d1f895c6fe 1384
mbed_official 340:28d1f895c6fe 1385 /* Change RTC state */
mbed_official 340:28d1f895c6fe 1386 hrtc->State = HAL_RTC_STATE_READY;
mbed_official 340:28d1f895c6fe 1387
mbed_official 340:28d1f895c6fe 1388 /* Process Unlocked */
mbed_official 340:28d1f895c6fe 1389 __HAL_UNLOCK(hrtc);
mbed_official 340:28d1f895c6fe 1390
mbed_official 340:28d1f895c6fe 1391 return HAL_OK;
mbed_official 340:28d1f895c6fe 1392 }
mbed_official 340:28d1f895c6fe 1393
mbed_official 340:28d1f895c6fe 1394 /**
mbed_official 340:28d1f895c6fe 1395 * @brief Enables the RTC reference clock detection.
mbed_official 441:d2c15dda23c1 1396 * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains
mbed_official 441:d2c15dda23c1 1397 * the configuration information for RTC.
mbed_official 340:28d1f895c6fe 1398 * @retval HAL status
mbed_official 340:28d1f895c6fe 1399 */
mbed_official 340:28d1f895c6fe 1400 HAL_StatusTypeDef HAL_RTCEx_SetRefClock(RTC_HandleTypeDef* hrtc)
mbed_official 340:28d1f895c6fe 1401 {
mbed_official 340:28d1f895c6fe 1402 /* Process Locked */
mbed_official 340:28d1f895c6fe 1403 __HAL_LOCK(hrtc);
mbed_official 340:28d1f895c6fe 1404
mbed_official 340:28d1f895c6fe 1405 hrtc->State = HAL_RTC_STATE_BUSY;
mbed_official 340:28d1f895c6fe 1406
mbed_official 340:28d1f895c6fe 1407 /* Disable the write protection for RTC registers */
mbed_official 340:28d1f895c6fe 1408 __HAL_RTC_WRITEPROTECTION_DISABLE(hrtc);
mbed_official 340:28d1f895c6fe 1409
mbed_official 340:28d1f895c6fe 1410 /* Set Initialization mode */
mbed_official 340:28d1f895c6fe 1411 if(RTC_EnterInitMode(hrtc) != HAL_OK)
mbed_official 340:28d1f895c6fe 1412 {
mbed_official 340:28d1f895c6fe 1413 /* Enable the write protection for RTC registers */
mbed_official 340:28d1f895c6fe 1414 __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc);
mbed_official 340:28d1f895c6fe 1415
mbed_official 340:28d1f895c6fe 1416 /* Set RTC state*/
mbed_official 340:28d1f895c6fe 1417 hrtc->State = HAL_RTC_STATE_ERROR;
mbed_official 340:28d1f895c6fe 1418
mbed_official 340:28d1f895c6fe 1419 /* Process Unlocked */
mbed_official 340:28d1f895c6fe 1420 __HAL_UNLOCK(hrtc);
mbed_official 340:28d1f895c6fe 1421
mbed_official 340:28d1f895c6fe 1422 return HAL_ERROR;
mbed_official 340:28d1f895c6fe 1423 }
mbed_official 340:28d1f895c6fe 1424 else
mbed_official 340:28d1f895c6fe 1425 {
mbed_official 340:28d1f895c6fe 1426 __HAL_RTC_CLOCKREF_DETECTION_ENABLE(hrtc);
mbed_official 340:28d1f895c6fe 1427
mbed_official 340:28d1f895c6fe 1428 /* Exit Initialization mode */
mbed_official 340:28d1f895c6fe 1429 hrtc->Instance->ISR &= (uint32_t)~RTC_ISR_INIT;
mbed_official 340:28d1f895c6fe 1430 }
mbed_official 340:28d1f895c6fe 1431
mbed_official 340:28d1f895c6fe 1432 /* Enable the write protection for RTC registers */
mbed_official 340:28d1f895c6fe 1433 __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc);
mbed_official 340:28d1f895c6fe 1434
mbed_official 340:28d1f895c6fe 1435 /* Change RTC state */
mbed_official 340:28d1f895c6fe 1436 hrtc->State = HAL_RTC_STATE_READY;
mbed_official 340:28d1f895c6fe 1437
mbed_official 340:28d1f895c6fe 1438 /* Process Unlocked */
mbed_official 340:28d1f895c6fe 1439 __HAL_UNLOCK(hrtc);
mbed_official 340:28d1f895c6fe 1440
mbed_official 340:28d1f895c6fe 1441 return HAL_OK;
mbed_official 340:28d1f895c6fe 1442 }
mbed_official 340:28d1f895c6fe 1443
mbed_official 340:28d1f895c6fe 1444 /**
mbed_official 340:28d1f895c6fe 1445 * @brief Disable the RTC reference clock detection.
mbed_official 441:d2c15dda23c1 1446 * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains
mbed_official 441:d2c15dda23c1 1447 * the configuration information for RTC.
mbed_official 340:28d1f895c6fe 1448 * @retval HAL status
mbed_official 340:28d1f895c6fe 1449 */
mbed_official 340:28d1f895c6fe 1450 HAL_StatusTypeDef HAL_RTCEx_DeactivateRefClock(RTC_HandleTypeDef* hrtc)
mbed_official 340:28d1f895c6fe 1451 {
mbed_official 340:28d1f895c6fe 1452 /* Process Locked */
mbed_official 340:28d1f895c6fe 1453 __HAL_LOCK(hrtc);
mbed_official 340:28d1f895c6fe 1454
mbed_official 340:28d1f895c6fe 1455 hrtc->State = HAL_RTC_STATE_BUSY;
mbed_official 340:28d1f895c6fe 1456
mbed_official 340:28d1f895c6fe 1457 /* Disable the write protection for RTC registers */
mbed_official 340:28d1f895c6fe 1458 __HAL_RTC_WRITEPROTECTION_DISABLE(hrtc);
mbed_official 340:28d1f895c6fe 1459
mbed_official 340:28d1f895c6fe 1460 /* Set Initialization mode */
mbed_official 340:28d1f895c6fe 1461 if(RTC_EnterInitMode(hrtc) != HAL_OK)
mbed_official 340:28d1f895c6fe 1462 {
mbed_official 340:28d1f895c6fe 1463 /* Enable the write protection for RTC registers */
mbed_official 340:28d1f895c6fe 1464 __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc);
mbed_official 340:28d1f895c6fe 1465
mbed_official 340:28d1f895c6fe 1466 /* Set RTC state*/
mbed_official 340:28d1f895c6fe 1467 hrtc->State = HAL_RTC_STATE_ERROR;
mbed_official 340:28d1f895c6fe 1468
mbed_official 340:28d1f895c6fe 1469 /* Process Unlocked */
mbed_official 340:28d1f895c6fe 1470 __HAL_UNLOCK(hrtc);
mbed_official 340:28d1f895c6fe 1471
mbed_official 340:28d1f895c6fe 1472 return HAL_ERROR;
mbed_official 340:28d1f895c6fe 1473 }
mbed_official 340:28d1f895c6fe 1474 else
mbed_official 340:28d1f895c6fe 1475 {
mbed_official 340:28d1f895c6fe 1476 __HAL_RTC_CLOCKREF_DETECTION_DISABLE(hrtc);
mbed_official 340:28d1f895c6fe 1477
mbed_official 340:28d1f895c6fe 1478 /* Exit Initialization mode */
mbed_official 340:28d1f895c6fe 1479 hrtc->Instance->ISR &= (uint32_t)~RTC_ISR_INIT;
mbed_official 340:28d1f895c6fe 1480 }
mbed_official 340:28d1f895c6fe 1481
mbed_official 340:28d1f895c6fe 1482 /* Enable the write protection for RTC registers */
mbed_official 340:28d1f895c6fe 1483 __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc);
mbed_official 340:28d1f895c6fe 1484
mbed_official 340:28d1f895c6fe 1485 /* Change RTC state */
mbed_official 340:28d1f895c6fe 1486 hrtc->State = HAL_RTC_STATE_READY;
mbed_official 340:28d1f895c6fe 1487
mbed_official 340:28d1f895c6fe 1488 /* Process Unlocked */
mbed_official 340:28d1f895c6fe 1489 __HAL_UNLOCK(hrtc);
mbed_official 340:28d1f895c6fe 1490
mbed_official 340:28d1f895c6fe 1491 return HAL_OK;
mbed_official 340:28d1f895c6fe 1492 }
mbed_official 340:28d1f895c6fe 1493
mbed_official 340:28d1f895c6fe 1494 /**
mbed_official 340:28d1f895c6fe 1495 * @brief Enables the Bypass Shadow feature.
mbed_official 441:d2c15dda23c1 1496 * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains
mbed_official 441:d2c15dda23c1 1497 * the configuration information for RTC.
mbed_official 340:28d1f895c6fe 1498 * @note When the Bypass Shadow is enabled the calendar value are taken
mbed_official 340:28d1f895c6fe 1499 * directly from the Calendar counter.
mbed_official 340:28d1f895c6fe 1500 * @retval HAL status
mbed_official 340:28d1f895c6fe 1501 */
mbed_official 340:28d1f895c6fe 1502 HAL_StatusTypeDef HAL_RTCEx_EnableBypassShadow(RTC_HandleTypeDef* hrtc)
mbed_official 340:28d1f895c6fe 1503 {
mbed_official 340:28d1f895c6fe 1504 /* Process Locked */
mbed_official 340:28d1f895c6fe 1505 __HAL_LOCK(hrtc);
mbed_official 340:28d1f895c6fe 1506
mbed_official 340:28d1f895c6fe 1507 hrtc->State = HAL_RTC_STATE_BUSY;
mbed_official 340:28d1f895c6fe 1508
mbed_official 340:28d1f895c6fe 1509 /* Disable the write protection for RTC registers */
mbed_official 340:28d1f895c6fe 1510 __HAL_RTC_WRITEPROTECTION_DISABLE(hrtc);
mbed_official 340:28d1f895c6fe 1511
mbed_official 340:28d1f895c6fe 1512 /* Set the BYPSHAD bit */
mbed_official 340:28d1f895c6fe 1513 hrtc->Instance->CR |= (uint8_t)RTC_CR_BYPSHAD;
mbed_official 340:28d1f895c6fe 1514
mbed_official 340:28d1f895c6fe 1515 /* Enable the write protection for RTC registers */
mbed_official 340:28d1f895c6fe 1516 __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc);
mbed_official 340:28d1f895c6fe 1517
mbed_official 340:28d1f895c6fe 1518 /* Change RTC state */
mbed_official 340:28d1f895c6fe 1519 hrtc->State = HAL_RTC_STATE_READY;
mbed_official 340:28d1f895c6fe 1520
mbed_official 340:28d1f895c6fe 1521 /* Process Unlocked */
mbed_official 340:28d1f895c6fe 1522 __HAL_UNLOCK(hrtc);
mbed_official 340:28d1f895c6fe 1523
mbed_official 340:28d1f895c6fe 1524 return HAL_OK;
mbed_official 340:28d1f895c6fe 1525 }
mbed_official 340:28d1f895c6fe 1526
mbed_official 340:28d1f895c6fe 1527 /**
mbed_official 340:28d1f895c6fe 1528 * @brief Disables the Bypass Shadow feature.
mbed_official 441:d2c15dda23c1 1529 * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains
mbed_official 441:d2c15dda23c1 1530 * the configuration information for RTC.
mbed_official 340:28d1f895c6fe 1531 * @note When the Bypass Shadow is enabled the calendar value are taken
mbed_official 340:28d1f895c6fe 1532 * directly from the Calendar counter.
mbed_official 340:28d1f895c6fe 1533 * @retval HAL status
mbed_official 340:28d1f895c6fe 1534 */
mbed_official 340:28d1f895c6fe 1535 HAL_StatusTypeDef HAL_RTCEx_DisableBypassShadow(RTC_HandleTypeDef* hrtc)
mbed_official 340:28d1f895c6fe 1536 {
mbed_official 340:28d1f895c6fe 1537 /* Process Locked */
mbed_official 340:28d1f895c6fe 1538 __HAL_LOCK(hrtc);
mbed_official 340:28d1f895c6fe 1539
mbed_official 340:28d1f895c6fe 1540 hrtc->State = HAL_RTC_STATE_BUSY;
mbed_official 340:28d1f895c6fe 1541
mbed_official 340:28d1f895c6fe 1542 /* Disable the write protection for RTC registers */
mbed_official 340:28d1f895c6fe 1543 __HAL_RTC_WRITEPROTECTION_DISABLE(hrtc);
mbed_official 340:28d1f895c6fe 1544
mbed_official 340:28d1f895c6fe 1545 /* Reset the BYPSHAD bit */
mbed_official 340:28d1f895c6fe 1546 hrtc->Instance->CR &= (uint8_t)~RTC_CR_BYPSHAD;
mbed_official 340:28d1f895c6fe 1547
mbed_official 340:28d1f895c6fe 1548 /* Enable the write protection for RTC registers */
mbed_official 340:28d1f895c6fe 1549 __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc);
mbed_official 340:28d1f895c6fe 1550
mbed_official 340:28d1f895c6fe 1551 /* Change RTC state */
mbed_official 340:28d1f895c6fe 1552 hrtc->State = HAL_RTC_STATE_READY;
mbed_official 340:28d1f895c6fe 1553
mbed_official 340:28d1f895c6fe 1554 /* Process Unlocked */
mbed_official 340:28d1f895c6fe 1555 __HAL_UNLOCK(hrtc);
mbed_official 340:28d1f895c6fe 1556
mbed_official 340:28d1f895c6fe 1557 return HAL_OK;
mbed_official 340:28d1f895c6fe 1558 }
mbed_official 340:28d1f895c6fe 1559
mbed_official 340:28d1f895c6fe 1560 /**
mbed_official 340:28d1f895c6fe 1561 * @}
mbed_official 340:28d1f895c6fe 1562 */
mbed_official 340:28d1f895c6fe 1563
mbed_official 340:28d1f895c6fe 1564 /**
mbed_official 340:28d1f895c6fe 1565 * @}
mbed_official 340:28d1f895c6fe 1566 */
mbed_official 340:28d1f895c6fe 1567
mbed_official 340:28d1f895c6fe 1568 #endif /* HAL_RTC_MODULE_ENABLED */
mbed_official 340:28d1f895c6fe 1569 /**
mbed_official 340:28d1f895c6fe 1570 * @}
mbed_official 340:28d1f895c6fe 1571 */
mbed_official 340:28d1f895c6fe 1572
mbed_official 340:28d1f895c6fe 1573 /**
mbed_official 340:28d1f895c6fe 1574 * @}
mbed_official 340:28d1f895c6fe 1575 */
mbed_official 340:28d1f895c6fe 1576
mbed_official 340:28d1f895c6fe 1577 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/