mbed library sources

Fork of mbed-src by mbed official

Committer:
mbed_official
Date:
Fri Nov 07 08:15:08 2014 +0000
Revision:
392:2b59412bb664
Parent:
targets/cmsis/TARGET_STM/TARGET_NUCLEO_F091RC/stm32f0xx_hal_rtc_ex.c@340:28d1f895c6fe
Child:
441:d2c15dda23c1
Synchronized with git revision eec0be05cd92349bee83c65f9e1302b25b5badf4

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

Targets: STM32F0 - Factorisation of NUCLEO_F030R8/F072RB/F091RC cmsis folders

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