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