mbed library sources

Dependents:   Encrypted my_mbed lklk CyaSSL_DTLS_Cellular ... more

Superseded

This library was superseded by mbed-dev - https://os.mbed.com/users/mbed_official/code/mbed-dev/.

Development branch of the mbed library sources. This library is kept in synch with the latest changes from the mbed SDK and it is not guaranteed to work.

If you are looking for a stable and tested release, please import one of the official mbed library releases:

Import librarymbed

The official Mbed 2 C/C++ SDK provides the software platform and libraries to build your applications.

Committer:
mbed_official
Date:
Fri Oct 31 11:00:10 2014 +0000
Revision:
376:cb4d9db17537
Synchronized with git revision 07b49da75eac883fc8916d3d6b6962664b8db29e

Full URL: https://github.com/mbedmicro/mbed/commit/07b49da75eac883fc8916d3d6b6962664b8db29e/

Targets: DISCO_L053C8 - new platform - STM32L0 Discovery board

Who changed what in which revision?

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