mbed library sources

Dependents:   Marvino mbot

Fork of mbed-src by mbed official

Committer:
mbed_official
Date:
Mon Sep 28 14:00:11 2015 +0100
Revision:
632:7687fb9c4f91
Parent:
385:be64abf45658
Child:
634:ac7d6880524d
Synchronized with git revision f7ce4ed029cc611121464252ff28d5e8beb895b0

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

NUCLEO_F303K8 - add support of the STM32F303K8

Who changed what in which revision?

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