mbed library sources

Fork of mbed-src by mbed official

Committer:
mbed_official
Date:
Wed Nov 05 14:30:08 2014 +0000
Revision:
387:643a59b3dbac
Parent:
382:ee426a420dbb
Child:
489:119543c9f674
Synchronized with git revision cfeccf154f8f92c3ea9c0c881c577c154537aecc

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

Exporters: STM32L053R8 - IAR exporter

Who changed what in which revision?

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