Mouse code for the MacroRat

Dependencies:   ITG3200 QEI

Committer:
sahilmgandhi
Date:
Sat Jun 03 00:22:44 2017 +0000
Revision:
46:b156ef445742
Parent:
18:6a4db94011d3
Final code for internal battlebot competition.

Who changed what in which revision?

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