mbed library sources

Fork of mbed-src by mbed official

Committer:
mbed_official
Date:
Mon Nov 03 10:15:07 2014 +0000
Revision:
380:510f0c3515e3
Parent:
targets/cmsis/TARGET_STM/TARGET_NUCLEO_F411RE/stm32f4xx_hal_rtc.c@352:95e80f5e68f6
Child:
532:fe11edbda85c
Synchronized with git revision 417f470ba9f4882d7079611cbc576afd9c49b0ef

Full URL: https://github.com/mbedmicro/mbed/commit/417f470ba9f4882d7079611cbc576afd9c49b0ef/

Targets: Factorisation of NUCLEO_F401RE and F411RE cmsis folders

Who changed what in which revision?

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