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