mbed library sources

Dependents:   Marvino mbot

Fork of mbed-src by mbed official

Committer:
jaerts
Date:
Tue Dec 22 13:22:16 2015 +0000
Revision:
637:ed69428d4850
Parent:
610:813dcc80987e
Add very shady LPC1768 CAN Filter implementation

Who changed what in which revision?

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