mbed library sources

Dependents:   frdm_kl05z_gpio_test

Fork of mbed-src by mbed official

Committer:
mbed_official
Date:
Fri Jun 27 07:30:09 2014 +0100
Revision:
242:7074e42da0b2
Parent:
133:d4dda5c437f0
Synchronized with git revision 124ef5e3add9e74a3221347a3fbeea7c8b3cf353

Full URL: https://github.com/mbedmicro/mbed/commit/124ef5e3add9e74a3221347a3fbeea7c8b3cf353/

[DISCO_F407VG] HAL update.

Who changed what in which revision?

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