Hal Drivers for L4

Dependents:   BSP OneHopeOnePrayer FINAL_AUDIO_RECORD AudioDemo

Fork of STM32L4xx_HAL_Driver by Senior Design: Sound Monitor

Committer:
EricLew
Date:
Wed Nov 25 17:30:43 2015 +0000
Revision:
2:7aef7655b0a8
Parent:
0:80ee8f3b695e
commit;

Who changed what in which revision?

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