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