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