mbed library sources

Dependents:   Encrypted my_mbed lklk CyaSSL_DTLS_Cellular ... more

Superseded

This library was superseded by mbed-dev - https://os.mbed.com/users/mbed_official/code/mbed-dev/.

Development branch of the mbed library sources. This library is kept in synch with the latest changes from the mbed SDK and it is not guaranteed to work.

If you are looking for a stable and tested release, please import one of the official mbed library releases:

Import librarymbed

The official Mbed 2 C/C++ SDK provides the software platform and libraries to build your applications.

Committer:
mbed_official
Date:
Thu Jul 02 16:30:08 2015 +0100
Revision:
581:39197bcd20f2
Parent:
532:fe11edbda85c
Child:
613:bc40b8d2aec4
Synchronized with git revision ae2d3cdffe70184eb8736d94f76c45c93f4b7724

Full URL: https://github.com/mbedmicro/mbed/commit/ae2d3cdffe70184eb8736d94f76c45c93f4b7724/

Make it possible to build the core mbed library with yotta

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 532:fe11edbda85c 5 * @version V1.3.0
mbed_official 532:fe11edbda85c 6 * @date 09-March-2015
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 532:fe11edbda85c 64 __HAL_RCC_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 532:fe11edbda85c 96 RTC wake-up, 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 532:fe11edbda85c 100 on an external interrupt (Auto-wake-up mode), by using the RTC alarm
mbed_official 532:fe11edbda85c 101 or the RTC wake-up 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 532:fe11edbda85c 104 Wake-up 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 532:fe11edbda85c 111 * <h2><center>&copy; COPYRIGHT(c) 2015 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 532:fe11edbda85c 145 /** @defgroup RTC 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 532:fe11edbda85c 159 /** @defgroup RTC_Exported_Functions RTC Exported Functions
mbed_official 235:685d5f11838f 160 * @{
mbed_official 235:685d5f11838f 161 */
mbed_official 235:685d5f11838f 162
mbed_official 532:fe11edbda85c 163 /** @defgroup RTC_Exported_Functions_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 532:fe11edbda85c 186 initialization, calendar update or after wake-up 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 532:fe11edbda85c 221 /* Allocate lock resource and initialize it */
mbed_official 532:fe11edbda85c 222 hrtc->Lock = HAL_UNLOCKED;
mbed_official 235:685d5f11838f 223 /* Initialize RTC MSP */
mbed_official 235:685d5f11838f 224 HAL_RTC_MspInit(hrtc);
mbed_official 235:685d5f11838f 225 }
mbed_official 235:685d5f11838f 226
mbed_official 235:685d5f11838f 227 /* Set RTC state */
mbed_official 235:685d5f11838f 228 hrtc->State = HAL_RTC_STATE_BUSY;
mbed_official 235:685d5f11838f 229
mbed_official 235:685d5f11838f 230 /* Disable the write protection for RTC registers */
mbed_official 235:685d5f11838f 231 __HAL_RTC_WRITEPROTECTION_DISABLE(hrtc);
mbed_official 235:685d5f11838f 232
mbed_official 235:685d5f11838f 233 /* Set Initialization mode */
mbed_official 235:685d5f11838f 234 if(RTC_EnterInitMode(hrtc) != HAL_OK)
mbed_official 235:685d5f11838f 235 {
mbed_official 235:685d5f11838f 236 /* Enable the write protection for RTC registers */
mbed_official 235:685d5f11838f 237 __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc);
mbed_official 235:685d5f11838f 238
mbed_official 235:685d5f11838f 239 /* Set RTC state */
mbed_official 235:685d5f11838f 240 hrtc->State = HAL_RTC_STATE_ERROR;
mbed_official 235:685d5f11838f 241
mbed_official 235:685d5f11838f 242 return HAL_ERROR;
mbed_official 235:685d5f11838f 243 }
mbed_official 235:685d5f11838f 244 else
mbed_official 235:685d5f11838f 245 {
mbed_official 235:685d5f11838f 246 /* Clear RTC_CR FMT, OSEL and POL Bits */
mbed_official 235:685d5f11838f 247 hrtc->Instance->CR &= ((uint32_t)~(RTC_CR_FMT | RTC_CR_OSEL | RTC_CR_POL));
mbed_official 235:685d5f11838f 248 /* Set RTC_CR register */
mbed_official 235:685d5f11838f 249 hrtc->Instance->CR |= (uint32_t)(hrtc->Init.HourFormat | hrtc->Init.OutPut | hrtc->Init.OutPutPolarity);
mbed_official 235:685d5f11838f 250
mbed_official 235:685d5f11838f 251 /* Configure the RTC PRER */
mbed_official 235:685d5f11838f 252 hrtc->Instance->PRER = (uint32_t)(hrtc->Init.SynchPrediv);
mbed_official 235:685d5f11838f 253 hrtc->Instance->PRER |= (uint32_t)(hrtc->Init.AsynchPrediv << 16);
mbed_official 235:685d5f11838f 254
mbed_official 235:685d5f11838f 255 /* Exit Initialization mode */
mbed_official 235:685d5f11838f 256 hrtc->Instance->ISR &= (uint32_t)~RTC_ISR_INIT;
mbed_official 235:685d5f11838f 257
mbed_official 235:685d5f11838f 258 hrtc->Instance->TAFCR &= (uint32_t)~RTC_TAFCR_ALARMOUTTYPE;
mbed_official 235:685d5f11838f 259 hrtc->Instance->TAFCR |= (uint32_t)(hrtc->Init.OutPutType);
mbed_official 235:685d5f11838f 260
mbed_official 235:685d5f11838f 261 /* Enable the write protection for RTC registers */
mbed_official 235:685d5f11838f 262 __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc);
mbed_official 235:685d5f11838f 263
mbed_official 235:685d5f11838f 264 /* Set RTC state */
mbed_official 235:685d5f11838f 265 hrtc->State = HAL_RTC_STATE_READY;
mbed_official 235:685d5f11838f 266
mbed_official 235:685d5f11838f 267 return HAL_OK;
mbed_official 235:685d5f11838f 268 }
mbed_official 235:685d5f11838f 269 }
mbed_official 235:685d5f11838f 270
mbed_official 235:685d5f11838f 271 /**
mbed_official 235:685d5f11838f 272 * @brief DeInitializes the RTC peripheral
mbed_official 235:685d5f11838f 273 * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains
mbed_official 235:685d5f11838f 274 * the configuration information for RTC.
mbed_official 235:685d5f11838f 275 * @note This function doesn't reset the RTC Backup Data registers.
mbed_official 235:685d5f11838f 276 * @retval HAL status
mbed_official 235:685d5f11838f 277 */
mbed_official 235:685d5f11838f 278 HAL_StatusTypeDef HAL_RTC_DeInit(RTC_HandleTypeDef *hrtc)
mbed_official 235:685d5f11838f 279 {
mbed_official 235:685d5f11838f 280 uint32_t tickstart = 0;
mbed_official 235:685d5f11838f 281
mbed_official 235:685d5f11838f 282 /* Set RTC state */
mbed_official 235:685d5f11838f 283 hrtc->State = HAL_RTC_STATE_BUSY;
mbed_official 235:685d5f11838f 284
mbed_official 235:685d5f11838f 285 /* Disable the write protection for RTC registers */
mbed_official 235:685d5f11838f 286 __HAL_RTC_WRITEPROTECTION_DISABLE(hrtc);
mbed_official 235:685d5f11838f 287
mbed_official 235:685d5f11838f 288 /* Set Initialization mode */
mbed_official 235:685d5f11838f 289 if(RTC_EnterInitMode(hrtc) != HAL_OK)
mbed_official 235:685d5f11838f 290 {
mbed_official 235:685d5f11838f 291 /* Enable the write protection for RTC registers */
mbed_official 235:685d5f11838f 292 __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc);
mbed_official 235:685d5f11838f 293
mbed_official 235:685d5f11838f 294 /* Set RTC state */
mbed_official 235:685d5f11838f 295 hrtc->State = HAL_RTC_STATE_ERROR;
mbed_official 235:685d5f11838f 296
mbed_official 235:685d5f11838f 297 return HAL_ERROR;
mbed_official 235:685d5f11838f 298 }
mbed_official 235:685d5f11838f 299 else
mbed_official 235:685d5f11838f 300 {
mbed_official 235:685d5f11838f 301 /* Reset TR, DR and CR registers */
mbed_official 235:685d5f11838f 302 hrtc->Instance->TR = (uint32_t)0x00000000;
mbed_official 235:685d5f11838f 303 hrtc->Instance->DR = (uint32_t)0x00002101;
mbed_official 235:685d5f11838f 304 /* Reset All CR bits except CR[2:0] */
mbed_official 235:685d5f11838f 305 hrtc->Instance->CR &= (uint32_t)0x00000007;
mbed_official 235:685d5f11838f 306
mbed_official 235:685d5f11838f 307 /* Get tick */
mbed_official 235:685d5f11838f 308 tickstart = HAL_GetTick();
mbed_official 235:685d5f11838f 309
mbed_official 235:685d5f11838f 310 /* Wait till WUTWF flag is set and if Time out is reached exit */
mbed_official 235:685d5f11838f 311 while(((hrtc->Instance->ISR) & RTC_ISR_WUTWF) == (uint32_t)RESET)
mbed_official 235:685d5f11838f 312 {
mbed_official 235:685d5f11838f 313 if((HAL_GetTick() - tickstart ) > RTC_TIMEOUT_VALUE)
mbed_official 235:685d5f11838f 314 {
mbed_official 235:685d5f11838f 315 /* Enable the write protection for RTC registers */
mbed_official 235:685d5f11838f 316 __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc);
mbed_official 235:685d5f11838f 317
mbed_official 235:685d5f11838f 318 /* Set RTC state */
mbed_official 235:685d5f11838f 319 hrtc->State = HAL_RTC_STATE_TIMEOUT;
mbed_official 235:685d5f11838f 320
mbed_official 235:685d5f11838f 321 return HAL_TIMEOUT;
mbed_official 235:685d5f11838f 322 }
mbed_official 235:685d5f11838f 323 }
mbed_official 235:685d5f11838f 324
mbed_official 235:685d5f11838f 325 /* Reset all RTC CR register bits */
mbed_official 235:685d5f11838f 326 hrtc->Instance->CR &= (uint32_t)0x00000000;
mbed_official 235:685d5f11838f 327 hrtc->Instance->WUTR = (uint32_t)0x0000FFFF;
mbed_official 235:685d5f11838f 328 hrtc->Instance->PRER = (uint32_t)0x007F00FF;
mbed_official 235:685d5f11838f 329 hrtc->Instance->CALIBR = (uint32_t)0x00000000;
mbed_official 235:685d5f11838f 330 hrtc->Instance->ALRMAR = (uint32_t)0x00000000;
mbed_official 235:685d5f11838f 331 hrtc->Instance->ALRMBR = (uint32_t)0x00000000;
mbed_official 235:685d5f11838f 332 hrtc->Instance->SHIFTR = (uint32_t)0x00000000;
mbed_official 235:685d5f11838f 333 hrtc->Instance->CALR = (uint32_t)0x00000000;
mbed_official 235:685d5f11838f 334 hrtc->Instance->ALRMASSR = (uint32_t)0x00000000;
mbed_official 235:685d5f11838f 335 hrtc->Instance->ALRMBSSR = (uint32_t)0x00000000;
mbed_official 235:685d5f11838f 336
mbed_official 235:685d5f11838f 337 /* Reset ISR register and exit initialization mode */
mbed_official 235:685d5f11838f 338 hrtc->Instance->ISR = (uint32_t)0x00000000;
mbed_official 235:685d5f11838f 339
mbed_official 235:685d5f11838f 340 /* Reset Tamper and alternate functions configuration register */
mbed_official 235:685d5f11838f 341 hrtc->Instance->TAFCR = 0x00000000;
mbed_official 235:685d5f11838f 342
mbed_official 235:685d5f11838f 343 /* If RTC_CR_BYPSHAD bit = 0, wait for synchro else this check is not needed */
mbed_official 235:685d5f11838f 344 if((hrtc->Instance->CR & RTC_CR_BYPSHAD) == RESET)
mbed_official 235:685d5f11838f 345 {
mbed_official 235:685d5f11838f 346 if(HAL_RTC_WaitForSynchro(hrtc) != HAL_OK)
mbed_official 235:685d5f11838f 347 {
mbed_official 235:685d5f11838f 348 /* Enable the write protection for RTC registers */
mbed_official 235:685d5f11838f 349 __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc);
mbed_official 235:685d5f11838f 350
mbed_official 235:685d5f11838f 351 hrtc->State = HAL_RTC_STATE_ERROR;
mbed_official 235:685d5f11838f 352
mbed_official 235:685d5f11838f 353 return HAL_ERROR;
mbed_official 235:685d5f11838f 354 }
mbed_official 235:685d5f11838f 355 }
mbed_official 235:685d5f11838f 356 }
mbed_official 235:685d5f11838f 357
mbed_official 235:685d5f11838f 358 /* Enable the write protection for RTC registers */
mbed_official 235:685d5f11838f 359 __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc);
mbed_official 235:685d5f11838f 360
mbed_official 235:685d5f11838f 361 /* De-Initialize RTC MSP */
mbed_official 235:685d5f11838f 362 HAL_RTC_MspDeInit(hrtc);
mbed_official 235:685d5f11838f 363
mbed_official 235:685d5f11838f 364 hrtc->State = HAL_RTC_STATE_RESET;
mbed_official 235:685d5f11838f 365
mbed_official 235:685d5f11838f 366 /* Release Lock */
mbed_official 235:685d5f11838f 367 __HAL_UNLOCK(hrtc);
mbed_official 235:685d5f11838f 368
mbed_official 235:685d5f11838f 369 return HAL_OK;
mbed_official 235:685d5f11838f 370 }
mbed_official 235:685d5f11838f 371
mbed_official 235:685d5f11838f 372 /**
mbed_official 235:685d5f11838f 373 * @brief Initializes the RTC MSP.
mbed_official 235:685d5f11838f 374 * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains
mbed_official 235:685d5f11838f 375 * the configuration information for RTC.
mbed_official 235:685d5f11838f 376 * @retval None
mbed_official 235:685d5f11838f 377 */
mbed_official 235:685d5f11838f 378 __weak void HAL_RTC_MspInit(RTC_HandleTypeDef* hrtc)
mbed_official 235:685d5f11838f 379 {
mbed_official 235:685d5f11838f 380 /* NOTE : This function Should not be modified, when the callback is needed,
mbed_official 532:fe11edbda85c 381 the HAL_RTC_MspInit could be implemented in the user file
mbed_official 235:685d5f11838f 382 */
mbed_official 235:685d5f11838f 383 }
mbed_official 235:685d5f11838f 384
mbed_official 235:685d5f11838f 385 /**
mbed_official 235:685d5f11838f 386 * @brief DeInitializes the RTC MSP.
mbed_official 235:685d5f11838f 387 * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains
mbed_official 235:685d5f11838f 388 * the configuration information for RTC.
mbed_official 235:685d5f11838f 389 * @retval None
mbed_official 235:685d5f11838f 390 */
mbed_official 235:685d5f11838f 391 __weak void HAL_RTC_MspDeInit(RTC_HandleTypeDef* hrtc)
mbed_official 235:685d5f11838f 392 {
mbed_official 235:685d5f11838f 393 /* NOTE : This function Should not be modified, when the callback is needed,
mbed_official 532:fe11edbda85c 394 the HAL_RTC_MspDeInit could be implemented in the user file
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 */
mbed_official 235:685d5f11838f 401
mbed_official 532:fe11edbda85c 402 /** @defgroup RTC_Exported_Functions_Group2 RTC Time and Date functions
mbed_official 235:685d5f11838f 403 * @brief RTC Time and Date functions
mbed_official 235:685d5f11838f 404 *
mbed_official 235:685d5f11838f 405 @verbatim
mbed_official 235:685d5f11838f 406 ===============================================================================
mbed_official 235:685d5f11838f 407 ##### RTC Time and Date functions #####
mbed_official 235:685d5f11838f 408 ===============================================================================
mbed_official 235:685d5f11838f 409
mbed_official 235:685d5f11838f 410 [..] This section provides functions allowing to configure Time and Date features
mbed_official 235:685d5f11838f 411
mbed_official 235:685d5f11838f 412 @endverbatim
mbed_official 235:685d5f11838f 413 * @{
mbed_official 235:685d5f11838f 414 */
mbed_official 235:685d5f11838f 415
mbed_official 235:685d5f11838f 416 /**
mbed_official 235:685d5f11838f 417 * @brief Sets RTC current time.
mbed_official 235:685d5f11838f 418 * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains
mbed_official 235:685d5f11838f 419 * the configuration information for RTC.
mbed_official 235:685d5f11838f 420 * @param sTime: Pointer to Time structure
mbed_official 235:685d5f11838f 421 * @param Format: Specifies the format of the entered parameters.
mbed_official 235:685d5f11838f 422 * This parameter can be one of the following values:
mbed_official 532:fe11edbda85c 423 * @arg RTC_FORMAT_BIN: Binary data format
mbed_official 532:fe11edbda85c 424 * @arg RTC_FORMAT_BCD: BCD data format
mbed_official 235:685d5f11838f 425 * @retval HAL status
mbed_official 235:685d5f11838f 426 */
mbed_official 235:685d5f11838f 427 HAL_StatusTypeDef HAL_RTC_SetTime(RTC_HandleTypeDef *hrtc, RTC_TimeTypeDef *sTime, uint32_t Format)
mbed_official 235:685d5f11838f 428 {
mbed_official 235:685d5f11838f 429 uint32_t tmpreg = 0;
mbed_official 235:685d5f11838f 430
mbed_official 235:685d5f11838f 431 /* Check the parameters */
mbed_official 235:685d5f11838f 432 assert_param(IS_RTC_FORMAT(Format));
mbed_official 235:685d5f11838f 433 assert_param(IS_RTC_DAYLIGHT_SAVING(sTime->DayLightSaving));
mbed_official 235:685d5f11838f 434 assert_param(IS_RTC_STORE_OPERATION(sTime->StoreOperation));
mbed_official 235:685d5f11838f 435
mbed_official 235:685d5f11838f 436 /* Process Locked */
mbed_official 235:685d5f11838f 437 __HAL_LOCK(hrtc);
mbed_official 235:685d5f11838f 438
mbed_official 235:685d5f11838f 439 hrtc->State = HAL_RTC_STATE_BUSY;
mbed_official 235:685d5f11838f 440
mbed_official 532:fe11edbda85c 441 if(Format == RTC_FORMAT_BIN)
mbed_official 235:685d5f11838f 442 {
mbed_official 235:685d5f11838f 443 if((hrtc->Instance->CR & RTC_CR_FMT) != (uint32_t)RESET)
mbed_official 235:685d5f11838f 444 {
mbed_official 235:685d5f11838f 445 assert_param(IS_RTC_HOUR12(sTime->Hours));
mbed_official 235:685d5f11838f 446 assert_param(IS_RTC_HOURFORMAT12(sTime->TimeFormat));
mbed_official 235:685d5f11838f 447 }
mbed_official 235:685d5f11838f 448 else
mbed_official 235:685d5f11838f 449 {
mbed_official 235:685d5f11838f 450 sTime->TimeFormat = 0x00;
mbed_official 235:685d5f11838f 451 assert_param(IS_RTC_HOUR24(sTime->Hours));
mbed_official 235:685d5f11838f 452 }
mbed_official 235:685d5f11838f 453 assert_param(IS_RTC_MINUTES(sTime->Minutes));
mbed_official 235:685d5f11838f 454 assert_param(IS_RTC_SECONDS(sTime->Seconds));
mbed_official 235:685d5f11838f 455
mbed_official 235:685d5f11838f 456 tmpreg = (uint32_t)(((uint32_t)RTC_ByteToBcd2(sTime->Hours) << 16) | \
mbed_official 235:685d5f11838f 457 ((uint32_t)RTC_ByteToBcd2(sTime->Minutes) << 8) | \
mbed_official 235:685d5f11838f 458 ((uint32_t)RTC_ByteToBcd2(sTime->Seconds)) | \
mbed_official 235:685d5f11838f 459 (((uint32_t)sTime->TimeFormat) << 16));
mbed_official 235:685d5f11838f 460 }
mbed_official 235:685d5f11838f 461 else
mbed_official 235:685d5f11838f 462 {
mbed_official 235:685d5f11838f 463 if((hrtc->Instance->CR & RTC_CR_FMT) != (uint32_t)RESET)
mbed_official 235:685d5f11838f 464 {
mbed_official 235:685d5f11838f 465 tmpreg = RTC_Bcd2ToByte(sTime->Hours);
mbed_official 235:685d5f11838f 466 assert_param(IS_RTC_HOUR12(tmpreg));
mbed_official 235:685d5f11838f 467 assert_param(IS_RTC_HOURFORMAT12(sTime->TimeFormat));
mbed_official 235:685d5f11838f 468 }
mbed_official 235:685d5f11838f 469 else
mbed_official 235:685d5f11838f 470 {
mbed_official 235:685d5f11838f 471 sTime->TimeFormat = 0x00;
mbed_official 235:685d5f11838f 472 assert_param(IS_RTC_HOUR24(RTC_Bcd2ToByte(sTime->Hours)));
mbed_official 235:685d5f11838f 473 }
mbed_official 235:685d5f11838f 474 assert_param(IS_RTC_MINUTES(RTC_Bcd2ToByte(sTime->Minutes)));
mbed_official 235:685d5f11838f 475 assert_param(IS_RTC_SECONDS(RTC_Bcd2ToByte(sTime->Seconds)));
mbed_official 235:685d5f11838f 476 tmpreg = (((uint32_t)(sTime->Hours) << 16) | \
mbed_official 235:685d5f11838f 477 ((uint32_t)(sTime->Minutes) << 8) | \
mbed_official 235:685d5f11838f 478 ((uint32_t)sTime->Seconds) | \
mbed_official 235:685d5f11838f 479 ((uint32_t)(sTime->TimeFormat) << 16));
mbed_official 235:685d5f11838f 480 }
mbed_official 235:685d5f11838f 481
mbed_official 235:685d5f11838f 482 /* Disable the write protection for RTC registers */
mbed_official 235:685d5f11838f 483 __HAL_RTC_WRITEPROTECTION_DISABLE(hrtc);
mbed_official 235:685d5f11838f 484
mbed_official 235:685d5f11838f 485 /* Set Initialization mode */
mbed_official 235:685d5f11838f 486 if(RTC_EnterInitMode(hrtc) != HAL_OK)
mbed_official 235:685d5f11838f 487 {
mbed_official 235:685d5f11838f 488 /* Enable the write protection for RTC registers */
mbed_official 235:685d5f11838f 489 __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc);
mbed_official 235:685d5f11838f 490
mbed_official 235:685d5f11838f 491 /* Set RTC state */
mbed_official 235:685d5f11838f 492 hrtc->State = HAL_RTC_STATE_ERROR;
mbed_official 235:685d5f11838f 493
mbed_official 235:685d5f11838f 494 /* Process Unlocked */
mbed_official 235:685d5f11838f 495 __HAL_UNLOCK(hrtc);
mbed_official 235:685d5f11838f 496
mbed_official 235:685d5f11838f 497 return HAL_ERROR;
mbed_official 235:685d5f11838f 498 }
mbed_official 235:685d5f11838f 499 else
mbed_official 235:685d5f11838f 500 {
mbed_official 235:685d5f11838f 501 /* Set the RTC_TR register */
mbed_official 235:685d5f11838f 502 hrtc->Instance->TR = (uint32_t)(tmpreg & RTC_TR_RESERVED_MASK);
mbed_official 235:685d5f11838f 503
mbed_official 235:685d5f11838f 504 /* Clear the bits to be configured */
mbed_official 235:685d5f11838f 505 hrtc->Instance->CR &= (uint32_t)~RTC_CR_BCK;
mbed_official 235:685d5f11838f 506
mbed_official 235:685d5f11838f 507 /* Configure the RTC_CR register */
mbed_official 235:685d5f11838f 508 hrtc->Instance->CR |= (uint32_t)(sTime->DayLightSaving | sTime->StoreOperation);
mbed_official 235:685d5f11838f 509
mbed_official 235:685d5f11838f 510 /* Exit Initialization mode */
mbed_official 235:685d5f11838f 511 hrtc->Instance->ISR &= (uint32_t)~RTC_ISR_INIT;
mbed_official 235:685d5f11838f 512
mbed_official 235:685d5f11838f 513 /* If CR_BYPSHAD bit = 0, wait for synchro else this check is not needed */
mbed_official 235:685d5f11838f 514 if((hrtc->Instance->CR & RTC_CR_BYPSHAD) == RESET)
mbed_official 235:685d5f11838f 515 {
mbed_official 235:685d5f11838f 516 if(HAL_RTC_WaitForSynchro(hrtc) != HAL_OK)
mbed_official 235:685d5f11838f 517 {
mbed_official 235:685d5f11838f 518 /* Enable the write protection for RTC registers */
mbed_official 235:685d5f11838f 519 __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc);
mbed_official 235:685d5f11838f 520
mbed_official 235:685d5f11838f 521 hrtc->State = HAL_RTC_STATE_ERROR;
mbed_official 235:685d5f11838f 522
mbed_official 235:685d5f11838f 523 /* Process Unlocked */
mbed_official 235:685d5f11838f 524 __HAL_UNLOCK(hrtc);
mbed_official 235:685d5f11838f 525
mbed_official 235:685d5f11838f 526 return HAL_ERROR;
mbed_official 235:685d5f11838f 527 }
mbed_official 235:685d5f11838f 528 }
mbed_official 235:685d5f11838f 529
mbed_official 235:685d5f11838f 530 /* Enable the write protection for RTC registers */
mbed_official 235:685d5f11838f 531 __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc);
mbed_official 235:685d5f11838f 532
mbed_official 235:685d5f11838f 533 hrtc->State = HAL_RTC_STATE_READY;
mbed_official 235:685d5f11838f 534
mbed_official 235:685d5f11838f 535 __HAL_UNLOCK(hrtc);
mbed_official 235:685d5f11838f 536
mbed_official 235:685d5f11838f 537 return HAL_OK;
mbed_official 235:685d5f11838f 538 }
mbed_official 235:685d5f11838f 539 }
mbed_official 235:685d5f11838f 540
mbed_official 235:685d5f11838f 541 /**
mbed_official 235:685d5f11838f 542 * @brief Gets RTC current time.
mbed_official 235:685d5f11838f 543 * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains
mbed_official 235:685d5f11838f 544 * the configuration information for RTC.
mbed_official 235:685d5f11838f 545 * @param sTime: Pointer to Time structure
mbed_official 235:685d5f11838f 546 * @param Format: Specifies the format of the entered parameters.
mbed_official 235:685d5f11838f 547 * This parameter can be one of the following values:
mbed_official 532:fe11edbda85c 548 * @arg RTC_FORMAT_BIN: Binary data format
mbed_official 532:fe11edbda85c 549 * @arg RTC_FORMAT_BCD: BCD data format
mbed_official 532:fe11edbda85c 550 * @note You must call HAL_RTC_GetDate() after HAL_RTC_GetTime() to unlock the values
mbed_official 532:fe11edbda85c 551 * in the higher-order calendar shadow registers to ensure consistency between the time and date values.
mbed_official 532:fe11edbda85c 552 * Reading RTC current time locks the values in calendar shadow registers until Current date is read.
mbed_official 235:685d5f11838f 553 * @retval HAL status
mbed_official 235:685d5f11838f 554 */
mbed_official 235:685d5f11838f 555 HAL_StatusTypeDef HAL_RTC_GetTime(RTC_HandleTypeDef *hrtc, RTC_TimeTypeDef *sTime, uint32_t Format)
mbed_official 235:685d5f11838f 556 {
mbed_official 235:685d5f11838f 557 uint32_t tmpreg = 0;
mbed_official 235:685d5f11838f 558
mbed_official 235:685d5f11838f 559 /* Check the parameters */
mbed_official 235:685d5f11838f 560 assert_param(IS_RTC_FORMAT(Format));
mbed_official 235:685d5f11838f 561
mbed_official 235:685d5f11838f 562 /* Get subseconds values from the correspondent registers*/
mbed_official 235:685d5f11838f 563 sTime->SubSeconds = (uint32_t)(hrtc->Instance->SSR);
mbed_official 235:685d5f11838f 564
mbed_official 235:685d5f11838f 565 /* Get the TR register */
mbed_official 235:685d5f11838f 566 tmpreg = (uint32_t)(hrtc->Instance->TR & RTC_TR_RESERVED_MASK);
mbed_official 235:685d5f11838f 567
mbed_official 235:685d5f11838f 568 /* Fill the structure fields with the read parameters */
mbed_official 235:685d5f11838f 569 sTime->Hours = (uint8_t)((tmpreg & (RTC_TR_HT | RTC_TR_HU)) >> 16);
mbed_official 235:685d5f11838f 570 sTime->Minutes = (uint8_t)((tmpreg & (RTC_TR_MNT | RTC_TR_MNU)) >>8);
mbed_official 235:685d5f11838f 571 sTime->Seconds = (uint8_t)(tmpreg & (RTC_TR_ST | RTC_TR_SU));
mbed_official 235:685d5f11838f 572 sTime->TimeFormat = (uint8_t)((tmpreg & (RTC_TR_PM)) >> 16);
mbed_official 235:685d5f11838f 573
mbed_official 235:685d5f11838f 574 /* Check the input parameters format */
mbed_official 532:fe11edbda85c 575 if(Format == RTC_FORMAT_BIN)
mbed_official 235:685d5f11838f 576 {
mbed_official 235:685d5f11838f 577 /* Convert the time structure parameters to Binary format */
mbed_official 235:685d5f11838f 578 sTime->Hours = (uint8_t)RTC_Bcd2ToByte(sTime->Hours);
mbed_official 235:685d5f11838f 579 sTime->Minutes = (uint8_t)RTC_Bcd2ToByte(sTime->Minutes);
mbed_official 235:685d5f11838f 580 sTime->Seconds = (uint8_t)RTC_Bcd2ToByte(sTime->Seconds);
mbed_official 235:685d5f11838f 581 }
mbed_official 235:685d5f11838f 582
mbed_official 235:685d5f11838f 583 return HAL_OK;
mbed_official 235:685d5f11838f 584 }
mbed_official 235:685d5f11838f 585
mbed_official 235:685d5f11838f 586 /**
mbed_official 235:685d5f11838f 587 * @brief Sets RTC current date.
mbed_official 235:685d5f11838f 588 * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains
mbed_official 235:685d5f11838f 589 * the configuration information for RTC.
mbed_official 235:685d5f11838f 590 * @param sDate: Pointer to date structure
mbed_official 235:685d5f11838f 591 * @param Format: specifies the format of the entered parameters.
mbed_official 235:685d5f11838f 592 * This parameter can be one of the following values:
mbed_official 532:fe11edbda85c 593 * @arg RTC_FORMAT_BIN: Binary data format
mbed_official 532:fe11edbda85c 594 * @arg RTC_FORMAT_BCD: BCD data format
mbed_official 235:685d5f11838f 595 * @retval HAL status
mbed_official 235:685d5f11838f 596 */
mbed_official 235:685d5f11838f 597 HAL_StatusTypeDef HAL_RTC_SetDate(RTC_HandleTypeDef *hrtc, RTC_DateTypeDef *sDate, uint32_t Format)
mbed_official 235:685d5f11838f 598 {
mbed_official 235:685d5f11838f 599 uint32_t datetmpreg = 0;
mbed_official 235:685d5f11838f 600
mbed_official 235:685d5f11838f 601 /* Check the parameters */
mbed_official 235:685d5f11838f 602 assert_param(IS_RTC_FORMAT(Format));
mbed_official 235:685d5f11838f 603
mbed_official 235:685d5f11838f 604 /* Process Locked */
mbed_official 235:685d5f11838f 605 __HAL_LOCK(hrtc);
mbed_official 235:685d5f11838f 606
mbed_official 235:685d5f11838f 607 hrtc->State = HAL_RTC_STATE_BUSY;
mbed_official 235:685d5f11838f 608
mbed_official 532:fe11edbda85c 609 if((Format == RTC_FORMAT_BIN) && ((sDate->Month & 0x10) == 0x10))
mbed_official 235:685d5f11838f 610 {
mbed_official 235:685d5f11838f 611 sDate->Month = (uint8_t)((sDate->Month & (uint8_t)~(0x10)) + (uint8_t)0x0A);
mbed_official 235:685d5f11838f 612 }
mbed_official 235:685d5f11838f 613
mbed_official 235:685d5f11838f 614 assert_param(IS_RTC_WEEKDAY(sDate->WeekDay));
mbed_official 235:685d5f11838f 615
mbed_official 532:fe11edbda85c 616 if(Format == RTC_FORMAT_BIN)
mbed_official 235:685d5f11838f 617 {
mbed_official 235:685d5f11838f 618 assert_param(IS_RTC_YEAR(sDate->Year));
mbed_official 235:685d5f11838f 619 assert_param(IS_RTC_MONTH(sDate->Month));
mbed_official 235:685d5f11838f 620 assert_param(IS_RTC_DATE(sDate->Date));
mbed_official 235:685d5f11838f 621
mbed_official 235:685d5f11838f 622 datetmpreg = (((uint32_t)RTC_ByteToBcd2(sDate->Year) << 16) | \
mbed_official 235:685d5f11838f 623 ((uint32_t)RTC_ByteToBcd2(sDate->Month) << 8) | \
mbed_official 235:685d5f11838f 624 ((uint32_t)RTC_ByteToBcd2(sDate->Date)) | \
mbed_official 235:685d5f11838f 625 ((uint32_t)sDate->WeekDay << 13));
mbed_official 235:685d5f11838f 626 }
mbed_official 235:685d5f11838f 627 else
mbed_official 235:685d5f11838f 628 {
mbed_official 235:685d5f11838f 629 assert_param(IS_RTC_YEAR(RTC_Bcd2ToByte(sDate->Year)));
mbed_official 235:685d5f11838f 630 datetmpreg = RTC_Bcd2ToByte(sDate->Month);
mbed_official 235:685d5f11838f 631 assert_param(IS_RTC_MONTH(datetmpreg));
mbed_official 235:685d5f11838f 632 datetmpreg = RTC_Bcd2ToByte(sDate->Date);
mbed_official 235:685d5f11838f 633 assert_param(IS_RTC_DATE(datetmpreg));
mbed_official 235:685d5f11838f 634
mbed_official 235:685d5f11838f 635 datetmpreg = ((((uint32_t)sDate->Year) << 16) | \
mbed_official 235:685d5f11838f 636 (((uint32_t)sDate->Month) << 8) | \
mbed_official 235:685d5f11838f 637 ((uint32_t)sDate->Date) | \
mbed_official 235:685d5f11838f 638 (((uint32_t)sDate->WeekDay) << 13));
mbed_official 235:685d5f11838f 639 }
mbed_official 235:685d5f11838f 640
mbed_official 235:685d5f11838f 641 /* Disable the write protection for RTC registers */
mbed_official 235:685d5f11838f 642 __HAL_RTC_WRITEPROTECTION_DISABLE(hrtc);
mbed_official 235:685d5f11838f 643
mbed_official 235:685d5f11838f 644 /* Set Initialization mode */
mbed_official 235:685d5f11838f 645 if(RTC_EnterInitMode(hrtc) != HAL_OK)
mbed_official 235:685d5f11838f 646 {
mbed_official 235:685d5f11838f 647 /* Enable the write protection for RTC registers */
mbed_official 235:685d5f11838f 648 __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc);
mbed_official 235:685d5f11838f 649
mbed_official 235:685d5f11838f 650 /* Set RTC state*/
mbed_official 235:685d5f11838f 651 hrtc->State = HAL_RTC_STATE_ERROR;
mbed_official 235:685d5f11838f 652
mbed_official 235:685d5f11838f 653 /* Process Unlocked */
mbed_official 235:685d5f11838f 654 __HAL_UNLOCK(hrtc);
mbed_official 235:685d5f11838f 655
mbed_official 235:685d5f11838f 656 return HAL_ERROR;
mbed_official 235:685d5f11838f 657 }
mbed_official 235:685d5f11838f 658 else
mbed_official 235:685d5f11838f 659 {
mbed_official 235:685d5f11838f 660 /* Set the RTC_DR register */
mbed_official 235:685d5f11838f 661 hrtc->Instance->DR = (uint32_t)(datetmpreg & RTC_DR_RESERVED_MASK);
mbed_official 235:685d5f11838f 662
mbed_official 235:685d5f11838f 663 /* Exit Initialization mode */
mbed_official 235:685d5f11838f 664 hrtc->Instance->ISR &= (uint32_t)~RTC_ISR_INIT;
mbed_official 235:685d5f11838f 665
mbed_official 235:685d5f11838f 666 /* If CR_BYPSHAD bit = 0, wait for synchro else this check is not needed */
mbed_official 235:685d5f11838f 667 if((hrtc->Instance->CR & RTC_CR_BYPSHAD) == RESET)
mbed_official 235:685d5f11838f 668 {
mbed_official 235:685d5f11838f 669 if(HAL_RTC_WaitForSynchro(hrtc) != HAL_OK)
mbed_official 235:685d5f11838f 670 {
mbed_official 235:685d5f11838f 671 /* Enable the write protection for RTC registers */
mbed_official 235:685d5f11838f 672 __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc);
mbed_official 235:685d5f11838f 673
mbed_official 235:685d5f11838f 674 hrtc->State = HAL_RTC_STATE_ERROR;
mbed_official 235:685d5f11838f 675
mbed_official 235:685d5f11838f 676 /* Process Unlocked */
mbed_official 235:685d5f11838f 677 __HAL_UNLOCK(hrtc);
mbed_official 235:685d5f11838f 678
mbed_official 235:685d5f11838f 679 return HAL_ERROR;
mbed_official 235:685d5f11838f 680 }
mbed_official 235:685d5f11838f 681 }
mbed_official 235:685d5f11838f 682
mbed_official 235:685d5f11838f 683 /* Enable the write protection for RTC registers */
mbed_official 235:685d5f11838f 684 __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc);
mbed_official 235:685d5f11838f 685
mbed_official 235:685d5f11838f 686 hrtc->State = HAL_RTC_STATE_READY ;
mbed_official 235:685d5f11838f 687
mbed_official 235:685d5f11838f 688 /* Process Unlocked */
mbed_official 235:685d5f11838f 689 __HAL_UNLOCK(hrtc);
mbed_official 235:685d5f11838f 690
mbed_official 235:685d5f11838f 691 return HAL_OK;
mbed_official 235:685d5f11838f 692 }
mbed_official 235:685d5f11838f 693 }
mbed_official 235:685d5f11838f 694
mbed_official 235:685d5f11838f 695 /**
mbed_official 235:685d5f11838f 696 * @brief Gets RTC current date.
mbed_official 235:685d5f11838f 697 * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains
mbed_official 235:685d5f11838f 698 * the configuration information for RTC.
mbed_official 235:685d5f11838f 699 * @param sDate: Pointer to Date structure
mbed_official 235:685d5f11838f 700 * @param Format: Specifies the format of the entered parameters.
mbed_official 235:685d5f11838f 701 * This parameter can be one of the following values:
mbed_official 532:fe11edbda85c 702 * @arg RTC_FORMAT_BIN: Binary data format
mbed_official 532:fe11edbda85c 703 * @arg RTC_FORMAT_BCD: BCD data format
mbed_official 532:fe11edbda85c 704 * @note You must call HAL_RTC_GetDate() after HAL_RTC_GetTime() to unlock the values
mbed_official 532:fe11edbda85c 705 * in the higher-order calendar shadow registers to ensure consistency between the time and date values.
mbed_official 532:fe11edbda85c 706 * Reading RTC current time locks the values in calendar shadow registers until Current date is read.
mbed_official 235:685d5f11838f 707 * @retval HAL status
mbed_official 235:685d5f11838f 708 */
mbed_official 235:685d5f11838f 709 HAL_StatusTypeDef HAL_RTC_GetDate(RTC_HandleTypeDef *hrtc, RTC_DateTypeDef *sDate, uint32_t Format)
mbed_official 235:685d5f11838f 710 {
mbed_official 235:685d5f11838f 711 uint32_t datetmpreg = 0;
mbed_official 235:685d5f11838f 712
mbed_official 235:685d5f11838f 713 /* Check the parameters */
mbed_official 235:685d5f11838f 714 assert_param(IS_RTC_FORMAT(Format));
mbed_official 235:685d5f11838f 715
mbed_official 235:685d5f11838f 716 /* Get the DR register */
mbed_official 235:685d5f11838f 717 datetmpreg = (uint32_t)(hrtc->Instance->DR & RTC_DR_RESERVED_MASK);
mbed_official 235:685d5f11838f 718
mbed_official 235:685d5f11838f 719 /* Fill the structure fields with the read parameters */
mbed_official 235:685d5f11838f 720 sDate->Year = (uint8_t)((datetmpreg & (RTC_DR_YT | RTC_DR_YU)) >> 16);
mbed_official 235:685d5f11838f 721 sDate->Month = (uint8_t)((datetmpreg & (RTC_DR_MT | RTC_DR_MU)) >> 8);
mbed_official 235:685d5f11838f 722 sDate->Date = (uint8_t)(datetmpreg & (RTC_DR_DT | RTC_DR_DU));
mbed_official 235:685d5f11838f 723 sDate->WeekDay = (uint8_t)((datetmpreg & (RTC_DR_WDU)) >> 13);
mbed_official 235:685d5f11838f 724
mbed_official 235:685d5f11838f 725 /* Check the input parameters format */
mbed_official 532:fe11edbda85c 726 if(Format == RTC_FORMAT_BIN)
mbed_official 235:685d5f11838f 727 {
mbed_official 235:685d5f11838f 728 /* Convert the date structure parameters to Binary format */
mbed_official 235:685d5f11838f 729 sDate->Year = (uint8_t)RTC_Bcd2ToByte(sDate->Year);
mbed_official 235:685d5f11838f 730 sDate->Month = (uint8_t)RTC_Bcd2ToByte(sDate->Month);
mbed_official 235:685d5f11838f 731 sDate->Date = (uint8_t)RTC_Bcd2ToByte(sDate->Date);
mbed_official 235:685d5f11838f 732 }
mbed_official 235:685d5f11838f 733 return HAL_OK;
mbed_official 235:685d5f11838f 734 }
mbed_official 235:685d5f11838f 735
mbed_official 235:685d5f11838f 736 /**
mbed_official 235:685d5f11838f 737 * @}
mbed_official 235:685d5f11838f 738 */
mbed_official 235:685d5f11838f 739
mbed_official 532:fe11edbda85c 740 /** @defgroup RTC_Exported_Functions_Group3 RTC Alarm functions
mbed_official 235:685d5f11838f 741 * @brief RTC Alarm functions
mbed_official 235:685d5f11838f 742 *
mbed_official 235:685d5f11838f 743 @verbatim
mbed_official 235:685d5f11838f 744 ===============================================================================
mbed_official 235:685d5f11838f 745 ##### RTC Alarm functions #####
mbed_official 235:685d5f11838f 746 ===============================================================================
mbed_official 235:685d5f11838f 747
mbed_official 235:685d5f11838f 748 [..] This section provides functions allowing to configure Alarm feature
mbed_official 235:685d5f11838f 749
mbed_official 235:685d5f11838f 750 @endverbatim
mbed_official 235:685d5f11838f 751 * @{
mbed_official 235:685d5f11838f 752 */
mbed_official 235:685d5f11838f 753 /**
mbed_official 235:685d5f11838f 754 * @brief Sets the specified RTC Alarm.
mbed_official 235:685d5f11838f 755 * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains
mbed_official 235:685d5f11838f 756 * the configuration information for RTC.
mbed_official 235:685d5f11838f 757 * @param sAlarm: Pointer to Alarm structure
mbed_official 235:685d5f11838f 758 * @param Format: Specifies the format of the entered parameters.
mbed_official 235:685d5f11838f 759 * This parameter can be one of the following values:
mbed_official 532:fe11edbda85c 760 * @arg RTC_FORMAT_BIN: Binary data format
mbed_official 532:fe11edbda85c 761 * @arg RTC_FORMAT_BCD: BCD data format
mbed_official 235:685d5f11838f 762 * @retval HAL status
mbed_official 235:685d5f11838f 763 */
mbed_official 235:685d5f11838f 764 HAL_StatusTypeDef HAL_RTC_SetAlarm(RTC_HandleTypeDef *hrtc, RTC_AlarmTypeDef *sAlarm, uint32_t Format)
mbed_official 235:685d5f11838f 765 {
mbed_official 235:685d5f11838f 766 uint32_t tickstart = 0;
mbed_official 235:685d5f11838f 767 uint32_t tmpreg = 0, subsecondtmpreg = 0;
mbed_official 235:685d5f11838f 768
mbed_official 235:685d5f11838f 769 /* Check the parameters */
mbed_official 235:685d5f11838f 770 assert_param(IS_RTC_FORMAT(Format));
mbed_official 532:fe11edbda85c 771 assert_param(IS_RTC_ALARM(sAlarm->Alarm));
mbed_official 532:fe11edbda85c 772 assert_param(IS_RTC_ALARM_MASK(sAlarm->AlarmMask));
mbed_official 235:685d5f11838f 773 assert_param(IS_RTC_ALARM_DATE_WEEKDAY_SEL(sAlarm->AlarmDateWeekDaySel));
mbed_official 235:685d5f11838f 774 assert_param(IS_RTC_ALARM_SUB_SECOND_VALUE(sAlarm->AlarmTime.SubSeconds));
mbed_official 235:685d5f11838f 775 assert_param(IS_RTC_ALARM_SUB_SECOND_MASK(sAlarm->AlarmSubSecondMask));
mbed_official 235:685d5f11838f 776
mbed_official 235:685d5f11838f 777 /* Process Locked */
mbed_official 235:685d5f11838f 778 __HAL_LOCK(hrtc);
mbed_official 235:685d5f11838f 779
mbed_official 235:685d5f11838f 780 hrtc->State = HAL_RTC_STATE_BUSY;
mbed_official 235:685d5f11838f 781
mbed_official 532:fe11edbda85c 782 if(Format == RTC_FORMAT_BIN)
mbed_official 235:685d5f11838f 783 {
mbed_official 235:685d5f11838f 784 if((hrtc->Instance->CR & RTC_CR_FMT) != (uint32_t)RESET)
mbed_official 235:685d5f11838f 785 {
mbed_official 235:685d5f11838f 786 assert_param(IS_RTC_HOUR12(sAlarm->AlarmTime.Hours));
mbed_official 235:685d5f11838f 787 assert_param(IS_RTC_HOURFORMAT12(sAlarm->AlarmTime.TimeFormat));
mbed_official 235:685d5f11838f 788 }
mbed_official 235:685d5f11838f 789 else
mbed_official 235:685d5f11838f 790 {
mbed_official 235:685d5f11838f 791 sAlarm->AlarmTime.TimeFormat = 0x00;
mbed_official 235:685d5f11838f 792 assert_param(IS_RTC_HOUR24(sAlarm->AlarmTime.Hours));
mbed_official 235:685d5f11838f 793 }
mbed_official 235:685d5f11838f 794 assert_param(IS_RTC_MINUTES(sAlarm->AlarmTime.Minutes));
mbed_official 235:685d5f11838f 795 assert_param(IS_RTC_SECONDS(sAlarm->AlarmTime.Seconds));
mbed_official 235:685d5f11838f 796
mbed_official 235:685d5f11838f 797 if(sAlarm->AlarmDateWeekDaySel == RTC_ALARMDATEWEEKDAYSEL_DATE)
mbed_official 235:685d5f11838f 798 {
mbed_official 235:685d5f11838f 799 assert_param(IS_RTC_ALARM_DATE_WEEKDAY_DATE(sAlarm->AlarmDateWeekDay));
mbed_official 235:685d5f11838f 800 }
mbed_official 235:685d5f11838f 801 else
mbed_official 235:685d5f11838f 802 {
mbed_official 235:685d5f11838f 803 assert_param(IS_RTC_ALARM_DATE_WEEKDAY_WEEKDAY(sAlarm->AlarmDateWeekDay));
mbed_official 235:685d5f11838f 804 }
mbed_official 235:685d5f11838f 805
mbed_official 235:685d5f11838f 806 tmpreg = (((uint32_t)RTC_ByteToBcd2(sAlarm->AlarmTime.Hours) << 16) | \
mbed_official 235:685d5f11838f 807 ((uint32_t)RTC_ByteToBcd2(sAlarm->AlarmTime.Minutes) << 8) | \
mbed_official 235:685d5f11838f 808 ((uint32_t)RTC_ByteToBcd2(sAlarm->AlarmTime.Seconds)) | \
mbed_official 235:685d5f11838f 809 ((uint32_t)(sAlarm->AlarmTime.TimeFormat) << 16) | \
mbed_official 235:685d5f11838f 810 ((uint32_t)RTC_ByteToBcd2(sAlarm->AlarmDateWeekDay) << 24) | \
mbed_official 235:685d5f11838f 811 ((uint32_t)sAlarm->AlarmDateWeekDaySel) | \
mbed_official 235:685d5f11838f 812 ((uint32_t)sAlarm->AlarmMask));
mbed_official 235:685d5f11838f 813 }
mbed_official 235:685d5f11838f 814 else
mbed_official 235:685d5f11838f 815 {
mbed_official 235:685d5f11838f 816 if((hrtc->Instance->CR & RTC_CR_FMT) != (uint32_t)RESET)
mbed_official 235:685d5f11838f 817 {
mbed_official 235:685d5f11838f 818 tmpreg = RTC_Bcd2ToByte(sAlarm->AlarmTime.Hours);
mbed_official 235:685d5f11838f 819 assert_param(IS_RTC_HOUR12(tmpreg));
mbed_official 235:685d5f11838f 820 assert_param(IS_RTC_HOURFORMAT12(sAlarm->AlarmTime.TimeFormat));
mbed_official 235:685d5f11838f 821 }
mbed_official 235:685d5f11838f 822 else
mbed_official 235:685d5f11838f 823 {
mbed_official 235:685d5f11838f 824 sAlarm->AlarmTime.TimeFormat = 0x00;
mbed_official 235:685d5f11838f 825 assert_param(IS_RTC_HOUR24(RTC_Bcd2ToByte(sAlarm->AlarmTime.Hours)));
mbed_official 235:685d5f11838f 826 }
mbed_official 235:685d5f11838f 827
mbed_official 235:685d5f11838f 828 assert_param(IS_RTC_MINUTES(RTC_Bcd2ToByte(sAlarm->AlarmTime.Minutes)));
mbed_official 235:685d5f11838f 829 assert_param(IS_RTC_SECONDS(RTC_Bcd2ToByte(sAlarm->AlarmTime.Seconds)));
mbed_official 235:685d5f11838f 830
mbed_official 235:685d5f11838f 831 if(sAlarm->AlarmDateWeekDaySel == RTC_ALARMDATEWEEKDAYSEL_DATE)
mbed_official 235:685d5f11838f 832 {
mbed_official 235:685d5f11838f 833 tmpreg = RTC_Bcd2ToByte(sAlarm->AlarmDateWeekDay);
mbed_official 235:685d5f11838f 834 assert_param(IS_RTC_ALARM_DATE_WEEKDAY_DATE(tmpreg));
mbed_official 235:685d5f11838f 835 }
mbed_official 235:685d5f11838f 836 else
mbed_official 235:685d5f11838f 837 {
mbed_official 235:685d5f11838f 838 tmpreg = RTC_Bcd2ToByte(sAlarm->AlarmDateWeekDay);
mbed_official 235:685d5f11838f 839 assert_param(IS_RTC_ALARM_DATE_WEEKDAY_WEEKDAY(tmpreg));
mbed_official 235:685d5f11838f 840 }
mbed_official 235:685d5f11838f 841
mbed_official 235:685d5f11838f 842 tmpreg = (((uint32_t)(sAlarm->AlarmTime.Hours) << 16) | \
mbed_official 235:685d5f11838f 843 ((uint32_t)(sAlarm->AlarmTime.Minutes) << 8) | \
mbed_official 235:685d5f11838f 844 ((uint32_t) sAlarm->AlarmTime.Seconds) | \
mbed_official 235:685d5f11838f 845 ((uint32_t)(sAlarm->AlarmTime.TimeFormat) << 16) | \
mbed_official 235:685d5f11838f 846 ((uint32_t)(sAlarm->AlarmDateWeekDay) << 24) | \
mbed_official 235:685d5f11838f 847 ((uint32_t)sAlarm->AlarmDateWeekDaySel) | \
mbed_official 235:685d5f11838f 848 ((uint32_t)sAlarm->AlarmMask));
mbed_official 235:685d5f11838f 849 }
mbed_official 235:685d5f11838f 850
mbed_official 235:685d5f11838f 851 /* Configure the Alarm A or Alarm B Sub Second registers */
mbed_official 235:685d5f11838f 852 subsecondtmpreg = (uint32_t)((uint32_t)(sAlarm->AlarmTime.SubSeconds) | (uint32_t)(sAlarm->AlarmSubSecondMask));
mbed_official 235:685d5f11838f 853
mbed_official 235:685d5f11838f 854 /* Disable the write protection for RTC registers */
mbed_official 235:685d5f11838f 855 __HAL_RTC_WRITEPROTECTION_DISABLE(hrtc);
mbed_official 235:685d5f11838f 856
mbed_official 235:685d5f11838f 857 /* Configure the Alarm register */
mbed_official 235:685d5f11838f 858 if(sAlarm->Alarm == RTC_ALARM_A)
mbed_official 235:685d5f11838f 859 {
mbed_official 235:685d5f11838f 860 /* Disable the Alarm A interrupt */
mbed_official 235:685d5f11838f 861 __HAL_RTC_ALARMA_DISABLE(hrtc);
mbed_official 235:685d5f11838f 862
mbed_official 235:685d5f11838f 863 /* In case of interrupt mode is used, the interrupt source must disabled */
mbed_official 235:685d5f11838f 864 __HAL_RTC_ALARM_DISABLE_IT(hrtc, RTC_IT_ALRA);
mbed_official 235:685d5f11838f 865
mbed_official 235:685d5f11838f 866 /* Get tick */
mbed_official 235:685d5f11838f 867 tickstart = HAL_GetTick();
mbed_official 235:685d5f11838f 868
mbed_official 235:685d5f11838f 869 /* Wait till RTC ALRAWF flag is set and if Time out is reached exit */
mbed_official 235:685d5f11838f 870 while(__HAL_RTC_ALARM_GET_FLAG(hrtc, RTC_FLAG_ALRAWF) == RESET)
mbed_official 235:685d5f11838f 871 {
mbed_official 235:685d5f11838f 872 if((HAL_GetTick() - tickstart ) > RTC_TIMEOUT_VALUE)
mbed_official 235:685d5f11838f 873 {
mbed_official 235:685d5f11838f 874 /* Enable the write protection for RTC registers */
mbed_official 235:685d5f11838f 875 __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc);
mbed_official 235:685d5f11838f 876
mbed_official 235:685d5f11838f 877 hrtc->State = HAL_RTC_STATE_TIMEOUT;
mbed_official 235:685d5f11838f 878
mbed_official 235:685d5f11838f 879 /* Process Unlocked */
mbed_official 235:685d5f11838f 880 __HAL_UNLOCK(hrtc);
mbed_official 235:685d5f11838f 881
mbed_official 235:685d5f11838f 882 return HAL_TIMEOUT;
mbed_official 235:685d5f11838f 883 }
mbed_official 235:685d5f11838f 884 }
mbed_official 235:685d5f11838f 885
mbed_official 235:685d5f11838f 886 hrtc->Instance->ALRMAR = (uint32_t)tmpreg;
mbed_official 235:685d5f11838f 887 /* Configure the Alarm A Sub Second register */
mbed_official 235:685d5f11838f 888 hrtc->Instance->ALRMASSR = subsecondtmpreg;
mbed_official 235:685d5f11838f 889 /* Configure the Alarm state: Enable Alarm */
mbed_official 235:685d5f11838f 890 __HAL_RTC_ALARMA_ENABLE(hrtc);
mbed_official 235:685d5f11838f 891 }
mbed_official 235:685d5f11838f 892 else
mbed_official 235:685d5f11838f 893 {
mbed_official 235:685d5f11838f 894 /* Disable the Alarm B interrupt */
mbed_official 235:685d5f11838f 895 __HAL_RTC_ALARMB_DISABLE(hrtc);
mbed_official 235:685d5f11838f 896
mbed_official 235:685d5f11838f 897 /* In case of interrupt mode is used, the interrupt source must disabled */
mbed_official 235:685d5f11838f 898 __HAL_RTC_ALARM_DISABLE_IT(hrtc, RTC_IT_ALRB);
mbed_official 235:685d5f11838f 899
mbed_official 235:685d5f11838f 900 /* Get tick */
mbed_official 235:685d5f11838f 901 tickstart = HAL_GetTick();
mbed_official 235:685d5f11838f 902
mbed_official 235:685d5f11838f 903 /* Wait till RTC ALRBWF flag is set and if Time out is reached exit */
mbed_official 235:685d5f11838f 904 while(__HAL_RTC_ALARM_GET_FLAG(hrtc, RTC_FLAG_ALRBWF) == RESET)
mbed_official 235:685d5f11838f 905 {
mbed_official 235:685d5f11838f 906 if((HAL_GetTick() - tickstart ) > RTC_TIMEOUT_VALUE)
mbed_official 235:685d5f11838f 907 {
mbed_official 235:685d5f11838f 908 /* Enable the write protection for RTC registers */
mbed_official 235:685d5f11838f 909 __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc);
mbed_official 235:685d5f11838f 910
mbed_official 235:685d5f11838f 911 hrtc->State = HAL_RTC_STATE_TIMEOUT;
mbed_official 235:685d5f11838f 912
mbed_official 235:685d5f11838f 913 /* Process Unlocked */
mbed_official 235:685d5f11838f 914 __HAL_UNLOCK(hrtc);
mbed_official 235:685d5f11838f 915
mbed_official 235:685d5f11838f 916 return HAL_TIMEOUT;
mbed_official 235:685d5f11838f 917 }
mbed_official 235:685d5f11838f 918 }
mbed_official 235:685d5f11838f 919
mbed_official 235:685d5f11838f 920 hrtc->Instance->ALRMBR = (uint32_t)tmpreg;
mbed_official 235:685d5f11838f 921 /* Configure the Alarm B Sub Second register */
mbed_official 235:685d5f11838f 922 hrtc->Instance->ALRMBSSR = subsecondtmpreg;
mbed_official 235:685d5f11838f 923 /* Configure the Alarm state: Enable Alarm */
mbed_official 235:685d5f11838f 924 __HAL_RTC_ALARMB_ENABLE(hrtc);
mbed_official 235:685d5f11838f 925 }
mbed_official 235:685d5f11838f 926
mbed_official 235:685d5f11838f 927 /* Enable the write protection for RTC registers */
mbed_official 235:685d5f11838f 928 __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc);
mbed_official 235:685d5f11838f 929
mbed_official 235:685d5f11838f 930 /* Change RTC state */
mbed_official 235:685d5f11838f 931 hrtc->State = HAL_RTC_STATE_READY;
mbed_official 235:685d5f11838f 932
mbed_official 235:685d5f11838f 933 /* Process Unlocked */
mbed_official 235:685d5f11838f 934 __HAL_UNLOCK(hrtc);
mbed_official 235:685d5f11838f 935
mbed_official 235:685d5f11838f 936 return HAL_OK;
mbed_official 235:685d5f11838f 937 }
mbed_official 235:685d5f11838f 938
mbed_official 235:685d5f11838f 939 /**
mbed_official 235:685d5f11838f 940 * @brief Sets the specified RTC Alarm with Interrupt
mbed_official 235:685d5f11838f 941 * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains
mbed_official 235:685d5f11838f 942 * the configuration information for RTC.
mbed_official 235:685d5f11838f 943 * @param sAlarm: Pointer to Alarm structure
mbed_official 235:685d5f11838f 944 * @param Format: Specifies the format of the entered parameters.
mbed_official 235:685d5f11838f 945 * This parameter can be one of the following values:
mbed_official 532:fe11edbda85c 946 * @arg RTC_FORMAT_BIN: Binary data format
mbed_official 532:fe11edbda85c 947 * @arg RTC_FORMAT_BCD: BCD data format
mbed_official 235:685d5f11838f 948 * @retval HAL status
mbed_official 235:685d5f11838f 949 */
mbed_official 235:685d5f11838f 950 HAL_StatusTypeDef HAL_RTC_SetAlarm_IT(RTC_HandleTypeDef *hrtc, RTC_AlarmTypeDef *sAlarm, uint32_t Format)
mbed_official 235:685d5f11838f 951 {
mbed_official 235:685d5f11838f 952 uint32_t tickstart = 0;
mbed_official 235:685d5f11838f 953 uint32_t tmpreg = 0, subsecondtmpreg = 0;
mbed_official 235:685d5f11838f 954
mbed_official 235:685d5f11838f 955 /* Check the parameters */
mbed_official 235:685d5f11838f 956 assert_param(IS_RTC_FORMAT(Format));
mbed_official 532:fe11edbda85c 957 assert_param(IS_RTC_ALARM(sAlarm->Alarm));
mbed_official 532:fe11edbda85c 958 assert_param(IS_RTC_ALARM_MASK(sAlarm->AlarmMask));
mbed_official 235:685d5f11838f 959 assert_param(IS_RTC_ALARM_DATE_WEEKDAY_SEL(sAlarm->AlarmDateWeekDaySel));
mbed_official 235:685d5f11838f 960 assert_param(IS_RTC_ALARM_SUB_SECOND_VALUE(sAlarm->AlarmTime.SubSeconds));
mbed_official 235:685d5f11838f 961 assert_param(IS_RTC_ALARM_SUB_SECOND_MASK(sAlarm->AlarmSubSecondMask));
mbed_official 235:685d5f11838f 962
mbed_official 235:685d5f11838f 963 /* Process Locked */
mbed_official 235:685d5f11838f 964 __HAL_LOCK(hrtc);
mbed_official 235:685d5f11838f 965
mbed_official 235:685d5f11838f 966 hrtc->State = HAL_RTC_STATE_BUSY;
mbed_official 235:685d5f11838f 967
mbed_official 532:fe11edbda85c 968 if(Format == RTC_FORMAT_BIN)
mbed_official 235:685d5f11838f 969 {
mbed_official 235:685d5f11838f 970 if((hrtc->Instance->CR & RTC_CR_FMT) != (uint32_t)RESET)
mbed_official 235:685d5f11838f 971 {
mbed_official 235:685d5f11838f 972 assert_param(IS_RTC_HOUR12(sAlarm->AlarmTime.Hours));
mbed_official 235:685d5f11838f 973 assert_param(IS_RTC_HOURFORMAT12(sAlarm->AlarmTime.TimeFormat));
mbed_official 235:685d5f11838f 974 }
mbed_official 235:685d5f11838f 975 else
mbed_official 235:685d5f11838f 976 {
mbed_official 235:685d5f11838f 977 sAlarm->AlarmTime.TimeFormat = 0x00;
mbed_official 235:685d5f11838f 978 assert_param(IS_RTC_HOUR24(sAlarm->AlarmTime.Hours));
mbed_official 235:685d5f11838f 979 }
mbed_official 235:685d5f11838f 980 assert_param(IS_RTC_MINUTES(sAlarm->AlarmTime.Minutes));
mbed_official 235:685d5f11838f 981 assert_param(IS_RTC_SECONDS(sAlarm->AlarmTime.Seconds));
mbed_official 235:685d5f11838f 982
mbed_official 235:685d5f11838f 983 if(sAlarm->AlarmDateWeekDaySel == RTC_ALARMDATEWEEKDAYSEL_DATE)
mbed_official 235:685d5f11838f 984 {
mbed_official 235:685d5f11838f 985 assert_param(IS_RTC_ALARM_DATE_WEEKDAY_DATE(sAlarm->AlarmDateWeekDay));
mbed_official 235:685d5f11838f 986 }
mbed_official 235:685d5f11838f 987 else
mbed_official 235:685d5f11838f 988 {
mbed_official 235:685d5f11838f 989 assert_param(IS_RTC_ALARM_DATE_WEEKDAY_WEEKDAY(sAlarm->AlarmDateWeekDay));
mbed_official 235:685d5f11838f 990 }
mbed_official 235:685d5f11838f 991 tmpreg = (((uint32_t)RTC_ByteToBcd2(sAlarm->AlarmTime.Hours) << 16) | \
mbed_official 235:685d5f11838f 992 ((uint32_t)RTC_ByteToBcd2(sAlarm->AlarmTime.Minutes) << 8) | \
mbed_official 235:685d5f11838f 993 ((uint32_t)RTC_ByteToBcd2(sAlarm->AlarmTime.Seconds)) | \
mbed_official 235:685d5f11838f 994 ((uint32_t)(sAlarm->AlarmTime.TimeFormat) << 16) | \
mbed_official 235:685d5f11838f 995 ((uint32_t)RTC_ByteToBcd2(sAlarm->AlarmDateWeekDay) << 24) | \
mbed_official 235:685d5f11838f 996 ((uint32_t)sAlarm->AlarmDateWeekDaySel) | \
mbed_official 235:685d5f11838f 997 ((uint32_t)sAlarm->AlarmMask));
mbed_official 235:685d5f11838f 998 }
mbed_official 235:685d5f11838f 999 else
mbed_official 235:685d5f11838f 1000 {
mbed_official 235:685d5f11838f 1001 if((hrtc->Instance->CR & RTC_CR_FMT) != (uint32_t)RESET)
mbed_official 235:685d5f11838f 1002 {
mbed_official 235:685d5f11838f 1003 tmpreg = RTC_Bcd2ToByte(sAlarm->AlarmTime.Hours);
mbed_official 235:685d5f11838f 1004 assert_param(IS_RTC_HOUR12(tmpreg));
mbed_official 235:685d5f11838f 1005 assert_param(IS_RTC_HOURFORMAT12(sAlarm->AlarmTime.TimeFormat));
mbed_official 235:685d5f11838f 1006 }
mbed_official 235:685d5f11838f 1007 else
mbed_official 235:685d5f11838f 1008 {
mbed_official 235:685d5f11838f 1009 sAlarm->AlarmTime.TimeFormat = 0x00;
mbed_official 235:685d5f11838f 1010 assert_param(IS_RTC_HOUR24(RTC_Bcd2ToByte(sAlarm->AlarmTime.Hours)));
mbed_official 235:685d5f11838f 1011 }
mbed_official 235:685d5f11838f 1012
mbed_official 235:685d5f11838f 1013 assert_param(IS_RTC_MINUTES(RTC_Bcd2ToByte(sAlarm->AlarmTime.Minutes)));
mbed_official 235:685d5f11838f 1014 assert_param(IS_RTC_SECONDS(RTC_Bcd2ToByte(sAlarm->AlarmTime.Seconds)));
mbed_official 235:685d5f11838f 1015
mbed_official 235:685d5f11838f 1016 if(sAlarm->AlarmDateWeekDaySel == RTC_ALARMDATEWEEKDAYSEL_DATE)
mbed_official 235:685d5f11838f 1017 {
mbed_official 235:685d5f11838f 1018 tmpreg = RTC_Bcd2ToByte(sAlarm->AlarmDateWeekDay);
mbed_official 235:685d5f11838f 1019 assert_param(IS_RTC_ALARM_DATE_WEEKDAY_DATE(tmpreg));
mbed_official 235:685d5f11838f 1020 }
mbed_official 235:685d5f11838f 1021 else
mbed_official 235:685d5f11838f 1022 {
mbed_official 235:685d5f11838f 1023 tmpreg = RTC_Bcd2ToByte(sAlarm->AlarmDateWeekDay);
mbed_official 235:685d5f11838f 1024 assert_param(IS_RTC_ALARM_DATE_WEEKDAY_WEEKDAY(tmpreg));
mbed_official 235:685d5f11838f 1025 }
mbed_official 235:685d5f11838f 1026 tmpreg = (((uint32_t)(sAlarm->AlarmTime.Hours) << 16) | \
mbed_official 235:685d5f11838f 1027 ((uint32_t)(sAlarm->AlarmTime.Minutes) << 8) | \
mbed_official 235:685d5f11838f 1028 ((uint32_t) sAlarm->AlarmTime.Seconds) | \
mbed_official 235:685d5f11838f 1029 ((uint32_t)(sAlarm->AlarmTime.TimeFormat) << 16) | \
mbed_official 235:685d5f11838f 1030 ((uint32_t)(sAlarm->AlarmDateWeekDay) << 24) | \
mbed_official 235:685d5f11838f 1031 ((uint32_t)sAlarm->AlarmDateWeekDaySel) | \
mbed_official 235:685d5f11838f 1032 ((uint32_t)sAlarm->AlarmMask));
mbed_official 235:685d5f11838f 1033 }
mbed_official 235:685d5f11838f 1034 /* Configure the Alarm A or Alarm B Sub Second registers */
mbed_official 235:685d5f11838f 1035 subsecondtmpreg = (uint32_t)((uint32_t)(sAlarm->AlarmTime.SubSeconds) | (uint32_t)(sAlarm->AlarmSubSecondMask));
mbed_official 235:685d5f11838f 1036
mbed_official 235:685d5f11838f 1037 /* Disable the write protection for RTC registers */
mbed_official 235:685d5f11838f 1038 __HAL_RTC_WRITEPROTECTION_DISABLE(hrtc);
mbed_official 235:685d5f11838f 1039
mbed_official 235:685d5f11838f 1040 /* Configure the Alarm register */
mbed_official 235:685d5f11838f 1041 if(sAlarm->Alarm == RTC_ALARM_A)
mbed_official 235:685d5f11838f 1042 {
mbed_official 235:685d5f11838f 1043 /* Disable the Alarm A interrupt */
mbed_official 235:685d5f11838f 1044 __HAL_RTC_ALARMA_DISABLE(hrtc);
mbed_official 235:685d5f11838f 1045
mbed_official 235:685d5f11838f 1046 /* Clear flag alarm A */
mbed_official 235:685d5f11838f 1047 __HAL_RTC_ALARM_CLEAR_FLAG(hrtc, RTC_FLAG_ALRAF);
mbed_official 235:685d5f11838f 1048
mbed_official 235:685d5f11838f 1049 /* Get tick */
mbed_official 235:685d5f11838f 1050 tickstart = HAL_GetTick();
mbed_official 235:685d5f11838f 1051
mbed_official 235:685d5f11838f 1052 /* Wait till RTC ALRAWF flag is set and if Time out is reached exit */
mbed_official 235:685d5f11838f 1053 while(__HAL_RTC_ALARM_GET_FLAG(hrtc, RTC_FLAG_ALRAWF) == RESET)
mbed_official 235:685d5f11838f 1054 {
mbed_official 235:685d5f11838f 1055 if((HAL_GetTick() - tickstart ) > RTC_TIMEOUT_VALUE)
mbed_official 235:685d5f11838f 1056 {
mbed_official 235:685d5f11838f 1057 /* Enable the write protection for RTC registers */
mbed_official 235:685d5f11838f 1058 __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc);
mbed_official 235:685d5f11838f 1059
mbed_official 235:685d5f11838f 1060 hrtc->State = HAL_RTC_STATE_TIMEOUT;
mbed_official 235:685d5f11838f 1061
mbed_official 235:685d5f11838f 1062 /* Process Unlocked */
mbed_official 235:685d5f11838f 1063 __HAL_UNLOCK(hrtc);
mbed_official 235:685d5f11838f 1064
mbed_official 235:685d5f11838f 1065 return HAL_TIMEOUT;
mbed_official 235:685d5f11838f 1066 }
mbed_official 235:685d5f11838f 1067 }
mbed_official 235:685d5f11838f 1068
mbed_official 235:685d5f11838f 1069 hrtc->Instance->ALRMAR = (uint32_t)tmpreg;
mbed_official 235:685d5f11838f 1070 /* Configure the Alarm A Sub Second register */
mbed_official 235:685d5f11838f 1071 hrtc->Instance->ALRMASSR = subsecondtmpreg;
mbed_official 235:685d5f11838f 1072 /* Configure the Alarm state: Enable Alarm */
mbed_official 235:685d5f11838f 1073 __HAL_RTC_ALARMA_ENABLE(hrtc);
mbed_official 235:685d5f11838f 1074 /* Configure the Alarm interrupt */
mbed_official 235:685d5f11838f 1075 __HAL_RTC_ALARM_ENABLE_IT(hrtc,RTC_IT_ALRA);
mbed_official 235:685d5f11838f 1076 }
mbed_official 235:685d5f11838f 1077 else
mbed_official 235:685d5f11838f 1078 {
mbed_official 235:685d5f11838f 1079 /* Disable the Alarm B interrupt */
mbed_official 235:685d5f11838f 1080 __HAL_RTC_ALARMB_DISABLE(hrtc);
mbed_official 235:685d5f11838f 1081
mbed_official 235:685d5f11838f 1082 /* Clear flag alarm B */
mbed_official 235:685d5f11838f 1083 __HAL_RTC_ALARM_CLEAR_FLAG(hrtc, RTC_FLAG_ALRBF);
mbed_official 235:685d5f11838f 1084
mbed_official 235:685d5f11838f 1085 /* Get tick */
mbed_official 235:685d5f11838f 1086 tickstart = HAL_GetTick();
mbed_official 235:685d5f11838f 1087
mbed_official 235:685d5f11838f 1088 /* Wait till RTC ALRBWF flag is set and if Time out is reached exit */
mbed_official 235:685d5f11838f 1089 while(__HAL_RTC_ALARM_GET_FLAG(hrtc, RTC_FLAG_ALRBWF) == RESET)
mbed_official 235:685d5f11838f 1090 {
mbed_official 235:685d5f11838f 1091 if((HAL_GetTick() - tickstart ) > RTC_TIMEOUT_VALUE)
mbed_official 235:685d5f11838f 1092 {
mbed_official 235:685d5f11838f 1093 /* Enable the write protection for RTC registers */
mbed_official 235:685d5f11838f 1094 __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc);
mbed_official 235:685d5f11838f 1095
mbed_official 235:685d5f11838f 1096 hrtc->State = HAL_RTC_STATE_TIMEOUT;
mbed_official 235:685d5f11838f 1097
mbed_official 235:685d5f11838f 1098 /* Process Unlocked */
mbed_official 235:685d5f11838f 1099 __HAL_UNLOCK(hrtc);
mbed_official 235:685d5f11838f 1100
mbed_official 235:685d5f11838f 1101 return HAL_TIMEOUT;
mbed_official 235:685d5f11838f 1102 }
mbed_official 235:685d5f11838f 1103 }
mbed_official 235:685d5f11838f 1104
mbed_official 235:685d5f11838f 1105 hrtc->Instance->ALRMBR = (uint32_t)tmpreg;
mbed_official 235:685d5f11838f 1106 /* Configure the Alarm B Sub Second register */
mbed_official 235:685d5f11838f 1107 hrtc->Instance->ALRMBSSR = subsecondtmpreg;
mbed_official 235:685d5f11838f 1108 /* Configure the Alarm state: Enable Alarm */
mbed_official 235:685d5f11838f 1109 __HAL_RTC_ALARMB_ENABLE(hrtc);
mbed_official 235:685d5f11838f 1110 /* Configure the Alarm interrupt */
mbed_official 235:685d5f11838f 1111 __HAL_RTC_ALARM_ENABLE_IT(hrtc, RTC_IT_ALRB);
mbed_official 235:685d5f11838f 1112 }
mbed_official 235:685d5f11838f 1113
mbed_official 235:685d5f11838f 1114 /* RTC Alarm Interrupt Configuration: EXTI configuration */
mbed_official 532:fe11edbda85c 1115 __HAL_RTC_ALARM_EXTI_ENABLE_IT();
mbed_official 235:685d5f11838f 1116
mbed_official 235:685d5f11838f 1117 EXTI->RTSR |= RTC_EXTI_LINE_ALARM_EVENT;
mbed_official 235:685d5f11838f 1118
mbed_official 235:685d5f11838f 1119 /* Enable the write protection for RTC registers */
mbed_official 235:685d5f11838f 1120 __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc);
mbed_official 235:685d5f11838f 1121
mbed_official 235:685d5f11838f 1122 hrtc->State = HAL_RTC_STATE_READY;
mbed_official 235:685d5f11838f 1123
mbed_official 235:685d5f11838f 1124 /* Process Unlocked */
mbed_official 235:685d5f11838f 1125 __HAL_UNLOCK(hrtc);
mbed_official 235:685d5f11838f 1126
mbed_official 235:685d5f11838f 1127 return HAL_OK;
mbed_official 235:685d5f11838f 1128 }
mbed_official 235:685d5f11838f 1129
mbed_official 235:685d5f11838f 1130 /**
mbed_official 532:fe11edbda85c 1131 * @brief Deactivate the specified RTC Alarm
mbed_official 235:685d5f11838f 1132 * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains
mbed_official 235:685d5f11838f 1133 * the configuration information for RTC.
mbed_official 235:685d5f11838f 1134 * @param Alarm: Specifies the Alarm.
mbed_official 235:685d5f11838f 1135 * This parameter can be one of the following values:
mbed_official 235:685d5f11838f 1136 * @arg RTC_ALARM_A: AlarmA
mbed_official 235:685d5f11838f 1137 * @arg RTC_ALARM_B: AlarmB
mbed_official 235:685d5f11838f 1138 * @retval HAL status
mbed_official 235:685d5f11838f 1139 */
mbed_official 235:685d5f11838f 1140 HAL_StatusTypeDef HAL_RTC_DeactivateAlarm(RTC_HandleTypeDef *hrtc, uint32_t Alarm)
mbed_official 235:685d5f11838f 1141 {
mbed_official 235:685d5f11838f 1142 uint32_t tickstart = 0;
mbed_official 235:685d5f11838f 1143
mbed_official 235:685d5f11838f 1144 /* Check the parameters */
mbed_official 532:fe11edbda85c 1145 assert_param(IS_RTC_ALARM(Alarm));
mbed_official 235:685d5f11838f 1146
mbed_official 235:685d5f11838f 1147 /* Process Locked */
mbed_official 235:685d5f11838f 1148 __HAL_LOCK(hrtc);
mbed_official 235:685d5f11838f 1149
mbed_official 235:685d5f11838f 1150 hrtc->State = HAL_RTC_STATE_BUSY;
mbed_official 235:685d5f11838f 1151
mbed_official 235:685d5f11838f 1152 /* Disable the write protection for RTC registers */
mbed_official 235:685d5f11838f 1153 __HAL_RTC_WRITEPROTECTION_DISABLE(hrtc);
mbed_official 235:685d5f11838f 1154
mbed_official 235:685d5f11838f 1155 if(Alarm == RTC_ALARM_A)
mbed_official 235:685d5f11838f 1156 {
mbed_official 235:685d5f11838f 1157 /* AlarmA */
mbed_official 235:685d5f11838f 1158 __HAL_RTC_ALARMA_DISABLE(hrtc);
mbed_official 235:685d5f11838f 1159
mbed_official 235:685d5f11838f 1160 /* In case of interrupt mode is used, the interrupt source must disabled */
mbed_official 235:685d5f11838f 1161 __HAL_RTC_ALARM_DISABLE_IT(hrtc, RTC_IT_ALRA);
mbed_official 235:685d5f11838f 1162
mbed_official 235:685d5f11838f 1163 /* Get tick */
mbed_official 235:685d5f11838f 1164 tickstart = HAL_GetTick();
mbed_official 235:685d5f11838f 1165
mbed_official 235:685d5f11838f 1166 /* Wait till RTC ALRxWF flag is set and if Time out is reached exit */
mbed_official 235:685d5f11838f 1167 while(__HAL_RTC_ALARM_GET_FLAG(hrtc, RTC_FLAG_ALRAWF) == RESET)
mbed_official 235:685d5f11838f 1168 {
mbed_official 235:685d5f11838f 1169 if((HAL_GetTick() - tickstart ) > RTC_TIMEOUT_VALUE)
mbed_official 235:685d5f11838f 1170 {
mbed_official 235:685d5f11838f 1171 /* Enable the write protection for RTC registers */
mbed_official 235:685d5f11838f 1172 __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc);
mbed_official 235:685d5f11838f 1173
mbed_official 235:685d5f11838f 1174 hrtc->State = HAL_RTC_STATE_TIMEOUT;
mbed_official 235:685d5f11838f 1175
mbed_official 235:685d5f11838f 1176 /* Process Unlocked */
mbed_official 235:685d5f11838f 1177 __HAL_UNLOCK(hrtc);
mbed_official 235:685d5f11838f 1178
mbed_official 235:685d5f11838f 1179 return HAL_TIMEOUT;
mbed_official 235:685d5f11838f 1180 }
mbed_official 235:685d5f11838f 1181 }
mbed_official 235:685d5f11838f 1182 }
mbed_official 235:685d5f11838f 1183 else
mbed_official 235:685d5f11838f 1184 {
mbed_official 235:685d5f11838f 1185 /* AlarmB */
mbed_official 235:685d5f11838f 1186 __HAL_RTC_ALARMB_DISABLE(hrtc);
mbed_official 235:685d5f11838f 1187
mbed_official 235:685d5f11838f 1188 /* In case of interrupt mode is used, the interrupt source must disabled */
mbed_official 235:685d5f11838f 1189 __HAL_RTC_ALARM_DISABLE_IT(hrtc,RTC_IT_ALRB);
mbed_official 235:685d5f11838f 1190
mbed_official 235:685d5f11838f 1191 /* Get tick */
mbed_official 235:685d5f11838f 1192 tickstart = HAL_GetTick();
mbed_official 235:685d5f11838f 1193
mbed_official 235:685d5f11838f 1194 /* Wait till RTC ALRxWF flag is set and if Time out is reached exit */
mbed_official 235:685d5f11838f 1195 while(__HAL_RTC_ALARM_GET_FLAG(hrtc, RTC_FLAG_ALRBWF) == RESET)
mbed_official 235:685d5f11838f 1196 {
mbed_official 235:685d5f11838f 1197 if((HAL_GetTick() - tickstart ) > RTC_TIMEOUT_VALUE)
mbed_official 235:685d5f11838f 1198 {
mbed_official 235:685d5f11838f 1199 /* Enable the write protection for RTC registers */
mbed_official 235:685d5f11838f 1200 __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc);
mbed_official 235:685d5f11838f 1201
mbed_official 235:685d5f11838f 1202 hrtc->State = HAL_RTC_STATE_TIMEOUT;
mbed_official 235:685d5f11838f 1203
mbed_official 235:685d5f11838f 1204 /* Process Unlocked */
mbed_official 235:685d5f11838f 1205 __HAL_UNLOCK(hrtc);
mbed_official 235:685d5f11838f 1206
mbed_official 235:685d5f11838f 1207 return HAL_TIMEOUT;
mbed_official 235:685d5f11838f 1208 }
mbed_official 235:685d5f11838f 1209 }
mbed_official 235:685d5f11838f 1210 }
mbed_official 235:685d5f11838f 1211 /* Enable the write protection for RTC registers */
mbed_official 235:685d5f11838f 1212 __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc);
mbed_official 235:685d5f11838f 1213
mbed_official 235:685d5f11838f 1214 hrtc->State = HAL_RTC_STATE_READY;
mbed_official 235:685d5f11838f 1215
mbed_official 235:685d5f11838f 1216 /* Process Unlocked */
mbed_official 235:685d5f11838f 1217 __HAL_UNLOCK(hrtc);
mbed_official 235:685d5f11838f 1218
mbed_official 235:685d5f11838f 1219 return HAL_OK;
mbed_official 235:685d5f11838f 1220 }
mbed_official 235:685d5f11838f 1221
mbed_official 235:685d5f11838f 1222 /**
mbed_official 235:685d5f11838f 1223 * @brief Gets the RTC Alarm value and masks.
mbed_official 235:685d5f11838f 1224 * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains
mbed_official 235:685d5f11838f 1225 * the configuration information for RTC.
mbed_official 235:685d5f11838f 1226 * @param sAlarm: Pointer to Date structure
mbed_official 235:685d5f11838f 1227 * @param Alarm: Specifies the Alarm.
mbed_official 235:685d5f11838f 1228 * This parameter can be one of the following values:
mbed_official 235:685d5f11838f 1229 * @arg RTC_ALARM_A: AlarmA
mbed_official 235:685d5f11838f 1230 * @arg RTC_ALARM_B: AlarmB
mbed_official 235:685d5f11838f 1231 * @param Format: Specifies the format of the entered parameters.
mbed_official 235:685d5f11838f 1232 * This parameter can be one of the following values:
mbed_official 532:fe11edbda85c 1233 * @arg RTC_FORMAT_BIN: Binary data format
mbed_official 532:fe11edbda85c 1234 * @arg RTC_FORMAT_BCD: BCD data format
mbed_official 235:685d5f11838f 1235 * @retval HAL status
mbed_official 235:685d5f11838f 1236 */
mbed_official 235:685d5f11838f 1237 HAL_StatusTypeDef HAL_RTC_GetAlarm(RTC_HandleTypeDef *hrtc, RTC_AlarmTypeDef *sAlarm, uint32_t Alarm, uint32_t Format)
mbed_official 235:685d5f11838f 1238 {
mbed_official 235:685d5f11838f 1239 uint32_t tmpreg = 0, subsecondtmpreg = 0;
mbed_official 235:685d5f11838f 1240
mbed_official 235:685d5f11838f 1241 /* Check the parameters */
mbed_official 235:685d5f11838f 1242 assert_param(IS_RTC_FORMAT(Format));
mbed_official 532:fe11edbda85c 1243 assert_param(IS_RTC_ALARM(Alarm));
mbed_official 235:685d5f11838f 1244
mbed_official 235:685d5f11838f 1245 if(Alarm == RTC_ALARM_A)
mbed_official 235:685d5f11838f 1246 {
mbed_official 235:685d5f11838f 1247 /* AlarmA */
mbed_official 235:685d5f11838f 1248 sAlarm->Alarm = RTC_ALARM_A;
mbed_official 235:685d5f11838f 1249
mbed_official 235:685d5f11838f 1250 tmpreg = (uint32_t)(hrtc->Instance->ALRMAR);
mbed_official 235:685d5f11838f 1251 subsecondtmpreg = (uint32_t)((hrtc->Instance->ALRMASSR ) & RTC_ALRMASSR_SS);
mbed_official 235:685d5f11838f 1252 }
mbed_official 235:685d5f11838f 1253 else
mbed_official 235:685d5f11838f 1254 {
mbed_official 235:685d5f11838f 1255 sAlarm->Alarm = RTC_ALARM_B;
mbed_official 235:685d5f11838f 1256
mbed_official 235:685d5f11838f 1257 tmpreg = (uint32_t)(hrtc->Instance->ALRMBR);
mbed_official 235:685d5f11838f 1258 subsecondtmpreg = (uint32_t)((hrtc->Instance->ALRMBSSR) & RTC_ALRMBSSR_SS);
mbed_official 235:685d5f11838f 1259 }
mbed_official 235:685d5f11838f 1260
mbed_official 235:685d5f11838f 1261 /* Fill the structure with the read parameters */
mbed_official 235:685d5f11838f 1262 sAlarm->AlarmTime.Hours = (uint32_t)((tmpreg & (RTC_ALRMAR_HT | RTC_ALRMAR_HU)) >> 16);
mbed_official 235:685d5f11838f 1263 sAlarm->AlarmTime.Minutes = (uint32_t)((tmpreg & (RTC_ALRMAR_MNT | RTC_ALRMAR_MNU)) >> 8);
mbed_official 235:685d5f11838f 1264 sAlarm->AlarmTime.Seconds = (uint32_t)(tmpreg & (RTC_ALRMAR_ST | RTC_ALRMAR_SU));
mbed_official 235:685d5f11838f 1265 sAlarm->AlarmTime.TimeFormat = (uint32_t)((tmpreg & RTC_ALRMAR_PM) >> 16);
mbed_official 235:685d5f11838f 1266 sAlarm->AlarmTime.SubSeconds = (uint32_t) subsecondtmpreg;
mbed_official 235:685d5f11838f 1267 sAlarm->AlarmDateWeekDay = (uint32_t)((tmpreg & (RTC_ALRMAR_DT | RTC_ALRMAR_DU)) >> 24);
mbed_official 235:685d5f11838f 1268 sAlarm->AlarmDateWeekDaySel = (uint32_t)(tmpreg & RTC_ALRMAR_WDSEL);
mbed_official 235:685d5f11838f 1269 sAlarm->AlarmMask = (uint32_t)(tmpreg & RTC_ALARMMASK_ALL);
mbed_official 235:685d5f11838f 1270
mbed_official 532:fe11edbda85c 1271 if(Format == RTC_FORMAT_BIN)
mbed_official 235:685d5f11838f 1272 {
mbed_official 235:685d5f11838f 1273 sAlarm->AlarmTime.Hours = RTC_Bcd2ToByte(sAlarm->AlarmTime.Hours);
mbed_official 235:685d5f11838f 1274 sAlarm->AlarmTime.Minutes = RTC_Bcd2ToByte(sAlarm->AlarmTime.Minutes);
mbed_official 235:685d5f11838f 1275 sAlarm->AlarmTime.Seconds = RTC_Bcd2ToByte(sAlarm->AlarmTime.Seconds);
mbed_official 235:685d5f11838f 1276 sAlarm->AlarmDateWeekDay = RTC_Bcd2ToByte(sAlarm->AlarmDateWeekDay);
mbed_official 235:685d5f11838f 1277 }
mbed_official 235:685d5f11838f 1278
mbed_official 235:685d5f11838f 1279 return HAL_OK;
mbed_official 235:685d5f11838f 1280 }
mbed_official 235:685d5f11838f 1281
mbed_official 235:685d5f11838f 1282 /**
mbed_official 235:685d5f11838f 1283 * @brief This function handles Alarm interrupt request.
mbed_official 235:685d5f11838f 1284 * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains
mbed_official 235:685d5f11838f 1285 * the configuration information for RTC.
mbed_official 235:685d5f11838f 1286 * @retval None
mbed_official 235:685d5f11838f 1287 */
mbed_official 235:685d5f11838f 1288 void HAL_RTC_AlarmIRQHandler(RTC_HandleTypeDef* hrtc)
mbed_official 235:685d5f11838f 1289 {
mbed_official 235:685d5f11838f 1290 if(__HAL_RTC_ALARM_GET_IT(hrtc, RTC_IT_ALRA))
mbed_official 235:685d5f11838f 1291 {
mbed_official 235:685d5f11838f 1292 /* Get the status of the Interrupt */
mbed_official 235:685d5f11838f 1293 if((uint32_t)(hrtc->Instance->CR & RTC_IT_ALRA) != (uint32_t)RESET)
mbed_official 235:685d5f11838f 1294 {
mbed_official 235:685d5f11838f 1295 /* AlarmA callback */
mbed_official 235:685d5f11838f 1296 HAL_RTC_AlarmAEventCallback(hrtc);
mbed_official 235:685d5f11838f 1297
mbed_official 235:685d5f11838f 1298 /* Clear the Alarm interrupt pending bit */
mbed_official 235:685d5f11838f 1299 __HAL_RTC_ALARM_CLEAR_FLAG(hrtc,RTC_FLAG_ALRAF);
mbed_official 235:685d5f11838f 1300 }
mbed_official 235:685d5f11838f 1301 }
mbed_official 235:685d5f11838f 1302
mbed_official 235:685d5f11838f 1303 if(__HAL_RTC_ALARM_GET_IT(hrtc, RTC_IT_ALRB))
mbed_official 235:685d5f11838f 1304 {
mbed_official 235:685d5f11838f 1305 /* Get the status of the Interrupt */
mbed_official 235:685d5f11838f 1306 if((uint32_t)(hrtc->Instance->CR & RTC_IT_ALRB) != (uint32_t)RESET)
mbed_official 235:685d5f11838f 1307 {
mbed_official 235:685d5f11838f 1308 /* AlarmB callback */
mbed_official 235:685d5f11838f 1309 HAL_RTCEx_AlarmBEventCallback(hrtc);
mbed_official 235:685d5f11838f 1310
mbed_official 235:685d5f11838f 1311 /* Clear the Alarm interrupt pending bit */
mbed_official 235:685d5f11838f 1312 __HAL_RTC_ALARM_CLEAR_FLAG(hrtc,RTC_FLAG_ALRBF);
mbed_official 235:685d5f11838f 1313 }
mbed_official 235:685d5f11838f 1314 }
mbed_official 235:685d5f11838f 1315
mbed_official 235:685d5f11838f 1316 /* Clear the EXTI's line Flag for RTC Alarm */
mbed_official 532:fe11edbda85c 1317 __HAL_RTC_ALARM_EXTI_CLEAR_FLAG();
mbed_official 235:685d5f11838f 1318
mbed_official 235:685d5f11838f 1319 /* Change RTC state */
mbed_official 235:685d5f11838f 1320 hrtc->State = HAL_RTC_STATE_READY;
mbed_official 235:685d5f11838f 1321 }
mbed_official 235:685d5f11838f 1322
mbed_official 235:685d5f11838f 1323 /**
mbed_official 235:685d5f11838f 1324 * @brief Alarm A callback.
mbed_official 235:685d5f11838f 1325 * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains
mbed_official 235:685d5f11838f 1326 * the configuration information for RTC.
mbed_official 235:685d5f11838f 1327 * @retval None
mbed_official 235:685d5f11838f 1328 */
mbed_official 235:685d5f11838f 1329 __weak void HAL_RTC_AlarmAEventCallback(RTC_HandleTypeDef *hrtc)
mbed_official 235:685d5f11838f 1330 {
mbed_official 235:685d5f11838f 1331 /* NOTE : This function Should not be modified, when the callback is needed,
mbed_official 235:685d5f11838f 1332 the HAL_RTC_AlarmAEventCallback could be implemented in the user file
mbed_official 235:685d5f11838f 1333 */
mbed_official 235:685d5f11838f 1334 }
mbed_official 235:685d5f11838f 1335
mbed_official 235:685d5f11838f 1336 /**
mbed_official 235:685d5f11838f 1337 * @brief This function handles AlarmA Polling request.
mbed_official 235:685d5f11838f 1338 * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains
mbed_official 235:685d5f11838f 1339 * the configuration information for RTC.
mbed_official 235:685d5f11838f 1340 * @param Timeout: Timeout duration
mbed_official 235:685d5f11838f 1341 * @retval HAL status
mbed_official 235:685d5f11838f 1342 */
mbed_official 235:685d5f11838f 1343 HAL_StatusTypeDef HAL_RTC_PollForAlarmAEvent(RTC_HandleTypeDef *hrtc, uint32_t Timeout)
mbed_official 235:685d5f11838f 1344 {
mbed_official 235:685d5f11838f 1345 uint32_t tickstart = 0;
mbed_official 235:685d5f11838f 1346
mbed_official 235:685d5f11838f 1347 /* Get tick */
mbed_official 235:685d5f11838f 1348 tickstart = HAL_GetTick();
mbed_official 235:685d5f11838f 1349
mbed_official 235:685d5f11838f 1350 while(__HAL_RTC_ALARM_GET_FLAG(hrtc, RTC_FLAG_ALRAF) == RESET)
mbed_official 235:685d5f11838f 1351 {
mbed_official 235:685d5f11838f 1352 if(Timeout != HAL_MAX_DELAY)
mbed_official 235:685d5f11838f 1353 {
mbed_official 235:685d5f11838f 1354 if((Timeout == 0)||((HAL_GetTick() - tickstart ) > Timeout))
mbed_official 235:685d5f11838f 1355 {
mbed_official 235:685d5f11838f 1356 hrtc->State = HAL_RTC_STATE_TIMEOUT;
mbed_official 235:685d5f11838f 1357 return HAL_TIMEOUT;
mbed_official 235:685d5f11838f 1358 }
mbed_official 235:685d5f11838f 1359 }
mbed_official 235:685d5f11838f 1360 }
mbed_official 235:685d5f11838f 1361
mbed_official 235:685d5f11838f 1362 /* Clear the Alarm interrupt pending bit */
mbed_official 235:685d5f11838f 1363 __HAL_RTC_ALARM_CLEAR_FLAG(hrtc, RTC_FLAG_ALRAF);
mbed_official 235:685d5f11838f 1364
mbed_official 235:685d5f11838f 1365 /* Change RTC state */
mbed_official 235:685d5f11838f 1366 hrtc->State = HAL_RTC_STATE_READY;
mbed_official 235:685d5f11838f 1367
mbed_official 235:685d5f11838f 1368 return HAL_OK;
mbed_official 235:685d5f11838f 1369 }
mbed_official 235:685d5f11838f 1370
mbed_official 235:685d5f11838f 1371 /**
mbed_official 235:685d5f11838f 1372 * @}
mbed_official 235:685d5f11838f 1373 */
mbed_official 235:685d5f11838f 1374
mbed_official 532:fe11edbda85c 1375 /** @defgroup RTC_Exported_Functions_Group4 Peripheral Control functions
mbed_official 235:685d5f11838f 1376 * @brief Peripheral Control functions
mbed_official 235:685d5f11838f 1377 *
mbed_official 235:685d5f11838f 1378 @verbatim
mbed_official 235:685d5f11838f 1379 ===============================================================================
mbed_official 235:685d5f11838f 1380 ##### Peripheral Control functions #####
mbed_official 235:685d5f11838f 1381 ===============================================================================
mbed_official 235:685d5f11838f 1382 [..]
mbed_official 235:685d5f11838f 1383 This subsection provides functions allowing to
mbed_official 235:685d5f11838f 1384 (+) Wait for RTC Time and Date Synchronization
mbed_official 235:685d5f11838f 1385
mbed_official 235:685d5f11838f 1386 @endverbatim
mbed_official 235:685d5f11838f 1387 * @{
mbed_official 235:685d5f11838f 1388 */
mbed_official 235:685d5f11838f 1389
mbed_official 235:685d5f11838f 1390 /**
mbed_official 235:685d5f11838f 1391 * @brief Waits until the RTC Time and Date registers (RTC_TR and RTC_DR) are
mbed_official 235:685d5f11838f 1392 * synchronized with RTC APB clock.
mbed_official 235:685d5f11838f 1393 * @note The RTC Resynchronization mode is write protected, use the
mbed_official 235:685d5f11838f 1394 * __HAL_RTC_WRITEPROTECTION_DISABLE() before calling this function.
mbed_official 235:685d5f11838f 1395 * @note To read the calendar through the shadow registers after Calendar
mbed_official 532:fe11edbda85c 1396 * initialization, calendar update or after wake-up from low power modes
mbed_official 235:685d5f11838f 1397 * the software must first clear the RSF flag.
mbed_official 235:685d5f11838f 1398 * The software must then wait until it is set again before reading
mbed_official 235:685d5f11838f 1399 * the calendar, which means that the calendar registers have been
mbed_official 235:685d5f11838f 1400 * correctly copied into the RTC_TR and RTC_DR shadow registers.
mbed_official 235:685d5f11838f 1401 * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains
mbed_official 235:685d5f11838f 1402 * the configuration information for RTC.
mbed_official 235:685d5f11838f 1403 * @retval HAL status
mbed_official 235:685d5f11838f 1404 */
mbed_official 235:685d5f11838f 1405 HAL_StatusTypeDef HAL_RTC_WaitForSynchro(RTC_HandleTypeDef* hrtc)
mbed_official 235:685d5f11838f 1406 {
mbed_official 235:685d5f11838f 1407 uint32_t tickstart = 0;
mbed_official 235:685d5f11838f 1408
mbed_official 235:685d5f11838f 1409 /* Clear RSF flag */
mbed_official 235:685d5f11838f 1410 hrtc->Instance->ISR &= (uint32_t)RTC_RSF_MASK;
mbed_official 235:685d5f11838f 1411
mbed_official 235:685d5f11838f 1412 /* Get tick */
mbed_official 235:685d5f11838f 1413 tickstart = HAL_GetTick();
mbed_official 235:685d5f11838f 1414
mbed_official 235:685d5f11838f 1415 /* Wait the registers to be synchronised */
mbed_official 235:685d5f11838f 1416 while((hrtc->Instance->ISR & RTC_ISR_RSF) == (uint32_t)RESET)
mbed_official 235:685d5f11838f 1417 {
mbed_official 235:685d5f11838f 1418 if((HAL_GetTick() - tickstart ) > RTC_TIMEOUT_VALUE)
mbed_official 235:685d5f11838f 1419 {
mbed_official 235:685d5f11838f 1420 return HAL_TIMEOUT;
mbed_official 235:685d5f11838f 1421 }
mbed_official 235:685d5f11838f 1422 }
mbed_official 235:685d5f11838f 1423
mbed_official 235:685d5f11838f 1424 return HAL_OK;
mbed_official 235:685d5f11838f 1425 }
mbed_official 235:685d5f11838f 1426
mbed_official 532:fe11edbda85c 1427 /**
mbed_official 532:fe11edbda85c 1428 * @}
mbed_official 532:fe11edbda85c 1429 */
mbed_official 532:fe11edbda85c 1430
mbed_official 532:fe11edbda85c 1431 /** @defgroup RTC_Exported_Functions_Group5 Peripheral State functions
mbed_official 235:685d5f11838f 1432 * @brief Peripheral State functions
mbed_official 235:685d5f11838f 1433 *
mbed_official 235:685d5f11838f 1434 @verbatim
mbed_official 235:685d5f11838f 1435 ===============================================================================
mbed_official 235:685d5f11838f 1436 ##### Peripheral State functions #####
mbed_official 235:685d5f11838f 1437 ===============================================================================
mbed_official 235:685d5f11838f 1438 [..]
mbed_official 235:685d5f11838f 1439 This subsection provides functions allowing to
mbed_official 235:685d5f11838f 1440 (+) Get RTC state
mbed_official 235:685d5f11838f 1441
mbed_official 235:685d5f11838f 1442 @endverbatim
mbed_official 235:685d5f11838f 1443 * @{
mbed_official 235:685d5f11838f 1444 */
mbed_official 235:685d5f11838f 1445 /**
mbed_official 235:685d5f11838f 1446 * @brief Returns the RTC state.
mbed_official 235:685d5f11838f 1447 * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains
mbed_official 235:685d5f11838f 1448 * the configuration information for RTC.
mbed_official 235:685d5f11838f 1449 * @retval HAL state
mbed_official 235:685d5f11838f 1450 */
mbed_official 235:685d5f11838f 1451 HAL_RTCStateTypeDef HAL_RTC_GetState(RTC_HandleTypeDef* hrtc)
mbed_official 235:685d5f11838f 1452 {
mbed_official 235:685d5f11838f 1453 return hrtc->State;
mbed_official 235:685d5f11838f 1454 }
mbed_official 235:685d5f11838f 1455
mbed_official 235:685d5f11838f 1456 /**
mbed_official 235:685d5f11838f 1457 * @}
mbed_official 235:685d5f11838f 1458 */
mbed_official 235:685d5f11838f 1459
mbed_official 235:685d5f11838f 1460 /**
mbed_official 235:685d5f11838f 1461 * @brief Enters the RTC Initialization mode.
mbed_official 235:685d5f11838f 1462 * @note The RTC Initialization mode is write protected, use the
mbed_official 235:685d5f11838f 1463 * __HAL_RTC_WRITEPROTECTION_DISABLE() before calling this function.
mbed_official 235:685d5f11838f 1464 * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains
mbed_official 235:685d5f11838f 1465 * the configuration information for RTC.
mbed_official 235:685d5f11838f 1466 * @retval HAL status
mbed_official 235:685d5f11838f 1467 */
mbed_official 235:685d5f11838f 1468 HAL_StatusTypeDef RTC_EnterInitMode(RTC_HandleTypeDef* hrtc)
mbed_official 235:685d5f11838f 1469 {
mbed_official 235:685d5f11838f 1470 uint32_t tickstart = 0;
mbed_official 235:685d5f11838f 1471
mbed_official 235:685d5f11838f 1472 /* Check if the Initialization mode is set */
mbed_official 235:685d5f11838f 1473 if((hrtc->Instance->ISR & RTC_ISR_INITF) == (uint32_t)RESET)
mbed_official 235:685d5f11838f 1474 {
mbed_official 235:685d5f11838f 1475 /* Set the Initialization mode */
mbed_official 235:685d5f11838f 1476 hrtc->Instance->ISR = (uint32_t)RTC_INIT_MASK;
mbed_official 235:685d5f11838f 1477
mbed_official 235:685d5f11838f 1478 /* Get tick */
mbed_official 235:685d5f11838f 1479 tickstart = HAL_GetTick();
mbed_official 235:685d5f11838f 1480
mbed_official 235:685d5f11838f 1481 /* Wait till RTC is in INIT state and if Time out is reached exit */
mbed_official 235:685d5f11838f 1482 while((hrtc->Instance->ISR & RTC_ISR_INITF) == (uint32_t)RESET)
mbed_official 235:685d5f11838f 1483 {
mbed_official 235:685d5f11838f 1484 if((HAL_GetTick() - tickstart ) > RTC_TIMEOUT_VALUE)
mbed_official 235:685d5f11838f 1485 {
mbed_official 235:685d5f11838f 1486 return HAL_TIMEOUT;
mbed_official 235:685d5f11838f 1487 }
mbed_official 235:685d5f11838f 1488 }
mbed_official 235:685d5f11838f 1489 }
mbed_official 235:685d5f11838f 1490
mbed_official 235:685d5f11838f 1491 return HAL_OK;
mbed_official 235:685d5f11838f 1492 }
mbed_official 235:685d5f11838f 1493
mbed_official 235:685d5f11838f 1494
mbed_official 235:685d5f11838f 1495 /**
mbed_official 235:685d5f11838f 1496 * @brief Converts a 2 digit decimal to BCD format.
mbed_official 235:685d5f11838f 1497 * @param Value: Byte to be converted
mbed_official 235:685d5f11838f 1498 * @retval Converted byte
mbed_official 235:685d5f11838f 1499 */
mbed_official 235:685d5f11838f 1500 uint8_t RTC_ByteToBcd2(uint8_t Value)
mbed_official 235:685d5f11838f 1501 {
mbed_official 235:685d5f11838f 1502 uint32_t bcdhigh = 0;
mbed_official 235:685d5f11838f 1503
mbed_official 235:685d5f11838f 1504 while(Value >= 10)
mbed_official 235:685d5f11838f 1505 {
mbed_official 235:685d5f11838f 1506 bcdhigh++;
mbed_official 235:685d5f11838f 1507 Value -= 10;
mbed_official 235:685d5f11838f 1508 }
mbed_official 235:685d5f11838f 1509
mbed_official 235:685d5f11838f 1510 return ((uint8_t)(bcdhigh << 4) | Value);
mbed_official 235:685d5f11838f 1511 }
mbed_official 235:685d5f11838f 1512
mbed_official 235:685d5f11838f 1513 /**
mbed_official 235:685d5f11838f 1514 * @brief Converts from 2 digit BCD to Binary.
mbed_official 235:685d5f11838f 1515 * @param Value: BCD value to be converted
mbed_official 235:685d5f11838f 1516 * @retval Converted word
mbed_official 235:685d5f11838f 1517 */
mbed_official 235:685d5f11838f 1518 uint8_t RTC_Bcd2ToByte(uint8_t Value)
mbed_official 235:685d5f11838f 1519 {
mbed_official 235:685d5f11838f 1520 uint32_t tmp = 0;
mbed_official 235:685d5f11838f 1521 tmp = ((uint8_t)(Value & (uint8_t)0xF0) >> (uint8_t)0x4) * 10;
mbed_official 235:685d5f11838f 1522 return (tmp + (Value & (uint8_t)0x0F));
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
mbed_official 235:685d5f11838f 1529 #endif /* HAL_RTC_MODULE_ENABLED */
mbed_official 235:685d5f11838f 1530 /**
mbed_official 235:685d5f11838f 1531 * @}
mbed_official 235:685d5f11838f 1532 */
mbed_official 235:685d5f11838f 1533
mbed_official 235:685d5f11838f 1534 /**
mbed_official 235:685d5f11838f 1535 * @}
mbed_official 235:685d5f11838f 1536 */
mbed_official 235:685d5f11838f 1537
mbed_official 235:685d5f11838f 1538 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/