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