Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
targets/cmsis/TARGET_STM/TARGET_STM32L1/stm32l1xx_hal_rtc.c@10:6444e6c798ce, 2015-08-14 (annotated)
- Committer:
- modtronix
- Date:
- Fri Aug 14 18:48:46 2015 +1000
- Revision:
- 10:6444e6c798ce
- Parent:
- 1:71204b8406f2
Updated to STM32CubeL1 V1.0.3
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| modtronix | 1:71204b8406f2 | 1 | /** |
| modtronix | 1:71204b8406f2 | 2 | ****************************************************************************** |
| modtronix | 1:71204b8406f2 | 3 | * @file stm32l1xx_hal_rtc.c |
| modtronix | 1:71204b8406f2 | 4 | * @author MCD Application Team |
| modtronix | 10:6444e6c798ce | 5 | * @version V1.1.1 |
| modtronix | 10:6444e6c798ce | 6 | * @date 31-March-2015 |
| modtronix | 1:71204b8406f2 | 7 | * @brief RTC HAL module driver. |
| modtronix | 1:71204b8406f2 | 8 | * This file provides firmware functions to manage the following |
| modtronix | 1:71204b8406f2 | 9 | * functionalities of the Real Time Clock (RTC) peripheral: |
| modtronix | 1:71204b8406f2 | 10 | * + Initialization and de-initialization functions |
| modtronix | 1:71204b8406f2 | 11 | * + RTC Time and Date functions |
| modtronix | 1:71204b8406f2 | 12 | * + RTC Alarm functions |
| modtronix | 1:71204b8406f2 | 13 | * + Peripheral Control functions |
| modtronix | 1:71204b8406f2 | 14 | * + Peripheral State functions |
| modtronix | 1:71204b8406f2 | 15 | * |
| modtronix | 1:71204b8406f2 | 16 | @verbatim |
| modtronix | 1:71204b8406f2 | 17 | ============================================================================== |
| modtronix | 1:71204b8406f2 | 18 | ##### Backup Domain Operating Condition ##### |
| modtronix | 1:71204b8406f2 | 19 | ============================================================================== |
| modtronix | 1:71204b8406f2 | 20 | [..] The real-time clock (RTC) and the RTC backup registers can be powered |
| modtronix | 1:71204b8406f2 | 21 | from the VBAT voltage when the main VDD supply is powered off. |
| modtronix | 1:71204b8406f2 | 22 | To retain the content of the RTC backup registers and supply the RTC |
| modtronix | 1:71204b8406f2 | 23 | when VDD is turned off, VBAT pin can be connected to an optional |
| modtronix | 1:71204b8406f2 | 24 | standby voltage supplied by a battery or by another source. |
| modtronix | 1:71204b8406f2 | 25 | |
| modtronix | 1:71204b8406f2 | 26 | [..] To allow the RTC operating even when the main digital supply (VDD) is turned |
| modtronix | 1:71204b8406f2 | 27 | off, the VBAT pin powers the following blocks: |
| modtronix | 1:71204b8406f2 | 28 | (#) The RTC |
| modtronix | 1:71204b8406f2 | 29 | (#) The LSE oscillator |
| modtronix | 1:71204b8406f2 | 30 | (#) PC13 to PC15 I/Os (when available) |
| modtronix | 1:71204b8406f2 | 31 | |
| modtronix | 1:71204b8406f2 | 32 | [..] When the backup domain is supplied by VDD (analog switch connected to VDD), |
| modtronix | 1:71204b8406f2 | 33 | the following pins are available: |
| modtronix | 1:71204b8406f2 | 34 | (#) PC14 and PC15 can be used as either GPIO or LSE pins |
| modtronix | 1:71204b8406f2 | 35 | (#) PC13 can be used as a GPIO or as the RTC_AF1 pin |
| modtronix | 1:71204b8406f2 | 36 | |
| modtronix | 1:71204b8406f2 | 37 | [..] When the backup domain is supplied by VBAT (analog switch connected to VBAT |
| modtronix | 1:71204b8406f2 | 38 | because VDD is not present), the following pins are available: |
| modtronix | 1:71204b8406f2 | 39 | (#) PC14 and PC15 can be used as LSE pins only |
| modtronix | 1:71204b8406f2 | 40 | (#) PC13 can be used as the RTC_AF1 pin |
| modtronix | 1:71204b8406f2 | 41 | |
| modtronix | 1:71204b8406f2 | 42 | ##### Backup Domain Reset ##### |
| modtronix | 1:71204b8406f2 | 43 | ================================================================== |
| modtronix | 1:71204b8406f2 | 44 | [..] The backup domain reset sets all RTC registers and the RCC_BDCR register |
| modtronix | 1:71204b8406f2 | 45 | to their reset values. |
| modtronix | 1:71204b8406f2 | 46 | [..] A backup domain reset is generated when one of the following events occurs: |
| modtronix | 1:71204b8406f2 | 47 | (#) Software reset, triggered by setting the BDRST bit in the |
| modtronix | 1:71204b8406f2 | 48 | RCC Backup domain control register (RCC_BDCR). |
| modtronix | 1:71204b8406f2 | 49 | (#) VDD or VBAT power on, if both supplies have previously been powered off. |
| modtronix | 1:71204b8406f2 | 50 | |
| modtronix | 1:71204b8406f2 | 51 | ##### Backup Domain Access ##### |
| modtronix | 1:71204b8406f2 | 52 | ================================================================== |
| modtronix | 1:71204b8406f2 | 53 | [..] After reset, the backup domain (RTC registers, RTC backup data |
| modtronix | 1:71204b8406f2 | 54 | registers and backup SRAM) is protected against possible unwanted write |
| modtronix | 1:71204b8406f2 | 55 | accesses. |
| modtronix | 1:71204b8406f2 | 56 | [..] To enable access to the RTC Domain and RTC registers, proceed as follows: |
| modtronix | 1:71204b8406f2 | 57 | (+) Enable the Power Controller (PWR) APB1 interface clock using the |
| modtronix | 10:6444e6c798ce | 58 | __HAL_RCC_PWR_CLK_ENABLE() function. |
| modtronix | 1:71204b8406f2 | 59 | (+) Enable access to RTC domain using the HAL_PWR_EnableBkUpAccess() function. |
| modtronix | 1:71204b8406f2 | 60 | (+) Select the RTC clock source using the __HAL_RCC_RTC_CONFIG() function. |
| modtronix | 1:71204b8406f2 | 61 | (+) Enable RTC Clock using the __HAL_RCC_RTC_ENABLE() function. |
| modtronix | 1:71204b8406f2 | 62 | |
| modtronix | 1:71204b8406f2 | 63 | |
| modtronix | 1:71204b8406f2 | 64 | ##### How to use this driver ##### |
| modtronix | 1:71204b8406f2 | 65 | ================================================================== |
| modtronix | 1:71204b8406f2 | 66 | [..] |
| modtronix | 1:71204b8406f2 | 67 | (+) Enable the RTC domain access (see description in the section above). |
| modtronix | 1:71204b8406f2 | 68 | (+) Configure the RTC Prescaler (Asynchronous and Synchronous) and RTC hour |
| modtronix | 1:71204b8406f2 | 69 | format using the HAL_RTC_Init() function. |
| modtronix | 1:71204b8406f2 | 70 | |
| modtronix | 1:71204b8406f2 | 71 | *** Time and Date configuration *** |
| modtronix | 1:71204b8406f2 | 72 | =================================== |
| modtronix | 1:71204b8406f2 | 73 | [..] |
| modtronix | 1:71204b8406f2 | 74 | (+) To configure the RTC Calendar (Time and Date) use the HAL_RTC_SetTime() |
| modtronix | 1:71204b8406f2 | 75 | and HAL_RTC_SetDate() functions. |
| modtronix | 1:71204b8406f2 | 76 | (+) To read the RTC Calendar, use the HAL_RTC_GetTime() and HAL_RTC_GetDate() functions. |
| modtronix | 1:71204b8406f2 | 77 | |
| modtronix | 1:71204b8406f2 | 78 | *** Alarm configuration *** |
| modtronix | 1:71204b8406f2 | 79 | =========================== |
| modtronix | 1:71204b8406f2 | 80 | [..] |
| modtronix | 1:71204b8406f2 | 81 | (+) To configure the RTC Alarm use the HAL_RTC_SetAlarm() function. |
| modtronix | 1:71204b8406f2 | 82 | You can also configure the RTC Alarm with interrupt mode using the HAL_RTC_SetAlarm_IT() function. |
| modtronix | 1:71204b8406f2 | 83 | (+) To read the RTC Alarm, use the HAL_RTC_GetAlarm() function. |
| modtronix | 1:71204b8406f2 | 84 | |
| modtronix | 1:71204b8406f2 | 85 | ##### RTC and low power modes ##### |
| modtronix | 1:71204b8406f2 | 86 | ================================================================== |
| modtronix | 1:71204b8406f2 | 87 | [..] The MCU can be woken up from a low power mode by an RTC alternate |
| modtronix | 1:71204b8406f2 | 88 | function. |
| modtronix | 1:71204b8406f2 | 89 | [..] The RTC alternate functions are the RTC alarms (Alarm A and Alarm B), |
| modtronix | 1:71204b8406f2 | 90 | RTC wakeup, RTC tamper event detection and RTC time stamp event detection. |
| modtronix | 1:71204b8406f2 | 91 | These RTC alternate functions can wake up the system from the Stop and |
| modtronix | 1:71204b8406f2 | 92 | Standby low power modes. |
| modtronix | 1:71204b8406f2 | 93 | [..] The system can also wake up from low power modes without depending |
| modtronix | 1:71204b8406f2 | 94 | on an external interrupt (Auto-wakeup mode), by using the RTC alarm |
| modtronix | 1:71204b8406f2 | 95 | or the RTC wakeup events. |
| modtronix | 1:71204b8406f2 | 96 | [..] The RTC provides a programmable time base for waking up from the |
| modtronix | 1:71204b8406f2 | 97 | Stop or Standby mode at regular intervals. |
| modtronix | 1:71204b8406f2 | 98 | Wakeup from STOP and STANDBY modes is possible only when the RTC clock source |
| modtronix | 1:71204b8406f2 | 99 | is LSE or LSI. |
| modtronix | 1:71204b8406f2 | 100 | |
| modtronix | 1:71204b8406f2 | 101 | @endverbatim |
| modtronix | 1:71204b8406f2 | 102 | ****************************************************************************** |
| modtronix | 1:71204b8406f2 | 103 | * @attention |
| modtronix | 1:71204b8406f2 | 104 | * |
| modtronix | 10:6444e6c798ce | 105 | * <h2><center>© COPYRIGHT(c) 2015 STMicroelectronics</center></h2> |
| modtronix | 1:71204b8406f2 | 106 | * |
| modtronix | 1:71204b8406f2 | 107 | * Redistribution and use in source and binary forms, with or without modification, |
| modtronix | 1:71204b8406f2 | 108 | * are permitted provided that the following conditions are met: |
| modtronix | 1:71204b8406f2 | 109 | * 1. Redistributions of source code must retain the above copyright notice, |
| modtronix | 1:71204b8406f2 | 110 | * this list of conditions and the following disclaimer. |
| modtronix | 1:71204b8406f2 | 111 | * 2. Redistributions in binary form must reproduce the above copyright notice, |
| modtronix | 1:71204b8406f2 | 112 | * this list of conditions and the following disclaimer in the documentation |
| modtronix | 1:71204b8406f2 | 113 | * and/or other materials provided with the distribution. |
| modtronix | 1:71204b8406f2 | 114 | * 3. Neither the name of STMicroelectronics nor the names of its contributors |
| modtronix | 1:71204b8406f2 | 115 | * may be used to endorse or promote products derived from this software |
| modtronix | 1:71204b8406f2 | 116 | * without specific prior written permission. |
| modtronix | 1:71204b8406f2 | 117 | * |
| modtronix | 1:71204b8406f2 | 118 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
| modtronix | 1:71204b8406f2 | 119 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| modtronix | 1:71204b8406f2 | 120 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
| modtronix | 1:71204b8406f2 | 121 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE |
| modtronix | 1:71204b8406f2 | 122 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
| modtronix | 1:71204b8406f2 | 123 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |
| modtronix | 1:71204b8406f2 | 124 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
| modtronix | 1:71204b8406f2 | 125 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |
| modtronix | 1:71204b8406f2 | 126 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| modtronix | 1:71204b8406f2 | 127 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| modtronix | 1:71204b8406f2 | 128 | * |
| modtronix | 1:71204b8406f2 | 129 | ****************************************************************************** |
| modtronix | 1:71204b8406f2 | 130 | */ |
| modtronix | 1:71204b8406f2 | 131 | |
| modtronix | 1:71204b8406f2 | 132 | /* Includes ------------------------------------------------------------------*/ |
| modtronix | 1:71204b8406f2 | 133 | #include "stm32l1xx_hal.h" |
| modtronix | 1:71204b8406f2 | 134 | |
| modtronix | 1:71204b8406f2 | 135 | /** @addtogroup STM32L1xx_HAL_Driver |
| modtronix | 1:71204b8406f2 | 136 | * @{ |
| modtronix | 1:71204b8406f2 | 137 | */ |
| modtronix | 1:71204b8406f2 | 138 | |
| modtronix | 1:71204b8406f2 | 139 | /** @defgroup RTC RTC |
| modtronix | 1:71204b8406f2 | 140 | * @brief RTC HAL module driver |
| modtronix | 1:71204b8406f2 | 141 | * @{ |
| modtronix | 1:71204b8406f2 | 142 | */ |
| modtronix | 1:71204b8406f2 | 143 | |
| modtronix | 1:71204b8406f2 | 144 | #ifdef HAL_RTC_MODULE_ENABLED |
| modtronix | 1:71204b8406f2 | 145 | |
| modtronix | 1:71204b8406f2 | 146 | /* Private typedef -----------------------------------------------------------*/ |
| modtronix | 1:71204b8406f2 | 147 | /* Private define ------------------------------------------------------------*/ |
| modtronix | 1:71204b8406f2 | 148 | /* Private macro -------------------------------------------------------------*/ |
| modtronix | 1:71204b8406f2 | 149 | /* Private variables ---------------------------------------------------------*/ |
| modtronix | 1:71204b8406f2 | 150 | /* Private function prototypes -----------------------------------------------*/ |
| modtronix | 1:71204b8406f2 | 151 | /* Private functions ---------------------------------------------------------*/ |
| modtronix | 1:71204b8406f2 | 152 | /** @defgroup RTC_Exported_Functions RTC Exported Functions |
| modtronix | 1:71204b8406f2 | 153 | * @{ |
| modtronix | 1:71204b8406f2 | 154 | */ |
| modtronix | 1:71204b8406f2 | 155 | |
| modtronix | 1:71204b8406f2 | 156 | /** @defgroup RTC_Exported_Functions_Group1 Initialization and de-initialization functions |
| modtronix | 1:71204b8406f2 | 157 | * @brief Initialization and Configuration functions |
| modtronix | 1:71204b8406f2 | 158 | * |
| modtronix | 1:71204b8406f2 | 159 | @verbatim |
| modtronix | 1:71204b8406f2 | 160 | =============================================================================== |
| modtronix | 1:71204b8406f2 | 161 | ##### Initialization and de-initialization functions ##### |
| modtronix | 1:71204b8406f2 | 162 | =============================================================================== |
| modtronix | 1:71204b8406f2 | 163 | [..] This section provides functions allowing to initialize and configure the |
| modtronix | 1:71204b8406f2 | 164 | RTC Prescaler (Synchronous and Asynchronous), RTC Hour format, disable |
| modtronix | 1:71204b8406f2 | 165 | RTC registers Write protection, enter and exit the RTC initialization mode, |
| modtronix | 1:71204b8406f2 | 166 | RTC registers synchronization check and reference clock detection enable. |
| modtronix | 1:71204b8406f2 | 167 | (#) The RTC Prescaler is programmed to generate the RTC 1Hz time base. |
| modtronix | 1:71204b8406f2 | 168 | It is split into 2 programmable prescalers to minimize power consumption. |
| modtronix | 1:71204b8406f2 | 169 | (++) A 7-bit asynchronous prescaler and a 13-bit synchronous prescaler. |
| modtronix | 1:71204b8406f2 | 170 | (++) When both prescalers are used, it is recommended to configure the |
| modtronix | 1:71204b8406f2 | 171 | asynchronous prescaler to a high value to minimize power consumption. |
| modtronix | 1:71204b8406f2 | 172 | (#) All RTC registers are Write protected. Writing to the RTC registers |
| modtronix | 1:71204b8406f2 | 173 | is enabled by writing a key into the Write Protection register, RTC_WPR. |
| modtronix | 1:71204b8406f2 | 174 | (#) To configure the RTC Calendar, user application should enter |
| modtronix | 1:71204b8406f2 | 175 | initialization mode. In this mode, the calendar counter is stopped |
| modtronix | 1:71204b8406f2 | 176 | and its value can be updated. When the initialization sequence is |
| modtronix | 1:71204b8406f2 | 177 | complete, the calendar restarts counting after 4 RTCCLK cycles. |
| modtronix | 1:71204b8406f2 | 178 | (#) To read the calendar through the shadow registers after Calendar |
| modtronix | 1:71204b8406f2 | 179 | initialization, calendar update or after wakeup from low power modes |
| modtronix | 1:71204b8406f2 | 180 | the software must first clear the RSF flag. The software must then |
| modtronix | 1:71204b8406f2 | 181 | wait until it is set again before reading the calendar, which means |
| modtronix | 1:71204b8406f2 | 182 | that the calendar registers have been correctly copied into the |
| modtronix | 1:71204b8406f2 | 183 | RTC_TR and RTC_DR shadow registers.The HAL_RTC_WaitForSynchro() function |
| modtronix | 1:71204b8406f2 | 184 | implements the above software sequence (RSF clear and RSF check). |
| modtronix | 1:71204b8406f2 | 185 | |
| modtronix | 1:71204b8406f2 | 186 | @endverbatim |
| modtronix | 1:71204b8406f2 | 187 | * @{ |
| modtronix | 1:71204b8406f2 | 188 | */ |
| modtronix | 1:71204b8406f2 | 189 | |
| modtronix | 1:71204b8406f2 | 190 | /** |
| modtronix | 1:71204b8406f2 | 191 | * @brief Initializes the RTC peripheral |
| modtronix | 1:71204b8406f2 | 192 | * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains |
| modtronix | 1:71204b8406f2 | 193 | * the configuration information for RTC. |
| modtronix | 1:71204b8406f2 | 194 | * @retval HAL status |
| modtronix | 1:71204b8406f2 | 195 | */ |
| modtronix | 1:71204b8406f2 | 196 | HAL_StatusTypeDef HAL_RTC_Init(RTC_HandleTypeDef *hrtc) |
| modtronix | 1:71204b8406f2 | 197 | { |
| modtronix | 1:71204b8406f2 | 198 | /* Check the RTC peripheral state */ |
| modtronix | 10:6444e6c798ce | 199 | if(hrtc == NULL) |
| modtronix | 1:71204b8406f2 | 200 | { |
| modtronix | 1:71204b8406f2 | 201 | return HAL_ERROR; |
| modtronix | 1:71204b8406f2 | 202 | } |
| modtronix | 1:71204b8406f2 | 203 | |
| modtronix | 1:71204b8406f2 | 204 | /* Check the parameters */ |
| modtronix | 1:71204b8406f2 | 205 | assert_param(IS_RTC_ALL_INSTANCE(hrtc->Instance)); |
| modtronix | 1:71204b8406f2 | 206 | assert_param(IS_RTC_HOUR_FORMAT(hrtc->Init.HourFormat)); |
| modtronix | 1:71204b8406f2 | 207 | assert_param(IS_RTC_ASYNCH_PREDIV(hrtc->Init.AsynchPrediv)); |
| modtronix | 1:71204b8406f2 | 208 | assert_param(IS_RTC_SYNCH_PREDIV(hrtc->Init.SynchPrediv)); |
| modtronix | 1:71204b8406f2 | 209 | assert_param(IS_RTC_OUTPUT(hrtc->Init.OutPut)); |
| modtronix | 1:71204b8406f2 | 210 | assert_param(IS_RTC_OUTPUT_POL(hrtc->Init.OutPutPolarity)); |
| modtronix | 1:71204b8406f2 | 211 | assert_param(IS_RTC_OUTPUT_TYPE(hrtc->Init.OutPutType)); |
| modtronix | 1:71204b8406f2 | 212 | |
| modtronix | 1:71204b8406f2 | 213 | if(hrtc->State == HAL_RTC_STATE_RESET) |
| modtronix | 1:71204b8406f2 | 214 | { |
| modtronix | 10:6444e6c798ce | 215 | /* Allocate lock resource and initialize it */ |
| modtronix | 10:6444e6c798ce | 216 | hrtc->Lock = HAL_UNLOCKED; |
| modtronix | 10:6444e6c798ce | 217 | |
| modtronix | 1:71204b8406f2 | 218 | /* Initialize RTC MSP */ |
| modtronix | 1:71204b8406f2 | 219 | HAL_RTC_MspInit(hrtc); |
| modtronix | 1:71204b8406f2 | 220 | } |
| modtronix | 1:71204b8406f2 | 221 | |
| modtronix | 1:71204b8406f2 | 222 | /* Set RTC state */ |
| modtronix | 1:71204b8406f2 | 223 | hrtc->State = HAL_RTC_STATE_BUSY; |
| modtronix | 1:71204b8406f2 | 224 | |
| modtronix | 1:71204b8406f2 | 225 | /* Disable the write protection for RTC registers */ |
| modtronix | 1:71204b8406f2 | 226 | __HAL_RTC_WRITEPROTECTION_DISABLE(hrtc); |
| modtronix | 1:71204b8406f2 | 227 | |
| modtronix | 1:71204b8406f2 | 228 | /* Set Initialization mode */ |
| modtronix | 1:71204b8406f2 | 229 | if(RTC_EnterInitMode(hrtc) != HAL_OK) |
| modtronix | 1:71204b8406f2 | 230 | { |
| modtronix | 1:71204b8406f2 | 231 | /* Enable the write protection for RTC registers */ |
| modtronix | 1:71204b8406f2 | 232 | __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc); |
| modtronix | 1:71204b8406f2 | 233 | |
| modtronix | 1:71204b8406f2 | 234 | /* Set RTC state */ |
| modtronix | 1:71204b8406f2 | 235 | hrtc->State = HAL_RTC_STATE_ERROR; |
| modtronix | 1:71204b8406f2 | 236 | |
| modtronix | 1:71204b8406f2 | 237 | return HAL_ERROR; |
| modtronix | 1:71204b8406f2 | 238 | } |
| modtronix | 1:71204b8406f2 | 239 | else |
| modtronix | 1:71204b8406f2 | 240 | { |
| modtronix | 1:71204b8406f2 | 241 | /* Clear RTC_CR FMT, OSEL and POL Bits */ |
| modtronix | 1:71204b8406f2 | 242 | hrtc->Instance->CR &= ((uint32_t)~(RTC_CR_FMT | RTC_CR_OSEL | RTC_CR_POL)); |
| modtronix | 1:71204b8406f2 | 243 | /* Set RTC_CR register */ |
| modtronix | 1:71204b8406f2 | 244 | hrtc->Instance->CR |= (uint32_t)(hrtc->Init.HourFormat | hrtc->Init.OutPut | hrtc->Init.OutPutPolarity); |
| modtronix | 1:71204b8406f2 | 245 | |
| modtronix | 1:71204b8406f2 | 246 | /* Configure the RTC PRER */ |
| modtronix | 1:71204b8406f2 | 247 | hrtc->Instance->PRER = (uint32_t)(hrtc->Init.SynchPrediv); |
| modtronix | 1:71204b8406f2 | 248 | hrtc->Instance->PRER |= (uint32_t)(hrtc->Init.AsynchPrediv << 16); |
| modtronix | 1:71204b8406f2 | 249 | |
| modtronix | 1:71204b8406f2 | 250 | /* Exit Initialization mode */ |
| modtronix | 1:71204b8406f2 | 251 | hrtc->Instance->ISR &= (uint32_t)~RTC_ISR_INIT; |
| modtronix | 1:71204b8406f2 | 252 | |
| modtronix | 1:71204b8406f2 | 253 | hrtc->Instance->TAFCR &= (uint32_t)~RTC_TAFCR_ALARMOUTTYPE; |
| modtronix | 1:71204b8406f2 | 254 | hrtc->Instance->TAFCR |= (uint32_t)(hrtc->Init.OutPutType); |
| modtronix | 1:71204b8406f2 | 255 | |
| modtronix | 1:71204b8406f2 | 256 | /* Enable the write protection for RTC registers */ |
| modtronix | 1:71204b8406f2 | 257 | __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc); |
| modtronix | 1:71204b8406f2 | 258 | |
| modtronix | 1:71204b8406f2 | 259 | /* Set RTC state */ |
| modtronix | 1:71204b8406f2 | 260 | hrtc->State = HAL_RTC_STATE_READY; |
| modtronix | 1:71204b8406f2 | 261 | |
| modtronix | 1:71204b8406f2 | 262 | return HAL_OK; |
| modtronix | 1:71204b8406f2 | 263 | } |
| modtronix | 1:71204b8406f2 | 264 | } |
| modtronix | 1:71204b8406f2 | 265 | |
| modtronix | 1:71204b8406f2 | 266 | /** |
| modtronix | 1:71204b8406f2 | 267 | * @brief DeInitializes the RTC peripheral |
| modtronix | 1:71204b8406f2 | 268 | * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains |
| modtronix | 1:71204b8406f2 | 269 | * the configuration information for RTC. |
| modtronix | 1:71204b8406f2 | 270 | * @note This function doesn't reset the RTC Backup Data registers. |
| modtronix | 1:71204b8406f2 | 271 | * @retval HAL status |
| modtronix | 1:71204b8406f2 | 272 | */ |
| modtronix | 1:71204b8406f2 | 273 | __weak HAL_StatusTypeDef HAL_RTC_DeInit(RTC_HandleTypeDef *hrtc) |
| modtronix | 1:71204b8406f2 | 274 | { |
| modtronix | 1:71204b8406f2 | 275 | /* Note : This function is defined into this file for library reference. */ |
| modtronix | 1:71204b8406f2 | 276 | /* Function content is located into file stm32l1xx_hal_rtc_ex.c */ |
| modtronix | 1:71204b8406f2 | 277 | |
| modtronix | 1:71204b8406f2 | 278 | /* Return function status */ |
| modtronix | 1:71204b8406f2 | 279 | return HAL_ERROR; |
| modtronix | 1:71204b8406f2 | 280 | } |
| modtronix | 1:71204b8406f2 | 281 | |
| modtronix | 1:71204b8406f2 | 282 | /** |
| modtronix | 1:71204b8406f2 | 283 | * @brief Initializes the RTC MSP. |
| modtronix | 1:71204b8406f2 | 284 | * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains |
| modtronix | 1:71204b8406f2 | 285 | * the configuration information for RTC. |
| modtronix | 1:71204b8406f2 | 286 | * @retval None |
| modtronix | 1:71204b8406f2 | 287 | */ |
| modtronix | 1:71204b8406f2 | 288 | __weak void HAL_RTC_MspInit(RTC_HandleTypeDef* hrtc) |
| modtronix | 1:71204b8406f2 | 289 | { |
| modtronix | 1:71204b8406f2 | 290 | /* NOTE : This function Should not be modified, when the callback is needed, |
| modtronix | 1:71204b8406f2 | 291 | the HAL_RTC_MspInit could be implemented in the user file |
| modtronix | 1:71204b8406f2 | 292 | */ |
| modtronix | 1:71204b8406f2 | 293 | } |
| modtronix | 1:71204b8406f2 | 294 | |
| modtronix | 1:71204b8406f2 | 295 | /** |
| modtronix | 1:71204b8406f2 | 296 | * @brief DeInitializes the RTC MSP. |
| modtronix | 1:71204b8406f2 | 297 | * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains |
| modtronix | 1:71204b8406f2 | 298 | * the configuration information for RTC. |
| modtronix | 1:71204b8406f2 | 299 | * @retval None |
| modtronix | 1:71204b8406f2 | 300 | */ |
| modtronix | 1:71204b8406f2 | 301 | __weak void HAL_RTC_MspDeInit(RTC_HandleTypeDef* hrtc) |
| modtronix | 1:71204b8406f2 | 302 | { |
| modtronix | 1:71204b8406f2 | 303 | /* NOTE : This function Should not be modified, when the callback is needed, |
| modtronix | 1:71204b8406f2 | 304 | the HAL_RTC_MspDeInit could be implemented in the user file |
| modtronix | 1:71204b8406f2 | 305 | */ |
| modtronix | 1:71204b8406f2 | 306 | } |
| modtronix | 1:71204b8406f2 | 307 | |
| modtronix | 1:71204b8406f2 | 308 | /** |
| modtronix | 1:71204b8406f2 | 309 | * @} |
| modtronix | 1:71204b8406f2 | 310 | */ |
| modtronix | 1:71204b8406f2 | 311 | |
| modtronix | 1:71204b8406f2 | 312 | /** @defgroup RTC_Exported_Functions_Group2 RTC Time and Date functions |
| modtronix | 1:71204b8406f2 | 313 | * @brief RTC Time and Date functions |
| modtronix | 1:71204b8406f2 | 314 | * |
| modtronix | 1:71204b8406f2 | 315 | @verbatim |
| modtronix | 1:71204b8406f2 | 316 | =============================================================================== |
| modtronix | 1:71204b8406f2 | 317 | ##### RTC Time and Date functions ##### |
| modtronix | 1:71204b8406f2 | 318 | =============================================================================== |
| modtronix | 1:71204b8406f2 | 319 | |
| modtronix | 1:71204b8406f2 | 320 | [..] This section provides functions allowing to configure Time and Date features |
| modtronix | 1:71204b8406f2 | 321 | |
| modtronix | 1:71204b8406f2 | 322 | @endverbatim |
| modtronix | 1:71204b8406f2 | 323 | * @{ |
| modtronix | 1:71204b8406f2 | 324 | */ |
| modtronix | 1:71204b8406f2 | 325 | |
| modtronix | 1:71204b8406f2 | 326 | /** |
| modtronix | 1:71204b8406f2 | 327 | * @brief Sets RTC current time. |
| modtronix | 1:71204b8406f2 | 328 | * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains |
| modtronix | 1:71204b8406f2 | 329 | * the configuration information for RTC. |
| modtronix | 1:71204b8406f2 | 330 | * @param sTime: Pointer to Time structure |
| modtronix | 1:71204b8406f2 | 331 | * @param Format: Specifies the format of the entered parameters. |
| modtronix | 1:71204b8406f2 | 332 | * This parameter can be one of the following values: |
| modtronix | 10:6444e6c798ce | 333 | * @arg RTC_FORMAT_BIN: Binary data format |
| modtronix | 10:6444e6c798ce | 334 | * @arg RTC_FORMAT_BCD: BCD data format |
| modtronix | 1:71204b8406f2 | 335 | * @retval HAL status |
| modtronix | 1:71204b8406f2 | 336 | */ |
| modtronix | 1:71204b8406f2 | 337 | HAL_StatusTypeDef HAL_RTC_SetTime(RTC_HandleTypeDef *hrtc, RTC_TimeTypeDef *sTime, uint32_t Format) |
| modtronix | 1:71204b8406f2 | 338 | { |
| modtronix | 1:71204b8406f2 | 339 | uint32_t tmpreg = 0; |
| modtronix | 1:71204b8406f2 | 340 | |
| modtronix | 1:71204b8406f2 | 341 | /* Check the parameters */ |
| modtronix | 1:71204b8406f2 | 342 | assert_param(IS_RTC_FORMAT(Format)); |
| modtronix | 1:71204b8406f2 | 343 | assert_param(IS_RTC_DAYLIGHT_SAVING(sTime->DayLightSaving)); |
| modtronix | 1:71204b8406f2 | 344 | assert_param(IS_RTC_STORE_OPERATION(sTime->StoreOperation)); |
| modtronix | 1:71204b8406f2 | 345 | |
| modtronix | 1:71204b8406f2 | 346 | /* Process Locked */ |
| modtronix | 1:71204b8406f2 | 347 | __HAL_LOCK(hrtc); |
| modtronix | 1:71204b8406f2 | 348 | |
| modtronix | 1:71204b8406f2 | 349 | hrtc->State = HAL_RTC_STATE_BUSY; |
| modtronix | 1:71204b8406f2 | 350 | |
| modtronix | 10:6444e6c798ce | 351 | if(Format == RTC_FORMAT_BIN) |
| modtronix | 1:71204b8406f2 | 352 | { |
| modtronix | 1:71204b8406f2 | 353 | if((hrtc->Instance->CR & RTC_CR_FMT) != (uint32_t)RESET) |
| modtronix | 1:71204b8406f2 | 354 | { |
| modtronix | 1:71204b8406f2 | 355 | assert_param(IS_RTC_HOUR12(sTime->Hours)); |
| modtronix | 1:71204b8406f2 | 356 | assert_param(IS_RTC_HOURFORMAT12(sTime->TimeFormat)); |
| modtronix | 1:71204b8406f2 | 357 | } |
| modtronix | 1:71204b8406f2 | 358 | else |
| modtronix | 1:71204b8406f2 | 359 | { |
| modtronix | 1:71204b8406f2 | 360 | sTime->TimeFormat = 0x00; |
| modtronix | 1:71204b8406f2 | 361 | assert_param(IS_RTC_HOUR24(sTime->Hours)); |
| modtronix | 1:71204b8406f2 | 362 | } |
| modtronix | 1:71204b8406f2 | 363 | assert_param(IS_RTC_MINUTES(sTime->Minutes)); |
| modtronix | 1:71204b8406f2 | 364 | assert_param(IS_RTC_SECONDS(sTime->Seconds)); |
| modtronix | 1:71204b8406f2 | 365 | |
| modtronix | 1:71204b8406f2 | 366 | tmpreg = (uint32_t)(((uint32_t)RTC_ByteToBcd2(sTime->Hours) << 16) | \ |
| modtronix | 1:71204b8406f2 | 367 | ((uint32_t)RTC_ByteToBcd2(sTime->Minutes) << 8) | \ |
| modtronix | 1:71204b8406f2 | 368 | ((uint32_t)RTC_ByteToBcd2(sTime->Seconds)) | \ |
| modtronix | 1:71204b8406f2 | 369 | (((uint32_t)sTime->TimeFormat) << 16)); |
| modtronix | 1:71204b8406f2 | 370 | } |
| modtronix | 1:71204b8406f2 | 371 | else |
| modtronix | 1:71204b8406f2 | 372 | { |
| modtronix | 1:71204b8406f2 | 373 | if((hrtc->Instance->CR & RTC_CR_FMT) != (uint32_t)RESET) |
| modtronix | 1:71204b8406f2 | 374 | { |
| modtronix | 1:71204b8406f2 | 375 | tmpreg = RTC_Bcd2ToByte(sTime->Hours); |
| modtronix | 1:71204b8406f2 | 376 | assert_param(IS_RTC_HOUR12(tmpreg)); |
| modtronix | 1:71204b8406f2 | 377 | assert_param(IS_RTC_HOURFORMAT12(sTime->TimeFormat)); |
| modtronix | 1:71204b8406f2 | 378 | } |
| modtronix | 1:71204b8406f2 | 379 | else |
| modtronix | 1:71204b8406f2 | 380 | { |
| modtronix | 1:71204b8406f2 | 381 | sTime->TimeFormat = 0x00; |
| modtronix | 1:71204b8406f2 | 382 | assert_param(IS_RTC_HOUR24(RTC_Bcd2ToByte(sTime->Hours))); |
| modtronix | 1:71204b8406f2 | 383 | } |
| modtronix | 1:71204b8406f2 | 384 | assert_param(IS_RTC_MINUTES(RTC_Bcd2ToByte(sTime->Minutes))); |
| modtronix | 1:71204b8406f2 | 385 | assert_param(IS_RTC_SECONDS(RTC_Bcd2ToByte(sTime->Seconds))); |
| modtronix | 1:71204b8406f2 | 386 | tmpreg = (((uint32_t)(sTime->Hours) << 16) | \ |
| modtronix | 1:71204b8406f2 | 387 | ((uint32_t)(sTime->Minutes) << 8) | \ |
| modtronix | 1:71204b8406f2 | 388 | ((uint32_t)sTime->Seconds) | \ |
| modtronix | 1:71204b8406f2 | 389 | ((uint32_t)(sTime->TimeFormat) << 16)); |
| modtronix | 1:71204b8406f2 | 390 | } |
| modtronix | 1:71204b8406f2 | 391 | |
| modtronix | 1:71204b8406f2 | 392 | /* Disable the write protection for RTC registers */ |
| modtronix | 1:71204b8406f2 | 393 | __HAL_RTC_WRITEPROTECTION_DISABLE(hrtc); |
| modtronix | 1:71204b8406f2 | 394 | |
| modtronix | 1:71204b8406f2 | 395 | /* Set Initialization mode */ |
| modtronix | 1:71204b8406f2 | 396 | if(RTC_EnterInitMode(hrtc) != HAL_OK) |
| modtronix | 1:71204b8406f2 | 397 | { |
| modtronix | 1:71204b8406f2 | 398 | /* Enable the write protection for RTC registers */ |
| modtronix | 1:71204b8406f2 | 399 | __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc); |
| modtronix | 1:71204b8406f2 | 400 | |
| modtronix | 1:71204b8406f2 | 401 | /* Set RTC state */ |
| modtronix | 1:71204b8406f2 | 402 | hrtc->State = HAL_RTC_STATE_ERROR; |
| modtronix | 1:71204b8406f2 | 403 | |
| modtronix | 1:71204b8406f2 | 404 | /* Process Unlocked */ |
| modtronix | 1:71204b8406f2 | 405 | __HAL_UNLOCK(hrtc); |
| modtronix | 1:71204b8406f2 | 406 | |
| modtronix | 1:71204b8406f2 | 407 | return HAL_ERROR; |
| modtronix | 1:71204b8406f2 | 408 | } |
| modtronix | 1:71204b8406f2 | 409 | else |
| modtronix | 1:71204b8406f2 | 410 | { |
| modtronix | 1:71204b8406f2 | 411 | /* Set the RTC_TR register */ |
| modtronix | 1:71204b8406f2 | 412 | hrtc->Instance->TR = (uint32_t)(tmpreg & RTC_TR_RESERVED_MASK); |
| modtronix | 1:71204b8406f2 | 413 | |
| modtronix | 1:71204b8406f2 | 414 | /* Clear the bits to be configured */ |
| modtronix | 1:71204b8406f2 | 415 | hrtc->Instance->CR &= (uint32_t)~RTC_CR_BCK; |
| modtronix | 1:71204b8406f2 | 416 | |
| modtronix | 1:71204b8406f2 | 417 | /* Configure the RTC_CR register */ |
| modtronix | 1:71204b8406f2 | 418 | hrtc->Instance->CR |= (uint32_t)(sTime->DayLightSaving | sTime->StoreOperation); |
| modtronix | 1:71204b8406f2 | 419 | |
| modtronix | 1:71204b8406f2 | 420 | /* Exit Initialization mode */ |
| modtronix | 1:71204b8406f2 | 421 | hrtc->Instance->ISR &= (uint32_t)~RTC_ISR_INIT; |
| modtronix | 1:71204b8406f2 | 422 | |
| modtronix | 1:71204b8406f2 | 423 | /* Wait for synchro */ |
| modtronix | 1:71204b8406f2 | 424 | if(HAL_RTC_WaitForSynchro(hrtc) != HAL_OK) |
| modtronix | 1:71204b8406f2 | 425 | { |
| modtronix | 1:71204b8406f2 | 426 | /* Enable the write protection for RTC registers */ |
| modtronix | 1:71204b8406f2 | 427 | __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc); |
| modtronix | 1:71204b8406f2 | 428 | |
| modtronix | 1:71204b8406f2 | 429 | hrtc->State = HAL_RTC_STATE_ERROR; |
| modtronix | 1:71204b8406f2 | 430 | |
| modtronix | 1:71204b8406f2 | 431 | /* Process Unlocked */ |
| modtronix | 1:71204b8406f2 | 432 | __HAL_UNLOCK(hrtc); |
| modtronix | 1:71204b8406f2 | 433 | |
| modtronix | 1:71204b8406f2 | 434 | return HAL_ERROR; |
| modtronix | 1:71204b8406f2 | 435 | } |
| modtronix | 1:71204b8406f2 | 436 | |
| modtronix | 1:71204b8406f2 | 437 | /* Enable the write protection for RTC registers */ |
| modtronix | 1:71204b8406f2 | 438 | __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc); |
| modtronix | 1:71204b8406f2 | 439 | |
| modtronix | 1:71204b8406f2 | 440 | hrtc->State = HAL_RTC_STATE_READY; |
| modtronix | 1:71204b8406f2 | 441 | |
| modtronix | 1:71204b8406f2 | 442 | __HAL_UNLOCK(hrtc); |
| modtronix | 1:71204b8406f2 | 443 | |
| modtronix | 1:71204b8406f2 | 444 | return HAL_OK; |
| modtronix | 1:71204b8406f2 | 445 | } |
| modtronix | 1:71204b8406f2 | 446 | } |
| modtronix | 1:71204b8406f2 | 447 | |
| modtronix | 1:71204b8406f2 | 448 | |
| modtronix | 1:71204b8406f2 | 449 | /** |
| modtronix | 1:71204b8406f2 | 450 | * @brief Sets RTC current date. |
| modtronix | 1:71204b8406f2 | 451 | * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains |
| modtronix | 1:71204b8406f2 | 452 | * the configuration information for RTC. |
| modtronix | 1:71204b8406f2 | 453 | * @param sDate: Pointer to date structure |
| modtronix | 1:71204b8406f2 | 454 | * @param Format: specifies the format of the entered parameters. |
| modtronix | 1:71204b8406f2 | 455 | * This parameter can be one of the following values: |
| modtronix | 10:6444e6c798ce | 456 | * @arg RTC_FORMAT_BIN: Binary data format |
| modtronix | 10:6444e6c798ce | 457 | * @arg RTC_FORMAT_BCD: BCD data format |
| modtronix | 1:71204b8406f2 | 458 | * @retval HAL status |
| modtronix | 1:71204b8406f2 | 459 | */ |
| modtronix | 1:71204b8406f2 | 460 | HAL_StatusTypeDef HAL_RTC_SetDate(RTC_HandleTypeDef *hrtc, RTC_DateTypeDef *sDate, uint32_t Format) |
| modtronix | 1:71204b8406f2 | 461 | { |
| modtronix | 1:71204b8406f2 | 462 | uint32_t datetmpreg = 0; |
| modtronix | 1:71204b8406f2 | 463 | |
| modtronix | 1:71204b8406f2 | 464 | /* Check the parameters */ |
| modtronix | 1:71204b8406f2 | 465 | assert_param(IS_RTC_FORMAT(Format)); |
| modtronix | 1:71204b8406f2 | 466 | |
| modtronix | 1:71204b8406f2 | 467 | /* Process Locked */ |
| modtronix | 1:71204b8406f2 | 468 | __HAL_LOCK(hrtc); |
| modtronix | 1:71204b8406f2 | 469 | |
| modtronix | 1:71204b8406f2 | 470 | hrtc->State = HAL_RTC_STATE_BUSY; |
| modtronix | 1:71204b8406f2 | 471 | |
| modtronix | 10:6444e6c798ce | 472 | if((Format == RTC_FORMAT_BIN) && ((sDate->Month & 0x10) == 0x10)) |
| modtronix | 1:71204b8406f2 | 473 | { |
| modtronix | 1:71204b8406f2 | 474 | sDate->Month = (uint8_t)((sDate->Month & (uint8_t)~(0x10)) + (uint8_t)0x0A); |
| modtronix | 1:71204b8406f2 | 475 | } |
| modtronix | 1:71204b8406f2 | 476 | |
| modtronix | 1:71204b8406f2 | 477 | assert_param(IS_RTC_WEEKDAY(sDate->WeekDay)); |
| modtronix | 1:71204b8406f2 | 478 | |
| modtronix | 10:6444e6c798ce | 479 | if(Format == RTC_FORMAT_BIN) |
| modtronix | 1:71204b8406f2 | 480 | { |
| modtronix | 1:71204b8406f2 | 481 | assert_param(IS_RTC_YEAR(sDate->Year)); |
| modtronix | 1:71204b8406f2 | 482 | assert_param(IS_RTC_MONTH(sDate->Month)); |
| modtronix | 1:71204b8406f2 | 483 | assert_param(IS_RTC_DATE(sDate->Date)); |
| modtronix | 1:71204b8406f2 | 484 | |
| modtronix | 1:71204b8406f2 | 485 | datetmpreg = (((uint32_t)RTC_ByteToBcd2(sDate->Year) << 16) | \ |
| modtronix | 1:71204b8406f2 | 486 | ((uint32_t)RTC_ByteToBcd2(sDate->Month) << 8) | \ |
| modtronix | 1:71204b8406f2 | 487 | ((uint32_t)RTC_ByteToBcd2(sDate->Date)) | \ |
| modtronix | 1:71204b8406f2 | 488 | ((uint32_t)sDate->WeekDay << 13)); |
| modtronix | 1:71204b8406f2 | 489 | } |
| modtronix | 1:71204b8406f2 | 490 | else |
| modtronix | 1:71204b8406f2 | 491 | { |
| modtronix | 1:71204b8406f2 | 492 | assert_param(IS_RTC_YEAR(RTC_Bcd2ToByte(sDate->Year))); |
| modtronix | 1:71204b8406f2 | 493 | datetmpreg = RTC_Bcd2ToByte(sDate->Month); |
| modtronix | 1:71204b8406f2 | 494 | assert_param(IS_RTC_MONTH(datetmpreg)); |
| modtronix | 1:71204b8406f2 | 495 | datetmpreg = RTC_Bcd2ToByte(sDate->Date); |
| modtronix | 1:71204b8406f2 | 496 | assert_param(IS_RTC_DATE(datetmpreg)); |
| modtronix | 1:71204b8406f2 | 497 | |
| modtronix | 1:71204b8406f2 | 498 | datetmpreg = ((((uint32_t)sDate->Year) << 16) | \ |
| modtronix | 1:71204b8406f2 | 499 | (((uint32_t)sDate->Month) << 8) | \ |
| modtronix | 1:71204b8406f2 | 500 | ((uint32_t)sDate->Date) | \ |
| modtronix | 1:71204b8406f2 | 501 | (((uint32_t)sDate->WeekDay) << 13)); |
| modtronix | 1:71204b8406f2 | 502 | } |
| modtronix | 1:71204b8406f2 | 503 | |
| modtronix | 1:71204b8406f2 | 504 | /* Disable the write protection for RTC registers */ |
| modtronix | 1:71204b8406f2 | 505 | __HAL_RTC_WRITEPROTECTION_DISABLE(hrtc); |
| modtronix | 1:71204b8406f2 | 506 | |
| modtronix | 1:71204b8406f2 | 507 | /* Set Initialization mode */ |
| modtronix | 1:71204b8406f2 | 508 | if(RTC_EnterInitMode(hrtc) != HAL_OK) |
| modtronix | 1:71204b8406f2 | 509 | { |
| modtronix | 1:71204b8406f2 | 510 | /* Enable the write protection for RTC registers */ |
| modtronix | 1:71204b8406f2 | 511 | __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc); |
| modtronix | 1:71204b8406f2 | 512 | |
| modtronix | 1:71204b8406f2 | 513 | /* Set RTC state*/ |
| modtronix | 1:71204b8406f2 | 514 | hrtc->State = HAL_RTC_STATE_ERROR; |
| modtronix | 1:71204b8406f2 | 515 | |
| modtronix | 1:71204b8406f2 | 516 | /* Process Unlocked */ |
| modtronix | 1:71204b8406f2 | 517 | __HAL_UNLOCK(hrtc); |
| modtronix | 1:71204b8406f2 | 518 | |
| modtronix | 1:71204b8406f2 | 519 | return HAL_ERROR; |
| modtronix | 1:71204b8406f2 | 520 | } |
| modtronix | 1:71204b8406f2 | 521 | else |
| modtronix | 1:71204b8406f2 | 522 | { |
| modtronix | 1:71204b8406f2 | 523 | /* Set the RTC_DR register */ |
| modtronix | 1:71204b8406f2 | 524 | hrtc->Instance->DR = (uint32_t)(datetmpreg & RTC_DR_RESERVED_MASK); |
| modtronix | 1:71204b8406f2 | 525 | |
| modtronix | 1:71204b8406f2 | 526 | /* Exit Initialization mode */ |
| modtronix | 1:71204b8406f2 | 527 | hrtc->Instance->ISR &= (uint32_t)~RTC_ISR_INIT; |
| modtronix | 1:71204b8406f2 | 528 | |
| modtronix | 1:71204b8406f2 | 529 | /* Wait for synchro */ |
| modtronix | 1:71204b8406f2 | 530 | if(HAL_RTC_WaitForSynchro(hrtc) != HAL_OK) |
| modtronix | 1:71204b8406f2 | 531 | { |
| modtronix | 1:71204b8406f2 | 532 | /* Enable the write protection for RTC registers */ |
| modtronix | 1:71204b8406f2 | 533 | __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc); |
| modtronix | 1:71204b8406f2 | 534 | |
| modtronix | 1:71204b8406f2 | 535 | hrtc->State = HAL_RTC_STATE_ERROR; |
| modtronix | 1:71204b8406f2 | 536 | |
| modtronix | 1:71204b8406f2 | 537 | /* Process Unlocked */ |
| modtronix | 1:71204b8406f2 | 538 | __HAL_UNLOCK(hrtc); |
| modtronix | 1:71204b8406f2 | 539 | |
| modtronix | 1:71204b8406f2 | 540 | return HAL_ERROR; |
| modtronix | 1:71204b8406f2 | 541 | } |
| modtronix | 1:71204b8406f2 | 542 | |
| modtronix | 1:71204b8406f2 | 543 | /* Enable the write protection for RTC registers */ |
| modtronix | 1:71204b8406f2 | 544 | __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc); |
| modtronix | 1:71204b8406f2 | 545 | |
| modtronix | 1:71204b8406f2 | 546 | hrtc->State = HAL_RTC_STATE_READY ; |
| modtronix | 1:71204b8406f2 | 547 | |
| modtronix | 1:71204b8406f2 | 548 | /* Process Unlocked */ |
| modtronix | 1:71204b8406f2 | 549 | __HAL_UNLOCK(hrtc); |
| modtronix | 1:71204b8406f2 | 550 | |
| modtronix | 1:71204b8406f2 | 551 | return HAL_OK; |
| modtronix | 1:71204b8406f2 | 552 | } |
| modtronix | 1:71204b8406f2 | 553 | } |
| modtronix | 1:71204b8406f2 | 554 | |
| modtronix | 1:71204b8406f2 | 555 | /** |
| modtronix | 1:71204b8406f2 | 556 | * @brief Gets RTC current date. |
| modtronix | 1:71204b8406f2 | 557 | * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains |
| modtronix | 1:71204b8406f2 | 558 | * the configuration information for RTC. |
| modtronix | 1:71204b8406f2 | 559 | * @param sDate: Pointer to Date structure |
| modtronix | 1:71204b8406f2 | 560 | * @param Format: Specifies the format of the entered parameters. |
| modtronix | 1:71204b8406f2 | 561 | * This parameter can be one of the following values: |
| modtronix | 10:6444e6c798ce | 562 | * @arg RTC_FORMAT_BIN: Binary data format |
| modtronix | 10:6444e6c798ce | 563 | * @arg RTC_FORMAT_BCD: BCD data format |
| modtronix | 10:6444e6c798ce | 564 | * @note You must call HAL_RTC_GetDate() after HAL_RTC_GetTime() to unlock the values |
| modtronix | 10:6444e6c798ce | 565 | * in the higher-order calendar shadow registers to ensure consistency between the time and date values. |
| modtronix | 10:6444e6c798ce | 566 | * Reading RTC current time locks the values in calendar shadow registers until Current date is read. |
| modtronix | 1:71204b8406f2 | 567 | * @retval HAL status |
| modtronix | 1:71204b8406f2 | 568 | */ |
| modtronix | 1:71204b8406f2 | 569 | HAL_StatusTypeDef HAL_RTC_GetDate(RTC_HandleTypeDef *hrtc, RTC_DateTypeDef *sDate, uint32_t Format) |
| modtronix | 1:71204b8406f2 | 570 | { |
| modtronix | 1:71204b8406f2 | 571 | uint32_t datetmpreg = 0; |
| modtronix | 1:71204b8406f2 | 572 | |
| modtronix | 1:71204b8406f2 | 573 | /* Check the parameters */ |
| modtronix | 1:71204b8406f2 | 574 | assert_param(IS_RTC_FORMAT(Format)); |
| modtronix | 1:71204b8406f2 | 575 | |
| modtronix | 1:71204b8406f2 | 576 | /* Get the DR register */ |
| modtronix | 1:71204b8406f2 | 577 | datetmpreg = (uint32_t)(hrtc->Instance->DR & RTC_DR_RESERVED_MASK); |
| modtronix | 1:71204b8406f2 | 578 | |
| modtronix | 1:71204b8406f2 | 579 | /* Fill the structure fields with the read parameters */ |
| modtronix | 1:71204b8406f2 | 580 | sDate->Year = (uint8_t)((datetmpreg & (RTC_DR_YT | RTC_DR_YU)) >> 16); |
| modtronix | 1:71204b8406f2 | 581 | sDate->Month = (uint8_t)((datetmpreg & (RTC_DR_MT | RTC_DR_MU)) >> 8); |
| modtronix | 1:71204b8406f2 | 582 | sDate->Date = (uint8_t)(datetmpreg & (RTC_DR_DT | RTC_DR_DU)); |
| modtronix | 1:71204b8406f2 | 583 | sDate->WeekDay = (uint8_t)((datetmpreg & (RTC_DR_WDU)) >> 13); |
| modtronix | 1:71204b8406f2 | 584 | |
| modtronix | 1:71204b8406f2 | 585 | /* Check the input parameters format */ |
| modtronix | 10:6444e6c798ce | 586 | if(Format == RTC_FORMAT_BIN) |
| modtronix | 1:71204b8406f2 | 587 | { |
| modtronix | 1:71204b8406f2 | 588 | /* Convert the date structure parameters to Binary format */ |
| modtronix | 1:71204b8406f2 | 589 | sDate->Year = (uint8_t)RTC_Bcd2ToByte(sDate->Year); |
| modtronix | 1:71204b8406f2 | 590 | sDate->Month = (uint8_t)RTC_Bcd2ToByte(sDate->Month); |
| modtronix | 1:71204b8406f2 | 591 | sDate->Date = (uint8_t)RTC_Bcd2ToByte(sDate->Date); |
| modtronix | 1:71204b8406f2 | 592 | } |
| modtronix | 1:71204b8406f2 | 593 | return HAL_OK; |
| modtronix | 1:71204b8406f2 | 594 | } |
| modtronix | 1:71204b8406f2 | 595 | |
| modtronix | 1:71204b8406f2 | 596 | /** |
| modtronix | 1:71204b8406f2 | 597 | * @} |
| modtronix | 1:71204b8406f2 | 598 | */ |
| modtronix | 1:71204b8406f2 | 599 | |
| modtronix | 1:71204b8406f2 | 600 | /** @defgroup RTC_Exported_Functions_Group3 RTC Alarm functions |
| modtronix | 1:71204b8406f2 | 601 | * @brief RTC Alarm functions |
| modtronix | 1:71204b8406f2 | 602 | * |
| modtronix | 1:71204b8406f2 | 603 | @verbatim |
| modtronix | 1:71204b8406f2 | 604 | =============================================================================== |
| modtronix | 1:71204b8406f2 | 605 | ##### RTC Alarm functions ##### |
| modtronix | 1:71204b8406f2 | 606 | =============================================================================== |
| modtronix | 1:71204b8406f2 | 607 | |
| modtronix | 1:71204b8406f2 | 608 | [..] This section provides functions allowing to configure Alarm feature |
| modtronix | 1:71204b8406f2 | 609 | |
| modtronix | 1:71204b8406f2 | 610 | @endverbatim |
| modtronix | 1:71204b8406f2 | 611 | * @{ |
| modtronix | 1:71204b8406f2 | 612 | */ |
| modtronix | 1:71204b8406f2 | 613 | |
| modtronix | 1:71204b8406f2 | 614 | /** |
| modtronix | 1:71204b8406f2 | 615 | * @brief Deactive the specified RTC Alarm |
| modtronix | 1:71204b8406f2 | 616 | * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains |
| modtronix | 1:71204b8406f2 | 617 | * the configuration information for RTC. |
| modtronix | 1:71204b8406f2 | 618 | * @param Alarm: Specifies the Alarm. |
| modtronix | 1:71204b8406f2 | 619 | * This parameter can be one of the following values: |
| modtronix | 1:71204b8406f2 | 620 | * @arg RTC_ALARM_A: AlarmA |
| modtronix | 1:71204b8406f2 | 621 | * @arg RTC_ALARM_B: AlarmB |
| modtronix | 1:71204b8406f2 | 622 | * @retval HAL status |
| modtronix | 1:71204b8406f2 | 623 | */ |
| modtronix | 1:71204b8406f2 | 624 | HAL_StatusTypeDef HAL_RTC_DeactivateAlarm(RTC_HandleTypeDef *hrtc, uint32_t Alarm) |
| modtronix | 1:71204b8406f2 | 625 | { |
| modtronix | 1:71204b8406f2 | 626 | uint32_t tickstart = 0; |
| modtronix | 1:71204b8406f2 | 627 | |
| modtronix | 1:71204b8406f2 | 628 | /* Check the parameters */ |
| modtronix | 10:6444e6c798ce | 629 | assert_param(IS_RTC_ALARM(Alarm)); |
| modtronix | 1:71204b8406f2 | 630 | |
| modtronix | 1:71204b8406f2 | 631 | /* Process Locked */ |
| modtronix | 1:71204b8406f2 | 632 | __HAL_LOCK(hrtc); |
| modtronix | 1:71204b8406f2 | 633 | |
| modtronix | 1:71204b8406f2 | 634 | hrtc->State = HAL_RTC_STATE_BUSY; |
| modtronix | 1:71204b8406f2 | 635 | |
| modtronix | 1:71204b8406f2 | 636 | /* Disable the write protection for RTC registers */ |
| modtronix | 1:71204b8406f2 | 637 | __HAL_RTC_WRITEPROTECTION_DISABLE(hrtc); |
| modtronix | 1:71204b8406f2 | 638 | |
| modtronix | 1:71204b8406f2 | 639 | if(Alarm == RTC_ALARM_A) |
| modtronix | 1:71204b8406f2 | 640 | { |
| modtronix | 1:71204b8406f2 | 641 | /* AlarmA */ |
| modtronix | 1:71204b8406f2 | 642 | __HAL_RTC_ALARMA_DISABLE(hrtc); |
| modtronix | 1:71204b8406f2 | 643 | |
| modtronix | 1:71204b8406f2 | 644 | /* In case of interrupt mode is used, the interrupt source must disabled */ |
| modtronix | 1:71204b8406f2 | 645 | __HAL_RTC_ALARM_DISABLE_IT(hrtc, RTC_IT_ALRA); |
| modtronix | 1:71204b8406f2 | 646 | |
| modtronix | 1:71204b8406f2 | 647 | tickstart = HAL_GetTick(); |
| modtronix | 1:71204b8406f2 | 648 | |
| modtronix | 1:71204b8406f2 | 649 | /* Wait till RTC ALRxWF flag is set and if Time out is reached exit */ |
| modtronix | 1:71204b8406f2 | 650 | while(__HAL_RTC_ALARM_GET_FLAG(hrtc, RTC_FLAG_ALRAWF) == RESET) |
| modtronix | 1:71204b8406f2 | 651 | { |
| modtronix | 1:71204b8406f2 | 652 | if((HAL_GetTick() - tickstart ) > RTC_TIMEOUT_VALUE) |
| modtronix | 1:71204b8406f2 | 653 | { |
| modtronix | 1:71204b8406f2 | 654 | /* Enable the write protection for RTC registers */ |
| modtronix | 1:71204b8406f2 | 655 | __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc); |
| modtronix | 1:71204b8406f2 | 656 | |
| modtronix | 1:71204b8406f2 | 657 | hrtc->State = HAL_RTC_STATE_TIMEOUT; |
| modtronix | 1:71204b8406f2 | 658 | |
| modtronix | 1:71204b8406f2 | 659 | /* Process Unlocked */ |
| modtronix | 1:71204b8406f2 | 660 | __HAL_UNLOCK(hrtc); |
| modtronix | 1:71204b8406f2 | 661 | |
| modtronix | 1:71204b8406f2 | 662 | return HAL_TIMEOUT; |
| modtronix | 1:71204b8406f2 | 663 | } |
| modtronix | 1:71204b8406f2 | 664 | } |
| modtronix | 1:71204b8406f2 | 665 | } |
| modtronix | 1:71204b8406f2 | 666 | else |
| modtronix | 1:71204b8406f2 | 667 | { |
| modtronix | 1:71204b8406f2 | 668 | /* AlarmB */ |
| modtronix | 1:71204b8406f2 | 669 | __HAL_RTC_ALARMB_DISABLE(hrtc); |
| modtronix | 1:71204b8406f2 | 670 | |
| modtronix | 1:71204b8406f2 | 671 | /* In case of interrupt mode is used, the interrupt source must disabled */ |
| modtronix | 1:71204b8406f2 | 672 | __HAL_RTC_ALARM_DISABLE_IT(hrtc,RTC_IT_ALRB); |
| modtronix | 1:71204b8406f2 | 673 | |
| modtronix | 1:71204b8406f2 | 674 | tickstart = HAL_GetTick(); |
| modtronix | 1:71204b8406f2 | 675 | |
| modtronix | 1:71204b8406f2 | 676 | /* Wait till RTC ALRxWF flag is set and if Time out is reached exit */ |
| modtronix | 1:71204b8406f2 | 677 | while(__HAL_RTC_ALARM_GET_FLAG(hrtc, RTC_FLAG_ALRBWF) == RESET) |
| modtronix | 1:71204b8406f2 | 678 | { |
| modtronix | 1:71204b8406f2 | 679 | if((HAL_GetTick() - tickstart ) > RTC_TIMEOUT_VALUE) |
| modtronix | 1:71204b8406f2 | 680 | { |
| modtronix | 1:71204b8406f2 | 681 | /* Enable the write protection for RTC registers */ |
| modtronix | 1:71204b8406f2 | 682 | __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc); |
| modtronix | 1:71204b8406f2 | 683 | |
| modtronix | 1:71204b8406f2 | 684 | hrtc->State = HAL_RTC_STATE_TIMEOUT; |
| modtronix | 1:71204b8406f2 | 685 | |
| modtronix | 1:71204b8406f2 | 686 | /* Process Unlocked */ |
| modtronix | 1:71204b8406f2 | 687 | __HAL_UNLOCK(hrtc); |
| modtronix | 1:71204b8406f2 | 688 | |
| modtronix | 1:71204b8406f2 | 689 | return HAL_TIMEOUT; |
| modtronix | 1:71204b8406f2 | 690 | } |
| modtronix | 1:71204b8406f2 | 691 | } |
| modtronix | 1:71204b8406f2 | 692 | } |
| modtronix | 1:71204b8406f2 | 693 | /* Enable the write protection for RTC registers */ |
| modtronix | 1:71204b8406f2 | 694 | __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc); |
| modtronix | 1:71204b8406f2 | 695 | |
| modtronix | 1:71204b8406f2 | 696 | hrtc->State = HAL_RTC_STATE_READY; |
| modtronix | 1:71204b8406f2 | 697 | |
| modtronix | 1:71204b8406f2 | 698 | /* Process Unlocked */ |
| modtronix | 1:71204b8406f2 | 699 | __HAL_UNLOCK(hrtc); |
| modtronix | 1:71204b8406f2 | 700 | |
| modtronix | 1:71204b8406f2 | 701 | return HAL_OK; |
| modtronix | 1:71204b8406f2 | 702 | } |
| modtronix | 1:71204b8406f2 | 703 | |
| modtronix | 1:71204b8406f2 | 704 | /** |
| modtronix | 1:71204b8406f2 | 705 | * @brief This function handles Alarm interrupt request. |
| modtronix | 1:71204b8406f2 | 706 | * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains |
| modtronix | 1:71204b8406f2 | 707 | * the configuration information for RTC. |
| modtronix | 1:71204b8406f2 | 708 | * @retval None |
| modtronix | 1:71204b8406f2 | 709 | */ |
| modtronix | 1:71204b8406f2 | 710 | void HAL_RTC_AlarmIRQHandler(RTC_HandleTypeDef* hrtc) |
| modtronix | 1:71204b8406f2 | 711 | { |
| modtronix | 1:71204b8406f2 | 712 | if(__HAL_RTC_ALARM_GET_IT(hrtc, RTC_IT_ALRA)) |
| modtronix | 1:71204b8406f2 | 713 | { |
| modtronix | 1:71204b8406f2 | 714 | /* Get the status of the Interrupt */ |
| modtronix | 1:71204b8406f2 | 715 | if((uint32_t)(hrtc->Instance->CR & RTC_IT_ALRA) != (uint32_t)RESET) |
| modtronix | 1:71204b8406f2 | 716 | { |
| modtronix | 1:71204b8406f2 | 717 | /* AlarmA callback */ |
| modtronix | 1:71204b8406f2 | 718 | HAL_RTC_AlarmAEventCallback(hrtc); |
| modtronix | 1:71204b8406f2 | 719 | |
| modtronix | 1:71204b8406f2 | 720 | /* Clear the Alarm interrupt pending bit */ |
| modtronix | 1:71204b8406f2 | 721 | __HAL_RTC_ALARM_CLEAR_FLAG(hrtc,RTC_FLAG_ALRAF); |
| modtronix | 1:71204b8406f2 | 722 | } |
| modtronix | 1:71204b8406f2 | 723 | } |
| modtronix | 1:71204b8406f2 | 724 | |
| modtronix | 1:71204b8406f2 | 725 | if(__HAL_RTC_ALARM_GET_IT(hrtc, RTC_IT_ALRB)) |
| modtronix | 1:71204b8406f2 | 726 | { |
| modtronix | 1:71204b8406f2 | 727 | /* Get the status of the Interrupt */ |
| modtronix | 1:71204b8406f2 | 728 | if((uint32_t)(hrtc->Instance->CR & RTC_IT_ALRB) != (uint32_t)RESET) |
| modtronix | 1:71204b8406f2 | 729 | { |
| modtronix | 1:71204b8406f2 | 730 | /* AlarmB callback */ |
| modtronix | 1:71204b8406f2 | 731 | HAL_RTCEx_AlarmBEventCallback(hrtc); |
| modtronix | 1:71204b8406f2 | 732 | |
| modtronix | 1:71204b8406f2 | 733 | /* Clear the Alarm interrupt pending bit */ |
| modtronix | 1:71204b8406f2 | 734 | __HAL_RTC_ALARM_CLEAR_FLAG(hrtc,RTC_FLAG_ALRBF); |
| modtronix | 1:71204b8406f2 | 735 | } |
| modtronix | 1:71204b8406f2 | 736 | } |
| modtronix | 1:71204b8406f2 | 737 | |
| modtronix | 1:71204b8406f2 | 738 | /* Clear the EXTI's line Flag for RTC Alarm */ |
| modtronix | 10:6444e6c798ce | 739 | __HAL_RTC_ALARM_EXTI_CLEAR_FLAG(); |
| modtronix | 1:71204b8406f2 | 740 | |
| modtronix | 1:71204b8406f2 | 741 | /* Change RTC state */ |
| modtronix | 1:71204b8406f2 | 742 | hrtc->State = HAL_RTC_STATE_READY; |
| modtronix | 1:71204b8406f2 | 743 | } |
| modtronix | 1:71204b8406f2 | 744 | |
| modtronix | 1:71204b8406f2 | 745 | /** |
| modtronix | 1:71204b8406f2 | 746 | * @brief Alarm A callback. |
| modtronix | 1:71204b8406f2 | 747 | * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains |
| modtronix | 1:71204b8406f2 | 748 | * the configuration information for RTC. |
| modtronix | 1:71204b8406f2 | 749 | * @retval None |
| modtronix | 1:71204b8406f2 | 750 | */ |
| modtronix | 1:71204b8406f2 | 751 | __weak void HAL_RTC_AlarmAEventCallback(RTC_HandleTypeDef *hrtc) |
| modtronix | 1:71204b8406f2 | 752 | { |
| modtronix | 1:71204b8406f2 | 753 | /* NOTE : This function Should not be modified, when the callback is needed, |
| modtronix | 1:71204b8406f2 | 754 | the HAL_RTC_AlarmAEventCallback could be implemented in the user file |
| modtronix | 1:71204b8406f2 | 755 | */ |
| modtronix | 1:71204b8406f2 | 756 | } |
| modtronix | 1:71204b8406f2 | 757 | |
| modtronix | 1:71204b8406f2 | 758 | /** |
| modtronix | 1:71204b8406f2 | 759 | * @brief This function handles AlarmA Polling request. |
| modtronix | 1:71204b8406f2 | 760 | * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains |
| modtronix | 1:71204b8406f2 | 761 | * the configuration information for RTC. |
| modtronix | 1:71204b8406f2 | 762 | * @param Timeout: Timeout duration |
| modtronix | 1:71204b8406f2 | 763 | * @retval HAL status |
| modtronix | 1:71204b8406f2 | 764 | */ |
| modtronix | 1:71204b8406f2 | 765 | HAL_StatusTypeDef HAL_RTC_PollForAlarmAEvent(RTC_HandleTypeDef *hrtc, uint32_t Timeout) |
| modtronix | 1:71204b8406f2 | 766 | { |
| modtronix | 1:71204b8406f2 | 767 | |
| modtronix | 1:71204b8406f2 | 768 | uint32_t tickstart = HAL_GetTick(); |
| modtronix | 1:71204b8406f2 | 769 | |
| modtronix | 1:71204b8406f2 | 770 | while(__HAL_RTC_ALARM_GET_FLAG(hrtc, RTC_FLAG_ALRAF) == RESET) |
| modtronix | 1:71204b8406f2 | 771 | { |
| modtronix | 1:71204b8406f2 | 772 | if(Timeout != HAL_MAX_DELAY) |
| modtronix | 1:71204b8406f2 | 773 | { |
| modtronix | 1:71204b8406f2 | 774 | if((Timeout == 0)||((HAL_GetTick() - tickstart ) > Timeout)) |
| modtronix | 1:71204b8406f2 | 775 | { |
| modtronix | 1:71204b8406f2 | 776 | hrtc->State = HAL_RTC_STATE_TIMEOUT; |
| modtronix | 1:71204b8406f2 | 777 | return HAL_TIMEOUT; |
| modtronix | 1:71204b8406f2 | 778 | } |
| modtronix | 1:71204b8406f2 | 779 | } |
| modtronix | 1:71204b8406f2 | 780 | } |
| modtronix | 1:71204b8406f2 | 781 | |
| modtronix | 1:71204b8406f2 | 782 | /* Clear the Alarm interrupt pending bit */ |
| modtronix | 1:71204b8406f2 | 783 | __HAL_RTC_ALARM_CLEAR_FLAG(hrtc, RTC_FLAG_ALRAF); |
| modtronix | 1:71204b8406f2 | 784 | |
| modtronix | 1:71204b8406f2 | 785 | /* Change RTC state */ |
| modtronix | 1:71204b8406f2 | 786 | hrtc->State = HAL_RTC_STATE_READY; |
| modtronix | 1:71204b8406f2 | 787 | |
| modtronix | 1:71204b8406f2 | 788 | return HAL_OK; |
| modtronix | 1:71204b8406f2 | 789 | } |
| modtronix | 1:71204b8406f2 | 790 | |
| modtronix | 1:71204b8406f2 | 791 | /** |
| modtronix | 1:71204b8406f2 | 792 | * @} |
| modtronix | 1:71204b8406f2 | 793 | */ |
| modtronix | 1:71204b8406f2 | 794 | |
| modtronix | 1:71204b8406f2 | 795 | /** @defgroup RTC_Exported_Functions_Group5 Peripheral State functions |
| modtronix | 1:71204b8406f2 | 796 | * @brief Peripheral State functions |
| modtronix | 1:71204b8406f2 | 797 | * |
| modtronix | 1:71204b8406f2 | 798 | @verbatim |
| modtronix | 1:71204b8406f2 | 799 | =============================================================================== |
| modtronix | 1:71204b8406f2 | 800 | ##### Peripheral State functions ##### |
| modtronix | 1:71204b8406f2 | 801 | =============================================================================== |
| modtronix | 1:71204b8406f2 | 802 | [..] |
| modtronix | 1:71204b8406f2 | 803 | This subsection provides functions allowing to |
| modtronix | 1:71204b8406f2 | 804 | (+) Get RTC state |
| modtronix | 1:71204b8406f2 | 805 | |
| modtronix | 1:71204b8406f2 | 806 | @endverbatim |
| modtronix | 1:71204b8406f2 | 807 | * @{ |
| modtronix | 1:71204b8406f2 | 808 | */ |
| modtronix | 1:71204b8406f2 | 809 | /** |
| modtronix | 1:71204b8406f2 | 810 | * @brief Returns the RTC state. |
| modtronix | 1:71204b8406f2 | 811 | * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains |
| modtronix | 1:71204b8406f2 | 812 | * the configuration information for RTC. |
| modtronix | 1:71204b8406f2 | 813 | * @retval HAL state |
| modtronix | 1:71204b8406f2 | 814 | */ |
| modtronix | 1:71204b8406f2 | 815 | HAL_RTCStateTypeDef HAL_RTC_GetState(RTC_HandleTypeDef* hrtc) |
| modtronix | 1:71204b8406f2 | 816 | { |
| modtronix | 1:71204b8406f2 | 817 | return hrtc->State; |
| modtronix | 1:71204b8406f2 | 818 | } |
| modtronix | 1:71204b8406f2 | 819 | |
| modtronix | 1:71204b8406f2 | 820 | /** |
| modtronix | 1:71204b8406f2 | 821 | * @} |
| modtronix | 1:71204b8406f2 | 822 | */ |
| modtronix | 1:71204b8406f2 | 823 | |
| modtronix | 1:71204b8406f2 | 824 | /** |
| modtronix | 1:71204b8406f2 | 825 | * @} |
| modtronix | 1:71204b8406f2 | 826 | */ |
| modtronix | 1:71204b8406f2 | 827 | |
| modtronix | 1:71204b8406f2 | 828 | /** @defgroup RTC_Internal_Functions RTC Internal function |
| modtronix | 1:71204b8406f2 | 829 | * @{ |
| modtronix | 1:71204b8406f2 | 830 | */ |
| modtronix | 1:71204b8406f2 | 831 | |
| modtronix | 1:71204b8406f2 | 832 | /** |
| modtronix | 1:71204b8406f2 | 833 | * @brief Enters the RTC Initialization mode. |
| modtronix | 1:71204b8406f2 | 834 | * @note The RTC Initialization mode is write protected, use the |
| modtronix | 1:71204b8406f2 | 835 | * __HAL_RTC_WRITEPROTECTION_DISABLE() before calling this function. |
| modtronix | 1:71204b8406f2 | 836 | * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains |
| modtronix | 1:71204b8406f2 | 837 | * the configuration information for RTC. |
| modtronix | 1:71204b8406f2 | 838 | * @retval HAL status |
| modtronix | 1:71204b8406f2 | 839 | */ |
| modtronix | 1:71204b8406f2 | 840 | HAL_StatusTypeDef RTC_EnterInitMode(RTC_HandleTypeDef* hrtc) |
| modtronix | 1:71204b8406f2 | 841 | { |
| modtronix | 1:71204b8406f2 | 842 | uint32_t tickstart = 0; |
| modtronix | 1:71204b8406f2 | 843 | |
| modtronix | 1:71204b8406f2 | 844 | /* Check if the Initialization mode is set */ |
| modtronix | 1:71204b8406f2 | 845 | if((hrtc->Instance->ISR & RTC_ISR_INITF) == (uint32_t)RESET) |
| modtronix | 1:71204b8406f2 | 846 | { |
| modtronix | 1:71204b8406f2 | 847 | /* Set the Initialization mode */ |
| modtronix | 1:71204b8406f2 | 848 | hrtc->Instance->ISR = (uint32_t)RTC_INIT_MASK; |
| modtronix | 1:71204b8406f2 | 849 | |
| modtronix | 1:71204b8406f2 | 850 | tickstart = HAL_GetTick(); |
| modtronix | 1:71204b8406f2 | 851 | /* Wait till RTC is in INIT state and if Time out is reached exit */ |
| modtronix | 1:71204b8406f2 | 852 | while((hrtc->Instance->ISR & RTC_ISR_INITF) == (uint32_t)RESET) |
| modtronix | 1:71204b8406f2 | 853 | { |
| modtronix | 1:71204b8406f2 | 854 | if((HAL_GetTick() - tickstart) > RTC_TIMEOUT_VALUE) |
| modtronix | 1:71204b8406f2 | 855 | { |
| modtronix | 1:71204b8406f2 | 856 | return HAL_TIMEOUT; |
| modtronix | 1:71204b8406f2 | 857 | } |
| modtronix | 1:71204b8406f2 | 858 | } |
| modtronix | 1:71204b8406f2 | 859 | } |
| modtronix | 1:71204b8406f2 | 860 | |
| modtronix | 1:71204b8406f2 | 861 | return HAL_OK; |
| modtronix | 1:71204b8406f2 | 862 | } |
| modtronix | 1:71204b8406f2 | 863 | |
| modtronix | 1:71204b8406f2 | 864 | /** |
| modtronix | 1:71204b8406f2 | 865 | * @brief Converts a 2 digit decimal to BCD format. |
| modtronix | 1:71204b8406f2 | 866 | * @param Value: Byte to be converted |
| modtronix | 1:71204b8406f2 | 867 | * @retval Converted byte |
| modtronix | 1:71204b8406f2 | 868 | */ |
| modtronix | 1:71204b8406f2 | 869 | uint8_t RTC_ByteToBcd2(uint8_t Value) |
| modtronix | 1:71204b8406f2 | 870 | { |
| modtronix | 1:71204b8406f2 | 871 | uint32_t bcdhigh = 0; |
| modtronix | 1:71204b8406f2 | 872 | |
| modtronix | 1:71204b8406f2 | 873 | while(Value >= 10) |
| modtronix | 1:71204b8406f2 | 874 | { |
| modtronix | 1:71204b8406f2 | 875 | bcdhigh++; |
| modtronix | 1:71204b8406f2 | 876 | Value -= 10; |
| modtronix | 1:71204b8406f2 | 877 | } |
| modtronix | 1:71204b8406f2 | 878 | |
| modtronix | 1:71204b8406f2 | 879 | return ((uint8_t)(bcdhigh << 4) | Value); |
| modtronix | 1:71204b8406f2 | 880 | } |
| modtronix | 1:71204b8406f2 | 881 | |
| modtronix | 1:71204b8406f2 | 882 | /** |
| modtronix | 1:71204b8406f2 | 883 | * @brief Converts from 2 digit BCD to Binary. |
| modtronix | 1:71204b8406f2 | 884 | * @param Value: BCD value to be converted |
| modtronix | 1:71204b8406f2 | 885 | * @retval Converted word |
| modtronix | 1:71204b8406f2 | 886 | */ |
| modtronix | 1:71204b8406f2 | 887 | uint8_t RTC_Bcd2ToByte(uint8_t Value) |
| modtronix | 1:71204b8406f2 | 888 | { |
| modtronix | 1:71204b8406f2 | 889 | uint32_t tmp = 0; |
| modtronix | 1:71204b8406f2 | 890 | tmp = ((uint8_t)(Value & (uint8_t)0xF0) >> (uint8_t)0x4) * 10; |
| modtronix | 1:71204b8406f2 | 891 | return (tmp + (Value & (uint8_t)0x0F)); |
| modtronix | 1:71204b8406f2 | 892 | } |
| modtronix | 1:71204b8406f2 | 893 | |
| modtronix | 1:71204b8406f2 | 894 | |
| modtronix | 1:71204b8406f2 | 895 | /** |
| modtronix | 1:71204b8406f2 | 896 | * @} |
| modtronix | 1:71204b8406f2 | 897 | */ |
| modtronix | 1:71204b8406f2 | 898 | |
| modtronix | 1:71204b8406f2 | 899 | #endif /* HAL_RTC_MODULE_ENABLED */ |
| modtronix | 1:71204b8406f2 | 900 | /** |
| modtronix | 1:71204b8406f2 | 901 | * @} |
| modtronix | 1:71204b8406f2 | 902 | */ |
| modtronix | 1:71204b8406f2 | 903 | |
| modtronix | 1:71204b8406f2 | 904 | /** |
| modtronix | 1:71204b8406f2 | 905 | * @} |
| modtronix | 1:71204b8406f2 | 906 | */ |
| modtronix | 1:71204b8406f2 | 907 | |
| modtronix | 1:71204b8406f2 | 908 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ |