mbed library sources
Dependents: frdm_kl05z_gpio_test
Fork of mbed-src by
targets/cmsis/TARGET_STM/TARGET_NUCLEO_F401RE/stm32f4xx_hal_rtc.c@87:085cde657901, 2014-02-08 (annotated)
- Committer:
- mbed_official
- Date:
- Sat Feb 08 19:45:06 2014 +0000
- Revision:
- 87:085cde657901
- Child:
- 106:ced8cbb51063
Synchronized with git revision 9272cdeb45ec7e6077641536509413da8fd2ebc2
Full URL: https://github.com/mbedmicro/mbed/commit/9272cdeb45ec7e6077641536509413da8fd2ebc2/
Add NUCLEO_F401RE, improvements
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
mbed_official | 87:085cde657901 | 1 | /** |
mbed_official | 87:085cde657901 | 2 | ****************************************************************************** |
mbed_official | 87:085cde657901 | 3 | * @file stm32f4xx_hal_rtc.c |
mbed_official | 87:085cde657901 | 4 | * @author MCD Application Team |
mbed_official | 87:085cde657901 | 5 | * @version V1.0.0RC2 |
mbed_official | 87:085cde657901 | 6 | * @date 04-February-2014 |
mbed_official | 87:085cde657901 | 7 | * @brief RTC HAL module driver. |
mbed_official | 87:085cde657901 | 8 | * This file provides firmware functions to manage the following |
mbed_official | 87:085cde657901 | 9 | * functionalities of the Real Time Clock (RTC) peripheral: |
mbed_official | 87:085cde657901 | 10 | * + Initialization and de-initialization functions |
mbed_official | 87:085cde657901 | 11 | * + RTC Time and Date functions |
mbed_official | 87:085cde657901 | 12 | * + RTC Alarm functions |
mbed_official | 87:085cde657901 | 13 | * + Peripheral Control functions |
mbed_official | 87:085cde657901 | 14 | * + Peripheral State functions |
mbed_official | 87:085cde657901 | 15 | * |
mbed_official | 87:085cde657901 | 16 | @verbatim |
mbed_official | 87:085cde657901 | 17 | ============================================================================== |
mbed_official | 87:085cde657901 | 18 | ##### Backup Domain Operating Condition ##### |
mbed_official | 87:085cde657901 | 19 | ============================================================================== |
mbed_official | 87:085cde657901 | 20 | [..] The real-time clock (RTC), the RTC backup registers, and the backup |
mbed_official | 87:085cde657901 | 21 | SRAM (BKP SRAM) can be powered from the VBAT voltage when the main |
mbed_official | 87:085cde657901 | 22 | VDD supply is powered off. |
mbed_official | 87:085cde657901 | 23 | To retain the content of the RTC backup registers, backup SRAM, and supply |
mbed_official | 87:085cde657901 | 24 | the RTC when VDD is turned off, VBAT pin can be connected to an optional |
mbed_official | 87:085cde657901 | 25 | standby voltage supplied by a battery or by another source. |
mbed_official | 87:085cde657901 | 26 | |
mbed_official | 87:085cde657901 | 27 | [..] To allow the RTC to operate even when the main digital supply (VDD) is turned |
mbed_official | 87:085cde657901 | 28 | off, the VBAT pin powers the following blocks: |
mbed_official | 87:085cde657901 | 29 | (#) The RTC |
mbed_official | 87:085cde657901 | 30 | (#) The LSE oscillator |
mbed_official | 87:085cde657901 | 31 | (#) The backup SRAM when the low power backup regulator is enabled |
mbed_official | 87:085cde657901 | 32 | (#) PC13 to PC15 I/Os, plus PI8 I/O (when available) |
mbed_official | 87:085cde657901 | 33 | |
mbed_official | 87:085cde657901 | 34 | [..] When the backup domain is supplied by VDD (analog switch connected to VDD), |
mbed_official | 87:085cde657901 | 35 | the following functions are available: |
mbed_official | 87:085cde657901 | 36 | (#) PC14 and PC15 can be used as either GPIO or LSE pins |
mbed_official | 87:085cde657901 | 37 | (#) PC13 can be used as a GPIO or as the RTC_AF1 pin |
mbed_official | 87:085cde657901 | 38 | (#) PI8 can be used as a GPIO or as the RTC_AF2 pin |
mbed_official | 87:085cde657901 | 39 | |
mbed_official | 87:085cde657901 | 40 | [..] When the backup domain is supplied by VBAT (analog switch connected to VBAT |
mbed_official | 87:085cde657901 | 41 | because VDD is not present), the following functions are available: |
mbed_official | 87:085cde657901 | 42 | (#) PC14 and PC15 can be used as LSE pins only |
mbed_official | 87:085cde657901 | 43 | (#) PC13 can be used as the RTC_AF1 pin |
mbed_official | 87:085cde657901 | 44 | (#) PI8 can be used as the RTC_AF2 pin |
mbed_official | 87:085cde657901 | 45 | |
mbed_official | 87:085cde657901 | 46 | ##### Backup Domain Reset ##### |
mbed_official | 87:085cde657901 | 47 | ================================================================== |
mbed_official | 87:085cde657901 | 48 | [..] The backup domain reset sets all RTC registers and the RCC_BDCR register |
mbed_official | 87:085cde657901 | 49 | to their reset values. The BKPSRAM is not affected by this reset. The only |
mbed_official | 87:085cde657901 | 50 | way of resetting the BKPSRAM is through the Flash interface by requesting |
mbed_official | 87:085cde657901 | 51 | a protection level change from 1 to 0. |
mbed_official | 87:085cde657901 | 52 | [..] A backup domain reset is generated when one of the following events occurs: |
mbed_official | 87:085cde657901 | 53 | (#) Software reset, triggered by setting the BDRST bit in the |
mbed_official | 87:085cde657901 | 54 | RCC Backup domain control register (RCC_BDCR). |
mbed_official | 87:085cde657901 | 55 | (#) VDD or VBAT power on, if both supplies have previously been powered off. |
mbed_official | 87:085cde657901 | 56 | |
mbed_official | 87:085cde657901 | 57 | ##### Backup Domain Access ##### |
mbed_official | 87:085cde657901 | 58 | ================================================================== |
mbed_official | 87:085cde657901 | 59 | [..] After reset, the backup domain (RTC registers, RTC backup data |
mbed_official | 87:085cde657901 | 60 | registers and backup SRAM) is protected against possible unwanted write |
mbed_official | 87:085cde657901 | 61 | accesses. |
mbed_official | 87:085cde657901 | 62 | [..] To enable access to the RTC Domain and RTC registers, proceed as follows: |
mbed_official | 87:085cde657901 | 63 | (+) Enable the Power Controller (PWR) APB1 interface clock using the |
mbed_official | 87:085cde657901 | 64 | __PWR_CLK_ENABLE() function. |
mbed_official | 87:085cde657901 | 65 | (+) Enable access to RTC domain using the HAL_PWR_EnableBkUpAccess() function. |
mbed_official | 87:085cde657901 | 66 | (+) Select the RTC clock source using the __HAL_RCC_RTC_CONFIG() function. |
mbed_official | 87:085cde657901 | 67 | (+) Enable RTC Clock using the __HAL_RCC_RTC_ENABLE() function. |
mbed_official | 87:085cde657901 | 68 | |
mbed_official | 87:085cde657901 | 69 | |
mbed_official | 87:085cde657901 | 70 | ##### How to use this driver ##### |
mbed_official | 87:085cde657901 | 71 | ================================================================== |
mbed_official | 87:085cde657901 | 72 | [..] |
mbed_official | 87:085cde657901 | 73 | (+) Enable the RTC domain access (see description in the section above). |
mbed_official | 87:085cde657901 | 74 | (+) Configure the RTC Prescaler (Asynchronous and Synchronous) and RTC hour |
mbed_official | 87:085cde657901 | 75 | format using the HAL_RTC_Init() function. |
mbed_official | 87:085cde657901 | 76 | |
mbed_official | 87:085cde657901 | 77 | *** Time and Date configuration *** |
mbed_official | 87:085cde657901 | 78 | =================================== |
mbed_official | 87:085cde657901 | 79 | [..] |
mbed_official | 87:085cde657901 | 80 | (+) To configure the RTC Calendar (Time and Date) use the HAL_RTC_SetTime() |
mbed_official | 87:085cde657901 | 81 | and HAL_RTC_SetDate() functions. |
mbed_official | 87:085cde657901 | 82 | (+) To read the RTC Calendar, use the HAL_RTC_GetTime() and HAL_RTC_GetDate() functions. |
mbed_official | 87:085cde657901 | 83 | |
mbed_official | 87:085cde657901 | 84 | *** Alarm configuration *** |
mbed_official | 87:085cde657901 | 85 | =========================== |
mbed_official | 87:085cde657901 | 86 | [..] |
mbed_official | 87:085cde657901 | 87 | (+) To configure the RTC Alarm use the HAL_RTC_SetAlarm() function. |
mbed_official | 87:085cde657901 | 88 | You can also configure the RTC Alarm with interrupt mode using the HAL_RTC_SetAlarm_IT() function. |
mbed_official | 87:085cde657901 | 89 | (+) To read the RTC Alarm, use the HAL_RTC_GetAlarm() function. |
mbed_official | 87:085cde657901 | 90 | |
mbed_official | 87:085cde657901 | 91 | ##### RTC and low power modes ##### |
mbed_official | 87:085cde657901 | 92 | ================================================================== |
mbed_official | 87:085cde657901 | 93 | [..] The MCU can be woken up from a low power mode by an RTC alternate |
mbed_official | 87:085cde657901 | 94 | function. |
mbed_official | 87:085cde657901 | 95 | [..] The RTC alternate functions are the RTC alarms (Alarm A and Alarm B), |
mbed_official | 87:085cde657901 | 96 | RTC wakeup, RTC tamper event detection and RTC time stamp event detection. |
mbed_official | 87:085cde657901 | 97 | These RTC alternate functions can wake up the system from the Stop and |
mbed_official | 87:085cde657901 | 98 | Standby low power modes. |
mbed_official | 87:085cde657901 | 99 | [..] The system can also wake up from low power modes without depending |
mbed_official | 87:085cde657901 | 100 | on an external interrupt (Auto-wakeup mode), by using the RTC alarm |
mbed_official | 87:085cde657901 | 101 | or the RTC wakeup events. |
mbed_official | 87:085cde657901 | 102 | [..] The RTC provides a programmable time base for waking up from the |
mbed_official | 87:085cde657901 | 103 | Stop or Standby mode at regular intervals. |
mbed_official | 87:085cde657901 | 104 | Wakeup from STOP and Standby modes is possible only when the RTC clock source |
mbed_official | 87:085cde657901 | 105 | is LSE or LSI. |
mbed_official | 87:085cde657901 | 106 | |
mbed_official | 87:085cde657901 | 107 | @endverbatim |
mbed_official | 87:085cde657901 | 108 | ****************************************************************************** |
mbed_official | 87:085cde657901 | 109 | * @attention |
mbed_official | 87:085cde657901 | 110 | * |
mbed_official | 87:085cde657901 | 111 | * <h2><center>© COPYRIGHT(c) 2014 STMicroelectronics</center></h2> |
mbed_official | 87:085cde657901 | 112 | * |
mbed_official | 87:085cde657901 | 113 | * Redistribution and use in source and binary forms, with or without modification, |
mbed_official | 87:085cde657901 | 114 | * are permitted provided that the following conditions are met: |
mbed_official | 87:085cde657901 | 115 | * 1. Redistributions of source code must retain the above copyright notice, |
mbed_official | 87:085cde657901 | 116 | * this list of conditions and the following disclaimer. |
mbed_official | 87:085cde657901 | 117 | * 2. Redistributions in binary form must reproduce the above copyright notice, |
mbed_official | 87:085cde657901 | 118 | * this list of conditions and the following disclaimer in the documentation |
mbed_official | 87:085cde657901 | 119 | * and/or other materials provided with the distribution. |
mbed_official | 87:085cde657901 | 120 | * 3. Neither the name of STMicroelectronics nor the names of its contributors |
mbed_official | 87:085cde657901 | 121 | * may be used to endorse or promote products derived from this software |
mbed_official | 87:085cde657901 | 122 | * without specific prior written permission. |
mbed_official | 87:085cde657901 | 123 | * |
mbed_official | 87:085cde657901 | 124 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
mbed_official | 87:085cde657901 | 125 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
mbed_official | 87:085cde657901 | 126 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
mbed_official | 87:085cde657901 | 127 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE |
mbed_official | 87:085cde657901 | 128 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
mbed_official | 87:085cde657901 | 129 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |
mbed_official | 87:085cde657901 | 130 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
mbed_official | 87:085cde657901 | 131 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |
mbed_official | 87:085cde657901 | 132 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
mbed_official | 87:085cde657901 | 133 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
mbed_official | 87:085cde657901 | 134 | * |
mbed_official | 87:085cde657901 | 135 | ****************************************************************************** |
mbed_official | 87:085cde657901 | 136 | */ |
mbed_official | 87:085cde657901 | 137 | |
mbed_official | 87:085cde657901 | 138 | /* Includes ------------------------------------------------------------------*/ |
mbed_official | 87:085cde657901 | 139 | #include "stm32f4xx_hal.h" |
mbed_official | 87:085cde657901 | 140 | |
mbed_official | 87:085cde657901 | 141 | /** @addtogroup STM32F4xx_HAL_Driver |
mbed_official | 87:085cde657901 | 142 | * @{ |
mbed_official | 87:085cde657901 | 143 | */ |
mbed_official | 87:085cde657901 | 144 | |
mbed_official | 87:085cde657901 | 145 | /** @defgroup RTC |
mbed_official | 87:085cde657901 | 146 | * @brief RTC HAL module driver |
mbed_official | 87:085cde657901 | 147 | * @{ |
mbed_official | 87:085cde657901 | 148 | */ |
mbed_official | 87:085cde657901 | 149 | |
mbed_official | 87:085cde657901 | 150 | #ifdef HAL_RTC_MODULE_ENABLED |
mbed_official | 87:085cde657901 | 151 | |
mbed_official | 87:085cde657901 | 152 | /* Private typedef -----------------------------------------------------------*/ |
mbed_official | 87:085cde657901 | 153 | /* Private define ------------------------------------------------------------*/ |
mbed_official | 87:085cde657901 | 154 | /* Masks Definition */ |
mbed_official | 87:085cde657901 | 155 | #define RTC_TR_RESERVED_MASK ((uint32_t)0x007F7F7F) |
mbed_official | 87:085cde657901 | 156 | #define RTC_DR_RESERVED_MASK ((uint32_t)0x00FFFF3F) |
mbed_official | 87:085cde657901 | 157 | #define RTC_INIT_MASK ((uint32_t)0xFFFFFFFF) |
mbed_official | 87:085cde657901 | 158 | #define RTC_RSF_MASK ((uint32_t)0xFFFFFF5F) |
mbed_official | 87:085cde657901 | 159 | #define RTC_FLAGS_MASK ((uint32_t)(RTC_FLAG_TSOVF | RTC_FLAG_TSF | RTC_FLAG_WUTF | \ |
mbed_official | 87:085cde657901 | 160 | RTC_FLAG_ALRBF | RTC_FLAG_ALRAF | RTC_FLAG_INITF | \ |
mbed_official | 87:085cde657901 | 161 | RTC_FLAG_RSF | RTC_FLAG_INITS | RTC_FLAG_WUTWF | \ |
mbed_official | 87:085cde657901 | 162 | RTC_FLAG_ALRBWF | RTC_FLAG_ALRAWF | RTC_FLAG_TAMP1F | \ |
mbed_official | 87:085cde657901 | 163 | RTC_FLAG_RECALPF | RTC_FLAG_SHPF)) |
mbed_official | 87:085cde657901 | 164 | |
mbed_official | 87:085cde657901 | 165 | #define RTC_TIMEOUT_VALUE 1000 |
mbed_official | 87:085cde657901 | 166 | /* Private macro -------------------------------------------------------------*/ |
mbed_official | 87:085cde657901 | 167 | /* Private variables ---------------------------------------------------------*/ |
mbed_official | 87:085cde657901 | 168 | /* Private function prototypes -----------------------------------------------*/ |
mbed_official | 87:085cde657901 | 169 | /* Private functions ---------------------------------------------------------*/ |
mbed_official | 87:085cde657901 | 170 | |
mbed_official | 87:085cde657901 | 171 | /** @defgroup RTC_Private_Functions |
mbed_official | 87:085cde657901 | 172 | * @{ |
mbed_official | 87:085cde657901 | 173 | */ |
mbed_official | 87:085cde657901 | 174 | |
mbed_official | 87:085cde657901 | 175 | /** @defgroup RTC_Group1 Initialization and de-initialization functions |
mbed_official | 87:085cde657901 | 176 | * @brief Initialization and Configuration functions |
mbed_official | 87:085cde657901 | 177 | * |
mbed_official | 87:085cde657901 | 178 | @verbatim |
mbed_official | 87:085cde657901 | 179 | =============================================================================== |
mbed_official | 87:085cde657901 | 180 | ##### Initialization and de-initialization functions ##### |
mbed_official | 87:085cde657901 | 181 | =============================================================================== |
mbed_official | 87:085cde657901 | 182 | [..] This section provide functions allowing to initialize and configure the |
mbed_official | 87:085cde657901 | 183 | RTC Prescaler (Synchronous and Asynchronous), RTC Hour format, disable |
mbed_official | 87:085cde657901 | 184 | RTC registers Write protection, enter and exit the RTC initialization mode, |
mbed_official | 87:085cde657901 | 185 | RTC registers synchronization check and reference clock detection enable. |
mbed_official | 87:085cde657901 | 186 | (#) The RTC Prescaler is programmed to generate the RTC 1Hz time base. |
mbed_official | 87:085cde657901 | 187 | It is split into 2 programmable prescalers to minimize power consumption. |
mbed_official | 87:085cde657901 | 188 | (++) A 7-bit asynchronous prescaler and A 13-bit synchronous prescaler. |
mbed_official | 87:085cde657901 | 189 | (++) When both prescalers are used, it is recommended to configure the |
mbed_official | 87:085cde657901 | 190 | asynchronous prescaler to a high value to minimize consumption. |
mbed_official | 87:085cde657901 | 191 | (#) All RTC registers are Write protected. Writing to the RTC registers |
mbed_official | 87:085cde657901 | 192 | is enabled by writing a key into the Write Protection register, RTC_WPR. |
mbed_official | 87:085cde657901 | 193 | (#) To Configure the RTC Calendar, user application should enter |
mbed_official | 87:085cde657901 | 194 | initialization mode. In this mode, the calendar counter is stopped |
mbed_official | 87:085cde657901 | 195 | and its value can be updated. When the initialization sequence is |
mbed_official | 87:085cde657901 | 196 | complete, the calendar restarts counting after 4 RTCCLK cycles. |
mbed_official | 87:085cde657901 | 197 | (#) To read the calendar through the shadow registers after Calendar |
mbed_official | 87:085cde657901 | 198 | initialization, calendar update or after wakeup from low power modes |
mbed_official | 87:085cde657901 | 199 | the software must first clear the RSF flag. The software must then |
mbed_official | 87:085cde657901 | 200 | wait until it is set again before reading the calendar, which means |
mbed_official | 87:085cde657901 | 201 | that the calendar registers have been correctly copied into the |
mbed_official | 87:085cde657901 | 202 | RTC_TR and RTC_DR shadow registers.The HAL_RTC_WaitForSynchro() function |
mbed_official | 87:085cde657901 | 203 | implements the above software sequence (RSF clear and RSF check). |
mbed_official | 87:085cde657901 | 204 | |
mbed_official | 87:085cde657901 | 205 | @endverbatim |
mbed_official | 87:085cde657901 | 206 | * @{ |
mbed_official | 87:085cde657901 | 207 | */ |
mbed_official | 87:085cde657901 | 208 | |
mbed_official | 87:085cde657901 | 209 | /** |
mbed_official | 87:085cde657901 | 210 | * @brief Initializes the RTC peripheral |
mbed_official | 87:085cde657901 | 211 | * @param hrtc: RTC handle |
mbed_official | 87:085cde657901 | 212 | * @retval HAL status |
mbed_official | 87:085cde657901 | 213 | */ |
mbed_official | 87:085cde657901 | 214 | HAL_StatusTypeDef HAL_RTC_Init(RTC_HandleTypeDef *hrtc) |
mbed_official | 87:085cde657901 | 215 | { |
mbed_official | 87:085cde657901 | 216 | /* Check the RTC peripheral state */ |
mbed_official | 87:085cde657901 | 217 | if(hrtc == NULL) |
mbed_official | 87:085cde657901 | 218 | { |
mbed_official | 87:085cde657901 | 219 | return HAL_ERROR; |
mbed_official | 87:085cde657901 | 220 | } |
mbed_official | 87:085cde657901 | 221 | |
mbed_official | 87:085cde657901 | 222 | /* Check the parameters */ |
mbed_official | 87:085cde657901 | 223 | assert_param(IS_RTC_HOUR_FORMAT(hrtc->Init.HourFormat)); |
mbed_official | 87:085cde657901 | 224 | assert_param(IS_RTC_ASYNCH_PREDIV(hrtc->Init.AsynchPrediv)); |
mbed_official | 87:085cde657901 | 225 | assert_param(IS_RTC_SYNCH_PREDIV(hrtc->Init.SynchPrediv)); |
mbed_official | 87:085cde657901 | 226 | assert_param (IS_RTC_OUTPUT(hrtc->Init.OutPut)); |
mbed_official | 87:085cde657901 | 227 | assert_param (IS_RTC_OUTPUT_POL(hrtc->Init.OutPutPolarity)); |
mbed_official | 87:085cde657901 | 228 | assert_param(IS_RTC_OUTPUT_TYPE(hrtc->Init.OutPutType)); |
mbed_official | 87:085cde657901 | 229 | |
mbed_official | 87:085cde657901 | 230 | if(hrtc->State == HAL_RTC_STATE_RESET) |
mbed_official | 87:085cde657901 | 231 | { |
mbed_official | 87:085cde657901 | 232 | /* Initialize RTC MSP */ |
mbed_official | 87:085cde657901 | 233 | HAL_RTC_MspInit(hrtc); |
mbed_official | 87:085cde657901 | 234 | } |
mbed_official | 87:085cde657901 | 235 | |
mbed_official | 87:085cde657901 | 236 | /* Set RTC state */ |
mbed_official | 87:085cde657901 | 237 | hrtc->State = HAL_RTC_STATE_BUSY; |
mbed_official | 87:085cde657901 | 238 | |
mbed_official | 87:085cde657901 | 239 | /* Disable the write protection for RTC registers */ |
mbed_official | 87:085cde657901 | 240 | __HAL_RTC_WRITEPROTECTION_DISABLE(hrtc); |
mbed_official | 87:085cde657901 | 241 | |
mbed_official | 87:085cde657901 | 242 | /* Set Initialization mode */ |
mbed_official | 87:085cde657901 | 243 | if(RTC_EnterInitMode(hrtc) != HAL_OK) |
mbed_official | 87:085cde657901 | 244 | { |
mbed_official | 87:085cde657901 | 245 | /* Enable the write protection for RTC registers */ |
mbed_official | 87:085cde657901 | 246 | __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc); |
mbed_official | 87:085cde657901 | 247 | |
mbed_official | 87:085cde657901 | 248 | /* Set RTC state */ |
mbed_official | 87:085cde657901 | 249 | hrtc->State = HAL_RTC_STATE_ERROR; |
mbed_official | 87:085cde657901 | 250 | |
mbed_official | 87:085cde657901 | 251 | return HAL_ERROR; |
mbed_official | 87:085cde657901 | 252 | } |
mbed_official | 87:085cde657901 | 253 | else |
mbed_official | 87:085cde657901 | 254 | { |
mbed_official | 87:085cde657901 | 255 | /* Clear RTC_CR FMT, OSEL and POL Bits */ |
mbed_official | 87:085cde657901 | 256 | hrtc->Instance->CR &= ((uint32_t)~(RTC_CR_FMT | RTC_CR_OSEL | RTC_CR_POL)); |
mbed_official | 87:085cde657901 | 257 | /* Set RTC_CR register */ |
mbed_official | 87:085cde657901 | 258 | hrtc->Instance->CR |= (uint32_t)(hrtc->Init.HourFormat | hrtc->Init.OutPut | hrtc->Init.OutPutPolarity); |
mbed_official | 87:085cde657901 | 259 | |
mbed_official | 87:085cde657901 | 260 | /* Configure the RTC PRER */ |
mbed_official | 87:085cde657901 | 261 | hrtc->Instance->PRER = (uint32_t)(hrtc->Init.SynchPrediv); |
mbed_official | 87:085cde657901 | 262 | hrtc->Instance->PRER |= (uint32_t)(hrtc->Init.AsynchPrediv << 16); |
mbed_official | 87:085cde657901 | 263 | |
mbed_official | 87:085cde657901 | 264 | /* Exit Initialization mode */ |
mbed_official | 87:085cde657901 | 265 | hrtc->Instance->ISR &= (uint32_t)~RTC_ISR_INIT; |
mbed_official | 87:085cde657901 | 266 | |
mbed_official | 87:085cde657901 | 267 | hrtc->Instance->TAFCR &= (uint32_t)~RTC_TAFCR_ALARMOUTTYPE; |
mbed_official | 87:085cde657901 | 268 | hrtc->Instance->TAFCR |= (uint32_t)(hrtc->Init.OutPutType); |
mbed_official | 87:085cde657901 | 269 | |
mbed_official | 87:085cde657901 | 270 | /* Enable the write protection for RTC registers */ |
mbed_official | 87:085cde657901 | 271 | __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc); |
mbed_official | 87:085cde657901 | 272 | |
mbed_official | 87:085cde657901 | 273 | /* Set RTC state */ |
mbed_official | 87:085cde657901 | 274 | hrtc->State = HAL_RTC_STATE_READY; |
mbed_official | 87:085cde657901 | 275 | |
mbed_official | 87:085cde657901 | 276 | return HAL_OK; |
mbed_official | 87:085cde657901 | 277 | } |
mbed_official | 87:085cde657901 | 278 | } |
mbed_official | 87:085cde657901 | 279 | |
mbed_official | 87:085cde657901 | 280 | /** |
mbed_official | 87:085cde657901 | 281 | * @brief DeInitializes the RTC peripheral |
mbed_official | 87:085cde657901 | 282 | * @param hrtc: RTC handle |
mbed_official | 87:085cde657901 | 283 | * @note This function doesn't reset the RTC Backup Data registers. |
mbed_official | 87:085cde657901 | 284 | * @retval HAL status |
mbed_official | 87:085cde657901 | 285 | */ |
mbed_official | 87:085cde657901 | 286 | HAL_StatusTypeDef HAL_RTC_DeInit(RTC_HandleTypeDef *hrtc) |
mbed_official | 87:085cde657901 | 287 | { |
mbed_official | 87:085cde657901 | 288 | uint32_t timeout = 0; |
mbed_official | 87:085cde657901 | 289 | |
mbed_official | 87:085cde657901 | 290 | /* Set RTC state */ |
mbed_official | 87:085cde657901 | 291 | hrtc->State = HAL_RTC_STATE_BUSY; |
mbed_official | 87:085cde657901 | 292 | |
mbed_official | 87:085cde657901 | 293 | /* Disable the write protection for RTC registers */ |
mbed_official | 87:085cde657901 | 294 | __HAL_RTC_WRITEPROTECTION_DISABLE(hrtc); |
mbed_official | 87:085cde657901 | 295 | |
mbed_official | 87:085cde657901 | 296 | /* Set Initialization mode */ |
mbed_official | 87:085cde657901 | 297 | if(RTC_EnterInitMode(hrtc) != HAL_OK) |
mbed_official | 87:085cde657901 | 298 | { |
mbed_official | 87:085cde657901 | 299 | /* Enable the write protection for RTC registers */ |
mbed_official | 87:085cde657901 | 300 | __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc); |
mbed_official | 87:085cde657901 | 301 | |
mbed_official | 87:085cde657901 | 302 | /* Set RTC state */ |
mbed_official | 87:085cde657901 | 303 | hrtc->State = HAL_RTC_STATE_ERROR; |
mbed_official | 87:085cde657901 | 304 | |
mbed_official | 87:085cde657901 | 305 | return HAL_ERROR; |
mbed_official | 87:085cde657901 | 306 | } |
mbed_official | 87:085cde657901 | 307 | else |
mbed_official | 87:085cde657901 | 308 | { |
mbed_official | 87:085cde657901 | 309 | /* Reset TR, DR and CR registers */ |
mbed_official | 87:085cde657901 | 310 | hrtc->Instance->TR = (uint32_t)0x00000000; |
mbed_official | 87:085cde657901 | 311 | hrtc->Instance->DR = (uint32_t)0x00002101; |
mbed_official | 87:085cde657901 | 312 | /* Reset All CR bits except CR[2:0] */ |
mbed_official | 87:085cde657901 | 313 | hrtc->Instance->CR &= (uint32_t)0x00000007; |
mbed_official | 87:085cde657901 | 314 | |
mbed_official | 87:085cde657901 | 315 | timeout = HAL_GetTick() + RTC_TIMEOUT_VALUE; |
mbed_official | 87:085cde657901 | 316 | |
mbed_official | 87:085cde657901 | 317 | /* Wait till WUTWF flag is set and if Time out is reached exit */ |
mbed_official | 87:085cde657901 | 318 | while(((hrtc->Instance->ISR) & RTC_ISR_WUTWF) == (uint32_t)RESET) |
mbed_official | 87:085cde657901 | 319 | { |
mbed_official | 87:085cde657901 | 320 | if(HAL_GetTick() >= timeout) |
mbed_official | 87:085cde657901 | 321 | { |
mbed_official | 87:085cde657901 | 322 | /* Enable the write protection for RTC registers */ |
mbed_official | 87:085cde657901 | 323 | __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc); |
mbed_official | 87:085cde657901 | 324 | |
mbed_official | 87:085cde657901 | 325 | /* Set RTC state */ |
mbed_official | 87:085cde657901 | 326 | hrtc->State = HAL_RTC_STATE_TIMEOUT; |
mbed_official | 87:085cde657901 | 327 | |
mbed_official | 87:085cde657901 | 328 | return HAL_TIMEOUT; |
mbed_official | 87:085cde657901 | 329 | } |
mbed_official | 87:085cde657901 | 330 | } |
mbed_official | 87:085cde657901 | 331 | |
mbed_official | 87:085cde657901 | 332 | /* Reset all RTC CR register bits */ |
mbed_official | 87:085cde657901 | 333 | hrtc->Instance->CR &= (uint32_t)0x00000000; |
mbed_official | 87:085cde657901 | 334 | hrtc->Instance->WUTR = (uint32_t)0x0000FFFF; |
mbed_official | 87:085cde657901 | 335 | hrtc->Instance->PRER = (uint32_t)0x007F00FF; |
mbed_official | 87:085cde657901 | 336 | hrtc->Instance->CALIBR = (uint32_t)0x00000000; |
mbed_official | 87:085cde657901 | 337 | hrtc->Instance->ALRMAR = (uint32_t)0x00000000; |
mbed_official | 87:085cde657901 | 338 | hrtc->Instance->ALRMBR = (uint32_t)0x00000000; |
mbed_official | 87:085cde657901 | 339 | hrtc->Instance->SHIFTR = (uint32_t)0x00000000; |
mbed_official | 87:085cde657901 | 340 | hrtc->Instance->CALR = (uint32_t)0x00000000; |
mbed_official | 87:085cde657901 | 341 | hrtc->Instance->ALRMASSR = (uint32_t)0x00000000; |
mbed_official | 87:085cde657901 | 342 | hrtc->Instance->ALRMBSSR = (uint32_t)0x00000000; |
mbed_official | 87:085cde657901 | 343 | |
mbed_official | 87:085cde657901 | 344 | /* Reset ISR register and exit initialization mode */ |
mbed_official | 87:085cde657901 | 345 | hrtc->Instance->ISR = (uint32_t)0x00000000; |
mbed_official | 87:085cde657901 | 346 | |
mbed_official | 87:085cde657901 | 347 | /* Reset Tamper and alternate functions configuration register */ |
mbed_official | 87:085cde657901 | 348 | hrtc->Instance->TAFCR = 0x00000000; |
mbed_official | 87:085cde657901 | 349 | |
mbed_official | 87:085cde657901 | 350 | /* If RTC_CR_BYPSHAD bit = 0, wait for synchro else this check is not needed */ |
mbed_official | 87:085cde657901 | 351 | if((hrtc->Instance->CR & RTC_CR_BYPSHAD) == RESET) |
mbed_official | 87:085cde657901 | 352 | { |
mbed_official | 87:085cde657901 | 353 | if(HAL_RTC_WaitForSynchro(hrtc) != HAL_OK) |
mbed_official | 87:085cde657901 | 354 | { |
mbed_official | 87:085cde657901 | 355 | /* Enable the write protection for RTC registers */ |
mbed_official | 87:085cde657901 | 356 | __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc); |
mbed_official | 87:085cde657901 | 357 | |
mbed_official | 87:085cde657901 | 358 | hrtc->State = HAL_RTC_STATE_ERROR; |
mbed_official | 87:085cde657901 | 359 | |
mbed_official | 87:085cde657901 | 360 | return HAL_ERROR; |
mbed_official | 87:085cde657901 | 361 | } |
mbed_official | 87:085cde657901 | 362 | } |
mbed_official | 87:085cde657901 | 363 | } |
mbed_official | 87:085cde657901 | 364 | |
mbed_official | 87:085cde657901 | 365 | /* Enable the write protection for RTC registers */ |
mbed_official | 87:085cde657901 | 366 | __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc); |
mbed_official | 87:085cde657901 | 367 | |
mbed_official | 87:085cde657901 | 368 | /* De-Initialize RTC MSP */ |
mbed_official | 87:085cde657901 | 369 | HAL_RTC_MspDeInit(hrtc); |
mbed_official | 87:085cde657901 | 370 | |
mbed_official | 87:085cde657901 | 371 | hrtc->State = HAL_RTC_STATE_RESET; |
mbed_official | 87:085cde657901 | 372 | |
mbed_official | 87:085cde657901 | 373 | return HAL_OK; |
mbed_official | 87:085cde657901 | 374 | } |
mbed_official | 87:085cde657901 | 375 | |
mbed_official | 87:085cde657901 | 376 | /** |
mbed_official | 87:085cde657901 | 377 | * @brief Initializes the RTC MSP. |
mbed_official | 87:085cde657901 | 378 | * @param hrtc: RTC handle |
mbed_official | 87:085cde657901 | 379 | * @retval None |
mbed_official | 87:085cde657901 | 380 | */ |
mbed_official | 87:085cde657901 | 381 | __weak void HAL_RTC_MspInit(RTC_HandleTypeDef* hrtc) |
mbed_official | 87:085cde657901 | 382 | { |
mbed_official | 87:085cde657901 | 383 | /* NOTE : This function Should not be modified, when the callback is needed, |
mbed_official | 87:085cde657901 | 384 | the HAL_RTC_MspInit could be implenetd in the user file |
mbed_official | 87:085cde657901 | 385 | */ |
mbed_official | 87:085cde657901 | 386 | } |
mbed_official | 87:085cde657901 | 387 | |
mbed_official | 87:085cde657901 | 388 | /** |
mbed_official | 87:085cde657901 | 389 | * @brief DeInitializes the RTC MSP. |
mbed_official | 87:085cde657901 | 390 | * @param hrtc: RTC handle |
mbed_official | 87:085cde657901 | 391 | * @retval None |
mbed_official | 87:085cde657901 | 392 | */ |
mbed_official | 87:085cde657901 | 393 | __weak void HAL_RTC_MspDeInit(RTC_HandleTypeDef* hrtc) |
mbed_official | 87:085cde657901 | 394 | { |
mbed_official | 87:085cde657901 | 395 | /* NOTE : This function Should not be modified, when the callback is needed, |
mbed_official | 87:085cde657901 | 396 | the HAL_RTC_MspDeInit could be implenetd in the user file |
mbed_official | 87:085cde657901 | 397 | */ |
mbed_official | 87:085cde657901 | 398 | } |
mbed_official | 87:085cde657901 | 399 | |
mbed_official | 87:085cde657901 | 400 | /** |
mbed_official | 87:085cde657901 | 401 | * @} |
mbed_official | 87:085cde657901 | 402 | */ |
mbed_official | 87:085cde657901 | 403 | |
mbed_official | 87:085cde657901 | 404 | /** @defgroup RTC_Group2 RTC Time and Date functions |
mbed_official | 87:085cde657901 | 405 | * @brief RTC Time and Date functions |
mbed_official | 87:085cde657901 | 406 | * |
mbed_official | 87:085cde657901 | 407 | @verbatim |
mbed_official | 87:085cde657901 | 408 | =============================================================================== |
mbed_official | 87:085cde657901 | 409 | ##### RTC Time and Date functions ##### |
mbed_official | 87:085cde657901 | 410 | =============================================================================== |
mbed_official | 87:085cde657901 | 411 | |
mbed_official | 87:085cde657901 | 412 | [..] This section provide functions allowing to configure Time and Date features |
mbed_official | 87:085cde657901 | 413 | |
mbed_official | 87:085cde657901 | 414 | @endverbatim |
mbed_official | 87:085cde657901 | 415 | * @{ |
mbed_official | 87:085cde657901 | 416 | */ |
mbed_official | 87:085cde657901 | 417 | |
mbed_official | 87:085cde657901 | 418 | /** |
mbed_official | 87:085cde657901 | 419 | * @brief Sets RTC current time. |
mbed_official | 87:085cde657901 | 420 | * @param hrtc: RTC handle |
mbed_official | 87:085cde657901 | 421 | * @param sTime: Pointer to Time structure |
mbed_official | 87:085cde657901 | 422 | * @param Format: Specifies the format of the entered parameters. |
mbed_official | 87:085cde657901 | 423 | * This parameter can be one of the following values: |
mbed_official | 87:085cde657901 | 424 | * @arg Format_BIN: Binary data format |
mbed_official | 87:085cde657901 | 425 | * @arg Format_BCD: BCD data format |
mbed_official | 87:085cde657901 | 426 | * @retval HAL status |
mbed_official | 87:085cde657901 | 427 | */ |
mbed_official | 87:085cde657901 | 428 | HAL_StatusTypeDef HAL_RTC_SetTime(RTC_HandleTypeDef *hrtc, RTC_TimeTypeDef *sTime, uint32_t Format) |
mbed_official | 87:085cde657901 | 429 | { |
mbed_official | 87:085cde657901 | 430 | uint32_t tmpreg = 0; |
mbed_official | 87:085cde657901 | 431 | |
mbed_official | 87:085cde657901 | 432 | /* Check the parameters */ |
mbed_official | 87:085cde657901 | 433 | assert_param(IS_RTC_FORMAT(Format)); |
mbed_official | 87:085cde657901 | 434 | assert_param(IS_RTC_DAYLIGHT_SAVING(sTime->DayLightSaving)); |
mbed_official | 87:085cde657901 | 435 | assert_param(IS_RTC_STORE_OPERATION(sTime->StoreOperation)); |
mbed_official | 87:085cde657901 | 436 | |
mbed_official | 87:085cde657901 | 437 | /* Process Locked */ |
mbed_official | 87:085cde657901 | 438 | __HAL_LOCK(hrtc); |
mbed_official | 87:085cde657901 | 439 | |
mbed_official | 87:085cde657901 | 440 | hrtc->State = HAL_RTC_STATE_BUSY; |
mbed_official | 87:085cde657901 | 441 | |
mbed_official | 87:085cde657901 | 442 | if(Format == FORMAT_BIN) |
mbed_official | 87:085cde657901 | 443 | { |
mbed_official | 87:085cde657901 | 444 | if((hrtc->Instance->CR & RTC_CR_FMT) != (uint32_t)RESET) |
mbed_official | 87:085cde657901 | 445 | { |
mbed_official | 87:085cde657901 | 446 | assert_param(IS_RTC_HOUR12(sTime->Hours)); |
mbed_official | 87:085cde657901 | 447 | assert_param(IS_RTC_HOURFORMAT12(sTime->TimeFormat)); |
mbed_official | 87:085cde657901 | 448 | } |
mbed_official | 87:085cde657901 | 449 | else |
mbed_official | 87:085cde657901 | 450 | { |
mbed_official | 87:085cde657901 | 451 | sTime->TimeFormat = 0x00; |
mbed_official | 87:085cde657901 | 452 | assert_param(IS_RTC_HOUR24(sTime->Hours)); |
mbed_official | 87:085cde657901 | 453 | } |
mbed_official | 87:085cde657901 | 454 | assert_param(IS_RTC_MINUTES(sTime->Minutes)); |
mbed_official | 87:085cde657901 | 455 | assert_param(IS_RTC_SECONDS(sTime->Seconds)); |
mbed_official | 87:085cde657901 | 456 | |
mbed_official | 87:085cde657901 | 457 | tmpreg = (uint32_t)(((uint32_t)RTC_ByteToBcd2(sTime->Hours) << 16) | \ |
mbed_official | 87:085cde657901 | 458 | ((uint32_t)RTC_ByteToBcd2(sTime->Minutes) << 8) | \ |
mbed_official | 87:085cde657901 | 459 | ((uint32_t)RTC_ByteToBcd2(sTime->Seconds)) | \ |
mbed_official | 87:085cde657901 | 460 | (((uint32_t)sTime->TimeFormat) << 16)); |
mbed_official | 87:085cde657901 | 461 | } |
mbed_official | 87:085cde657901 | 462 | else |
mbed_official | 87:085cde657901 | 463 | { |
mbed_official | 87:085cde657901 | 464 | if((hrtc->Instance->CR & RTC_CR_FMT) != (uint32_t)RESET) |
mbed_official | 87:085cde657901 | 465 | { |
mbed_official | 87:085cde657901 | 466 | tmpreg = RTC_Bcd2ToByte(sTime->Hours); |
mbed_official | 87:085cde657901 | 467 | assert_param(IS_RTC_HOUR12(tmpreg)); |
mbed_official | 87:085cde657901 | 468 | assert_param(IS_RTC_HOURFORMAT12(sTime->TimeFormat)); |
mbed_official | 87:085cde657901 | 469 | } |
mbed_official | 87:085cde657901 | 470 | else |
mbed_official | 87:085cde657901 | 471 | { |
mbed_official | 87:085cde657901 | 472 | sTime->TimeFormat = 0x00; |
mbed_official | 87:085cde657901 | 473 | assert_param(IS_RTC_HOUR24(RTC_Bcd2ToByte(sTime->Hours))); |
mbed_official | 87:085cde657901 | 474 | } |
mbed_official | 87:085cde657901 | 475 | assert_param(IS_RTC_MINUTES(RTC_Bcd2ToByte(sTime->Minutes))); |
mbed_official | 87:085cde657901 | 476 | assert_param(IS_RTC_SECONDS(RTC_Bcd2ToByte(sTime->Seconds))); |
mbed_official | 87:085cde657901 | 477 | tmpreg = (((uint32_t)(sTime->Hours) << 16) | \ |
mbed_official | 87:085cde657901 | 478 | ((uint32_t)(sTime->Minutes) << 8) | \ |
mbed_official | 87:085cde657901 | 479 | ((uint32_t)sTime->Seconds) | \ |
mbed_official | 87:085cde657901 | 480 | ((uint32_t)(sTime->TimeFormat) << 16)); |
mbed_official | 87:085cde657901 | 481 | } |
mbed_official | 87:085cde657901 | 482 | |
mbed_official | 87:085cde657901 | 483 | /* Disable the write protection for RTC registers */ |
mbed_official | 87:085cde657901 | 484 | __HAL_RTC_WRITEPROTECTION_DISABLE(hrtc); |
mbed_official | 87:085cde657901 | 485 | |
mbed_official | 87:085cde657901 | 486 | /* Set Initialization mode */ |
mbed_official | 87:085cde657901 | 487 | if(RTC_EnterInitMode(hrtc) != HAL_OK) |
mbed_official | 87:085cde657901 | 488 | { |
mbed_official | 87:085cde657901 | 489 | /* Enable the write protection for RTC registers */ |
mbed_official | 87:085cde657901 | 490 | __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc); |
mbed_official | 87:085cde657901 | 491 | |
mbed_official | 87:085cde657901 | 492 | /* Set RTC state */ |
mbed_official | 87:085cde657901 | 493 | hrtc->State = HAL_RTC_STATE_ERROR; |
mbed_official | 87:085cde657901 | 494 | |
mbed_official | 87:085cde657901 | 495 | /* Process Unlocked */ |
mbed_official | 87:085cde657901 | 496 | __HAL_UNLOCK(hrtc); |
mbed_official | 87:085cde657901 | 497 | |
mbed_official | 87:085cde657901 | 498 | return HAL_ERROR; |
mbed_official | 87:085cde657901 | 499 | } |
mbed_official | 87:085cde657901 | 500 | else |
mbed_official | 87:085cde657901 | 501 | { |
mbed_official | 87:085cde657901 | 502 | /* Set the RTC_TR register */ |
mbed_official | 87:085cde657901 | 503 | hrtc->Instance->TR = (uint32_t)(tmpreg & RTC_TR_RESERVED_MASK); |
mbed_official | 87:085cde657901 | 504 | |
mbed_official | 87:085cde657901 | 505 | /* Clear the bits to be configured */ |
mbed_official | 87:085cde657901 | 506 | hrtc->Instance->CR &= (uint32_t)~RTC_CR_BCK; |
mbed_official | 87:085cde657901 | 507 | |
mbed_official | 87:085cde657901 | 508 | /* Configure the RTC_CR register */ |
mbed_official | 87:085cde657901 | 509 | hrtc->Instance->CR |= (uint32_t)(sTime->DayLightSaving | sTime->StoreOperation); |
mbed_official | 87:085cde657901 | 510 | |
mbed_official | 87:085cde657901 | 511 | /* Exit Initialization mode */ |
mbed_official | 87:085cde657901 | 512 | hrtc->Instance->ISR &= (uint32_t)~RTC_ISR_INIT; |
mbed_official | 87:085cde657901 | 513 | |
mbed_official | 87:085cde657901 | 514 | /* If CR_BYPSHAD bit = 0, wait for synchro else this check is not needed */ |
mbed_official | 87:085cde657901 | 515 | if((hrtc->Instance->CR & RTC_CR_BYPSHAD) == RESET) |
mbed_official | 87:085cde657901 | 516 | { |
mbed_official | 87:085cde657901 | 517 | if(HAL_RTC_WaitForSynchro(hrtc) != HAL_OK) |
mbed_official | 87:085cde657901 | 518 | { |
mbed_official | 87:085cde657901 | 519 | /* Enable the write protection for RTC registers */ |
mbed_official | 87:085cde657901 | 520 | __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc); |
mbed_official | 87:085cde657901 | 521 | |
mbed_official | 87:085cde657901 | 522 | hrtc->State = HAL_RTC_STATE_ERROR; |
mbed_official | 87:085cde657901 | 523 | |
mbed_official | 87:085cde657901 | 524 | /* Process Unlocked */ |
mbed_official | 87:085cde657901 | 525 | __HAL_UNLOCK(hrtc); |
mbed_official | 87:085cde657901 | 526 | |
mbed_official | 87:085cde657901 | 527 | return HAL_ERROR; |
mbed_official | 87:085cde657901 | 528 | } |
mbed_official | 87:085cde657901 | 529 | } |
mbed_official | 87:085cde657901 | 530 | |
mbed_official | 87:085cde657901 | 531 | /* Enable the write protection for RTC registers */ |
mbed_official | 87:085cde657901 | 532 | __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc); |
mbed_official | 87:085cde657901 | 533 | |
mbed_official | 87:085cde657901 | 534 | hrtc->State = HAL_RTC_STATE_READY; |
mbed_official | 87:085cde657901 | 535 | |
mbed_official | 87:085cde657901 | 536 | __HAL_UNLOCK(hrtc); |
mbed_official | 87:085cde657901 | 537 | |
mbed_official | 87:085cde657901 | 538 | return HAL_OK; |
mbed_official | 87:085cde657901 | 539 | } |
mbed_official | 87:085cde657901 | 540 | } |
mbed_official | 87:085cde657901 | 541 | |
mbed_official | 87:085cde657901 | 542 | /** |
mbed_official | 87:085cde657901 | 543 | * @brief Gets RTC current time. |
mbed_official | 87:085cde657901 | 544 | * @param hrtc: RTC handle |
mbed_official | 87:085cde657901 | 545 | * @param sTime: Pointer to Time structure |
mbed_official | 87:085cde657901 | 546 | * @param Format: Specifies the format of the entered parameters. |
mbed_official | 87:085cde657901 | 547 | * This parameter can be one of the following values: |
mbed_official | 87:085cde657901 | 548 | * @arg Format_BIN: Binary data format |
mbed_official | 87:085cde657901 | 549 | * @arg Format_BCD: BCD data format |
mbed_official | 87:085cde657901 | 550 | * @note Call HAL_RTC_GetDate() after HAL_RTC_GetTime() to unlock the values |
mbed_official | 87:085cde657901 | 551 | * in the higher-order calendar shadow registers. |
mbed_official | 87:085cde657901 | 552 | * @retval HAL status |
mbed_official | 87:085cde657901 | 553 | */ |
mbed_official | 87:085cde657901 | 554 | HAL_StatusTypeDef HAL_RTC_GetTime(RTC_HandleTypeDef *hrtc, RTC_TimeTypeDef *sTime, uint32_t Format) |
mbed_official | 87:085cde657901 | 555 | { |
mbed_official | 87:085cde657901 | 556 | uint32_t tmpreg = 0; |
mbed_official | 87:085cde657901 | 557 | |
mbed_official | 87:085cde657901 | 558 | /* Check the parameters */ |
mbed_official | 87:085cde657901 | 559 | assert_param(IS_RTC_FORMAT(Format)); |
mbed_official | 87:085cde657901 | 560 | |
mbed_official | 87:085cde657901 | 561 | /* Get subseconds values from the correspondent registers*/ |
mbed_official | 87:085cde657901 | 562 | sTime->SubSeconds = (uint32_t)(hrtc->Instance->SSR); |
mbed_official | 87:085cde657901 | 563 | |
mbed_official | 87:085cde657901 | 564 | /* Get the TR register */ |
mbed_official | 87:085cde657901 | 565 | tmpreg = (uint32_t)(hrtc->Instance->TR & RTC_TR_RESERVED_MASK); |
mbed_official | 87:085cde657901 | 566 | |
mbed_official | 87:085cde657901 | 567 | /* Fill the structure fields with the read parameters */ |
mbed_official | 87:085cde657901 | 568 | sTime->Hours = (uint8_t)((tmpreg & (RTC_TR_HT | RTC_TR_HU)) >> 16); |
mbed_official | 87:085cde657901 | 569 | sTime->Minutes = (uint8_t)((tmpreg & (RTC_TR_MNT | RTC_TR_MNU)) >>8); |
mbed_official | 87:085cde657901 | 570 | sTime->Seconds = (uint8_t)(tmpreg & (RTC_TR_ST | RTC_TR_SU)); |
mbed_official | 87:085cde657901 | 571 | sTime->TimeFormat = (uint8_t)((tmpreg & (RTC_TR_PM)) >> 16); |
mbed_official | 87:085cde657901 | 572 | |
mbed_official | 87:085cde657901 | 573 | /* Check the input parameters format */ |
mbed_official | 87:085cde657901 | 574 | if(Format == FORMAT_BIN) |
mbed_official | 87:085cde657901 | 575 | { |
mbed_official | 87:085cde657901 | 576 | /* Convert the time structure parameters to Binary format */ |
mbed_official | 87:085cde657901 | 577 | sTime->Hours = (uint8_t)RTC_Bcd2ToByte(sTime->Hours); |
mbed_official | 87:085cde657901 | 578 | sTime->Minutes = (uint8_t)RTC_Bcd2ToByte(sTime->Minutes); |
mbed_official | 87:085cde657901 | 579 | sTime->Seconds = (uint8_t)RTC_Bcd2ToByte(sTime->Seconds); |
mbed_official | 87:085cde657901 | 580 | } |
mbed_official | 87:085cde657901 | 581 | |
mbed_official | 87:085cde657901 | 582 | return HAL_OK; |
mbed_official | 87:085cde657901 | 583 | } |
mbed_official | 87:085cde657901 | 584 | |
mbed_official | 87:085cde657901 | 585 | /** |
mbed_official | 87:085cde657901 | 586 | * @brief Sets RTC current date. |
mbed_official | 87:085cde657901 | 587 | * @param hrtc: RTC handle |
mbed_official | 87:085cde657901 | 588 | * @param sDate: Pointer to date structure |
mbed_official | 87:085cde657901 | 589 | * @param Format: specifies the format of the entered parameters. |
mbed_official | 87:085cde657901 | 590 | * This parameter can be one of the following values: |
mbed_official | 87:085cde657901 | 591 | * @arg Format_BIN: Binary data format |
mbed_official | 87:085cde657901 | 592 | * @arg Format_BCD: BCD data format |
mbed_official | 87:085cde657901 | 593 | * @retval HAL status |
mbed_official | 87:085cde657901 | 594 | */ |
mbed_official | 87:085cde657901 | 595 | HAL_StatusTypeDef HAL_RTC_SetDate(RTC_HandleTypeDef *hrtc, RTC_DateTypeDef *sDate, uint32_t Format) |
mbed_official | 87:085cde657901 | 596 | { |
mbed_official | 87:085cde657901 | 597 | uint32_t datetmpreg = 0; |
mbed_official | 87:085cde657901 | 598 | |
mbed_official | 87:085cde657901 | 599 | /* Check the parameters */ |
mbed_official | 87:085cde657901 | 600 | assert_param(IS_RTC_FORMAT(Format)); |
mbed_official | 87:085cde657901 | 601 | |
mbed_official | 87:085cde657901 | 602 | /* Process Locked */ |
mbed_official | 87:085cde657901 | 603 | __HAL_LOCK(hrtc); |
mbed_official | 87:085cde657901 | 604 | |
mbed_official | 87:085cde657901 | 605 | hrtc->State = HAL_RTC_STATE_BUSY; |
mbed_official | 87:085cde657901 | 606 | |
mbed_official | 87:085cde657901 | 607 | if((Format == FORMAT_BIN) && ((sDate->Month & 0x10) == 0x10)) |
mbed_official | 87:085cde657901 | 608 | { |
mbed_official | 87:085cde657901 | 609 | sDate->Month = (uint8_t)((sDate->Month & (uint8_t)~(0x10)) + (uint8_t)0x0A); |
mbed_official | 87:085cde657901 | 610 | } |
mbed_official | 87:085cde657901 | 611 | |
mbed_official | 87:085cde657901 | 612 | assert_param(IS_RTC_WEEKDAY(sDate->WeekDay)); |
mbed_official | 87:085cde657901 | 613 | |
mbed_official | 87:085cde657901 | 614 | if(Format == FORMAT_BIN) |
mbed_official | 87:085cde657901 | 615 | { |
mbed_official | 87:085cde657901 | 616 | assert_param(IS_RTC_YEAR(sDate->Year)); |
mbed_official | 87:085cde657901 | 617 | assert_param(IS_RTC_MONTH(sDate->Month)); |
mbed_official | 87:085cde657901 | 618 | assert_param(IS_RTC_DATE(sDate->Date)); |
mbed_official | 87:085cde657901 | 619 | |
mbed_official | 87:085cde657901 | 620 | datetmpreg = (((uint32_t)RTC_ByteToBcd2(sDate->Year) << 16) | \ |
mbed_official | 87:085cde657901 | 621 | ((uint32_t)RTC_ByteToBcd2(sDate->Month) << 8) | \ |
mbed_official | 87:085cde657901 | 622 | ((uint32_t)RTC_ByteToBcd2(sDate->Date)) | \ |
mbed_official | 87:085cde657901 | 623 | ((uint32_t)sDate->WeekDay << 13)); |
mbed_official | 87:085cde657901 | 624 | } |
mbed_official | 87:085cde657901 | 625 | else |
mbed_official | 87:085cde657901 | 626 | { |
mbed_official | 87:085cde657901 | 627 | assert_param(IS_RTC_YEAR(RTC_Bcd2ToByte(sDate->Year))); |
mbed_official | 87:085cde657901 | 628 | datetmpreg = RTC_Bcd2ToByte(sDate->Month); |
mbed_official | 87:085cde657901 | 629 | assert_param(IS_RTC_MONTH(datetmpreg)); |
mbed_official | 87:085cde657901 | 630 | datetmpreg = RTC_Bcd2ToByte(sDate->Date); |
mbed_official | 87:085cde657901 | 631 | assert_param(IS_RTC_DATE(datetmpreg)); |
mbed_official | 87:085cde657901 | 632 | |
mbed_official | 87:085cde657901 | 633 | datetmpreg = ((((uint32_t)sDate->Year) << 16) | \ |
mbed_official | 87:085cde657901 | 634 | (((uint32_t)sDate->Month) << 8) | \ |
mbed_official | 87:085cde657901 | 635 | ((uint32_t)sDate->Date) | \ |
mbed_official | 87:085cde657901 | 636 | (((uint32_t)sDate->WeekDay) << 13)); |
mbed_official | 87:085cde657901 | 637 | } |
mbed_official | 87:085cde657901 | 638 | |
mbed_official | 87:085cde657901 | 639 | /* Disable the write protection for RTC registers */ |
mbed_official | 87:085cde657901 | 640 | __HAL_RTC_WRITEPROTECTION_DISABLE(hrtc); |
mbed_official | 87:085cde657901 | 641 | |
mbed_official | 87:085cde657901 | 642 | /* Set Initialization mode */ |
mbed_official | 87:085cde657901 | 643 | if(RTC_EnterInitMode(hrtc) != HAL_OK) |
mbed_official | 87:085cde657901 | 644 | { |
mbed_official | 87:085cde657901 | 645 | /* Enable the write protection for RTC registers */ |
mbed_official | 87:085cde657901 | 646 | __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc); |
mbed_official | 87:085cde657901 | 647 | |
mbed_official | 87:085cde657901 | 648 | /* Set RTC state*/ |
mbed_official | 87:085cde657901 | 649 | hrtc->State = HAL_RTC_STATE_ERROR; |
mbed_official | 87:085cde657901 | 650 | |
mbed_official | 87:085cde657901 | 651 | /* Process Unlocked */ |
mbed_official | 87:085cde657901 | 652 | __HAL_UNLOCK(hrtc); |
mbed_official | 87:085cde657901 | 653 | |
mbed_official | 87:085cde657901 | 654 | return HAL_ERROR; |
mbed_official | 87:085cde657901 | 655 | } |
mbed_official | 87:085cde657901 | 656 | else |
mbed_official | 87:085cde657901 | 657 | { |
mbed_official | 87:085cde657901 | 658 | /* Set the RTC_DR register */ |
mbed_official | 87:085cde657901 | 659 | hrtc->Instance->DR = (uint32_t)(datetmpreg & RTC_DR_RESERVED_MASK); |
mbed_official | 87:085cde657901 | 660 | |
mbed_official | 87:085cde657901 | 661 | /* Exit Initialization mode */ |
mbed_official | 87:085cde657901 | 662 | hrtc->Instance->ISR &= (uint32_t)~RTC_ISR_INIT; |
mbed_official | 87:085cde657901 | 663 | |
mbed_official | 87:085cde657901 | 664 | /* If CR_BYPSHAD bit = 0, wait for synchro else this check is not needed */ |
mbed_official | 87:085cde657901 | 665 | if((hrtc->Instance->CR & RTC_CR_BYPSHAD) == RESET) |
mbed_official | 87:085cde657901 | 666 | { |
mbed_official | 87:085cde657901 | 667 | if(HAL_RTC_WaitForSynchro(hrtc) != HAL_OK) |
mbed_official | 87:085cde657901 | 668 | { |
mbed_official | 87:085cde657901 | 669 | /* Enable the write protection for RTC registers */ |
mbed_official | 87:085cde657901 | 670 | __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc); |
mbed_official | 87:085cde657901 | 671 | |
mbed_official | 87:085cde657901 | 672 | hrtc->State = HAL_RTC_STATE_ERROR; |
mbed_official | 87:085cde657901 | 673 | |
mbed_official | 87:085cde657901 | 674 | /* Process Unlocked */ |
mbed_official | 87:085cde657901 | 675 | __HAL_UNLOCK(hrtc); |
mbed_official | 87:085cde657901 | 676 | |
mbed_official | 87:085cde657901 | 677 | return HAL_ERROR; |
mbed_official | 87:085cde657901 | 678 | } |
mbed_official | 87:085cde657901 | 679 | } |
mbed_official | 87:085cde657901 | 680 | |
mbed_official | 87:085cde657901 | 681 | /* Enable the write protection for RTC registers */ |
mbed_official | 87:085cde657901 | 682 | __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc); |
mbed_official | 87:085cde657901 | 683 | |
mbed_official | 87:085cde657901 | 684 | hrtc->State = HAL_RTC_STATE_READY ; |
mbed_official | 87:085cde657901 | 685 | |
mbed_official | 87:085cde657901 | 686 | /* Process Unlocked */ |
mbed_official | 87:085cde657901 | 687 | __HAL_UNLOCK(hrtc); |
mbed_official | 87:085cde657901 | 688 | |
mbed_official | 87:085cde657901 | 689 | return HAL_OK; |
mbed_official | 87:085cde657901 | 690 | } |
mbed_official | 87:085cde657901 | 691 | } |
mbed_official | 87:085cde657901 | 692 | |
mbed_official | 87:085cde657901 | 693 | /** |
mbed_official | 87:085cde657901 | 694 | * @brief Gets RTC current date. |
mbed_official | 87:085cde657901 | 695 | * @param hrtc: RTC handle |
mbed_official | 87:085cde657901 | 696 | * @param sDate: Pointer to Date structure |
mbed_official | 87:085cde657901 | 697 | * @param Format: Specifies the format of the entered parameters. |
mbed_official | 87:085cde657901 | 698 | * This parameter can be one of the following values: |
mbed_official | 87:085cde657901 | 699 | * @arg Format_BIN : Binary data format |
mbed_official | 87:085cde657901 | 700 | * @arg Format_BCD : BCD data format |
mbed_official | 87:085cde657901 | 701 | * @retval HAL status |
mbed_official | 87:085cde657901 | 702 | */ |
mbed_official | 87:085cde657901 | 703 | HAL_StatusTypeDef HAL_RTC_GetDate(RTC_HandleTypeDef *hrtc, RTC_DateTypeDef *sDate, uint32_t Format) |
mbed_official | 87:085cde657901 | 704 | { |
mbed_official | 87:085cde657901 | 705 | uint32_t datetmpreg = 0; |
mbed_official | 87:085cde657901 | 706 | |
mbed_official | 87:085cde657901 | 707 | /* Check the parameters */ |
mbed_official | 87:085cde657901 | 708 | assert_param(IS_RTC_FORMAT(Format)); |
mbed_official | 87:085cde657901 | 709 | |
mbed_official | 87:085cde657901 | 710 | /* Get the DR register */ |
mbed_official | 87:085cde657901 | 711 | datetmpreg = (uint32_t)(hrtc->Instance->DR & RTC_DR_RESERVED_MASK); |
mbed_official | 87:085cde657901 | 712 | |
mbed_official | 87:085cde657901 | 713 | /* Fill the structure fields with the read parameters */ |
mbed_official | 87:085cde657901 | 714 | sDate->Year = (uint8_t)((datetmpreg & (RTC_DR_YT | RTC_DR_YU)) >> 16); |
mbed_official | 87:085cde657901 | 715 | sDate->Month = (uint8_t)((datetmpreg & (RTC_DR_MT | RTC_DR_MU)) >> 8); |
mbed_official | 87:085cde657901 | 716 | sDate->Date = (uint8_t)(datetmpreg & (RTC_DR_DT | RTC_DR_DU)); |
mbed_official | 87:085cde657901 | 717 | sDate->WeekDay = (uint8_t)((datetmpreg & (RTC_DR_WDU)) >> 13); |
mbed_official | 87:085cde657901 | 718 | |
mbed_official | 87:085cde657901 | 719 | /* Check the input parameters format */ |
mbed_official | 87:085cde657901 | 720 | if(Format == FORMAT_BIN) |
mbed_official | 87:085cde657901 | 721 | { |
mbed_official | 87:085cde657901 | 722 | /* Convert the date structure parameters to Binary format */ |
mbed_official | 87:085cde657901 | 723 | sDate->Year = (uint8_t)RTC_Bcd2ToByte(sDate->Year); |
mbed_official | 87:085cde657901 | 724 | sDate->Month = (uint8_t)RTC_Bcd2ToByte(sDate->Month); |
mbed_official | 87:085cde657901 | 725 | sDate->Date = (uint8_t)RTC_Bcd2ToByte(sDate->Date); |
mbed_official | 87:085cde657901 | 726 | } |
mbed_official | 87:085cde657901 | 727 | return HAL_OK; |
mbed_official | 87:085cde657901 | 728 | } |
mbed_official | 87:085cde657901 | 729 | |
mbed_official | 87:085cde657901 | 730 | /** |
mbed_official | 87:085cde657901 | 731 | * @} |
mbed_official | 87:085cde657901 | 732 | */ |
mbed_official | 87:085cde657901 | 733 | |
mbed_official | 87:085cde657901 | 734 | /** @defgroup RTC_Group3 RTC Alarm functions |
mbed_official | 87:085cde657901 | 735 | * @brief RTC Alarm functions |
mbed_official | 87:085cde657901 | 736 | * |
mbed_official | 87:085cde657901 | 737 | @verbatim |
mbed_official | 87:085cde657901 | 738 | =============================================================================== |
mbed_official | 87:085cde657901 | 739 | ##### RTC Alarm functions ##### |
mbed_official | 87:085cde657901 | 740 | =============================================================================== |
mbed_official | 87:085cde657901 | 741 | |
mbed_official | 87:085cde657901 | 742 | [..] This section provide functions allowing to configure Alarm feature |
mbed_official | 87:085cde657901 | 743 | |
mbed_official | 87:085cde657901 | 744 | @endverbatim |
mbed_official | 87:085cde657901 | 745 | * @{ |
mbed_official | 87:085cde657901 | 746 | */ |
mbed_official | 87:085cde657901 | 747 | /** |
mbed_official | 87:085cde657901 | 748 | * @brief Sets the specified RTC Alarm. |
mbed_official | 87:085cde657901 | 749 | * @param hrtc: RTC handle |
mbed_official | 87:085cde657901 | 750 | * @param sAlarm: Pointer to Alarm structure |
mbed_official | 87:085cde657901 | 751 | * @param Format: Specifies the format of the entered parameters. |
mbed_official | 87:085cde657901 | 752 | * This parameter can be one of the following values: |
mbed_official | 87:085cde657901 | 753 | * @arg Format_BIN: Binary data format |
mbed_official | 87:085cde657901 | 754 | * @arg Format_BCD: BCD data format |
mbed_official | 87:085cde657901 | 755 | * @retval HAL status |
mbed_official | 87:085cde657901 | 756 | */ |
mbed_official | 87:085cde657901 | 757 | HAL_StatusTypeDef HAL_RTC_SetAlarm(RTC_HandleTypeDef *hrtc, RTC_AlarmTypeDef *sAlarm, uint32_t Format) |
mbed_official | 87:085cde657901 | 758 | { |
mbed_official | 87:085cde657901 | 759 | uint32_t timeout = 0; |
mbed_official | 87:085cde657901 | 760 | uint32_t tmpreg = 0, subsecondtmpreg = 0; |
mbed_official | 87:085cde657901 | 761 | |
mbed_official | 87:085cde657901 | 762 | /* Check the parameters */ |
mbed_official | 87:085cde657901 | 763 | assert_param(IS_RTC_FORMAT(Format)); |
mbed_official | 87:085cde657901 | 764 | assert_param(IS_ALARM(sAlarm->Alarm)); |
mbed_official | 87:085cde657901 | 765 | assert_param(IS_ALARM_MASK(sAlarm->AlarmMask)); |
mbed_official | 87:085cde657901 | 766 | assert_param(IS_RTC_ALARM_DATE_WEEKDAY_SEL(sAlarm->AlarmDateWeekDaySel)); |
mbed_official | 87:085cde657901 | 767 | assert_param(IS_RTC_ALARM_SUB_SECOND_VALUE(sAlarm->AlarmTime.SubSeconds)); |
mbed_official | 87:085cde657901 | 768 | assert_param(IS_RTC_ALARM_SUB_SECOND_MASK(sAlarm->AlarmSubSecondMask)); |
mbed_official | 87:085cde657901 | 769 | |
mbed_official | 87:085cde657901 | 770 | /* Process Locked */ |
mbed_official | 87:085cde657901 | 771 | __HAL_LOCK(hrtc); |
mbed_official | 87:085cde657901 | 772 | |
mbed_official | 87:085cde657901 | 773 | hrtc->State = HAL_RTC_STATE_BUSY; |
mbed_official | 87:085cde657901 | 774 | |
mbed_official | 87:085cde657901 | 775 | if(Format == FORMAT_BIN) |
mbed_official | 87:085cde657901 | 776 | { |
mbed_official | 87:085cde657901 | 777 | if((hrtc->Instance->CR & RTC_CR_FMT) != (uint32_t)RESET) |
mbed_official | 87:085cde657901 | 778 | { |
mbed_official | 87:085cde657901 | 779 | assert_param(IS_RTC_HOUR12(sAlarm->AlarmTime.Hours)); |
mbed_official | 87:085cde657901 | 780 | assert_param(IS_RTC_HOURFORMAT12(sAlarm->AlarmTime.TimeFormat)); |
mbed_official | 87:085cde657901 | 781 | } |
mbed_official | 87:085cde657901 | 782 | else |
mbed_official | 87:085cde657901 | 783 | { |
mbed_official | 87:085cde657901 | 784 | sAlarm->AlarmTime.TimeFormat = 0x00; |
mbed_official | 87:085cde657901 | 785 | assert_param(IS_RTC_HOUR24(sAlarm->AlarmTime.Hours)); |
mbed_official | 87:085cde657901 | 786 | } |
mbed_official | 87:085cde657901 | 787 | assert_param(IS_RTC_MINUTES(sAlarm->AlarmTime.Minutes)); |
mbed_official | 87:085cde657901 | 788 | assert_param(IS_RTC_SECONDS(sAlarm->AlarmTime.Seconds)); |
mbed_official | 87:085cde657901 | 789 | |
mbed_official | 87:085cde657901 | 790 | if(sAlarm->AlarmDateWeekDaySel == RTC_ALARMDATEWEEKDAYSEL_DATE) |
mbed_official | 87:085cde657901 | 791 | { |
mbed_official | 87:085cde657901 | 792 | assert_param(IS_RTC_ALARM_DATE_WEEKDAY_DATE(sAlarm->AlarmDateWeekDay)); |
mbed_official | 87:085cde657901 | 793 | } |
mbed_official | 87:085cde657901 | 794 | else |
mbed_official | 87:085cde657901 | 795 | { |
mbed_official | 87:085cde657901 | 796 | assert_param(IS_RTC_ALARM_DATE_WEEKDAY_WEEKDAY(sAlarm->AlarmDateWeekDay)); |
mbed_official | 87:085cde657901 | 797 | } |
mbed_official | 87:085cde657901 | 798 | |
mbed_official | 87:085cde657901 | 799 | tmpreg = (((uint32_t)RTC_ByteToBcd2(sAlarm->AlarmTime.Hours) << 16) | \ |
mbed_official | 87:085cde657901 | 800 | ((uint32_t)RTC_ByteToBcd2(sAlarm->AlarmTime.Minutes) << 8) | \ |
mbed_official | 87:085cde657901 | 801 | ((uint32_t)RTC_ByteToBcd2(sAlarm->AlarmTime.Seconds)) | \ |
mbed_official | 87:085cde657901 | 802 | ((uint32_t)(sAlarm->AlarmTime.TimeFormat) << 16) | \ |
mbed_official | 87:085cde657901 | 803 | ((uint32_t)RTC_ByteToBcd2(sAlarm->AlarmDateWeekDay) << 24) | \ |
mbed_official | 87:085cde657901 | 804 | ((uint32_t)sAlarm->AlarmDateWeekDaySel) | \ |
mbed_official | 87:085cde657901 | 805 | ((uint32_t)sAlarm->AlarmMask)); |
mbed_official | 87:085cde657901 | 806 | } |
mbed_official | 87:085cde657901 | 807 | else |
mbed_official | 87:085cde657901 | 808 | { |
mbed_official | 87:085cde657901 | 809 | if((hrtc->Instance->CR & RTC_CR_FMT) != (uint32_t)RESET) |
mbed_official | 87:085cde657901 | 810 | { |
mbed_official | 87:085cde657901 | 811 | tmpreg = RTC_Bcd2ToByte(sAlarm->AlarmTime.Hours); |
mbed_official | 87:085cde657901 | 812 | assert_param(IS_RTC_HOUR12(tmpreg)); |
mbed_official | 87:085cde657901 | 813 | assert_param(IS_RTC_HOURFORMAT12(sAlarm->AlarmTime.TimeFormat)); |
mbed_official | 87:085cde657901 | 814 | } |
mbed_official | 87:085cde657901 | 815 | else |
mbed_official | 87:085cde657901 | 816 | { |
mbed_official | 87:085cde657901 | 817 | sAlarm->AlarmTime.TimeFormat = 0x00; |
mbed_official | 87:085cde657901 | 818 | assert_param(IS_RTC_HOUR24(RTC_Bcd2ToByte(sAlarm->AlarmTime.Hours))); |
mbed_official | 87:085cde657901 | 819 | } |
mbed_official | 87:085cde657901 | 820 | |
mbed_official | 87:085cde657901 | 821 | assert_param(IS_RTC_MINUTES(RTC_Bcd2ToByte(sAlarm->AlarmTime.Minutes))); |
mbed_official | 87:085cde657901 | 822 | assert_param(IS_RTC_SECONDS(RTC_Bcd2ToByte(sAlarm->AlarmTime.Seconds))); |
mbed_official | 87:085cde657901 | 823 | |
mbed_official | 87:085cde657901 | 824 | if(sAlarm->AlarmDateWeekDaySel == RTC_ALARMDATEWEEKDAYSEL_DATE) |
mbed_official | 87:085cde657901 | 825 | { |
mbed_official | 87:085cde657901 | 826 | tmpreg = RTC_Bcd2ToByte(sAlarm->AlarmDateWeekDay); |
mbed_official | 87:085cde657901 | 827 | assert_param(IS_RTC_ALARM_DATE_WEEKDAY_DATE(tmpreg)); |
mbed_official | 87:085cde657901 | 828 | } |
mbed_official | 87:085cde657901 | 829 | else |
mbed_official | 87:085cde657901 | 830 | { |
mbed_official | 87:085cde657901 | 831 | tmpreg = RTC_Bcd2ToByte(sAlarm->AlarmDateWeekDay); |
mbed_official | 87:085cde657901 | 832 | assert_param(IS_RTC_ALARM_DATE_WEEKDAY_WEEKDAY(tmpreg)); |
mbed_official | 87:085cde657901 | 833 | } |
mbed_official | 87:085cde657901 | 834 | |
mbed_official | 87:085cde657901 | 835 | tmpreg = (((uint32_t)(sAlarm->AlarmTime.Hours) << 16) | \ |
mbed_official | 87:085cde657901 | 836 | ((uint32_t)(sAlarm->AlarmTime.Minutes) << 8) | \ |
mbed_official | 87:085cde657901 | 837 | ((uint32_t) sAlarm->AlarmTime.Seconds) | \ |
mbed_official | 87:085cde657901 | 838 | ((uint32_t)(sAlarm->AlarmTime.TimeFormat) << 16) | \ |
mbed_official | 87:085cde657901 | 839 | ((uint32_t)(sAlarm->AlarmDateWeekDay) << 24) | \ |
mbed_official | 87:085cde657901 | 840 | ((uint32_t)sAlarm->AlarmDateWeekDaySel) | \ |
mbed_official | 87:085cde657901 | 841 | ((uint32_t)sAlarm->AlarmMask)); |
mbed_official | 87:085cde657901 | 842 | } |
mbed_official | 87:085cde657901 | 843 | |
mbed_official | 87:085cde657901 | 844 | /* Configure the Alarm A or Alarm B Sub Second registers */ |
mbed_official | 87:085cde657901 | 845 | subsecondtmpreg = (uint32_t)((uint32_t)(sAlarm->AlarmTime.SubSeconds) | (uint32_t)(sAlarm->AlarmSubSecondMask)); |
mbed_official | 87:085cde657901 | 846 | |
mbed_official | 87:085cde657901 | 847 | /* Disable the write protection for RTC registers */ |
mbed_official | 87:085cde657901 | 848 | __HAL_RTC_WRITEPROTECTION_DISABLE(hrtc); |
mbed_official | 87:085cde657901 | 849 | |
mbed_official | 87:085cde657901 | 850 | /* Configure the Alarm register */ |
mbed_official | 87:085cde657901 | 851 | if(sAlarm->Alarm == RTC_ALARM_A) |
mbed_official | 87:085cde657901 | 852 | { |
mbed_official | 87:085cde657901 | 853 | /* Disable the Alarm A interrupt */ |
mbed_official | 87:085cde657901 | 854 | __HAL_RTC_ALARMA_DISABLE(hrtc); |
mbed_official | 87:085cde657901 | 855 | |
mbed_official | 87:085cde657901 | 856 | /* In case of interrupt mode is used, the interrupt source must disabled */ |
mbed_official | 87:085cde657901 | 857 | __HAL_RTC_ALARM_DISABLE_IT(hrtc, RTC_IT_ALRA); |
mbed_official | 87:085cde657901 | 858 | |
mbed_official | 87:085cde657901 | 859 | timeout = HAL_GetTick() + RTC_TIMEOUT_VALUE; |
mbed_official | 87:085cde657901 | 860 | /* Wait till RTC ALRAWF flag is set and if Time out is reached exit */ |
mbed_official | 87:085cde657901 | 861 | while(__HAL_RTC_ALARM_GET_FLAG(hrtc, RTC_FLAG_ALRAWF) == RESET) |
mbed_official | 87:085cde657901 | 862 | { |
mbed_official | 87:085cde657901 | 863 | if(HAL_GetTick() >= timeout) |
mbed_official | 87:085cde657901 | 864 | { |
mbed_official | 87:085cde657901 | 865 | /* Enable the write protection for RTC registers */ |
mbed_official | 87:085cde657901 | 866 | __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc); |
mbed_official | 87:085cde657901 | 867 | |
mbed_official | 87:085cde657901 | 868 | hrtc->State = HAL_RTC_STATE_TIMEOUT; |
mbed_official | 87:085cde657901 | 869 | |
mbed_official | 87:085cde657901 | 870 | /* Process Unlocked */ |
mbed_official | 87:085cde657901 | 871 | __HAL_UNLOCK(hrtc); |
mbed_official | 87:085cde657901 | 872 | |
mbed_official | 87:085cde657901 | 873 | return HAL_TIMEOUT; |
mbed_official | 87:085cde657901 | 874 | } |
mbed_official | 87:085cde657901 | 875 | } |
mbed_official | 87:085cde657901 | 876 | |
mbed_official | 87:085cde657901 | 877 | hrtc->Instance->ALRMAR = (uint32_t)tmpreg; |
mbed_official | 87:085cde657901 | 878 | /* Configure the Alarm A Sub Second register */ |
mbed_official | 87:085cde657901 | 879 | hrtc->Instance->ALRMASSR = subsecondtmpreg; |
mbed_official | 87:085cde657901 | 880 | /* Configure the Alarm state: Enable Alarm */ |
mbed_official | 87:085cde657901 | 881 | __HAL_RTC_ALARMA_ENABLE(hrtc); |
mbed_official | 87:085cde657901 | 882 | } |
mbed_official | 87:085cde657901 | 883 | else |
mbed_official | 87:085cde657901 | 884 | { |
mbed_official | 87:085cde657901 | 885 | /* Disable the Alarm B interrupt */ |
mbed_official | 87:085cde657901 | 886 | __HAL_RTC_ALARMB_DISABLE(hrtc); |
mbed_official | 87:085cde657901 | 887 | |
mbed_official | 87:085cde657901 | 888 | /* In case of interrupt mode is used, the interrupt source must disabled */ |
mbed_official | 87:085cde657901 | 889 | __HAL_RTC_ALARM_DISABLE_IT(hrtc, RTC_IT_ALRB); |
mbed_official | 87:085cde657901 | 890 | |
mbed_official | 87:085cde657901 | 891 | timeout = HAL_GetTick() + RTC_TIMEOUT_VALUE; |
mbed_official | 87:085cde657901 | 892 | /* Wait till RTC ALRBWF flag is set and if Time out is reached exit */ |
mbed_official | 87:085cde657901 | 893 | while(__HAL_RTC_ALARM_GET_FLAG(hrtc, RTC_FLAG_ALRBWF) == RESET) |
mbed_official | 87:085cde657901 | 894 | { |
mbed_official | 87:085cde657901 | 895 | if(HAL_GetTick() >= timeout) |
mbed_official | 87:085cde657901 | 896 | { |
mbed_official | 87:085cde657901 | 897 | /* Enable the write protection for RTC registers */ |
mbed_official | 87:085cde657901 | 898 | __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc); |
mbed_official | 87:085cde657901 | 899 | |
mbed_official | 87:085cde657901 | 900 | hrtc->State = HAL_RTC_STATE_TIMEOUT; |
mbed_official | 87:085cde657901 | 901 | |
mbed_official | 87:085cde657901 | 902 | /* Process Unlocked */ |
mbed_official | 87:085cde657901 | 903 | __HAL_UNLOCK(hrtc); |
mbed_official | 87:085cde657901 | 904 | |
mbed_official | 87:085cde657901 | 905 | return HAL_TIMEOUT; |
mbed_official | 87:085cde657901 | 906 | } |
mbed_official | 87:085cde657901 | 907 | } |
mbed_official | 87:085cde657901 | 908 | |
mbed_official | 87:085cde657901 | 909 | hrtc->Instance->ALRMBR = (uint32_t)tmpreg; |
mbed_official | 87:085cde657901 | 910 | /* Configure the Alarm B Sub Second register */ |
mbed_official | 87:085cde657901 | 911 | hrtc->Instance->ALRMBSSR = subsecondtmpreg; |
mbed_official | 87:085cde657901 | 912 | /* Configure the Alarm state: Enable Alarm */ |
mbed_official | 87:085cde657901 | 913 | __HAL_RTC_ALARMB_ENABLE(hrtc); |
mbed_official | 87:085cde657901 | 914 | } |
mbed_official | 87:085cde657901 | 915 | |
mbed_official | 87:085cde657901 | 916 | /* Enable the write protection for RTC registers */ |
mbed_official | 87:085cde657901 | 917 | __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc); |
mbed_official | 87:085cde657901 | 918 | |
mbed_official | 87:085cde657901 | 919 | /* Change RTC state */ |
mbed_official | 87:085cde657901 | 920 | hrtc->State = HAL_RTC_STATE_READY; |
mbed_official | 87:085cde657901 | 921 | |
mbed_official | 87:085cde657901 | 922 | /* Process Unlocked */ |
mbed_official | 87:085cde657901 | 923 | __HAL_UNLOCK(hrtc); |
mbed_official | 87:085cde657901 | 924 | |
mbed_official | 87:085cde657901 | 925 | return HAL_OK; |
mbed_official | 87:085cde657901 | 926 | } |
mbed_official | 87:085cde657901 | 927 | |
mbed_official | 87:085cde657901 | 928 | /** |
mbed_official | 87:085cde657901 | 929 | * @brief Sets the specified RTC Alarm with Interrupt |
mbed_official | 87:085cde657901 | 930 | * @param hrtc: RTC handle |
mbed_official | 87:085cde657901 | 931 | * @param sAlarm: Pointer to Alarm structure |
mbed_official | 87:085cde657901 | 932 | * @param Format: Specifies the format of the entered parameters. |
mbed_official | 87:085cde657901 | 933 | * This parameter can be one of the following values: |
mbed_official | 87:085cde657901 | 934 | * @arg Format_BIN: Binary data format |
mbed_official | 87:085cde657901 | 935 | * @arg Format_BCD: BCD data format |
mbed_official | 87:085cde657901 | 936 | * @retval HAL status |
mbed_official | 87:085cde657901 | 937 | */ |
mbed_official | 87:085cde657901 | 938 | HAL_StatusTypeDef HAL_RTC_SetAlarm_IT(RTC_HandleTypeDef *hrtc, RTC_AlarmTypeDef *sAlarm, uint32_t Format) |
mbed_official | 87:085cde657901 | 939 | { |
mbed_official | 87:085cde657901 | 940 | uint32_t timeout = 0; |
mbed_official | 87:085cde657901 | 941 | uint32_t tmpreg = 0, subsecondtmpreg = 0; |
mbed_official | 87:085cde657901 | 942 | |
mbed_official | 87:085cde657901 | 943 | /* Check the parameters */ |
mbed_official | 87:085cde657901 | 944 | assert_param(IS_RTC_FORMAT(Format)); |
mbed_official | 87:085cde657901 | 945 | assert_param(IS_ALARM(sAlarm->Alarm)); |
mbed_official | 87:085cde657901 | 946 | assert_param(IS_ALARM_MASK(sAlarm->AlarmMask)); |
mbed_official | 87:085cde657901 | 947 | assert_param(IS_RTC_ALARM_DATE_WEEKDAY_SEL(sAlarm->AlarmDateWeekDaySel)); |
mbed_official | 87:085cde657901 | 948 | assert_param(IS_RTC_ALARM_SUB_SECOND_VALUE(sAlarm->AlarmTime.SubSeconds)); |
mbed_official | 87:085cde657901 | 949 | assert_param(IS_RTC_ALARM_SUB_SECOND_MASK(sAlarm->AlarmSubSecondMask)); |
mbed_official | 87:085cde657901 | 950 | |
mbed_official | 87:085cde657901 | 951 | /* Process Locked */ |
mbed_official | 87:085cde657901 | 952 | __HAL_LOCK(hrtc); |
mbed_official | 87:085cde657901 | 953 | |
mbed_official | 87:085cde657901 | 954 | hrtc->State = HAL_RTC_STATE_BUSY; |
mbed_official | 87:085cde657901 | 955 | |
mbed_official | 87:085cde657901 | 956 | if(Format == FORMAT_BIN) |
mbed_official | 87:085cde657901 | 957 | { |
mbed_official | 87:085cde657901 | 958 | if((hrtc->Instance->CR & RTC_CR_FMT) != (uint32_t)RESET) |
mbed_official | 87:085cde657901 | 959 | { |
mbed_official | 87:085cde657901 | 960 | assert_param(IS_RTC_HOUR12(sAlarm->AlarmTime.Hours)); |
mbed_official | 87:085cde657901 | 961 | assert_param(IS_RTC_HOURFORMAT12(sAlarm->AlarmTime.TimeFormat)); |
mbed_official | 87:085cde657901 | 962 | } |
mbed_official | 87:085cde657901 | 963 | else |
mbed_official | 87:085cde657901 | 964 | { |
mbed_official | 87:085cde657901 | 965 | sAlarm->AlarmTime.TimeFormat = 0x00; |
mbed_official | 87:085cde657901 | 966 | assert_param(IS_RTC_HOUR24(sAlarm->AlarmTime.Hours)); |
mbed_official | 87:085cde657901 | 967 | } |
mbed_official | 87:085cde657901 | 968 | assert_param(IS_RTC_MINUTES(sAlarm->AlarmTime.Minutes)); |
mbed_official | 87:085cde657901 | 969 | assert_param(IS_RTC_SECONDS(sAlarm->AlarmTime.Seconds)); |
mbed_official | 87:085cde657901 | 970 | |
mbed_official | 87:085cde657901 | 971 | if(sAlarm->AlarmDateWeekDaySel == RTC_ALARMDATEWEEKDAYSEL_DATE) |
mbed_official | 87:085cde657901 | 972 | { |
mbed_official | 87:085cde657901 | 973 | assert_param(IS_RTC_ALARM_DATE_WEEKDAY_DATE(sAlarm->AlarmDateWeekDay)); |
mbed_official | 87:085cde657901 | 974 | } |
mbed_official | 87:085cde657901 | 975 | else |
mbed_official | 87:085cde657901 | 976 | { |
mbed_official | 87:085cde657901 | 977 | assert_param(IS_RTC_ALARM_DATE_WEEKDAY_WEEKDAY(sAlarm->AlarmDateWeekDay)); |
mbed_official | 87:085cde657901 | 978 | } |
mbed_official | 87:085cde657901 | 979 | tmpreg = (((uint32_t)RTC_ByteToBcd2(sAlarm->AlarmTime.Hours) << 16) | \ |
mbed_official | 87:085cde657901 | 980 | ((uint32_t)RTC_ByteToBcd2(sAlarm->AlarmTime.Minutes) << 8) | \ |
mbed_official | 87:085cde657901 | 981 | ((uint32_t)RTC_ByteToBcd2(sAlarm->AlarmTime.Seconds)) | \ |
mbed_official | 87:085cde657901 | 982 | ((uint32_t)(sAlarm->AlarmTime.TimeFormat) << 16) | \ |
mbed_official | 87:085cde657901 | 983 | ((uint32_t)RTC_ByteToBcd2(sAlarm->AlarmDateWeekDay) << 24) | \ |
mbed_official | 87:085cde657901 | 984 | ((uint32_t)sAlarm->AlarmDateWeekDaySel) | \ |
mbed_official | 87:085cde657901 | 985 | ((uint32_t)sAlarm->AlarmMask)); |
mbed_official | 87:085cde657901 | 986 | } |
mbed_official | 87:085cde657901 | 987 | else |
mbed_official | 87:085cde657901 | 988 | { |
mbed_official | 87:085cde657901 | 989 | if((hrtc->Instance->CR & RTC_CR_FMT) != (uint32_t)RESET) |
mbed_official | 87:085cde657901 | 990 | { |
mbed_official | 87:085cde657901 | 991 | tmpreg = RTC_Bcd2ToByte(sAlarm->AlarmTime.Hours); |
mbed_official | 87:085cde657901 | 992 | assert_param(IS_RTC_HOUR12(tmpreg)); |
mbed_official | 87:085cde657901 | 993 | assert_param(IS_RTC_HOURFORMAT12(sAlarm->AlarmTime.TimeFormat)); |
mbed_official | 87:085cde657901 | 994 | } |
mbed_official | 87:085cde657901 | 995 | else |
mbed_official | 87:085cde657901 | 996 | { |
mbed_official | 87:085cde657901 | 997 | sAlarm->AlarmTime.TimeFormat = 0x00; |
mbed_official | 87:085cde657901 | 998 | assert_param(IS_RTC_HOUR24(RTC_Bcd2ToByte(sAlarm->AlarmTime.Hours))); |
mbed_official | 87:085cde657901 | 999 | } |
mbed_official | 87:085cde657901 | 1000 | |
mbed_official | 87:085cde657901 | 1001 | assert_param(IS_RTC_MINUTES(RTC_Bcd2ToByte(sAlarm->AlarmTime.Minutes))); |
mbed_official | 87:085cde657901 | 1002 | assert_param(IS_RTC_SECONDS(RTC_Bcd2ToByte(sAlarm->AlarmTime.Seconds))); |
mbed_official | 87:085cde657901 | 1003 | |
mbed_official | 87:085cde657901 | 1004 | if(sAlarm->AlarmDateWeekDaySel == RTC_ALARMDATEWEEKDAYSEL_DATE) |
mbed_official | 87:085cde657901 | 1005 | { |
mbed_official | 87:085cde657901 | 1006 | tmpreg = RTC_Bcd2ToByte(sAlarm->AlarmDateWeekDay); |
mbed_official | 87:085cde657901 | 1007 | assert_param(IS_RTC_ALARM_DATE_WEEKDAY_DATE(tmpreg)); |
mbed_official | 87:085cde657901 | 1008 | } |
mbed_official | 87:085cde657901 | 1009 | else |
mbed_official | 87:085cde657901 | 1010 | { |
mbed_official | 87:085cde657901 | 1011 | tmpreg = RTC_Bcd2ToByte(sAlarm->AlarmDateWeekDay); |
mbed_official | 87:085cde657901 | 1012 | assert_param(IS_RTC_ALARM_DATE_WEEKDAY_WEEKDAY(tmpreg)); |
mbed_official | 87:085cde657901 | 1013 | } |
mbed_official | 87:085cde657901 | 1014 | tmpreg = (((uint32_t)(sAlarm->AlarmTime.Hours) << 16) | \ |
mbed_official | 87:085cde657901 | 1015 | ((uint32_t)(sAlarm->AlarmTime.Minutes) << 8) | \ |
mbed_official | 87:085cde657901 | 1016 | ((uint32_t) sAlarm->AlarmTime.Seconds) | \ |
mbed_official | 87:085cde657901 | 1017 | ((uint32_t)(sAlarm->AlarmTime.TimeFormat) << 16) | \ |
mbed_official | 87:085cde657901 | 1018 | ((uint32_t)(sAlarm->AlarmDateWeekDay) << 24) | \ |
mbed_official | 87:085cde657901 | 1019 | ((uint32_t)sAlarm->AlarmDateWeekDaySel) | \ |
mbed_official | 87:085cde657901 | 1020 | ((uint32_t)sAlarm->AlarmMask)); |
mbed_official | 87:085cde657901 | 1021 | } |
mbed_official | 87:085cde657901 | 1022 | /* Configure the Alarm A or Alarm B Sub Second registers */ |
mbed_official | 87:085cde657901 | 1023 | subsecondtmpreg = (uint32_t)((uint32_t)(sAlarm->AlarmTime.SubSeconds) | (uint32_t)(sAlarm->AlarmSubSecondMask)); |
mbed_official | 87:085cde657901 | 1024 | |
mbed_official | 87:085cde657901 | 1025 | /* Disable the write protection for RTC registers */ |
mbed_official | 87:085cde657901 | 1026 | __HAL_RTC_WRITEPROTECTION_DISABLE(hrtc); |
mbed_official | 87:085cde657901 | 1027 | |
mbed_official | 87:085cde657901 | 1028 | /* Configure the Alarm register */ |
mbed_official | 87:085cde657901 | 1029 | if(sAlarm->Alarm == RTC_ALARM_A) |
mbed_official | 87:085cde657901 | 1030 | { |
mbed_official | 87:085cde657901 | 1031 | /* Disable the Alarm A interrupt */ |
mbed_official | 87:085cde657901 | 1032 | __HAL_RTC_ALARMA_DISABLE(hrtc); |
mbed_official | 87:085cde657901 | 1033 | |
mbed_official | 87:085cde657901 | 1034 | timeout = HAL_GetTick() + RTC_TIMEOUT_VALUE; |
mbed_official | 87:085cde657901 | 1035 | /* Wait till RTC ALRAWF flag is set and if Time out is reached exit */ |
mbed_official | 87:085cde657901 | 1036 | while(__HAL_RTC_ALARM_GET_FLAG(hrtc, RTC_FLAG_ALRAWF) == RESET) |
mbed_official | 87:085cde657901 | 1037 | { |
mbed_official | 87:085cde657901 | 1038 | if(HAL_GetTick() >= timeout) |
mbed_official | 87:085cde657901 | 1039 | { |
mbed_official | 87:085cde657901 | 1040 | /* Enable the write protection for RTC registers */ |
mbed_official | 87:085cde657901 | 1041 | __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc); |
mbed_official | 87:085cde657901 | 1042 | |
mbed_official | 87:085cde657901 | 1043 | hrtc->State = HAL_RTC_STATE_TIMEOUT; |
mbed_official | 87:085cde657901 | 1044 | |
mbed_official | 87:085cde657901 | 1045 | /* Process Unlocked */ |
mbed_official | 87:085cde657901 | 1046 | __HAL_UNLOCK(hrtc); |
mbed_official | 87:085cde657901 | 1047 | |
mbed_official | 87:085cde657901 | 1048 | return HAL_TIMEOUT; |
mbed_official | 87:085cde657901 | 1049 | } |
mbed_official | 87:085cde657901 | 1050 | } |
mbed_official | 87:085cde657901 | 1051 | |
mbed_official | 87:085cde657901 | 1052 | hrtc->Instance->ALRMAR = (uint32_t)tmpreg; |
mbed_official | 87:085cde657901 | 1053 | /* Configure the Alarm A Sub Second register */ |
mbed_official | 87:085cde657901 | 1054 | hrtc->Instance->ALRMASSR = subsecondtmpreg; |
mbed_official | 87:085cde657901 | 1055 | /* Configure the Alarm state: Enable Alarm */ |
mbed_official | 87:085cde657901 | 1056 | __HAL_RTC_ALARMA_ENABLE(hrtc); |
mbed_official | 87:085cde657901 | 1057 | /* Configure the Alarm interrupt */ |
mbed_official | 87:085cde657901 | 1058 | __HAL_RTC_ALARM_ENABLE_IT(hrtc,RTC_IT_ALRA); |
mbed_official | 87:085cde657901 | 1059 | } |
mbed_official | 87:085cde657901 | 1060 | else |
mbed_official | 87:085cde657901 | 1061 | { |
mbed_official | 87:085cde657901 | 1062 | /* Disable the Alarm B interrupt */ |
mbed_official | 87:085cde657901 | 1063 | __HAL_RTC_ALARMB_DISABLE(hrtc); |
mbed_official | 87:085cde657901 | 1064 | |
mbed_official | 87:085cde657901 | 1065 | timeout = HAL_GetTick() + RTC_TIMEOUT_VALUE; |
mbed_official | 87:085cde657901 | 1066 | /* Wait till RTC ALRBWF flag is set and if Time out is reached exit */ |
mbed_official | 87:085cde657901 | 1067 | while(__HAL_RTC_ALARM_GET_FLAG(hrtc, RTC_FLAG_ALRBWF) == RESET) |
mbed_official | 87:085cde657901 | 1068 | { |
mbed_official | 87:085cde657901 | 1069 | if(HAL_GetTick() >= timeout) |
mbed_official | 87:085cde657901 | 1070 | { |
mbed_official | 87:085cde657901 | 1071 | /* Enable the write protection for RTC registers */ |
mbed_official | 87:085cde657901 | 1072 | __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc); |
mbed_official | 87:085cde657901 | 1073 | |
mbed_official | 87:085cde657901 | 1074 | hrtc->State = HAL_RTC_STATE_TIMEOUT; |
mbed_official | 87:085cde657901 | 1075 | |
mbed_official | 87:085cde657901 | 1076 | /* Process Unlocked */ |
mbed_official | 87:085cde657901 | 1077 | __HAL_UNLOCK(hrtc); |
mbed_official | 87:085cde657901 | 1078 | |
mbed_official | 87:085cde657901 | 1079 | return HAL_TIMEOUT; |
mbed_official | 87:085cde657901 | 1080 | } |
mbed_official | 87:085cde657901 | 1081 | } |
mbed_official | 87:085cde657901 | 1082 | |
mbed_official | 87:085cde657901 | 1083 | hrtc->Instance->ALRMBR = (uint32_t)tmpreg; |
mbed_official | 87:085cde657901 | 1084 | /* Configure the Alarm B Sub Second register */ |
mbed_official | 87:085cde657901 | 1085 | hrtc->Instance->ALRMBSSR = subsecondtmpreg; |
mbed_official | 87:085cde657901 | 1086 | /* Configure the Alarm state: Enable Alarm */ |
mbed_official | 87:085cde657901 | 1087 | __HAL_RTC_ALARMB_ENABLE(hrtc); |
mbed_official | 87:085cde657901 | 1088 | /* Configure the Alarm interrupt */ |
mbed_official | 87:085cde657901 | 1089 | __HAL_RTC_ALARM_ENABLE_IT(hrtc, RTC_IT_ALRB); |
mbed_official | 87:085cde657901 | 1090 | } |
mbed_official | 87:085cde657901 | 1091 | |
mbed_official | 87:085cde657901 | 1092 | /* RTC Alarm Interrupt Configuration: EXTI configuration */ |
mbed_official | 87:085cde657901 | 1093 | __HAL_RTC_ENABLE_IT(RTC_EXTI_LINE_ALARM_EVENT); |
mbed_official | 87:085cde657901 | 1094 | |
mbed_official | 87:085cde657901 | 1095 | EXTI->RTSR |= RTC_EXTI_LINE_ALARM_EVENT; |
mbed_official | 87:085cde657901 | 1096 | |
mbed_official | 87:085cde657901 | 1097 | /* Enable the write protection for RTC registers */ |
mbed_official | 87:085cde657901 | 1098 | __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc); |
mbed_official | 87:085cde657901 | 1099 | |
mbed_official | 87:085cde657901 | 1100 | hrtc->State = HAL_RTC_STATE_READY; |
mbed_official | 87:085cde657901 | 1101 | |
mbed_official | 87:085cde657901 | 1102 | /* Process Unlocked */ |
mbed_official | 87:085cde657901 | 1103 | __HAL_UNLOCK(hrtc); |
mbed_official | 87:085cde657901 | 1104 | |
mbed_official | 87:085cde657901 | 1105 | return HAL_OK; |
mbed_official | 87:085cde657901 | 1106 | } |
mbed_official | 87:085cde657901 | 1107 | |
mbed_official | 87:085cde657901 | 1108 | /** |
mbed_official | 87:085cde657901 | 1109 | * @brief Deactive the specified RTC Alarm |
mbed_official | 87:085cde657901 | 1110 | * @param hrtc: RTC handle |
mbed_official | 87:085cde657901 | 1111 | * @param Alarm: Specifies the Alarm. |
mbed_official | 87:085cde657901 | 1112 | * This parameter can be one of the following values: |
mbed_official | 87:085cde657901 | 1113 | * @arg ALARM_A : AlarmA |
mbed_official | 87:085cde657901 | 1114 | * @arg ALARM_B : AlarmB |
mbed_official | 87:085cde657901 | 1115 | * @retval HAL status |
mbed_official | 87:085cde657901 | 1116 | */ |
mbed_official | 87:085cde657901 | 1117 | HAL_StatusTypeDef HAL_RTC_DeactivateAlarm(RTC_HandleTypeDef *hrtc, uint32_t Alarm) |
mbed_official | 87:085cde657901 | 1118 | { |
mbed_official | 87:085cde657901 | 1119 | uint32_t timeout = 0; |
mbed_official | 87:085cde657901 | 1120 | |
mbed_official | 87:085cde657901 | 1121 | /* Check the parameters */ |
mbed_official | 87:085cde657901 | 1122 | assert_param(IS_ALARM(Alarm)); |
mbed_official | 87:085cde657901 | 1123 | |
mbed_official | 87:085cde657901 | 1124 | /* Process Locked */ |
mbed_official | 87:085cde657901 | 1125 | __HAL_LOCK(hrtc); |
mbed_official | 87:085cde657901 | 1126 | |
mbed_official | 87:085cde657901 | 1127 | hrtc->State = HAL_RTC_STATE_BUSY; |
mbed_official | 87:085cde657901 | 1128 | |
mbed_official | 87:085cde657901 | 1129 | /* Disable the write protection for RTC registers */ |
mbed_official | 87:085cde657901 | 1130 | __HAL_RTC_WRITEPROTECTION_DISABLE(hrtc); |
mbed_official | 87:085cde657901 | 1131 | |
mbed_official | 87:085cde657901 | 1132 | if(Alarm == RTC_ALARM_A) |
mbed_official | 87:085cde657901 | 1133 | { |
mbed_official | 87:085cde657901 | 1134 | /* AlarmA */ |
mbed_official | 87:085cde657901 | 1135 | __HAL_RTC_ALARMA_DISABLE(hrtc); |
mbed_official | 87:085cde657901 | 1136 | |
mbed_official | 87:085cde657901 | 1137 | /* In case of interrupt mode is used, the interrupt source must disabled */ |
mbed_official | 87:085cde657901 | 1138 | __HAL_RTC_ALARM_DISABLE_IT(hrtc, RTC_IT_ALRA); |
mbed_official | 87:085cde657901 | 1139 | |
mbed_official | 87:085cde657901 | 1140 | timeout = HAL_GetTick() + RTC_TIMEOUT_VALUE; |
mbed_official | 87:085cde657901 | 1141 | |
mbed_official | 87:085cde657901 | 1142 | /* Wait till RTC ALRxWF flag is set and if Time out is reached exit */ |
mbed_official | 87:085cde657901 | 1143 | while(__HAL_RTC_ALARM_GET_FLAG(hrtc, RTC_FLAG_ALRAWF) == RESET) |
mbed_official | 87:085cde657901 | 1144 | { |
mbed_official | 87:085cde657901 | 1145 | if(HAL_GetTick() >= timeout) |
mbed_official | 87:085cde657901 | 1146 | { |
mbed_official | 87:085cde657901 | 1147 | /* Enable the write protection for RTC registers */ |
mbed_official | 87:085cde657901 | 1148 | __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc); |
mbed_official | 87:085cde657901 | 1149 | |
mbed_official | 87:085cde657901 | 1150 | hrtc->State = HAL_RTC_STATE_TIMEOUT; |
mbed_official | 87:085cde657901 | 1151 | |
mbed_official | 87:085cde657901 | 1152 | /* Process Unlocked */ |
mbed_official | 87:085cde657901 | 1153 | __HAL_UNLOCK(hrtc); |
mbed_official | 87:085cde657901 | 1154 | |
mbed_official | 87:085cde657901 | 1155 | return HAL_TIMEOUT; |
mbed_official | 87:085cde657901 | 1156 | } |
mbed_official | 87:085cde657901 | 1157 | } |
mbed_official | 87:085cde657901 | 1158 | } |
mbed_official | 87:085cde657901 | 1159 | else |
mbed_official | 87:085cde657901 | 1160 | { |
mbed_official | 87:085cde657901 | 1161 | /* AlarmB */ |
mbed_official | 87:085cde657901 | 1162 | __HAL_RTC_ALARMB_DISABLE(hrtc); |
mbed_official | 87:085cde657901 | 1163 | |
mbed_official | 87:085cde657901 | 1164 | /* In case of interrupt mode is used, the interrupt source must disabled */ |
mbed_official | 87:085cde657901 | 1165 | __HAL_RTC_ALARM_DISABLE_IT(hrtc,RTC_IT_ALRB); |
mbed_official | 87:085cde657901 | 1166 | |
mbed_official | 87:085cde657901 | 1167 | timeout = HAL_GetTick() + RTC_TIMEOUT_VALUE; |
mbed_official | 87:085cde657901 | 1168 | |
mbed_official | 87:085cde657901 | 1169 | /* Wait till RTC ALRxWF flag is set and if Time out is reached exit */ |
mbed_official | 87:085cde657901 | 1170 | while(__HAL_RTC_ALARM_GET_FLAG(hrtc, RTC_FLAG_ALRBWF) == RESET) |
mbed_official | 87:085cde657901 | 1171 | { |
mbed_official | 87:085cde657901 | 1172 | if(HAL_GetTick() >= timeout) |
mbed_official | 87:085cde657901 | 1173 | { |
mbed_official | 87:085cde657901 | 1174 | /* Enable the write protection for RTC registers */ |
mbed_official | 87:085cde657901 | 1175 | __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc); |
mbed_official | 87:085cde657901 | 1176 | |
mbed_official | 87:085cde657901 | 1177 | hrtc->State = HAL_RTC_STATE_TIMEOUT; |
mbed_official | 87:085cde657901 | 1178 | |
mbed_official | 87:085cde657901 | 1179 | /* Process Unlocked */ |
mbed_official | 87:085cde657901 | 1180 | __HAL_UNLOCK(hrtc); |
mbed_official | 87:085cde657901 | 1181 | |
mbed_official | 87:085cde657901 | 1182 | return HAL_TIMEOUT; |
mbed_official | 87:085cde657901 | 1183 | } |
mbed_official | 87:085cde657901 | 1184 | } |
mbed_official | 87:085cde657901 | 1185 | } |
mbed_official | 87:085cde657901 | 1186 | /* Enable the write protection for RTC registers */ |
mbed_official | 87:085cde657901 | 1187 | __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc); |
mbed_official | 87:085cde657901 | 1188 | |
mbed_official | 87:085cde657901 | 1189 | hrtc->State = HAL_RTC_STATE_READY; |
mbed_official | 87:085cde657901 | 1190 | |
mbed_official | 87:085cde657901 | 1191 | /* Process Unlocked */ |
mbed_official | 87:085cde657901 | 1192 | __HAL_UNLOCK(hrtc); |
mbed_official | 87:085cde657901 | 1193 | |
mbed_official | 87:085cde657901 | 1194 | return HAL_OK; |
mbed_official | 87:085cde657901 | 1195 | } |
mbed_official | 87:085cde657901 | 1196 | |
mbed_official | 87:085cde657901 | 1197 | /** |
mbed_official | 87:085cde657901 | 1198 | * @brief Gets the RTC Alarm value and masks. |
mbed_official | 87:085cde657901 | 1199 | * @param hrtc: RTC handle |
mbed_official | 87:085cde657901 | 1200 | * @param sAlarm: Pointer to Date structure |
mbed_official | 87:085cde657901 | 1201 | * @param Alarm: Specifies the Alarm |
mbed_official | 87:085cde657901 | 1202 | * This parameter can be one of the following values: |
mbed_official | 87:085cde657901 | 1203 | * @arg ALARM_A: AlarmA |
mbed_official | 87:085cde657901 | 1204 | * @arg ALARM_B: AlarmB |
mbed_official | 87:085cde657901 | 1205 | * @param Format: Specifies the format of the entered parameters. |
mbed_official | 87:085cde657901 | 1206 | * This parameter can be one of the following values: |
mbed_official | 87:085cde657901 | 1207 | * @arg Format_BIN: Binary data format |
mbed_official | 87:085cde657901 | 1208 | * @arg Format_BCD: BCD data format |
mbed_official | 87:085cde657901 | 1209 | * @retval HAL status |
mbed_official | 87:085cde657901 | 1210 | */ |
mbed_official | 87:085cde657901 | 1211 | HAL_StatusTypeDef HAL_RTC_GetAlarm(RTC_HandleTypeDef *hrtc, RTC_AlarmTypeDef *sAlarm, uint32_t Alarm, uint32_t Format) |
mbed_official | 87:085cde657901 | 1212 | { |
mbed_official | 87:085cde657901 | 1213 | uint32_t tmpreg = 0, subsecondtmpreg = 0; |
mbed_official | 87:085cde657901 | 1214 | |
mbed_official | 87:085cde657901 | 1215 | /* Check the parameters */ |
mbed_official | 87:085cde657901 | 1216 | assert_param(IS_RTC_FORMAT(Format)); |
mbed_official | 87:085cde657901 | 1217 | assert_param(IS_ALARM(Alarm)); |
mbed_official | 87:085cde657901 | 1218 | |
mbed_official | 87:085cde657901 | 1219 | if(Alarm == RTC_ALARM_A) |
mbed_official | 87:085cde657901 | 1220 | { |
mbed_official | 87:085cde657901 | 1221 | /* AlarmA */ |
mbed_official | 87:085cde657901 | 1222 | sAlarm->Alarm = RTC_ALARM_A; |
mbed_official | 87:085cde657901 | 1223 | |
mbed_official | 87:085cde657901 | 1224 | tmpreg = (uint32_t)(hrtc->Instance->ALRMAR); |
mbed_official | 87:085cde657901 | 1225 | subsecondtmpreg = (uint32_t)((hrtc->Instance->ALRMASSR ) & RTC_ALRMASSR_SS); |
mbed_official | 87:085cde657901 | 1226 | } |
mbed_official | 87:085cde657901 | 1227 | else |
mbed_official | 87:085cde657901 | 1228 | { |
mbed_official | 87:085cde657901 | 1229 | sAlarm->Alarm = RTC_ALARM_B; |
mbed_official | 87:085cde657901 | 1230 | |
mbed_official | 87:085cde657901 | 1231 | tmpreg = (uint32_t)(hrtc->Instance->ALRMBR); |
mbed_official | 87:085cde657901 | 1232 | subsecondtmpreg = (uint32_t)((hrtc->Instance->ALRMBSSR) & RTC_ALRMBSSR_SS); |
mbed_official | 87:085cde657901 | 1233 | } |
mbed_official | 87:085cde657901 | 1234 | |
mbed_official | 87:085cde657901 | 1235 | /* Fill the structure with the read parameters */ |
mbed_official | 87:085cde657901 | 1236 | sAlarm->AlarmTime.Hours = (uint32_t)((tmpreg & (RTC_ALRMAR_HT | RTC_ALRMAR_HU)) >> 16); |
mbed_official | 87:085cde657901 | 1237 | sAlarm->AlarmTime.Minutes = (uint32_t)((tmpreg & (RTC_ALRMAR_MNT | RTC_ALRMAR_MNU)) >> 8); |
mbed_official | 87:085cde657901 | 1238 | sAlarm->AlarmTime.Seconds = (uint32_t)(tmpreg & (RTC_ALRMAR_ST | RTC_ALRMAR_SU)); |
mbed_official | 87:085cde657901 | 1239 | sAlarm->AlarmTime.TimeFormat = (uint32_t)((tmpreg & RTC_ALRMAR_PM) >> 16); |
mbed_official | 87:085cde657901 | 1240 | sAlarm->AlarmTime.SubSeconds = (uint32_t) subsecondtmpreg; |
mbed_official | 87:085cde657901 | 1241 | sAlarm->AlarmDateWeekDay = (uint32_t)((tmpreg & (RTC_ALRMAR_DT | RTC_ALRMAR_DU)) >> 24); |
mbed_official | 87:085cde657901 | 1242 | sAlarm->AlarmDateWeekDaySel = (uint32_t)(tmpreg & RTC_ALRMAR_WDSEL); |
mbed_official | 87:085cde657901 | 1243 | sAlarm->AlarmMask = (uint32_t)(tmpreg & RTC_ALARMMASK_ALL); |
mbed_official | 87:085cde657901 | 1244 | |
mbed_official | 87:085cde657901 | 1245 | if(Format == FORMAT_BIN) |
mbed_official | 87:085cde657901 | 1246 | { |
mbed_official | 87:085cde657901 | 1247 | sAlarm->AlarmTime.Hours = RTC_Bcd2ToByte(sAlarm->AlarmTime.Hours); |
mbed_official | 87:085cde657901 | 1248 | sAlarm->AlarmTime.Minutes = RTC_Bcd2ToByte(sAlarm->AlarmTime.Minutes); |
mbed_official | 87:085cde657901 | 1249 | sAlarm->AlarmTime.Seconds = RTC_Bcd2ToByte(sAlarm->AlarmTime.Seconds); |
mbed_official | 87:085cde657901 | 1250 | sAlarm->AlarmDateWeekDay = RTC_Bcd2ToByte(sAlarm->AlarmDateWeekDay); |
mbed_official | 87:085cde657901 | 1251 | } |
mbed_official | 87:085cde657901 | 1252 | |
mbed_official | 87:085cde657901 | 1253 | return HAL_OK; |
mbed_official | 87:085cde657901 | 1254 | } |
mbed_official | 87:085cde657901 | 1255 | |
mbed_official | 87:085cde657901 | 1256 | /** |
mbed_official | 87:085cde657901 | 1257 | * @brief This function handles Alarm interrupt request. |
mbed_official | 87:085cde657901 | 1258 | * @param hrtc: RTC handle |
mbed_official | 87:085cde657901 | 1259 | * @retval None |
mbed_official | 87:085cde657901 | 1260 | */ |
mbed_official | 87:085cde657901 | 1261 | void HAL_RTC_AlarmIRQHandler(RTC_HandleTypeDef* hrtc) |
mbed_official | 87:085cde657901 | 1262 | { |
mbed_official | 87:085cde657901 | 1263 | if(__HAL_RTC_ALARM_GET_IT(hrtc, RTC_IT_ALRA)) |
mbed_official | 87:085cde657901 | 1264 | { |
mbed_official | 87:085cde657901 | 1265 | /* Get the status of the Interrupt */ |
mbed_official | 87:085cde657901 | 1266 | if((uint32_t)(hrtc->Instance->CR & RTC_IT_ALRA) != (uint32_t)RESET) |
mbed_official | 87:085cde657901 | 1267 | { |
mbed_official | 87:085cde657901 | 1268 | /* AlarmA callback */ |
mbed_official | 87:085cde657901 | 1269 | HAL_RTC_AlarmAEventCallback(hrtc); |
mbed_official | 87:085cde657901 | 1270 | |
mbed_official | 87:085cde657901 | 1271 | /* Clear the Alarm interrupt pending bit */ |
mbed_official | 87:085cde657901 | 1272 | __HAL_RTC_ALARM_CLEAR_FLAG(hrtc,RTC_FLAG_ALRAF); |
mbed_official | 87:085cde657901 | 1273 | } |
mbed_official | 87:085cde657901 | 1274 | } |
mbed_official | 87:085cde657901 | 1275 | |
mbed_official | 87:085cde657901 | 1276 | if(__HAL_RTC_ALARM_GET_IT(hrtc, RTC_IT_ALRB)) |
mbed_official | 87:085cde657901 | 1277 | { |
mbed_official | 87:085cde657901 | 1278 | /* Get the status of the Interrupt */ |
mbed_official | 87:085cde657901 | 1279 | if((uint32_t)(hrtc->Instance->CR & RTC_IT_ALRB) != (uint32_t)RESET) |
mbed_official | 87:085cde657901 | 1280 | { |
mbed_official | 87:085cde657901 | 1281 | /* AlarmB callback */ |
mbed_official | 87:085cde657901 | 1282 | HAL_RTCEx_AlarmBEventCallback(hrtc); |
mbed_official | 87:085cde657901 | 1283 | |
mbed_official | 87:085cde657901 | 1284 | /* Clear the Alarm interrupt pending bit */ |
mbed_official | 87:085cde657901 | 1285 | __HAL_RTC_ALARM_CLEAR_FLAG(hrtc,RTC_FLAG_ALRBF); |
mbed_official | 87:085cde657901 | 1286 | } |
mbed_official | 87:085cde657901 | 1287 | } |
mbed_official | 87:085cde657901 | 1288 | |
mbed_official | 87:085cde657901 | 1289 | /* Clear the EXTI's line Flag for RTC Alarm */ |
mbed_official | 87:085cde657901 | 1290 | __HAL_RTC_CLEAR_FLAG(RTC_EXTI_LINE_ALARM_EVENT); |
mbed_official | 87:085cde657901 | 1291 | |
mbed_official | 87:085cde657901 | 1292 | /* Change RTC state */ |
mbed_official | 87:085cde657901 | 1293 | hrtc->State = HAL_RTC_STATE_READY; |
mbed_official | 87:085cde657901 | 1294 | } |
mbed_official | 87:085cde657901 | 1295 | |
mbed_official | 87:085cde657901 | 1296 | /** |
mbed_official | 87:085cde657901 | 1297 | * @brief Alarm A callback. |
mbed_official | 87:085cde657901 | 1298 | * @param hrtc: RTC handle |
mbed_official | 87:085cde657901 | 1299 | * @retval None |
mbed_official | 87:085cde657901 | 1300 | */ |
mbed_official | 87:085cde657901 | 1301 | __weak void HAL_RTC_AlarmAEventCallback(RTC_HandleTypeDef *hrtc) |
mbed_official | 87:085cde657901 | 1302 | { |
mbed_official | 87:085cde657901 | 1303 | /* NOTE : This function Should not be modified, when the callback is needed, |
mbed_official | 87:085cde657901 | 1304 | the HAL_RTC_AlarmAEventCallback could be implemented in the user file |
mbed_official | 87:085cde657901 | 1305 | */ |
mbed_official | 87:085cde657901 | 1306 | } |
mbed_official | 87:085cde657901 | 1307 | |
mbed_official | 87:085cde657901 | 1308 | /** |
mbed_official | 87:085cde657901 | 1309 | * @brief This function handles AlarmA Polling request. |
mbed_official | 87:085cde657901 | 1310 | * @param hrtc: RTC handle |
mbed_official | 87:085cde657901 | 1311 | * @param Timeout: Timeout duration |
mbed_official | 87:085cde657901 | 1312 | * @retval HAL status |
mbed_official | 87:085cde657901 | 1313 | */ |
mbed_official | 87:085cde657901 | 1314 | HAL_StatusTypeDef HAL_RTC_PollForAlarmAEvent(RTC_HandleTypeDef *hrtc, uint32_t Timeout) |
mbed_official | 87:085cde657901 | 1315 | { |
mbed_official | 87:085cde657901 | 1316 | |
mbed_official | 87:085cde657901 | 1317 | uint32_t timeout = 0; |
mbed_official | 87:085cde657901 | 1318 | |
mbed_official | 87:085cde657901 | 1319 | /* Get Timeout value */ |
mbed_official | 87:085cde657901 | 1320 | timeout = HAL_GetTick() + Timeout; |
mbed_official | 87:085cde657901 | 1321 | |
mbed_official | 87:085cde657901 | 1322 | while(__HAL_RTC_ALARM_GET_FLAG(hrtc, RTC_FLAG_ALRAF) == RESET) |
mbed_official | 87:085cde657901 | 1323 | { |
mbed_official | 87:085cde657901 | 1324 | if(Timeout != HAL_MAX_DELAY) |
mbed_official | 87:085cde657901 | 1325 | { |
mbed_official | 87:085cde657901 | 1326 | if(HAL_GetTick() >= timeout) |
mbed_official | 87:085cde657901 | 1327 | { |
mbed_official | 87:085cde657901 | 1328 | hrtc->State = HAL_RTC_STATE_TIMEOUT; |
mbed_official | 87:085cde657901 | 1329 | return HAL_TIMEOUT; |
mbed_official | 87:085cde657901 | 1330 | } |
mbed_official | 87:085cde657901 | 1331 | } |
mbed_official | 87:085cde657901 | 1332 | } |
mbed_official | 87:085cde657901 | 1333 | |
mbed_official | 87:085cde657901 | 1334 | /* Clear the Alarm interrupt pending bit */ |
mbed_official | 87:085cde657901 | 1335 | __HAL_RTC_ALARM_CLEAR_FLAG(hrtc, RTC_FLAG_ALRAF); |
mbed_official | 87:085cde657901 | 1336 | |
mbed_official | 87:085cde657901 | 1337 | /* Change RTC state */ |
mbed_official | 87:085cde657901 | 1338 | hrtc->State = HAL_RTC_STATE_READY; |
mbed_official | 87:085cde657901 | 1339 | |
mbed_official | 87:085cde657901 | 1340 | return HAL_OK; |
mbed_official | 87:085cde657901 | 1341 | } |
mbed_official | 87:085cde657901 | 1342 | |
mbed_official | 87:085cde657901 | 1343 | /** |
mbed_official | 87:085cde657901 | 1344 | * @} |
mbed_official | 87:085cde657901 | 1345 | */ |
mbed_official | 87:085cde657901 | 1346 | |
mbed_official | 87:085cde657901 | 1347 | /** @defgroup RTC_Group4 Peripheral Control functions |
mbed_official | 87:085cde657901 | 1348 | * @brief Peripheral Control functions |
mbed_official | 87:085cde657901 | 1349 | * |
mbed_official | 87:085cde657901 | 1350 | @verbatim |
mbed_official | 87:085cde657901 | 1351 | =============================================================================== |
mbed_official | 87:085cde657901 | 1352 | ##### Peripheral Control functions ##### |
mbed_official | 87:085cde657901 | 1353 | =============================================================================== |
mbed_official | 87:085cde657901 | 1354 | [..] |
mbed_official | 87:085cde657901 | 1355 | This subsection provides functions allowing to |
mbed_official | 87:085cde657901 | 1356 | (+) Wait for RTC Time and Date Synchronization |
mbed_official | 87:085cde657901 | 1357 | |
mbed_official | 87:085cde657901 | 1358 | @endverbatim |
mbed_official | 87:085cde657901 | 1359 | * @{ |
mbed_official | 87:085cde657901 | 1360 | */ |
mbed_official | 87:085cde657901 | 1361 | |
mbed_official | 87:085cde657901 | 1362 | /** |
mbed_official | 87:085cde657901 | 1363 | * @brief Waits until the RTC Time and Date registers (RTC_TR and RTC_DR) are |
mbed_official | 87:085cde657901 | 1364 | * synchronized with RTC APB clock. |
mbed_official | 87:085cde657901 | 1365 | * @note The RTC Resynchronization mode is write protected, use the |
mbed_official | 87:085cde657901 | 1366 | * __HAL_RTC_WRITEPROTECTION_DISABLE() before calling this function. |
mbed_official | 87:085cde657901 | 1367 | * @note To read the calendar through the shadow registers after Calendar |
mbed_official | 87:085cde657901 | 1368 | * initialization, calendar update or after wakeup from low power modes |
mbed_official | 87:085cde657901 | 1369 | * the software must first clear the RSF flag. |
mbed_official | 87:085cde657901 | 1370 | * The software must then wait until it is set again before reading |
mbed_official | 87:085cde657901 | 1371 | * the calendar, which means that the calendar registers have been |
mbed_official | 87:085cde657901 | 1372 | * correctly copied into the RTC_TR and RTC_DR shadow registers. |
mbed_official | 87:085cde657901 | 1373 | * @param hrtc: RTC handle |
mbed_official | 87:085cde657901 | 1374 | * @retval HAL status |
mbed_official | 87:085cde657901 | 1375 | */ |
mbed_official | 87:085cde657901 | 1376 | HAL_StatusTypeDef HAL_RTC_WaitForSynchro(RTC_HandleTypeDef* hrtc) |
mbed_official | 87:085cde657901 | 1377 | { |
mbed_official | 87:085cde657901 | 1378 | uint32_t timeout = 0; |
mbed_official | 87:085cde657901 | 1379 | |
mbed_official | 87:085cde657901 | 1380 | /* Clear RSF flag */ |
mbed_official | 87:085cde657901 | 1381 | hrtc->Instance->ISR &= (uint32_t)RTC_RSF_MASK; |
mbed_official | 87:085cde657901 | 1382 | |
mbed_official | 87:085cde657901 | 1383 | timeout = HAL_GetTick() + RTC_TIMEOUT_VALUE; |
mbed_official | 87:085cde657901 | 1384 | |
mbed_official | 87:085cde657901 | 1385 | /* Wait the registers to be synchronised */ |
mbed_official | 87:085cde657901 | 1386 | while((hrtc->Instance->ISR & RTC_ISR_RSF) == (uint32_t)RESET) |
mbed_official | 87:085cde657901 | 1387 | { |
mbed_official | 87:085cde657901 | 1388 | if(HAL_GetTick() >= timeout) |
mbed_official | 87:085cde657901 | 1389 | { |
mbed_official | 87:085cde657901 | 1390 | return HAL_TIMEOUT; |
mbed_official | 87:085cde657901 | 1391 | } |
mbed_official | 87:085cde657901 | 1392 | } |
mbed_official | 87:085cde657901 | 1393 | |
mbed_official | 87:085cde657901 | 1394 | return HAL_OK; |
mbed_official | 87:085cde657901 | 1395 | } |
mbed_official | 87:085cde657901 | 1396 | |
mbed_official | 87:085cde657901 | 1397 | /** @defgroup RTC_Group5 Peripheral State functions |
mbed_official | 87:085cde657901 | 1398 | * @brief Peripheral State functions |
mbed_official | 87:085cde657901 | 1399 | * |
mbed_official | 87:085cde657901 | 1400 | @verbatim |
mbed_official | 87:085cde657901 | 1401 | =============================================================================== |
mbed_official | 87:085cde657901 | 1402 | ##### Peripheral State functions ##### |
mbed_official | 87:085cde657901 | 1403 | =============================================================================== |
mbed_official | 87:085cde657901 | 1404 | [..] |
mbed_official | 87:085cde657901 | 1405 | This subsection provides functions allowing to |
mbed_official | 87:085cde657901 | 1406 | (+) Get RTC state |
mbed_official | 87:085cde657901 | 1407 | |
mbed_official | 87:085cde657901 | 1408 | @endverbatim |
mbed_official | 87:085cde657901 | 1409 | * @{ |
mbed_official | 87:085cde657901 | 1410 | */ |
mbed_official | 87:085cde657901 | 1411 | /** |
mbed_official | 87:085cde657901 | 1412 | * @brief Returns the Alarm state. |
mbed_official | 87:085cde657901 | 1413 | * @param hrtc: RTC handle |
mbed_official | 87:085cde657901 | 1414 | * @retval HAL state |
mbed_official | 87:085cde657901 | 1415 | */ |
mbed_official | 87:085cde657901 | 1416 | HAL_RTCStateTypeDef HAL_RTC_GetState(RTC_HandleTypeDef* hrtc) |
mbed_official | 87:085cde657901 | 1417 | { |
mbed_official | 87:085cde657901 | 1418 | return hrtc->State; |
mbed_official | 87:085cde657901 | 1419 | } |
mbed_official | 87:085cde657901 | 1420 | |
mbed_official | 87:085cde657901 | 1421 | /** |
mbed_official | 87:085cde657901 | 1422 | * @} |
mbed_official | 87:085cde657901 | 1423 | */ |
mbed_official | 87:085cde657901 | 1424 | |
mbed_official | 87:085cde657901 | 1425 | /** |
mbed_official | 87:085cde657901 | 1426 | * @brief Enters the RTC Initialization mode. |
mbed_official | 87:085cde657901 | 1427 | * @note The RTC Initialization mode is write protected, use the |
mbed_official | 87:085cde657901 | 1428 | * __HAL_RTC_WRITEPROTECTION_DISABLE() before calling this function. |
mbed_official | 87:085cde657901 | 1429 | * @param hrtc: RTC handle |
mbed_official | 87:085cde657901 | 1430 | * @retval HAL status |
mbed_official | 87:085cde657901 | 1431 | */ |
mbed_official | 87:085cde657901 | 1432 | HAL_StatusTypeDef RTC_EnterInitMode(RTC_HandleTypeDef* hrtc) |
mbed_official | 87:085cde657901 | 1433 | { |
mbed_official | 87:085cde657901 | 1434 | uint32_t timeout = 0; |
mbed_official | 87:085cde657901 | 1435 | |
mbed_official | 87:085cde657901 | 1436 | /* Check if the Initialization mode is set */ |
mbed_official | 87:085cde657901 | 1437 | if((hrtc->Instance->ISR & RTC_ISR_INITF) == (uint32_t)RESET) |
mbed_official | 87:085cde657901 | 1438 | { |
mbed_official | 87:085cde657901 | 1439 | /* Set the Initialization mode */ |
mbed_official | 87:085cde657901 | 1440 | hrtc->Instance->ISR = (uint32_t)RTC_INIT_MASK; |
mbed_official | 87:085cde657901 | 1441 | |
mbed_official | 87:085cde657901 | 1442 | timeout = HAL_GetTick() + RTC_TIMEOUT_VALUE; |
mbed_official | 87:085cde657901 | 1443 | /* Wait till RTC is in INIT state and if Time out is reached exit */ |
mbed_official | 87:085cde657901 | 1444 | while((hrtc->Instance->ISR & RTC_ISR_INITF) == (uint32_t)RESET) |
mbed_official | 87:085cde657901 | 1445 | { |
mbed_official | 87:085cde657901 | 1446 | if(HAL_GetTick() >= timeout) |
mbed_official | 87:085cde657901 | 1447 | { |
mbed_official | 87:085cde657901 | 1448 | return HAL_TIMEOUT; |
mbed_official | 87:085cde657901 | 1449 | } |
mbed_official | 87:085cde657901 | 1450 | } |
mbed_official | 87:085cde657901 | 1451 | } |
mbed_official | 87:085cde657901 | 1452 | |
mbed_official | 87:085cde657901 | 1453 | return HAL_OK; |
mbed_official | 87:085cde657901 | 1454 | } |
mbed_official | 87:085cde657901 | 1455 | |
mbed_official | 87:085cde657901 | 1456 | |
mbed_official | 87:085cde657901 | 1457 | /** |
mbed_official | 87:085cde657901 | 1458 | * @brief Converts a 2 digit decimal to BCD format. |
mbed_official | 87:085cde657901 | 1459 | * @param Value: Byte to be converted |
mbed_official | 87:085cde657901 | 1460 | * @retval Converted byte |
mbed_official | 87:085cde657901 | 1461 | */ |
mbed_official | 87:085cde657901 | 1462 | uint8_t RTC_ByteToBcd2(uint8_t Value) |
mbed_official | 87:085cde657901 | 1463 | { |
mbed_official | 87:085cde657901 | 1464 | uint32_t bcdhigh = 0; |
mbed_official | 87:085cde657901 | 1465 | |
mbed_official | 87:085cde657901 | 1466 | while(Value >= 10) |
mbed_official | 87:085cde657901 | 1467 | { |
mbed_official | 87:085cde657901 | 1468 | bcdhigh++; |
mbed_official | 87:085cde657901 | 1469 | Value -= 10; |
mbed_official | 87:085cde657901 | 1470 | } |
mbed_official | 87:085cde657901 | 1471 | |
mbed_official | 87:085cde657901 | 1472 | return ((uint8_t)(bcdhigh << 4) | Value); |
mbed_official | 87:085cde657901 | 1473 | } |
mbed_official | 87:085cde657901 | 1474 | |
mbed_official | 87:085cde657901 | 1475 | /** |
mbed_official | 87:085cde657901 | 1476 | * @brief Converts from 2 digit BCD to Binary. |
mbed_official | 87:085cde657901 | 1477 | * @param Value: BCD value to be converted |
mbed_official | 87:085cde657901 | 1478 | * @retval Converted word |
mbed_official | 87:085cde657901 | 1479 | */ |
mbed_official | 87:085cde657901 | 1480 | uint8_t RTC_Bcd2ToByte(uint8_t Value) |
mbed_official | 87:085cde657901 | 1481 | { |
mbed_official | 87:085cde657901 | 1482 | uint32_t tmp = 0; |
mbed_official | 87:085cde657901 | 1483 | tmp = ((uint8_t)(Value & (uint8_t)0xF0) >> (uint8_t)0x4) * 10; |
mbed_official | 87:085cde657901 | 1484 | return (tmp + (Value & (uint8_t)0x0F)); |
mbed_official | 87:085cde657901 | 1485 | } |
mbed_official | 87:085cde657901 | 1486 | |
mbed_official | 87:085cde657901 | 1487 | /** |
mbed_official | 87:085cde657901 | 1488 | * @} |
mbed_official | 87:085cde657901 | 1489 | */ |
mbed_official | 87:085cde657901 | 1490 | |
mbed_official | 87:085cde657901 | 1491 | #endif /* HAL_RTC_MODULE_ENABLED */ |
mbed_official | 87:085cde657901 | 1492 | /** |
mbed_official | 87:085cde657901 | 1493 | * @} |
mbed_official | 87:085cde657901 | 1494 | */ |
mbed_official | 87:085cde657901 | 1495 | |
mbed_official | 87:085cde657901 | 1496 | /** |
mbed_official | 87:085cde657901 | 1497 | * @} |
mbed_official | 87:085cde657901 | 1498 | */ |
mbed_official | 87:085cde657901 | 1499 | |
mbed_official | 87:085cde657901 | 1500 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ |