TUKS MCU Introductory course / TUKS-COURSE-TIMER
Committer:
elmot
Date:
Fri Feb 24 21:13:56 2017 +0000
Revision:
1:d0dfbce63a89
Ready-to-copy

Who changed what in which revision?

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