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:
Wed Jul 01 09:45:11 2015 +0100
Revision:
579:53297373a894
Parent:
489:119543c9f674
Synchronized with git revision d5b4d2ab9c47edb4dc5776e7177b0c2263459081

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

Initial version of drivers for SAMR21

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