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 Aug 20 10:45:13 2015 +0100
Revision:
613:bc40b8d2aec4
Parent:
532:fe11edbda85c
Synchronized with git revision 92ca8c7b60a283b6bb60eb65b183dac1599f0ade

Full URL: https://github.com/mbedmicro/mbed/commit/92ca8c7b60a283b6bb60eb65b183dac1599f0ade/

Nordic: update application start address in GCC linker script

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 613:bc40b8d2aec4 5 * @version V1.3.2
mbed_official 613:bc40b8d2aec4 6 * @date 26-June-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 613:bc40b8d2aec4 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 613:bc40b8d2aec4 206 if(hrtc == 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 613:bc40b8d2aec4 550 * @note You can use SubSeconds and SecondFraction (sTime structure fields returned) to convert SubSeconds
mbed_official 613:bc40b8d2aec4 551 * value in second fraction ratio with time unit following generic formula:
mbed_official 613:bc40b8d2aec4 552 * Second fraction ratio * time_unit= [(SecondFraction-SubSeconds)/(SecondFraction+1)] * time_unit
mbed_official 613:bc40b8d2aec4 553 * This conversion can be performed only if no shift operation is pending (ie. SHFP=0) when PREDIV_S >= SS
mbed_official 532:fe11edbda85c 554 * @note You must call HAL_RTC_GetDate() after HAL_RTC_GetTime() to unlock the values
mbed_official 613:bc40b8d2aec4 555 * in the higher-order calendar shadow registers to ensure consistency between the time and date values.
mbed_official 613:bc40b8d2aec4 556 * Reading RTC current time locks the values in calendar shadow registers until current date is read.
mbed_official 235:685d5f11838f 557 * @retval HAL status
mbed_official 235:685d5f11838f 558 */
mbed_official 235:685d5f11838f 559 HAL_StatusTypeDef HAL_RTC_GetTime(RTC_HandleTypeDef *hrtc, RTC_TimeTypeDef *sTime, uint32_t Format)
mbed_official 235:685d5f11838f 560 {
mbed_official 235:685d5f11838f 561 uint32_t tmpreg = 0;
mbed_official 235:685d5f11838f 562
mbed_official 235:685d5f11838f 563 /* Check the parameters */
mbed_official 235:685d5f11838f 564 assert_param(IS_RTC_FORMAT(Format));
mbed_official 235:685d5f11838f 565
mbed_official 613:bc40b8d2aec4 566 /* Get subseconds structure field from the corresponding register */
mbed_official 235:685d5f11838f 567 sTime->SubSeconds = (uint32_t)(hrtc->Instance->SSR);
mbed_official 235:685d5f11838f 568
mbed_official 613:bc40b8d2aec4 569 /* Get SecondFraction structure field from the corresponding register field */
mbed_official 613:bc40b8d2aec4 570 sTime->SecondFraction = (uint32_t)(hrtc->Instance->PRER & RTC_PRER_PREDIV_S);
mbed_official 613:bc40b8d2aec4 571
mbed_official 235:685d5f11838f 572 /* Get the TR register */
mbed_official 235:685d5f11838f 573 tmpreg = (uint32_t)(hrtc->Instance->TR & RTC_TR_RESERVED_MASK);
mbed_official 235:685d5f11838f 574
mbed_official 235:685d5f11838f 575 /* Fill the structure fields with the read parameters */
mbed_official 235:685d5f11838f 576 sTime->Hours = (uint8_t)((tmpreg & (RTC_TR_HT | RTC_TR_HU)) >> 16);
mbed_official 235:685d5f11838f 577 sTime->Minutes = (uint8_t)((tmpreg & (RTC_TR_MNT | RTC_TR_MNU)) >>8);
mbed_official 235:685d5f11838f 578 sTime->Seconds = (uint8_t)(tmpreg & (RTC_TR_ST | RTC_TR_SU));
mbed_official 235:685d5f11838f 579 sTime->TimeFormat = (uint8_t)((tmpreg & (RTC_TR_PM)) >> 16);
mbed_official 235:685d5f11838f 580
mbed_official 235:685d5f11838f 581 /* Check the input parameters format */
mbed_official 532:fe11edbda85c 582 if(Format == RTC_FORMAT_BIN)
mbed_official 235:685d5f11838f 583 {
mbed_official 235:685d5f11838f 584 /* Convert the time structure parameters to Binary format */
mbed_official 235:685d5f11838f 585 sTime->Hours = (uint8_t)RTC_Bcd2ToByte(sTime->Hours);
mbed_official 235:685d5f11838f 586 sTime->Minutes = (uint8_t)RTC_Bcd2ToByte(sTime->Minutes);
mbed_official 235:685d5f11838f 587 sTime->Seconds = (uint8_t)RTC_Bcd2ToByte(sTime->Seconds);
mbed_official 235:685d5f11838f 588 }
mbed_official 235:685d5f11838f 589
mbed_official 235:685d5f11838f 590 return HAL_OK;
mbed_official 235:685d5f11838f 591 }
mbed_official 235:685d5f11838f 592
mbed_official 235:685d5f11838f 593 /**
mbed_official 235:685d5f11838f 594 * @brief Sets RTC current date.
mbed_official 235:685d5f11838f 595 * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains
mbed_official 235:685d5f11838f 596 * the configuration information for RTC.
mbed_official 235:685d5f11838f 597 * @param sDate: Pointer to date structure
mbed_official 235:685d5f11838f 598 * @param Format: specifies the format of the entered parameters.
mbed_official 235:685d5f11838f 599 * This parameter can be one of the following values:
mbed_official 532:fe11edbda85c 600 * @arg RTC_FORMAT_BIN: Binary data format
mbed_official 532:fe11edbda85c 601 * @arg RTC_FORMAT_BCD: BCD data format
mbed_official 235:685d5f11838f 602 * @retval HAL status
mbed_official 235:685d5f11838f 603 */
mbed_official 235:685d5f11838f 604 HAL_StatusTypeDef HAL_RTC_SetDate(RTC_HandleTypeDef *hrtc, RTC_DateTypeDef *sDate, uint32_t Format)
mbed_official 235:685d5f11838f 605 {
mbed_official 235:685d5f11838f 606 uint32_t datetmpreg = 0;
mbed_official 235:685d5f11838f 607
mbed_official 235:685d5f11838f 608 /* Check the parameters */
mbed_official 235:685d5f11838f 609 assert_param(IS_RTC_FORMAT(Format));
mbed_official 235:685d5f11838f 610
mbed_official 235:685d5f11838f 611 /* Process Locked */
mbed_official 235:685d5f11838f 612 __HAL_LOCK(hrtc);
mbed_official 235:685d5f11838f 613
mbed_official 235:685d5f11838f 614 hrtc->State = HAL_RTC_STATE_BUSY;
mbed_official 235:685d5f11838f 615
mbed_official 532:fe11edbda85c 616 if((Format == RTC_FORMAT_BIN) && ((sDate->Month & 0x10) == 0x10))
mbed_official 235:685d5f11838f 617 {
mbed_official 235:685d5f11838f 618 sDate->Month = (uint8_t)((sDate->Month & (uint8_t)~(0x10)) + (uint8_t)0x0A);
mbed_official 235:685d5f11838f 619 }
mbed_official 235:685d5f11838f 620
mbed_official 235:685d5f11838f 621 assert_param(IS_RTC_WEEKDAY(sDate->WeekDay));
mbed_official 235:685d5f11838f 622
mbed_official 532:fe11edbda85c 623 if(Format == RTC_FORMAT_BIN)
mbed_official 235:685d5f11838f 624 {
mbed_official 235:685d5f11838f 625 assert_param(IS_RTC_YEAR(sDate->Year));
mbed_official 235:685d5f11838f 626 assert_param(IS_RTC_MONTH(sDate->Month));
mbed_official 235:685d5f11838f 627 assert_param(IS_RTC_DATE(sDate->Date));
mbed_official 235:685d5f11838f 628
mbed_official 235:685d5f11838f 629 datetmpreg = (((uint32_t)RTC_ByteToBcd2(sDate->Year) << 16) | \
mbed_official 235:685d5f11838f 630 ((uint32_t)RTC_ByteToBcd2(sDate->Month) << 8) | \
mbed_official 235:685d5f11838f 631 ((uint32_t)RTC_ByteToBcd2(sDate->Date)) | \
mbed_official 235:685d5f11838f 632 ((uint32_t)sDate->WeekDay << 13));
mbed_official 235:685d5f11838f 633 }
mbed_official 235:685d5f11838f 634 else
mbed_official 235:685d5f11838f 635 {
mbed_official 235:685d5f11838f 636 assert_param(IS_RTC_YEAR(RTC_Bcd2ToByte(sDate->Year)));
mbed_official 235:685d5f11838f 637 datetmpreg = RTC_Bcd2ToByte(sDate->Month);
mbed_official 235:685d5f11838f 638 assert_param(IS_RTC_MONTH(datetmpreg));
mbed_official 235:685d5f11838f 639 datetmpreg = RTC_Bcd2ToByte(sDate->Date);
mbed_official 235:685d5f11838f 640 assert_param(IS_RTC_DATE(datetmpreg));
mbed_official 235:685d5f11838f 641
mbed_official 235:685d5f11838f 642 datetmpreg = ((((uint32_t)sDate->Year) << 16) | \
mbed_official 235:685d5f11838f 643 (((uint32_t)sDate->Month) << 8) | \
mbed_official 235:685d5f11838f 644 ((uint32_t)sDate->Date) | \
mbed_official 235:685d5f11838f 645 (((uint32_t)sDate->WeekDay) << 13));
mbed_official 235:685d5f11838f 646 }
mbed_official 235:685d5f11838f 647
mbed_official 235:685d5f11838f 648 /* Disable the write protection for RTC registers */
mbed_official 235:685d5f11838f 649 __HAL_RTC_WRITEPROTECTION_DISABLE(hrtc);
mbed_official 235:685d5f11838f 650
mbed_official 235:685d5f11838f 651 /* Set Initialization mode */
mbed_official 235:685d5f11838f 652 if(RTC_EnterInitMode(hrtc) != HAL_OK)
mbed_official 235:685d5f11838f 653 {
mbed_official 235:685d5f11838f 654 /* Enable the write protection for RTC registers */
mbed_official 235:685d5f11838f 655 __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc);
mbed_official 235:685d5f11838f 656
mbed_official 235:685d5f11838f 657 /* Set RTC state*/
mbed_official 235:685d5f11838f 658 hrtc->State = HAL_RTC_STATE_ERROR;
mbed_official 235:685d5f11838f 659
mbed_official 235:685d5f11838f 660 /* Process Unlocked */
mbed_official 235:685d5f11838f 661 __HAL_UNLOCK(hrtc);
mbed_official 235:685d5f11838f 662
mbed_official 235:685d5f11838f 663 return HAL_ERROR;
mbed_official 235:685d5f11838f 664 }
mbed_official 235:685d5f11838f 665 else
mbed_official 235:685d5f11838f 666 {
mbed_official 235:685d5f11838f 667 /* Set the RTC_DR register */
mbed_official 235:685d5f11838f 668 hrtc->Instance->DR = (uint32_t)(datetmpreg & RTC_DR_RESERVED_MASK);
mbed_official 235:685d5f11838f 669
mbed_official 235:685d5f11838f 670 /* Exit Initialization mode */
mbed_official 235:685d5f11838f 671 hrtc->Instance->ISR &= (uint32_t)~RTC_ISR_INIT;
mbed_official 235:685d5f11838f 672
mbed_official 235:685d5f11838f 673 /* If CR_BYPSHAD bit = 0, wait for synchro else this check is not needed */
mbed_official 235:685d5f11838f 674 if((hrtc->Instance->CR & RTC_CR_BYPSHAD) == RESET)
mbed_official 235:685d5f11838f 675 {
mbed_official 235:685d5f11838f 676 if(HAL_RTC_WaitForSynchro(hrtc) != HAL_OK)
mbed_official 235:685d5f11838f 677 {
mbed_official 235:685d5f11838f 678 /* Enable the write protection for RTC registers */
mbed_official 235:685d5f11838f 679 __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc);
mbed_official 235:685d5f11838f 680
mbed_official 235:685d5f11838f 681 hrtc->State = HAL_RTC_STATE_ERROR;
mbed_official 235:685d5f11838f 682
mbed_official 235:685d5f11838f 683 /* Process Unlocked */
mbed_official 235:685d5f11838f 684 __HAL_UNLOCK(hrtc);
mbed_official 235:685d5f11838f 685
mbed_official 235:685d5f11838f 686 return HAL_ERROR;
mbed_official 235:685d5f11838f 687 }
mbed_official 235:685d5f11838f 688 }
mbed_official 235:685d5f11838f 689
mbed_official 235:685d5f11838f 690 /* Enable the write protection for RTC registers */
mbed_official 235:685d5f11838f 691 __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc);
mbed_official 235:685d5f11838f 692
mbed_official 235:685d5f11838f 693 hrtc->State = HAL_RTC_STATE_READY ;
mbed_official 235:685d5f11838f 694
mbed_official 235:685d5f11838f 695 /* Process Unlocked */
mbed_official 235:685d5f11838f 696 __HAL_UNLOCK(hrtc);
mbed_official 235:685d5f11838f 697
mbed_official 235:685d5f11838f 698 return HAL_OK;
mbed_official 235:685d5f11838f 699 }
mbed_official 235:685d5f11838f 700 }
mbed_official 235:685d5f11838f 701
mbed_official 235:685d5f11838f 702 /**
mbed_official 235:685d5f11838f 703 * @brief Gets RTC current date.
mbed_official 235:685d5f11838f 704 * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains
mbed_official 235:685d5f11838f 705 * the configuration information for RTC.
mbed_official 235:685d5f11838f 706 * @param sDate: Pointer to Date structure
mbed_official 235:685d5f11838f 707 * @param Format: Specifies the format of the entered parameters.
mbed_official 235:685d5f11838f 708 * This parameter can be one of the following values:
mbed_official 532:fe11edbda85c 709 * @arg RTC_FORMAT_BIN: Binary data format
mbed_official 532:fe11edbda85c 710 * @arg RTC_FORMAT_BCD: BCD data format
mbed_official 532:fe11edbda85c 711 * @note You must call HAL_RTC_GetDate() after HAL_RTC_GetTime() to unlock the values
mbed_official 532:fe11edbda85c 712 * in the higher-order calendar shadow registers to ensure consistency between the time and date values.
mbed_official 532:fe11edbda85c 713 * Reading RTC current time locks the values in calendar shadow registers until Current date is read.
mbed_official 235:685d5f11838f 714 * @retval HAL status
mbed_official 235:685d5f11838f 715 */
mbed_official 235:685d5f11838f 716 HAL_StatusTypeDef HAL_RTC_GetDate(RTC_HandleTypeDef *hrtc, RTC_DateTypeDef *sDate, uint32_t Format)
mbed_official 235:685d5f11838f 717 {
mbed_official 235:685d5f11838f 718 uint32_t datetmpreg = 0;
mbed_official 235:685d5f11838f 719
mbed_official 235:685d5f11838f 720 /* Check the parameters */
mbed_official 235:685d5f11838f 721 assert_param(IS_RTC_FORMAT(Format));
mbed_official 235:685d5f11838f 722
mbed_official 235:685d5f11838f 723 /* Get the DR register */
mbed_official 235:685d5f11838f 724 datetmpreg = (uint32_t)(hrtc->Instance->DR & RTC_DR_RESERVED_MASK);
mbed_official 235:685d5f11838f 725
mbed_official 235:685d5f11838f 726 /* Fill the structure fields with the read parameters */
mbed_official 235:685d5f11838f 727 sDate->Year = (uint8_t)((datetmpreg & (RTC_DR_YT | RTC_DR_YU)) >> 16);
mbed_official 235:685d5f11838f 728 sDate->Month = (uint8_t)((datetmpreg & (RTC_DR_MT | RTC_DR_MU)) >> 8);
mbed_official 235:685d5f11838f 729 sDate->Date = (uint8_t)(datetmpreg & (RTC_DR_DT | RTC_DR_DU));
mbed_official 235:685d5f11838f 730 sDate->WeekDay = (uint8_t)((datetmpreg & (RTC_DR_WDU)) >> 13);
mbed_official 235:685d5f11838f 731
mbed_official 235:685d5f11838f 732 /* Check the input parameters format */
mbed_official 532:fe11edbda85c 733 if(Format == RTC_FORMAT_BIN)
mbed_official 235:685d5f11838f 734 {
mbed_official 235:685d5f11838f 735 /* Convert the date structure parameters to Binary format */
mbed_official 235:685d5f11838f 736 sDate->Year = (uint8_t)RTC_Bcd2ToByte(sDate->Year);
mbed_official 235:685d5f11838f 737 sDate->Month = (uint8_t)RTC_Bcd2ToByte(sDate->Month);
mbed_official 235:685d5f11838f 738 sDate->Date = (uint8_t)RTC_Bcd2ToByte(sDate->Date);
mbed_official 235:685d5f11838f 739 }
mbed_official 235:685d5f11838f 740 return HAL_OK;
mbed_official 235:685d5f11838f 741 }
mbed_official 235:685d5f11838f 742
mbed_official 235:685d5f11838f 743 /**
mbed_official 235:685d5f11838f 744 * @}
mbed_official 235:685d5f11838f 745 */
mbed_official 235:685d5f11838f 746
mbed_official 532:fe11edbda85c 747 /** @defgroup RTC_Exported_Functions_Group3 RTC Alarm functions
mbed_official 235:685d5f11838f 748 * @brief RTC Alarm functions
mbed_official 235:685d5f11838f 749 *
mbed_official 235:685d5f11838f 750 @verbatim
mbed_official 235:685d5f11838f 751 ===============================================================================
mbed_official 235:685d5f11838f 752 ##### RTC Alarm functions #####
mbed_official 235:685d5f11838f 753 ===============================================================================
mbed_official 235:685d5f11838f 754
mbed_official 235:685d5f11838f 755 [..] This section provides functions allowing to configure Alarm feature
mbed_official 235:685d5f11838f 756
mbed_official 235:685d5f11838f 757 @endverbatim
mbed_official 235:685d5f11838f 758 * @{
mbed_official 235:685d5f11838f 759 */
mbed_official 235:685d5f11838f 760 /**
mbed_official 235:685d5f11838f 761 * @brief Sets the specified RTC Alarm.
mbed_official 235:685d5f11838f 762 * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains
mbed_official 235:685d5f11838f 763 * the configuration information for RTC.
mbed_official 235:685d5f11838f 764 * @param sAlarm: Pointer to Alarm structure
mbed_official 235:685d5f11838f 765 * @param Format: Specifies the format of the entered parameters.
mbed_official 235:685d5f11838f 766 * This parameter can be one of the following values:
mbed_official 532:fe11edbda85c 767 * @arg RTC_FORMAT_BIN: Binary data format
mbed_official 532:fe11edbda85c 768 * @arg RTC_FORMAT_BCD: BCD data format
mbed_official 235:685d5f11838f 769 * @retval HAL status
mbed_official 235:685d5f11838f 770 */
mbed_official 235:685d5f11838f 771 HAL_StatusTypeDef HAL_RTC_SetAlarm(RTC_HandleTypeDef *hrtc, RTC_AlarmTypeDef *sAlarm, uint32_t Format)
mbed_official 235:685d5f11838f 772 {
mbed_official 235:685d5f11838f 773 uint32_t tickstart = 0;
mbed_official 235:685d5f11838f 774 uint32_t tmpreg = 0, subsecondtmpreg = 0;
mbed_official 235:685d5f11838f 775
mbed_official 235:685d5f11838f 776 /* Check the parameters */
mbed_official 235:685d5f11838f 777 assert_param(IS_RTC_FORMAT(Format));
mbed_official 532:fe11edbda85c 778 assert_param(IS_RTC_ALARM(sAlarm->Alarm));
mbed_official 532:fe11edbda85c 779 assert_param(IS_RTC_ALARM_MASK(sAlarm->AlarmMask));
mbed_official 235:685d5f11838f 780 assert_param(IS_RTC_ALARM_DATE_WEEKDAY_SEL(sAlarm->AlarmDateWeekDaySel));
mbed_official 235:685d5f11838f 781 assert_param(IS_RTC_ALARM_SUB_SECOND_VALUE(sAlarm->AlarmTime.SubSeconds));
mbed_official 235:685d5f11838f 782 assert_param(IS_RTC_ALARM_SUB_SECOND_MASK(sAlarm->AlarmSubSecondMask));
mbed_official 235:685d5f11838f 783
mbed_official 235:685d5f11838f 784 /* Process Locked */
mbed_official 235:685d5f11838f 785 __HAL_LOCK(hrtc);
mbed_official 235:685d5f11838f 786
mbed_official 235:685d5f11838f 787 hrtc->State = HAL_RTC_STATE_BUSY;
mbed_official 235:685d5f11838f 788
mbed_official 532:fe11edbda85c 789 if(Format == RTC_FORMAT_BIN)
mbed_official 235:685d5f11838f 790 {
mbed_official 235:685d5f11838f 791 if((hrtc->Instance->CR & RTC_CR_FMT) != (uint32_t)RESET)
mbed_official 235:685d5f11838f 792 {
mbed_official 235:685d5f11838f 793 assert_param(IS_RTC_HOUR12(sAlarm->AlarmTime.Hours));
mbed_official 235:685d5f11838f 794 assert_param(IS_RTC_HOURFORMAT12(sAlarm->AlarmTime.TimeFormat));
mbed_official 235:685d5f11838f 795 }
mbed_official 235:685d5f11838f 796 else
mbed_official 235:685d5f11838f 797 {
mbed_official 235:685d5f11838f 798 sAlarm->AlarmTime.TimeFormat = 0x00;
mbed_official 235:685d5f11838f 799 assert_param(IS_RTC_HOUR24(sAlarm->AlarmTime.Hours));
mbed_official 235:685d5f11838f 800 }
mbed_official 235:685d5f11838f 801 assert_param(IS_RTC_MINUTES(sAlarm->AlarmTime.Minutes));
mbed_official 235:685d5f11838f 802 assert_param(IS_RTC_SECONDS(sAlarm->AlarmTime.Seconds));
mbed_official 235:685d5f11838f 803
mbed_official 235:685d5f11838f 804 if(sAlarm->AlarmDateWeekDaySel == RTC_ALARMDATEWEEKDAYSEL_DATE)
mbed_official 235:685d5f11838f 805 {
mbed_official 235:685d5f11838f 806 assert_param(IS_RTC_ALARM_DATE_WEEKDAY_DATE(sAlarm->AlarmDateWeekDay));
mbed_official 235:685d5f11838f 807 }
mbed_official 235:685d5f11838f 808 else
mbed_official 235:685d5f11838f 809 {
mbed_official 235:685d5f11838f 810 assert_param(IS_RTC_ALARM_DATE_WEEKDAY_WEEKDAY(sAlarm->AlarmDateWeekDay));
mbed_official 235:685d5f11838f 811 }
mbed_official 235:685d5f11838f 812
mbed_official 235:685d5f11838f 813 tmpreg = (((uint32_t)RTC_ByteToBcd2(sAlarm->AlarmTime.Hours) << 16) | \
mbed_official 235:685d5f11838f 814 ((uint32_t)RTC_ByteToBcd2(sAlarm->AlarmTime.Minutes) << 8) | \
mbed_official 235:685d5f11838f 815 ((uint32_t)RTC_ByteToBcd2(sAlarm->AlarmTime.Seconds)) | \
mbed_official 235:685d5f11838f 816 ((uint32_t)(sAlarm->AlarmTime.TimeFormat) << 16) | \
mbed_official 235:685d5f11838f 817 ((uint32_t)RTC_ByteToBcd2(sAlarm->AlarmDateWeekDay) << 24) | \
mbed_official 235:685d5f11838f 818 ((uint32_t)sAlarm->AlarmDateWeekDaySel) | \
mbed_official 235:685d5f11838f 819 ((uint32_t)sAlarm->AlarmMask));
mbed_official 235:685d5f11838f 820 }
mbed_official 235:685d5f11838f 821 else
mbed_official 235:685d5f11838f 822 {
mbed_official 235:685d5f11838f 823 if((hrtc->Instance->CR & RTC_CR_FMT) != (uint32_t)RESET)
mbed_official 235:685d5f11838f 824 {
mbed_official 235:685d5f11838f 825 tmpreg = RTC_Bcd2ToByte(sAlarm->AlarmTime.Hours);
mbed_official 235:685d5f11838f 826 assert_param(IS_RTC_HOUR12(tmpreg));
mbed_official 235:685d5f11838f 827 assert_param(IS_RTC_HOURFORMAT12(sAlarm->AlarmTime.TimeFormat));
mbed_official 235:685d5f11838f 828 }
mbed_official 235:685d5f11838f 829 else
mbed_official 235:685d5f11838f 830 {
mbed_official 235:685d5f11838f 831 sAlarm->AlarmTime.TimeFormat = 0x00;
mbed_official 235:685d5f11838f 832 assert_param(IS_RTC_HOUR24(RTC_Bcd2ToByte(sAlarm->AlarmTime.Hours)));
mbed_official 235:685d5f11838f 833 }
mbed_official 235:685d5f11838f 834
mbed_official 235:685d5f11838f 835 assert_param(IS_RTC_MINUTES(RTC_Bcd2ToByte(sAlarm->AlarmTime.Minutes)));
mbed_official 235:685d5f11838f 836 assert_param(IS_RTC_SECONDS(RTC_Bcd2ToByte(sAlarm->AlarmTime.Seconds)));
mbed_official 235:685d5f11838f 837
mbed_official 235:685d5f11838f 838 if(sAlarm->AlarmDateWeekDaySel == RTC_ALARMDATEWEEKDAYSEL_DATE)
mbed_official 235:685d5f11838f 839 {
mbed_official 235:685d5f11838f 840 tmpreg = RTC_Bcd2ToByte(sAlarm->AlarmDateWeekDay);
mbed_official 235:685d5f11838f 841 assert_param(IS_RTC_ALARM_DATE_WEEKDAY_DATE(tmpreg));
mbed_official 235:685d5f11838f 842 }
mbed_official 235:685d5f11838f 843 else
mbed_official 235:685d5f11838f 844 {
mbed_official 235:685d5f11838f 845 tmpreg = RTC_Bcd2ToByte(sAlarm->AlarmDateWeekDay);
mbed_official 235:685d5f11838f 846 assert_param(IS_RTC_ALARM_DATE_WEEKDAY_WEEKDAY(tmpreg));
mbed_official 235:685d5f11838f 847 }
mbed_official 235:685d5f11838f 848
mbed_official 235:685d5f11838f 849 tmpreg = (((uint32_t)(sAlarm->AlarmTime.Hours) << 16) | \
mbed_official 235:685d5f11838f 850 ((uint32_t)(sAlarm->AlarmTime.Minutes) << 8) | \
mbed_official 235:685d5f11838f 851 ((uint32_t) sAlarm->AlarmTime.Seconds) | \
mbed_official 235:685d5f11838f 852 ((uint32_t)(sAlarm->AlarmTime.TimeFormat) << 16) | \
mbed_official 235:685d5f11838f 853 ((uint32_t)(sAlarm->AlarmDateWeekDay) << 24) | \
mbed_official 235:685d5f11838f 854 ((uint32_t)sAlarm->AlarmDateWeekDaySel) | \
mbed_official 235:685d5f11838f 855 ((uint32_t)sAlarm->AlarmMask));
mbed_official 235:685d5f11838f 856 }
mbed_official 235:685d5f11838f 857
mbed_official 235:685d5f11838f 858 /* Configure the Alarm A or Alarm B Sub Second registers */
mbed_official 235:685d5f11838f 859 subsecondtmpreg = (uint32_t)((uint32_t)(sAlarm->AlarmTime.SubSeconds) | (uint32_t)(sAlarm->AlarmSubSecondMask));
mbed_official 235:685d5f11838f 860
mbed_official 235:685d5f11838f 861 /* Disable the write protection for RTC registers */
mbed_official 235:685d5f11838f 862 __HAL_RTC_WRITEPROTECTION_DISABLE(hrtc);
mbed_official 235:685d5f11838f 863
mbed_official 235:685d5f11838f 864 /* Configure the Alarm register */
mbed_official 235:685d5f11838f 865 if(sAlarm->Alarm == RTC_ALARM_A)
mbed_official 235:685d5f11838f 866 {
mbed_official 235:685d5f11838f 867 /* Disable the Alarm A interrupt */
mbed_official 235:685d5f11838f 868 __HAL_RTC_ALARMA_DISABLE(hrtc);
mbed_official 235:685d5f11838f 869
mbed_official 235:685d5f11838f 870 /* In case of interrupt mode is used, the interrupt source must disabled */
mbed_official 235:685d5f11838f 871 __HAL_RTC_ALARM_DISABLE_IT(hrtc, RTC_IT_ALRA);
mbed_official 235:685d5f11838f 872
mbed_official 235:685d5f11838f 873 /* Get tick */
mbed_official 235:685d5f11838f 874 tickstart = HAL_GetTick();
mbed_official 235:685d5f11838f 875
mbed_official 235:685d5f11838f 876 /* Wait till RTC ALRAWF flag is set and if Time out is reached exit */
mbed_official 235:685d5f11838f 877 while(__HAL_RTC_ALARM_GET_FLAG(hrtc, RTC_FLAG_ALRAWF) == RESET)
mbed_official 235:685d5f11838f 878 {
mbed_official 235:685d5f11838f 879 if((HAL_GetTick() - tickstart ) > RTC_TIMEOUT_VALUE)
mbed_official 235:685d5f11838f 880 {
mbed_official 235:685d5f11838f 881 /* Enable the write protection for RTC registers */
mbed_official 235:685d5f11838f 882 __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc);
mbed_official 235:685d5f11838f 883
mbed_official 235:685d5f11838f 884 hrtc->State = HAL_RTC_STATE_TIMEOUT;
mbed_official 235:685d5f11838f 885
mbed_official 235:685d5f11838f 886 /* Process Unlocked */
mbed_official 235:685d5f11838f 887 __HAL_UNLOCK(hrtc);
mbed_official 235:685d5f11838f 888
mbed_official 235:685d5f11838f 889 return HAL_TIMEOUT;
mbed_official 235:685d5f11838f 890 }
mbed_official 235:685d5f11838f 891 }
mbed_official 235:685d5f11838f 892
mbed_official 235:685d5f11838f 893 hrtc->Instance->ALRMAR = (uint32_t)tmpreg;
mbed_official 235:685d5f11838f 894 /* Configure the Alarm A Sub Second register */
mbed_official 235:685d5f11838f 895 hrtc->Instance->ALRMASSR = subsecondtmpreg;
mbed_official 235:685d5f11838f 896 /* Configure the Alarm state: Enable Alarm */
mbed_official 235:685d5f11838f 897 __HAL_RTC_ALARMA_ENABLE(hrtc);
mbed_official 235:685d5f11838f 898 }
mbed_official 235:685d5f11838f 899 else
mbed_official 235:685d5f11838f 900 {
mbed_official 235:685d5f11838f 901 /* Disable the Alarm B interrupt */
mbed_official 235:685d5f11838f 902 __HAL_RTC_ALARMB_DISABLE(hrtc);
mbed_official 235:685d5f11838f 903
mbed_official 235:685d5f11838f 904 /* In case of interrupt mode is used, the interrupt source must disabled */
mbed_official 235:685d5f11838f 905 __HAL_RTC_ALARM_DISABLE_IT(hrtc, RTC_IT_ALRB);
mbed_official 235:685d5f11838f 906
mbed_official 235:685d5f11838f 907 /* Get tick */
mbed_official 235:685d5f11838f 908 tickstart = HAL_GetTick();
mbed_official 235:685d5f11838f 909
mbed_official 235:685d5f11838f 910 /* Wait till RTC ALRBWF flag is set and if Time out is reached exit */
mbed_official 235:685d5f11838f 911 while(__HAL_RTC_ALARM_GET_FLAG(hrtc, RTC_FLAG_ALRBWF) == RESET)
mbed_official 235:685d5f11838f 912 {
mbed_official 235:685d5f11838f 913 if((HAL_GetTick() - tickstart ) > RTC_TIMEOUT_VALUE)
mbed_official 235:685d5f11838f 914 {
mbed_official 235:685d5f11838f 915 /* Enable the write protection for RTC registers */
mbed_official 235:685d5f11838f 916 __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc);
mbed_official 235:685d5f11838f 917
mbed_official 235:685d5f11838f 918 hrtc->State = HAL_RTC_STATE_TIMEOUT;
mbed_official 235:685d5f11838f 919
mbed_official 235:685d5f11838f 920 /* Process Unlocked */
mbed_official 235:685d5f11838f 921 __HAL_UNLOCK(hrtc);
mbed_official 235:685d5f11838f 922
mbed_official 235:685d5f11838f 923 return HAL_TIMEOUT;
mbed_official 235:685d5f11838f 924 }
mbed_official 235:685d5f11838f 925 }
mbed_official 235:685d5f11838f 926
mbed_official 235:685d5f11838f 927 hrtc->Instance->ALRMBR = (uint32_t)tmpreg;
mbed_official 235:685d5f11838f 928 /* Configure the Alarm B Sub Second register */
mbed_official 235:685d5f11838f 929 hrtc->Instance->ALRMBSSR = subsecondtmpreg;
mbed_official 235:685d5f11838f 930 /* Configure the Alarm state: Enable Alarm */
mbed_official 235:685d5f11838f 931 __HAL_RTC_ALARMB_ENABLE(hrtc);
mbed_official 235:685d5f11838f 932 }
mbed_official 235:685d5f11838f 933
mbed_official 235:685d5f11838f 934 /* Enable the write protection for RTC registers */
mbed_official 235:685d5f11838f 935 __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc);
mbed_official 235:685d5f11838f 936
mbed_official 235:685d5f11838f 937 /* Change RTC state */
mbed_official 235:685d5f11838f 938 hrtc->State = HAL_RTC_STATE_READY;
mbed_official 235:685d5f11838f 939
mbed_official 235:685d5f11838f 940 /* Process Unlocked */
mbed_official 235:685d5f11838f 941 __HAL_UNLOCK(hrtc);
mbed_official 235:685d5f11838f 942
mbed_official 235:685d5f11838f 943 return HAL_OK;
mbed_official 235:685d5f11838f 944 }
mbed_official 235:685d5f11838f 945
mbed_official 235:685d5f11838f 946 /**
mbed_official 235:685d5f11838f 947 * @brief Sets the specified RTC Alarm with Interrupt
mbed_official 235:685d5f11838f 948 * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains
mbed_official 235:685d5f11838f 949 * the configuration information for RTC.
mbed_official 235:685d5f11838f 950 * @param sAlarm: Pointer to Alarm structure
mbed_official 235:685d5f11838f 951 * @param Format: Specifies the format of the entered parameters.
mbed_official 235:685d5f11838f 952 * This parameter can be one of the following values:
mbed_official 532:fe11edbda85c 953 * @arg RTC_FORMAT_BIN: Binary data format
mbed_official 532:fe11edbda85c 954 * @arg RTC_FORMAT_BCD: BCD data format
mbed_official 235:685d5f11838f 955 * @retval HAL status
mbed_official 235:685d5f11838f 956 */
mbed_official 235:685d5f11838f 957 HAL_StatusTypeDef HAL_RTC_SetAlarm_IT(RTC_HandleTypeDef *hrtc, RTC_AlarmTypeDef *sAlarm, uint32_t Format)
mbed_official 235:685d5f11838f 958 {
mbed_official 235:685d5f11838f 959 uint32_t tickstart = 0;
mbed_official 235:685d5f11838f 960 uint32_t tmpreg = 0, subsecondtmpreg = 0;
mbed_official 235:685d5f11838f 961
mbed_official 235:685d5f11838f 962 /* Check the parameters */
mbed_official 235:685d5f11838f 963 assert_param(IS_RTC_FORMAT(Format));
mbed_official 532:fe11edbda85c 964 assert_param(IS_RTC_ALARM(sAlarm->Alarm));
mbed_official 532:fe11edbda85c 965 assert_param(IS_RTC_ALARM_MASK(sAlarm->AlarmMask));
mbed_official 235:685d5f11838f 966 assert_param(IS_RTC_ALARM_DATE_WEEKDAY_SEL(sAlarm->AlarmDateWeekDaySel));
mbed_official 235:685d5f11838f 967 assert_param(IS_RTC_ALARM_SUB_SECOND_VALUE(sAlarm->AlarmTime.SubSeconds));
mbed_official 235:685d5f11838f 968 assert_param(IS_RTC_ALARM_SUB_SECOND_MASK(sAlarm->AlarmSubSecondMask));
mbed_official 235:685d5f11838f 969
mbed_official 235:685d5f11838f 970 /* Process Locked */
mbed_official 235:685d5f11838f 971 __HAL_LOCK(hrtc);
mbed_official 235:685d5f11838f 972
mbed_official 235:685d5f11838f 973 hrtc->State = HAL_RTC_STATE_BUSY;
mbed_official 235:685d5f11838f 974
mbed_official 532:fe11edbda85c 975 if(Format == RTC_FORMAT_BIN)
mbed_official 235:685d5f11838f 976 {
mbed_official 235:685d5f11838f 977 if((hrtc->Instance->CR & RTC_CR_FMT) != (uint32_t)RESET)
mbed_official 235:685d5f11838f 978 {
mbed_official 235:685d5f11838f 979 assert_param(IS_RTC_HOUR12(sAlarm->AlarmTime.Hours));
mbed_official 235:685d5f11838f 980 assert_param(IS_RTC_HOURFORMAT12(sAlarm->AlarmTime.TimeFormat));
mbed_official 235:685d5f11838f 981 }
mbed_official 235:685d5f11838f 982 else
mbed_official 235:685d5f11838f 983 {
mbed_official 235:685d5f11838f 984 sAlarm->AlarmTime.TimeFormat = 0x00;
mbed_official 235:685d5f11838f 985 assert_param(IS_RTC_HOUR24(sAlarm->AlarmTime.Hours));
mbed_official 235:685d5f11838f 986 }
mbed_official 235:685d5f11838f 987 assert_param(IS_RTC_MINUTES(sAlarm->AlarmTime.Minutes));
mbed_official 235:685d5f11838f 988 assert_param(IS_RTC_SECONDS(sAlarm->AlarmTime.Seconds));
mbed_official 235:685d5f11838f 989
mbed_official 235:685d5f11838f 990 if(sAlarm->AlarmDateWeekDaySel == RTC_ALARMDATEWEEKDAYSEL_DATE)
mbed_official 235:685d5f11838f 991 {
mbed_official 235:685d5f11838f 992 assert_param(IS_RTC_ALARM_DATE_WEEKDAY_DATE(sAlarm->AlarmDateWeekDay));
mbed_official 235:685d5f11838f 993 }
mbed_official 235:685d5f11838f 994 else
mbed_official 235:685d5f11838f 995 {
mbed_official 235:685d5f11838f 996 assert_param(IS_RTC_ALARM_DATE_WEEKDAY_WEEKDAY(sAlarm->AlarmDateWeekDay));
mbed_official 235:685d5f11838f 997 }
mbed_official 235:685d5f11838f 998 tmpreg = (((uint32_t)RTC_ByteToBcd2(sAlarm->AlarmTime.Hours) << 16) | \
mbed_official 235:685d5f11838f 999 ((uint32_t)RTC_ByteToBcd2(sAlarm->AlarmTime.Minutes) << 8) | \
mbed_official 235:685d5f11838f 1000 ((uint32_t)RTC_ByteToBcd2(sAlarm->AlarmTime.Seconds)) | \
mbed_official 235:685d5f11838f 1001 ((uint32_t)(sAlarm->AlarmTime.TimeFormat) << 16) | \
mbed_official 235:685d5f11838f 1002 ((uint32_t)RTC_ByteToBcd2(sAlarm->AlarmDateWeekDay) << 24) | \
mbed_official 235:685d5f11838f 1003 ((uint32_t)sAlarm->AlarmDateWeekDaySel) | \
mbed_official 235:685d5f11838f 1004 ((uint32_t)sAlarm->AlarmMask));
mbed_official 235:685d5f11838f 1005 }
mbed_official 235:685d5f11838f 1006 else
mbed_official 235:685d5f11838f 1007 {
mbed_official 235:685d5f11838f 1008 if((hrtc->Instance->CR & RTC_CR_FMT) != (uint32_t)RESET)
mbed_official 235:685d5f11838f 1009 {
mbed_official 235:685d5f11838f 1010 tmpreg = RTC_Bcd2ToByte(sAlarm->AlarmTime.Hours);
mbed_official 235:685d5f11838f 1011 assert_param(IS_RTC_HOUR12(tmpreg));
mbed_official 235:685d5f11838f 1012 assert_param(IS_RTC_HOURFORMAT12(sAlarm->AlarmTime.TimeFormat));
mbed_official 235:685d5f11838f 1013 }
mbed_official 235:685d5f11838f 1014 else
mbed_official 235:685d5f11838f 1015 {
mbed_official 235:685d5f11838f 1016 sAlarm->AlarmTime.TimeFormat = 0x00;
mbed_official 235:685d5f11838f 1017 assert_param(IS_RTC_HOUR24(RTC_Bcd2ToByte(sAlarm->AlarmTime.Hours)));
mbed_official 235:685d5f11838f 1018 }
mbed_official 235:685d5f11838f 1019
mbed_official 235:685d5f11838f 1020 assert_param(IS_RTC_MINUTES(RTC_Bcd2ToByte(sAlarm->AlarmTime.Minutes)));
mbed_official 235:685d5f11838f 1021 assert_param(IS_RTC_SECONDS(RTC_Bcd2ToByte(sAlarm->AlarmTime.Seconds)));
mbed_official 235:685d5f11838f 1022
mbed_official 235:685d5f11838f 1023 if(sAlarm->AlarmDateWeekDaySel == RTC_ALARMDATEWEEKDAYSEL_DATE)
mbed_official 235:685d5f11838f 1024 {
mbed_official 235:685d5f11838f 1025 tmpreg = RTC_Bcd2ToByte(sAlarm->AlarmDateWeekDay);
mbed_official 235:685d5f11838f 1026 assert_param(IS_RTC_ALARM_DATE_WEEKDAY_DATE(tmpreg));
mbed_official 235:685d5f11838f 1027 }
mbed_official 235:685d5f11838f 1028 else
mbed_official 235:685d5f11838f 1029 {
mbed_official 235:685d5f11838f 1030 tmpreg = RTC_Bcd2ToByte(sAlarm->AlarmDateWeekDay);
mbed_official 235:685d5f11838f 1031 assert_param(IS_RTC_ALARM_DATE_WEEKDAY_WEEKDAY(tmpreg));
mbed_official 235:685d5f11838f 1032 }
mbed_official 235:685d5f11838f 1033 tmpreg = (((uint32_t)(sAlarm->AlarmTime.Hours) << 16) | \
mbed_official 235:685d5f11838f 1034 ((uint32_t)(sAlarm->AlarmTime.Minutes) << 8) | \
mbed_official 235:685d5f11838f 1035 ((uint32_t) sAlarm->AlarmTime.Seconds) | \
mbed_official 235:685d5f11838f 1036 ((uint32_t)(sAlarm->AlarmTime.TimeFormat) << 16) | \
mbed_official 235:685d5f11838f 1037 ((uint32_t)(sAlarm->AlarmDateWeekDay) << 24) | \
mbed_official 235:685d5f11838f 1038 ((uint32_t)sAlarm->AlarmDateWeekDaySel) | \
mbed_official 235:685d5f11838f 1039 ((uint32_t)sAlarm->AlarmMask));
mbed_official 235:685d5f11838f 1040 }
mbed_official 235:685d5f11838f 1041 /* Configure the Alarm A or Alarm B Sub Second registers */
mbed_official 235:685d5f11838f 1042 subsecondtmpreg = (uint32_t)((uint32_t)(sAlarm->AlarmTime.SubSeconds) | (uint32_t)(sAlarm->AlarmSubSecondMask));
mbed_official 235:685d5f11838f 1043
mbed_official 235:685d5f11838f 1044 /* Disable the write protection for RTC registers */
mbed_official 235:685d5f11838f 1045 __HAL_RTC_WRITEPROTECTION_DISABLE(hrtc);
mbed_official 235:685d5f11838f 1046
mbed_official 235:685d5f11838f 1047 /* Configure the Alarm register */
mbed_official 235:685d5f11838f 1048 if(sAlarm->Alarm == RTC_ALARM_A)
mbed_official 235:685d5f11838f 1049 {
mbed_official 235:685d5f11838f 1050 /* Disable the Alarm A interrupt */
mbed_official 235:685d5f11838f 1051 __HAL_RTC_ALARMA_DISABLE(hrtc);
mbed_official 235:685d5f11838f 1052
mbed_official 235:685d5f11838f 1053 /* Clear flag alarm A */
mbed_official 235:685d5f11838f 1054 __HAL_RTC_ALARM_CLEAR_FLAG(hrtc, RTC_FLAG_ALRAF);
mbed_official 235:685d5f11838f 1055
mbed_official 235:685d5f11838f 1056 /* Get tick */
mbed_official 235:685d5f11838f 1057 tickstart = HAL_GetTick();
mbed_official 235:685d5f11838f 1058
mbed_official 235:685d5f11838f 1059 /* Wait till RTC ALRAWF flag is set and if Time out is reached exit */
mbed_official 235:685d5f11838f 1060 while(__HAL_RTC_ALARM_GET_FLAG(hrtc, RTC_FLAG_ALRAWF) == RESET)
mbed_official 235:685d5f11838f 1061 {
mbed_official 235:685d5f11838f 1062 if((HAL_GetTick() - tickstart ) > RTC_TIMEOUT_VALUE)
mbed_official 235:685d5f11838f 1063 {
mbed_official 235:685d5f11838f 1064 /* Enable the write protection for RTC registers */
mbed_official 235:685d5f11838f 1065 __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc);
mbed_official 235:685d5f11838f 1066
mbed_official 235:685d5f11838f 1067 hrtc->State = HAL_RTC_STATE_TIMEOUT;
mbed_official 235:685d5f11838f 1068
mbed_official 235:685d5f11838f 1069 /* Process Unlocked */
mbed_official 235:685d5f11838f 1070 __HAL_UNLOCK(hrtc);
mbed_official 235:685d5f11838f 1071
mbed_official 235:685d5f11838f 1072 return HAL_TIMEOUT;
mbed_official 235:685d5f11838f 1073 }
mbed_official 235:685d5f11838f 1074 }
mbed_official 235:685d5f11838f 1075
mbed_official 235:685d5f11838f 1076 hrtc->Instance->ALRMAR = (uint32_t)tmpreg;
mbed_official 235:685d5f11838f 1077 /* Configure the Alarm A Sub Second register */
mbed_official 235:685d5f11838f 1078 hrtc->Instance->ALRMASSR = subsecondtmpreg;
mbed_official 235:685d5f11838f 1079 /* Configure the Alarm state: Enable Alarm */
mbed_official 235:685d5f11838f 1080 __HAL_RTC_ALARMA_ENABLE(hrtc);
mbed_official 235:685d5f11838f 1081 /* Configure the Alarm interrupt */
mbed_official 235:685d5f11838f 1082 __HAL_RTC_ALARM_ENABLE_IT(hrtc,RTC_IT_ALRA);
mbed_official 235:685d5f11838f 1083 }
mbed_official 235:685d5f11838f 1084 else
mbed_official 235:685d5f11838f 1085 {
mbed_official 235:685d5f11838f 1086 /* Disable the Alarm B interrupt */
mbed_official 235:685d5f11838f 1087 __HAL_RTC_ALARMB_DISABLE(hrtc);
mbed_official 235:685d5f11838f 1088
mbed_official 235:685d5f11838f 1089 /* Clear flag alarm B */
mbed_official 235:685d5f11838f 1090 __HAL_RTC_ALARM_CLEAR_FLAG(hrtc, RTC_FLAG_ALRBF);
mbed_official 235:685d5f11838f 1091
mbed_official 235:685d5f11838f 1092 /* Get tick */
mbed_official 235:685d5f11838f 1093 tickstart = HAL_GetTick();
mbed_official 235:685d5f11838f 1094
mbed_official 235:685d5f11838f 1095 /* Wait till RTC ALRBWF flag is set and if Time out is reached exit */
mbed_official 235:685d5f11838f 1096 while(__HAL_RTC_ALARM_GET_FLAG(hrtc, RTC_FLAG_ALRBWF) == RESET)
mbed_official 235:685d5f11838f 1097 {
mbed_official 235:685d5f11838f 1098 if((HAL_GetTick() - tickstart ) > RTC_TIMEOUT_VALUE)
mbed_official 235:685d5f11838f 1099 {
mbed_official 235:685d5f11838f 1100 /* Enable the write protection for RTC registers */
mbed_official 235:685d5f11838f 1101 __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc);
mbed_official 235:685d5f11838f 1102
mbed_official 235:685d5f11838f 1103 hrtc->State = HAL_RTC_STATE_TIMEOUT;
mbed_official 235:685d5f11838f 1104
mbed_official 235:685d5f11838f 1105 /* Process Unlocked */
mbed_official 235:685d5f11838f 1106 __HAL_UNLOCK(hrtc);
mbed_official 235:685d5f11838f 1107
mbed_official 235:685d5f11838f 1108 return HAL_TIMEOUT;
mbed_official 235:685d5f11838f 1109 }
mbed_official 235:685d5f11838f 1110 }
mbed_official 235:685d5f11838f 1111
mbed_official 235:685d5f11838f 1112 hrtc->Instance->ALRMBR = (uint32_t)tmpreg;
mbed_official 235:685d5f11838f 1113 /* Configure the Alarm B Sub Second register */
mbed_official 235:685d5f11838f 1114 hrtc->Instance->ALRMBSSR = subsecondtmpreg;
mbed_official 235:685d5f11838f 1115 /* Configure the Alarm state: Enable Alarm */
mbed_official 235:685d5f11838f 1116 __HAL_RTC_ALARMB_ENABLE(hrtc);
mbed_official 235:685d5f11838f 1117 /* Configure the Alarm interrupt */
mbed_official 235:685d5f11838f 1118 __HAL_RTC_ALARM_ENABLE_IT(hrtc, RTC_IT_ALRB);
mbed_official 235:685d5f11838f 1119 }
mbed_official 235:685d5f11838f 1120
mbed_official 235:685d5f11838f 1121 /* RTC Alarm Interrupt Configuration: EXTI configuration */
mbed_official 532:fe11edbda85c 1122 __HAL_RTC_ALARM_EXTI_ENABLE_IT();
mbed_official 235:685d5f11838f 1123
mbed_official 235:685d5f11838f 1124 EXTI->RTSR |= RTC_EXTI_LINE_ALARM_EVENT;
mbed_official 235:685d5f11838f 1125
mbed_official 235:685d5f11838f 1126 /* Enable the write protection for RTC registers */
mbed_official 235:685d5f11838f 1127 __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc);
mbed_official 235:685d5f11838f 1128
mbed_official 235:685d5f11838f 1129 hrtc->State = HAL_RTC_STATE_READY;
mbed_official 235:685d5f11838f 1130
mbed_official 235:685d5f11838f 1131 /* Process Unlocked */
mbed_official 235:685d5f11838f 1132 __HAL_UNLOCK(hrtc);
mbed_official 235:685d5f11838f 1133
mbed_official 235:685d5f11838f 1134 return HAL_OK;
mbed_official 235:685d5f11838f 1135 }
mbed_official 235:685d5f11838f 1136
mbed_official 235:685d5f11838f 1137 /**
mbed_official 532:fe11edbda85c 1138 * @brief Deactivate the specified RTC Alarm
mbed_official 235:685d5f11838f 1139 * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains
mbed_official 235:685d5f11838f 1140 * the configuration information for RTC.
mbed_official 235:685d5f11838f 1141 * @param Alarm: Specifies the Alarm.
mbed_official 235:685d5f11838f 1142 * This parameter can be one of the following values:
mbed_official 235:685d5f11838f 1143 * @arg RTC_ALARM_A: AlarmA
mbed_official 235:685d5f11838f 1144 * @arg RTC_ALARM_B: AlarmB
mbed_official 235:685d5f11838f 1145 * @retval HAL status
mbed_official 235:685d5f11838f 1146 */
mbed_official 235:685d5f11838f 1147 HAL_StatusTypeDef HAL_RTC_DeactivateAlarm(RTC_HandleTypeDef *hrtc, uint32_t Alarm)
mbed_official 235:685d5f11838f 1148 {
mbed_official 235:685d5f11838f 1149 uint32_t tickstart = 0;
mbed_official 235:685d5f11838f 1150
mbed_official 235:685d5f11838f 1151 /* Check the parameters */
mbed_official 532:fe11edbda85c 1152 assert_param(IS_RTC_ALARM(Alarm));
mbed_official 235:685d5f11838f 1153
mbed_official 235:685d5f11838f 1154 /* Process Locked */
mbed_official 235:685d5f11838f 1155 __HAL_LOCK(hrtc);
mbed_official 235:685d5f11838f 1156
mbed_official 235:685d5f11838f 1157 hrtc->State = HAL_RTC_STATE_BUSY;
mbed_official 235:685d5f11838f 1158
mbed_official 235:685d5f11838f 1159 /* Disable the write protection for RTC registers */
mbed_official 235:685d5f11838f 1160 __HAL_RTC_WRITEPROTECTION_DISABLE(hrtc);
mbed_official 235:685d5f11838f 1161
mbed_official 235:685d5f11838f 1162 if(Alarm == RTC_ALARM_A)
mbed_official 235:685d5f11838f 1163 {
mbed_official 235:685d5f11838f 1164 /* AlarmA */
mbed_official 235:685d5f11838f 1165 __HAL_RTC_ALARMA_DISABLE(hrtc);
mbed_official 235:685d5f11838f 1166
mbed_official 235:685d5f11838f 1167 /* In case of interrupt mode is used, the interrupt source must disabled */
mbed_official 235:685d5f11838f 1168 __HAL_RTC_ALARM_DISABLE_IT(hrtc, RTC_IT_ALRA);
mbed_official 235:685d5f11838f 1169
mbed_official 235:685d5f11838f 1170 /* Get tick */
mbed_official 235:685d5f11838f 1171 tickstart = HAL_GetTick();
mbed_official 235:685d5f11838f 1172
mbed_official 235:685d5f11838f 1173 /* Wait till RTC ALRxWF flag is set and if Time out is reached exit */
mbed_official 235:685d5f11838f 1174 while(__HAL_RTC_ALARM_GET_FLAG(hrtc, RTC_FLAG_ALRAWF) == RESET)
mbed_official 235:685d5f11838f 1175 {
mbed_official 235:685d5f11838f 1176 if((HAL_GetTick() - tickstart ) > RTC_TIMEOUT_VALUE)
mbed_official 235:685d5f11838f 1177 {
mbed_official 235:685d5f11838f 1178 /* Enable the write protection for RTC registers */
mbed_official 235:685d5f11838f 1179 __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc);
mbed_official 235:685d5f11838f 1180
mbed_official 235:685d5f11838f 1181 hrtc->State = HAL_RTC_STATE_TIMEOUT;
mbed_official 235:685d5f11838f 1182
mbed_official 235:685d5f11838f 1183 /* Process Unlocked */
mbed_official 235:685d5f11838f 1184 __HAL_UNLOCK(hrtc);
mbed_official 235:685d5f11838f 1185
mbed_official 235:685d5f11838f 1186 return HAL_TIMEOUT;
mbed_official 235:685d5f11838f 1187 }
mbed_official 235:685d5f11838f 1188 }
mbed_official 235:685d5f11838f 1189 }
mbed_official 235:685d5f11838f 1190 else
mbed_official 235:685d5f11838f 1191 {
mbed_official 235:685d5f11838f 1192 /* AlarmB */
mbed_official 235:685d5f11838f 1193 __HAL_RTC_ALARMB_DISABLE(hrtc);
mbed_official 235:685d5f11838f 1194
mbed_official 235:685d5f11838f 1195 /* In case of interrupt mode is used, the interrupt source must disabled */
mbed_official 235:685d5f11838f 1196 __HAL_RTC_ALARM_DISABLE_IT(hrtc,RTC_IT_ALRB);
mbed_official 235:685d5f11838f 1197
mbed_official 235:685d5f11838f 1198 /* Get tick */
mbed_official 235:685d5f11838f 1199 tickstart = HAL_GetTick();
mbed_official 235:685d5f11838f 1200
mbed_official 235:685d5f11838f 1201 /* Wait till RTC ALRxWF flag is set and if Time out is reached exit */
mbed_official 235:685d5f11838f 1202 while(__HAL_RTC_ALARM_GET_FLAG(hrtc, RTC_FLAG_ALRBWF) == RESET)
mbed_official 235:685d5f11838f 1203 {
mbed_official 235:685d5f11838f 1204 if((HAL_GetTick() - tickstart ) > RTC_TIMEOUT_VALUE)
mbed_official 235:685d5f11838f 1205 {
mbed_official 235:685d5f11838f 1206 /* Enable the write protection for RTC registers */
mbed_official 235:685d5f11838f 1207 __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc);
mbed_official 235:685d5f11838f 1208
mbed_official 235:685d5f11838f 1209 hrtc->State = HAL_RTC_STATE_TIMEOUT;
mbed_official 235:685d5f11838f 1210
mbed_official 235:685d5f11838f 1211 /* Process Unlocked */
mbed_official 235:685d5f11838f 1212 __HAL_UNLOCK(hrtc);
mbed_official 235:685d5f11838f 1213
mbed_official 235:685d5f11838f 1214 return HAL_TIMEOUT;
mbed_official 235:685d5f11838f 1215 }
mbed_official 235:685d5f11838f 1216 }
mbed_official 235:685d5f11838f 1217 }
mbed_official 235:685d5f11838f 1218 /* Enable the write protection for RTC registers */
mbed_official 235:685d5f11838f 1219 __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc);
mbed_official 235:685d5f11838f 1220
mbed_official 235:685d5f11838f 1221 hrtc->State = HAL_RTC_STATE_READY;
mbed_official 235:685d5f11838f 1222
mbed_official 235:685d5f11838f 1223 /* Process Unlocked */
mbed_official 235:685d5f11838f 1224 __HAL_UNLOCK(hrtc);
mbed_official 235:685d5f11838f 1225
mbed_official 235:685d5f11838f 1226 return HAL_OK;
mbed_official 235:685d5f11838f 1227 }
mbed_official 235:685d5f11838f 1228
mbed_official 235:685d5f11838f 1229 /**
mbed_official 235:685d5f11838f 1230 * @brief Gets the RTC Alarm value and masks.
mbed_official 235:685d5f11838f 1231 * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains
mbed_official 235:685d5f11838f 1232 * the configuration information for RTC.
mbed_official 235:685d5f11838f 1233 * @param sAlarm: Pointer to Date structure
mbed_official 235:685d5f11838f 1234 * @param Alarm: Specifies the Alarm.
mbed_official 235:685d5f11838f 1235 * This parameter can be one of the following values:
mbed_official 235:685d5f11838f 1236 * @arg RTC_ALARM_A: AlarmA
mbed_official 235:685d5f11838f 1237 * @arg RTC_ALARM_B: AlarmB
mbed_official 235:685d5f11838f 1238 * @param Format: Specifies the format of the entered parameters.
mbed_official 235:685d5f11838f 1239 * This parameter can be one of the following values:
mbed_official 532:fe11edbda85c 1240 * @arg RTC_FORMAT_BIN: Binary data format
mbed_official 532:fe11edbda85c 1241 * @arg RTC_FORMAT_BCD: BCD data format
mbed_official 235:685d5f11838f 1242 * @retval HAL status
mbed_official 235:685d5f11838f 1243 */
mbed_official 235:685d5f11838f 1244 HAL_StatusTypeDef HAL_RTC_GetAlarm(RTC_HandleTypeDef *hrtc, RTC_AlarmTypeDef *sAlarm, uint32_t Alarm, uint32_t Format)
mbed_official 235:685d5f11838f 1245 {
mbed_official 235:685d5f11838f 1246 uint32_t tmpreg = 0, subsecondtmpreg = 0;
mbed_official 235:685d5f11838f 1247
mbed_official 235:685d5f11838f 1248 /* Check the parameters */
mbed_official 235:685d5f11838f 1249 assert_param(IS_RTC_FORMAT(Format));
mbed_official 532:fe11edbda85c 1250 assert_param(IS_RTC_ALARM(Alarm));
mbed_official 235:685d5f11838f 1251
mbed_official 235:685d5f11838f 1252 if(Alarm == RTC_ALARM_A)
mbed_official 235:685d5f11838f 1253 {
mbed_official 235:685d5f11838f 1254 /* AlarmA */
mbed_official 235:685d5f11838f 1255 sAlarm->Alarm = RTC_ALARM_A;
mbed_official 235:685d5f11838f 1256
mbed_official 235:685d5f11838f 1257 tmpreg = (uint32_t)(hrtc->Instance->ALRMAR);
mbed_official 235:685d5f11838f 1258 subsecondtmpreg = (uint32_t)((hrtc->Instance->ALRMASSR ) & RTC_ALRMASSR_SS);
mbed_official 235:685d5f11838f 1259 }
mbed_official 235:685d5f11838f 1260 else
mbed_official 235:685d5f11838f 1261 {
mbed_official 235:685d5f11838f 1262 sAlarm->Alarm = RTC_ALARM_B;
mbed_official 235:685d5f11838f 1263
mbed_official 235:685d5f11838f 1264 tmpreg = (uint32_t)(hrtc->Instance->ALRMBR);
mbed_official 235:685d5f11838f 1265 subsecondtmpreg = (uint32_t)((hrtc->Instance->ALRMBSSR) & RTC_ALRMBSSR_SS);
mbed_official 235:685d5f11838f 1266 }
mbed_official 235:685d5f11838f 1267
mbed_official 235:685d5f11838f 1268 /* Fill the structure with the read parameters */
mbed_official 235:685d5f11838f 1269 sAlarm->AlarmTime.Hours = (uint32_t)((tmpreg & (RTC_ALRMAR_HT | RTC_ALRMAR_HU)) >> 16);
mbed_official 235:685d5f11838f 1270 sAlarm->AlarmTime.Minutes = (uint32_t)((tmpreg & (RTC_ALRMAR_MNT | RTC_ALRMAR_MNU)) >> 8);
mbed_official 235:685d5f11838f 1271 sAlarm->AlarmTime.Seconds = (uint32_t)(tmpreg & (RTC_ALRMAR_ST | RTC_ALRMAR_SU));
mbed_official 235:685d5f11838f 1272 sAlarm->AlarmTime.TimeFormat = (uint32_t)((tmpreg & RTC_ALRMAR_PM) >> 16);
mbed_official 235:685d5f11838f 1273 sAlarm->AlarmTime.SubSeconds = (uint32_t) subsecondtmpreg;
mbed_official 235:685d5f11838f 1274 sAlarm->AlarmDateWeekDay = (uint32_t)((tmpreg & (RTC_ALRMAR_DT | RTC_ALRMAR_DU)) >> 24);
mbed_official 235:685d5f11838f 1275 sAlarm->AlarmDateWeekDaySel = (uint32_t)(tmpreg & RTC_ALRMAR_WDSEL);
mbed_official 235:685d5f11838f 1276 sAlarm->AlarmMask = (uint32_t)(tmpreg & RTC_ALARMMASK_ALL);
mbed_official 235:685d5f11838f 1277
mbed_official 532:fe11edbda85c 1278 if(Format == RTC_FORMAT_BIN)
mbed_official 235:685d5f11838f 1279 {
mbed_official 235:685d5f11838f 1280 sAlarm->AlarmTime.Hours = RTC_Bcd2ToByte(sAlarm->AlarmTime.Hours);
mbed_official 235:685d5f11838f 1281 sAlarm->AlarmTime.Minutes = RTC_Bcd2ToByte(sAlarm->AlarmTime.Minutes);
mbed_official 235:685d5f11838f 1282 sAlarm->AlarmTime.Seconds = RTC_Bcd2ToByte(sAlarm->AlarmTime.Seconds);
mbed_official 235:685d5f11838f 1283 sAlarm->AlarmDateWeekDay = RTC_Bcd2ToByte(sAlarm->AlarmDateWeekDay);
mbed_official 235:685d5f11838f 1284 }
mbed_official 235:685d5f11838f 1285
mbed_official 235:685d5f11838f 1286 return HAL_OK;
mbed_official 235:685d5f11838f 1287 }
mbed_official 235:685d5f11838f 1288
mbed_official 235:685d5f11838f 1289 /**
mbed_official 235:685d5f11838f 1290 * @brief This function handles Alarm interrupt request.
mbed_official 235:685d5f11838f 1291 * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains
mbed_official 235:685d5f11838f 1292 * the configuration information for RTC.
mbed_official 235:685d5f11838f 1293 * @retval None
mbed_official 235:685d5f11838f 1294 */
mbed_official 235:685d5f11838f 1295 void HAL_RTC_AlarmIRQHandler(RTC_HandleTypeDef* hrtc)
mbed_official 235:685d5f11838f 1296 {
mbed_official 235:685d5f11838f 1297 if(__HAL_RTC_ALARM_GET_IT(hrtc, RTC_IT_ALRA))
mbed_official 235:685d5f11838f 1298 {
mbed_official 235:685d5f11838f 1299 /* Get the status of the Interrupt */
mbed_official 235:685d5f11838f 1300 if((uint32_t)(hrtc->Instance->CR & RTC_IT_ALRA) != (uint32_t)RESET)
mbed_official 235:685d5f11838f 1301 {
mbed_official 235:685d5f11838f 1302 /* AlarmA callback */
mbed_official 235:685d5f11838f 1303 HAL_RTC_AlarmAEventCallback(hrtc);
mbed_official 235:685d5f11838f 1304
mbed_official 235:685d5f11838f 1305 /* Clear the Alarm interrupt pending bit */
mbed_official 235:685d5f11838f 1306 __HAL_RTC_ALARM_CLEAR_FLAG(hrtc,RTC_FLAG_ALRAF);
mbed_official 235:685d5f11838f 1307 }
mbed_official 235:685d5f11838f 1308 }
mbed_official 235:685d5f11838f 1309
mbed_official 235:685d5f11838f 1310 if(__HAL_RTC_ALARM_GET_IT(hrtc, RTC_IT_ALRB))
mbed_official 235:685d5f11838f 1311 {
mbed_official 235:685d5f11838f 1312 /* Get the status of the Interrupt */
mbed_official 235:685d5f11838f 1313 if((uint32_t)(hrtc->Instance->CR & RTC_IT_ALRB) != (uint32_t)RESET)
mbed_official 235:685d5f11838f 1314 {
mbed_official 235:685d5f11838f 1315 /* AlarmB callback */
mbed_official 235:685d5f11838f 1316 HAL_RTCEx_AlarmBEventCallback(hrtc);
mbed_official 235:685d5f11838f 1317
mbed_official 235:685d5f11838f 1318 /* Clear the Alarm interrupt pending bit */
mbed_official 235:685d5f11838f 1319 __HAL_RTC_ALARM_CLEAR_FLAG(hrtc,RTC_FLAG_ALRBF);
mbed_official 235:685d5f11838f 1320 }
mbed_official 235:685d5f11838f 1321 }
mbed_official 235:685d5f11838f 1322
mbed_official 235:685d5f11838f 1323 /* Clear the EXTI's line Flag for RTC Alarm */
mbed_official 532:fe11edbda85c 1324 __HAL_RTC_ALARM_EXTI_CLEAR_FLAG();
mbed_official 235:685d5f11838f 1325
mbed_official 235:685d5f11838f 1326 /* Change RTC state */
mbed_official 235:685d5f11838f 1327 hrtc->State = HAL_RTC_STATE_READY;
mbed_official 235:685d5f11838f 1328 }
mbed_official 235:685d5f11838f 1329
mbed_official 235:685d5f11838f 1330 /**
mbed_official 235:685d5f11838f 1331 * @brief Alarm A callback.
mbed_official 235:685d5f11838f 1332 * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains
mbed_official 235:685d5f11838f 1333 * the configuration information for RTC.
mbed_official 235:685d5f11838f 1334 * @retval None
mbed_official 235:685d5f11838f 1335 */
mbed_official 235:685d5f11838f 1336 __weak void HAL_RTC_AlarmAEventCallback(RTC_HandleTypeDef *hrtc)
mbed_official 235:685d5f11838f 1337 {
mbed_official 235:685d5f11838f 1338 /* NOTE : This function Should not be modified, when the callback is needed,
mbed_official 235:685d5f11838f 1339 the HAL_RTC_AlarmAEventCallback could be implemented in the user file
mbed_official 235:685d5f11838f 1340 */
mbed_official 235:685d5f11838f 1341 }
mbed_official 235:685d5f11838f 1342
mbed_official 235:685d5f11838f 1343 /**
mbed_official 235:685d5f11838f 1344 * @brief This function handles AlarmA Polling request.
mbed_official 235:685d5f11838f 1345 * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains
mbed_official 235:685d5f11838f 1346 * the configuration information for RTC.
mbed_official 235:685d5f11838f 1347 * @param Timeout: Timeout duration
mbed_official 235:685d5f11838f 1348 * @retval HAL status
mbed_official 235:685d5f11838f 1349 */
mbed_official 235:685d5f11838f 1350 HAL_StatusTypeDef HAL_RTC_PollForAlarmAEvent(RTC_HandleTypeDef *hrtc, uint32_t Timeout)
mbed_official 235:685d5f11838f 1351 {
mbed_official 235:685d5f11838f 1352 uint32_t tickstart = 0;
mbed_official 235:685d5f11838f 1353
mbed_official 235:685d5f11838f 1354 /* Get tick */
mbed_official 235:685d5f11838f 1355 tickstart = HAL_GetTick();
mbed_official 235:685d5f11838f 1356
mbed_official 235:685d5f11838f 1357 while(__HAL_RTC_ALARM_GET_FLAG(hrtc, RTC_FLAG_ALRAF) == RESET)
mbed_official 235:685d5f11838f 1358 {
mbed_official 235:685d5f11838f 1359 if(Timeout != HAL_MAX_DELAY)
mbed_official 235:685d5f11838f 1360 {
mbed_official 235:685d5f11838f 1361 if((Timeout == 0)||((HAL_GetTick() - tickstart ) > Timeout))
mbed_official 235:685d5f11838f 1362 {
mbed_official 235:685d5f11838f 1363 hrtc->State = HAL_RTC_STATE_TIMEOUT;
mbed_official 235:685d5f11838f 1364 return HAL_TIMEOUT;
mbed_official 235:685d5f11838f 1365 }
mbed_official 235:685d5f11838f 1366 }
mbed_official 235:685d5f11838f 1367 }
mbed_official 235:685d5f11838f 1368
mbed_official 235:685d5f11838f 1369 /* Clear the Alarm interrupt pending bit */
mbed_official 235:685d5f11838f 1370 __HAL_RTC_ALARM_CLEAR_FLAG(hrtc, RTC_FLAG_ALRAF);
mbed_official 235:685d5f11838f 1371
mbed_official 235:685d5f11838f 1372 /* Change RTC state */
mbed_official 235:685d5f11838f 1373 hrtc->State = HAL_RTC_STATE_READY;
mbed_official 235:685d5f11838f 1374
mbed_official 235:685d5f11838f 1375 return HAL_OK;
mbed_official 235:685d5f11838f 1376 }
mbed_official 235:685d5f11838f 1377
mbed_official 235:685d5f11838f 1378 /**
mbed_official 235:685d5f11838f 1379 * @}
mbed_official 235:685d5f11838f 1380 */
mbed_official 235:685d5f11838f 1381
mbed_official 532:fe11edbda85c 1382 /** @defgroup RTC_Exported_Functions_Group4 Peripheral Control functions
mbed_official 235:685d5f11838f 1383 * @brief Peripheral Control functions
mbed_official 235:685d5f11838f 1384 *
mbed_official 235:685d5f11838f 1385 @verbatim
mbed_official 235:685d5f11838f 1386 ===============================================================================
mbed_official 235:685d5f11838f 1387 ##### Peripheral Control functions #####
mbed_official 235:685d5f11838f 1388 ===============================================================================
mbed_official 235:685d5f11838f 1389 [..]
mbed_official 235:685d5f11838f 1390 This subsection provides functions allowing to
mbed_official 235:685d5f11838f 1391 (+) Wait for RTC Time and Date Synchronization
mbed_official 235:685d5f11838f 1392
mbed_official 235:685d5f11838f 1393 @endverbatim
mbed_official 235:685d5f11838f 1394 * @{
mbed_official 235:685d5f11838f 1395 */
mbed_official 235:685d5f11838f 1396
mbed_official 235:685d5f11838f 1397 /**
mbed_official 235:685d5f11838f 1398 * @brief Waits until the RTC Time and Date registers (RTC_TR and RTC_DR) are
mbed_official 235:685d5f11838f 1399 * synchronized with RTC APB clock.
mbed_official 235:685d5f11838f 1400 * @note The RTC Resynchronization mode is write protected, use the
mbed_official 235:685d5f11838f 1401 * __HAL_RTC_WRITEPROTECTION_DISABLE() before calling this function.
mbed_official 235:685d5f11838f 1402 * @note To read the calendar through the shadow registers after Calendar
mbed_official 532:fe11edbda85c 1403 * initialization, calendar update or after wake-up from low power modes
mbed_official 235:685d5f11838f 1404 * the software must first clear the RSF flag.
mbed_official 235:685d5f11838f 1405 * The software must then wait until it is set again before reading
mbed_official 235:685d5f11838f 1406 * the calendar, which means that the calendar registers have been
mbed_official 235:685d5f11838f 1407 * correctly copied into the RTC_TR and RTC_DR shadow registers.
mbed_official 235:685d5f11838f 1408 * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains
mbed_official 235:685d5f11838f 1409 * the configuration information for RTC.
mbed_official 235:685d5f11838f 1410 * @retval HAL status
mbed_official 235:685d5f11838f 1411 */
mbed_official 235:685d5f11838f 1412 HAL_StatusTypeDef HAL_RTC_WaitForSynchro(RTC_HandleTypeDef* hrtc)
mbed_official 235:685d5f11838f 1413 {
mbed_official 235:685d5f11838f 1414 uint32_t tickstart = 0;
mbed_official 235:685d5f11838f 1415
mbed_official 235:685d5f11838f 1416 /* Clear RSF flag */
mbed_official 235:685d5f11838f 1417 hrtc->Instance->ISR &= (uint32_t)RTC_RSF_MASK;
mbed_official 235:685d5f11838f 1418
mbed_official 235:685d5f11838f 1419 /* Get tick */
mbed_official 235:685d5f11838f 1420 tickstart = HAL_GetTick();
mbed_official 235:685d5f11838f 1421
mbed_official 235:685d5f11838f 1422 /* Wait the registers to be synchronised */
mbed_official 235:685d5f11838f 1423 while((hrtc->Instance->ISR & RTC_ISR_RSF) == (uint32_t)RESET)
mbed_official 235:685d5f11838f 1424 {
mbed_official 235:685d5f11838f 1425 if((HAL_GetTick() - tickstart ) > RTC_TIMEOUT_VALUE)
mbed_official 235:685d5f11838f 1426 {
mbed_official 235:685d5f11838f 1427 return HAL_TIMEOUT;
mbed_official 235:685d5f11838f 1428 }
mbed_official 235:685d5f11838f 1429 }
mbed_official 235:685d5f11838f 1430
mbed_official 235:685d5f11838f 1431 return HAL_OK;
mbed_official 235:685d5f11838f 1432 }
mbed_official 235:685d5f11838f 1433
mbed_official 532:fe11edbda85c 1434 /**
mbed_official 532:fe11edbda85c 1435 * @}
mbed_official 532:fe11edbda85c 1436 */
mbed_official 532:fe11edbda85c 1437
mbed_official 532:fe11edbda85c 1438 /** @defgroup RTC_Exported_Functions_Group5 Peripheral State functions
mbed_official 235:685d5f11838f 1439 * @brief Peripheral State functions
mbed_official 235:685d5f11838f 1440 *
mbed_official 235:685d5f11838f 1441 @verbatim
mbed_official 235:685d5f11838f 1442 ===============================================================================
mbed_official 235:685d5f11838f 1443 ##### Peripheral State functions #####
mbed_official 235:685d5f11838f 1444 ===============================================================================
mbed_official 235:685d5f11838f 1445 [..]
mbed_official 235:685d5f11838f 1446 This subsection provides functions allowing to
mbed_official 235:685d5f11838f 1447 (+) Get RTC state
mbed_official 235:685d5f11838f 1448
mbed_official 235:685d5f11838f 1449 @endverbatim
mbed_official 235:685d5f11838f 1450 * @{
mbed_official 235:685d5f11838f 1451 */
mbed_official 235:685d5f11838f 1452 /**
mbed_official 235:685d5f11838f 1453 * @brief Returns the RTC state.
mbed_official 235:685d5f11838f 1454 * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains
mbed_official 235:685d5f11838f 1455 * the configuration information for RTC.
mbed_official 235:685d5f11838f 1456 * @retval HAL state
mbed_official 235:685d5f11838f 1457 */
mbed_official 235:685d5f11838f 1458 HAL_RTCStateTypeDef HAL_RTC_GetState(RTC_HandleTypeDef* hrtc)
mbed_official 235:685d5f11838f 1459 {
mbed_official 235:685d5f11838f 1460 return hrtc->State;
mbed_official 235:685d5f11838f 1461 }
mbed_official 235:685d5f11838f 1462
mbed_official 235:685d5f11838f 1463 /**
mbed_official 235:685d5f11838f 1464 * @}
mbed_official 235:685d5f11838f 1465 */
mbed_official 235:685d5f11838f 1466
mbed_official 235:685d5f11838f 1467 /**
mbed_official 235:685d5f11838f 1468 * @brief Enters the RTC Initialization mode.
mbed_official 235:685d5f11838f 1469 * @note The RTC Initialization mode is write protected, use the
mbed_official 235:685d5f11838f 1470 * __HAL_RTC_WRITEPROTECTION_DISABLE() before calling this function.
mbed_official 235:685d5f11838f 1471 * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains
mbed_official 235:685d5f11838f 1472 * the configuration information for RTC.
mbed_official 235:685d5f11838f 1473 * @retval HAL status
mbed_official 235:685d5f11838f 1474 */
mbed_official 235:685d5f11838f 1475 HAL_StatusTypeDef RTC_EnterInitMode(RTC_HandleTypeDef* hrtc)
mbed_official 235:685d5f11838f 1476 {
mbed_official 235:685d5f11838f 1477 uint32_t tickstart = 0;
mbed_official 235:685d5f11838f 1478
mbed_official 235:685d5f11838f 1479 /* Check if the Initialization mode is set */
mbed_official 235:685d5f11838f 1480 if((hrtc->Instance->ISR & RTC_ISR_INITF) == (uint32_t)RESET)
mbed_official 235:685d5f11838f 1481 {
mbed_official 235:685d5f11838f 1482 /* Set the Initialization mode */
mbed_official 235:685d5f11838f 1483 hrtc->Instance->ISR = (uint32_t)RTC_INIT_MASK;
mbed_official 235:685d5f11838f 1484
mbed_official 235:685d5f11838f 1485 /* Get tick */
mbed_official 235:685d5f11838f 1486 tickstart = HAL_GetTick();
mbed_official 235:685d5f11838f 1487
mbed_official 235:685d5f11838f 1488 /* Wait till RTC is in INIT state and if Time out is reached exit */
mbed_official 235:685d5f11838f 1489 while((hrtc->Instance->ISR & RTC_ISR_INITF) == (uint32_t)RESET)
mbed_official 235:685d5f11838f 1490 {
mbed_official 235:685d5f11838f 1491 if((HAL_GetTick() - tickstart ) > RTC_TIMEOUT_VALUE)
mbed_official 235:685d5f11838f 1492 {
mbed_official 235:685d5f11838f 1493 return HAL_TIMEOUT;
mbed_official 235:685d5f11838f 1494 }
mbed_official 235:685d5f11838f 1495 }
mbed_official 235:685d5f11838f 1496 }
mbed_official 235:685d5f11838f 1497
mbed_official 235:685d5f11838f 1498 return HAL_OK;
mbed_official 235:685d5f11838f 1499 }
mbed_official 235:685d5f11838f 1500
mbed_official 235:685d5f11838f 1501
mbed_official 235:685d5f11838f 1502 /**
mbed_official 235:685d5f11838f 1503 * @brief Converts a 2 digit decimal to BCD format.
mbed_official 235:685d5f11838f 1504 * @param Value: Byte to be converted
mbed_official 235:685d5f11838f 1505 * @retval Converted byte
mbed_official 235:685d5f11838f 1506 */
mbed_official 235:685d5f11838f 1507 uint8_t RTC_ByteToBcd2(uint8_t Value)
mbed_official 235:685d5f11838f 1508 {
mbed_official 235:685d5f11838f 1509 uint32_t bcdhigh = 0;
mbed_official 235:685d5f11838f 1510
mbed_official 235:685d5f11838f 1511 while(Value >= 10)
mbed_official 235:685d5f11838f 1512 {
mbed_official 235:685d5f11838f 1513 bcdhigh++;
mbed_official 235:685d5f11838f 1514 Value -= 10;
mbed_official 235:685d5f11838f 1515 }
mbed_official 235:685d5f11838f 1516
mbed_official 235:685d5f11838f 1517 return ((uint8_t)(bcdhigh << 4) | Value);
mbed_official 235:685d5f11838f 1518 }
mbed_official 235:685d5f11838f 1519
mbed_official 235:685d5f11838f 1520 /**
mbed_official 235:685d5f11838f 1521 * @brief Converts from 2 digit BCD to Binary.
mbed_official 235:685d5f11838f 1522 * @param Value: BCD value to be converted
mbed_official 235:685d5f11838f 1523 * @retval Converted word
mbed_official 235:685d5f11838f 1524 */
mbed_official 235:685d5f11838f 1525 uint8_t RTC_Bcd2ToByte(uint8_t Value)
mbed_official 235:685d5f11838f 1526 {
mbed_official 235:685d5f11838f 1527 uint32_t tmp = 0;
mbed_official 235:685d5f11838f 1528 tmp = ((uint8_t)(Value & (uint8_t)0xF0) >> (uint8_t)0x4) * 10;
mbed_official 235:685d5f11838f 1529 return (tmp + (Value & (uint8_t)0x0F));
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 #endif /* HAL_RTC_MODULE_ENABLED */
mbed_official 235:685d5f11838f 1537 /**
mbed_official 235:685d5f11838f 1538 * @}
mbed_official 235:685d5f11838f 1539 */
mbed_official 235:685d5f11838f 1540
mbed_official 235:685d5f11838f 1541 /**
mbed_official 235:685d5f11838f 1542 * @}
mbed_official 235:685d5f11838f 1543 */
mbed_official 235:685d5f11838f 1544
mbed_official 235:685d5f11838f 1545 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/