Mbed for VNG board

Fork of mbed-src by mbed official

Committer:
mbed_official
Date:
Fri Nov 07 15:45:07 2014 +0000
Revision:
394:83f921546702
Parent:
targets/cmsis/TARGET_STM/TARGET_NUCLEO_L152RE/stm32l1xx_hal_rtc.c@354:e67efb2aab0e
Synchronized with git revision aab52cb7ec5a665869e507dd988bbfd55b7e087e

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

Tests: Fix cpputest testrunner

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mbed_official 354:e67efb2aab0e 1 /**
mbed_official 354:e67efb2aab0e 2 ******************************************************************************
mbed_official 354:e67efb2aab0e 3 * @file stm32l1xx_hal_rtc.c
mbed_official 354:e67efb2aab0e 4 * @author MCD Application Team
mbed_official 354:e67efb2aab0e 5 * @version V1.0.0
mbed_official 354:e67efb2aab0e 6 * @date 5-September-2014
mbed_official 354:e67efb2aab0e 7 * @brief RTC HAL module driver.
mbed_official 354:e67efb2aab0e 8 * This file provides firmware functions to manage the following
mbed_official 354:e67efb2aab0e 9 * functionalities of the Real Time Clock (RTC) peripheral:
mbed_official 354:e67efb2aab0e 10 * + Initialization and de-initialization functions
mbed_official 354:e67efb2aab0e 11 * + RTC Time and Date functions
mbed_official 354:e67efb2aab0e 12 * + RTC Alarm functions
mbed_official 354:e67efb2aab0e 13 * + Peripheral Control functions
mbed_official 354:e67efb2aab0e 14 * + Peripheral State functions
mbed_official 354:e67efb2aab0e 15 *
mbed_official 354:e67efb2aab0e 16 @verbatim
mbed_official 354:e67efb2aab0e 17 ==============================================================================
mbed_official 354:e67efb2aab0e 18 ##### Backup Domain Operating Condition #####
mbed_official 354:e67efb2aab0e 19 ==============================================================================
mbed_official 354:e67efb2aab0e 20 [..] The real-time clock (RTC) and the RTC backup registers can be powered
mbed_official 354:e67efb2aab0e 21 from the VBAT voltage when the main VDD supply is powered off.
mbed_official 354:e67efb2aab0e 22 To retain the content of the RTC backup registers and supply the RTC
mbed_official 354:e67efb2aab0e 23 when VDD is turned off, VBAT pin can be connected to an optional
mbed_official 354:e67efb2aab0e 24 standby voltage supplied by a battery or by another source.
mbed_official 354:e67efb2aab0e 25
mbed_official 354:e67efb2aab0e 26 [..] To allow the RTC operating even when the main digital supply (VDD) is turned
mbed_official 354:e67efb2aab0e 27 off, the VBAT pin powers the following blocks:
mbed_official 354:e67efb2aab0e 28 (#) The RTC
mbed_official 354:e67efb2aab0e 29 (#) The LSE oscillator
mbed_official 354:e67efb2aab0e 30 (#) PC13 to PC15 I/Os (when available)
mbed_official 354:e67efb2aab0e 31
mbed_official 354:e67efb2aab0e 32 [..] When the backup domain is supplied by VDD (analog switch connected to VDD),
mbed_official 354:e67efb2aab0e 33 the following pins are available:
mbed_official 354:e67efb2aab0e 34 (#) PC14 and PC15 can be used as either GPIO or LSE pins
mbed_official 354:e67efb2aab0e 35 (#) PC13 can be used as a GPIO or as the RTC_AF1 pin
mbed_official 354:e67efb2aab0e 36
mbed_official 354:e67efb2aab0e 37 [..] When the backup domain is supplied by VBAT (analog switch connected to VBAT
mbed_official 354:e67efb2aab0e 38 because VDD is not present), the following pins are available:
mbed_official 354:e67efb2aab0e 39 (#) PC14 and PC15 can be used as LSE pins only
mbed_official 354:e67efb2aab0e 40 (#) PC13 can be used as the RTC_AF1 pin
mbed_official 354:e67efb2aab0e 41
mbed_official 354:e67efb2aab0e 42 ##### Backup Domain Reset #####
mbed_official 354:e67efb2aab0e 43 ==================================================================
mbed_official 354:e67efb2aab0e 44 [..] The backup domain reset sets all RTC registers and the RCC_BDCR register
mbed_official 354:e67efb2aab0e 45 to their reset values.
mbed_official 354:e67efb2aab0e 46 [..] A backup domain reset is generated when one of the following events occurs:
mbed_official 354:e67efb2aab0e 47 (#) Software reset, triggered by setting the BDRST bit in the
mbed_official 354:e67efb2aab0e 48 RCC Backup domain control register (RCC_BDCR).
mbed_official 354:e67efb2aab0e 49 (#) VDD or VBAT power on, if both supplies have previously been powered off.
mbed_official 354:e67efb2aab0e 50
mbed_official 354:e67efb2aab0e 51 ##### Backup Domain Access #####
mbed_official 354:e67efb2aab0e 52 ==================================================================
mbed_official 354:e67efb2aab0e 53 [..] After reset, the backup domain (RTC registers, RTC backup data
mbed_official 354:e67efb2aab0e 54 registers and backup SRAM) is protected against possible unwanted write
mbed_official 354:e67efb2aab0e 55 accesses.
mbed_official 354:e67efb2aab0e 56 [..] To enable access to the RTC Domain and RTC registers, proceed as follows:
mbed_official 354:e67efb2aab0e 57 (+) Enable the Power Controller (PWR) APB1 interface clock using the
mbed_official 354:e67efb2aab0e 58 __PWR_CLK_ENABLE() function.
mbed_official 354:e67efb2aab0e 59 (+) Enable access to RTC domain using the HAL_PWR_EnableBkUpAccess() function.
mbed_official 354:e67efb2aab0e 60 (+) Select the RTC clock source using the __HAL_RCC_RTC_CONFIG() function.
mbed_official 354:e67efb2aab0e 61 (+) Enable RTC Clock using the __HAL_RCC_RTC_ENABLE() function.
mbed_official 354:e67efb2aab0e 62
mbed_official 354:e67efb2aab0e 63
mbed_official 354:e67efb2aab0e 64 ##### How to use this driver #####
mbed_official 354:e67efb2aab0e 65 ==================================================================
mbed_official 354:e67efb2aab0e 66 [..]
mbed_official 354:e67efb2aab0e 67 (+) Enable the RTC domain access (see description in the section above).
mbed_official 354:e67efb2aab0e 68 (+) Configure the RTC Prescaler (Asynchronous and Synchronous) and RTC hour
mbed_official 354:e67efb2aab0e 69 format using the HAL_RTC_Init() function.
mbed_official 354:e67efb2aab0e 70
mbed_official 354:e67efb2aab0e 71 *** Time and Date configuration ***
mbed_official 354:e67efb2aab0e 72 ===================================
mbed_official 354:e67efb2aab0e 73 [..]
mbed_official 354:e67efb2aab0e 74 (+) To configure the RTC Calendar (Time and Date) use the HAL_RTC_SetTime()
mbed_official 354:e67efb2aab0e 75 and HAL_RTC_SetDate() functions.
mbed_official 354:e67efb2aab0e 76 (+) To read the RTC Calendar, use the HAL_RTC_GetTime() and HAL_RTC_GetDate() functions.
mbed_official 354:e67efb2aab0e 77
mbed_official 354:e67efb2aab0e 78 *** Alarm configuration ***
mbed_official 354:e67efb2aab0e 79 ===========================
mbed_official 354:e67efb2aab0e 80 [..]
mbed_official 354:e67efb2aab0e 81 (+) To configure the RTC Alarm use the HAL_RTC_SetAlarm() function.
mbed_official 354:e67efb2aab0e 82 You can also configure the RTC Alarm with interrupt mode using the HAL_RTC_SetAlarm_IT() function.
mbed_official 354:e67efb2aab0e 83 (+) To read the RTC Alarm, use the HAL_RTC_GetAlarm() function.
mbed_official 354:e67efb2aab0e 84
mbed_official 354:e67efb2aab0e 85 ##### RTC and low power modes #####
mbed_official 354:e67efb2aab0e 86 ==================================================================
mbed_official 354:e67efb2aab0e 87 [..] The MCU can be woken up from a low power mode by an RTC alternate
mbed_official 354:e67efb2aab0e 88 function.
mbed_official 354:e67efb2aab0e 89 [..] The RTC alternate functions are the RTC alarms (Alarm A and Alarm B),
mbed_official 354:e67efb2aab0e 90 RTC wakeup, RTC tamper event detection and RTC time stamp event detection.
mbed_official 354:e67efb2aab0e 91 These RTC alternate functions can wake up the system from the Stop and
mbed_official 354:e67efb2aab0e 92 Standby low power modes.
mbed_official 354:e67efb2aab0e 93 [..] The system can also wake up from low power modes without depending
mbed_official 354:e67efb2aab0e 94 on an external interrupt (Auto-wakeup mode), by using the RTC alarm
mbed_official 354:e67efb2aab0e 95 or the RTC wakeup events.
mbed_official 354:e67efb2aab0e 96 [..] The RTC provides a programmable time base for waking up from the
mbed_official 354:e67efb2aab0e 97 Stop or Standby mode at regular intervals.
mbed_official 354:e67efb2aab0e 98 Wakeup from STOP and STANDBY modes is possible only when the RTC clock source
mbed_official 354:e67efb2aab0e 99 is LSE or LSI.
mbed_official 354:e67efb2aab0e 100
mbed_official 354:e67efb2aab0e 101 @endverbatim
mbed_official 354:e67efb2aab0e 102 ******************************************************************************
mbed_official 354:e67efb2aab0e 103 * @attention
mbed_official 354:e67efb2aab0e 104 *
mbed_official 354:e67efb2aab0e 105 * <h2><center>&copy; COPYRIGHT(c) 2014 STMicroelectronics</center></h2>
mbed_official 354:e67efb2aab0e 106 *
mbed_official 354:e67efb2aab0e 107 * Redistribution and use in source and binary forms, with or without modification,
mbed_official 354:e67efb2aab0e 108 * are permitted provided that the following conditions are met:
mbed_official 354:e67efb2aab0e 109 * 1. Redistributions of source code must retain the above copyright notice,
mbed_official 354:e67efb2aab0e 110 * this list of conditions and the following disclaimer.
mbed_official 354:e67efb2aab0e 111 * 2. Redistributions in binary form must reproduce the above copyright notice,
mbed_official 354:e67efb2aab0e 112 * this list of conditions and the following disclaimer in the documentation
mbed_official 354:e67efb2aab0e 113 * and/or other materials provided with the distribution.
mbed_official 354:e67efb2aab0e 114 * 3. Neither the name of STMicroelectronics nor the names of its contributors
mbed_official 354:e67efb2aab0e 115 * may be used to endorse or promote products derived from this software
mbed_official 354:e67efb2aab0e 116 * without specific prior written permission.
mbed_official 354:e67efb2aab0e 117 *
mbed_official 354:e67efb2aab0e 118 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
mbed_official 354:e67efb2aab0e 119 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
mbed_official 354:e67efb2aab0e 120 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
mbed_official 354:e67efb2aab0e 121 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
mbed_official 354:e67efb2aab0e 122 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
mbed_official 354:e67efb2aab0e 123 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
mbed_official 354:e67efb2aab0e 124 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
mbed_official 354:e67efb2aab0e 125 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
mbed_official 354:e67efb2aab0e 126 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
mbed_official 354:e67efb2aab0e 127 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
mbed_official 354:e67efb2aab0e 128 *
mbed_official 354:e67efb2aab0e 129 ******************************************************************************
mbed_official 354:e67efb2aab0e 130 */
mbed_official 354:e67efb2aab0e 131
mbed_official 354:e67efb2aab0e 132 /* Includes ------------------------------------------------------------------*/
mbed_official 354:e67efb2aab0e 133 #include "stm32l1xx_hal.h"
mbed_official 354:e67efb2aab0e 134
mbed_official 354:e67efb2aab0e 135 /** @addtogroup STM32L1xx_HAL_Driver
mbed_official 354:e67efb2aab0e 136 * @{
mbed_official 354:e67efb2aab0e 137 */
mbed_official 354:e67efb2aab0e 138
mbed_official 354:e67efb2aab0e 139 /** @defgroup RTC RTC
mbed_official 354:e67efb2aab0e 140 * @brief RTC HAL module driver
mbed_official 354:e67efb2aab0e 141 * @{
mbed_official 354:e67efb2aab0e 142 */
mbed_official 354:e67efb2aab0e 143
mbed_official 354:e67efb2aab0e 144 #ifdef HAL_RTC_MODULE_ENABLED
mbed_official 354:e67efb2aab0e 145
mbed_official 354:e67efb2aab0e 146 /* Private typedef -----------------------------------------------------------*/
mbed_official 354:e67efb2aab0e 147 /* Private define ------------------------------------------------------------*/
mbed_official 354:e67efb2aab0e 148 /* Private macro -------------------------------------------------------------*/
mbed_official 354:e67efb2aab0e 149 /* Private variables ---------------------------------------------------------*/
mbed_official 354:e67efb2aab0e 150 /* Private function prototypes -----------------------------------------------*/
mbed_official 354:e67efb2aab0e 151 /* Private functions ---------------------------------------------------------*/
mbed_official 354:e67efb2aab0e 152 /** @defgroup RTC_Exported_Functions RTC Exported Functions
mbed_official 354:e67efb2aab0e 153 * @{
mbed_official 354:e67efb2aab0e 154 */
mbed_official 354:e67efb2aab0e 155
mbed_official 354:e67efb2aab0e 156 /** @defgroup RTC_Exported_Functions_Group1 Initialization and de-initialization functions
mbed_official 354:e67efb2aab0e 157 * @brief Initialization and Configuration functions
mbed_official 354:e67efb2aab0e 158 *
mbed_official 354:e67efb2aab0e 159 @verbatim
mbed_official 354:e67efb2aab0e 160 ===============================================================================
mbed_official 354:e67efb2aab0e 161 ##### Initialization and de-initialization functions #####
mbed_official 354:e67efb2aab0e 162 ===============================================================================
mbed_official 354:e67efb2aab0e 163 [..] This section provides functions allowing to initialize and configure the
mbed_official 354:e67efb2aab0e 164 RTC Prescaler (Synchronous and Asynchronous), RTC Hour format, disable
mbed_official 354:e67efb2aab0e 165 RTC registers Write protection, enter and exit the RTC initialization mode,
mbed_official 354:e67efb2aab0e 166 RTC registers synchronization check and reference clock detection enable.
mbed_official 354:e67efb2aab0e 167 (#) The RTC Prescaler is programmed to generate the RTC 1Hz time base.
mbed_official 354:e67efb2aab0e 168 It is split into 2 programmable prescalers to minimize power consumption.
mbed_official 354:e67efb2aab0e 169 (++) A 7-bit asynchronous prescaler and a 13-bit synchronous prescaler.
mbed_official 354:e67efb2aab0e 170 (++) When both prescalers are used, it is recommended to configure the
mbed_official 354:e67efb2aab0e 171 asynchronous prescaler to a high value to minimize power consumption.
mbed_official 354:e67efb2aab0e 172 (#) All RTC registers are Write protected. Writing to the RTC registers
mbed_official 354:e67efb2aab0e 173 is enabled by writing a key into the Write Protection register, RTC_WPR.
mbed_official 354:e67efb2aab0e 174 (#) To configure the RTC Calendar, user application should enter
mbed_official 354:e67efb2aab0e 175 initialization mode. In this mode, the calendar counter is stopped
mbed_official 354:e67efb2aab0e 176 and its value can be updated. When the initialization sequence is
mbed_official 354:e67efb2aab0e 177 complete, the calendar restarts counting after 4 RTCCLK cycles.
mbed_official 354:e67efb2aab0e 178 (#) To read the calendar through the shadow registers after Calendar
mbed_official 354:e67efb2aab0e 179 initialization, calendar update or after wakeup from low power modes
mbed_official 354:e67efb2aab0e 180 the software must first clear the RSF flag. The software must then
mbed_official 354:e67efb2aab0e 181 wait until it is set again before reading the calendar, which means
mbed_official 354:e67efb2aab0e 182 that the calendar registers have been correctly copied into the
mbed_official 354:e67efb2aab0e 183 RTC_TR and RTC_DR shadow registers.The HAL_RTC_WaitForSynchro() function
mbed_official 354:e67efb2aab0e 184 implements the above software sequence (RSF clear and RSF check).
mbed_official 354:e67efb2aab0e 185
mbed_official 354:e67efb2aab0e 186 @endverbatim
mbed_official 354:e67efb2aab0e 187 * @{
mbed_official 354:e67efb2aab0e 188 */
mbed_official 354:e67efb2aab0e 189
mbed_official 354:e67efb2aab0e 190 /**
mbed_official 354:e67efb2aab0e 191 * @brief Initializes the RTC peripheral
mbed_official 354:e67efb2aab0e 192 * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains
mbed_official 354:e67efb2aab0e 193 * the configuration information for RTC.
mbed_official 354:e67efb2aab0e 194 * @retval HAL status
mbed_official 354:e67efb2aab0e 195 */
mbed_official 354:e67efb2aab0e 196 HAL_StatusTypeDef HAL_RTC_Init(RTC_HandleTypeDef *hrtc)
mbed_official 354:e67efb2aab0e 197 {
mbed_official 354:e67efb2aab0e 198 /* Check the RTC peripheral state */
mbed_official 354:e67efb2aab0e 199 if(hrtc == HAL_NULL)
mbed_official 354:e67efb2aab0e 200 {
mbed_official 354:e67efb2aab0e 201 return HAL_ERROR;
mbed_official 354:e67efb2aab0e 202 }
mbed_official 354:e67efb2aab0e 203
mbed_official 354:e67efb2aab0e 204 /* Check the parameters */
mbed_official 354:e67efb2aab0e 205 assert_param(IS_RTC_ALL_INSTANCE(hrtc->Instance));
mbed_official 354:e67efb2aab0e 206 assert_param(IS_RTC_HOUR_FORMAT(hrtc->Init.HourFormat));
mbed_official 354:e67efb2aab0e 207 assert_param(IS_RTC_ASYNCH_PREDIV(hrtc->Init.AsynchPrediv));
mbed_official 354:e67efb2aab0e 208 assert_param(IS_RTC_SYNCH_PREDIV(hrtc->Init.SynchPrediv));
mbed_official 354:e67efb2aab0e 209 assert_param(IS_RTC_OUTPUT(hrtc->Init.OutPut));
mbed_official 354:e67efb2aab0e 210 assert_param(IS_RTC_OUTPUT_POL(hrtc->Init.OutPutPolarity));
mbed_official 354:e67efb2aab0e 211 assert_param(IS_RTC_OUTPUT_TYPE(hrtc->Init.OutPutType));
mbed_official 354:e67efb2aab0e 212
mbed_official 354:e67efb2aab0e 213 if(hrtc->State == HAL_RTC_STATE_RESET)
mbed_official 354:e67efb2aab0e 214 {
mbed_official 354:e67efb2aab0e 215 /* Initialize RTC MSP */
mbed_official 354:e67efb2aab0e 216 HAL_RTC_MspInit(hrtc);
mbed_official 354:e67efb2aab0e 217 }
mbed_official 354:e67efb2aab0e 218
mbed_official 354:e67efb2aab0e 219 /* Set RTC state */
mbed_official 354:e67efb2aab0e 220 hrtc->State = HAL_RTC_STATE_BUSY;
mbed_official 354:e67efb2aab0e 221
mbed_official 354:e67efb2aab0e 222 /* Disable the write protection for RTC registers */
mbed_official 354:e67efb2aab0e 223 __HAL_RTC_WRITEPROTECTION_DISABLE(hrtc);
mbed_official 354:e67efb2aab0e 224
mbed_official 354:e67efb2aab0e 225 /* Set Initialization mode */
mbed_official 354:e67efb2aab0e 226 if(RTC_EnterInitMode(hrtc) != HAL_OK)
mbed_official 354:e67efb2aab0e 227 {
mbed_official 354:e67efb2aab0e 228 /* Enable the write protection for RTC registers */
mbed_official 354:e67efb2aab0e 229 __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc);
mbed_official 354:e67efb2aab0e 230
mbed_official 354:e67efb2aab0e 231 /* Set RTC state */
mbed_official 354:e67efb2aab0e 232 hrtc->State = HAL_RTC_STATE_ERROR;
mbed_official 354:e67efb2aab0e 233
mbed_official 354:e67efb2aab0e 234 return HAL_ERROR;
mbed_official 354:e67efb2aab0e 235 }
mbed_official 354:e67efb2aab0e 236 else
mbed_official 354:e67efb2aab0e 237 {
mbed_official 354:e67efb2aab0e 238 /* Clear RTC_CR FMT, OSEL and POL Bits */
mbed_official 354:e67efb2aab0e 239 hrtc->Instance->CR &= ((uint32_t)~(RTC_CR_FMT | RTC_CR_OSEL | RTC_CR_POL));
mbed_official 354:e67efb2aab0e 240 /* Set RTC_CR register */
mbed_official 354:e67efb2aab0e 241 hrtc->Instance->CR |= (uint32_t)(hrtc->Init.HourFormat | hrtc->Init.OutPut | hrtc->Init.OutPutPolarity);
mbed_official 354:e67efb2aab0e 242
mbed_official 354:e67efb2aab0e 243 /* Configure the RTC PRER */
mbed_official 354:e67efb2aab0e 244 hrtc->Instance->PRER = (uint32_t)(hrtc->Init.SynchPrediv);
mbed_official 354:e67efb2aab0e 245 hrtc->Instance->PRER |= (uint32_t)(hrtc->Init.AsynchPrediv << 16);
mbed_official 354:e67efb2aab0e 246
mbed_official 354:e67efb2aab0e 247 /* Exit Initialization mode */
mbed_official 354:e67efb2aab0e 248 hrtc->Instance->ISR &= (uint32_t)~RTC_ISR_INIT;
mbed_official 354:e67efb2aab0e 249
mbed_official 354:e67efb2aab0e 250 hrtc->Instance->TAFCR &= (uint32_t)~RTC_TAFCR_ALARMOUTTYPE;
mbed_official 354:e67efb2aab0e 251 hrtc->Instance->TAFCR |= (uint32_t)(hrtc->Init.OutPutType);
mbed_official 354:e67efb2aab0e 252
mbed_official 354:e67efb2aab0e 253 /* Enable the write protection for RTC registers */
mbed_official 354:e67efb2aab0e 254 __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc);
mbed_official 354:e67efb2aab0e 255
mbed_official 354:e67efb2aab0e 256 /* Set RTC state */
mbed_official 354:e67efb2aab0e 257 hrtc->State = HAL_RTC_STATE_READY;
mbed_official 354:e67efb2aab0e 258
mbed_official 354:e67efb2aab0e 259 return HAL_OK;
mbed_official 354:e67efb2aab0e 260 }
mbed_official 354:e67efb2aab0e 261 }
mbed_official 354:e67efb2aab0e 262
mbed_official 354:e67efb2aab0e 263 /**
mbed_official 354:e67efb2aab0e 264 * @brief DeInitializes the RTC peripheral
mbed_official 354:e67efb2aab0e 265 * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains
mbed_official 354:e67efb2aab0e 266 * the configuration information for RTC.
mbed_official 354:e67efb2aab0e 267 * @note This function doesn't reset the RTC Backup Data registers.
mbed_official 354:e67efb2aab0e 268 * @retval HAL status
mbed_official 354:e67efb2aab0e 269 */
mbed_official 354:e67efb2aab0e 270 __weak HAL_StatusTypeDef HAL_RTC_DeInit(RTC_HandleTypeDef *hrtc)
mbed_official 354:e67efb2aab0e 271 {
mbed_official 354:e67efb2aab0e 272 /* Note : This function is defined into this file for library reference. */
mbed_official 354:e67efb2aab0e 273 /* Function content is located into file stm32l1xx_hal_rtc_ex.c */
mbed_official 354:e67efb2aab0e 274
mbed_official 354:e67efb2aab0e 275 /* Return function status */
mbed_official 354:e67efb2aab0e 276 return HAL_ERROR;
mbed_official 354:e67efb2aab0e 277 }
mbed_official 354:e67efb2aab0e 278
mbed_official 354:e67efb2aab0e 279 /**
mbed_official 354:e67efb2aab0e 280 * @brief Initializes the RTC MSP.
mbed_official 354:e67efb2aab0e 281 * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains
mbed_official 354:e67efb2aab0e 282 * the configuration information for RTC.
mbed_official 354:e67efb2aab0e 283 * @retval None
mbed_official 354:e67efb2aab0e 284 */
mbed_official 354:e67efb2aab0e 285 __weak void HAL_RTC_MspInit(RTC_HandleTypeDef* hrtc)
mbed_official 354:e67efb2aab0e 286 {
mbed_official 354:e67efb2aab0e 287 /* NOTE : This function Should not be modified, when the callback is needed,
mbed_official 354:e67efb2aab0e 288 the HAL_RTC_MspInit could be implemented in the user file
mbed_official 354:e67efb2aab0e 289 */
mbed_official 354:e67efb2aab0e 290 }
mbed_official 354:e67efb2aab0e 291
mbed_official 354:e67efb2aab0e 292 /**
mbed_official 354:e67efb2aab0e 293 * @brief DeInitializes the RTC MSP.
mbed_official 354:e67efb2aab0e 294 * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains
mbed_official 354:e67efb2aab0e 295 * the configuration information for RTC.
mbed_official 354:e67efb2aab0e 296 * @retval None
mbed_official 354:e67efb2aab0e 297 */
mbed_official 354:e67efb2aab0e 298 __weak void HAL_RTC_MspDeInit(RTC_HandleTypeDef* hrtc)
mbed_official 354:e67efb2aab0e 299 {
mbed_official 354:e67efb2aab0e 300 /* NOTE : This function Should not be modified, when the callback is needed,
mbed_official 354:e67efb2aab0e 301 the HAL_RTC_MspDeInit could be implemented in the user file
mbed_official 354:e67efb2aab0e 302 */
mbed_official 354:e67efb2aab0e 303 }
mbed_official 354:e67efb2aab0e 304
mbed_official 354:e67efb2aab0e 305 /**
mbed_official 354:e67efb2aab0e 306 * @}
mbed_official 354:e67efb2aab0e 307 */
mbed_official 354:e67efb2aab0e 308
mbed_official 354:e67efb2aab0e 309 /** @defgroup RTC_Exported_Functions_Group2 RTC Time and Date functions
mbed_official 354:e67efb2aab0e 310 * @brief RTC Time and Date functions
mbed_official 354:e67efb2aab0e 311 *
mbed_official 354:e67efb2aab0e 312 @verbatim
mbed_official 354:e67efb2aab0e 313 ===============================================================================
mbed_official 354:e67efb2aab0e 314 ##### RTC Time and Date functions #####
mbed_official 354:e67efb2aab0e 315 ===============================================================================
mbed_official 354:e67efb2aab0e 316
mbed_official 354:e67efb2aab0e 317 [..] This section provides functions allowing to configure Time and Date features
mbed_official 354:e67efb2aab0e 318
mbed_official 354:e67efb2aab0e 319 @endverbatim
mbed_official 354:e67efb2aab0e 320 * @{
mbed_official 354:e67efb2aab0e 321 */
mbed_official 354:e67efb2aab0e 322
mbed_official 354:e67efb2aab0e 323 /**
mbed_official 354:e67efb2aab0e 324 * @brief Sets RTC current time.
mbed_official 354:e67efb2aab0e 325 * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains
mbed_official 354:e67efb2aab0e 326 * the configuration information for RTC.
mbed_official 354:e67efb2aab0e 327 * @param sTime: Pointer to Time structure
mbed_official 354:e67efb2aab0e 328 * @param Format: Specifies the format of the entered parameters.
mbed_official 354:e67efb2aab0e 329 * This parameter can be one of the following values:
mbed_official 354:e67efb2aab0e 330 * @arg FORMAT_BIN: Binary data format
mbed_official 354:e67efb2aab0e 331 * @arg FORMAT_BCD: BCD data format
mbed_official 354:e67efb2aab0e 332 * @retval HAL status
mbed_official 354:e67efb2aab0e 333 */
mbed_official 354:e67efb2aab0e 334 HAL_StatusTypeDef HAL_RTC_SetTime(RTC_HandleTypeDef *hrtc, RTC_TimeTypeDef *sTime, uint32_t Format)
mbed_official 354:e67efb2aab0e 335 {
mbed_official 354:e67efb2aab0e 336 uint32_t tmpreg = 0;
mbed_official 354:e67efb2aab0e 337
mbed_official 354:e67efb2aab0e 338 /* Check the parameters */
mbed_official 354:e67efb2aab0e 339 assert_param(IS_RTC_FORMAT(Format));
mbed_official 354:e67efb2aab0e 340 assert_param(IS_RTC_DAYLIGHT_SAVING(sTime->DayLightSaving));
mbed_official 354:e67efb2aab0e 341 assert_param(IS_RTC_STORE_OPERATION(sTime->StoreOperation));
mbed_official 354:e67efb2aab0e 342
mbed_official 354:e67efb2aab0e 343 /* Process Locked */
mbed_official 354:e67efb2aab0e 344 __HAL_LOCK(hrtc);
mbed_official 354:e67efb2aab0e 345
mbed_official 354:e67efb2aab0e 346 hrtc->State = HAL_RTC_STATE_BUSY;
mbed_official 354:e67efb2aab0e 347
mbed_official 354:e67efb2aab0e 348 if(Format == FORMAT_BIN)
mbed_official 354:e67efb2aab0e 349 {
mbed_official 354:e67efb2aab0e 350 if((hrtc->Instance->CR & RTC_CR_FMT) != (uint32_t)RESET)
mbed_official 354:e67efb2aab0e 351 {
mbed_official 354:e67efb2aab0e 352 assert_param(IS_RTC_HOUR12(sTime->Hours));
mbed_official 354:e67efb2aab0e 353 assert_param(IS_RTC_HOURFORMAT12(sTime->TimeFormat));
mbed_official 354:e67efb2aab0e 354 }
mbed_official 354:e67efb2aab0e 355 else
mbed_official 354:e67efb2aab0e 356 {
mbed_official 354:e67efb2aab0e 357 sTime->TimeFormat = 0x00;
mbed_official 354:e67efb2aab0e 358 assert_param(IS_RTC_HOUR24(sTime->Hours));
mbed_official 354:e67efb2aab0e 359 }
mbed_official 354:e67efb2aab0e 360 assert_param(IS_RTC_MINUTES(sTime->Minutes));
mbed_official 354:e67efb2aab0e 361 assert_param(IS_RTC_SECONDS(sTime->Seconds));
mbed_official 354:e67efb2aab0e 362
mbed_official 354:e67efb2aab0e 363 tmpreg = (uint32_t)(((uint32_t)RTC_ByteToBcd2(sTime->Hours) << 16) | \
mbed_official 354:e67efb2aab0e 364 ((uint32_t)RTC_ByteToBcd2(sTime->Minutes) << 8) | \
mbed_official 354:e67efb2aab0e 365 ((uint32_t)RTC_ByteToBcd2(sTime->Seconds)) | \
mbed_official 354:e67efb2aab0e 366 (((uint32_t)sTime->TimeFormat) << 16));
mbed_official 354:e67efb2aab0e 367 }
mbed_official 354:e67efb2aab0e 368 else
mbed_official 354:e67efb2aab0e 369 {
mbed_official 354:e67efb2aab0e 370 if((hrtc->Instance->CR & RTC_CR_FMT) != (uint32_t)RESET)
mbed_official 354:e67efb2aab0e 371 {
mbed_official 354:e67efb2aab0e 372 tmpreg = RTC_Bcd2ToByte(sTime->Hours);
mbed_official 354:e67efb2aab0e 373 assert_param(IS_RTC_HOUR12(tmpreg));
mbed_official 354:e67efb2aab0e 374 assert_param(IS_RTC_HOURFORMAT12(sTime->TimeFormat));
mbed_official 354:e67efb2aab0e 375 }
mbed_official 354:e67efb2aab0e 376 else
mbed_official 354:e67efb2aab0e 377 {
mbed_official 354:e67efb2aab0e 378 sTime->TimeFormat = 0x00;
mbed_official 354:e67efb2aab0e 379 assert_param(IS_RTC_HOUR24(RTC_Bcd2ToByte(sTime->Hours)));
mbed_official 354:e67efb2aab0e 380 }
mbed_official 354:e67efb2aab0e 381 assert_param(IS_RTC_MINUTES(RTC_Bcd2ToByte(sTime->Minutes)));
mbed_official 354:e67efb2aab0e 382 assert_param(IS_RTC_SECONDS(RTC_Bcd2ToByte(sTime->Seconds)));
mbed_official 354:e67efb2aab0e 383 tmpreg = (((uint32_t)(sTime->Hours) << 16) | \
mbed_official 354:e67efb2aab0e 384 ((uint32_t)(sTime->Minutes) << 8) | \
mbed_official 354:e67efb2aab0e 385 ((uint32_t)sTime->Seconds) | \
mbed_official 354:e67efb2aab0e 386 ((uint32_t)(sTime->TimeFormat) << 16));
mbed_official 354:e67efb2aab0e 387 }
mbed_official 354:e67efb2aab0e 388
mbed_official 354:e67efb2aab0e 389 /* Disable the write protection for RTC registers */
mbed_official 354:e67efb2aab0e 390 __HAL_RTC_WRITEPROTECTION_DISABLE(hrtc);
mbed_official 354:e67efb2aab0e 391
mbed_official 354:e67efb2aab0e 392 /* Set Initialization mode */
mbed_official 354:e67efb2aab0e 393 if(RTC_EnterInitMode(hrtc) != HAL_OK)
mbed_official 354:e67efb2aab0e 394 {
mbed_official 354:e67efb2aab0e 395 /* Enable the write protection for RTC registers */
mbed_official 354:e67efb2aab0e 396 __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc);
mbed_official 354:e67efb2aab0e 397
mbed_official 354:e67efb2aab0e 398 /* Set RTC state */
mbed_official 354:e67efb2aab0e 399 hrtc->State = HAL_RTC_STATE_ERROR;
mbed_official 354:e67efb2aab0e 400
mbed_official 354:e67efb2aab0e 401 /* Process Unlocked */
mbed_official 354:e67efb2aab0e 402 __HAL_UNLOCK(hrtc);
mbed_official 354:e67efb2aab0e 403
mbed_official 354:e67efb2aab0e 404 return HAL_ERROR;
mbed_official 354:e67efb2aab0e 405 }
mbed_official 354:e67efb2aab0e 406 else
mbed_official 354:e67efb2aab0e 407 {
mbed_official 354:e67efb2aab0e 408 /* Set the RTC_TR register */
mbed_official 354:e67efb2aab0e 409 hrtc->Instance->TR = (uint32_t)(tmpreg & RTC_TR_RESERVED_MASK);
mbed_official 354:e67efb2aab0e 410
mbed_official 354:e67efb2aab0e 411 /* Clear the bits to be configured */
mbed_official 354:e67efb2aab0e 412 hrtc->Instance->CR &= (uint32_t)~RTC_CR_BCK;
mbed_official 354:e67efb2aab0e 413
mbed_official 354:e67efb2aab0e 414 /* Configure the RTC_CR register */
mbed_official 354:e67efb2aab0e 415 hrtc->Instance->CR |= (uint32_t)(sTime->DayLightSaving | sTime->StoreOperation);
mbed_official 354:e67efb2aab0e 416
mbed_official 354:e67efb2aab0e 417 /* Exit Initialization mode */
mbed_official 354:e67efb2aab0e 418 hrtc->Instance->ISR &= (uint32_t)~RTC_ISR_INIT;
mbed_official 354:e67efb2aab0e 419
mbed_official 354:e67efb2aab0e 420 /* Wait for synchro */
mbed_official 354:e67efb2aab0e 421 if(HAL_RTC_WaitForSynchro(hrtc) != HAL_OK)
mbed_official 354:e67efb2aab0e 422 {
mbed_official 354:e67efb2aab0e 423 /* Enable the write protection for RTC registers */
mbed_official 354:e67efb2aab0e 424 __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc);
mbed_official 354:e67efb2aab0e 425
mbed_official 354:e67efb2aab0e 426 hrtc->State = HAL_RTC_STATE_ERROR;
mbed_official 354:e67efb2aab0e 427
mbed_official 354:e67efb2aab0e 428 /* Process Unlocked */
mbed_official 354:e67efb2aab0e 429 __HAL_UNLOCK(hrtc);
mbed_official 354:e67efb2aab0e 430
mbed_official 354:e67efb2aab0e 431 return HAL_ERROR;
mbed_official 354:e67efb2aab0e 432 }
mbed_official 354:e67efb2aab0e 433
mbed_official 354:e67efb2aab0e 434 /* Enable the write protection for RTC registers */
mbed_official 354:e67efb2aab0e 435 __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc);
mbed_official 354:e67efb2aab0e 436
mbed_official 354:e67efb2aab0e 437 hrtc->State = HAL_RTC_STATE_READY;
mbed_official 354:e67efb2aab0e 438
mbed_official 354:e67efb2aab0e 439 __HAL_UNLOCK(hrtc);
mbed_official 354:e67efb2aab0e 440
mbed_official 354:e67efb2aab0e 441 return HAL_OK;
mbed_official 354:e67efb2aab0e 442 }
mbed_official 354:e67efb2aab0e 443 }
mbed_official 354:e67efb2aab0e 444
mbed_official 354:e67efb2aab0e 445
mbed_official 354:e67efb2aab0e 446 /**
mbed_official 354:e67efb2aab0e 447 * @brief Sets RTC current date.
mbed_official 354:e67efb2aab0e 448 * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains
mbed_official 354:e67efb2aab0e 449 * the configuration information for RTC.
mbed_official 354:e67efb2aab0e 450 * @param sDate: Pointer to date structure
mbed_official 354:e67efb2aab0e 451 * @param Format: specifies the format of the entered parameters.
mbed_official 354:e67efb2aab0e 452 * This parameter can be one of the following values:
mbed_official 354:e67efb2aab0e 453 * @arg FORMAT_BIN: Binary data format
mbed_official 354:e67efb2aab0e 454 * @arg FORMAT_BCD: BCD data format
mbed_official 354:e67efb2aab0e 455 * @retval HAL status
mbed_official 354:e67efb2aab0e 456 */
mbed_official 354:e67efb2aab0e 457 HAL_StatusTypeDef HAL_RTC_SetDate(RTC_HandleTypeDef *hrtc, RTC_DateTypeDef *sDate, uint32_t Format)
mbed_official 354:e67efb2aab0e 458 {
mbed_official 354:e67efb2aab0e 459 uint32_t datetmpreg = 0;
mbed_official 354:e67efb2aab0e 460
mbed_official 354:e67efb2aab0e 461 /* Check the parameters */
mbed_official 354:e67efb2aab0e 462 assert_param(IS_RTC_FORMAT(Format));
mbed_official 354:e67efb2aab0e 463
mbed_official 354:e67efb2aab0e 464 /* Process Locked */
mbed_official 354:e67efb2aab0e 465 __HAL_LOCK(hrtc);
mbed_official 354:e67efb2aab0e 466
mbed_official 354:e67efb2aab0e 467 hrtc->State = HAL_RTC_STATE_BUSY;
mbed_official 354:e67efb2aab0e 468
mbed_official 354:e67efb2aab0e 469 if((Format == FORMAT_BIN) && ((sDate->Month & 0x10) == 0x10))
mbed_official 354:e67efb2aab0e 470 {
mbed_official 354:e67efb2aab0e 471 sDate->Month = (uint8_t)((sDate->Month & (uint8_t)~(0x10)) + (uint8_t)0x0A);
mbed_official 354:e67efb2aab0e 472 }
mbed_official 354:e67efb2aab0e 473
mbed_official 354:e67efb2aab0e 474 assert_param(IS_RTC_WEEKDAY(sDate->WeekDay));
mbed_official 354:e67efb2aab0e 475
mbed_official 354:e67efb2aab0e 476 if(Format == FORMAT_BIN)
mbed_official 354:e67efb2aab0e 477 {
mbed_official 354:e67efb2aab0e 478 assert_param(IS_RTC_YEAR(sDate->Year));
mbed_official 354:e67efb2aab0e 479 assert_param(IS_RTC_MONTH(sDate->Month));
mbed_official 354:e67efb2aab0e 480 assert_param(IS_RTC_DATE(sDate->Date));
mbed_official 354:e67efb2aab0e 481
mbed_official 354:e67efb2aab0e 482 datetmpreg = (((uint32_t)RTC_ByteToBcd2(sDate->Year) << 16) | \
mbed_official 354:e67efb2aab0e 483 ((uint32_t)RTC_ByteToBcd2(sDate->Month) << 8) | \
mbed_official 354:e67efb2aab0e 484 ((uint32_t)RTC_ByteToBcd2(sDate->Date)) | \
mbed_official 354:e67efb2aab0e 485 ((uint32_t)sDate->WeekDay << 13));
mbed_official 354:e67efb2aab0e 486 }
mbed_official 354:e67efb2aab0e 487 else
mbed_official 354:e67efb2aab0e 488 {
mbed_official 354:e67efb2aab0e 489 assert_param(IS_RTC_YEAR(RTC_Bcd2ToByte(sDate->Year)));
mbed_official 354:e67efb2aab0e 490 datetmpreg = RTC_Bcd2ToByte(sDate->Month);
mbed_official 354:e67efb2aab0e 491 assert_param(IS_RTC_MONTH(datetmpreg));
mbed_official 354:e67efb2aab0e 492 datetmpreg = RTC_Bcd2ToByte(sDate->Date);
mbed_official 354:e67efb2aab0e 493 assert_param(IS_RTC_DATE(datetmpreg));
mbed_official 354:e67efb2aab0e 494
mbed_official 354:e67efb2aab0e 495 datetmpreg = ((((uint32_t)sDate->Year) << 16) | \
mbed_official 354:e67efb2aab0e 496 (((uint32_t)sDate->Month) << 8) | \
mbed_official 354:e67efb2aab0e 497 ((uint32_t)sDate->Date) | \
mbed_official 354:e67efb2aab0e 498 (((uint32_t)sDate->WeekDay) << 13));
mbed_official 354:e67efb2aab0e 499 }
mbed_official 354:e67efb2aab0e 500
mbed_official 354:e67efb2aab0e 501 /* Disable the write protection for RTC registers */
mbed_official 354:e67efb2aab0e 502 __HAL_RTC_WRITEPROTECTION_DISABLE(hrtc);
mbed_official 354:e67efb2aab0e 503
mbed_official 354:e67efb2aab0e 504 /* Set Initialization mode */
mbed_official 354:e67efb2aab0e 505 if(RTC_EnterInitMode(hrtc) != HAL_OK)
mbed_official 354:e67efb2aab0e 506 {
mbed_official 354:e67efb2aab0e 507 /* Enable the write protection for RTC registers */
mbed_official 354:e67efb2aab0e 508 __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc);
mbed_official 354:e67efb2aab0e 509
mbed_official 354:e67efb2aab0e 510 /* Set RTC state*/
mbed_official 354:e67efb2aab0e 511 hrtc->State = HAL_RTC_STATE_ERROR;
mbed_official 354:e67efb2aab0e 512
mbed_official 354:e67efb2aab0e 513 /* Process Unlocked */
mbed_official 354:e67efb2aab0e 514 __HAL_UNLOCK(hrtc);
mbed_official 354:e67efb2aab0e 515
mbed_official 354:e67efb2aab0e 516 return HAL_ERROR;
mbed_official 354:e67efb2aab0e 517 }
mbed_official 354:e67efb2aab0e 518 else
mbed_official 354:e67efb2aab0e 519 {
mbed_official 354:e67efb2aab0e 520 /* Set the RTC_DR register */
mbed_official 354:e67efb2aab0e 521 hrtc->Instance->DR = (uint32_t)(datetmpreg & RTC_DR_RESERVED_MASK);
mbed_official 354:e67efb2aab0e 522
mbed_official 354:e67efb2aab0e 523 /* Exit Initialization mode */
mbed_official 354:e67efb2aab0e 524 hrtc->Instance->ISR &= (uint32_t)~RTC_ISR_INIT;
mbed_official 354:e67efb2aab0e 525
mbed_official 354:e67efb2aab0e 526 /* Wait for synchro */
mbed_official 354:e67efb2aab0e 527 if(HAL_RTC_WaitForSynchro(hrtc) != HAL_OK)
mbed_official 354:e67efb2aab0e 528 {
mbed_official 354:e67efb2aab0e 529 /* Enable the write protection for RTC registers */
mbed_official 354:e67efb2aab0e 530 __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc);
mbed_official 354:e67efb2aab0e 531
mbed_official 354:e67efb2aab0e 532 hrtc->State = HAL_RTC_STATE_ERROR;
mbed_official 354:e67efb2aab0e 533
mbed_official 354:e67efb2aab0e 534 /* Process Unlocked */
mbed_official 354:e67efb2aab0e 535 __HAL_UNLOCK(hrtc);
mbed_official 354:e67efb2aab0e 536
mbed_official 354:e67efb2aab0e 537 return HAL_ERROR;
mbed_official 354:e67efb2aab0e 538 }
mbed_official 354:e67efb2aab0e 539
mbed_official 354:e67efb2aab0e 540 /* Enable the write protection for RTC registers */
mbed_official 354:e67efb2aab0e 541 __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc);
mbed_official 354:e67efb2aab0e 542
mbed_official 354:e67efb2aab0e 543 hrtc->State = HAL_RTC_STATE_READY ;
mbed_official 354:e67efb2aab0e 544
mbed_official 354:e67efb2aab0e 545 /* Process Unlocked */
mbed_official 354:e67efb2aab0e 546 __HAL_UNLOCK(hrtc);
mbed_official 354:e67efb2aab0e 547
mbed_official 354:e67efb2aab0e 548 return HAL_OK;
mbed_official 354:e67efb2aab0e 549 }
mbed_official 354:e67efb2aab0e 550 }
mbed_official 354:e67efb2aab0e 551
mbed_official 354:e67efb2aab0e 552 /**
mbed_official 354:e67efb2aab0e 553 * @brief Gets RTC current date.
mbed_official 354:e67efb2aab0e 554 * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains
mbed_official 354:e67efb2aab0e 555 * the configuration information for RTC.
mbed_official 354:e67efb2aab0e 556 * @param sDate: Pointer to Date structure
mbed_official 354:e67efb2aab0e 557 * @param Format: Specifies the format of the entered parameters.
mbed_official 354:e67efb2aab0e 558 * This parameter can be one of the following values:
mbed_official 354:e67efb2aab0e 559 * @arg FORMAT_BIN: Binary data format
mbed_official 354:e67efb2aab0e 560 * @arg FORMAT_BCD: BCD data format
mbed_official 354:e67efb2aab0e 561 * @retval HAL status
mbed_official 354:e67efb2aab0e 562 */
mbed_official 354:e67efb2aab0e 563 HAL_StatusTypeDef HAL_RTC_GetDate(RTC_HandleTypeDef *hrtc, RTC_DateTypeDef *sDate, uint32_t Format)
mbed_official 354:e67efb2aab0e 564 {
mbed_official 354:e67efb2aab0e 565 uint32_t datetmpreg = 0;
mbed_official 354:e67efb2aab0e 566
mbed_official 354:e67efb2aab0e 567 /* Check the parameters */
mbed_official 354:e67efb2aab0e 568 assert_param(IS_RTC_FORMAT(Format));
mbed_official 354:e67efb2aab0e 569
mbed_official 354:e67efb2aab0e 570 /* Get the DR register */
mbed_official 354:e67efb2aab0e 571 datetmpreg = (uint32_t)(hrtc->Instance->DR & RTC_DR_RESERVED_MASK);
mbed_official 354:e67efb2aab0e 572
mbed_official 354:e67efb2aab0e 573 /* Fill the structure fields with the read parameters */
mbed_official 354:e67efb2aab0e 574 sDate->Year = (uint8_t)((datetmpreg & (RTC_DR_YT | RTC_DR_YU)) >> 16);
mbed_official 354:e67efb2aab0e 575 sDate->Month = (uint8_t)((datetmpreg & (RTC_DR_MT | RTC_DR_MU)) >> 8);
mbed_official 354:e67efb2aab0e 576 sDate->Date = (uint8_t)(datetmpreg & (RTC_DR_DT | RTC_DR_DU));
mbed_official 354:e67efb2aab0e 577 sDate->WeekDay = (uint8_t)((datetmpreg & (RTC_DR_WDU)) >> 13);
mbed_official 354:e67efb2aab0e 578
mbed_official 354:e67efb2aab0e 579 /* Check the input parameters format */
mbed_official 354:e67efb2aab0e 580 if(Format == FORMAT_BIN)
mbed_official 354:e67efb2aab0e 581 {
mbed_official 354:e67efb2aab0e 582 /* Convert the date structure parameters to Binary format */
mbed_official 354:e67efb2aab0e 583 sDate->Year = (uint8_t)RTC_Bcd2ToByte(sDate->Year);
mbed_official 354:e67efb2aab0e 584 sDate->Month = (uint8_t)RTC_Bcd2ToByte(sDate->Month);
mbed_official 354:e67efb2aab0e 585 sDate->Date = (uint8_t)RTC_Bcd2ToByte(sDate->Date);
mbed_official 354:e67efb2aab0e 586 }
mbed_official 354:e67efb2aab0e 587 return HAL_OK;
mbed_official 354:e67efb2aab0e 588 }
mbed_official 354:e67efb2aab0e 589
mbed_official 354:e67efb2aab0e 590 /**
mbed_official 354:e67efb2aab0e 591 * @}
mbed_official 354:e67efb2aab0e 592 */
mbed_official 354:e67efb2aab0e 593
mbed_official 354:e67efb2aab0e 594 /** @defgroup RTC_Exported_Functions_Group3 RTC Alarm functions
mbed_official 354:e67efb2aab0e 595 * @brief RTC Alarm functions
mbed_official 354:e67efb2aab0e 596 *
mbed_official 354:e67efb2aab0e 597 @verbatim
mbed_official 354:e67efb2aab0e 598 ===============================================================================
mbed_official 354:e67efb2aab0e 599 ##### RTC Alarm functions #####
mbed_official 354:e67efb2aab0e 600 ===============================================================================
mbed_official 354:e67efb2aab0e 601
mbed_official 354:e67efb2aab0e 602 [..] This section provides functions allowing to configure Alarm feature
mbed_official 354:e67efb2aab0e 603
mbed_official 354:e67efb2aab0e 604 @endverbatim
mbed_official 354:e67efb2aab0e 605 * @{
mbed_official 354:e67efb2aab0e 606 */
mbed_official 354:e67efb2aab0e 607
mbed_official 354:e67efb2aab0e 608 /**
mbed_official 354:e67efb2aab0e 609 * @brief Deactive the specified RTC Alarm
mbed_official 354:e67efb2aab0e 610 * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains
mbed_official 354:e67efb2aab0e 611 * the configuration information for RTC.
mbed_official 354:e67efb2aab0e 612 * @param Alarm: Specifies the Alarm.
mbed_official 354:e67efb2aab0e 613 * This parameter can be one of the following values:
mbed_official 354:e67efb2aab0e 614 * @arg RTC_ALARM_A: AlarmA
mbed_official 354:e67efb2aab0e 615 * @arg RTC_ALARM_B: AlarmB
mbed_official 354:e67efb2aab0e 616 * @retval HAL status
mbed_official 354:e67efb2aab0e 617 */
mbed_official 354:e67efb2aab0e 618 HAL_StatusTypeDef HAL_RTC_DeactivateAlarm(RTC_HandleTypeDef *hrtc, uint32_t Alarm)
mbed_official 354:e67efb2aab0e 619 {
mbed_official 354:e67efb2aab0e 620 uint32_t tickstart = 0;
mbed_official 354:e67efb2aab0e 621
mbed_official 354:e67efb2aab0e 622 /* Check the parameters */
mbed_official 354:e67efb2aab0e 623 assert_param(IS_ALARM(Alarm));
mbed_official 354:e67efb2aab0e 624
mbed_official 354:e67efb2aab0e 625 /* Process Locked */
mbed_official 354:e67efb2aab0e 626 __HAL_LOCK(hrtc);
mbed_official 354:e67efb2aab0e 627
mbed_official 354:e67efb2aab0e 628 hrtc->State = HAL_RTC_STATE_BUSY;
mbed_official 354:e67efb2aab0e 629
mbed_official 354:e67efb2aab0e 630 /* Disable the write protection for RTC registers */
mbed_official 354:e67efb2aab0e 631 __HAL_RTC_WRITEPROTECTION_DISABLE(hrtc);
mbed_official 354:e67efb2aab0e 632
mbed_official 354:e67efb2aab0e 633 if(Alarm == RTC_ALARM_A)
mbed_official 354:e67efb2aab0e 634 {
mbed_official 354:e67efb2aab0e 635 /* AlarmA */
mbed_official 354:e67efb2aab0e 636 __HAL_RTC_ALARMA_DISABLE(hrtc);
mbed_official 354:e67efb2aab0e 637
mbed_official 354:e67efb2aab0e 638 /* In case of interrupt mode is used, the interrupt source must disabled */
mbed_official 354:e67efb2aab0e 639 __HAL_RTC_ALARM_DISABLE_IT(hrtc, RTC_IT_ALRA);
mbed_official 354:e67efb2aab0e 640
mbed_official 354:e67efb2aab0e 641 tickstart = HAL_GetTick();
mbed_official 354:e67efb2aab0e 642
mbed_official 354:e67efb2aab0e 643 /* Wait till RTC ALRxWF flag is set and if Time out is reached exit */
mbed_official 354:e67efb2aab0e 644 while(__HAL_RTC_ALARM_GET_FLAG(hrtc, RTC_FLAG_ALRAWF) == RESET)
mbed_official 354:e67efb2aab0e 645 {
mbed_official 354:e67efb2aab0e 646 if((HAL_GetTick() - tickstart ) > RTC_TIMEOUT_VALUE)
mbed_official 354:e67efb2aab0e 647 {
mbed_official 354:e67efb2aab0e 648 /* Enable the write protection for RTC registers */
mbed_official 354:e67efb2aab0e 649 __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc);
mbed_official 354:e67efb2aab0e 650
mbed_official 354:e67efb2aab0e 651 hrtc->State = HAL_RTC_STATE_TIMEOUT;
mbed_official 354:e67efb2aab0e 652
mbed_official 354:e67efb2aab0e 653 /* Process Unlocked */
mbed_official 354:e67efb2aab0e 654 __HAL_UNLOCK(hrtc);
mbed_official 354:e67efb2aab0e 655
mbed_official 354:e67efb2aab0e 656 return HAL_TIMEOUT;
mbed_official 354:e67efb2aab0e 657 }
mbed_official 354:e67efb2aab0e 658 }
mbed_official 354:e67efb2aab0e 659 }
mbed_official 354:e67efb2aab0e 660 else
mbed_official 354:e67efb2aab0e 661 {
mbed_official 354:e67efb2aab0e 662 /* AlarmB */
mbed_official 354:e67efb2aab0e 663 __HAL_RTC_ALARMB_DISABLE(hrtc);
mbed_official 354:e67efb2aab0e 664
mbed_official 354:e67efb2aab0e 665 /* In case of interrupt mode is used, the interrupt source must disabled */
mbed_official 354:e67efb2aab0e 666 __HAL_RTC_ALARM_DISABLE_IT(hrtc,RTC_IT_ALRB);
mbed_official 354:e67efb2aab0e 667
mbed_official 354:e67efb2aab0e 668 tickstart = HAL_GetTick();
mbed_official 354:e67efb2aab0e 669
mbed_official 354:e67efb2aab0e 670 /* Wait till RTC ALRxWF flag is set and if Time out is reached exit */
mbed_official 354:e67efb2aab0e 671 while(__HAL_RTC_ALARM_GET_FLAG(hrtc, RTC_FLAG_ALRBWF) == RESET)
mbed_official 354:e67efb2aab0e 672 {
mbed_official 354:e67efb2aab0e 673 if((HAL_GetTick() - tickstart ) > RTC_TIMEOUT_VALUE)
mbed_official 354:e67efb2aab0e 674 {
mbed_official 354:e67efb2aab0e 675 /* Enable the write protection for RTC registers */
mbed_official 354:e67efb2aab0e 676 __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc);
mbed_official 354:e67efb2aab0e 677
mbed_official 354:e67efb2aab0e 678 hrtc->State = HAL_RTC_STATE_TIMEOUT;
mbed_official 354:e67efb2aab0e 679
mbed_official 354:e67efb2aab0e 680 /* Process Unlocked */
mbed_official 354:e67efb2aab0e 681 __HAL_UNLOCK(hrtc);
mbed_official 354:e67efb2aab0e 682
mbed_official 354:e67efb2aab0e 683 return HAL_TIMEOUT;
mbed_official 354:e67efb2aab0e 684 }
mbed_official 354:e67efb2aab0e 685 }
mbed_official 354:e67efb2aab0e 686 }
mbed_official 354:e67efb2aab0e 687 /* Enable the write protection for RTC registers */
mbed_official 354:e67efb2aab0e 688 __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc);
mbed_official 354:e67efb2aab0e 689
mbed_official 354:e67efb2aab0e 690 hrtc->State = HAL_RTC_STATE_READY;
mbed_official 354:e67efb2aab0e 691
mbed_official 354:e67efb2aab0e 692 /* Process Unlocked */
mbed_official 354:e67efb2aab0e 693 __HAL_UNLOCK(hrtc);
mbed_official 354:e67efb2aab0e 694
mbed_official 354:e67efb2aab0e 695 return HAL_OK;
mbed_official 354:e67efb2aab0e 696 }
mbed_official 354:e67efb2aab0e 697
mbed_official 354:e67efb2aab0e 698 /**
mbed_official 354:e67efb2aab0e 699 * @brief This function handles Alarm interrupt request.
mbed_official 354:e67efb2aab0e 700 * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains
mbed_official 354:e67efb2aab0e 701 * the configuration information for RTC.
mbed_official 354:e67efb2aab0e 702 * @retval None
mbed_official 354:e67efb2aab0e 703 */
mbed_official 354:e67efb2aab0e 704 void HAL_RTC_AlarmIRQHandler(RTC_HandleTypeDef* hrtc)
mbed_official 354:e67efb2aab0e 705 {
mbed_official 354:e67efb2aab0e 706 if(__HAL_RTC_ALARM_GET_IT(hrtc, RTC_IT_ALRA))
mbed_official 354:e67efb2aab0e 707 {
mbed_official 354:e67efb2aab0e 708 /* Get the status of the Interrupt */
mbed_official 354:e67efb2aab0e 709 if((uint32_t)(hrtc->Instance->CR & RTC_IT_ALRA) != (uint32_t)RESET)
mbed_official 354:e67efb2aab0e 710 {
mbed_official 354:e67efb2aab0e 711 /* AlarmA callback */
mbed_official 354:e67efb2aab0e 712 HAL_RTC_AlarmAEventCallback(hrtc);
mbed_official 354:e67efb2aab0e 713
mbed_official 354:e67efb2aab0e 714 /* Clear the Alarm interrupt pending bit */
mbed_official 354:e67efb2aab0e 715 __HAL_RTC_ALARM_CLEAR_FLAG(hrtc,RTC_FLAG_ALRAF);
mbed_official 354:e67efb2aab0e 716 }
mbed_official 354:e67efb2aab0e 717 }
mbed_official 354:e67efb2aab0e 718
mbed_official 354:e67efb2aab0e 719 if(__HAL_RTC_ALARM_GET_IT(hrtc, RTC_IT_ALRB))
mbed_official 354:e67efb2aab0e 720 {
mbed_official 354:e67efb2aab0e 721 /* Get the status of the Interrupt */
mbed_official 354:e67efb2aab0e 722 if((uint32_t)(hrtc->Instance->CR & RTC_IT_ALRB) != (uint32_t)RESET)
mbed_official 354:e67efb2aab0e 723 {
mbed_official 354:e67efb2aab0e 724 /* AlarmB callback */
mbed_official 354:e67efb2aab0e 725 HAL_RTCEx_AlarmBEventCallback(hrtc);
mbed_official 354:e67efb2aab0e 726
mbed_official 354:e67efb2aab0e 727 /* Clear the Alarm interrupt pending bit */
mbed_official 354:e67efb2aab0e 728 __HAL_RTC_ALARM_CLEAR_FLAG(hrtc,RTC_FLAG_ALRBF);
mbed_official 354:e67efb2aab0e 729 }
mbed_official 354:e67efb2aab0e 730 }
mbed_official 354:e67efb2aab0e 731
mbed_official 354:e67efb2aab0e 732 /* Clear the EXTI's line Flag for RTC Alarm */
mbed_official 354:e67efb2aab0e 733 __HAL_RTC_CLEAR_FLAG(RTC_EXTI_LINE_ALARM_EVENT);
mbed_official 354:e67efb2aab0e 734
mbed_official 354:e67efb2aab0e 735 /* Change RTC state */
mbed_official 354:e67efb2aab0e 736 hrtc->State = HAL_RTC_STATE_READY;
mbed_official 354:e67efb2aab0e 737 }
mbed_official 354:e67efb2aab0e 738
mbed_official 354:e67efb2aab0e 739 /**
mbed_official 354:e67efb2aab0e 740 * @brief Alarm A callback.
mbed_official 354:e67efb2aab0e 741 * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains
mbed_official 354:e67efb2aab0e 742 * the configuration information for RTC.
mbed_official 354:e67efb2aab0e 743 * @retval None
mbed_official 354:e67efb2aab0e 744 */
mbed_official 354:e67efb2aab0e 745 __weak void HAL_RTC_AlarmAEventCallback(RTC_HandleTypeDef *hrtc)
mbed_official 354:e67efb2aab0e 746 {
mbed_official 354:e67efb2aab0e 747 /* NOTE : This function Should not be modified, when the callback is needed,
mbed_official 354:e67efb2aab0e 748 the HAL_RTC_AlarmAEventCallback could be implemented in the user file
mbed_official 354:e67efb2aab0e 749 */
mbed_official 354:e67efb2aab0e 750 }
mbed_official 354:e67efb2aab0e 751
mbed_official 354:e67efb2aab0e 752 /**
mbed_official 354:e67efb2aab0e 753 * @brief This function handles AlarmA Polling request.
mbed_official 354:e67efb2aab0e 754 * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains
mbed_official 354:e67efb2aab0e 755 * the configuration information for RTC.
mbed_official 354:e67efb2aab0e 756 * @param Timeout: Timeout duration
mbed_official 354:e67efb2aab0e 757 * @retval HAL status
mbed_official 354:e67efb2aab0e 758 */
mbed_official 354:e67efb2aab0e 759 HAL_StatusTypeDef HAL_RTC_PollForAlarmAEvent(RTC_HandleTypeDef *hrtc, uint32_t Timeout)
mbed_official 354:e67efb2aab0e 760 {
mbed_official 354:e67efb2aab0e 761
mbed_official 354:e67efb2aab0e 762 uint32_t tickstart = HAL_GetTick();
mbed_official 354:e67efb2aab0e 763
mbed_official 354:e67efb2aab0e 764 while(__HAL_RTC_ALARM_GET_FLAG(hrtc, RTC_FLAG_ALRAF) == RESET)
mbed_official 354:e67efb2aab0e 765 {
mbed_official 354:e67efb2aab0e 766 if(Timeout != HAL_MAX_DELAY)
mbed_official 354:e67efb2aab0e 767 {
mbed_official 354:e67efb2aab0e 768 if((Timeout == 0)||((HAL_GetTick() - tickstart ) > Timeout))
mbed_official 354:e67efb2aab0e 769 {
mbed_official 354:e67efb2aab0e 770 hrtc->State = HAL_RTC_STATE_TIMEOUT;
mbed_official 354:e67efb2aab0e 771 return HAL_TIMEOUT;
mbed_official 354:e67efb2aab0e 772 }
mbed_official 354:e67efb2aab0e 773 }
mbed_official 354:e67efb2aab0e 774 }
mbed_official 354:e67efb2aab0e 775
mbed_official 354:e67efb2aab0e 776 /* Clear the Alarm interrupt pending bit */
mbed_official 354:e67efb2aab0e 777 __HAL_RTC_ALARM_CLEAR_FLAG(hrtc, RTC_FLAG_ALRAF);
mbed_official 354:e67efb2aab0e 778
mbed_official 354:e67efb2aab0e 779 /* Change RTC state */
mbed_official 354:e67efb2aab0e 780 hrtc->State = HAL_RTC_STATE_READY;
mbed_official 354:e67efb2aab0e 781
mbed_official 354:e67efb2aab0e 782 return HAL_OK;
mbed_official 354:e67efb2aab0e 783 }
mbed_official 354:e67efb2aab0e 784
mbed_official 354:e67efb2aab0e 785 /**
mbed_official 354:e67efb2aab0e 786 * @}
mbed_official 354:e67efb2aab0e 787 */
mbed_official 354:e67efb2aab0e 788
mbed_official 354:e67efb2aab0e 789 /** @defgroup RTC_Exported_Functions_Group5 Peripheral State functions
mbed_official 354:e67efb2aab0e 790 * @brief Peripheral State functions
mbed_official 354:e67efb2aab0e 791 *
mbed_official 354:e67efb2aab0e 792 @verbatim
mbed_official 354:e67efb2aab0e 793 ===============================================================================
mbed_official 354:e67efb2aab0e 794 ##### Peripheral State functions #####
mbed_official 354:e67efb2aab0e 795 ===============================================================================
mbed_official 354:e67efb2aab0e 796 [..]
mbed_official 354:e67efb2aab0e 797 This subsection provides functions allowing to
mbed_official 354:e67efb2aab0e 798 (+) Get RTC state
mbed_official 354:e67efb2aab0e 799
mbed_official 354:e67efb2aab0e 800 @endverbatim
mbed_official 354:e67efb2aab0e 801 * @{
mbed_official 354:e67efb2aab0e 802 */
mbed_official 354:e67efb2aab0e 803 /**
mbed_official 354:e67efb2aab0e 804 * @brief Returns the RTC state.
mbed_official 354:e67efb2aab0e 805 * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains
mbed_official 354:e67efb2aab0e 806 * the configuration information for RTC.
mbed_official 354:e67efb2aab0e 807 * @retval HAL state
mbed_official 354:e67efb2aab0e 808 */
mbed_official 354:e67efb2aab0e 809 HAL_RTCStateTypeDef HAL_RTC_GetState(RTC_HandleTypeDef* hrtc)
mbed_official 354:e67efb2aab0e 810 {
mbed_official 354:e67efb2aab0e 811 return hrtc->State;
mbed_official 354:e67efb2aab0e 812 }
mbed_official 354:e67efb2aab0e 813
mbed_official 354:e67efb2aab0e 814 /**
mbed_official 354:e67efb2aab0e 815 * @}
mbed_official 354:e67efb2aab0e 816 */
mbed_official 354:e67efb2aab0e 817
mbed_official 354:e67efb2aab0e 818 /**
mbed_official 354:e67efb2aab0e 819 * @}
mbed_official 354:e67efb2aab0e 820 */
mbed_official 354:e67efb2aab0e 821
mbed_official 354:e67efb2aab0e 822 /** @defgroup RTC_Internal_Functions RTC Internal function
mbed_official 354:e67efb2aab0e 823 * @{
mbed_official 354:e67efb2aab0e 824 */
mbed_official 354:e67efb2aab0e 825
mbed_official 354:e67efb2aab0e 826 /**
mbed_official 354:e67efb2aab0e 827 * @brief Enters the RTC Initialization mode.
mbed_official 354:e67efb2aab0e 828 * @note The RTC Initialization mode is write protected, use the
mbed_official 354:e67efb2aab0e 829 * __HAL_RTC_WRITEPROTECTION_DISABLE() before calling this function.
mbed_official 354:e67efb2aab0e 830 * @param hrtc: pointer to a RTC_HandleTypeDef structure that contains
mbed_official 354:e67efb2aab0e 831 * the configuration information for RTC.
mbed_official 354:e67efb2aab0e 832 * @retval HAL status
mbed_official 354:e67efb2aab0e 833 */
mbed_official 354:e67efb2aab0e 834 HAL_StatusTypeDef RTC_EnterInitMode(RTC_HandleTypeDef* hrtc)
mbed_official 354:e67efb2aab0e 835 {
mbed_official 354:e67efb2aab0e 836 uint32_t tickstart = 0;
mbed_official 354:e67efb2aab0e 837
mbed_official 354:e67efb2aab0e 838 /* Check if the Initialization mode is set */
mbed_official 354:e67efb2aab0e 839 if((hrtc->Instance->ISR & RTC_ISR_INITF) == (uint32_t)RESET)
mbed_official 354:e67efb2aab0e 840 {
mbed_official 354:e67efb2aab0e 841 /* Set the Initialization mode */
mbed_official 354:e67efb2aab0e 842 hrtc->Instance->ISR = (uint32_t)RTC_INIT_MASK;
mbed_official 354:e67efb2aab0e 843
mbed_official 354:e67efb2aab0e 844 tickstart = HAL_GetTick();
mbed_official 354:e67efb2aab0e 845 /* Wait till RTC is in INIT state and if Time out is reached exit */
mbed_official 354:e67efb2aab0e 846 while((hrtc->Instance->ISR & RTC_ISR_INITF) == (uint32_t)RESET)
mbed_official 354:e67efb2aab0e 847 {
mbed_official 354:e67efb2aab0e 848 if((HAL_GetTick() - tickstart) > RTC_TIMEOUT_VALUE)
mbed_official 354:e67efb2aab0e 849 {
mbed_official 354:e67efb2aab0e 850 return HAL_TIMEOUT;
mbed_official 354:e67efb2aab0e 851 }
mbed_official 354:e67efb2aab0e 852 }
mbed_official 354:e67efb2aab0e 853 }
mbed_official 354:e67efb2aab0e 854
mbed_official 354:e67efb2aab0e 855 return HAL_OK;
mbed_official 354:e67efb2aab0e 856 }
mbed_official 354:e67efb2aab0e 857
mbed_official 354:e67efb2aab0e 858 /**
mbed_official 354:e67efb2aab0e 859 * @brief Converts a 2 digit decimal to BCD format.
mbed_official 354:e67efb2aab0e 860 * @param Value: Byte to be converted
mbed_official 354:e67efb2aab0e 861 * @retval Converted byte
mbed_official 354:e67efb2aab0e 862 */
mbed_official 354:e67efb2aab0e 863 uint8_t RTC_ByteToBcd2(uint8_t Value)
mbed_official 354:e67efb2aab0e 864 {
mbed_official 354:e67efb2aab0e 865 uint32_t bcdhigh = 0;
mbed_official 354:e67efb2aab0e 866
mbed_official 354:e67efb2aab0e 867 while(Value >= 10)
mbed_official 354:e67efb2aab0e 868 {
mbed_official 354:e67efb2aab0e 869 bcdhigh++;
mbed_official 354:e67efb2aab0e 870 Value -= 10;
mbed_official 354:e67efb2aab0e 871 }
mbed_official 354:e67efb2aab0e 872
mbed_official 354:e67efb2aab0e 873 return ((uint8_t)(bcdhigh << 4) | Value);
mbed_official 354:e67efb2aab0e 874 }
mbed_official 354:e67efb2aab0e 875
mbed_official 354:e67efb2aab0e 876 /**
mbed_official 354:e67efb2aab0e 877 * @brief Converts from 2 digit BCD to Binary.
mbed_official 354:e67efb2aab0e 878 * @param Value: BCD value to be converted
mbed_official 354:e67efb2aab0e 879 * @retval Converted word
mbed_official 354:e67efb2aab0e 880 */
mbed_official 354:e67efb2aab0e 881 uint8_t RTC_Bcd2ToByte(uint8_t Value)
mbed_official 354:e67efb2aab0e 882 {
mbed_official 354:e67efb2aab0e 883 uint32_t tmp = 0;
mbed_official 354:e67efb2aab0e 884 tmp = ((uint8_t)(Value & (uint8_t)0xF0) >> (uint8_t)0x4) * 10;
mbed_official 354:e67efb2aab0e 885 return (tmp + (Value & (uint8_t)0x0F));
mbed_official 354:e67efb2aab0e 886 }
mbed_official 354:e67efb2aab0e 887
mbed_official 354:e67efb2aab0e 888
mbed_official 354:e67efb2aab0e 889 /**
mbed_official 354:e67efb2aab0e 890 * @}
mbed_official 354:e67efb2aab0e 891 */
mbed_official 354:e67efb2aab0e 892
mbed_official 354:e67efb2aab0e 893 #endif /* HAL_RTC_MODULE_ENABLED */
mbed_official 354:e67efb2aab0e 894 /**
mbed_official 354:e67efb2aab0e 895 * @}
mbed_official 354:e67efb2aab0e 896 */
mbed_official 354:e67efb2aab0e 897
mbed_official 354:e67efb2aab0e 898 /**
mbed_official 354:e67efb2aab0e 899 * @}
mbed_official 354:e67efb2aab0e 900 */
mbed_official 354:e67efb2aab0e 901
mbed_official 354:e67efb2aab0e 902 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/