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