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