mbed library sources

Dependents:   Marvino mbot

Fork of mbed-src by mbed official

Committer:
jaerts
Date:
Tue Dec 22 13:22:16 2015 +0000
Revision:
637:ed69428d4850
Parent:
155:8435094ec241
Add very shady LPC1768 CAN Filter implementation

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mbed_official 155:8435094ec241 1 /**
mbed_official 155:8435094ec241 2 ******************************************************************************
mbed_official 155:8435094ec241 3 * @file stm32f30x_rtc.c
mbed_official 155:8435094ec241 4 * @author MCD Application Team
mbed_official 155:8435094ec241 5 * @version V1.1.0
mbed_official 155:8435094ec241 6 * @date 27-February-2014
mbed_official 155:8435094ec241 7 * @brief This file provides firmware functions to manage the following
mbed_official 155:8435094ec241 8 * functionalities of the Real-Time Clock (RTC) peripheral:
mbed_official 155:8435094ec241 9 * + Initialization
mbed_official 155:8435094ec241 10 * + Calendar (Time and Date) configuration
mbed_official 155:8435094ec241 11 * + Alarms (Alarm A and Alarm B) configuration
mbed_official 155:8435094ec241 12 * + WakeUp Timer configuration
mbed_official 155:8435094ec241 13 * + Daylight Saving configuration
mbed_official 155:8435094ec241 14 * + Output pin Configuration
mbed_official 155:8435094ec241 15 * + Smooth digital Calibration configuration
mbed_official 155:8435094ec241 16 * + TimeStamp configuration
mbed_official 155:8435094ec241 17 * + Tampers configuration
mbed_official 155:8435094ec241 18 * + Backup Data Registers configuration
mbed_official 155:8435094ec241 19 * + Output Type Config configuration
mbed_official 155:8435094ec241 20 * + Shift control synchronisation
mbed_official 155:8435094ec241 21 * + Interrupts and flags management
mbed_official 155:8435094ec241 22 *
mbed_official 155:8435094ec241 23 @verbatim
mbed_official 155:8435094ec241 24
mbed_official 155:8435094ec241 25 ===============================================================================
mbed_official 155:8435094ec241 26 ##### RTC Operating Condition #####
mbed_official 155:8435094ec241 27 ===============================================================================
mbed_official 155:8435094ec241 28 [..] The real-time clock (RTC) and the RTC backup registers can be powered
mbed_official 155:8435094ec241 29 from the VBAT voltage when the main VDD supply is powered off.
mbed_official 155:8435094ec241 30 To retain the content of the RTC backup registers and supply the RTC
mbed_official 155:8435094ec241 31 when VDD is turned off, VBAT pin can be connected to an optional
mbed_official 155:8435094ec241 32 standby voltage supplied by a battery or by another source.
mbed_official 155:8435094ec241 33
mbed_official 155:8435094ec241 34 [..] To allow the RTC to operate even when the main digital supply (VDD)
mbed_official 155:8435094ec241 35 is turned off, the VBAT pin powers the following blocks:
mbed_official 155:8435094ec241 36 (#) The RTC
mbed_official 155:8435094ec241 37 (#) The LSE oscillator
mbed_official 155:8435094ec241 38 (#) PC13 to PC15 I/Os (when available)
mbed_official 155:8435094ec241 39
mbed_official 155:8435094ec241 40 [..] When the backup domain is supplied by VDD (analog switch connected
mbed_official 155:8435094ec241 41 to VDD), the following functions are available:
mbed_official 155:8435094ec241 42 (#) PC14 and PC15 can be used as either GPIO or LSE pins
mbed_official 155:8435094ec241 43 (#) PC13 can be used as a GPIO or as the RTC_AF pin
mbed_official 155:8435094ec241 44
mbed_official 155:8435094ec241 45 [..] When the backup domain is supplied by VBAT (analog switch connected
mbed_official 155:8435094ec241 46 to VBAT because VDD is not present), the following functions are available:
mbed_official 155:8435094ec241 47 (#) PC14 and PC15 can be used as LSE pins only
mbed_official 155:8435094ec241 48 (#) PC13 can be used as the RTC_AF pin
mbed_official 155:8435094ec241 49
mbed_official 155:8435094ec241 50 ##### Backup Domain Reset #####
mbed_official 155:8435094ec241 51 ===============================================================================
mbed_official 155:8435094ec241 52 [..] The backup domain reset sets all RTC registers and the RCC_BDCR
mbed_official 155:8435094ec241 53 register to their reset values.
mbed_official 155:8435094ec241 54 A backup domain reset is generated when one of the following events
mbed_official 155:8435094ec241 55 occurs:
mbed_official 155:8435094ec241 56 (#) Software reset, triggered by setting the BDRST bit in the
mbed_official 155:8435094ec241 57 RCC Backup domain control register (RCC_BDCR). You can use the
mbed_official 155:8435094ec241 58 RCC_BackupResetCmd().
mbed_official 155:8435094ec241 59 (#) VDD or VBAT power on, if both supplies have previously been
mbed_official 155:8435094ec241 60 powered off.
mbed_official 155:8435094ec241 61
mbed_official 155:8435094ec241 62 ##### Backup Domain Access #####
mbed_official 155:8435094ec241 63 ===============================================================================
mbed_official 155:8435094ec241 64 [..] After reset, the backup domain (RTC registers and RTC backup data
mbed_official 155:8435094ec241 65 registers) is protected against possible unwanted write accesses.
mbed_official 155:8435094ec241 66 [..] To enable access to the Backup Domain and RTC registers, proceed as follows:
mbed_official 155:8435094ec241 67 (#) Enable the Power Controller (PWR) APB1 interface clock using the
mbed_official 155:8435094ec241 68 RCC_APB1PeriphClockCmd() function.
mbed_official 155:8435094ec241 69 (#) Enable access to Backup domain using the PWR_BackupAccessCmd() function.
mbed_official 155:8435094ec241 70 (#) Select the RTC clock source using the RCC_RTCCLKConfig() function.
mbed_official 155:8435094ec241 71 (#) Enable RTC Clock using the RCC_RTCCLKCmd() function.
mbed_official 155:8435094ec241 72
mbed_official 155:8435094ec241 73 ##### How to use this driver #####
mbed_official 155:8435094ec241 74 ===============================================================================
mbed_official 155:8435094ec241 75 [..]
mbed_official 155:8435094ec241 76 (+) Enable the backup domain access (see description in the section above)
mbed_official 155:8435094ec241 77 (+) Configure the RTC Prescaler (Asynchronous and Synchronous) and
mbed_official 155:8435094ec241 78 RTC hour format using the RTC_Init() function.
mbed_official 155:8435094ec241 79
mbed_official 155:8435094ec241 80 *** Time and Date configuration ***
mbed_official 155:8435094ec241 81 ===================================
mbed_official 155:8435094ec241 82 [..]
mbed_official 155:8435094ec241 83 (+) To configure the RTC Calendar (Time and Date) use the RTC_SetTime()
mbed_official 155:8435094ec241 84 and RTC_SetDate() functions.
mbed_official 155:8435094ec241 85 (+) To read the RTC Calendar, use the RTC_GetTime() and RTC_GetDate()
mbed_official 155:8435094ec241 86 functions.
mbed_official 155:8435094ec241 87 (+) To read the RTC subsecond, use the RTC_GetSubSecond() function.
mbed_official 155:8435094ec241 88 (+) Use the RTC_DayLightSavingConfig() function to add or sub one
mbed_official 155:8435094ec241 89 hour to the RTC Calendar.
mbed_official 155:8435094ec241 90
mbed_official 155:8435094ec241 91 *** Alarm configuration ***
mbed_official 155:8435094ec241 92 ===========================
mbed_official 155:8435094ec241 93 [..]
mbed_official 155:8435094ec241 94 (+) To configure the RTC Alarm use the RTC_SetAlarm() function.
mbed_official 155:8435094ec241 95 (+) Enable the selected RTC Alarm using the RTC_AlarmCmd() function.
mbed_official 155:8435094ec241 96 (+) To read the RTC Alarm, use the RTC_GetAlarm() function.
mbed_official 155:8435094ec241 97 (+) To read the RTC alarm SubSecond, use the RTC_GetAlarmSubSecond() function.
mbed_official 155:8435094ec241 98
mbed_official 155:8435094ec241 99 *** RTC Wakeup configuration ***
mbed_official 155:8435094ec241 100 ================================
mbed_official 155:8435094ec241 101 [..]
mbed_official 155:8435094ec241 102 (+) Configure the RTC Wakeup Clock source use the RTC_WakeUpClockConfig()
mbed_official 155:8435094ec241 103 function.
mbed_official 155:8435094ec241 104 (+) Configure the RTC WakeUp Counter using the RTC_SetWakeUpCounter()
mbed_official 155:8435094ec241 105 function
mbed_official 155:8435094ec241 106 (+) Enable the RTC WakeUp using the RTC_WakeUpCmd() function
mbed_official 155:8435094ec241 107 (+) To read the RTC WakeUp Counter register, use the RTC_GetWakeUpCounter()
mbed_official 155:8435094ec241 108 function.
mbed_official 155:8435094ec241 109
mbed_official 155:8435094ec241 110 *** Outputs configuration ***
mbed_official 155:8435094ec241 111 =============================
mbed_official 155:8435094ec241 112 [..] The RTC has 2 different outputs:
mbed_official 155:8435094ec241 113 (+) AFO_ALARM: this output is used to manage the RTC Alarm A, Alarm B
mbed_official 155:8435094ec241 114 and WaKeUp signals.
mbed_official 155:8435094ec241 115 To output the selected RTC signal on RTC_AF pin, use the
mbed_official 155:8435094ec241 116 RTC_OutputConfig() function.
mbed_official 155:8435094ec241 117 (+) AFO_CALIB: this output is 512Hz signal or 1Hz .
mbed_official 155:8435094ec241 118 To output the RTC Clock on RTC_AF pin, use the RTC_CalibOutputCmd()
mbed_official 155:8435094ec241 119 function.
mbed_official 155:8435094ec241 120
mbed_official 155:8435094ec241 121 *** Smooth digital Calibration configuration ***
mbed_official 155:8435094ec241 122 ================================================
mbed_official 155:8435094ec241 123 [..]
mbed_official 155:8435094ec241 124 (+) Configure the RTC Original Digital Calibration Value and the corresponding
mbed_official 155:8435094ec241 125 calibration cycle period (32s,16s and 8s) using the RTC_SmoothCalibConfig()
mbed_official 155:8435094ec241 126 function.
mbed_official 155:8435094ec241 127
mbed_official 155:8435094ec241 128 *** TimeStamp configuration ***
mbed_official 155:8435094ec241 129 ===============================
mbed_official 155:8435094ec241 130 [..]
mbed_official 155:8435094ec241 131 (+) Configure the RTC_AF trigger and enables the RTC TimeStamp
mbed_official 155:8435094ec241 132 using the RTC_TimeStampCmd() function.
mbed_official 155:8435094ec241 133 (+) To read the RTC TimeStamp Time and Date register, use the
mbed_official 155:8435094ec241 134 RTC_GetTimeStamp() function.
mbed_official 155:8435094ec241 135 (+) To read the RTC TimeStamp SubSecond register, use the
mbed_official 155:8435094ec241 136 RTC_GetTimeStampSubSecond() function.
mbed_official 155:8435094ec241 137
mbed_official 155:8435094ec241 138 *** Tamper configuration ***
mbed_official 155:8435094ec241 139 ============================
mbed_official 155:8435094ec241 140 [..]
mbed_official 155:8435094ec241 141 (+) Configure the Tamper filter count using RTC_TamperFilterConfig()
mbed_official 155:8435094ec241 142 function.
mbed_official 155:8435094ec241 143 (+) Configure the RTC Tamper trigger Edge or Level according to the Tamper
mbed_official 155:8435094ec241 144 filter (if equal to 0 Edge else Level) value using the RTC_TamperConfig() function.
mbed_official 155:8435094ec241 145 (+) Configure the Tamper sampling frequency using RTC_TamperSamplingFreqConfig()
mbed_official 155:8435094ec241 146 function.
mbed_official 155:8435094ec241 147 (+) Configure the Tamper precharge or discharge duration using
mbed_official 155:8435094ec241 148 RTC_TamperPinsPrechargeDuration() function.
mbed_official 155:8435094ec241 149 (+) Enable the Tamper Pull-UP using RTC_TamperPullUpDisableCmd() function.
mbed_official 155:8435094ec241 150 (+) Enable the RTC Tamper using the RTC_TamperCmd() function.
mbed_official 155:8435094ec241 151 (+) Enable the Time stamp on Tamper detection event using
mbed_official 155:8435094ec241 152 RTC_TSOnTamperDetecCmd() function.
mbed_official 155:8435094ec241 153
mbed_official 155:8435094ec241 154 *** Backup Data Registers configuration ***
mbed_official 155:8435094ec241 155 ===========================================
mbed_official 155:8435094ec241 156 [..]
mbed_official 155:8435094ec241 157 (+) To write to the RTC Backup Data registers, use the RTC_WriteBackupRegister()
mbed_official 155:8435094ec241 158 function.
mbed_official 155:8435094ec241 159 (+) To read the RTC Backup Data registers, use the RTC_ReadBackupRegister()
mbed_official 155:8435094ec241 160 function.
mbed_official 155:8435094ec241 161
mbed_official 155:8435094ec241 162 ##### RTC and low power modes #####
mbed_official 155:8435094ec241 163 ===============================================================================
mbed_official 155:8435094ec241 164 [..] The MCU can be woken up from a low power mode by an RTC alternate
mbed_official 155:8435094ec241 165 function.
mbed_official 155:8435094ec241 166 [..] The RTC alternate functions are the RTC alarms (Alarm A and Alarm B),
mbed_official 155:8435094ec241 167 RTC wakeup, RTC tamper event detection and RTC time stamp event detection.
mbed_official 155:8435094ec241 168 These RTC alternate functions can wake up the system from the Stop
mbed_official 155:8435094ec241 169 and Standby lowpower modes.
mbed_official 155:8435094ec241 170 The system can also wake up from low power modes without depending
mbed_official 155:8435094ec241 171 on an external interrupt (Auto-wakeup mode), by using the RTC alarm
mbed_official 155:8435094ec241 172 or the RTC wakeup events.
mbed_official 155:8435094ec241 173 [..] The RTC provides a programmable time base for waking up from the
mbed_official 155:8435094ec241 174 Stop or Standby mode at regular intervals.
mbed_official 155:8435094ec241 175 Wakeup from STOP and Standby modes is possible only when the RTC
mbed_official 155:8435094ec241 176 clock source is LSE or LSI.
mbed_official 155:8435094ec241 177
mbed_official 155:8435094ec241 178 ##### Selection of RTC_AF alternate functions #####
mbed_official 155:8435094ec241 179 ===============================================================================
mbed_official 155:8435094ec241 180 [..] The RTC_AF pin (PC13) can be used for the following purposes:
mbed_official 155:8435094ec241 181 (+) Wakeup pin 2 (WKUP2) using the PWR_WakeUpPinCmd() function.
mbed_official 155:8435094ec241 182 (+) AFO_ALARM output
mbed_official 155:8435094ec241 183 (+) AFO_CALIB output
mbed_official 155:8435094ec241 184 (+) AFI_TAMPER
mbed_official 155:8435094ec241 185 (+) AFI_TIMESTAMP
mbed_official 155:8435094ec241 186
mbed_official 155:8435094ec241 187 +------------------------------------------------------------------------------------------+
mbed_official 155:8435094ec241 188 | Pin |RTC ALARM |RTC CALIB |RTC TAMPER |RTC TIMESTAMP |PC13MODE| PC13VALUE |
mbed_official 155:8435094ec241 189 | configuration | OUTPUT | OUTPUT | INPUT | INPUT | bit | bit |
mbed_official 155:8435094ec241 190 | and function | ENABLED | ENABLED | ENABLED | ENABLED | | |
mbed_official 155:8435094ec241 191 |-----------------|----------|----------|-----------|--------------|--------|--------------|
mbed_official 155:8435094ec241 192 | Alarm out | | | | | Don't | |
mbed_official 155:8435094ec241 193 | output OD | 1 |Don't care|Don't care | Don't care | care | 0 |
mbed_official 155:8435094ec241 194 |-----------------|----------|----------|-----------|--------------|--------|--------------|
mbed_official 155:8435094ec241 195 | Alarm out | | | | | Don't | |
mbed_official 155:8435094ec241 196 | output PP | 1 |Don't care|Don't care | Don't care | care | 1 |
mbed_official 155:8435094ec241 197 |-----------------|----------|----------|-----------|--------------|--------|--------------|
mbed_official 155:8435094ec241 198 | Calibration out | | | | | Don't | |
mbed_official 155:8435094ec241 199 | output PP | 0 | 1 |Don't care | Don't care | care | Don't care |
mbed_official 155:8435094ec241 200 |-----------------|----------|----------|-----------|--------------|--------|--------------|
mbed_official 155:8435094ec241 201 | TAMPER input | | | | | Don't | |
mbed_official 155:8435094ec241 202 | floating | 0 | 0 | 1 | 0 | care | Don't care |
mbed_official 155:8435094ec241 203 |-----------------|----------|----------|-----------|--------------|--------|--------------|
mbed_official 155:8435094ec241 204 | TIMESTAMP and | | | | | Don't | |
mbed_official 155:8435094ec241 205 | TAMPER input | 0 | 0 | 1 | 1 | care | Don't care |
mbed_official 155:8435094ec241 206 | floating | | | | | | |
mbed_official 155:8435094ec241 207 |-----------------|----------|----------|-----------|--------------|--------|--------------|
mbed_official 155:8435094ec241 208 | TIMESTAMP input | | | | | Don't | |
mbed_official 155:8435094ec241 209 | floating | 0 | 0 | 0 | 1 | care | Don't care |
mbed_official 155:8435094ec241 210 |-----------------|----------|----------|-----------|--------------|--------|--------------|
mbed_official 155:8435094ec241 211 | Output PP | 0 | 0 | 0 | 0 | 1 | PC13 output |
mbed_official 155:8435094ec241 212 | Forced | | | | | | |
mbed_official 155:8435094ec241 213 |-----------------|----------|----------|-----------|--------------|--------|--------------|
mbed_official 155:8435094ec241 214 | Wakeup Pin or | 0 | 0 | 0 | 0 | 0 | Don't care |
mbed_official 155:8435094ec241 215 | Standard GPIO | | | | | | |
mbed_official 155:8435094ec241 216 +------------------------------------------------------------------------------------------+
mbed_official 155:8435094ec241 217
mbed_official 155:8435094ec241 218 @endverbatim
mbed_official 155:8435094ec241 219
mbed_official 155:8435094ec241 220 ******************************************************************************
mbed_official 155:8435094ec241 221 * @attention
mbed_official 155:8435094ec241 222 *
mbed_official 155:8435094ec241 223 * <h2><center>&copy; COPYRIGHT(c) 2014 STMicroelectronics</center></h2>
mbed_official 155:8435094ec241 224 *
mbed_official 155:8435094ec241 225 * Redistribution and use in source and binary forms, with or without modification,
mbed_official 155:8435094ec241 226 * are permitted provided that the following conditions are met:
mbed_official 155:8435094ec241 227 * 1. Redistributions of source code must retain the above copyright notice,
mbed_official 155:8435094ec241 228 * this list of conditions and the following disclaimer.
mbed_official 155:8435094ec241 229 * 2. Redistributions in binary form must reproduce the above copyright notice,
mbed_official 155:8435094ec241 230 * this list of conditions and the following disclaimer in the documentation
mbed_official 155:8435094ec241 231 * and/or other materials provided with the distribution.
mbed_official 155:8435094ec241 232 * 3. Neither the name of STMicroelectronics nor the names of its contributors
mbed_official 155:8435094ec241 233 * may be used to endorse or promote products derived from this software
mbed_official 155:8435094ec241 234 * without specific prior written permission.
mbed_official 155:8435094ec241 235 *
mbed_official 155:8435094ec241 236 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
mbed_official 155:8435094ec241 237 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
mbed_official 155:8435094ec241 238 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
mbed_official 155:8435094ec241 239 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
mbed_official 155:8435094ec241 240 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
mbed_official 155:8435094ec241 241 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
mbed_official 155:8435094ec241 242 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
mbed_official 155:8435094ec241 243 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
mbed_official 155:8435094ec241 244 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
mbed_official 155:8435094ec241 245 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
mbed_official 155:8435094ec241 246 *
mbed_official 155:8435094ec241 247 ******************************************************************************
mbed_official 155:8435094ec241 248 */
mbed_official 155:8435094ec241 249
mbed_official 155:8435094ec241 250 /* Includes ------------------------------------------------------------------*/
mbed_official 155:8435094ec241 251 #include "stm32f30x_rtc.h"
mbed_official 155:8435094ec241 252 #include "stm32f30x_rcc.h"
mbed_official 155:8435094ec241 253
mbed_official 155:8435094ec241 254 /** @addtogroup STM32F30x_StdPeriph_Driver
mbed_official 155:8435094ec241 255 * @{
mbed_official 155:8435094ec241 256 */
mbed_official 155:8435094ec241 257
mbed_official 155:8435094ec241 258 /** @defgroup RTC
mbed_official 155:8435094ec241 259 * @brief RTC driver modules
mbed_official 155:8435094ec241 260 * @{
mbed_official 155:8435094ec241 261 */
mbed_official 155:8435094ec241 262
mbed_official 155:8435094ec241 263 /* Private typedef -----------------------------------------------------------*/
mbed_official 155:8435094ec241 264 /* Private define ------------------------------------------------------------*/
mbed_official 155:8435094ec241 265
mbed_official 155:8435094ec241 266 /* Masks Definition */
mbed_official 155:8435094ec241 267 #define RTC_TR_RESERVED_MASK ((uint32_t)0x007F7F7F)
mbed_official 155:8435094ec241 268 #define RTC_DR_RESERVED_MASK ((uint32_t)0x00FFFF3F)
mbed_official 155:8435094ec241 269 #define RTC_INIT_MASK ((uint32_t)0xFFFFFFFF)
mbed_official 155:8435094ec241 270 #define RTC_RSF_MASK ((uint32_t)0xFFFFFF5F)
mbed_official 155:8435094ec241 271 #define RTC_FLAGS_MASK ((uint32_t)(RTC_FLAG_TSOVF | RTC_FLAG_TSF | RTC_FLAG_WUTF | \
mbed_official 155:8435094ec241 272 RTC_FLAG_ALRBF | RTC_FLAG_ALRAF | RTC_FLAG_INITF | \
mbed_official 155:8435094ec241 273 RTC_FLAG_RSF | RTC_FLAG_INITS | RTC_FLAG_WUTWF | \
mbed_official 155:8435094ec241 274 RTC_FLAG_ALRBWF | RTC_FLAG_ALRAWF | RTC_FLAG_TAMP1F | \
mbed_official 155:8435094ec241 275 RTC_FLAG_TAMP2F | RTC_FLAG_TAMP3F | RTC_FLAG_RECALPF | \
mbed_official 155:8435094ec241 276 RTC_FLAG_SHPF))
mbed_official 155:8435094ec241 277
mbed_official 155:8435094ec241 278 #define INITMODE_TIMEOUT ((uint32_t) 0x00002000)
mbed_official 155:8435094ec241 279 #define SYNCHRO_TIMEOUT ((uint32_t) 0x00008000)
mbed_official 155:8435094ec241 280 #define RECALPF_TIMEOUT ((uint32_t) 0x00001000)
mbed_official 155:8435094ec241 281 #define SHPF_TIMEOUT ((uint32_t) 0x00002000)
mbed_official 155:8435094ec241 282
mbed_official 155:8435094ec241 283 /* Private macro -------------------------------------------------------------*/
mbed_official 155:8435094ec241 284 /* Private variables ---------------------------------------------------------*/
mbed_official 155:8435094ec241 285 /* Private function prototypes -----------------------------------------------*/
mbed_official 155:8435094ec241 286 static uint8_t RTC_ByteToBcd2(uint8_t Value);
mbed_official 155:8435094ec241 287 static uint8_t RTC_Bcd2ToByte(uint8_t Value);
mbed_official 155:8435094ec241 288
mbed_official 155:8435094ec241 289 /* Private functions ---------------------------------------------------------*/
mbed_official 155:8435094ec241 290
mbed_official 155:8435094ec241 291 /** @defgroup RTC_Private_Functions
mbed_official 155:8435094ec241 292 * @{
mbed_official 155:8435094ec241 293 */
mbed_official 155:8435094ec241 294
mbed_official 155:8435094ec241 295 /** @defgroup RTC_Group1 Initialization and Configuration functions
mbed_official 155:8435094ec241 296 * @brief Initialization and Configuration functions
mbed_official 155:8435094ec241 297 *
mbed_official 155:8435094ec241 298 @verbatim
mbed_official 155:8435094ec241 299 ===============================================================================
mbed_official 155:8435094ec241 300 ##### Initialization and Configuration functions #####
mbed_official 155:8435094ec241 301 ===============================================================================
mbed_official 155:8435094ec241 302 [..] This section provide functions allowing to initialize and configure the RTC
mbed_official 155:8435094ec241 303 Prescaler (Synchronous and Asynchronous), RTC Hour format, disable RTC registers
mbed_official 155:8435094ec241 304 Write protection, enter and exit the RTC initialization mode, RTC registers
mbed_official 155:8435094ec241 305 synchronization check and reference clock detection enable.
mbed_official 155:8435094ec241 306 (#) The RTC Prescaler is programmed to generate the RTC 1Hz time base. It is
mbed_official 155:8435094ec241 307 split into 2 programmable prescalers to minimize power consumption.
mbed_official 155:8435094ec241 308 (++) A 7-bit asynchronous prescaler and A 13-bit synchronous prescaler.
mbed_official 155:8435094ec241 309 (++) When both prescalers are used, it is recommended to configure the
mbed_official 155:8435094ec241 310 asynchronous prescaler to a high value to minimize consumption.
mbed_official 155:8435094ec241 311 (#) All RTC registers are Write protected. Writing to the RTC registers
mbed_official 155:8435094ec241 312 is enabled by writing a key into the Write Protection register, RTC_WPR.
mbed_official 155:8435094ec241 313 (#) To Configure the RTC Calendar, user application should enter initialization
mbed_official 155:8435094ec241 314 mode. In this mode, the calendar counter is stopped and its value
mbed_official 155:8435094ec241 315 can be updated. When the initialization sequence is complete, the
mbed_official 155:8435094ec241 316 calendar restarts counting after 4 RTCCLK cycles.
mbed_official 155:8435094ec241 317 (#) To read the calendar through the shadow registers after Calendar
mbed_official 155:8435094ec241 318 initialization, calendar update or after wakeup from low power modes
mbed_official 155:8435094ec241 319 the software must first clear the RSF flag. The software must then
mbed_official 155:8435094ec241 320 wait until it is set again before reading the calendar, which means
mbed_official 155:8435094ec241 321 that the calendar registers have been correctly copied into the RTC_TR
mbed_official 155:8435094ec241 322 and RTC_DR shadow registers. The RTC_WaitForSynchro() function
mbed_official 155:8435094ec241 323 implements the above software sequence (RSF clear and RSF check).
mbed_official 155:8435094ec241 324
mbed_official 155:8435094ec241 325 @endverbatim
mbed_official 155:8435094ec241 326 * @{
mbed_official 155:8435094ec241 327 */
mbed_official 155:8435094ec241 328
mbed_official 155:8435094ec241 329 /**
mbed_official 155:8435094ec241 330 * @brief Deinitializes the RTC registers to their default reset values.
mbed_official 155:8435094ec241 331 * @note This function doesn't reset the RTC Clock source and RTC Backup Data
mbed_official 155:8435094ec241 332 * registers.
mbed_official 155:8435094ec241 333 * @param None
mbed_official 155:8435094ec241 334 * @retval An ErrorStatus enumeration value:
mbed_official 155:8435094ec241 335 * - SUCCESS: RTC registers are deinitialized
mbed_official 155:8435094ec241 336 * - ERROR: RTC registers are not deinitialized
mbed_official 155:8435094ec241 337 */
mbed_official 155:8435094ec241 338 ErrorStatus RTC_DeInit(void)
mbed_official 155:8435094ec241 339 {
mbed_official 155:8435094ec241 340 __IO uint32_t wutcounter = 0x00;
mbed_official 155:8435094ec241 341 uint32_t wutwfstatus = 0x00;
mbed_official 155:8435094ec241 342 ErrorStatus status = ERROR;
mbed_official 155:8435094ec241 343
mbed_official 155:8435094ec241 344 /* Disable the write protection for RTC registers */
mbed_official 155:8435094ec241 345 RTC->WPR = 0xCA;
mbed_official 155:8435094ec241 346 RTC->WPR = 0x53;
mbed_official 155:8435094ec241 347
mbed_official 155:8435094ec241 348 /* Set Initialization mode */
mbed_official 155:8435094ec241 349 if (RTC_EnterInitMode() == ERROR)
mbed_official 155:8435094ec241 350 {
mbed_official 155:8435094ec241 351 status = ERROR;
mbed_official 155:8435094ec241 352 }
mbed_official 155:8435094ec241 353 else
mbed_official 155:8435094ec241 354 {
mbed_official 155:8435094ec241 355 /* Reset TR, DR and CR registers */
mbed_official 155:8435094ec241 356 RTC->TR = (uint32_t)0x00000000;
mbed_official 155:8435094ec241 357 RTC->DR = (uint32_t)0x00002101;
mbed_official 155:8435094ec241 358
mbed_official 155:8435094ec241 359 /* Reset All CR bits except CR[2:0] */
mbed_official 155:8435094ec241 360 RTC->CR &= (uint32_t)0x00000007;
mbed_official 155:8435094ec241 361
mbed_official 155:8435094ec241 362 /* Wait till RTC WUTWF flag is set and if Time out is reached exit */
mbed_official 155:8435094ec241 363 do
mbed_official 155:8435094ec241 364 {
mbed_official 155:8435094ec241 365 wutwfstatus = RTC->ISR & RTC_ISR_WUTWF;
mbed_official 155:8435094ec241 366 wutcounter++;
mbed_official 155:8435094ec241 367 } while((wutcounter != INITMODE_TIMEOUT) && (wutwfstatus == 0x00));
mbed_official 155:8435094ec241 368
mbed_official 155:8435094ec241 369 if ((RTC->ISR & RTC_ISR_WUTWF) == RESET)
mbed_official 155:8435094ec241 370 {
mbed_official 155:8435094ec241 371 status = ERROR;
mbed_official 155:8435094ec241 372 }
mbed_official 155:8435094ec241 373 else
mbed_official 155:8435094ec241 374 {
mbed_official 155:8435094ec241 375 /* Reset all RTC CR register bits */
mbed_official 155:8435094ec241 376 RTC->CR &= (uint32_t)0x00000000;
mbed_official 155:8435094ec241 377 RTC->WUTR = (uint32_t)0x0000FFFF;
mbed_official 155:8435094ec241 378 RTC->PRER = (uint32_t)0x007F00FF;
mbed_official 155:8435094ec241 379 RTC->ALRMAR = (uint32_t)0x00000000;
mbed_official 155:8435094ec241 380 RTC->ALRMBR = (uint32_t)0x00000000;
mbed_official 155:8435094ec241 381 RTC->SHIFTR = (uint32_t)0x00000000;
mbed_official 155:8435094ec241 382 RTC->CALR = (uint32_t)0x00000000;
mbed_official 155:8435094ec241 383 RTC->ALRMASSR = (uint32_t)0x00000000;
mbed_official 155:8435094ec241 384 RTC->ALRMBSSR = (uint32_t)0x00000000;
mbed_official 155:8435094ec241 385
mbed_official 155:8435094ec241 386 /* Reset ISR register and exit initialization mode */
mbed_official 155:8435094ec241 387 RTC->ISR = (uint32_t)0x00000000;
mbed_official 155:8435094ec241 388
mbed_official 155:8435094ec241 389 /* Reset Tamper and alternate functions configuration register */
mbed_official 155:8435094ec241 390 RTC->TAFCR = 0x00000000;
mbed_official 155:8435094ec241 391
mbed_official 155:8435094ec241 392 /* Wait till the RTC RSF flag is set */
mbed_official 155:8435094ec241 393 if (RTC_WaitForSynchro() == ERROR)
mbed_official 155:8435094ec241 394 {
mbed_official 155:8435094ec241 395 status = ERROR;
mbed_official 155:8435094ec241 396 }
mbed_official 155:8435094ec241 397 else
mbed_official 155:8435094ec241 398 {
mbed_official 155:8435094ec241 399 status = SUCCESS;
mbed_official 155:8435094ec241 400 }
mbed_official 155:8435094ec241 401 }
mbed_official 155:8435094ec241 402 }
mbed_official 155:8435094ec241 403
mbed_official 155:8435094ec241 404 /* Enable the write protection for RTC registers */
mbed_official 155:8435094ec241 405 RTC->WPR = 0xFF;
mbed_official 155:8435094ec241 406
mbed_official 155:8435094ec241 407 return status;
mbed_official 155:8435094ec241 408 }
mbed_official 155:8435094ec241 409
mbed_official 155:8435094ec241 410 /**
mbed_official 155:8435094ec241 411 * @brief Initializes the RTC registers according to the specified parameters
mbed_official 155:8435094ec241 412 * in RTC_InitStruct.
mbed_official 155:8435094ec241 413 * @param RTC_InitStruct: pointer to a RTC_InitTypeDef structure that contains
mbed_official 155:8435094ec241 414 * the configuration information for the RTC peripheral.
mbed_official 155:8435094ec241 415 * @note The RTC Prescaler register is write protected and can be written in
mbed_official 155:8435094ec241 416 * initialization mode only.
mbed_official 155:8435094ec241 417 * @retval An ErrorStatus enumeration value:
mbed_official 155:8435094ec241 418 * - SUCCESS: RTC registers are initialized
mbed_official 155:8435094ec241 419 * - ERROR: RTC registers are not initialized
mbed_official 155:8435094ec241 420 */
mbed_official 155:8435094ec241 421 ErrorStatus RTC_Init(RTC_InitTypeDef* RTC_InitStruct)
mbed_official 155:8435094ec241 422 {
mbed_official 155:8435094ec241 423 ErrorStatus status = ERROR;
mbed_official 155:8435094ec241 424
mbed_official 155:8435094ec241 425 /* Check the parameters */
mbed_official 155:8435094ec241 426 assert_param(IS_RTC_HOUR_FORMAT(RTC_InitStruct->RTC_HourFormat));
mbed_official 155:8435094ec241 427 assert_param(IS_RTC_ASYNCH_PREDIV(RTC_InitStruct->RTC_AsynchPrediv));
mbed_official 155:8435094ec241 428 assert_param(IS_RTC_SYNCH_PREDIV(RTC_InitStruct->RTC_SynchPrediv));
mbed_official 155:8435094ec241 429
mbed_official 155:8435094ec241 430 /* Disable the write protection for RTC registers */
mbed_official 155:8435094ec241 431 RTC->WPR = 0xCA;
mbed_official 155:8435094ec241 432 RTC->WPR = 0x53;
mbed_official 155:8435094ec241 433
mbed_official 155:8435094ec241 434 /* Set Initialization mode */
mbed_official 155:8435094ec241 435 if (RTC_EnterInitMode() == ERROR)
mbed_official 155:8435094ec241 436 {
mbed_official 155:8435094ec241 437 status = ERROR;
mbed_official 155:8435094ec241 438 }
mbed_official 155:8435094ec241 439 else
mbed_official 155:8435094ec241 440 {
mbed_official 155:8435094ec241 441 /* Clear RTC CR FMT Bit */
mbed_official 155:8435094ec241 442 RTC->CR &= ((uint32_t)~(RTC_CR_FMT));
mbed_official 155:8435094ec241 443 /* Set RTC_CR register */
mbed_official 155:8435094ec241 444 RTC->CR |= ((uint32_t)(RTC_InitStruct->RTC_HourFormat));
mbed_official 155:8435094ec241 445
mbed_official 155:8435094ec241 446 /* Configure the RTC PRER */
mbed_official 155:8435094ec241 447 RTC->PRER = (uint32_t)(RTC_InitStruct->RTC_SynchPrediv);
mbed_official 155:8435094ec241 448 RTC->PRER |= (uint32_t)(RTC_InitStruct->RTC_AsynchPrediv << 16);
mbed_official 155:8435094ec241 449
mbed_official 155:8435094ec241 450 /* Exit Initialization mode */
mbed_official 155:8435094ec241 451 RTC_ExitInitMode();
mbed_official 155:8435094ec241 452
mbed_official 155:8435094ec241 453 status = SUCCESS;
mbed_official 155:8435094ec241 454 }
mbed_official 155:8435094ec241 455 /* Enable the write protection for RTC registers */
mbed_official 155:8435094ec241 456 RTC->WPR = 0xFF;
mbed_official 155:8435094ec241 457
mbed_official 155:8435094ec241 458 return status;
mbed_official 155:8435094ec241 459 }
mbed_official 155:8435094ec241 460
mbed_official 155:8435094ec241 461 /**
mbed_official 155:8435094ec241 462 * @brief Fills each RTC_InitStruct member with its default value.
mbed_official 155:8435094ec241 463 * @param RTC_InitStruct: pointer to a RTC_InitTypeDef structure which will be
mbed_official 155:8435094ec241 464 * initialized.
mbed_official 155:8435094ec241 465 * @retval None
mbed_official 155:8435094ec241 466 */
mbed_official 155:8435094ec241 467 void RTC_StructInit(RTC_InitTypeDef* RTC_InitStruct)
mbed_official 155:8435094ec241 468 {
mbed_official 155:8435094ec241 469 /* Initialize the RTC_HourFormat member */
mbed_official 155:8435094ec241 470 RTC_InitStruct->RTC_HourFormat = RTC_HourFormat_24;
mbed_official 155:8435094ec241 471
mbed_official 155:8435094ec241 472 /* Initialize the RTC_AsynchPrediv member */
mbed_official 155:8435094ec241 473 RTC_InitStruct->RTC_AsynchPrediv = (uint32_t)0x7F;
mbed_official 155:8435094ec241 474
mbed_official 155:8435094ec241 475 /* Initialize the RTC_SynchPrediv member */
mbed_official 155:8435094ec241 476 RTC_InitStruct->RTC_SynchPrediv = (uint32_t)0xFF;
mbed_official 155:8435094ec241 477 }
mbed_official 155:8435094ec241 478
mbed_official 155:8435094ec241 479 /**
mbed_official 155:8435094ec241 480 * @brief Enables or disables the RTC registers write protection.
mbed_official 155:8435094ec241 481 * @note All the RTC registers are write protected except for RTC_ISR[13:8],
mbed_official 155:8435094ec241 482 * RTC_TAFCR and RTC_BKPxR.
mbed_official 155:8435094ec241 483 * @note Writing a wrong key reactivates the write protection.
mbed_official 155:8435094ec241 484 * @note The protection mechanism is not affected by system reset.
mbed_official 155:8435094ec241 485 * @param NewState: new state of the write protection.
mbed_official 155:8435094ec241 486 * This parameter can be: ENABLE or DISABLE.
mbed_official 155:8435094ec241 487 * @retval None
mbed_official 155:8435094ec241 488 */
mbed_official 155:8435094ec241 489 void RTC_WriteProtectionCmd(FunctionalState NewState)
mbed_official 155:8435094ec241 490 {
mbed_official 155:8435094ec241 491 /* Check the parameters */
mbed_official 155:8435094ec241 492 assert_param(IS_FUNCTIONAL_STATE(NewState));
mbed_official 155:8435094ec241 493
mbed_official 155:8435094ec241 494 if (NewState != DISABLE)
mbed_official 155:8435094ec241 495 {
mbed_official 155:8435094ec241 496 /* Enable the write protection for RTC registers */
mbed_official 155:8435094ec241 497 RTC->WPR = 0xFF;
mbed_official 155:8435094ec241 498 }
mbed_official 155:8435094ec241 499 else
mbed_official 155:8435094ec241 500 {
mbed_official 155:8435094ec241 501 /* Disable the write protection for RTC registers */
mbed_official 155:8435094ec241 502 RTC->WPR = 0xCA;
mbed_official 155:8435094ec241 503 RTC->WPR = 0x53;
mbed_official 155:8435094ec241 504 }
mbed_official 155:8435094ec241 505 }
mbed_official 155:8435094ec241 506
mbed_official 155:8435094ec241 507 /**
mbed_official 155:8435094ec241 508 * @brief Enters the RTC Initialization mode.
mbed_official 155:8435094ec241 509 * @note The RTC Initialization mode is write protected, use the
mbed_official 155:8435094ec241 510 * RTC_WriteProtectionCmd(DISABLE) before calling this function.
mbed_official 155:8435094ec241 511 * @param None
mbed_official 155:8435094ec241 512 * @retval An ErrorStatus enumeration value:
mbed_official 155:8435094ec241 513 * - SUCCESS: RTC is in Init mode
mbed_official 155:8435094ec241 514 * - ERROR: RTC is not in Init mode
mbed_official 155:8435094ec241 515 */
mbed_official 155:8435094ec241 516 ErrorStatus RTC_EnterInitMode(void)
mbed_official 155:8435094ec241 517 {
mbed_official 155:8435094ec241 518 __IO uint32_t initcounter = 0x00;
mbed_official 155:8435094ec241 519 ErrorStatus status = ERROR;
mbed_official 155:8435094ec241 520 uint32_t initstatus = 0x00;
mbed_official 155:8435094ec241 521
mbed_official 155:8435094ec241 522 /* Check if the Initialization mode is set */
mbed_official 155:8435094ec241 523 if ((RTC->ISR & RTC_ISR_INITF) == (uint32_t)RESET)
mbed_official 155:8435094ec241 524 {
mbed_official 155:8435094ec241 525 /* Set the Initialization mode */
mbed_official 155:8435094ec241 526 RTC->ISR = (uint32_t)RTC_INIT_MASK;
mbed_official 155:8435094ec241 527
mbed_official 155:8435094ec241 528 /* Wait till RTC is in INIT state and if Time out is reached exit */
mbed_official 155:8435094ec241 529 do
mbed_official 155:8435094ec241 530 {
mbed_official 155:8435094ec241 531 initstatus = RTC->ISR & RTC_ISR_INITF;
mbed_official 155:8435094ec241 532 initcounter++;
mbed_official 155:8435094ec241 533 } while((initcounter != INITMODE_TIMEOUT) && (initstatus == 0x00));
mbed_official 155:8435094ec241 534
mbed_official 155:8435094ec241 535 if ((RTC->ISR & RTC_ISR_INITF) != RESET)
mbed_official 155:8435094ec241 536 {
mbed_official 155:8435094ec241 537 status = SUCCESS;
mbed_official 155:8435094ec241 538 }
mbed_official 155:8435094ec241 539 else
mbed_official 155:8435094ec241 540 {
mbed_official 155:8435094ec241 541 status = ERROR;
mbed_official 155:8435094ec241 542 }
mbed_official 155:8435094ec241 543 }
mbed_official 155:8435094ec241 544 else
mbed_official 155:8435094ec241 545 {
mbed_official 155:8435094ec241 546 status = SUCCESS;
mbed_official 155:8435094ec241 547 }
mbed_official 155:8435094ec241 548
mbed_official 155:8435094ec241 549 return (status);
mbed_official 155:8435094ec241 550 }
mbed_official 155:8435094ec241 551
mbed_official 155:8435094ec241 552 /**
mbed_official 155:8435094ec241 553 * @brief Exits the RTC Initialization mode.
mbed_official 155:8435094ec241 554 * @note When the initialization sequence is complete, the calendar restarts
mbed_official 155:8435094ec241 555 * counting after 4 RTCCLK cycles.
mbed_official 155:8435094ec241 556 * @note The RTC Initialization mode is write protected, use the
mbed_official 155:8435094ec241 557 * RTC_WriteProtectionCmd(DISABLE) before calling this function.
mbed_official 155:8435094ec241 558 * @param None
mbed_official 155:8435094ec241 559 * @retval None
mbed_official 155:8435094ec241 560 */
mbed_official 155:8435094ec241 561 void RTC_ExitInitMode(void)
mbed_official 155:8435094ec241 562 {
mbed_official 155:8435094ec241 563 /* Exit Initialization mode */
mbed_official 155:8435094ec241 564 RTC->ISR &= (uint32_t)~RTC_ISR_INIT;
mbed_official 155:8435094ec241 565 }
mbed_official 155:8435094ec241 566
mbed_official 155:8435094ec241 567 /**
mbed_official 155:8435094ec241 568 * @brief Waits until the RTC Time and Date registers (RTC_TR and RTC_DR) are
mbed_official 155:8435094ec241 569 * synchronized with RTC APB clock.
mbed_official 155:8435094ec241 570 * @note The RTC Resynchronization mode is write protected, use the
mbed_official 155:8435094ec241 571 * RTC_WriteProtectionCmd(DISABLE) before calling this function.
mbed_official 155:8435094ec241 572 * @note To read the calendar through the shadow registers after Calendar
mbed_official 155:8435094ec241 573 * initialization, calendar update or after wakeup from low power modes
mbed_official 155:8435094ec241 574 * the software must first clear the RSF flag.
mbed_official 155:8435094ec241 575 * The software must then wait until it is set again before reading
mbed_official 155:8435094ec241 576 * the calendar, which means that the calendar registers have been
mbed_official 155:8435094ec241 577 * correctly copied into the RTC_TR and RTC_DR shadow registers.
mbed_official 155:8435094ec241 578 * @param None
mbed_official 155:8435094ec241 579 * @retval An ErrorStatus enumeration value:
mbed_official 155:8435094ec241 580 * - SUCCESS: RTC registers are synchronised
mbed_official 155:8435094ec241 581 * - ERROR: RTC registers are not synchronised
mbed_official 155:8435094ec241 582 */
mbed_official 155:8435094ec241 583 ErrorStatus RTC_WaitForSynchro(void)
mbed_official 155:8435094ec241 584 {
mbed_official 155:8435094ec241 585 __IO uint32_t synchrocounter = 0;
mbed_official 155:8435094ec241 586 ErrorStatus status = ERROR;
mbed_official 155:8435094ec241 587 uint32_t synchrostatus = 0x00;
mbed_official 155:8435094ec241 588
mbed_official 155:8435094ec241 589 if ((RTC->CR & RTC_CR_BYPSHAD) != RESET)
mbed_official 155:8435094ec241 590 {
mbed_official 155:8435094ec241 591 /* Bypass shadow mode */
mbed_official 155:8435094ec241 592 status = SUCCESS;
mbed_official 155:8435094ec241 593 }
mbed_official 155:8435094ec241 594 else
mbed_official 155:8435094ec241 595 {
mbed_official 155:8435094ec241 596 /* Disable the write protection for RTC registers */
mbed_official 155:8435094ec241 597 RTC->WPR = 0xCA;
mbed_official 155:8435094ec241 598 RTC->WPR = 0x53;
mbed_official 155:8435094ec241 599
mbed_official 155:8435094ec241 600 /* Clear RSF flag */
mbed_official 155:8435094ec241 601 RTC->ISR &= (uint32_t)RTC_RSF_MASK;
mbed_official 155:8435094ec241 602
mbed_official 155:8435094ec241 603 /* Wait the registers to be synchronised */
mbed_official 155:8435094ec241 604 do
mbed_official 155:8435094ec241 605 {
mbed_official 155:8435094ec241 606 synchrostatus = RTC->ISR & RTC_ISR_RSF;
mbed_official 155:8435094ec241 607 synchrocounter++;
mbed_official 155:8435094ec241 608 } while((synchrocounter != SYNCHRO_TIMEOUT) && (synchrostatus == 0x00));
mbed_official 155:8435094ec241 609
mbed_official 155:8435094ec241 610 if ((RTC->ISR & RTC_ISR_RSF) != RESET)
mbed_official 155:8435094ec241 611 {
mbed_official 155:8435094ec241 612 status = SUCCESS;
mbed_official 155:8435094ec241 613 }
mbed_official 155:8435094ec241 614 else
mbed_official 155:8435094ec241 615 {
mbed_official 155:8435094ec241 616 status = ERROR;
mbed_official 155:8435094ec241 617 }
mbed_official 155:8435094ec241 618
mbed_official 155:8435094ec241 619 /* Enable the write protection for RTC registers */
mbed_official 155:8435094ec241 620 RTC->WPR = 0xFF;
mbed_official 155:8435094ec241 621 }
mbed_official 155:8435094ec241 622
mbed_official 155:8435094ec241 623 return (status);
mbed_official 155:8435094ec241 624 }
mbed_official 155:8435094ec241 625
mbed_official 155:8435094ec241 626 /**
mbed_official 155:8435094ec241 627 * @brief Enables or disables the RTC reference clock detection.
mbed_official 155:8435094ec241 628 * @param NewState: new state of the RTC reference clock.
mbed_official 155:8435094ec241 629 * This parameter can be: ENABLE or DISABLE.
mbed_official 155:8435094ec241 630 * @retval An ErrorStatus enumeration value:
mbed_official 155:8435094ec241 631 * - SUCCESS: RTC reference clock detection is enabled
mbed_official 155:8435094ec241 632 * - ERROR: RTC reference clock detection is disabled
mbed_official 155:8435094ec241 633 */
mbed_official 155:8435094ec241 634 ErrorStatus RTC_RefClockCmd(FunctionalState NewState)
mbed_official 155:8435094ec241 635 {
mbed_official 155:8435094ec241 636 ErrorStatus status = ERROR;
mbed_official 155:8435094ec241 637
mbed_official 155:8435094ec241 638 /* Check the parameters */
mbed_official 155:8435094ec241 639 assert_param(IS_FUNCTIONAL_STATE(NewState));
mbed_official 155:8435094ec241 640
mbed_official 155:8435094ec241 641 /* Disable the write protection for RTC registers */
mbed_official 155:8435094ec241 642 RTC->WPR = 0xCA;
mbed_official 155:8435094ec241 643 RTC->WPR = 0x53;
mbed_official 155:8435094ec241 644
mbed_official 155:8435094ec241 645 /* Set Initialization mode */
mbed_official 155:8435094ec241 646 if (RTC_EnterInitMode() == ERROR)
mbed_official 155:8435094ec241 647 {
mbed_official 155:8435094ec241 648 status = ERROR;
mbed_official 155:8435094ec241 649 }
mbed_official 155:8435094ec241 650 else
mbed_official 155:8435094ec241 651 {
mbed_official 155:8435094ec241 652 if (NewState != DISABLE)
mbed_official 155:8435094ec241 653 {
mbed_official 155:8435094ec241 654 /* Enable the RTC reference clock detection */
mbed_official 155:8435094ec241 655 RTC->CR |= RTC_CR_REFCKON;
mbed_official 155:8435094ec241 656 }
mbed_official 155:8435094ec241 657 else
mbed_official 155:8435094ec241 658 {
mbed_official 155:8435094ec241 659 /* Disable the RTC reference clock detection */
mbed_official 155:8435094ec241 660 RTC->CR &= ~RTC_CR_REFCKON;
mbed_official 155:8435094ec241 661 }
mbed_official 155:8435094ec241 662 /* Exit Initialization mode */
mbed_official 155:8435094ec241 663 RTC_ExitInitMode();
mbed_official 155:8435094ec241 664
mbed_official 155:8435094ec241 665 status = SUCCESS;
mbed_official 155:8435094ec241 666 }
mbed_official 155:8435094ec241 667
mbed_official 155:8435094ec241 668 /* Enable the write protection for RTC registers */
mbed_official 155:8435094ec241 669 RTC->WPR = 0xFF;
mbed_official 155:8435094ec241 670
mbed_official 155:8435094ec241 671 return status;
mbed_official 155:8435094ec241 672 }
mbed_official 155:8435094ec241 673
mbed_official 155:8435094ec241 674 /**
mbed_official 155:8435094ec241 675 * @brief Enables or Disables the Bypass Shadow feature.
mbed_official 155:8435094ec241 676 * @note When the Bypass Shadow is enabled the calendar value are taken
mbed_official 155:8435094ec241 677 * directly from the Calendar counter.
mbed_official 155:8435094ec241 678 * @param NewState: new state of the Bypass Shadow feature.
mbed_official 155:8435094ec241 679 * This parameter can be: ENABLE or DISABLE.
mbed_official 155:8435094ec241 680 * @retval None
mbed_official 155:8435094ec241 681 */
mbed_official 155:8435094ec241 682 void RTC_BypassShadowCmd(FunctionalState NewState)
mbed_official 155:8435094ec241 683 {
mbed_official 155:8435094ec241 684 /* Check the parameters */
mbed_official 155:8435094ec241 685 assert_param(IS_FUNCTIONAL_STATE(NewState));
mbed_official 155:8435094ec241 686
mbed_official 155:8435094ec241 687 /* Disable the write protection for RTC registers */
mbed_official 155:8435094ec241 688 RTC->WPR = 0xCA;
mbed_official 155:8435094ec241 689 RTC->WPR = 0x53;
mbed_official 155:8435094ec241 690
mbed_official 155:8435094ec241 691 if (NewState != DISABLE)
mbed_official 155:8435094ec241 692 {
mbed_official 155:8435094ec241 693 /* Set the BYPSHAD bit */
mbed_official 155:8435094ec241 694 RTC->CR |= (uint8_t)RTC_CR_BYPSHAD;
mbed_official 155:8435094ec241 695 }
mbed_official 155:8435094ec241 696 else
mbed_official 155:8435094ec241 697 {
mbed_official 155:8435094ec241 698 /* Reset the BYPSHAD bit */
mbed_official 155:8435094ec241 699 RTC->CR &= (uint8_t)~RTC_CR_BYPSHAD;
mbed_official 155:8435094ec241 700 }
mbed_official 155:8435094ec241 701
mbed_official 155:8435094ec241 702 /* Enable the write protection for RTC registers */
mbed_official 155:8435094ec241 703 RTC->WPR = 0xFF;
mbed_official 155:8435094ec241 704 }
mbed_official 155:8435094ec241 705
mbed_official 155:8435094ec241 706 /**
mbed_official 155:8435094ec241 707 * @}
mbed_official 155:8435094ec241 708 */
mbed_official 155:8435094ec241 709
mbed_official 155:8435094ec241 710 /** @defgroup RTC_Group2 Time and Date configuration functions
mbed_official 155:8435094ec241 711 * @brief Time and Date configuration functions
mbed_official 155:8435094ec241 712 *
mbed_official 155:8435094ec241 713 @verbatim
mbed_official 155:8435094ec241 714 ===============================================================================
mbed_official 155:8435094ec241 715 ##### Time and Date configuration functions #####
mbed_official 155:8435094ec241 716 ===============================================================================
mbed_official 155:8435094ec241 717 [..] This section provide functions allowing to program and read the RTC Calendar
mbed_official 155:8435094ec241 718 (Time and Date).
mbed_official 155:8435094ec241 719
mbed_official 155:8435094ec241 720 @endverbatim
mbed_official 155:8435094ec241 721 * @{
mbed_official 155:8435094ec241 722 */
mbed_official 155:8435094ec241 723
mbed_official 155:8435094ec241 724 /**
mbed_official 155:8435094ec241 725 * @brief Set the RTC current time.
mbed_official 155:8435094ec241 726 * @param RTC_Format: specifies the format of the entered parameters.
mbed_official 155:8435094ec241 727 * This parameter can be one of the following values:
mbed_official 155:8435094ec241 728 * @arg RTC_Format_BIN: Binary data format
mbed_official 155:8435094ec241 729 * @arg RTC_Format_BCD: BCD data format
mbed_official 155:8435094ec241 730 * @param RTC_TimeStruct: pointer to a RTC_TimeTypeDef structure that contains
mbed_official 155:8435094ec241 731 * the time configuration information for the RTC.
mbed_official 155:8435094ec241 732 * @retval An ErrorStatus enumeration value:
mbed_official 155:8435094ec241 733 * - SUCCESS: RTC Time register is configured
mbed_official 155:8435094ec241 734 * - ERROR: RTC Time register is not configured
mbed_official 155:8435094ec241 735 */
mbed_official 155:8435094ec241 736 ErrorStatus RTC_SetTime(uint32_t RTC_Format, RTC_TimeTypeDef* RTC_TimeStruct)
mbed_official 155:8435094ec241 737 {
mbed_official 155:8435094ec241 738 uint32_t tmpreg = 0;
mbed_official 155:8435094ec241 739 ErrorStatus status = ERROR;
mbed_official 155:8435094ec241 740
mbed_official 155:8435094ec241 741 /* Check the parameters */
mbed_official 155:8435094ec241 742 assert_param(IS_RTC_FORMAT(RTC_Format));
mbed_official 155:8435094ec241 743
mbed_official 155:8435094ec241 744 if (RTC_Format == RTC_Format_BIN)
mbed_official 155:8435094ec241 745 {
mbed_official 155:8435094ec241 746 if ((RTC->CR & RTC_CR_FMT) != (uint32_t)RESET)
mbed_official 155:8435094ec241 747 {
mbed_official 155:8435094ec241 748 assert_param(IS_RTC_HOUR12(RTC_TimeStruct->RTC_Hours));
mbed_official 155:8435094ec241 749 assert_param(IS_RTC_H12(RTC_TimeStruct->RTC_H12));
mbed_official 155:8435094ec241 750 }
mbed_official 155:8435094ec241 751 else
mbed_official 155:8435094ec241 752 {
mbed_official 155:8435094ec241 753 RTC_TimeStruct->RTC_H12 = 0x00;
mbed_official 155:8435094ec241 754 assert_param(IS_RTC_HOUR24(RTC_TimeStruct->RTC_Hours));
mbed_official 155:8435094ec241 755 }
mbed_official 155:8435094ec241 756 assert_param(IS_RTC_MINUTES(RTC_TimeStruct->RTC_Minutes));
mbed_official 155:8435094ec241 757 assert_param(IS_RTC_SECONDS(RTC_TimeStruct->RTC_Seconds));
mbed_official 155:8435094ec241 758 }
mbed_official 155:8435094ec241 759 else
mbed_official 155:8435094ec241 760 {
mbed_official 155:8435094ec241 761 if ((RTC->CR & RTC_CR_FMT) != (uint32_t)RESET)
mbed_official 155:8435094ec241 762 {
mbed_official 155:8435094ec241 763 tmpreg = RTC_Bcd2ToByte(RTC_TimeStruct->RTC_Hours);
mbed_official 155:8435094ec241 764 assert_param(IS_RTC_HOUR12(tmpreg));
mbed_official 155:8435094ec241 765 assert_param(IS_RTC_H12(RTC_TimeStruct->RTC_H12));
mbed_official 155:8435094ec241 766 }
mbed_official 155:8435094ec241 767 else
mbed_official 155:8435094ec241 768 {
mbed_official 155:8435094ec241 769 RTC_TimeStruct->RTC_H12 = 0x00;
mbed_official 155:8435094ec241 770 assert_param(IS_RTC_HOUR24(RTC_Bcd2ToByte(RTC_TimeStruct->RTC_Hours)));
mbed_official 155:8435094ec241 771 }
mbed_official 155:8435094ec241 772 assert_param(IS_RTC_MINUTES(RTC_Bcd2ToByte(RTC_TimeStruct->RTC_Minutes)));
mbed_official 155:8435094ec241 773 assert_param(IS_RTC_SECONDS(RTC_Bcd2ToByte(RTC_TimeStruct->RTC_Seconds)));
mbed_official 155:8435094ec241 774 }
mbed_official 155:8435094ec241 775
mbed_official 155:8435094ec241 776 /* Check the input parameters format */
mbed_official 155:8435094ec241 777 if (RTC_Format != RTC_Format_BIN)
mbed_official 155:8435094ec241 778 {
mbed_official 155:8435094ec241 779 tmpreg = (((uint32_t)(RTC_TimeStruct->RTC_Hours) << 16) | \
mbed_official 155:8435094ec241 780 ((uint32_t)(RTC_TimeStruct->RTC_Minutes) << 8) | \
mbed_official 155:8435094ec241 781 ((uint32_t)RTC_TimeStruct->RTC_Seconds) | \
mbed_official 155:8435094ec241 782 ((uint32_t)(RTC_TimeStruct->RTC_H12) << 16));
mbed_official 155:8435094ec241 783 }
mbed_official 155:8435094ec241 784 else
mbed_official 155:8435094ec241 785 {
mbed_official 155:8435094ec241 786 tmpreg = (uint32_t)(((uint32_t)RTC_ByteToBcd2(RTC_TimeStruct->RTC_Hours) << 16) | \
mbed_official 155:8435094ec241 787 ((uint32_t)RTC_ByteToBcd2(RTC_TimeStruct->RTC_Minutes) << 8) | \
mbed_official 155:8435094ec241 788 ((uint32_t)RTC_ByteToBcd2(RTC_TimeStruct->RTC_Seconds)) | \
mbed_official 155:8435094ec241 789 (((uint32_t)RTC_TimeStruct->RTC_H12) << 16));
mbed_official 155:8435094ec241 790 }
mbed_official 155:8435094ec241 791
mbed_official 155:8435094ec241 792 /* Disable the write protection for RTC registers */
mbed_official 155:8435094ec241 793 RTC->WPR = 0xCA;
mbed_official 155:8435094ec241 794 RTC->WPR = 0x53;
mbed_official 155:8435094ec241 795
mbed_official 155:8435094ec241 796 /* Set Initialization mode */
mbed_official 155:8435094ec241 797 if (RTC_EnterInitMode() == ERROR)
mbed_official 155:8435094ec241 798 {
mbed_official 155:8435094ec241 799 status = ERROR;
mbed_official 155:8435094ec241 800 }
mbed_official 155:8435094ec241 801 else
mbed_official 155:8435094ec241 802 {
mbed_official 155:8435094ec241 803 /* Set the RTC_TR register */
mbed_official 155:8435094ec241 804 RTC->TR = (uint32_t)(tmpreg & RTC_TR_RESERVED_MASK);
mbed_official 155:8435094ec241 805
mbed_official 155:8435094ec241 806 /* Exit Initialization mode */
mbed_official 155:8435094ec241 807 RTC_ExitInitMode();
mbed_official 155:8435094ec241 808
mbed_official 155:8435094ec241 809 /* If RTC_CR_BYPSHAD bit = 0, wait for synchro else this check is not needed */
mbed_official 155:8435094ec241 810 if ((RTC->CR & RTC_CR_BYPSHAD) == RESET)
mbed_official 155:8435094ec241 811 {
mbed_official 155:8435094ec241 812 if (RTC_WaitForSynchro() == ERROR)
mbed_official 155:8435094ec241 813 {
mbed_official 155:8435094ec241 814 status = ERROR;
mbed_official 155:8435094ec241 815 }
mbed_official 155:8435094ec241 816 else
mbed_official 155:8435094ec241 817 {
mbed_official 155:8435094ec241 818 status = SUCCESS;
mbed_official 155:8435094ec241 819 }
mbed_official 155:8435094ec241 820 }
mbed_official 155:8435094ec241 821 else
mbed_official 155:8435094ec241 822 {
mbed_official 155:8435094ec241 823 status = SUCCESS;
mbed_official 155:8435094ec241 824 }
mbed_official 155:8435094ec241 825
mbed_official 155:8435094ec241 826 }
mbed_official 155:8435094ec241 827 /* Enable the write protection for RTC registers */
mbed_official 155:8435094ec241 828 RTC->WPR = 0xFF;
mbed_official 155:8435094ec241 829
mbed_official 155:8435094ec241 830 return status;
mbed_official 155:8435094ec241 831 }
mbed_official 155:8435094ec241 832
mbed_official 155:8435094ec241 833 /**
mbed_official 155:8435094ec241 834 * @brief Fills each RTC_TimeStruct member with its default value
mbed_official 155:8435094ec241 835 * (Time = 00h:00min:00sec).
mbed_official 155:8435094ec241 836 * @param RTC_TimeStruct: pointer to a RTC_TimeTypeDef structure which will be
mbed_official 155:8435094ec241 837 * initialized.
mbed_official 155:8435094ec241 838 * @retval None
mbed_official 155:8435094ec241 839 */
mbed_official 155:8435094ec241 840 void RTC_TimeStructInit(RTC_TimeTypeDef* RTC_TimeStruct)
mbed_official 155:8435094ec241 841 {
mbed_official 155:8435094ec241 842 /* Time = 00h:00min:00sec */
mbed_official 155:8435094ec241 843 RTC_TimeStruct->RTC_H12 = RTC_H12_AM;
mbed_official 155:8435094ec241 844 RTC_TimeStruct->RTC_Hours = 0;
mbed_official 155:8435094ec241 845 RTC_TimeStruct->RTC_Minutes = 0;
mbed_official 155:8435094ec241 846 RTC_TimeStruct->RTC_Seconds = 0;
mbed_official 155:8435094ec241 847 }
mbed_official 155:8435094ec241 848
mbed_official 155:8435094ec241 849 /**
mbed_official 155:8435094ec241 850 * @brief Get the RTC current Time.
mbed_official 155:8435094ec241 851 * @param RTC_Format: specifies the format of the returned parameters.
mbed_official 155:8435094ec241 852 * This parameter can be one of the following values:
mbed_official 155:8435094ec241 853 * @arg RTC_Format_BIN: Binary data format
mbed_official 155:8435094ec241 854 * @arg RTC_Format_BCD: BCD data format
mbed_official 155:8435094ec241 855 * @param RTC_TimeStruct: pointer to a RTC_TimeTypeDef structure that will
mbed_official 155:8435094ec241 856 * contain the returned current time configuration.
mbed_official 155:8435094ec241 857 * @retval None
mbed_official 155:8435094ec241 858 */
mbed_official 155:8435094ec241 859 void RTC_GetTime(uint32_t RTC_Format, RTC_TimeTypeDef* RTC_TimeStruct)
mbed_official 155:8435094ec241 860 {
mbed_official 155:8435094ec241 861 uint32_t tmpreg = 0;
mbed_official 155:8435094ec241 862
mbed_official 155:8435094ec241 863 /* Check the parameters */
mbed_official 155:8435094ec241 864 assert_param(IS_RTC_FORMAT(RTC_Format));
mbed_official 155:8435094ec241 865
mbed_official 155:8435094ec241 866 /* Get the RTC_TR register */
mbed_official 155:8435094ec241 867 tmpreg = (uint32_t)(RTC->TR & RTC_TR_RESERVED_MASK);
mbed_official 155:8435094ec241 868
mbed_official 155:8435094ec241 869 /* Fill the structure fields with the read parameters */
mbed_official 155:8435094ec241 870 RTC_TimeStruct->RTC_Hours = (uint8_t)((tmpreg & (RTC_TR_HT | RTC_TR_HU)) >> 16);
mbed_official 155:8435094ec241 871 RTC_TimeStruct->RTC_Minutes = (uint8_t)((tmpreg & (RTC_TR_MNT | RTC_TR_MNU)) >>8);
mbed_official 155:8435094ec241 872 RTC_TimeStruct->RTC_Seconds = (uint8_t)(tmpreg & (RTC_TR_ST | RTC_TR_SU));
mbed_official 155:8435094ec241 873 RTC_TimeStruct->RTC_H12 = (uint8_t)((tmpreg & (RTC_TR_PM)) >> 16);
mbed_official 155:8435094ec241 874
mbed_official 155:8435094ec241 875 /* Check the input parameters format */
mbed_official 155:8435094ec241 876 if (RTC_Format == RTC_Format_BIN)
mbed_official 155:8435094ec241 877 {
mbed_official 155:8435094ec241 878 /* Convert the structure parameters to Binary format */
mbed_official 155:8435094ec241 879 RTC_TimeStruct->RTC_Hours = (uint8_t)RTC_Bcd2ToByte(RTC_TimeStruct->RTC_Hours);
mbed_official 155:8435094ec241 880 RTC_TimeStruct->RTC_Minutes = (uint8_t)RTC_Bcd2ToByte(RTC_TimeStruct->RTC_Minutes);
mbed_official 155:8435094ec241 881 RTC_TimeStruct->RTC_Seconds = (uint8_t)RTC_Bcd2ToByte(RTC_TimeStruct->RTC_Seconds);
mbed_official 155:8435094ec241 882 }
mbed_official 155:8435094ec241 883 }
mbed_official 155:8435094ec241 884
mbed_official 155:8435094ec241 885 /**
mbed_official 155:8435094ec241 886 * @brief Gets the RTC current Calendar Subseconds value.
mbed_official 155:8435094ec241 887 * @note This function freeze the Time and Date registers after reading the
mbed_official 155:8435094ec241 888 * SSR register.
mbed_official 155:8435094ec241 889 * @param None
mbed_official 155:8435094ec241 890 * @retval RTC current Calendar Subseconds value.
mbed_official 155:8435094ec241 891 */
mbed_official 155:8435094ec241 892 uint32_t RTC_GetSubSecond(void)
mbed_official 155:8435094ec241 893 {
mbed_official 155:8435094ec241 894 uint32_t tmpreg = 0;
mbed_official 155:8435094ec241 895
mbed_official 155:8435094ec241 896 /* Get subseconds values from the correspondent registers*/
mbed_official 155:8435094ec241 897 tmpreg = (uint32_t)(RTC->SSR);
mbed_official 155:8435094ec241 898
mbed_official 155:8435094ec241 899 /* Read DR register to unfroze calendar registers */
mbed_official 155:8435094ec241 900 (void) (RTC->DR);
mbed_official 155:8435094ec241 901
mbed_official 155:8435094ec241 902 return (tmpreg);
mbed_official 155:8435094ec241 903 }
mbed_official 155:8435094ec241 904
mbed_official 155:8435094ec241 905 /**
mbed_official 155:8435094ec241 906 * @brief Set the RTC current date.
mbed_official 155:8435094ec241 907 * @param RTC_Format: specifies the format of the entered parameters.
mbed_official 155:8435094ec241 908 * This parameter can be one of the following values:
mbed_official 155:8435094ec241 909 * @arg RTC_Format_BIN: Binary data format
mbed_official 155:8435094ec241 910 * @arg RTC_Format_BCD: BCD data format
mbed_official 155:8435094ec241 911 * @param RTC_DateStruct: pointer to a RTC_DateTypeDef structure that contains
mbed_official 155:8435094ec241 912 * the date configuration information for the RTC.
mbed_official 155:8435094ec241 913 * @retval An ErrorStatus enumeration value:
mbed_official 155:8435094ec241 914 * - SUCCESS: RTC Date register is configured
mbed_official 155:8435094ec241 915 * - ERROR: RTC Date register is not configured
mbed_official 155:8435094ec241 916 */
mbed_official 155:8435094ec241 917 ErrorStatus RTC_SetDate(uint32_t RTC_Format, RTC_DateTypeDef* RTC_DateStruct)
mbed_official 155:8435094ec241 918 {
mbed_official 155:8435094ec241 919 uint32_t tmpreg = 0;
mbed_official 155:8435094ec241 920 ErrorStatus status = ERROR;
mbed_official 155:8435094ec241 921
mbed_official 155:8435094ec241 922 /* Check the parameters */
mbed_official 155:8435094ec241 923 assert_param(IS_RTC_FORMAT(RTC_Format));
mbed_official 155:8435094ec241 924
mbed_official 155:8435094ec241 925 if ((RTC_Format == RTC_Format_BIN) && ((RTC_DateStruct->RTC_Month & 0x10) == 0x10))
mbed_official 155:8435094ec241 926 {
mbed_official 155:8435094ec241 927 RTC_DateStruct->RTC_Month = (RTC_DateStruct->RTC_Month & (uint32_t)~(0x10)) + 0x0A;
mbed_official 155:8435094ec241 928 }
mbed_official 155:8435094ec241 929 if (RTC_Format == RTC_Format_BIN)
mbed_official 155:8435094ec241 930 {
mbed_official 155:8435094ec241 931 assert_param(IS_RTC_YEAR(RTC_DateStruct->RTC_Year));
mbed_official 155:8435094ec241 932 assert_param(IS_RTC_MONTH(RTC_DateStruct->RTC_Month));
mbed_official 155:8435094ec241 933 assert_param(IS_RTC_DATE(RTC_DateStruct->RTC_Date));
mbed_official 155:8435094ec241 934 }
mbed_official 155:8435094ec241 935 else
mbed_official 155:8435094ec241 936 {
mbed_official 155:8435094ec241 937 assert_param(IS_RTC_YEAR(RTC_Bcd2ToByte(RTC_DateStruct->RTC_Year)));
mbed_official 155:8435094ec241 938 tmpreg = RTC_Bcd2ToByte(RTC_DateStruct->RTC_Month);
mbed_official 155:8435094ec241 939 assert_param(IS_RTC_MONTH(tmpreg));
mbed_official 155:8435094ec241 940 tmpreg = RTC_Bcd2ToByte(RTC_DateStruct->RTC_Date);
mbed_official 155:8435094ec241 941 assert_param(IS_RTC_DATE(tmpreg));
mbed_official 155:8435094ec241 942 }
mbed_official 155:8435094ec241 943 assert_param(IS_RTC_WEEKDAY(RTC_DateStruct->RTC_WeekDay));
mbed_official 155:8435094ec241 944
mbed_official 155:8435094ec241 945 /* Check the input parameters format */
mbed_official 155:8435094ec241 946 if (RTC_Format != RTC_Format_BIN)
mbed_official 155:8435094ec241 947 {
mbed_official 155:8435094ec241 948 tmpreg = ((((uint32_t)RTC_DateStruct->RTC_Year) << 16) | \
mbed_official 155:8435094ec241 949 (((uint32_t)RTC_DateStruct->RTC_Month) << 8) | \
mbed_official 155:8435094ec241 950 ((uint32_t)RTC_DateStruct->RTC_Date) | \
mbed_official 155:8435094ec241 951 (((uint32_t)RTC_DateStruct->RTC_WeekDay) << 13));
mbed_official 155:8435094ec241 952 }
mbed_official 155:8435094ec241 953 else
mbed_official 155:8435094ec241 954 {
mbed_official 155:8435094ec241 955 tmpreg = (((uint32_t)RTC_ByteToBcd2(RTC_DateStruct->RTC_Year) << 16) | \
mbed_official 155:8435094ec241 956 ((uint32_t)RTC_ByteToBcd2(RTC_DateStruct->RTC_Month) << 8) | \
mbed_official 155:8435094ec241 957 ((uint32_t)RTC_ByteToBcd2(RTC_DateStruct->RTC_Date)) | \
mbed_official 155:8435094ec241 958 ((uint32_t)RTC_DateStruct->RTC_WeekDay << 13));
mbed_official 155:8435094ec241 959 }
mbed_official 155:8435094ec241 960
mbed_official 155:8435094ec241 961 /* Disable the write protection for RTC registers */
mbed_official 155:8435094ec241 962 RTC->WPR = 0xCA;
mbed_official 155:8435094ec241 963 RTC->WPR = 0x53;
mbed_official 155:8435094ec241 964
mbed_official 155:8435094ec241 965 /* Set Initialization mode */
mbed_official 155:8435094ec241 966 if (RTC_EnterInitMode() == ERROR)
mbed_official 155:8435094ec241 967 {
mbed_official 155:8435094ec241 968 status = ERROR;
mbed_official 155:8435094ec241 969 }
mbed_official 155:8435094ec241 970 else
mbed_official 155:8435094ec241 971 {
mbed_official 155:8435094ec241 972 /* Set the RTC_DR register */
mbed_official 155:8435094ec241 973 RTC->DR = (uint32_t)(tmpreg & RTC_DR_RESERVED_MASK);
mbed_official 155:8435094ec241 974
mbed_official 155:8435094ec241 975 /* Exit Initialization mode */
mbed_official 155:8435094ec241 976 RTC_ExitInitMode();
mbed_official 155:8435094ec241 977
mbed_official 155:8435094ec241 978 /* If RTC_CR_BYPSHAD bit = 0, wait for synchro else this check is not needed */
mbed_official 155:8435094ec241 979 if ((RTC->CR & RTC_CR_BYPSHAD) == RESET)
mbed_official 155:8435094ec241 980 {
mbed_official 155:8435094ec241 981 if (RTC_WaitForSynchro() == ERROR)
mbed_official 155:8435094ec241 982 {
mbed_official 155:8435094ec241 983 status = ERROR;
mbed_official 155:8435094ec241 984 }
mbed_official 155:8435094ec241 985 else
mbed_official 155:8435094ec241 986 {
mbed_official 155:8435094ec241 987 status = SUCCESS;
mbed_official 155:8435094ec241 988 }
mbed_official 155:8435094ec241 989 }
mbed_official 155:8435094ec241 990 else
mbed_official 155:8435094ec241 991 {
mbed_official 155:8435094ec241 992 status = SUCCESS;
mbed_official 155:8435094ec241 993 }
mbed_official 155:8435094ec241 994 }
mbed_official 155:8435094ec241 995 /* Enable the write protection for RTC registers */
mbed_official 155:8435094ec241 996 RTC->WPR = 0xFF;
mbed_official 155:8435094ec241 997
mbed_official 155:8435094ec241 998 return status;
mbed_official 155:8435094ec241 999 }
mbed_official 155:8435094ec241 1000
mbed_official 155:8435094ec241 1001 /**
mbed_official 155:8435094ec241 1002 * @brief Fills each RTC_DateStruct member with its default value
mbed_official 155:8435094ec241 1003 * (Monday, January 01 xx00).
mbed_official 155:8435094ec241 1004 * @param RTC_DateStruct: pointer to a RTC_DateTypeDef structure which will be
mbed_official 155:8435094ec241 1005 * initialized.
mbed_official 155:8435094ec241 1006 * @retval None
mbed_official 155:8435094ec241 1007 */
mbed_official 155:8435094ec241 1008 void RTC_DateStructInit(RTC_DateTypeDef* RTC_DateStruct)
mbed_official 155:8435094ec241 1009 {
mbed_official 155:8435094ec241 1010 /* Monday, January 01 xx00 */
mbed_official 155:8435094ec241 1011 RTC_DateStruct->RTC_WeekDay = RTC_Weekday_Monday;
mbed_official 155:8435094ec241 1012 RTC_DateStruct->RTC_Date = 1;
mbed_official 155:8435094ec241 1013 RTC_DateStruct->RTC_Month = RTC_Month_January;
mbed_official 155:8435094ec241 1014 RTC_DateStruct->RTC_Year = 0;
mbed_official 155:8435094ec241 1015 }
mbed_official 155:8435094ec241 1016
mbed_official 155:8435094ec241 1017 /**
mbed_official 155:8435094ec241 1018 * @brief Get the RTC current date.
mbed_official 155:8435094ec241 1019 * @param RTC_Format: specifies the format of the returned parameters.
mbed_official 155:8435094ec241 1020 * This parameter can be one of the following values:
mbed_official 155:8435094ec241 1021 * @arg RTC_Format_BIN: Binary data format
mbed_official 155:8435094ec241 1022 * @arg RTC_Format_BCD: BCD data format
mbed_official 155:8435094ec241 1023 * @param RTC_DateStruct: pointer to a RTC_DateTypeDef structure that will
mbed_official 155:8435094ec241 1024 * contain the returned current date configuration.
mbed_official 155:8435094ec241 1025 * @retval None
mbed_official 155:8435094ec241 1026 */
mbed_official 155:8435094ec241 1027 void RTC_GetDate(uint32_t RTC_Format, RTC_DateTypeDef* RTC_DateStruct)
mbed_official 155:8435094ec241 1028 {
mbed_official 155:8435094ec241 1029 uint32_t tmpreg = 0;
mbed_official 155:8435094ec241 1030
mbed_official 155:8435094ec241 1031 /* Check the parameters */
mbed_official 155:8435094ec241 1032 assert_param(IS_RTC_FORMAT(RTC_Format));
mbed_official 155:8435094ec241 1033
mbed_official 155:8435094ec241 1034 /* Get the RTC_TR register */
mbed_official 155:8435094ec241 1035 tmpreg = (uint32_t)(RTC->DR & RTC_DR_RESERVED_MASK);
mbed_official 155:8435094ec241 1036
mbed_official 155:8435094ec241 1037 /* Fill the structure fields with the read parameters */
mbed_official 155:8435094ec241 1038 RTC_DateStruct->RTC_Year = (uint8_t)((tmpreg & (RTC_DR_YT | RTC_DR_YU)) >> 16);
mbed_official 155:8435094ec241 1039 RTC_DateStruct->RTC_Month = (uint8_t)((tmpreg & (RTC_DR_MT | RTC_DR_MU)) >> 8);
mbed_official 155:8435094ec241 1040 RTC_DateStruct->RTC_Date = (uint8_t)(tmpreg & (RTC_DR_DT | RTC_DR_DU));
mbed_official 155:8435094ec241 1041 RTC_DateStruct->RTC_WeekDay = (uint8_t)((tmpreg & (RTC_DR_WDU)) >> 13);
mbed_official 155:8435094ec241 1042
mbed_official 155:8435094ec241 1043 /* Check the input parameters format */
mbed_official 155:8435094ec241 1044 if (RTC_Format == RTC_Format_BIN)
mbed_official 155:8435094ec241 1045 {
mbed_official 155:8435094ec241 1046 /* Convert the structure parameters to Binary format */
mbed_official 155:8435094ec241 1047 RTC_DateStruct->RTC_Year = (uint8_t)RTC_Bcd2ToByte(RTC_DateStruct->RTC_Year);
mbed_official 155:8435094ec241 1048 RTC_DateStruct->RTC_Month = (uint8_t)RTC_Bcd2ToByte(RTC_DateStruct->RTC_Month);
mbed_official 155:8435094ec241 1049 RTC_DateStruct->RTC_Date = (uint8_t)RTC_Bcd2ToByte(RTC_DateStruct->RTC_Date);
mbed_official 155:8435094ec241 1050 RTC_DateStruct->RTC_WeekDay = (uint8_t)(RTC_DateStruct->RTC_WeekDay);
mbed_official 155:8435094ec241 1051 }
mbed_official 155:8435094ec241 1052 }
mbed_official 155:8435094ec241 1053
mbed_official 155:8435094ec241 1054 /**
mbed_official 155:8435094ec241 1055 * @}
mbed_official 155:8435094ec241 1056 */
mbed_official 155:8435094ec241 1057
mbed_official 155:8435094ec241 1058 /** @defgroup RTC_Group3 Alarms configuration functions
mbed_official 155:8435094ec241 1059 * @brief Alarms (Alarm A and Alarm B) configuration functions
mbed_official 155:8435094ec241 1060 *
mbed_official 155:8435094ec241 1061 @verbatim
mbed_official 155:8435094ec241 1062 ===============================================================================
mbed_official 155:8435094ec241 1063 ##### Alarms (Alarm A and Alarm B) configuration functions #####
mbed_official 155:8435094ec241 1064 ===============================================================================
mbed_official 155:8435094ec241 1065 [..] This section provides functions allowing to program and read the RTC Alarms.
mbed_official 155:8435094ec241 1066
mbed_official 155:8435094ec241 1067 @endverbatim
mbed_official 155:8435094ec241 1068 * @{
mbed_official 155:8435094ec241 1069 */
mbed_official 155:8435094ec241 1070
mbed_official 155:8435094ec241 1071 /**
mbed_official 155:8435094ec241 1072 * @brief Set the specified RTC Alarm.
mbed_official 155:8435094ec241 1073 * @note The Alarm register can only be written when the corresponding Alarm
mbed_official 155:8435094ec241 1074 * is disabled (Use the RTC_AlarmCmd(DISABLE)).
mbed_official 155:8435094ec241 1075 * @param RTC_Format: specifies the format of the returned parameters.
mbed_official 155:8435094ec241 1076 * This parameter can be one of the following values:
mbed_official 155:8435094ec241 1077 * @arg RTC_Format_BIN: Binary data format
mbed_official 155:8435094ec241 1078 * @arg RTC_Format_BCD: BCD data format
mbed_official 155:8435094ec241 1079 * @param RTC_Alarm: specifies the alarm to be configured.
mbed_official 155:8435094ec241 1080 * This parameter can be one of the following values:
mbed_official 155:8435094ec241 1081 * @arg RTC_Alarm_A: to select Alarm A
mbed_official 155:8435094ec241 1082 * @arg RTC_Alarm_B: to select Alarm B
mbed_official 155:8435094ec241 1083 * @param RTC_AlarmStruct: pointer to a RTC_AlarmTypeDef structure that
mbed_official 155:8435094ec241 1084 * contains the alarm configuration parameters.
mbed_official 155:8435094ec241 1085 * @retval None
mbed_official 155:8435094ec241 1086 */
mbed_official 155:8435094ec241 1087 void RTC_SetAlarm(uint32_t RTC_Format, uint32_t RTC_Alarm, RTC_AlarmTypeDef* RTC_AlarmStruct)
mbed_official 155:8435094ec241 1088 {
mbed_official 155:8435094ec241 1089 uint32_t tmpreg = 0;
mbed_official 155:8435094ec241 1090
mbed_official 155:8435094ec241 1091 /* Check the parameters */
mbed_official 155:8435094ec241 1092 assert_param(IS_RTC_FORMAT(RTC_Format));
mbed_official 155:8435094ec241 1093 assert_param(IS_RTC_ALARM(RTC_Alarm));
mbed_official 155:8435094ec241 1094 assert_param(IS_ALARM_MASK(RTC_AlarmStruct->RTC_AlarmMask));
mbed_official 155:8435094ec241 1095 assert_param(IS_RTC_ALARM_DATE_WEEKDAY_SEL(RTC_AlarmStruct->RTC_AlarmDateWeekDaySel));
mbed_official 155:8435094ec241 1096
mbed_official 155:8435094ec241 1097 if (RTC_Format == RTC_Format_BIN)
mbed_official 155:8435094ec241 1098 {
mbed_official 155:8435094ec241 1099 if ((RTC->CR & RTC_CR_FMT) != (uint32_t)RESET)
mbed_official 155:8435094ec241 1100 {
mbed_official 155:8435094ec241 1101 assert_param(IS_RTC_HOUR12(RTC_AlarmStruct->RTC_AlarmTime.RTC_Hours));
mbed_official 155:8435094ec241 1102 assert_param(IS_RTC_H12(RTC_AlarmStruct->RTC_AlarmTime.RTC_H12));
mbed_official 155:8435094ec241 1103 }
mbed_official 155:8435094ec241 1104 else
mbed_official 155:8435094ec241 1105 {
mbed_official 155:8435094ec241 1106 RTC_AlarmStruct->RTC_AlarmTime.RTC_H12 = 0x00;
mbed_official 155:8435094ec241 1107 assert_param(IS_RTC_HOUR24(RTC_AlarmStruct->RTC_AlarmTime.RTC_Hours));
mbed_official 155:8435094ec241 1108 }
mbed_official 155:8435094ec241 1109 assert_param(IS_RTC_MINUTES(RTC_AlarmStruct->RTC_AlarmTime.RTC_Minutes));
mbed_official 155:8435094ec241 1110 assert_param(IS_RTC_SECONDS(RTC_AlarmStruct->RTC_AlarmTime.RTC_Seconds));
mbed_official 155:8435094ec241 1111
mbed_official 155:8435094ec241 1112 if(RTC_AlarmStruct->RTC_AlarmDateWeekDaySel == RTC_AlarmDateWeekDaySel_Date)
mbed_official 155:8435094ec241 1113 {
mbed_official 155:8435094ec241 1114 assert_param(IS_RTC_ALARM_DATE_WEEKDAY_DATE(RTC_AlarmStruct->RTC_AlarmDateWeekDay));
mbed_official 155:8435094ec241 1115 }
mbed_official 155:8435094ec241 1116 else
mbed_official 155:8435094ec241 1117 {
mbed_official 155:8435094ec241 1118 assert_param(IS_RTC_ALARM_DATE_WEEKDAY_WEEKDAY(RTC_AlarmStruct->RTC_AlarmDateWeekDay));
mbed_official 155:8435094ec241 1119 }
mbed_official 155:8435094ec241 1120 }
mbed_official 155:8435094ec241 1121 else
mbed_official 155:8435094ec241 1122 {
mbed_official 155:8435094ec241 1123 if ((RTC->CR & RTC_CR_FMT) != (uint32_t)RESET)
mbed_official 155:8435094ec241 1124 {
mbed_official 155:8435094ec241 1125 tmpreg = RTC_Bcd2ToByte(RTC_AlarmStruct->RTC_AlarmTime.RTC_Hours);
mbed_official 155:8435094ec241 1126 assert_param(IS_RTC_HOUR12(tmpreg));
mbed_official 155:8435094ec241 1127 assert_param(IS_RTC_H12(RTC_AlarmStruct->RTC_AlarmTime.RTC_H12));
mbed_official 155:8435094ec241 1128 }
mbed_official 155:8435094ec241 1129 else
mbed_official 155:8435094ec241 1130 {
mbed_official 155:8435094ec241 1131 RTC_AlarmStruct->RTC_AlarmTime.RTC_H12 = 0x00;
mbed_official 155:8435094ec241 1132 assert_param(IS_RTC_HOUR24(RTC_Bcd2ToByte(RTC_AlarmStruct->RTC_AlarmTime.RTC_Hours)));
mbed_official 155:8435094ec241 1133 }
mbed_official 155:8435094ec241 1134
mbed_official 155:8435094ec241 1135 assert_param(IS_RTC_MINUTES(RTC_Bcd2ToByte(RTC_AlarmStruct->RTC_AlarmTime.RTC_Minutes)));
mbed_official 155:8435094ec241 1136 assert_param(IS_RTC_SECONDS(RTC_Bcd2ToByte(RTC_AlarmStruct->RTC_AlarmTime.RTC_Seconds)));
mbed_official 155:8435094ec241 1137
mbed_official 155:8435094ec241 1138 if(RTC_AlarmStruct->RTC_AlarmDateWeekDaySel == RTC_AlarmDateWeekDaySel_Date)
mbed_official 155:8435094ec241 1139 {
mbed_official 155:8435094ec241 1140 tmpreg = RTC_Bcd2ToByte(RTC_AlarmStruct->RTC_AlarmDateWeekDay);
mbed_official 155:8435094ec241 1141 assert_param(IS_RTC_ALARM_DATE_WEEKDAY_DATE(tmpreg));
mbed_official 155:8435094ec241 1142 }
mbed_official 155:8435094ec241 1143 else
mbed_official 155:8435094ec241 1144 {
mbed_official 155:8435094ec241 1145 tmpreg = RTC_Bcd2ToByte(RTC_AlarmStruct->RTC_AlarmDateWeekDay);
mbed_official 155:8435094ec241 1146 assert_param(IS_RTC_ALARM_DATE_WEEKDAY_WEEKDAY(tmpreg));
mbed_official 155:8435094ec241 1147 }
mbed_official 155:8435094ec241 1148 }
mbed_official 155:8435094ec241 1149
mbed_official 155:8435094ec241 1150 /* Check the input parameters format */
mbed_official 155:8435094ec241 1151 if (RTC_Format != RTC_Format_BIN)
mbed_official 155:8435094ec241 1152 {
mbed_official 155:8435094ec241 1153 tmpreg = (((uint32_t)(RTC_AlarmStruct->RTC_AlarmTime.RTC_Hours) << 16) | \
mbed_official 155:8435094ec241 1154 ((uint32_t)(RTC_AlarmStruct->RTC_AlarmTime.RTC_Minutes) << 8) | \
mbed_official 155:8435094ec241 1155 ((uint32_t)RTC_AlarmStruct->RTC_AlarmTime.RTC_Seconds) | \
mbed_official 155:8435094ec241 1156 ((uint32_t)(RTC_AlarmStruct->RTC_AlarmTime.RTC_H12) << 16) | \
mbed_official 155:8435094ec241 1157 ((uint32_t)(RTC_AlarmStruct->RTC_AlarmDateWeekDay) << 24) | \
mbed_official 155:8435094ec241 1158 ((uint32_t)RTC_AlarmStruct->RTC_AlarmDateWeekDaySel) | \
mbed_official 155:8435094ec241 1159 ((uint32_t)RTC_AlarmStruct->RTC_AlarmMask));
mbed_official 155:8435094ec241 1160 }
mbed_official 155:8435094ec241 1161 else
mbed_official 155:8435094ec241 1162 {
mbed_official 155:8435094ec241 1163 tmpreg = (((uint32_t)RTC_ByteToBcd2(RTC_AlarmStruct->RTC_AlarmTime.RTC_Hours) << 16) | \
mbed_official 155:8435094ec241 1164 ((uint32_t)RTC_ByteToBcd2(RTC_AlarmStruct->RTC_AlarmTime.RTC_Minutes) << 8) | \
mbed_official 155:8435094ec241 1165 ((uint32_t)RTC_ByteToBcd2(RTC_AlarmStruct->RTC_AlarmTime.RTC_Seconds)) | \
mbed_official 155:8435094ec241 1166 ((uint32_t)(RTC_AlarmStruct->RTC_AlarmTime.RTC_H12) << 16) | \
mbed_official 155:8435094ec241 1167 ((uint32_t)RTC_ByteToBcd2(RTC_AlarmStruct->RTC_AlarmDateWeekDay) << 24) | \
mbed_official 155:8435094ec241 1168 ((uint32_t)RTC_AlarmStruct->RTC_AlarmDateWeekDaySel) | \
mbed_official 155:8435094ec241 1169 ((uint32_t)RTC_AlarmStruct->RTC_AlarmMask));
mbed_official 155:8435094ec241 1170 }
mbed_official 155:8435094ec241 1171
mbed_official 155:8435094ec241 1172 /* Disable the write protection for RTC registers */
mbed_official 155:8435094ec241 1173 RTC->WPR = 0xCA;
mbed_official 155:8435094ec241 1174 RTC->WPR = 0x53;
mbed_official 155:8435094ec241 1175
mbed_official 155:8435094ec241 1176 /* Configure the Alarm register */
mbed_official 155:8435094ec241 1177 if (RTC_Alarm == RTC_Alarm_A)
mbed_official 155:8435094ec241 1178 {
mbed_official 155:8435094ec241 1179 RTC->ALRMAR = (uint32_t)tmpreg;
mbed_official 155:8435094ec241 1180 }
mbed_official 155:8435094ec241 1181 else
mbed_official 155:8435094ec241 1182 {
mbed_official 155:8435094ec241 1183 RTC->ALRMBR = (uint32_t)tmpreg;
mbed_official 155:8435094ec241 1184 }
mbed_official 155:8435094ec241 1185
mbed_official 155:8435094ec241 1186 /* Enable the write protection for RTC registers */
mbed_official 155:8435094ec241 1187 RTC->WPR = 0xFF;
mbed_official 155:8435094ec241 1188 }
mbed_official 155:8435094ec241 1189
mbed_official 155:8435094ec241 1190 /**
mbed_official 155:8435094ec241 1191 * @brief Fills each RTC_AlarmStruct member with its default value
mbed_official 155:8435094ec241 1192 * (Time = 00h:00mn:00sec / Date = 1st day of the month/Mask =
mbed_official 155:8435094ec241 1193 * all fields are masked).
mbed_official 155:8435094ec241 1194 * @param RTC_AlarmStruct: pointer to a @ref RTC_AlarmTypeDef structure which
mbed_official 155:8435094ec241 1195 * will be initialized.
mbed_official 155:8435094ec241 1196 * @retval None
mbed_official 155:8435094ec241 1197 */
mbed_official 155:8435094ec241 1198 void RTC_AlarmStructInit(RTC_AlarmTypeDef* RTC_AlarmStruct)
mbed_official 155:8435094ec241 1199 {
mbed_official 155:8435094ec241 1200 /* Alarm Time Settings : Time = 00h:00mn:00sec */
mbed_official 155:8435094ec241 1201 RTC_AlarmStruct->RTC_AlarmTime.RTC_H12 = RTC_H12_AM;
mbed_official 155:8435094ec241 1202 RTC_AlarmStruct->RTC_AlarmTime.RTC_Hours = 0;
mbed_official 155:8435094ec241 1203 RTC_AlarmStruct->RTC_AlarmTime.RTC_Minutes = 0;
mbed_official 155:8435094ec241 1204 RTC_AlarmStruct->RTC_AlarmTime.RTC_Seconds = 0;
mbed_official 155:8435094ec241 1205
mbed_official 155:8435094ec241 1206 /* Alarm Date Settings : Date = 1st day of the month */
mbed_official 155:8435094ec241 1207 RTC_AlarmStruct->RTC_AlarmDateWeekDaySel = RTC_AlarmDateWeekDaySel_Date;
mbed_official 155:8435094ec241 1208 RTC_AlarmStruct->RTC_AlarmDateWeekDay = 1;
mbed_official 155:8435094ec241 1209
mbed_official 155:8435094ec241 1210 /* Alarm Masks Settings : Mask = all fields are not masked */
mbed_official 155:8435094ec241 1211 RTC_AlarmStruct->RTC_AlarmMask = RTC_AlarmMask_None;
mbed_official 155:8435094ec241 1212 }
mbed_official 155:8435094ec241 1213
mbed_official 155:8435094ec241 1214 /**
mbed_official 155:8435094ec241 1215 * @brief Get the RTC Alarm value and masks.
mbed_official 155:8435094ec241 1216 * @param RTC_Format: specifies the format of the output parameters.
mbed_official 155:8435094ec241 1217 * This parameter can be one of the following values:
mbed_official 155:8435094ec241 1218 * @arg RTC_Format_BIN: Binary data format
mbed_official 155:8435094ec241 1219 * @arg RTC_Format_BCD: BCD data format
mbed_official 155:8435094ec241 1220 * @param RTC_Alarm: specifies the alarm to be read.
mbed_official 155:8435094ec241 1221 * This parameter can be one of the following values:
mbed_official 155:8435094ec241 1222 * @arg RTC_Alarm_A: to select Alarm A
mbed_official 155:8435094ec241 1223 * @arg RTC_Alarm_B: to select Alarm B
mbed_official 155:8435094ec241 1224 * @param RTC_AlarmStruct: pointer to a RTC_AlarmTypeDef structure that will
mbed_official 155:8435094ec241 1225 * contains the output alarm configuration values.
mbed_official 155:8435094ec241 1226 * @retval None
mbed_official 155:8435094ec241 1227 */
mbed_official 155:8435094ec241 1228 void RTC_GetAlarm(uint32_t RTC_Format, uint32_t RTC_Alarm, RTC_AlarmTypeDef* RTC_AlarmStruct)
mbed_official 155:8435094ec241 1229 {
mbed_official 155:8435094ec241 1230 uint32_t tmpreg = 0;
mbed_official 155:8435094ec241 1231
mbed_official 155:8435094ec241 1232 /* Check the parameters */
mbed_official 155:8435094ec241 1233 assert_param(IS_RTC_FORMAT(RTC_Format));
mbed_official 155:8435094ec241 1234 assert_param(IS_RTC_ALARM(RTC_Alarm));
mbed_official 155:8435094ec241 1235
mbed_official 155:8435094ec241 1236 /* Get the RTC_ALRMxR register */
mbed_official 155:8435094ec241 1237 if (RTC_Alarm == RTC_Alarm_A)
mbed_official 155:8435094ec241 1238 {
mbed_official 155:8435094ec241 1239 tmpreg = (uint32_t)(RTC->ALRMAR);
mbed_official 155:8435094ec241 1240 }
mbed_official 155:8435094ec241 1241 else
mbed_official 155:8435094ec241 1242 {
mbed_official 155:8435094ec241 1243 tmpreg = (uint32_t)(RTC->ALRMBR);
mbed_official 155:8435094ec241 1244 }
mbed_official 155:8435094ec241 1245
mbed_official 155:8435094ec241 1246 /* Fill the structure with the read parameters */
mbed_official 155:8435094ec241 1247 RTC_AlarmStruct->RTC_AlarmTime.RTC_Hours = (uint32_t)((tmpreg & (RTC_ALRMAR_HT | \
mbed_official 155:8435094ec241 1248 RTC_ALRMAR_HU)) >> 16);
mbed_official 155:8435094ec241 1249 RTC_AlarmStruct->RTC_AlarmTime.RTC_Minutes = (uint32_t)((tmpreg & (RTC_ALRMAR_MNT | \
mbed_official 155:8435094ec241 1250 RTC_ALRMAR_MNU)) >> 8);
mbed_official 155:8435094ec241 1251 RTC_AlarmStruct->RTC_AlarmTime.RTC_Seconds = (uint32_t)(tmpreg & (RTC_ALRMAR_ST | \
mbed_official 155:8435094ec241 1252 RTC_ALRMAR_SU));
mbed_official 155:8435094ec241 1253 RTC_AlarmStruct->RTC_AlarmTime.RTC_H12 = (uint32_t)((tmpreg & RTC_ALRMAR_PM) >> 16);
mbed_official 155:8435094ec241 1254 RTC_AlarmStruct->RTC_AlarmDateWeekDay = (uint32_t)((tmpreg & (RTC_ALRMAR_DT | RTC_ALRMAR_DU)) >> 24);
mbed_official 155:8435094ec241 1255 RTC_AlarmStruct->RTC_AlarmDateWeekDaySel = (uint32_t)(tmpreg & RTC_ALRMAR_WDSEL);
mbed_official 155:8435094ec241 1256 RTC_AlarmStruct->RTC_AlarmMask = (uint32_t)(tmpreg & RTC_AlarmMask_All);
mbed_official 155:8435094ec241 1257
mbed_official 155:8435094ec241 1258 if (RTC_Format == RTC_Format_BIN)
mbed_official 155:8435094ec241 1259 {
mbed_official 155:8435094ec241 1260 RTC_AlarmStruct->RTC_AlarmTime.RTC_Hours = RTC_Bcd2ToByte(RTC_AlarmStruct-> \
mbed_official 155:8435094ec241 1261 RTC_AlarmTime.RTC_Hours);
mbed_official 155:8435094ec241 1262 RTC_AlarmStruct->RTC_AlarmTime.RTC_Minutes = RTC_Bcd2ToByte(RTC_AlarmStruct-> \
mbed_official 155:8435094ec241 1263 RTC_AlarmTime.RTC_Minutes);
mbed_official 155:8435094ec241 1264 RTC_AlarmStruct->RTC_AlarmTime.RTC_Seconds = RTC_Bcd2ToByte(RTC_AlarmStruct-> \
mbed_official 155:8435094ec241 1265 RTC_AlarmTime.RTC_Seconds);
mbed_official 155:8435094ec241 1266 RTC_AlarmStruct->RTC_AlarmDateWeekDay = RTC_Bcd2ToByte(RTC_AlarmStruct->RTC_AlarmDateWeekDay);
mbed_official 155:8435094ec241 1267 }
mbed_official 155:8435094ec241 1268 }
mbed_official 155:8435094ec241 1269
mbed_official 155:8435094ec241 1270 /**
mbed_official 155:8435094ec241 1271 * @brief Enables or disables the specified RTC Alarm.
mbed_official 155:8435094ec241 1272 * @param RTC_Alarm: specifies the alarm to be configured.
mbed_official 155:8435094ec241 1273 * This parameter can be any combination of the following values:
mbed_official 155:8435094ec241 1274 * @arg RTC_Alarm_A: to select Alarm A
mbed_official 155:8435094ec241 1275 * @arg RTC_Alarm_B: to select Alarm B
mbed_official 155:8435094ec241 1276 * @param NewState: new state of the specified alarm.
mbed_official 155:8435094ec241 1277 * This parameter can be: ENABLE or DISABLE.
mbed_official 155:8435094ec241 1278 * @retval An ErrorStatus enumeration value:
mbed_official 155:8435094ec241 1279 * - SUCCESS: RTC Alarm is enabled/disabled
mbed_official 155:8435094ec241 1280 * - ERROR: RTC Alarm is not enabled/disabled
mbed_official 155:8435094ec241 1281 */
mbed_official 155:8435094ec241 1282 ErrorStatus RTC_AlarmCmd(uint32_t RTC_Alarm, FunctionalState NewState)
mbed_official 155:8435094ec241 1283 {
mbed_official 155:8435094ec241 1284 __IO uint32_t alarmcounter = 0x00;
mbed_official 155:8435094ec241 1285 uint32_t alarmstatus = 0x00;
mbed_official 155:8435094ec241 1286 ErrorStatus status = ERROR;
mbed_official 155:8435094ec241 1287
mbed_official 155:8435094ec241 1288 /* Check the parameters */
mbed_official 155:8435094ec241 1289 assert_param(IS_RTC_CMD_ALARM(RTC_Alarm));
mbed_official 155:8435094ec241 1290 assert_param(IS_FUNCTIONAL_STATE(NewState));
mbed_official 155:8435094ec241 1291
mbed_official 155:8435094ec241 1292 /* Disable the write protection for RTC registers */
mbed_official 155:8435094ec241 1293 RTC->WPR = 0xCA;
mbed_official 155:8435094ec241 1294 RTC->WPR = 0x53;
mbed_official 155:8435094ec241 1295
mbed_official 155:8435094ec241 1296 /* Configure the Alarm state */
mbed_official 155:8435094ec241 1297 if (NewState != DISABLE)
mbed_official 155:8435094ec241 1298 {
mbed_official 155:8435094ec241 1299 RTC->CR |= (uint32_t)RTC_Alarm;
mbed_official 155:8435094ec241 1300
mbed_official 155:8435094ec241 1301 status = SUCCESS;
mbed_official 155:8435094ec241 1302 }
mbed_official 155:8435094ec241 1303 else
mbed_official 155:8435094ec241 1304 {
mbed_official 155:8435094ec241 1305 /* Disable the Alarm in RTC_CR register */
mbed_official 155:8435094ec241 1306 RTC->CR &= (uint32_t)~RTC_Alarm;
mbed_official 155:8435094ec241 1307
mbed_official 155:8435094ec241 1308 /* Wait till RTC ALRxWF flag is set and if Time out is reached exit */
mbed_official 155:8435094ec241 1309 do
mbed_official 155:8435094ec241 1310 {
mbed_official 155:8435094ec241 1311 alarmstatus = RTC->ISR & (RTC_Alarm >> 8);
mbed_official 155:8435094ec241 1312 alarmcounter++;
mbed_official 155:8435094ec241 1313 } while((alarmcounter != INITMODE_TIMEOUT) && (alarmstatus == 0x00));
mbed_official 155:8435094ec241 1314
mbed_official 155:8435094ec241 1315 if ((RTC->ISR & (RTC_Alarm >> 8)) == RESET)
mbed_official 155:8435094ec241 1316 {
mbed_official 155:8435094ec241 1317 status = ERROR;
mbed_official 155:8435094ec241 1318 }
mbed_official 155:8435094ec241 1319 else
mbed_official 155:8435094ec241 1320 {
mbed_official 155:8435094ec241 1321 status = SUCCESS;
mbed_official 155:8435094ec241 1322 }
mbed_official 155:8435094ec241 1323 }
mbed_official 155:8435094ec241 1324
mbed_official 155:8435094ec241 1325 /* Enable the write protection for RTC registers */
mbed_official 155:8435094ec241 1326 RTC->WPR = 0xFF;
mbed_official 155:8435094ec241 1327
mbed_official 155:8435094ec241 1328 return status;
mbed_official 155:8435094ec241 1329 }
mbed_official 155:8435094ec241 1330
mbed_official 155:8435094ec241 1331 /**
mbed_official 155:8435094ec241 1332 * @brief Configures the RTC AlarmA/B Subseconds value and mask.
mbed_official 155:8435094ec241 1333 * @note This function is performed only when the Alarm is disabled.
mbed_official 155:8435094ec241 1334 * @param RTC_Alarm: specifies the alarm to be configured.
mbed_official 155:8435094ec241 1335 * This parameter can be one of the following values:
mbed_official 155:8435094ec241 1336 * @arg RTC_Alarm_A: to select Alarm A
mbed_official 155:8435094ec241 1337 * @arg RTC_Alarm_B: to select Alarm B
mbed_official 155:8435094ec241 1338 * @param RTC_AlarmSubSecondValue: specifies the Subseconds value.
mbed_official 155:8435094ec241 1339 * This parameter can be a value from 0 to 0x00007FFF.
mbed_official 155:8435094ec241 1340 * @param RTC_AlarmSubSecondMask: specifies the Subseconds Mask.
mbed_official 155:8435094ec241 1341 * This parameter can be any combination of the following values:
mbed_official 155:8435094ec241 1342 * @arg RTC_AlarmSubSecondMask_All : All Alarm SS fields are masked.
mbed_official 155:8435094ec241 1343 * There is no comparison on sub seconds for Alarm.
mbed_official 155:8435094ec241 1344 * @arg RTC_AlarmSubSecondMask_SS14_1 : SS[14:1] are don't care in Alarm comparison.
mbed_official 155:8435094ec241 1345 * Only SS[0] is compared
mbed_official 155:8435094ec241 1346 * @arg RTC_AlarmSubSecondMask_SS14_2 : SS[14:2] are don't care in Alarm comparison.
mbed_official 155:8435094ec241 1347 * Only SS[1:0] are compared
mbed_official 155:8435094ec241 1348 * @arg RTC_AlarmSubSecondMask_SS14_3 : SS[14:3] are don't care in Alarm comparison.
mbed_official 155:8435094ec241 1349 * Only SS[2:0] are compared
mbed_official 155:8435094ec241 1350 * @arg RTC_AlarmSubSecondMask_SS14_4 : SS[14:4] are don't care in Alarm comparison.
mbed_official 155:8435094ec241 1351 * Only SS[3:0] are compared
mbed_official 155:8435094ec241 1352 * @arg RTC_AlarmSubSecondMask_SS14_5 : SS[14:5] are don't care in Alarm comparison.
mbed_official 155:8435094ec241 1353 * Only SS[4:0] are compared
mbed_official 155:8435094ec241 1354 * @arg RTC_AlarmSubSecondMask_SS14_6 : SS[14:6] are don't care in Alarm comparison.
mbed_official 155:8435094ec241 1355 * Only SS[5:0] are compared
mbed_official 155:8435094ec241 1356 * @arg RTC_AlarmSubSecondMask_SS14_7 : SS[14:7] are don't care in Alarm comparison.
mbed_official 155:8435094ec241 1357 * Only SS[6:0] are compared
mbed_official 155:8435094ec241 1358 * @arg RTC_AlarmSubSecondMask_SS14_8 : SS[14:8] are don't care in Alarm comparison.
mbed_official 155:8435094ec241 1359 * Only SS[7:0] are compared
mbed_official 155:8435094ec241 1360 * @arg RTC_AlarmSubSecondMask_SS14_9 : SS[14:9] are don't care in Alarm comparison.
mbed_official 155:8435094ec241 1361 * Only SS[8:0] are compared
mbed_official 155:8435094ec241 1362 * @arg RTC_AlarmSubSecondMask_SS14_10: SS[14:10] are don't care in Alarm comparison.
mbed_official 155:8435094ec241 1363 * Only SS[9:0] are compared
mbed_official 155:8435094ec241 1364 * @arg RTC_AlarmSubSecondMask_SS14_11: SS[14:11] are don't care in Alarm comparison.
mbed_official 155:8435094ec241 1365 * Only SS[10:0] are compared
mbed_official 155:8435094ec241 1366 * @arg RTC_AlarmSubSecondMask_SS14_12: SS[14:12] are don't care in Alarm comparison.
mbed_official 155:8435094ec241 1367 * Only SS[11:0] are compared
mbed_official 155:8435094ec241 1368 * @arg RTC_AlarmSubSecondMask_SS14_13: SS[14:13] are don't care in Alarm comparison.
mbed_official 155:8435094ec241 1369 * Only SS[12:0] are compared
mbed_official 155:8435094ec241 1370 * @arg RTC_AlarmSubSecondMask_SS14 : SS[14] is don't care in Alarm comparison.
mbed_official 155:8435094ec241 1371 * Only SS[13:0] are compared
mbed_official 155:8435094ec241 1372 * @arg RTC_AlarmSubSecondMask_None : SS[14:0] are compared and must match
mbed_official 155:8435094ec241 1373 * to activate alarm
mbed_official 155:8435094ec241 1374 * @retval None
mbed_official 155:8435094ec241 1375 */
mbed_official 155:8435094ec241 1376 void RTC_AlarmSubSecondConfig(uint32_t RTC_Alarm, uint32_t RTC_AlarmSubSecondValue, uint32_t RTC_AlarmSubSecondMask)
mbed_official 155:8435094ec241 1377 {
mbed_official 155:8435094ec241 1378 uint32_t tmpreg = 0;
mbed_official 155:8435094ec241 1379
mbed_official 155:8435094ec241 1380 /* Check the parameters */
mbed_official 155:8435094ec241 1381 assert_param(IS_RTC_ALARM(RTC_Alarm));
mbed_official 155:8435094ec241 1382 assert_param(IS_RTC_ALARM_SUB_SECOND_VALUE(RTC_AlarmSubSecondValue));
mbed_official 155:8435094ec241 1383 assert_param(IS_RTC_ALARM_SUB_SECOND_MASK(RTC_AlarmSubSecondMask));
mbed_official 155:8435094ec241 1384
mbed_official 155:8435094ec241 1385 /* Disable the write protection for RTC registers */
mbed_official 155:8435094ec241 1386 RTC->WPR = 0xCA;
mbed_official 155:8435094ec241 1387 RTC->WPR = 0x53;
mbed_official 155:8435094ec241 1388
mbed_official 155:8435094ec241 1389 /* Configure the Alarm A or Alarm B SubSecond registers */
mbed_official 155:8435094ec241 1390 tmpreg = (uint32_t) (uint32_t)(RTC_AlarmSubSecondValue) | (uint32_t)(RTC_AlarmSubSecondMask);
mbed_official 155:8435094ec241 1391
mbed_official 155:8435094ec241 1392 if (RTC_Alarm == RTC_Alarm_A)
mbed_official 155:8435094ec241 1393 {
mbed_official 155:8435094ec241 1394 /* Configure the AlarmA SubSecond register */
mbed_official 155:8435094ec241 1395 RTC->ALRMASSR = tmpreg;
mbed_official 155:8435094ec241 1396 }
mbed_official 155:8435094ec241 1397 else
mbed_official 155:8435094ec241 1398 {
mbed_official 155:8435094ec241 1399 /* Configure the Alarm B SubSecond register */
mbed_official 155:8435094ec241 1400 RTC->ALRMBSSR = tmpreg;
mbed_official 155:8435094ec241 1401 }
mbed_official 155:8435094ec241 1402
mbed_official 155:8435094ec241 1403 /* Enable the write protection for RTC registers */
mbed_official 155:8435094ec241 1404 RTC->WPR = 0xFF;
mbed_official 155:8435094ec241 1405
mbed_official 155:8435094ec241 1406 }
mbed_official 155:8435094ec241 1407
mbed_official 155:8435094ec241 1408 /**
mbed_official 155:8435094ec241 1409 * @brief Gets the RTC Alarm Subseconds value.
mbed_official 155:8435094ec241 1410 * @param RTC_Alarm: specifies the alarm to be read.
mbed_official 155:8435094ec241 1411 * This parameter can be one of the following values:
mbed_official 155:8435094ec241 1412 * @arg RTC_Alarm_A: to select Alarm A
mbed_official 155:8435094ec241 1413 * @arg RTC_Alarm_B: to select Alarm B
mbed_official 155:8435094ec241 1414 * @param None
mbed_official 155:8435094ec241 1415 * @retval RTC Alarm Subseconds value.
mbed_official 155:8435094ec241 1416 */
mbed_official 155:8435094ec241 1417 uint32_t RTC_GetAlarmSubSecond(uint32_t RTC_Alarm)
mbed_official 155:8435094ec241 1418 {
mbed_official 155:8435094ec241 1419 uint32_t tmpreg = 0;
mbed_official 155:8435094ec241 1420
mbed_official 155:8435094ec241 1421 /* Get the RTC_ALRMxR register */
mbed_official 155:8435094ec241 1422 if (RTC_Alarm == RTC_Alarm_A)
mbed_official 155:8435094ec241 1423 {
mbed_official 155:8435094ec241 1424 tmpreg = (uint32_t)((RTC->ALRMASSR) & RTC_ALRMASSR_SS);
mbed_official 155:8435094ec241 1425 }
mbed_official 155:8435094ec241 1426 else
mbed_official 155:8435094ec241 1427 {
mbed_official 155:8435094ec241 1428 tmpreg = (uint32_t)((RTC->ALRMBSSR) & RTC_ALRMBSSR_SS);
mbed_official 155:8435094ec241 1429 }
mbed_official 155:8435094ec241 1430
mbed_official 155:8435094ec241 1431 return (tmpreg);
mbed_official 155:8435094ec241 1432 }
mbed_official 155:8435094ec241 1433
mbed_official 155:8435094ec241 1434 /**
mbed_official 155:8435094ec241 1435 * @}
mbed_official 155:8435094ec241 1436 */
mbed_official 155:8435094ec241 1437
mbed_official 155:8435094ec241 1438 /** @defgroup RTC_Group4 WakeUp Timer configuration functions
mbed_official 155:8435094ec241 1439 * @brief WakeUp Timer configuration functions
mbed_official 155:8435094ec241 1440 *
mbed_official 155:8435094ec241 1441 @verbatim
mbed_official 155:8435094ec241 1442 ===============================================================================
mbed_official 155:8435094ec241 1443 ##### WakeUp Timer configuration functions #####
mbed_official 155:8435094ec241 1444 ===============================================================================
mbed_official 155:8435094ec241 1445 [..] This section provide functions allowing to program and read the RTC WakeUp.
mbed_official 155:8435094ec241 1446
mbed_official 155:8435094ec241 1447 @endverbatim
mbed_official 155:8435094ec241 1448 * @{
mbed_official 155:8435094ec241 1449 */
mbed_official 155:8435094ec241 1450
mbed_official 155:8435094ec241 1451 /**
mbed_official 155:8435094ec241 1452 * @brief Configures the RTC Wakeup clock source.
mbed_official 155:8435094ec241 1453 * @note The WakeUp Clock source can only be changed when the RTC WakeUp
mbed_official 155:8435094ec241 1454 * is disabled (Use the RTC_WakeUpCmd(DISABLE)).
mbed_official 155:8435094ec241 1455 * @param RTC_WakeUpClock: Wakeup Clock source.
mbed_official 155:8435094ec241 1456 * This parameter can be one of the following values:
mbed_official 155:8435094ec241 1457 * @arg RTC_WakeUpClock_RTCCLK_Div16: RTC Wakeup Counter Clock = RTCCLK/16
mbed_official 155:8435094ec241 1458 * @arg RTC_WakeUpClock_RTCCLK_Div8: RTC Wakeup Counter Clock = RTCCLK/8
mbed_official 155:8435094ec241 1459 * @arg RTC_WakeUpClock_RTCCLK_Div4: RTC Wakeup Counter Clock = RTCCLK/4
mbed_official 155:8435094ec241 1460 * @arg RTC_WakeUpClock_RTCCLK_Div2: RTC Wakeup Counter Clock = RTCCLK/2
mbed_official 155:8435094ec241 1461 * @arg RTC_WakeUpClock_CK_SPRE_16bits: RTC Wakeup Counter Clock = CK_SPRE
mbed_official 155:8435094ec241 1462 * @arg RTC_WakeUpClock_CK_SPRE_17bits: RTC Wakeup Counter Clock = CK_SPRE
mbed_official 155:8435094ec241 1463 * @retval None
mbed_official 155:8435094ec241 1464 */
mbed_official 155:8435094ec241 1465 void RTC_WakeUpClockConfig(uint32_t RTC_WakeUpClock)
mbed_official 155:8435094ec241 1466 {
mbed_official 155:8435094ec241 1467 /* Check the parameters */
mbed_official 155:8435094ec241 1468 assert_param(IS_RTC_WAKEUP_CLOCK(RTC_WakeUpClock));
mbed_official 155:8435094ec241 1469
mbed_official 155:8435094ec241 1470 /* Disable the write protection for RTC registers */
mbed_official 155:8435094ec241 1471 RTC->WPR = 0xCA;
mbed_official 155:8435094ec241 1472 RTC->WPR = 0x53;
mbed_official 155:8435094ec241 1473
mbed_official 155:8435094ec241 1474 /* Clear the Wakeup Timer clock source bits in CR register */
mbed_official 155:8435094ec241 1475 RTC->CR &= (uint32_t)~RTC_CR_WUCKSEL;
mbed_official 155:8435094ec241 1476
mbed_official 155:8435094ec241 1477 /* Configure the clock source */
mbed_official 155:8435094ec241 1478 RTC->CR |= (uint32_t)RTC_WakeUpClock;
mbed_official 155:8435094ec241 1479
mbed_official 155:8435094ec241 1480 /* Enable the write protection for RTC registers */
mbed_official 155:8435094ec241 1481 RTC->WPR = 0xFF;
mbed_official 155:8435094ec241 1482 }
mbed_official 155:8435094ec241 1483
mbed_official 155:8435094ec241 1484 /**
mbed_official 155:8435094ec241 1485 * @brief Configures the RTC Wakeup counter.
mbed_official 155:8435094ec241 1486 * @note The RTC WakeUp counter can only be written when the RTC WakeUp
mbed_official 155:8435094ec241 1487 * is disabled (Use the RTC_WakeUpCmd(DISABLE)).
mbed_official 155:8435094ec241 1488 * @param RTC_WakeUpCounter: specifies the WakeUp counter.
mbed_official 155:8435094ec241 1489 * This parameter can be a value from 0x0000 to 0xFFFF.
mbed_official 155:8435094ec241 1490 * @retval None
mbed_official 155:8435094ec241 1491 */
mbed_official 155:8435094ec241 1492 void RTC_SetWakeUpCounter(uint32_t RTC_WakeUpCounter)
mbed_official 155:8435094ec241 1493 {
mbed_official 155:8435094ec241 1494 /* Check the parameters */
mbed_official 155:8435094ec241 1495 assert_param(IS_RTC_WAKEUP_COUNTER(RTC_WakeUpCounter));
mbed_official 155:8435094ec241 1496
mbed_official 155:8435094ec241 1497 /* Disable the write protection for RTC registers */
mbed_official 155:8435094ec241 1498 RTC->WPR = 0xCA;
mbed_official 155:8435094ec241 1499 RTC->WPR = 0x53;
mbed_official 155:8435094ec241 1500
mbed_official 155:8435094ec241 1501 /* Configure the Wakeup Timer counter */
mbed_official 155:8435094ec241 1502 RTC->WUTR = (uint32_t)RTC_WakeUpCounter;
mbed_official 155:8435094ec241 1503
mbed_official 155:8435094ec241 1504 /* Enable the write protection for RTC registers */
mbed_official 155:8435094ec241 1505 RTC->WPR = 0xFF;
mbed_official 155:8435094ec241 1506 }
mbed_official 155:8435094ec241 1507
mbed_official 155:8435094ec241 1508 /**
mbed_official 155:8435094ec241 1509 * @brief Returns the RTC WakeUp timer counter value.
mbed_official 155:8435094ec241 1510 * @param None
mbed_official 155:8435094ec241 1511 * @retval The RTC WakeUp Counter value.
mbed_official 155:8435094ec241 1512 */
mbed_official 155:8435094ec241 1513 uint32_t RTC_GetWakeUpCounter(void)
mbed_official 155:8435094ec241 1514 {
mbed_official 155:8435094ec241 1515 /* Get the counter value */
mbed_official 155:8435094ec241 1516 return ((uint32_t)(RTC->WUTR & RTC_WUTR_WUT));
mbed_official 155:8435094ec241 1517 }
mbed_official 155:8435094ec241 1518
mbed_official 155:8435094ec241 1519 /**
mbed_official 155:8435094ec241 1520 * @brief Enables or Disables the RTC WakeUp timer.
mbed_official 155:8435094ec241 1521 * @param NewState: new state of the WakeUp timer.
mbed_official 155:8435094ec241 1522 * This parameter can be: ENABLE or DISABLE.
mbed_official 155:8435094ec241 1523 * @retval None
mbed_official 155:8435094ec241 1524 */
mbed_official 155:8435094ec241 1525 ErrorStatus RTC_WakeUpCmd(FunctionalState NewState)
mbed_official 155:8435094ec241 1526 {
mbed_official 155:8435094ec241 1527 __IO uint32_t wutcounter = 0x00;
mbed_official 155:8435094ec241 1528 uint32_t wutwfstatus = 0x00;
mbed_official 155:8435094ec241 1529 ErrorStatus status = ERROR;
mbed_official 155:8435094ec241 1530
mbed_official 155:8435094ec241 1531 /* Check the parameters */
mbed_official 155:8435094ec241 1532 assert_param(IS_FUNCTIONAL_STATE(NewState));
mbed_official 155:8435094ec241 1533
mbed_official 155:8435094ec241 1534 /* Disable the write protection for RTC registers */
mbed_official 155:8435094ec241 1535 RTC->WPR = 0xCA;
mbed_official 155:8435094ec241 1536 RTC->WPR = 0x53;
mbed_official 155:8435094ec241 1537
mbed_official 155:8435094ec241 1538 if (NewState != DISABLE)
mbed_official 155:8435094ec241 1539 {
mbed_official 155:8435094ec241 1540 /* Enable the Wakeup Timer */
mbed_official 155:8435094ec241 1541 RTC->CR |= (uint32_t)RTC_CR_WUTE;
mbed_official 155:8435094ec241 1542 status = SUCCESS;
mbed_official 155:8435094ec241 1543 }
mbed_official 155:8435094ec241 1544 else
mbed_official 155:8435094ec241 1545 {
mbed_official 155:8435094ec241 1546 /* Disable the Wakeup Timer */
mbed_official 155:8435094ec241 1547 RTC->CR &= (uint32_t)~RTC_CR_WUTE;
mbed_official 155:8435094ec241 1548 /* Wait till RTC WUTWF flag is set and if Time out is reached exit */
mbed_official 155:8435094ec241 1549 do
mbed_official 155:8435094ec241 1550 {
mbed_official 155:8435094ec241 1551 wutwfstatus = RTC->ISR & RTC_ISR_WUTWF;
mbed_official 155:8435094ec241 1552 wutcounter++;
mbed_official 155:8435094ec241 1553 } while((wutcounter != INITMODE_TIMEOUT) && (wutwfstatus == 0x00));
mbed_official 155:8435094ec241 1554
mbed_official 155:8435094ec241 1555 if ((RTC->ISR & RTC_ISR_WUTWF) == RESET)
mbed_official 155:8435094ec241 1556 {
mbed_official 155:8435094ec241 1557 status = ERROR;
mbed_official 155:8435094ec241 1558 }
mbed_official 155:8435094ec241 1559 else
mbed_official 155:8435094ec241 1560 {
mbed_official 155:8435094ec241 1561 status = SUCCESS;
mbed_official 155:8435094ec241 1562 }
mbed_official 155:8435094ec241 1563 }
mbed_official 155:8435094ec241 1564
mbed_official 155:8435094ec241 1565 /* Enable the write protection for RTC registers */
mbed_official 155:8435094ec241 1566 RTC->WPR = 0xFF;
mbed_official 155:8435094ec241 1567
mbed_official 155:8435094ec241 1568 return status;
mbed_official 155:8435094ec241 1569 }
mbed_official 155:8435094ec241 1570
mbed_official 155:8435094ec241 1571 /**
mbed_official 155:8435094ec241 1572 * @}
mbed_official 155:8435094ec241 1573 */
mbed_official 155:8435094ec241 1574
mbed_official 155:8435094ec241 1575 /** @defgroup RTC_Group5 Daylight Saving configuration functions
mbed_official 155:8435094ec241 1576 * @brief Daylight Saving configuration functions
mbed_official 155:8435094ec241 1577 *
mbed_official 155:8435094ec241 1578 @verbatim
mbed_official 155:8435094ec241 1579 ===============================================================================
mbed_official 155:8435094ec241 1580 ##### Daylight Saving configuration functions #####
mbed_official 155:8435094ec241 1581 ===============================================================================
mbed_official 155:8435094ec241 1582 [..] This section provide functions allowing to configure the RTC DayLight Saving.
mbed_official 155:8435094ec241 1583
mbed_official 155:8435094ec241 1584 @endverbatim
mbed_official 155:8435094ec241 1585 * @{
mbed_official 155:8435094ec241 1586 */
mbed_official 155:8435094ec241 1587
mbed_official 155:8435094ec241 1588 /**
mbed_official 155:8435094ec241 1589 * @brief Adds or substract one hour from the current time.
mbed_official 155:8435094ec241 1590 * @param RTC_DayLightSaveOperation: the value of hour adjustment.
mbed_official 155:8435094ec241 1591 * This parameter can be one of the following values:
mbed_official 155:8435094ec241 1592 * @arg RTC_DayLightSaving_SUB1H: Substract one hour (winter time)
mbed_official 155:8435094ec241 1593 * @arg RTC_DayLightSaving_ADD1H: Add one hour (summer time)
mbed_official 155:8435094ec241 1594 * @param RTC_StoreOperation: Specifies the value to be written in the BCK bit
mbed_official 155:8435094ec241 1595 * in CR register to store the operation.
mbed_official 155:8435094ec241 1596 * This parameter can be one of the following values:
mbed_official 155:8435094ec241 1597 * @arg RTC_StoreOperation_Reset: BCK Bit Reset
mbed_official 155:8435094ec241 1598 * @arg RTC_StoreOperation_Set: BCK Bit Set
mbed_official 155:8435094ec241 1599 * @retval None
mbed_official 155:8435094ec241 1600 */
mbed_official 155:8435094ec241 1601 void RTC_DayLightSavingConfig(uint32_t RTC_DayLightSaving, uint32_t RTC_StoreOperation)
mbed_official 155:8435094ec241 1602 {
mbed_official 155:8435094ec241 1603 /* Check the parameters */
mbed_official 155:8435094ec241 1604 assert_param(IS_RTC_DAYLIGHT_SAVING(RTC_DayLightSaving));
mbed_official 155:8435094ec241 1605 assert_param(IS_RTC_STORE_OPERATION(RTC_StoreOperation));
mbed_official 155:8435094ec241 1606
mbed_official 155:8435094ec241 1607 /* Disable the write protection for RTC registers */
mbed_official 155:8435094ec241 1608 RTC->WPR = 0xCA;
mbed_official 155:8435094ec241 1609 RTC->WPR = 0x53;
mbed_official 155:8435094ec241 1610
mbed_official 155:8435094ec241 1611 /* Clear the bits to be configured */
mbed_official 155:8435094ec241 1612 RTC->CR &= (uint32_t)~(RTC_CR_BCK);
mbed_official 155:8435094ec241 1613
mbed_official 155:8435094ec241 1614 /* Configure the RTC_CR register */
mbed_official 155:8435094ec241 1615 RTC->CR |= (uint32_t)(RTC_DayLightSaving | RTC_StoreOperation);
mbed_official 155:8435094ec241 1616
mbed_official 155:8435094ec241 1617 /* Enable the write protection for RTC registers */
mbed_official 155:8435094ec241 1618 RTC->WPR = 0xFF;
mbed_official 155:8435094ec241 1619 }
mbed_official 155:8435094ec241 1620
mbed_official 155:8435094ec241 1621 /**
mbed_official 155:8435094ec241 1622 * @brief Returns the RTC Day Light Saving stored operation.
mbed_official 155:8435094ec241 1623 * @param None
mbed_official 155:8435094ec241 1624 * @retval RTC Day Light Saving stored operation.
mbed_official 155:8435094ec241 1625 * - RTC_StoreOperation_Reset
mbed_official 155:8435094ec241 1626 * - RTC_StoreOperation_Set
mbed_official 155:8435094ec241 1627 */
mbed_official 155:8435094ec241 1628 uint32_t RTC_GetStoreOperation(void)
mbed_official 155:8435094ec241 1629 {
mbed_official 155:8435094ec241 1630 return (RTC->CR & RTC_CR_BCK);
mbed_official 155:8435094ec241 1631 }
mbed_official 155:8435094ec241 1632
mbed_official 155:8435094ec241 1633 /**
mbed_official 155:8435094ec241 1634 * @}
mbed_official 155:8435094ec241 1635 */
mbed_official 155:8435094ec241 1636
mbed_official 155:8435094ec241 1637 /** @defgroup RTC_Group6 Output pin Configuration function
mbed_official 155:8435094ec241 1638 * @brief Output pin Configuration function
mbed_official 155:8435094ec241 1639 *
mbed_official 155:8435094ec241 1640 @verbatim
mbed_official 155:8435094ec241 1641 ===============================================================================
mbed_official 155:8435094ec241 1642 ##### Output pin Configuration function #####
mbed_official 155:8435094ec241 1643 ===============================================================================
mbed_official 155:8435094ec241 1644 [..] This section provide functions allowing to configure the RTC Output source.
mbed_official 155:8435094ec241 1645
mbed_official 155:8435094ec241 1646 @endverbatim
mbed_official 155:8435094ec241 1647 * @{
mbed_official 155:8435094ec241 1648 */
mbed_official 155:8435094ec241 1649
mbed_official 155:8435094ec241 1650 /**
mbed_official 155:8435094ec241 1651 * @brief Configures the RTC output source (AFO_ALARM).
mbed_official 155:8435094ec241 1652 * @param RTC_Output: Specifies which signal will be routed to the RTC output.
mbed_official 155:8435094ec241 1653 * This parameter can be one of the following values:
mbed_official 155:8435094ec241 1654 * @arg RTC_Output_Disable: No output selected
mbed_official 155:8435094ec241 1655 * @arg RTC_Output_AlarmA: signal of AlarmA mapped to output
mbed_official 155:8435094ec241 1656 * @arg RTC_Output_AlarmB: signal of AlarmB mapped to output
mbed_official 155:8435094ec241 1657 * @arg RTC_Output_WakeUp: signal of WakeUp mapped to output
mbed_official 155:8435094ec241 1658 * @param RTC_OutputPolarity: Specifies the polarity of the output signal.
mbed_official 155:8435094ec241 1659 * This parameter can be one of the following:
mbed_official 155:8435094ec241 1660 * @arg RTC_OutputPolarity_High: The output pin is high when the
mbed_official 155:8435094ec241 1661 * ALRAF/ALRBF/WUTF is high (depending on OSEL)
mbed_official 155:8435094ec241 1662 * @arg RTC_OutputPolarity_Low: The output pin is low when the
mbed_official 155:8435094ec241 1663 * ALRAF/ALRBF/WUTF is high (depending on OSEL)
mbed_official 155:8435094ec241 1664 * @retval None
mbed_official 155:8435094ec241 1665 */
mbed_official 155:8435094ec241 1666 void RTC_OutputConfig(uint32_t RTC_Output, uint32_t RTC_OutputPolarity)
mbed_official 155:8435094ec241 1667 {
mbed_official 155:8435094ec241 1668 /* Check the parameters */
mbed_official 155:8435094ec241 1669 assert_param(IS_RTC_OUTPUT(RTC_Output));
mbed_official 155:8435094ec241 1670 assert_param(IS_RTC_OUTPUT_POL(RTC_OutputPolarity));
mbed_official 155:8435094ec241 1671
mbed_official 155:8435094ec241 1672 /* Disable the write protection for RTC registers */
mbed_official 155:8435094ec241 1673 RTC->WPR = 0xCA;
mbed_official 155:8435094ec241 1674 RTC->WPR = 0x53;
mbed_official 155:8435094ec241 1675
mbed_official 155:8435094ec241 1676 /* Clear the bits to be configured */
mbed_official 155:8435094ec241 1677 RTC->CR &= (uint32_t)~(RTC_CR_OSEL | RTC_CR_POL);
mbed_official 155:8435094ec241 1678
mbed_official 155:8435094ec241 1679 /* Configure the output selection and polarity */
mbed_official 155:8435094ec241 1680 RTC->CR |= (uint32_t)(RTC_Output | RTC_OutputPolarity);
mbed_official 155:8435094ec241 1681
mbed_official 155:8435094ec241 1682 /* Enable the write protection for RTC registers */
mbed_official 155:8435094ec241 1683 RTC->WPR = 0xFF;
mbed_official 155:8435094ec241 1684 }
mbed_official 155:8435094ec241 1685
mbed_official 155:8435094ec241 1686 /**
mbed_official 155:8435094ec241 1687 * @}
mbed_official 155:8435094ec241 1688 */
mbed_official 155:8435094ec241 1689
mbed_official 155:8435094ec241 1690 /** @defgroup RTC_Group7 Digital Calibration configuration functions
mbed_official 155:8435094ec241 1691 * @brief Digital Calibration configuration functions
mbed_official 155:8435094ec241 1692 *
mbed_official 155:8435094ec241 1693 @verbatim
mbed_official 155:8435094ec241 1694 ===============================================================================
mbed_official 155:8435094ec241 1695 ##### Digital Calibration configuration functions #####
mbed_official 155:8435094ec241 1696 ===============================================================================
mbed_official 155:8435094ec241 1697
mbed_official 155:8435094ec241 1698 @endverbatim
mbed_official 155:8435094ec241 1699 * @{
mbed_official 155:8435094ec241 1700 */
mbed_official 155:8435094ec241 1701
mbed_official 155:8435094ec241 1702 /**
mbed_official 155:8435094ec241 1703 * @brief Enables or disables the RTC clock to be output through the relative
mbed_official 155:8435094ec241 1704 * pin.
mbed_official 155:8435094ec241 1705 * @param NewState: new state of the digital calibration Output.
mbed_official 155:8435094ec241 1706 * This parameter can be: ENABLE or DISABLE.
mbed_official 155:8435094ec241 1707 * @retval None
mbed_official 155:8435094ec241 1708 */
mbed_official 155:8435094ec241 1709 void RTC_CalibOutputCmd(FunctionalState NewState)
mbed_official 155:8435094ec241 1710 {
mbed_official 155:8435094ec241 1711 /* Check the parameters */
mbed_official 155:8435094ec241 1712 assert_param(IS_FUNCTIONAL_STATE(NewState));
mbed_official 155:8435094ec241 1713
mbed_official 155:8435094ec241 1714 /* Disable the write protection for RTC registers */
mbed_official 155:8435094ec241 1715 RTC->WPR = 0xCA;
mbed_official 155:8435094ec241 1716 RTC->WPR = 0x53;
mbed_official 155:8435094ec241 1717
mbed_official 155:8435094ec241 1718 if (NewState != DISABLE)
mbed_official 155:8435094ec241 1719 {
mbed_official 155:8435094ec241 1720 /* Enable the RTC clock output */
mbed_official 155:8435094ec241 1721 RTC->CR |= (uint32_t)RTC_CR_COE;
mbed_official 155:8435094ec241 1722 }
mbed_official 155:8435094ec241 1723 else
mbed_official 155:8435094ec241 1724 {
mbed_official 155:8435094ec241 1725 /* Disable the RTC clock output */
mbed_official 155:8435094ec241 1726 RTC->CR &= (uint32_t)~RTC_CR_COE;
mbed_official 155:8435094ec241 1727 }
mbed_official 155:8435094ec241 1728
mbed_official 155:8435094ec241 1729 /* Enable the write protection for RTC registers */
mbed_official 155:8435094ec241 1730 RTC->WPR = 0xFF;
mbed_official 155:8435094ec241 1731 }
mbed_official 155:8435094ec241 1732
mbed_official 155:8435094ec241 1733 /**
mbed_official 155:8435094ec241 1734 * @brief Configures the Calibration Pinout (RTC_CALIB) Selection (1Hz or 512Hz).
mbed_official 155:8435094ec241 1735 * @param RTC_CalibOutput : Select the Calibration output Selection .
mbed_official 155:8435094ec241 1736 * This parameter can be one of the following values:
mbed_official 155:8435094ec241 1737 * @arg RTC_CalibOutput_512Hz: A signal has a regular waveform at 512Hz.
mbed_official 155:8435094ec241 1738 * @arg RTC_CalibOutput_1Hz : A signal has a regular waveform at 1Hz.
mbed_official 155:8435094ec241 1739 * @retval None
mbed_official 155:8435094ec241 1740 */
mbed_official 155:8435094ec241 1741 void RTC_CalibOutputConfig(uint32_t RTC_CalibOutput)
mbed_official 155:8435094ec241 1742 {
mbed_official 155:8435094ec241 1743 /* Check the parameters */
mbed_official 155:8435094ec241 1744 assert_param(IS_RTC_CALIB_OUTPUT(RTC_CalibOutput));
mbed_official 155:8435094ec241 1745
mbed_official 155:8435094ec241 1746 /* Disable the write protection for RTC registers */
mbed_official 155:8435094ec241 1747 RTC->WPR = 0xCA;
mbed_official 155:8435094ec241 1748 RTC->WPR = 0x53;
mbed_official 155:8435094ec241 1749
mbed_official 155:8435094ec241 1750 /*clear flags before config*/
mbed_official 155:8435094ec241 1751 RTC->CR &= (uint32_t)~(RTC_CR_COSEL);
mbed_official 155:8435094ec241 1752
mbed_official 155:8435094ec241 1753 /* Configure the RTC_CR register */
mbed_official 155:8435094ec241 1754 RTC->CR |= (uint32_t)RTC_CalibOutput;
mbed_official 155:8435094ec241 1755
mbed_official 155:8435094ec241 1756 /* Enable the write protection for RTC registers */
mbed_official 155:8435094ec241 1757 RTC->WPR = 0xFF;
mbed_official 155:8435094ec241 1758 }
mbed_official 155:8435094ec241 1759
mbed_official 155:8435094ec241 1760 /**
mbed_official 155:8435094ec241 1761 * @brief Configures the Smooth Calibration Settings.
mbed_official 155:8435094ec241 1762 * @param RTC_SmoothCalibPeriod : Select the Smooth Calibration Period.
mbed_official 155:8435094ec241 1763 * This parameter can be can be one of the following values:
mbed_official 155:8435094ec241 1764 * @arg RTC_SmoothCalibPeriod_32sec : The smooth calibration periode is 32s.
mbed_official 155:8435094ec241 1765 * @arg RTC_SmoothCalibPeriod_16sec : The smooth calibration periode is 16s.
mbed_official 155:8435094ec241 1766 * @arg RTC_SmoothCalibPeriod_8sec : The smooth calibartion periode is 8s.
mbed_official 155:8435094ec241 1767 * @param RTC_SmoothCalibPlusPulses : Select to Set or reset the CALP bit.
mbed_official 155:8435094ec241 1768 * This parameter can be one of the following values:
mbed_official 155:8435094ec241 1769 * @arg RTC_SmoothCalibPlusPulses_Set : Add one RTCCLK puls every 2**11 pulses.
mbed_official 155:8435094ec241 1770 * @arg RTC_SmoothCalibPlusPulses_Reset: No RTCCLK pulses are added.
mbed_official 155:8435094ec241 1771 * @param RTC_SmouthCalibMinusPulsesValue: Select the value of CALM[8:0] bits.
mbed_official 155:8435094ec241 1772 * This parameter can be one any value from 0 to 0x000001FF.
mbed_official 155:8435094ec241 1773 * @retval An ErrorStatus enumeration value:
mbed_official 155:8435094ec241 1774 * - SUCCESS: RTC Calib registers are configured
mbed_official 155:8435094ec241 1775 * - ERROR: RTC Calib registers are not configured
mbed_official 155:8435094ec241 1776 */
mbed_official 155:8435094ec241 1777 ErrorStatus RTC_SmoothCalibConfig(uint32_t RTC_SmoothCalibPeriod,
mbed_official 155:8435094ec241 1778 uint32_t RTC_SmoothCalibPlusPulses,
mbed_official 155:8435094ec241 1779 uint32_t RTC_SmouthCalibMinusPulsesValue)
mbed_official 155:8435094ec241 1780 {
mbed_official 155:8435094ec241 1781 ErrorStatus status = ERROR;
mbed_official 155:8435094ec241 1782 uint32_t recalpfcount = 0;
mbed_official 155:8435094ec241 1783
mbed_official 155:8435094ec241 1784 /* Check the parameters */
mbed_official 155:8435094ec241 1785 assert_param(IS_RTC_SMOOTH_CALIB_PERIOD(RTC_SmoothCalibPeriod));
mbed_official 155:8435094ec241 1786 assert_param(IS_RTC_SMOOTH_CALIB_PLUS(RTC_SmoothCalibPlusPulses));
mbed_official 155:8435094ec241 1787 assert_param(IS_RTC_SMOOTH_CALIB_MINUS(RTC_SmouthCalibMinusPulsesValue));
mbed_official 155:8435094ec241 1788
mbed_official 155:8435094ec241 1789 /* Disable the write protection for RTC registers */
mbed_official 155:8435094ec241 1790 RTC->WPR = 0xCA;
mbed_official 155:8435094ec241 1791 RTC->WPR = 0x53;
mbed_official 155:8435094ec241 1792
mbed_official 155:8435094ec241 1793 /* check if a calibration is pending*/
mbed_official 155:8435094ec241 1794 if ((RTC->ISR & RTC_ISR_RECALPF) != RESET)
mbed_official 155:8435094ec241 1795 {
mbed_official 155:8435094ec241 1796 /* wait until the Calibration is completed*/
mbed_official 155:8435094ec241 1797 while (((RTC->ISR & RTC_ISR_RECALPF) != RESET) && (recalpfcount != RECALPF_TIMEOUT))
mbed_official 155:8435094ec241 1798 {
mbed_official 155:8435094ec241 1799 recalpfcount++;
mbed_official 155:8435094ec241 1800 }
mbed_official 155:8435094ec241 1801 }
mbed_official 155:8435094ec241 1802
mbed_official 155:8435094ec241 1803 /* check if the calibration pending is completed or if there is no calibration operation at all*/
mbed_official 155:8435094ec241 1804 if ((RTC->ISR & RTC_ISR_RECALPF) == RESET)
mbed_official 155:8435094ec241 1805 {
mbed_official 155:8435094ec241 1806 /* Configure the Smooth calibration settings */
mbed_official 155:8435094ec241 1807 RTC->CALR = (uint32_t)((uint32_t)RTC_SmoothCalibPeriod | (uint32_t)RTC_SmoothCalibPlusPulses | (uint32_t)RTC_SmouthCalibMinusPulsesValue);
mbed_official 155:8435094ec241 1808
mbed_official 155:8435094ec241 1809 status = SUCCESS;
mbed_official 155:8435094ec241 1810 }
mbed_official 155:8435094ec241 1811 else
mbed_official 155:8435094ec241 1812 {
mbed_official 155:8435094ec241 1813 status = ERROR;
mbed_official 155:8435094ec241 1814 }
mbed_official 155:8435094ec241 1815
mbed_official 155:8435094ec241 1816 /* Enable the write protection for RTC registers */
mbed_official 155:8435094ec241 1817 RTC->WPR = 0xFF;
mbed_official 155:8435094ec241 1818
mbed_official 155:8435094ec241 1819 return (ErrorStatus)(status);
mbed_official 155:8435094ec241 1820 }
mbed_official 155:8435094ec241 1821
mbed_official 155:8435094ec241 1822 /**
mbed_official 155:8435094ec241 1823 * @}
mbed_official 155:8435094ec241 1824 */
mbed_official 155:8435094ec241 1825
mbed_official 155:8435094ec241 1826
mbed_official 155:8435094ec241 1827 /** @defgroup RTC_Group8 TimeStamp configuration functions
mbed_official 155:8435094ec241 1828 * @brief TimeStamp configuration functions
mbed_official 155:8435094ec241 1829 *
mbed_official 155:8435094ec241 1830 @verbatim
mbed_official 155:8435094ec241 1831 ===============================================================================
mbed_official 155:8435094ec241 1832 ##### TimeStamp configuration functions #####
mbed_official 155:8435094ec241 1833 ===============================================================================
mbed_official 155:8435094ec241 1834
mbed_official 155:8435094ec241 1835 @endverbatim
mbed_official 155:8435094ec241 1836 * @{
mbed_official 155:8435094ec241 1837 */
mbed_official 155:8435094ec241 1838
mbed_official 155:8435094ec241 1839 /**
mbed_official 155:8435094ec241 1840 * @brief Enables or Disables the RTC TimeStamp functionality with the
mbed_official 155:8435094ec241 1841 * specified time stamp pin stimulating edge.
mbed_official 155:8435094ec241 1842 * @param RTC_TimeStampEdge: Specifies the pin edge on which the TimeStamp is
mbed_official 155:8435094ec241 1843 * activated.
mbed_official 155:8435094ec241 1844 * This parameter can be one of the following:
mbed_official 155:8435094ec241 1845 * @arg RTC_TimeStampEdge_Rising: the Time stamp event occurs on the rising
mbed_official 155:8435094ec241 1846 * edge of the related pin.
mbed_official 155:8435094ec241 1847 * @arg RTC_TimeStampEdge_Falling: the Time stamp event occurs on the
mbed_official 155:8435094ec241 1848 * falling edge of the related pin.
mbed_official 155:8435094ec241 1849 * @param NewState: new state of the TimeStamp.
mbed_official 155:8435094ec241 1850 * This parameter can be: ENABLE or DISABLE.
mbed_official 155:8435094ec241 1851 * @retval None
mbed_official 155:8435094ec241 1852 */
mbed_official 155:8435094ec241 1853 void RTC_TimeStampCmd(uint32_t RTC_TimeStampEdge, FunctionalState NewState)
mbed_official 155:8435094ec241 1854 {
mbed_official 155:8435094ec241 1855 uint32_t tmpreg = 0;
mbed_official 155:8435094ec241 1856
mbed_official 155:8435094ec241 1857 /* Check the parameters */
mbed_official 155:8435094ec241 1858 assert_param(IS_RTC_TIMESTAMP_EDGE(RTC_TimeStampEdge));
mbed_official 155:8435094ec241 1859 assert_param(IS_FUNCTIONAL_STATE(NewState));
mbed_official 155:8435094ec241 1860
mbed_official 155:8435094ec241 1861 /* Get the RTC_CR register and clear the bits to be configured */
mbed_official 155:8435094ec241 1862 tmpreg = (uint32_t)(RTC->CR & (uint32_t)~(RTC_CR_TSEDGE | RTC_CR_TSE));
mbed_official 155:8435094ec241 1863
mbed_official 155:8435094ec241 1864 /* Get the new configuration */
mbed_official 155:8435094ec241 1865 if (NewState != DISABLE)
mbed_official 155:8435094ec241 1866 {
mbed_official 155:8435094ec241 1867 tmpreg |= (uint32_t)(RTC_TimeStampEdge | RTC_CR_TSE);
mbed_official 155:8435094ec241 1868 }
mbed_official 155:8435094ec241 1869 else
mbed_official 155:8435094ec241 1870 {
mbed_official 155:8435094ec241 1871 tmpreg |= (uint32_t)(RTC_TimeStampEdge);
mbed_official 155:8435094ec241 1872 }
mbed_official 155:8435094ec241 1873
mbed_official 155:8435094ec241 1874 /* Disable the write protection for RTC registers */
mbed_official 155:8435094ec241 1875 RTC->WPR = 0xCA;
mbed_official 155:8435094ec241 1876 RTC->WPR = 0x53;
mbed_official 155:8435094ec241 1877
mbed_official 155:8435094ec241 1878 /* Configure the Time Stamp TSEDGE and Enable bits */
mbed_official 155:8435094ec241 1879 RTC->CR = (uint32_t)tmpreg;
mbed_official 155:8435094ec241 1880
mbed_official 155:8435094ec241 1881 /* Enable the write protection for RTC registers */
mbed_official 155:8435094ec241 1882 RTC->WPR = 0xFF;
mbed_official 155:8435094ec241 1883 }
mbed_official 155:8435094ec241 1884
mbed_official 155:8435094ec241 1885 /**
mbed_official 155:8435094ec241 1886 * @brief Gets the RTC TimeStamp value and masks.
mbed_official 155:8435094ec241 1887 * @param RTC_Format: specifies the format of the output parameters.
mbed_official 155:8435094ec241 1888 * This parameter can be one of the following values:
mbed_official 155:8435094ec241 1889 * @arg RTC_Format_BIN: Binary data format
mbed_official 155:8435094ec241 1890 * @arg RTC_Format_BCD: BCD data format
mbed_official 155:8435094ec241 1891 * @param RTC_StampTimeStruct: pointer to a RTC_TimeTypeDef structure that will
mbed_official 155:8435094ec241 1892 * contains the TimeStamp time values.
mbed_official 155:8435094ec241 1893 * @param RTC_StampDateStruct: pointer to a RTC_DateTypeDef structure that will
mbed_official 155:8435094ec241 1894 * contains the TimeStamp date values.
mbed_official 155:8435094ec241 1895 * @retval None
mbed_official 155:8435094ec241 1896 */
mbed_official 155:8435094ec241 1897 void RTC_GetTimeStamp(uint32_t RTC_Format, RTC_TimeTypeDef* RTC_StampTimeStruct,
mbed_official 155:8435094ec241 1898 RTC_DateTypeDef* RTC_StampDateStruct)
mbed_official 155:8435094ec241 1899 {
mbed_official 155:8435094ec241 1900 uint32_t tmptime = 0, tmpdate = 0;
mbed_official 155:8435094ec241 1901
mbed_official 155:8435094ec241 1902 /* Check the parameters */
mbed_official 155:8435094ec241 1903 assert_param(IS_RTC_FORMAT(RTC_Format));
mbed_official 155:8435094ec241 1904
mbed_official 155:8435094ec241 1905 /* Get the TimeStamp time and date registers values */
mbed_official 155:8435094ec241 1906 tmptime = (uint32_t)(RTC->TSTR & RTC_TR_RESERVED_MASK);
mbed_official 155:8435094ec241 1907 tmpdate = (uint32_t)(RTC->TSDR & RTC_DR_RESERVED_MASK);
mbed_official 155:8435094ec241 1908
mbed_official 155:8435094ec241 1909 /* Fill the Time structure fields with the read parameters */
mbed_official 155:8435094ec241 1910 RTC_StampTimeStruct->RTC_Hours = (uint8_t)((tmptime & (RTC_TR_HT | RTC_TR_HU)) >> 16);
mbed_official 155:8435094ec241 1911 RTC_StampTimeStruct->RTC_Minutes = (uint8_t)((tmptime & (RTC_TR_MNT | RTC_TR_MNU)) >> 8);
mbed_official 155:8435094ec241 1912 RTC_StampTimeStruct->RTC_Seconds = (uint8_t)(tmptime & (RTC_TR_ST | RTC_TR_SU));
mbed_official 155:8435094ec241 1913 RTC_StampTimeStruct->RTC_H12 = (uint8_t)((tmptime & (RTC_TR_PM)) >> 16);
mbed_official 155:8435094ec241 1914
mbed_official 155:8435094ec241 1915 /* Fill the Date structure fields with the read parameters */
mbed_official 155:8435094ec241 1916 RTC_StampDateStruct->RTC_Year = 0;
mbed_official 155:8435094ec241 1917 RTC_StampDateStruct->RTC_Month = (uint8_t)((tmpdate & (RTC_DR_MT | RTC_DR_MU)) >> 8);
mbed_official 155:8435094ec241 1918 RTC_StampDateStruct->RTC_Date = (uint8_t)(tmpdate & (RTC_DR_DT | RTC_DR_DU));
mbed_official 155:8435094ec241 1919 RTC_StampDateStruct->RTC_WeekDay = (uint8_t)((tmpdate & (RTC_DR_WDU)) >> 13);
mbed_official 155:8435094ec241 1920
mbed_official 155:8435094ec241 1921 /* Check the input parameters format */
mbed_official 155:8435094ec241 1922 if (RTC_Format == RTC_Format_BIN)
mbed_official 155:8435094ec241 1923 {
mbed_official 155:8435094ec241 1924 /* Convert the Time structure parameters to Binary format */
mbed_official 155:8435094ec241 1925 RTC_StampTimeStruct->RTC_Hours = (uint8_t)RTC_Bcd2ToByte(RTC_StampTimeStruct->RTC_Hours);
mbed_official 155:8435094ec241 1926 RTC_StampTimeStruct->RTC_Minutes = (uint8_t)RTC_Bcd2ToByte(RTC_StampTimeStruct->RTC_Minutes);
mbed_official 155:8435094ec241 1927 RTC_StampTimeStruct->RTC_Seconds = (uint8_t)RTC_Bcd2ToByte(RTC_StampTimeStruct->RTC_Seconds);
mbed_official 155:8435094ec241 1928
mbed_official 155:8435094ec241 1929 /* Convert the Date structure parameters to Binary format */
mbed_official 155:8435094ec241 1930 RTC_StampDateStruct->RTC_Month = (uint8_t)RTC_Bcd2ToByte(RTC_StampDateStruct->RTC_Month);
mbed_official 155:8435094ec241 1931 RTC_StampDateStruct->RTC_Date = (uint8_t)RTC_Bcd2ToByte(RTC_StampDateStruct->RTC_Date);
mbed_official 155:8435094ec241 1932 RTC_StampDateStruct->RTC_WeekDay = (uint8_t)RTC_Bcd2ToByte(RTC_StampDateStruct->RTC_WeekDay);
mbed_official 155:8435094ec241 1933 }
mbed_official 155:8435094ec241 1934 }
mbed_official 155:8435094ec241 1935
mbed_official 155:8435094ec241 1936 /**
mbed_official 155:8435094ec241 1937 * @brief Gets the RTC timestamp Subseconds value.
mbed_official 155:8435094ec241 1938 * @param None
mbed_official 155:8435094ec241 1939 * @retval RTC current timestamp Subseconds value.
mbed_official 155:8435094ec241 1940 */
mbed_official 155:8435094ec241 1941 uint32_t RTC_GetTimeStampSubSecond(void)
mbed_official 155:8435094ec241 1942 {
mbed_official 155:8435094ec241 1943 /* Get timestamp subseconds values from the correspondent registers */
mbed_official 155:8435094ec241 1944 return (uint32_t)(RTC->TSSSR);
mbed_official 155:8435094ec241 1945 }
mbed_official 155:8435094ec241 1946
mbed_official 155:8435094ec241 1947 /**
mbed_official 155:8435094ec241 1948 * @}
mbed_official 155:8435094ec241 1949 */
mbed_official 155:8435094ec241 1950
mbed_official 155:8435094ec241 1951 /** @defgroup RTC_Group9 Tampers configuration functions
mbed_official 155:8435094ec241 1952 * @brief Tampers configuration functions
mbed_official 155:8435094ec241 1953 *
mbed_official 155:8435094ec241 1954 @verbatim
mbed_official 155:8435094ec241 1955 ===============================================================================
mbed_official 155:8435094ec241 1956 ##### Tampers configuration functions #####
mbed_official 155:8435094ec241 1957 ===============================================================================
mbed_official 155:8435094ec241 1958
mbed_official 155:8435094ec241 1959 @endverbatim
mbed_official 155:8435094ec241 1960 * @{
mbed_official 155:8435094ec241 1961 */
mbed_official 155:8435094ec241 1962
mbed_official 155:8435094ec241 1963 /**
mbed_official 155:8435094ec241 1964 * @brief Configures the select Tamper pin edge.
mbed_official 155:8435094ec241 1965 * @param RTC_Tamper: Selected tamper pin.
mbed_official 155:8435094ec241 1966 * This parameter can be any combination of the following values:
mbed_official 155:8435094ec241 1967 * @arg RTC_Tamper_1: Select Tamper 1.
mbed_official 155:8435094ec241 1968 * @arg RTC_Tamper_2: Select Tamper 2.
mbed_official 155:8435094ec241 1969 * @arg RTC_Tamper_3: Select Tamper 3.
mbed_official 155:8435094ec241 1970 * @param RTC_TamperTrigger: Specifies the trigger on the tamper pin that
mbed_official 155:8435094ec241 1971 * stimulates tamper event.
mbed_official 155:8435094ec241 1972 * This parameter can be one of the following values:
mbed_official 155:8435094ec241 1973 * @arg RTC_TamperTrigger_RisingEdge: Rising Edge of the tamper pin causes tamper event.
mbed_official 155:8435094ec241 1974 * @arg RTC_TamperTrigger_FallingEdge: Falling Edge of the tamper pin causes tamper event.
mbed_official 155:8435094ec241 1975 * @arg RTC_TamperTrigger_LowLevel: Low Level of the tamper pin causes tamper event.
mbed_official 155:8435094ec241 1976 * @arg RTC_TamperTrigger_HighLevel: High Level of the tamper pin causes tamper event.
mbed_official 155:8435094ec241 1977 * @retval None
mbed_official 155:8435094ec241 1978 */
mbed_official 155:8435094ec241 1979 void RTC_TamperTriggerConfig(uint32_t RTC_Tamper, uint32_t RTC_TamperTrigger)
mbed_official 155:8435094ec241 1980 {
mbed_official 155:8435094ec241 1981 /* Check the parameters */
mbed_official 155:8435094ec241 1982 assert_param(IS_RTC_TAMPER(RTC_Tamper));
mbed_official 155:8435094ec241 1983 assert_param(IS_RTC_TAMPER_TRIGGER(RTC_TamperTrigger));
mbed_official 155:8435094ec241 1984
mbed_official 155:8435094ec241 1985 /* Check if the active level for Tamper is rising edge (Low level)*/
mbed_official 155:8435094ec241 1986 if (RTC_TamperTrigger == RTC_TamperTrigger_RisingEdge)
mbed_official 155:8435094ec241 1987 {
mbed_official 155:8435094ec241 1988 /* Configure the RTC_TAFCR register */
mbed_official 155:8435094ec241 1989 RTC->TAFCR &= (uint32_t)((uint32_t)~(RTC_Tamper << 1));
mbed_official 155:8435094ec241 1990 }
mbed_official 155:8435094ec241 1991 else
mbed_official 155:8435094ec241 1992 {
mbed_official 155:8435094ec241 1993 /* Configure the RTC_TAFCR register */
mbed_official 155:8435094ec241 1994 RTC->TAFCR |= (uint32_t)(RTC_Tamper << 1);
mbed_official 155:8435094ec241 1995 }
mbed_official 155:8435094ec241 1996 }
mbed_official 155:8435094ec241 1997
mbed_official 155:8435094ec241 1998 /**
mbed_official 155:8435094ec241 1999 * @brief Enables or Disables the Tamper detection.
mbed_official 155:8435094ec241 2000 * @param RTC_Tamper: Selected tamper pin.
mbed_official 155:8435094ec241 2001 * This parameter can be any combination of the following values:
mbed_official 155:8435094ec241 2002 * @arg RTC_Tamper_1: Select Tamper 1.
mbed_official 155:8435094ec241 2003 * @arg RTC_Tamper_2: Select Tamper 2.
mbed_official 155:8435094ec241 2004 * @arg RTC_Tamper_3: Select Tamper 3.
mbed_official 155:8435094ec241 2005 * @param NewState: new state of the tamper pin.
mbed_official 155:8435094ec241 2006 * This parameter can be: ENABLE or DISABLE.
mbed_official 155:8435094ec241 2007 * @retval None
mbed_official 155:8435094ec241 2008 */
mbed_official 155:8435094ec241 2009 void RTC_TamperCmd(uint32_t RTC_Tamper, FunctionalState NewState)
mbed_official 155:8435094ec241 2010 {
mbed_official 155:8435094ec241 2011 /* Check the parameters */
mbed_official 155:8435094ec241 2012 assert_param(IS_RTC_TAMPER(RTC_Tamper));
mbed_official 155:8435094ec241 2013 assert_param(IS_FUNCTIONAL_STATE(NewState));
mbed_official 155:8435094ec241 2014
mbed_official 155:8435094ec241 2015 if (NewState != DISABLE)
mbed_official 155:8435094ec241 2016 {
mbed_official 155:8435094ec241 2017 /* Enable the selected Tamper pin */
mbed_official 155:8435094ec241 2018 RTC->TAFCR |= (uint32_t)RTC_Tamper;
mbed_official 155:8435094ec241 2019 }
mbed_official 155:8435094ec241 2020 else
mbed_official 155:8435094ec241 2021 {
mbed_official 155:8435094ec241 2022 /* Disable the selected Tamper pin */
mbed_official 155:8435094ec241 2023 RTC->TAFCR &= (uint32_t)~RTC_Tamper;
mbed_official 155:8435094ec241 2024 }
mbed_official 155:8435094ec241 2025 }
mbed_official 155:8435094ec241 2026
mbed_official 155:8435094ec241 2027 /**
mbed_official 155:8435094ec241 2028 * @brief Configures the Tampers Filter.
mbed_official 155:8435094ec241 2029 * @param RTC_TamperFilter: Specifies the tampers filter.
mbed_official 155:8435094ec241 2030 * This parameter can be one of the following values:
mbed_official 155:8435094ec241 2031 * @arg RTC_TamperFilter_Disable: Tamper filter is disabled.
mbed_official 155:8435094ec241 2032 * @arg RTC_TamperFilter_2Sample: Tamper is activated after 2 consecutive
mbed_official 155:8435094ec241 2033 * samples at the active level
mbed_official 155:8435094ec241 2034 * @arg RTC_TamperFilter_4Sample: Tamper is activated after 4 consecutive
mbed_official 155:8435094ec241 2035 * samples at the active level
mbed_official 155:8435094ec241 2036 * @arg RTC_TamperFilter_8Sample: Tamper is activated after 8 consecutive
mbed_official 155:8435094ec241 2037 * samples at the active level
mbed_official 155:8435094ec241 2038 * @retval None
mbed_official 155:8435094ec241 2039 */
mbed_official 155:8435094ec241 2040 void RTC_TamperFilterConfig(uint32_t RTC_TamperFilter)
mbed_official 155:8435094ec241 2041 {
mbed_official 155:8435094ec241 2042 /* Check the parameters */
mbed_official 155:8435094ec241 2043 assert_param(IS_RTC_TAMPER_FILTER(RTC_TamperFilter));
mbed_official 155:8435094ec241 2044
mbed_official 155:8435094ec241 2045 /* Clear TAMPFLT[1:0] bits in the RTC_TAFCR register */
mbed_official 155:8435094ec241 2046 RTC->TAFCR &= (uint32_t)~(RTC_TAFCR_TAMPFLT);
mbed_official 155:8435094ec241 2047
mbed_official 155:8435094ec241 2048 /* Configure the RTC_TAFCR register */
mbed_official 155:8435094ec241 2049 RTC->TAFCR |= (uint32_t)RTC_TamperFilter;
mbed_official 155:8435094ec241 2050 }
mbed_official 155:8435094ec241 2051
mbed_official 155:8435094ec241 2052 /**
mbed_official 155:8435094ec241 2053 * @brief Configures the Tampers Sampling Frequency.
mbed_official 155:8435094ec241 2054 * @param RTC_TamperSamplingFreq: Specifies the tampers Sampling Frequency.
mbed_official 155:8435094ec241 2055 * This parameter can be one of the following values:
mbed_official 155:8435094ec241 2056 * @arg RTC_TamperSamplingFreq_RTCCLK_Div32768: Each of the tamper inputs are sampled
mbed_official 155:8435094ec241 2057 * with a frequency = RTCCLK / 32768
mbed_official 155:8435094ec241 2058 * @arg RTC_TamperSamplingFreq_RTCCLK_Div16384: Each of the tamper inputs are sampled
mbed_official 155:8435094ec241 2059 * with a frequency = RTCCLK / 16384
mbed_official 155:8435094ec241 2060 * @arg RTC_TamperSamplingFreq_RTCCLK_Div8192: Each of the tamper inputs are sampled
mbed_official 155:8435094ec241 2061 * with a frequency = RTCCLK / 8192
mbed_official 155:8435094ec241 2062 * @arg RTC_TamperSamplingFreq_RTCCLK_Div4096: Each of the tamper inputs are sampled
mbed_official 155:8435094ec241 2063 * with a frequency = RTCCLK / 4096
mbed_official 155:8435094ec241 2064 * @arg RTC_TamperSamplingFreq_RTCCLK_Div2048: Each of the tamper inputs are sampled
mbed_official 155:8435094ec241 2065 * with a frequency = RTCCLK / 2048
mbed_official 155:8435094ec241 2066 * @arg RTC_TamperSamplingFreq_RTCCLK_Div1024: Each of the tamper inputs are sampled
mbed_official 155:8435094ec241 2067 * with a frequency = RTCCLK / 1024
mbed_official 155:8435094ec241 2068 * @arg RTC_TamperSamplingFreq_RTCCLK_Div512: Each of the tamper inputs are sampled
mbed_official 155:8435094ec241 2069 * with a frequency = RTCCLK / 512
mbed_official 155:8435094ec241 2070 * @arg RTC_TamperSamplingFreq_RTCCLK_Div256: Each of the tamper inputs are sampled
mbed_official 155:8435094ec241 2071 * with a frequency = RTCCLK / 256
mbed_official 155:8435094ec241 2072 * @retval None
mbed_official 155:8435094ec241 2073 */
mbed_official 155:8435094ec241 2074 void RTC_TamperSamplingFreqConfig(uint32_t RTC_TamperSamplingFreq)
mbed_official 155:8435094ec241 2075 {
mbed_official 155:8435094ec241 2076 /* Check the parameters */
mbed_official 155:8435094ec241 2077 assert_param(IS_RTC_TAMPER_SAMPLING_FREQ(RTC_TamperSamplingFreq));
mbed_official 155:8435094ec241 2078
mbed_official 155:8435094ec241 2079 /* Clear TAMPFREQ[2:0] bits in the RTC_TAFCR register */
mbed_official 155:8435094ec241 2080 RTC->TAFCR &= (uint32_t)~(RTC_TAFCR_TAMPFREQ);
mbed_official 155:8435094ec241 2081
mbed_official 155:8435094ec241 2082 /* Configure the RTC_TAFCR register */
mbed_official 155:8435094ec241 2083 RTC->TAFCR |= (uint32_t)RTC_TamperSamplingFreq;
mbed_official 155:8435094ec241 2084 }
mbed_official 155:8435094ec241 2085
mbed_official 155:8435094ec241 2086 /**
mbed_official 155:8435094ec241 2087 * @brief Configures the Tampers Pins input Precharge Duration.
mbed_official 155:8435094ec241 2088 * @param RTC_TamperPrechargeDuration: Specifies the Tampers Pins input
mbed_official 155:8435094ec241 2089 * Precharge Duration.
mbed_official 155:8435094ec241 2090 * This parameter can be one of the following values:
mbed_official 155:8435094ec241 2091 * @arg RTC_TamperPrechargeDuration_1RTCCLK: Tamper pins are pre-charged before sampling during 1 RTCCLK cycle
mbed_official 155:8435094ec241 2092 * @arg RTC_TamperPrechargeDuration_2RTCCLK: Tamper pins are pre-charged before sampling during 2 RTCCLK cycle
mbed_official 155:8435094ec241 2093 * @arg RTC_TamperPrechargeDuration_4RTCCLK: Tamper pins are pre-charged before sampling during 4 RTCCLK cycle
mbed_official 155:8435094ec241 2094 * @arg RTC_TamperPrechargeDuration_8RTCCLK: Tamper pins are pre-charged before sampling during 8 RTCCLK cycle
mbed_official 155:8435094ec241 2095 * @retval None
mbed_official 155:8435094ec241 2096 */
mbed_official 155:8435094ec241 2097 void RTC_TamperPinsPrechargeDuration(uint32_t RTC_TamperPrechargeDuration)
mbed_official 155:8435094ec241 2098 {
mbed_official 155:8435094ec241 2099 /* Check the parameters */
mbed_official 155:8435094ec241 2100 assert_param(IS_RTC_TAMPER_PRECHARGE_DURATION(RTC_TamperPrechargeDuration));
mbed_official 155:8435094ec241 2101
mbed_official 155:8435094ec241 2102 /* Clear TAMPPRCH[1:0] bits in the RTC_TAFCR register */
mbed_official 155:8435094ec241 2103 RTC->TAFCR &= (uint32_t)~(RTC_TAFCR_TAMPPRCH);
mbed_official 155:8435094ec241 2104
mbed_official 155:8435094ec241 2105 /* Configure the RTC_TAFCR register */
mbed_official 155:8435094ec241 2106 RTC->TAFCR |= (uint32_t)RTC_TamperPrechargeDuration;
mbed_official 155:8435094ec241 2107 }
mbed_official 155:8435094ec241 2108
mbed_official 155:8435094ec241 2109 /**
mbed_official 155:8435094ec241 2110 * @brief Enables or Disables the TimeStamp on Tamper Detection Event.
mbed_official 155:8435094ec241 2111 * @note The timestamp is valid even the TSE bit in tamper control register
mbed_official 155:8435094ec241 2112 * is reset.
mbed_official 155:8435094ec241 2113 * @param NewState: new state of the timestamp on tamper event.
mbed_official 155:8435094ec241 2114 * This parameter can be: ENABLE or DISABLE.
mbed_official 155:8435094ec241 2115 * @retval None
mbed_official 155:8435094ec241 2116 */
mbed_official 155:8435094ec241 2117 void RTC_TimeStampOnTamperDetectionCmd(FunctionalState NewState)
mbed_official 155:8435094ec241 2118 {
mbed_official 155:8435094ec241 2119 /* Check the parameters */
mbed_official 155:8435094ec241 2120 assert_param(IS_FUNCTIONAL_STATE(NewState));
mbed_official 155:8435094ec241 2121
mbed_official 155:8435094ec241 2122 if (NewState != DISABLE)
mbed_official 155:8435094ec241 2123 {
mbed_official 155:8435094ec241 2124 /* Save timestamp on tamper detection event */
mbed_official 155:8435094ec241 2125 RTC->TAFCR |= (uint32_t)RTC_TAFCR_TAMPTS;
mbed_official 155:8435094ec241 2126 }
mbed_official 155:8435094ec241 2127 else
mbed_official 155:8435094ec241 2128 {
mbed_official 155:8435094ec241 2129 /* Tamper detection does not cause a timestamp to be saved */
mbed_official 155:8435094ec241 2130 RTC->TAFCR &= (uint32_t)~RTC_TAFCR_TAMPTS;
mbed_official 155:8435094ec241 2131 }
mbed_official 155:8435094ec241 2132 }
mbed_official 155:8435094ec241 2133
mbed_official 155:8435094ec241 2134 /**
mbed_official 155:8435094ec241 2135 * @brief Enables or Disables the Precharge of Tamper pin.
mbed_official 155:8435094ec241 2136 * @param NewState: new state of tamper pull up.
mbed_official 155:8435094ec241 2137 * This parameter can be: ENABLE or DISABLE.
mbed_official 155:8435094ec241 2138 * @retval None
mbed_official 155:8435094ec241 2139 */
mbed_official 155:8435094ec241 2140 void RTC_TamperPullUpCmd(FunctionalState NewState)
mbed_official 155:8435094ec241 2141 {
mbed_official 155:8435094ec241 2142 /* Check the parameters */
mbed_official 155:8435094ec241 2143 assert_param(IS_FUNCTIONAL_STATE(NewState));
mbed_official 155:8435094ec241 2144
mbed_official 155:8435094ec241 2145 if (NewState != DISABLE)
mbed_official 155:8435094ec241 2146 {
mbed_official 155:8435094ec241 2147 /* Enable precharge of the selected Tamper pin */
mbed_official 155:8435094ec241 2148 RTC->TAFCR &= (uint32_t)~RTC_TAFCR_TAMPPUDIS;
mbed_official 155:8435094ec241 2149 }
mbed_official 155:8435094ec241 2150 else
mbed_official 155:8435094ec241 2151 {
mbed_official 155:8435094ec241 2152 /* Disable precharge of the selected Tamper pin */
mbed_official 155:8435094ec241 2153 RTC->TAFCR |= (uint32_t)RTC_TAFCR_TAMPPUDIS;
mbed_official 155:8435094ec241 2154 }
mbed_official 155:8435094ec241 2155 }
mbed_official 155:8435094ec241 2156
mbed_official 155:8435094ec241 2157 /**
mbed_official 155:8435094ec241 2158 * @}
mbed_official 155:8435094ec241 2159 */
mbed_official 155:8435094ec241 2160
mbed_official 155:8435094ec241 2161 /** @defgroup RTC_Group10 Backup Data Registers configuration functions
mbed_official 155:8435094ec241 2162 * @brief Backup Data Registers configuration functions
mbed_official 155:8435094ec241 2163 *
mbed_official 155:8435094ec241 2164 @verbatim
mbed_official 155:8435094ec241 2165 ===============================================================================
mbed_official 155:8435094ec241 2166 ##### Backup Data Registers configuration functions #####
mbed_official 155:8435094ec241 2167 ===============================================================================
mbed_official 155:8435094ec241 2168
mbed_official 155:8435094ec241 2169 @endverbatim
mbed_official 155:8435094ec241 2170 * @{
mbed_official 155:8435094ec241 2171 */
mbed_official 155:8435094ec241 2172
mbed_official 155:8435094ec241 2173 /**
mbed_official 155:8435094ec241 2174 * @brief Writes a data in a specified RTC Backup data register.
mbed_official 155:8435094ec241 2175 * @param RTC_BKP_DR: RTC Backup data Register number.
mbed_official 155:8435094ec241 2176 * This parameter can be: RTC_BKP_DRx where x can be from 0 to 15 to
mbed_official 155:8435094ec241 2177 * specify the register.
mbed_official 155:8435094ec241 2178 * @param Data: Data to be written in the specified RTC Backup data register.
mbed_official 155:8435094ec241 2179 * @retval None
mbed_official 155:8435094ec241 2180 */
mbed_official 155:8435094ec241 2181 void RTC_WriteBackupRegister(uint32_t RTC_BKP_DR, uint32_t Data)
mbed_official 155:8435094ec241 2182 {
mbed_official 155:8435094ec241 2183 __IO uint32_t tmp = 0;
mbed_official 155:8435094ec241 2184
mbed_official 155:8435094ec241 2185 /* Check the parameters */
mbed_official 155:8435094ec241 2186 assert_param(IS_RTC_BKP(RTC_BKP_DR));
mbed_official 155:8435094ec241 2187
mbed_official 155:8435094ec241 2188 tmp = RTC_BASE + 0x50;
mbed_official 155:8435094ec241 2189 tmp += (RTC_BKP_DR * 4);
mbed_official 155:8435094ec241 2190
mbed_official 155:8435094ec241 2191 /* Write the specified register */
mbed_official 155:8435094ec241 2192 *(__IO uint32_t *)tmp = (uint32_t)Data;
mbed_official 155:8435094ec241 2193 }
mbed_official 155:8435094ec241 2194
mbed_official 155:8435094ec241 2195 /**
mbed_official 155:8435094ec241 2196 * @brief Reads data from the specified RTC Backup data Register.
mbed_official 155:8435094ec241 2197 * @param RTC_BKP_DR: RTC Backup data Register number.
mbed_official 155:8435094ec241 2198 * This parameter can be: RTC_BKP_DRx where x can be from 0 to 15 to
mbed_official 155:8435094ec241 2199 * specify the register.
mbed_official 155:8435094ec241 2200 * @retval None
mbed_official 155:8435094ec241 2201 */
mbed_official 155:8435094ec241 2202 uint32_t RTC_ReadBackupRegister(uint32_t RTC_BKP_DR)
mbed_official 155:8435094ec241 2203 {
mbed_official 155:8435094ec241 2204 __IO uint32_t tmp = 0;
mbed_official 155:8435094ec241 2205
mbed_official 155:8435094ec241 2206 /* Check the parameters */
mbed_official 155:8435094ec241 2207 assert_param(IS_RTC_BKP(RTC_BKP_DR));
mbed_official 155:8435094ec241 2208
mbed_official 155:8435094ec241 2209 tmp = RTC_BASE + 0x50;
mbed_official 155:8435094ec241 2210 tmp += (RTC_BKP_DR * 4);
mbed_official 155:8435094ec241 2211
mbed_official 155:8435094ec241 2212 /* Read the specified register */
mbed_official 155:8435094ec241 2213 return (*(__IO uint32_t *)tmp);
mbed_official 155:8435094ec241 2214 }
mbed_official 155:8435094ec241 2215
mbed_official 155:8435094ec241 2216 /**
mbed_official 155:8435094ec241 2217 * @}
mbed_official 155:8435094ec241 2218 */
mbed_official 155:8435094ec241 2219
mbed_official 155:8435094ec241 2220 /** @defgroup RTC_Group11 Output Type Config configuration functions
mbed_official 155:8435094ec241 2221 * @brief Output Type Config configuration functions
mbed_official 155:8435094ec241 2222 *
mbed_official 155:8435094ec241 2223 @verbatim
mbed_official 155:8435094ec241 2224 ===============================================================================
mbed_official 155:8435094ec241 2225 ##### Output Type Config configuration functions #####
mbed_official 155:8435094ec241 2226 ===============================================================================
mbed_official 155:8435094ec241 2227
mbed_official 155:8435094ec241 2228 @endverbatim
mbed_official 155:8435094ec241 2229 * @{
mbed_official 155:8435094ec241 2230 */
mbed_official 155:8435094ec241 2231
mbed_official 155:8435094ec241 2232 /**
mbed_official 155:8435094ec241 2233 * @brief Configures the RTC Output Pin mode.
mbed_official 155:8435094ec241 2234 * @param RTC_OutputType: specifies the RTC Output (PC13) pin mode.
mbed_official 155:8435094ec241 2235 * This parameter can be one of the following values:
mbed_official 155:8435094ec241 2236 * @arg RTC_OutputType_OpenDrain: RTC Output (PC13) is configured in
mbed_official 155:8435094ec241 2237 * Open Drain mode.
mbed_official 155:8435094ec241 2238 * @arg RTC_OutputType_PushPull: RTC Output (PC13) is configured in
mbed_official 155:8435094ec241 2239 * Push Pull mode.
mbed_official 155:8435094ec241 2240 * @retval None
mbed_official 155:8435094ec241 2241 */
mbed_official 155:8435094ec241 2242 void RTC_OutputTypeConfig(uint32_t RTC_OutputType)
mbed_official 155:8435094ec241 2243 {
mbed_official 155:8435094ec241 2244 /* Check the parameters */
mbed_official 155:8435094ec241 2245 assert_param(IS_RTC_OUTPUT_TYPE(RTC_OutputType));
mbed_official 155:8435094ec241 2246
mbed_official 155:8435094ec241 2247 RTC->TAFCR &= (uint32_t)~(RTC_TAFCR_ALARMOUTTYPE);
mbed_official 155:8435094ec241 2248 RTC->TAFCR |= (uint32_t)(RTC_OutputType);
mbed_official 155:8435094ec241 2249 }
mbed_official 155:8435094ec241 2250
mbed_official 155:8435094ec241 2251 /**
mbed_official 155:8435094ec241 2252 * @}
mbed_official 155:8435094ec241 2253 */
mbed_official 155:8435094ec241 2254
mbed_official 155:8435094ec241 2255 /** @defgroup RTC_Group12 Shift control synchronisation functions
mbed_official 155:8435094ec241 2256 * @brief Shift control synchronisation functions
mbed_official 155:8435094ec241 2257 *
mbed_official 155:8435094ec241 2258 @verbatim
mbed_official 155:8435094ec241 2259 ===============================================================================
mbed_official 155:8435094ec241 2260 ##### Shift control synchronisation functions #####
mbed_official 155:8435094ec241 2261 ===============================================================================
mbed_official 155:8435094ec241 2262
mbed_official 155:8435094ec241 2263 @endverbatim
mbed_official 155:8435094ec241 2264 * @{
mbed_official 155:8435094ec241 2265 */
mbed_official 155:8435094ec241 2266
mbed_official 155:8435094ec241 2267 /**
mbed_official 155:8435094ec241 2268 * @brief Configures the Synchronization Shift Control Settings.
mbed_official 155:8435094ec241 2269 * @note When REFCKON is set, firmware must not write to Shift control register
mbed_official 155:8435094ec241 2270 * @param RTC_ShiftAdd1S : Select to add or not 1 second to the time Calendar.
mbed_official 155:8435094ec241 2271 * This parameter can be one of the following values :
mbed_official 155:8435094ec241 2272 * @arg RTC_ShiftAdd1S_Set : Add one second to the clock calendar.
mbed_official 155:8435094ec241 2273 * @arg RTC_ShiftAdd1S_Reset: No effect.
mbed_official 155:8435094ec241 2274 * @param RTC_ShiftSubFS: Select the number of Second Fractions to Substitute.
mbed_official 155:8435094ec241 2275 * This parameter can be one any value from 0 to 0x7FFF.
mbed_official 155:8435094ec241 2276 * @retval An ErrorStatus enumeration value:
mbed_official 155:8435094ec241 2277 * - SUCCESS: RTC Shift registers are configured
mbed_official 155:8435094ec241 2278 * - ERROR: RTC Shift registers are not configured
mbed_official 155:8435094ec241 2279 */
mbed_official 155:8435094ec241 2280 ErrorStatus RTC_SynchroShiftConfig(uint32_t RTC_ShiftAdd1S, uint32_t RTC_ShiftSubFS)
mbed_official 155:8435094ec241 2281 {
mbed_official 155:8435094ec241 2282 ErrorStatus status = ERROR;
mbed_official 155:8435094ec241 2283 uint32_t shpfcount = 0;
mbed_official 155:8435094ec241 2284
mbed_official 155:8435094ec241 2285 /* Check the parameters */
mbed_official 155:8435094ec241 2286 assert_param(IS_RTC_SHIFT_ADD1S(RTC_ShiftAdd1S));
mbed_official 155:8435094ec241 2287 assert_param(IS_RTC_SHIFT_SUBFS(RTC_ShiftSubFS));
mbed_official 155:8435094ec241 2288
mbed_official 155:8435094ec241 2289 /* Disable the write protection for RTC registers */
mbed_official 155:8435094ec241 2290 RTC->WPR = 0xCA;
mbed_official 155:8435094ec241 2291 RTC->WPR = 0x53;
mbed_official 155:8435094ec241 2292
mbed_official 155:8435094ec241 2293 /* Check if a Shift is pending*/
mbed_official 155:8435094ec241 2294 if ((RTC->ISR & RTC_ISR_SHPF) != RESET)
mbed_official 155:8435094ec241 2295 {
mbed_official 155:8435094ec241 2296 /* Wait until the shift is completed*/
mbed_official 155:8435094ec241 2297 while (((RTC->ISR & RTC_ISR_SHPF) != RESET) && (shpfcount != SHPF_TIMEOUT))
mbed_official 155:8435094ec241 2298 {
mbed_official 155:8435094ec241 2299 shpfcount++;
mbed_official 155:8435094ec241 2300 }
mbed_official 155:8435094ec241 2301 }
mbed_official 155:8435094ec241 2302
mbed_official 155:8435094ec241 2303 /* Check if the Shift pending is completed or if there is no Shift operation at all*/
mbed_official 155:8435094ec241 2304 if ((RTC->ISR & RTC_ISR_SHPF) == RESET)
mbed_official 155:8435094ec241 2305 {
mbed_official 155:8435094ec241 2306 /* check if the reference clock detection is disabled */
mbed_official 155:8435094ec241 2307 if((RTC->CR & RTC_CR_REFCKON) == RESET)
mbed_official 155:8435094ec241 2308 {
mbed_official 155:8435094ec241 2309 /* Configure the Shift settings */
mbed_official 155:8435094ec241 2310 RTC->SHIFTR = (uint32_t)(uint32_t)(RTC_ShiftSubFS) | (uint32_t)(RTC_ShiftAdd1S);
mbed_official 155:8435094ec241 2311
mbed_official 155:8435094ec241 2312 if(RTC_WaitForSynchro() == ERROR)
mbed_official 155:8435094ec241 2313 {
mbed_official 155:8435094ec241 2314 status = ERROR;
mbed_official 155:8435094ec241 2315 }
mbed_official 155:8435094ec241 2316 else
mbed_official 155:8435094ec241 2317 {
mbed_official 155:8435094ec241 2318 status = SUCCESS;
mbed_official 155:8435094ec241 2319 }
mbed_official 155:8435094ec241 2320 }
mbed_official 155:8435094ec241 2321 else
mbed_official 155:8435094ec241 2322 {
mbed_official 155:8435094ec241 2323 status = ERROR;
mbed_official 155:8435094ec241 2324 }
mbed_official 155:8435094ec241 2325 }
mbed_official 155:8435094ec241 2326 else
mbed_official 155:8435094ec241 2327 {
mbed_official 155:8435094ec241 2328 status = ERROR;
mbed_official 155:8435094ec241 2329 }
mbed_official 155:8435094ec241 2330
mbed_official 155:8435094ec241 2331 /* Enable the write protection for RTC registers */
mbed_official 155:8435094ec241 2332 RTC->WPR = 0xFF;
mbed_official 155:8435094ec241 2333
mbed_official 155:8435094ec241 2334 return (ErrorStatus)(status);
mbed_official 155:8435094ec241 2335 }
mbed_official 155:8435094ec241 2336
mbed_official 155:8435094ec241 2337 /**
mbed_official 155:8435094ec241 2338 * @}
mbed_official 155:8435094ec241 2339 */
mbed_official 155:8435094ec241 2340
mbed_official 155:8435094ec241 2341 /** @defgroup RTC_Group13 Interrupts and flags management functions
mbed_official 155:8435094ec241 2342 * @brief Interrupts and flags management functions
mbed_official 155:8435094ec241 2343 *
mbed_official 155:8435094ec241 2344 @verbatim
mbed_official 155:8435094ec241 2345 ===============================================================================
mbed_official 155:8435094ec241 2346 ##### Interrupts and flags management functions #####
mbed_official 155:8435094ec241 2347 ===============================================================================
mbed_official 155:8435094ec241 2348 [..] All RTC interrupts are connected to the EXTI controller.
mbed_official 155:8435094ec241 2349 (+) To enable the RTC Alarm interrupt, the following sequence is required:
mbed_official 155:8435094ec241 2350 (++) Configure and enable the EXTI Line 17 in interrupt mode and select
mbed_official 155:8435094ec241 2351 the rising edge sensitivity using the EXTI_Init() function.
mbed_official 155:8435094ec241 2352 (++) Configure and enable the RTC_Alarm IRQ channel in the NVIC using
mbed_official 155:8435094ec241 2353 the NVIC_Init() function.
mbed_official 155:8435094ec241 2354 (++) Configure the RTC to generate RTC alarms (Alarm A and/or Alarm B)
mbed_official 155:8435094ec241 2355 using the RTC_SetAlarm() and RTC_AlarmCmd() functions.
mbed_official 155:8435094ec241 2356 (+) To enable the RTC Wakeup interrupt, the following sequence is required:
mbed_official 155:8435094ec241 2357 (++) Configure and enable the EXTI Line 20 in interrupt mode and select
mbed_official 155:8435094ec241 2358 the rising edge sensitivity using the EXTI_Init() function.
mbed_official 155:8435094ec241 2359 (++) Configure and enable the RTC_WKUP IRQ channel in the NVIC using
mbed_official 155:8435094ec241 2360 the NVIC_Init() function.
mbed_official 155:8435094ec241 2361 (++) Configure the RTC to generate the RTC wakeup timer event using the
mbed_official 155:8435094ec241 2362 RTC_WakeUpClockConfig(), RTC_SetWakeUpCounter() and RTC_WakeUpCmd()
mbed_official 155:8435094ec241 2363 functions.
mbed_official 155:8435094ec241 2364 (+) To enable the RTC Tamper interrupt, the following sequence is required:
mbed_official 155:8435094ec241 2365 (++) Configure and enable the EXTI Line 19 in interrupt mode and select
mbed_official 155:8435094ec241 2366 the rising edge sensitivity using the EXTI_Init() function.
mbed_official 155:8435094ec241 2367 (++) Configure and enable the TAMP_STAMP IRQ channel in the NVIC using
mbed_official 155:8435094ec241 2368 the NVIC_Init() function.
mbed_official 155:8435094ec241 2369 (++) Configure the RTC to detect the RTC tamper event using the
mbed_official 155:8435094ec241 2370 RTC_TamperTriggerConfig() and RTC_TamperCmd() functions.
mbed_official 155:8435094ec241 2371 (+) To enable the RTC TimeStamp interrupt, the following sequence is required:
mbed_official 155:8435094ec241 2372 (++) Configure and enable the EXTI Line 19 in interrupt mode and select
mbed_official 155:8435094ec241 2373 the rising edge sensitivity using the EXTI_Init() function.
mbed_official 155:8435094ec241 2374 (++) Configure and enable the TAMP_STAMP IRQ channel in the NVIC using
mbed_official 155:8435094ec241 2375 the NVIC_Init() function.
mbed_official 155:8435094ec241 2376 (++) Configure the RTC to detect the RTC time-stamp event using the
mbed_official 155:8435094ec241 2377 RTC_TimeStampCmd() functions.
mbed_official 155:8435094ec241 2378
mbed_official 155:8435094ec241 2379 @endverbatim
mbed_official 155:8435094ec241 2380 * @{
mbed_official 155:8435094ec241 2381 */
mbed_official 155:8435094ec241 2382
mbed_official 155:8435094ec241 2383 /**
mbed_official 155:8435094ec241 2384 * @brief Enables or disables the specified RTC interrupts.
mbed_official 155:8435094ec241 2385 * @param RTC_IT: specifies the RTC interrupt sources to be enabled or disabled.
mbed_official 155:8435094ec241 2386 * This parameter can be any combination of the following values:
mbed_official 155:8435094ec241 2387 * @arg RTC_IT_TS: Time Stamp interrupt mask
mbed_official 155:8435094ec241 2388 * @arg RTC_IT_WUT: WakeUp Timer interrupt mask
mbed_official 155:8435094ec241 2389 * @arg RTC_IT_ALRB: Alarm B interrupt mask
mbed_official 155:8435094ec241 2390 * @arg RTC_IT_ALRA: Alarm A interrupt mask
mbed_official 155:8435094ec241 2391 * @arg RTC_IT_TAMP: Tamper event interrupt mask
mbed_official 155:8435094ec241 2392 * @param NewState: new state of the specified RTC interrupts.
mbed_official 155:8435094ec241 2393 * This parameter can be: ENABLE or DISABLE.
mbed_official 155:8435094ec241 2394 * @retval None
mbed_official 155:8435094ec241 2395 */
mbed_official 155:8435094ec241 2396 void RTC_ITConfig(uint32_t RTC_IT, FunctionalState NewState)
mbed_official 155:8435094ec241 2397 {
mbed_official 155:8435094ec241 2398 /* Check the parameters */
mbed_official 155:8435094ec241 2399 assert_param(IS_RTC_CONFIG_IT(RTC_IT));
mbed_official 155:8435094ec241 2400 assert_param(IS_FUNCTIONAL_STATE(NewState));
mbed_official 155:8435094ec241 2401
mbed_official 155:8435094ec241 2402 /* Disable the write protection for RTC registers */
mbed_official 155:8435094ec241 2403 RTC->WPR = 0xCA;
mbed_official 155:8435094ec241 2404 RTC->WPR = 0x53;
mbed_official 155:8435094ec241 2405
mbed_official 155:8435094ec241 2406 if (NewState != DISABLE)
mbed_official 155:8435094ec241 2407 {
mbed_official 155:8435094ec241 2408 /* Configure the Interrupts in the RTC_CR register */
mbed_official 155:8435094ec241 2409 RTC->CR |= (uint32_t)(RTC_IT & ~RTC_TAFCR_TAMPIE);
mbed_official 155:8435094ec241 2410 /* Configure the Tamper Interrupt in the RTC_TAFCR */
mbed_official 155:8435094ec241 2411 RTC->TAFCR |= (uint32_t)(RTC_IT & RTC_TAFCR_TAMPIE);
mbed_official 155:8435094ec241 2412 }
mbed_official 155:8435094ec241 2413 else
mbed_official 155:8435094ec241 2414 {
mbed_official 155:8435094ec241 2415 /* Configure the Interrupts in the RTC_CR register */
mbed_official 155:8435094ec241 2416 RTC->CR &= (uint32_t)~(RTC_IT & (uint32_t)~RTC_TAFCR_TAMPIE);
mbed_official 155:8435094ec241 2417 /* Configure the Tamper Interrupt in the RTC_TAFCR */
mbed_official 155:8435094ec241 2418 RTC->TAFCR &= (uint32_t)~(RTC_IT & RTC_TAFCR_TAMPIE);
mbed_official 155:8435094ec241 2419 }
mbed_official 155:8435094ec241 2420 /* Enable the write protection for RTC registers */
mbed_official 155:8435094ec241 2421 RTC->WPR = 0xFF;
mbed_official 155:8435094ec241 2422 }
mbed_official 155:8435094ec241 2423
mbed_official 155:8435094ec241 2424 /**
mbed_official 155:8435094ec241 2425 * @brief Checks whether the specified RTC flag is set or not.
mbed_official 155:8435094ec241 2426 * @param RTC_FLAG: specifies the flag to check.
mbed_official 155:8435094ec241 2427 * This parameter can be one of the following values:
mbed_official 155:8435094ec241 2428 * @arg RTC_FLAG_RECALPF: RECALPF event flag
mbed_official 155:8435094ec241 2429 * @arg RTC_FLAG_TAMP3F: Tamper 3 event flag
mbed_official 155:8435094ec241 2430 * @arg RTC_FLAG_TAMP2F: Tamper 2 event flag
mbed_official 155:8435094ec241 2431 * @arg RTC_FLAG_TAMP1F: Tamper 1 event flag
mbed_official 155:8435094ec241 2432 * @arg RTC_FLAG_TSOVF: Time Stamp OverFlow flag
mbed_official 155:8435094ec241 2433 * @arg RTC_FLAG_TSF: Time Stamp event flag
mbed_official 155:8435094ec241 2434 * @arg RTC_FLAG_WUTF: WakeUp Timer flag
mbed_official 155:8435094ec241 2435 * @arg RTC_FLAG_ALRBF: Alarm B flag
mbed_official 155:8435094ec241 2436 * @arg RTC_FLAG_ALRAF: Alarm A flag
mbed_official 155:8435094ec241 2437 * @arg RTC_FLAG_INITF: Initialization mode flag
mbed_official 155:8435094ec241 2438 * @arg RTC_FLAG_RSF: Registers Synchronized flag
mbed_official 155:8435094ec241 2439 * @arg RTC_FLAG_INITS: Registers Configured flag
mbed_official 155:8435094ec241 2440 * @argRTC_FLAG_SHPF : Shift operation pending flag.
mbed_official 155:8435094ec241 2441 * @arg RTC_FLAG_WUTWF: WakeUp Timer Write flag
mbed_official 155:8435094ec241 2442 * @arg RTC_FLAG_ALRBWF: Alarm B Write flag
mbed_official 155:8435094ec241 2443 * @arg RTC_FLAG_ALRAWF: Alarm A write flag
mbed_official 155:8435094ec241 2444 * @retval The new state of RTC_FLAG (SET or RESET).
mbed_official 155:8435094ec241 2445 */
mbed_official 155:8435094ec241 2446 FlagStatus RTC_GetFlagStatus(uint32_t RTC_FLAG)
mbed_official 155:8435094ec241 2447 {
mbed_official 155:8435094ec241 2448 FlagStatus bitstatus = RESET;
mbed_official 155:8435094ec241 2449 uint32_t tmpreg = 0;
mbed_official 155:8435094ec241 2450
mbed_official 155:8435094ec241 2451 /* Check the parameters */
mbed_official 155:8435094ec241 2452 assert_param(IS_RTC_GET_FLAG(RTC_FLAG));
mbed_official 155:8435094ec241 2453
mbed_official 155:8435094ec241 2454 /* Get all the flags */
mbed_official 155:8435094ec241 2455 tmpreg = (uint32_t)(RTC->ISR & RTC_FLAGS_MASK);
mbed_official 155:8435094ec241 2456
mbed_official 155:8435094ec241 2457 /* Return the status of the flag */
mbed_official 155:8435094ec241 2458 if ((tmpreg & RTC_FLAG) != (uint32_t)RESET)
mbed_official 155:8435094ec241 2459 {
mbed_official 155:8435094ec241 2460 bitstatus = SET;
mbed_official 155:8435094ec241 2461 }
mbed_official 155:8435094ec241 2462 else
mbed_official 155:8435094ec241 2463 {
mbed_official 155:8435094ec241 2464 bitstatus = RESET;
mbed_official 155:8435094ec241 2465 }
mbed_official 155:8435094ec241 2466 return bitstatus;
mbed_official 155:8435094ec241 2467 }
mbed_official 155:8435094ec241 2468
mbed_official 155:8435094ec241 2469 /**
mbed_official 155:8435094ec241 2470 * @brief Clears the RTC's pending flags.
mbed_official 155:8435094ec241 2471 * @param RTC_FLAG: specifies the RTC flag to clear.
mbed_official 155:8435094ec241 2472 * This parameter can be any combination of the following values:
mbed_official 155:8435094ec241 2473 * @arg RTC_FLAG_TAMP3F: Tamper 3 event flag
mbed_official 155:8435094ec241 2474 * @arg RTC_FLAG_TAMP2F: Tamper 2 event flag
mbed_official 155:8435094ec241 2475 * @arg RTC_FLAG_TAMP1F: Tamper 1 event flag
mbed_official 155:8435094ec241 2476 * @arg RTC_FLAG_TSOVF: Time Stamp Overflow flag
mbed_official 155:8435094ec241 2477 * @arg RTC_FLAG_TSF: Time Stamp event flag
mbed_official 155:8435094ec241 2478 * @arg RTC_FLAG_WUTF: WakeUp Timer flag
mbed_official 155:8435094ec241 2479 * @arg RTC_FLAG_ALRBF: Alarm B flag
mbed_official 155:8435094ec241 2480 * @arg RTC_FLAG_ALRAF: Alarm A flag
mbed_official 155:8435094ec241 2481 * @arg RTC_FLAG_RSF: Registers Synchronized flag
mbed_official 155:8435094ec241 2482 * @retval None
mbed_official 155:8435094ec241 2483 */
mbed_official 155:8435094ec241 2484 void RTC_ClearFlag(uint32_t RTC_FLAG)
mbed_official 155:8435094ec241 2485 {
mbed_official 155:8435094ec241 2486 /* Check the parameters */
mbed_official 155:8435094ec241 2487 assert_param(IS_RTC_CLEAR_FLAG(RTC_FLAG));
mbed_official 155:8435094ec241 2488
mbed_official 155:8435094ec241 2489 /* Clear the Flags in the RTC_ISR register */
mbed_official 155:8435094ec241 2490 RTC->ISR = (uint32_t)((uint32_t)(~((RTC_FLAG | RTC_ISR_INIT)& 0x0001FFFF) | (uint32_t)(RTC->ISR & RTC_ISR_INIT)));
mbed_official 155:8435094ec241 2491 }
mbed_official 155:8435094ec241 2492
mbed_official 155:8435094ec241 2493 /**
mbed_official 155:8435094ec241 2494 * @brief Checks whether the specified RTC interrupt has occurred or not.
mbed_official 155:8435094ec241 2495 * @param RTC_IT: specifies the RTC interrupt source to check.
mbed_official 155:8435094ec241 2496 * This parameter can be one of the following values:
mbed_official 155:8435094ec241 2497 * @arg RTC_IT_TS: Time Stamp interrupt
mbed_official 155:8435094ec241 2498 * @arg RTC_IT_WUT: WakeUp Timer interrupt
mbed_official 155:8435094ec241 2499 * @arg RTC_IT_ALRB: Alarm B interrupt
mbed_official 155:8435094ec241 2500 * @arg RTC_IT_ALRA: Alarm A interrupt
mbed_official 155:8435094ec241 2501 * @arg RTC_IT_TAMP1: Tamper1 event interrupt
mbed_official 155:8435094ec241 2502 * @arg RTC_IT_TAMP2: Tamper2 event interrupt
mbed_official 155:8435094ec241 2503 * @arg RTC_IT_TAMP3: Tamper3 event interrupt
mbed_official 155:8435094ec241 2504 * @retval The new state of RTC_IT (SET or RESET).
mbed_official 155:8435094ec241 2505 */
mbed_official 155:8435094ec241 2506 ITStatus RTC_GetITStatus(uint32_t RTC_IT)
mbed_official 155:8435094ec241 2507 {
mbed_official 155:8435094ec241 2508 ITStatus bitstatus = RESET;
mbed_official 155:8435094ec241 2509 uint32_t tmpreg = 0, enablestatus = 0;
mbed_official 155:8435094ec241 2510
mbed_official 155:8435094ec241 2511 /* Check the parameters */
mbed_official 155:8435094ec241 2512 assert_param(IS_RTC_GET_IT(RTC_IT));
mbed_official 155:8435094ec241 2513
mbed_official 155:8435094ec241 2514 /* Get the TAMPER Interrupt enable bit and pending bit */
mbed_official 155:8435094ec241 2515 tmpreg = (uint32_t)(RTC->TAFCR & (RTC_TAFCR_TAMPIE));
mbed_official 155:8435094ec241 2516
mbed_official 155:8435094ec241 2517 /* Get the Interrupt enable Status */
mbed_official 155:8435094ec241 2518 enablestatus = (uint32_t)((RTC->CR & RTC_IT) | (tmpreg & ((RTC_IT >> (RTC_IT >> 18)) >> 15)));
mbed_official 155:8435094ec241 2519
mbed_official 155:8435094ec241 2520 /* Get the Interrupt pending bit */
mbed_official 155:8435094ec241 2521 tmpreg = (uint32_t)((RTC->ISR & (uint32_t)(RTC_IT >> 4)));
mbed_official 155:8435094ec241 2522
mbed_official 155:8435094ec241 2523 /* Get the status of the Interrupt */
mbed_official 155:8435094ec241 2524 if ((enablestatus != (uint32_t)RESET) && ((tmpreg & 0x0000FFFF) != (uint32_t)RESET))
mbed_official 155:8435094ec241 2525 {
mbed_official 155:8435094ec241 2526 bitstatus = SET;
mbed_official 155:8435094ec241 2527 }
mbed_official 155:8435094ec241 2528 else
mbed_official 155:8435094ec241 2529 {
mbed_official 155:8435094ec241 2530 bitstatus = RESET;
mbed_official 155:8435094ec241 2531 }
mbed_official 155:8435094ec241 2532 return bitstatus;
mbed_official 155:8435094ec241 2533 }
mbed_official 155:8435094ec241 2534
mbed_official 155:8435094ec241 2535 /**
mbed_official 155:8435094ec241 2536 * @brief Clears the RTC's interrupt pending bits.
mbed_official 155:8435094ec241 2537 * @param RTC_IT: specifies the RTC interrupt pending bit to clear.
mbed_official 155:8435094ec241 2538 * This parameter can be any combination of the following values:
mbed_official 155:8435094ec241 2539 * @arg RTC_IT_TS: Time Stamp interrupt
mbed_official 155:8435094ec241 2540 * @arg RTC_IT_WUT: WakeUp Timer interrupt
mbed_official 155:8435094ec241 2541 * @arg RTC_IT_ALRB: Alarm B interrupt
mbed_official 155:8435094ec241 2542 * @arg RTC_IT_ALRA: Alarm A interrupt
mbed_official 155:8435094ec241 2543 * @arg RTC_IT_TAMP1: Tamper1 event interrupt
mbed_official 155:8435094ec241 2544 * @arg RTC_IT_TAMP2: Tamper2 event interrupt
mbed_official 155:8435094ec241 2545 * @arg RTC_IT_TAMP3: Tamper3 event interrupt
mbed_official 155:8435094ec241 2546 * @retval None
mbed_official 155:8435094ec241 2547 */
mbed_official 155:8435094ec241 2548 void RTC_ClearITPendingBit(uint32_t RTC_IT)
mbed_official 155:8435094ec241 2549 {
mbed_official 155:8435094ec241 2550 uint32_t tmpreg = 0;
mbed_official 155:8435094ec241 2551
mbed_official 155:8435094ec241 2552 /* Check the parameters */
mbed_official 155:8435094ec241 2553 assert_param(IS_RTC_CLEAR_IT(RTC_IT));
mbed_official 155:8435094ec241 2554
mbed_official 155:8435094ec241 2555 /* Get the RTC_ISR Interrupt pending bits mask */
mbed_official 155:8435094ec241 2556 tmpreg = (uint32_t)(RTC_IT >> 4);
mbed_official 155:8435094ec241 2557
mbed_official 155:8435094ec241 2558 /* Clear the interrupt pending bits in the RTC_ISR register */
mbed_official 155:8435094ec241 2559 RTC->ISR = (uint32_t)((uint32_t)(~((tmpreg | RTC_ISR_INIT)& 0x0000FFFF) | (uint32_t)(RTC->ISR & RTC_ISR_INIT)));
mbed_official 155:8435094ec241 2560 }
mbed_official 155:8435094ec241 2561
mbed_official 155:8435094ec241 2562 /**
mbed_official 155:8435094ec241 2563 * @}
mbed_official 155:8435094ec241 2564 */
mbed_official 155:8435094ec241 2565
mbed_official 155:8435094ec241 2566 /**
mbed_official 155:8435094ec241 2567 * @brief Converts a 2 digit decimal to BCD format.
mbed_official 155:8435094ec241 2568 * @param Value: Byte to be converted.
mbed_official 155:8435094ec241 2569 * @retval Converted byte
mbed_official 155:8435094ec241 2570 */
mbed_official 155:8435094ec241 2571 static uint8_t RTC_ByteToBcd2(uint8_t Value)
mbed_official 155:8435094ec241 2572 {
mbed_official 155:8435094ec241 2573 uint8_t bcdhigh = 0;
mbed_official 155:8435094ec241 2574
mbed_official 155:8435094ec241 2575 while (Value >= 10)
mbed_official 155:8435094ec241 2576 {
mbed_official 155:8435094ec241 2577 bcdhigh++;
mbed_official 155:8435094ec241 2578 Value -= 10;
mbed_official 155:8435094ec241 2579 }
mbed_official 155:8435094ec241 2580
mbed_official 155:8435094ec241 2581 return ((uint8_t)(bcdhigh << 4) | Value);
mbed_official 155:8435094ec241 2582 }
mbed_official 155:8435094ec241 2583
mbed_official 155:8435094ec241 2584 /**
mbed_official 155:8435094ec241 2585 * @brief Convert from 2 digit BCD to Binary.
mbed_official 155:8435094ec241 2586 * @param Value: BCD value to be converted.
mbed_official 155:8435094ec241 2587 * @retval Converted word
mbed_official 155:8435094ec241 2588 */
mbed_official 155:8435094ec241 2589 static uint8_t RTC_Bcd2ToByte(uint8_t Value)
mbed_official 155:8435094ec241 2590 {
mbed_official 155:8435094ec241 2591 uint8_t tmp = 0;
mbed_official 155:8435094ec241 2592 tmp = ((uint8_t)(Value & (uint8_t)0xF0) >> (uint8_t)0x4) * 10;
mbed_official 155:8435094ec241 2593 return (tmp + (Value & (uint8_t)0x0F));
mbed_official 155:8435094ec241 2594 }
mbed_official 155:8435094ec241 2595
mbed_official 155:8435094ec241 2596 /**
mbed_official 155:8435094ec241 2597 * @}
mbed_official 155:8435094ec241 2598 */
mbed_official 155:8435094ec241 2599
mbed_official 155:8435094ec241 2600 /**
mbed_official 155:8435094ec241 2601 * @}
mbed_official 155:8435094ec241 2602 */
mbed_official 155:8435094ec241 2603
mbed_official 155:8435094ec241 2604 /**
mbed_official 155:8435094ec241 2605 * @}
mbed_official 155:8435094ec241 2606 */
mbed_official 155:8435094ec241 2607
mbed_official 155:8435094ec241 2608 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/