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