1 /** 2 ****************************************************************************** 3 * @file stm32f37x_rtc.h 4 * @author MCD Application Team 5 * @version V1.0.0 6 * @date 20-September-2012 7 * @brief This file contains all the functions prototypes for the RTC 8 * firmware library. 9 ****************************************************************************** 10 * @attention 11 * 12 * <h2><center>© COPYRIGHT 2012 STMicroelectronics</center></h2> 13 * 14 * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License"); 15 * You may not use this file except in compliance with the License. 16 * You may obtain a copy of the License at: 17 * 18 * http://www.st.com/software_license_agreement_liberty_v2 19 * 20 * Unless required by applicable law or agreed to in writing, software 21 * distributed under the License is distributed on an "AS IS" BASIS, 22 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 23 * See the License for the specific language governing permissions and 24 * limitations under the License. 25 * 26 ****************************************************************************** 27 */ 28 29 /* Define to prevent recursive inclusion -------------------------------------*/ 30 #ifndef __STM32F37X_RTC_H 31 #define __STM32F37X_RTC_H 32 33 #ifdef __cplusplus 34 extern "C" { 35 #endif 36 37 /* Includes ------------------------------------------------------------------*/ 38 #include "stm32f37x.h" 39 40 /** @addtogroup STM32F37x_StdPeriph_Driver 41 * @{ 42 */ 43 44 /** @addtogroup RTC 45 * @{ 46 */ 47 48 /* Exported types ------------------------------------------------------------*/ 49 50 /** 51 * @brief RTC Init structures definition 52 */ 53 typedef struct 54 { 55 uint32_t RTC_HourFormat; /*!< Specifies the RTC Hour Format. 56 This parameter can be a value of @ref RTC_Hour_Formats */ 57 58 uint32_t RTC_AsynchPrediv; /*!< Specifies the RTC Asynchronous Predivider value. 59 This parameter must be set to a value lower than 0x7F */ 60 61 uint32_t RTC_SynchPrediv; /*!< Specifies the RTC Synchronous Predivider value. 62 This parameter must be set to a value lower than 0x1FFF */ 63 }RTC_InitTypeDef; 64 65 /** 66 * @brief RTC Time structure definition 67 */ 68 typedef struct 69 { 70 uint8_t RTC_Hours; /*!< Specifies the RTC Time Hour. 71 This parameter must be set to a value in the 0-12 range 72 if the RTC_HourFormat_12 is selected or 0-23 range if 73 the RTC_HourFormat_24 is selected. */ 74 75 uint8_t RTC_Minutes; /*!< Specifies the RTC Time Minutes. 76 This parameter must be set to a value in the 0-59 range. */ 77 78 uint8_t RTC_Seconds; /*!< Specifies the RTC Time Seconds. 79 This parameter must be set to a value in the 0-59 range. */ 80 81 uint8_t RTC_H12; /*!< Specifies the RTC AM/PM Time. 82 This parameter can be a value of @ref RTC_AM_PM_Definitions */ 83 }RTC_TimeTypeDef; 84 85 /** 86 * @brief RTC Date structure definition 87 */ 88 typedef struct 89 { 90 uint8_t RTC_WeekDay; /*!< Specifies the RTC Date WeekDay. 91 This parameter can be a value of @ref RTC_WeekDay_Definitions */ 92 93 uint8_t RTC_Month; /*!< Specifies the RTC Date Month (in BCD format). 94 This parameter can be a value of @ref RTC_Month_Date_Definitions */ 95 96 uint8_t RTC_Date; /*!< Specifies the RTC Date. 97 This parameter must be set to a value in the 1-31 range. */ 98 99 uint8_t RTC_Year; /*!< Specifies the RTC Date Year. 100 This parameter must be set to a value in the 0-99 range. */ 101 }RTC_DateTypeDef; 102 103 /** 104 * @brief RTC Alarm structure definition 105 */ 106 typedef struct 107 { 108 RTC_TimeTypeDef RTC_AlarmTime; /*!< Specifies the RTC Alarm Time members. */ 109 110 uint32_t RTC_AlarmMask; /*!< Specifies the RTC Alarm Masks. 111 This parameter can be a value of @ref RTC_AlarmMask_Definitions */ 112 113 uint32_t RTC_AlarmDateWeekDaySel; /*!< Specifies the RTC Alarm is on Date or WeekDay. 114 This parameter can be a value of @ref RTC_AlarmDateWeekDay_Definitions */ 115 116 uint8_t RTC_AlarmDateWeekDay; /*!< Specifies the RTC Alarm Date/WeekDay. 117 This parameter must be set to a value in the 1-31 range 118 if the Alarm Date is selected. 119 This parameter can be a value of @ref RTC_WeekDay_Definitions 120 if the Alarm WeekDay is selected. */ 121 }RTC_AlarmTypeDef; 122 123 /* Exported constants --------------------------------------------------------*/ 124 125 /** @defgroup RTC_Exported_Constants 126 * @{ 127 */ 128 129 130 /** @defgroup RTC_Hour_Formats 131 * @{ 132 */ 133 #define RTC_HourFormat_24 ((uint32_t)0x00000000) 134 #define RTC_HourFormat_12 ((uint32_t)0x00000040) 135 #define IS_RTC_HOUR_FORMAT(FORMAT) (((FORMAT) == RTC_HourFormat_12) || \ 136 ((FORMAT) == RTC_HourFormat_24)) 137 /** 138 * @} 139 */ 140 141 /** @defgroup RTC_Asynchronous_Predivider 142 * @{ 143 */ 144 #define IS_RTC_ASYNCH_PREDIV(PREDIV) ((PREDIV) <= 0x7F) 145 146 /** 147 * @} 148 */ 149 150 151 /** @defgroup RTC_Synchronous_Predivider 152 * @{ 153 */ 154 #define IS_RTC_SYNCH_PREDIV(PREDIV) ((PREDIV) <= 0x7FFF) 155 156 /** 157 * @} 158 */ 159 160 /** @defgroup RTC_Time_Definitions 161 * @{ 162 */ 163 #define IS_RTC_HOUR12(HOUR) (((HOUR) > 0) && ((HOUR) <= 12)) 164 #define IS_RTC_HOUR24(HOUR) ((HOUR) <= 23) 165 #define IS_RTC_MINUTES(MINUTES) ((MINUTES) <= 59) 166 #define IS_RTC_SECONDS(SECONDS) ((SECONDS) <= 59) 167 168 /** 169 * @} 170 */ 171 172 /** @defgroup RTC_AM_PM_Definitions 173 * @{ 174 */ 175 #define RTC_H12_AM ((uint8_t)0x00) 176 #define RTC_H12_PM ((uint8_t)0x40) 177 #define IS_RTC_H12(PM) (((PM) == RTC_H12_AM) || ((PM) == RTC_H12_PM)) 178 179 /** 180 * @} 181 */ 182 183 /** @defgroup RTC_Year_Date_Definitions 184 * @{ 185 */ 186 #define IS_RTC_YEAR(YEAR) ((YEAR) <= 99) 187 188 /** 189 * @} 190 */ 191 192 /** @defgroup RTC_Month_Date_Definitions 193 * @{ 194 */ 195 196 /* Coded in BCD format */ 197 #define RTC_Month_January ((uint8_t)0x01) 198 #define RTC_Month_February ((uint8_t)0x02) 199 #define RTC_Month_March ((uint8_t)0x03) 200 #define RTC_Month_April ((uint8_t)0x04) 201 #define RTC_Month_May ((uint8_t)0x05) 202 #define RTC_Month_June ((uint8_t)0x06) 203 #define RTC_Month_July ((uint8_t)0x07) 204 #define RTC_Month_August ((uint8_t)0x08) 205 #define RTC_Month_September ((uint8_t)0x09) 206 #define RTC_Month_October ((uint8_t)0x10) 207 #define RTC_Month_November ((uint8_t)0x11) 208 #define RTC_Month_December ((uint8_t)0x12) 209 #define IS_RTC_MONTH(MONTH) (((MONTH) >= 1) && ((MONTH) <= 12)) 210 #define IS_RTC_DATE(DATE) (((DATE) >= 1) && ((DATE) <= 31)) 211 212 /** 213 * @} 214 */ 215 216 /** @defgroup RTC_WeekDay_Definitions 217 * @{ 218 */ 219 220 #define RTC_Weekday_Monday ((uint8_t)0x01) 221 #define RTC_Weekday_Tuesday ((uint8_t)0x02) 222 #define RTC_Weekday_Wednesday ((uint8_t)0x03) 223 #define RTC_Weekday_Thursday ((uint8_t)0x04) 224 #define RTC_Weekday_Friday ((uint8_t)0x05) 225 #define RTC_Weekday_Saturday ((uint8_t)0x06) 226 #define RTC_Weekday_Sunday ((uint8_t)0x07) 227 #define IS_RTC_WEEKDAY(WEEKDAY) (((WEEKDAY) == RTC_Weekday_Monday) || \ 228 ((WEEKDAY) == RTC_Weekday_Tuesday) || \ 229 ((WEEKDAY) == RTC_Weekday_Wednesday) || \ 230 ((WEEKDAY) == RTC_Weekday_Thursday) || \ 231 ((WEEKDAY) == RTC_Weekday_Friday) || \ 232 ((WEEKDAY) == RTC_Weekday_Saturday) || \ 233 ((WEEKDAY) == RTC_Weekday_Sunday)) 234 /** 235 * @} 236 */ 237 238 239 /** @defgroup RTC_Alarm_Definitions 240 * @{ 241 */ 242 #define IS_RTC_ALARM_DATE_WEEKDAY_DATE(DATE) (((DATE) > 0) && ((DATE) <= 31)) 243 #define IS_RTC_ALARM_DATE_WEEKDAY_WEEKDAY(WEEKDAY) (((WEEKDAY) == RTC_Weekday_Monday) || \ 244 ((WEEKDAY) == RTC_Weekday_Tuesday) || \ 245 ((WEEKDAY) == RTC_Weekday_Wednesday) || \ 246 ((WEEKDAY) == RTC_Weekday_Thursday) || \ 247 ((WEEKDAY) == RTC_Weekday_Friday) || \ 248 ((WEEKDAY) == RTC_Weekday_Saturday) || \ 249 ((WEEKDAY) == RTC_Weekday_Sunday)) 250 251 /** 252 * @} 253 */ 254 255 256 /** @defgroup RTC_AlarmDateWeekDay_Definitions 257 * @{ 258 */ 259 #define RTC_AlarmDateWeekDaySel_Date ((uint32_t)0x00000000) 260 #define RTC_AlarmDateWeekDaySel_WeekDay ((uint32_t)0x40000000) 261 262 #define IS_RTC_ALARM_DATE_WEEKDAY_SEL(SEL) (((SEL) == RTC_AlarmDateWeekDaySel_Date) || \ 263 ((SEL) == RTC_AlarmDateWeekDaySel_WeekDay)) 264 265 /** 266 * @} 267 */ 268 269 270 /** @defgroup RTC_AlarmMask_Definitions 271 * @{ 272 */ 273 #define RTC_AlarmMask_None ((uint32_t)0x00000000) 274 #define RTC_AlarmMask_DateWeekDay ((uint32_t)0x80000000) 275 #define RTC_AlarmMask_Hours ((uint32_t)0x00800000) 276 #define RTC_AlarmMask_Minutes ((uint32_t)0x00008000) 277 #define RTC_AlarmMask_Seconds ((uint32_t)0x00000080) 278 #define RTC_AlarmMask_All ((uint32_t)0x80808080) 279 #define IS_ALARM_MASK(MASK) (((MASK) & 0x7F7F7F7F) == (uint32_t)RESET) 280 281 /** 282 * @} 283 */ 284 285 /** @defgroup RTC_Alarms_Definitions 286 * @{ 287 */ 288 #define RTC_Alarm_A ((uint32_t)0x00000100) 289 #define RTC_Alarm_B ((uint32_t)0x00000200) 290 #define IS_RTC_ALARM(ALARM) (((ALARM) == RTC_Alarm_A) || ((ALARM) == RTC_Alarm_B)) 291 #define IS_RTC_CMD_ALARM(ALARM) (((ALARM) & (RTC_Alarm_A | RTC_Alarm_B)) != (uint32_t)RESET) 292 293 /** 294 * @} 295 */ 296 297 /** @defgroup RTC_Alarm_Sub_Seconds_Masks_Definitions 298 * @{ 299 */ 300 #define RTC_AlarmSubSecondMask_All ((uint32_t)0x00000000) /*!< All Alarm SS fields are masked. 301 There is no comparison on sub seconds 302 for Alarm */ 303 #define RTC_AlarmSubSecondMask_SS14_1 ((uint32_t)0x01000000) /*!< SS[14:1] are don't care in Alarm 304 comparison. Only SS[0] is compared. */ 305 #define RTC_AlarmSubSecondMask_SS14_2 ((uint32_t)0x02000000) /*!< SS[14:2] are don't care in Alarm 306 comparison. Only SS[1:0] are compared */ 307 #define RTC_AlarmSubSecondMask_SS14_3 ((uint32_t)0x03000000) /*!< SS[14:3] are don't care in Alarm 308 comparison. Only SS[2:0] are compared */ 309 #define RTC_AlarmSubSecondMask_SS14_4 ((uint32_t)0x04000000) /*!< SS[14:4] are don't care in Alarm 310 comparison. Only SS[3:0] are compared */ 311 #define RTC_AlarmSubSecondMask_SS14_5 ((uint32_t)0x05000000) /*!< SS[14:5] are don't care in Alarm 312 comparison. Only SS[4:0] are compared */ 313 #define RTC_AlarmSubSecondMask_SS14_6 ((uint32_t)0x06000000) /*!< SS[14:6] are don't care in Alarm 314 comparison. Only SS[5:0] are compared */ 315 #define RTC_AlarmSubSecondMask_SS14_7 ((uint32_t)0x07000000) /*!< SS[14:7] are don't care in Alarm 316 comparison. Only SS[6:0] are compared */ 317 #define RTC_AlarmSubSecondMask_SS14_8 ((uint32_t)0x08000000) /*!< SS[14:8] are don't care in Alarm 318 comparison. Only SS[7:0] are compared */ 319 #define RTC_AlarmSubSecondMask_SS14_9 ((uint32_t)0x09000000) /*!< SS[14:9] are don't care in Alarm 320 comparison. Only SS[8:0] are compared */ 321 #define RTC_AlarmSubSecondMask_SS14_10 ((uint32_t)0x0A000000) /*!< SS[14:10] are don't care in Alarm 322 comparison. Only SS[9:0] are compared */ 323 #define RTC_AlarmSubSecondMask_SS14_11 ((uint32_t)0x0B000000) /*!< SS[14:11] are don't care in Alarm 324 comparison. Only SS[10:0] are compared */ 325 #define RTC_AlarmSubSecondMask_SS14_12 ((uint32_t)0x0C000000) /*!< SS[14:12] are don't care in Alarm 326 comparison.Only SS[11:0] are compared */ 327 #define RTC_AlarmSubSecondMask_SS14_13 ((uint32_t)0x0D000000) /*!< SS[14:13] are don't care in Alarm 328 comparison. Only SS[12:0] are compared */ 329 #define RTC_AlarmSubSecondMask_SS14 ((uint32_t)0x0E000000) /*!< SS[14] is don't care in Alarm 330 comparison.Only SS[13:0] are compared */ 331 #define RTC_AlarmSubSecondMask_None ((uint32_t)0x0F000000) /*!< SS[14:0] are compared and must match 332 to activate alarm. */ 333 #define IS_RTC_ALARM_SUB_SECOND_MASK(MASK) (((MASK) == RTC_AlarmSubSecondMask_All) || \ 334 ((MASK) == RTC_AlarmSubSecondMask_SS14_1) || \ 335 ((MASK) == RTC_AlarmSubSecondMask_SS14_2) || \ 336 ((MASK) == RTC_AlarmSubSecondMask_SS14_3) || \ 337 ((MASK) == RTC_AlarmSubSecondMask_SS14_4) || \ 338 ((MASK) == RTC_AlarmSubSecondMask_SS14_5) || \ 339 ((MASK) == RTC_AlarmSubSecondMask_SS14_6) || \ 340 ((MASK) == RTC_AlarmSubSecondMask_SS14_7) || \ 341 ((MASK) == RTC_AlarmSubSecondMask_SS14_8) || \ 342 ((MASK) == RTC_AlarmSubSecondMask_SS14_9) || \ 343 ((MASK) == RTC_AlarmSubSecondMask_SS14_10) || \ 344 ((MASK) == RTC_AlarmSubSecondMask_SS14_11) || \ 345 ((MASK) == RTC_AlarmSubSecondMask_SS14_12) || \ 346 ((MASK) == RTC_AlarmSubSecondMask_SS14_13) || \ 347 ((MASK) == RTC_AlarmSubSecondMask_SS14) || \ 348 ((MASK) == RTC_AlarmSubSecondMask_None)) 349 /** 350 * @} 351 */ 352 353 /** @defgroup RTC_Alarm_Sub_Seconds_Value 354 * @{ 355 */ 356 357 #define IS_RTC_ALARM_SUB_SECOND_VALUE(VALUE) ((VALUE) <= 0x00007FFF) 358 359 /** 360 * @} 361 */ 362 363 /** @defgroup RTC_Wakeup_Timer_Definitions 364 * @{ 365 */ 366 #define RTC_WakeUpClock_RTCCLK_Div16 ((uint32_t)0x00000000) 367 #define RTC_WakeUpClock_RTCCLK_Div8 ((uint32_t)0x00000001) 368 #define RTC_WakeUpClock_RTCCLK_Div4 ((uint32_t)0x00000002) 369 #define RTC_WakeUpClock_RTCCLK_Div2 ((uint32_t)0x00000003) 370 #define RTC_WakeUpClock_CK_SPRE_16bits ((uint32_t)0x00000004) 371 #define RTC_WakeUpClock_CK_SPRE_17bits ((uint32_t)0x00000006) 372 #define IS_RTC_WAKEUP_CLOCK(CLOCK) (((CLOCK) == RTC_WakeUpClock_RTCCLK_Div16) || \ 373 ((CLOCK) == RTC_WakeUpClock_RTCCLK_Div8) || \ 374 ((CLOCK) == RTC_WakeUpClock_RTCCLK_Div4) || \ 375 ((CLOCK) == RTC_WakeUpClock_RTCCLK_Div2) || \ 376 ((CLOCK) == RTC_WakeUpClock_CK_SPRE_16bits) || \ 377 ((CLOCK) == RTC_WakeUpClock_CK_SPRE_17bits)) 378 #define IS_RTC_WAKEUP_COUNTER(COUNTER) ((COUNTER) <= 0xFFFF) 379 /** 380 * @} 381 */ 382 383 /** @defgroup RTC_Time_Stamp_Edges_definitions 384 * @{ 385 */ 386 #define RTC_TimeStampEdge_Rising ((uint32_t)0x00000000) 387 #define RTC_TimeStampEdge_Falling ((uint32_t)0x00000008) 388 #define IS_RTC_TIMESTAMP_EDGE(EDGE) (((EDGE) == RTC_TimeStampEdge_Rising) || \ 389 ((EDGE) == RTC_TimeStampEdge_Falling)) 390 /** 391 * @} 392 */ 393 394 /** @defgroup RTC_Output_selection_Definitions 395 * @{ 396 */ 397 #define RTC_Output_Disable ((uint32_t)0x00000000) 398 #define RTC_Output_AlarmA ((uint32_t)0x00200000) 399 #define RTC_Output_AlarmB ((uint32_t)0x00400000) 400 #define RTC_Output_WakeUp ((uint32_t)0x00600000) 401 402 #define IS_RTC_OUTPUT(OUTPUT) (((OUTPUT) == RTC_Output_Disable) || \ 403 ((OUTPUT) == RTC_Output_AlarmA) || \ 404 ((OUTPUT) == RTC_Output_AlarmB) || \ 405 ((OUTPUT) == RTC_Output_WakeUp)) 406 407 /** 408 * @} 409 */ 410 411 /** @defgroup RTC_Output_Polarity_Definitions 412 * @{ 413 */ 414 #define RTC_OutputPolarity_High ((uint32_t)0x00000000) 415 #define RTC_OutputPolarity_Low ((uint32_t)0x00100000) 416 #define IS_RTC_OUTPUT_POL(POL) (((POL) == RTC_OutputPolarity_High) || \ 417 ((POL) == RTC_OutputPolarity_Low)) 418 /** 419 * @} 420 */ 421 422 423 /** @defgroup RTC_Calib_Output_selection_Definitions 424 * @{ 425 */ 426 #define RTC_CalibOutput_512Hz ((uint32_t)0x00000000) 427 #define RTC_CalibOutput_1Hz ((uint32_t)0x00080000) 428 #define IS_RTC_CALIB_OUTPUT(OUTPUT) (((OUTPUT) == RTC_CalibOutput_512Hz) || \ 429 ((OUTPUT) == RTC_CalibOutput_1Hz)) 430 /** 431 * @} 432 */ 433 434 /** @defgroup RTC_Smooth_calib_period_Definitions 435 * @{ 436 */ 437 #define RTC_SmoothCalibPeriod_32sec ((uint32_t)0x00000000) /*!< if RTCCLK = 32768 Hz, Smooth calibation 438 period is 32s, else 2exp20 RTCCLK seconds */ 439 #define RTC_SmoothCalibPeriod_16sec ((uint32_t)0x00002000) /*!< if RTCCLK = 32768 Hz, Smooth calibation 440 period is 16s, else 2exp19 RTCCLK seconds */ 441 #define RTC_SmoothCalibPeriod_8sec ((uint32_t)0x00004000) /*!< if RTCCLK = 32768 Hz, Smooth calibation 442 period is 8s, else 2exp18 RTCCLK seconds */ 443 #define IS_RTC_SMOOTH_CALIB_PERIOD(PERIOD) (((PERIOD) == RTC_SmoothCalibPeriod_32sec) || \ 444 ((PERIOD) == RTC_SmoothCalibPeriod_16sec) || \ 445 ((PERIOD) == RTC_SmoothCalibPeriod_8sec)) 446 447 /** 448 * @} 449 */ 450 451 /** @defgroup RTC_Smooth_calib_Plus_pulses_Definitions 452 * @{ 453 */ 454 #define RTC_SmoothCalibPlusPulses_Set ((uint32_t)0x00008000) /*!< The number of RTCCLK pulses added 455 during a X -second window = Y - CALM[8:0]. 456 with Y = 512, 256, 128 when X = 32, 16, 8 */ 457 #define RTC_SmoothCalibPlusPulses_Reset ((uint32_t)0x00000000) /*!< The number of RTCCLK pulses subbstited 458 during a 32-second window = CALM[8:0]. */ 459 #define IS_RTC_SMOOTH_CALIB_PLUS(PLUS) (((PLUS) == RTC_SmoothCalibPlusPulses_Set) || \ 460 ((PLUS) == RTC_SmoothCalibPlusPulses_Reset)) 461 462 /** 463 * @} 464 */ 465 466 /** @defgroup RTC_Smooth_calib_Minus_pulses_Definitions 467 * @{ 468 */ 469 #define IS_RTC_SMOOTH_CALIB_MINUS(VALUE) ((VALUE) <= 0x000001FF) 470 471 /** 472 * @} 473 */ 474 475 /** @defgroup RTC_DayLightSaving_Definitions 476 * @{ 477 */ 478 #define RTC_DayLightSaving_SUB1H ((uint32_t)0x00020000) 479 #define RTC_DayLightSaving_ADD1H ((uint32_t)0x00010000) 480 #define IS_RTC_DAYLIGHT_SAVING(SAVING) (((SAVING) == RTC_DayLightSaving_SUB1H) || \ 481 ((SAVING) == RTC_DayLightSaving_ADD1H)) 482 483 #define RTC_StoreOperation_Reset ((uint32_t)0x00000000) 484 #define RTC_StoreOperation_Set ((uint32_t)0x00040000) 485 #define IS_RTC_STORE_OPERATION(OPERATION) (((OPERATION) == RTC_StoreOperation_Reset) || \ 486 ((OPERATION) == RTC_StoreOperation_Set)) 487 /** 488 * @} 489 */ 490 491 /** @defgroup RTC_Tamper_Trigger_Definitions 492 * @{ 493 */ 494 #define RTC_TamperTrigger_RisingEdge ((uint32_t)0x00000000) 495 #define RTC_TamperTrigger_FallingEdge ((uint32_t)0x00000001) 496 #define RTC_TamperTrigger_LowLevel ((uint32_t)0x00000000) 497 #define RTC_TamperTrigger_HighLevel ((uint32_t)0x00000001) 498 #define IS_RTC_TAMPER_TRIGGER(TRIGGER) (((TRIGGER) == RTC_TamperTrigger_RisingEdge) || \ 499 ((TRIGGER) == RTC_TamperTrigger_FallingEdge) || \ 500 ((TRIGGER) == RTC_TamperTrigger_LowLevel) || \ 501 ((TRIGGER) == RTC_TamperTrigger_HighLevel)) 502 503 /** 504 * @} 505 */ 506 507 /** @defgroup RTC_Tamper_Filter_Definitions 508 * @{ 509 */ 510 #define RTC_TamperFilter_Disable ((uint32_t)0x00000000) /*!< Tamper filter is disabled */ 511 512 #define RTC_TamperFilter_2Sample ((uint32_t)0x00000800) /*!< Tamper is activated after 2 513 consecutive samples at the active level */ 514 #define RTC_TamperFilter_4Sample ((uint32_t)0x00001000) /*!< Tamper is activated after 4 515 consecutive samples at the active level */ 516 #define RTC_TamperFilter_8Sample ((uint32_t)0x00001800) /*!< Tamper is activated after 8 517 consecutive samples at the active leve. */ 518 #define IS_RTC_TAMPER_FILTER(FILTER) (((FILTER) == RTC_TamperFilter_Disable) || \ 519 ((FILTER) == RTC_TamperFilter_2Sample) || \ 520 ((FILTER) == RTC_TamperFilter_4Sample) || \ 521 ((FILTER) == RTC_TamperFilter_8Sample)) 522 /** 523 * @} 524 */ 525 526 /** @defgroup RTC_Tamper_Sampling_Frequencies_Definitions 527 * @{ 528 */ 529 #define RTC_TamperSamplingFreq_RTCCLK_Div32768 ((uint32_t)0x00000000) /*!< Each of the tamper inputs are sampled 530 with a frequency = RTCCLK / 32768 */ 531 #define RTC_TamperSamplingFreq_RTCCLK_Div16384 ((uint32_t)0x00000100) /*!< Each of the tamper inputs are sampled 532 with a frequency = RTCCLK / 16384 */ 533 #define RTC_TamperSamplingFreq_RTCCLK_Div8192 ((uint32_t)0x00000200) /*!< Each of the tamper inputs are sampled 534 with a frequency = RTCCLK / 8192 */ 535 #define RTC_TamperSamplingFreq_RTCCLK_Div4096 ((uint32_t)0x00000300) /*!< Each of the tamper inputs are sampled 536 with a frequency = RTCCLK / 4096 */ 537 #define RTC_TamperSamplingFreq_RTCCLK_Div2048 ((uint32_t)0x00000400) /*!< Each of the tamper inputs are sampled 538 with a frequency = RTCCLK / 2048 */ 539 #define RTC_TamperSamplingFreq_RTCCLK_Div1024 ((uint32_t)0x00000500) /*!< Each of the tamper inputs are sampled 540 with a frequency = RTCCLK / 1024 */ 541 #define RTC_TamperSamplingFreq_RTCCLK_Div512 ((uint32_t)0x00000600) /*!< Each of the tamper inputs are sampled 542 with a frequency = RTCCLK / 512 */ 543 #define RTC_TamperSamplingFreq_RTCCLK_Div256 ((uint32_t)0x00000700) /*!< Each of the tamper inputs are sampled 544 with a frequency = RTCCLK / 256 */ 545 #define IS_RTC_TAMPER_SAMPLING_FREQ(FREQ) (((FREQ) ==RTC_TamperSamplingFreq_RTCCLK_Div32768) || \ 546 ((FREQ) ==RTC_TamperSamplingFreq_RTCCLK_Div16384) || \ 547 ((FREQ) ==RTC_TamperSamplingFreq_RTCCLK_Div8192) || \ 548 ((FREQ) ==RTC_TamperSamplingFreq_RTCCLK_Div4096) || \ 549 ((FREQ) ==RTC_TamperSamplingFreq_RTCCLK_Div2048) || \ 550 ((FREQ) ==RTC_TamperSamplingFreq_RTCCLK_Div1024) || \ 551 ((FREQ) ==RTC_TamperSamplingFreq_RTCCLK_Div512) || \ 552 ((FREQ) ==RTC_TamperSamplingFreq_RTCCLK_Div256)) 553 554 /** 555 * @} 556 */ 557 558 /** @defgroup RTC_Tamper_Pin_Precharge_Duration_Definitions 559 * @{ 560 */ 561 #define RTC_TamperPrechargeDuration_1RTCCLK ((uint32_t)0x00000000) /*!< Tamper pins are pre-charged before 562 sampling during 1 RTCCLK cycle */ 563 #define RTC_TamperPrechargeDuration_2RTCCLK ((uint32_t)0x00002000) /*!< Tamper pins are pre-charged before 564 sampling during 2 RTCCLK cycles */ 565 #define RTC_TamperPrechargeDuration_4RTCCLK ((uint32_t)0x00004000) /*!< Tamper pins are pre-charged before 566 sampling during 4 RTCCLK cycles */ 567 #define RTC_TamperPrechargeDuration_8RTCCLK ((uint32_t)0x00006000) /*!< Tamper pins are pre-charged before 568 sampling during 8 RTCCLK cycles */ 569 570 #define IS_RTC_TAMPER_PRECHARGE_DURATION(DURATION) (((DURATION) == RTC_TamperPrechargeDuration_1RTCCLK) || \ 571 ((DURATION) == RTC_TamperPrechargeDuration_2RTCCLK) || \ 572 ((DURATION) == RTC_TamperPrechargeDuration_4RTCCLK) || \ 573 ((DURATION) == RTC_TamperPrechargeDuration_8RTCCLK)) 574 /** 575 * @} 576 */ 577 578 /** @defgroup RTC_Tamper_Pins_Definitions 579 * @{ 580 */ 581 #define RTC_Tamper_1 RTC_TAFCR_TAMP1E /*!< Tamper detection enable for 582 input tamper 1 */ 583 #define RTC_Tamper_2 RTC_TAFCR_TAMP2E /*!< Tamper detection enable for 584 input tamper 2 */ 585 #define RTC_Tamper_3 RTC_TAFCR_TAMP3E /*!< Tamper detection enable for 586 input tamper 3 */ 587 588 #define IS_RTC_TAMPER(TAMPER) ((((TAMPER) & (uint32_t)0xFFFFFFD6) == 0x00) && ((TAMPER) != (uint32_t)RESET)) 589 590 591 /** 592 * @} 593 */ 594 595 /** @defgroup RTC_Output_Type_ALARM_OUT 596 * @{ 597 */ 598 #define RTC_OutputType_OpenDrain ((uint32_t)0x00000000) 599 #define RTC_OutputType_PushPull ((uint32_t)0x00040000) 600 #define IS_RTC_OUTPUT_TYPE(TYPE) (((TYPE) == RTC_OutputType_OpenDrain) || \ 601 ((TYPE) == RTC_OutputType_PushPull)) 602 603 /** 604 * @} 605 */ 606 607 /** @defgroup RTC_Add_1_Second_Parameter_Definitions 608 * @{ 609 */ 610 #define RTC_ShiftAdd1S_Reset ((uint32_t)0x00000000) 611 #define RTC_ShiftAdd1S_Set ((uint32_t)0x80000000) 612 #define IS_RTC_SHIFT_ADD1S(SEL) (((SEL) == RTC_ShiftAdd1S_Reset) || \ 613 ((SEL) == RTC_ShiftAdd1S_Set)) 614 /** 615 * @} 616 */ 617 618 /** @defgroup RTC_Substract_Fraction_Of_Second_Value 619 * @{ 620 */ 621 #define IS_RTC_SHIFT_SUBFS(FS) ((FS) <= 0x00007FFF) 622 623 /** 624 * @} 625 */ 626 627 /** @defgroup RTC_Backup_Registers_Definitions 628 * @{ 629 */ 630 631 #define RTC_BKP_DR0 ((uint32_t)0x00000000) 632 #define RTC_BKP_DR1 ((uint32_t)0x00000001) 633 #define RTC_BKP_DR2 ((uint32_t)0x00000002) 634 #define RTC_BKP_DR3 ((uint32_t)0x00000003) 635 #define RTC_BKP_DR4 ((uint32_t)0x00000004) 636 #define RTC_BKP_DR5 ((uint32_t)0x00000005) 637 #define RTC_BKP_DR6 ((uint32_t)0x00000006) 638 #define RTC_BKP_DR7 ((uint32_t)0x00000007) 639 #define RTC_BKP_DR8 ((uint32_t)0x00000008) 640 #define RTC_BKP_DR9 ((uint32_t)0x00000009) 641 #define RTC_BKP_DR10 ((uint32_t)0x0000000A) 642 #define RTC_BKP_DR11 ((uint32_t)0x0000000B) 643 #define RTC_BKP_DR12 ((uint32_t)0x0000000C) 644 #define RTC_BKP_DR13 ((uint32_t)0x0000000D) 645 #define RTC_BKP_DR14 ((uint32_t)0x0000000E) 646 #define RTC_BKP_DR15 ((uint32_t)0x0000000F) 647 #define RTC_BKP_DR16 ((uint32_t)0x00000010) 648 #define RTC_BKP_DR17 ((uint32_t)0x00000011) 649 #define RTC_BKP_DR18 ((uint32_t)0x00000012) 650 #define RTC_BKP_DR19 ((uint32_t)0x00000013) 651 #define RTC_BKP_DR20 ((uint32_t)0x00000014) 652 #define RTC_BKP_DR21 ((uint32_t)0x00000015) 653 #define RTC_BKP_DR22 ((uint32_t)0x00000016) 654 #define RTC_BKP_DR23 ((uint32_t)0x00000017) 655 #define RTC_BKP_DR24 ((uint32_t)0x00000018) 656 #define RTC_BKP_DR25 ((uint32_t)0x00000019) 657 #define RTC_BKP_DR26 ((uint32_t)0x0000001A) 658 #define RTC_BKP_DR27 ((uint32_t)0x0000001B) 659 #define RTC_BKP_DR28 ((uint32_t)0x0000001C) 660 #define RTC_BKP_DR29 ((uint32_t)0x0000001D) 661 #define RTC_BKP_DR30 ((uint32_t)0x0000001E) 662 #define RTC_BKP_DR31 ((uint32_t)0x0000001F) 663 #define IS_RTC_BKP(BKP) (((BKP) == RTC_BKP_DR0) || \ 664 ((BKP) == RTC_BKP_DR1) || \ 665 ((BKP) == RTC_BKP_DR2) || \ 666 ((BKP) == RTC_BKP_DR3) || \ 667 ((BKP) == RTC_BKP_DR4) || \ 668 ((BKP) == RTC_BKP_DR5) || \ 669 ((BKP) == RTC_BKP_DR6) || \ 670 ((BKP) == RTC_BKP_DR7) || \ 671 ((BKP) == RTC_BKP_DR8) || \ 672 ((BKP) == RTC_BKP_DR9) || \ 673 ((BKP) == RTC_BKP_DR10) || \ 674 ((BKP) == RTC_BKP_DR11) || \ 675 ((BKP) == RTC_BKP_DR12) || \ 676 ((BKP) == RTC_BKP_DR13) || \ 677 ((BKP) == RTC_BKP_DR14) || \ 678 ((BKP) == RTC_BKP_DR15) || \ 679 ((BKP) == RTC_BKP_DR16) || \ 680 ((BKP) == RTC_BKP_DR17) || \ 681 ((BKP) == RTC_BKP_DR18) || \ 682 ((BKP) == RTC_BKP_DR19) || \ 683 ((BKP) == RTC_BKP_DR20) || \ 684 ((BKP) == RTC_BKP_DR21) || \ 685 ((BKP) == RTC_BKP_DR22) || \ 686 ((BKP) == RTC_BKP_DR23) || \ 687 ((BKP) == RTC_BKP_DR24) || \ 688 ((BKP) == RTC_BKP_DR25) || \ 689 ((BKP) == RTC_BKP_DR26) || \ 690 ((BKP) == RTC_BKP_DR27) || \ 691 ((BKP) == RTC_BKP_DR28) || \ 692 ((BKP) == RTC_BKP_DR29) || \ 693 ((BKP) == RTC_BKP_DR30) || \ 694 ((BKP) == RTC_BKP_DR31)) 695 /** 696 * @} 697 */ 698 699 /** @defgroup RTC_Input_parameter_format_definitions 700 * @{ 701 */ 702 #define RTC_Format_BIN ((uint32_t)0x000000000) 703 #define RTC_Format_BCD ((uint32_t)0x000000001) 704 #define IS_RTC_FORMAT(FORMAT) (((FORMAT) == RTC_Format_BIN) || ((FORMAT) == RTC_Format_BCD)) 705 706 /** 707 * @} 708 */ 709 710 /** @defgroup RTC_Flags_Definitions 711 * @{ 712 */ 713 #define RTC_FLAG_RECALPF ((uint32_t)0x00010000) 714 #define RTC_FLAG_TAMP3F ((uint32_t)0x00008000) 715 #define RTC_FLAG_TAMP2F ((uint32_t)0x00004000) 716 #define RTC_FLAG_TAMP1F ((uint32_t)0x00002000) 717 #define RTC_FLAG_TSOVF ((uint32_t)0x00001000) 718 #define RTC_FLAG_TSF ((uint32_t)0x00000800) 719 #define RTC_FLAG_WUTF ((uint32_t)0x00000400) 720 #define RTC_FLAG_ALRBF ((uint32_t)0x00000200) 721 #define RTC_FLAG_ALRAF ((uint32_t)0x00000100) 722 #define RTC_FLAG_INITF ((uint32_t)0x00000040) 723 #define RTC_FLAG_RSF ((uint32_t)0x00000020) 724 #define RTC_FLAG_INITS ((uint32_t)0x00000010) 725 #define RTC_FLAG_SHPF ((uint32_t)0x00000008) 726 #define RTC_FLAG_WUTWF ((uint32_t)0x00000004) 727 #define RTC_FLAG_ALRBWF ((uint32_t)0x00000002) 728 #define RTC_FLAG_ALRAWF ((uint32_t)0x00000001) 729 #define IS_RTC_GET_FLAG(FLAG) (((FLAG) == RTC_FLAG_TSOVF) || ((FLAG) == RTC_FLAG_TSF) || \ 730 ((FLAG) == RTC_FLAG_WUTF) || ((FLAG) == RTC_FLAG_ALRBF) || \ 731 ((FLAG) == RTC_FLAG_ALRAF) || ((FLAG) == RTC_FLAG_INITF) || \ 732 ((FLAG) == RTC_FLAG_RSF) || ((FLAG) == RTC_FLAG_WUTWF) || \ 733 ((FLAG) == RTC_FLAG_ALRBWF) || ((FLAG) == RTC_FLAG_ALRAWF) || \ 734 ((FLAG) == RTC_FLAG_TAMP1F) || ((FLAG) == RTC_FLAG_TAMP2F) || \ 735 ((FLAG) == RTC_FLAG_TAMP3F) || ((FLAG) == RTC_FLAG_RECALPF) || \ 736 ((FLAG) == RTC_FLAG_SHPF)) 737 #define IS_RTC_CLEAR_FLAG(FLAG) (((FLAG) != (uint32_t)RESET) && (((FLAG) & 0xFFFF00DF) == (uint32_t)RESET)) 738 739 /** 740 * @} 741 */ 742 743 /** @defgroup RTC_Interrupts_Definitions 744 * @{ 745 */ 746 #define RTC_IT_TS ((uint32_t)0x00008000) 747 #define RTC_IT_WUT ((uint32_t)0x00004000) 748 #define RTC_IT_ALRB ((uint32_t)0x00002000) 749 #define RTC_IT_ALRA ((uint32_t)0x00001000) 750 #define RTC_IT_TAMP ((uint32_t)0x00000004) /* Used only to Enable the Tamper Interrupt */ 751 #define RTC_IT_TAMP1 ((uint32_t)0x00020000) 752 #define RTC_IT_TAMP2 ((uint32_t)0x00040000) 753 #define RTC_IT_TAMP3 ((uint32_t)0x00080000) 754 755 756 #define IS_RTC_CONFIG_IT(IT) (((IT) != (uint32_t)RESET) && (((IT) & 0xFFFF0FFB) == (uint32_t)RESET)) 757 #define IS_RTC_GET_IT(IT) (((IT) == RTC_IT_TS) || ((IT) == RTC_IT_WUT) || \ 758 ((IT) == RTC_IT_ALRB) || ((IT) == RTC_IT_ALRA) || \ 759 ((IT) == RTC_IT_TAMP1) || ((IT) == RTC_IT_TAMP2) || \ 760 ((IT) == RTC_IT_TAMP3)) 761 #define IS_RTC_CLEAR_IT(IT) (((IT) != (uint32_t)RESET) && (((IT) & 0xFFF10FFF) == (uint32_t)RESET)) 762 763 /** 764 * @} 765 */ 766 767 /** 768 * @} 769 */ 770 771 772 /* Exported macro ------------------------------------------------------------*/ 773 /* Exported functions --------------------------------------------------------*/ 774 775 /* Function used to set the RTC configuration to the default reset state *****/ 776 ErrorStatus RTC_DeInit(void); 777 778 779 /* Initialization and Configuration functions *********************************/ 780 ErrorStatus RTC_Init(RTC_InitTypeDef* RTC_InitStruct); 781 void RTC_StructInit(RTC_InitTypeDef* RTC_InitStruct); 782 void RTC_WriteProtectionCmd(FunctionalState NewState); 783 ErrorStatus RTC_EnterInitMode(void); 784 void RTC_ExitInitMode(void); 785 ErrorStatus RTC_WaitForSynchro(void); 786 ErrorStatus RTC_RefClockCmd(FunctionalState NewState); 787 void RTC_BypassShadowCmd(FunctionalState NewState); 788 789 /* Time and Date configuration functions **************************************/ 790 ErrorStatus RTC_SetTime(uint32_t RTC_Format, RTC_TimeTypeDef* RTC_TimeStruct); 791 void RTC_TimeStructInit(RTC_TimeTypeDef* RTC_TimeStruct); 792 void RTC_GetTime(uint32_t RTC_Format, RTC_TimeTypeDef* RTC_TimeStruct); 793 uint32_t RTC_GetSubSecond(void); 794 ErrorStatus RTC_SetDate(uint32_t RTC_Format, RTC_DateTypeDef* RTC_DateStruct); 795 void RTC_DateStructInit(RTC_DateTypeDef* RTC_DateStruct); 796 void RTC_GetDate(uint32_t RTC_Format, RTC_DateTypeDef* RTC_DateStruct); 797 798 /* Alarms (Alarm A and Alarm B) configuration functions **********************/ 799 void RTC_SetAlarm(uint32_t RTC_Format, uint32_t RTC_Alarm, RTC_AlarmTypeDef* RTC_AlarmStruct); 800 void RTC_AlarmStructInit(RTC_AlarmTypeDef* RTC_AlarmStruct); 801 void RTC_GetAlarm(uint32_t RTC_Format, uint32_t RTC_Alarm, RTC_AlarmTypeDef* RTC_AlarmStruct); 802 ErrorStatus RTC_AlarmCmd(uint32_t RTC_Alarm, FunctionalState NewState); 803 void RTC_AlarmSubSecondConfig(uint32_t RTC_Alarm, uint32_t RTC_AlarmSubSecondValue, uint32_t RTC_AlarmSubSecondMask); 804 uint32_t RTC_GetAlarmSubSecond(uint32_t RTC_Alarm); 805 806 /* WakeUp Timer configuration functions ***************************************/ 807 void RTC_WakeUpClockConfig(uint32_t RTC_WakeUpClock); 808 void RTC_SetWakeUpCounter(uint32_t RTC_WakeUpCounter); 809 uint32_t RTC_GetWakeUpCounter(void); 810 ErrorStatus RTC_WakeUpCmd(FunctionalState NewState); 811 812 /* Daylight Saving configuration functions ************************************/ 813 void RTC_DayLightSavingConfig(uint32_t RTC_DayLightSaving, uint32_t RTC_StoreOperation); 814 uint32_t RTC_GetStoreOperation(void); 815 816 /* Output pin Configuration function ******************************************/ 817 void RTC_OutputConfig(uint32_t RTC_Output, uint32_t RTC_OutputPolarity); 818 819 /* Coarse Calibration configuration functions *********************************/ 820 void RTC_CalibOutputCmd(FunctionalState NewState); 821 void RTC_CalibOutputConfig(uint32_t RTC_CalibOutput); 822 ErrorStatus RTC_SmoothCalibConfig(uint32_t RTC_SmoothCalibPeriod, 823 uint32_t RTC_SmoothCalibPlusPulses, 824 uint32_t RTC_SmouthCalibMinusPulsesValue); 825 826 /* TimeStamp configuration functions ******************************************/ 827 void RTC_TimeStampCmd(uint32_t RTC_TimeStampEdge, FunctionalState NewState); 828 void RTC_GetTimeStamp(uint32_t RTC_Format, RTC_TimeTypeDef* RTC_StampTimeStruct, 829 RTC_DateTypeDef* RTC_StampDateStruct); 830 uint32_t RTC_GetTimeStampSubSecond(void); 831 832 /* Tampers configuration functions ********************************************/ 833 void RTC_TamperTriggerConfig(uint32_t RTC_Tamper, uint32_t RTC_TamperTrigger); 834 void RTC_TamperCmd(uint32_t RTC_Tamper, FunctionalState NewState); 835 void RTC_TamperFilterConfig(uint32_t RTC_TamperFilter); 836 void RTC_TamperSamplingFreqConfig(uint32_t RTC_TamperSamplingFreq); 837 void RTC_TamperPinsPrechargeDuration(uint32_t RTC_TamperPrechargeDuration); 838 void RTC_TimeStampOnTamperDetectionCmd(FunctionalState NewState); 839 void RTC_TamperPullUpCmd(FunctionalState NewState); 840 841 /* Backup Data Registers configuration functions ******************************/ 842 void RTC_WriteBackupRegister(uint32_t RTC_BKP_DR, uint32_t Data); 843 uint32_t RTC_ReadBackupRegister(uint32_t RTC_BKP_DR); 844 845 /* Output Type Config configuration functions *********************************/ 846 void RTC_OutputTypeConfig(uint32_t RTC_OutputType); 847 848 /* RTC_Shift_control_synchonisation_functions *********************************/ 849 ErrorStatus RTC_SynchroShiftConfig(uint32_t RTC_ShiftAdd1S, uint32_t RTC_ShiftSubFS); 850 851 /* Interrupts and flags management functions **********************************/ 852 void RTC_ITConfig(uint32_t RTC_IT, FunctionalState NewState); 853 FlagStatus RTC_GetFlagStatus(uint32_t RTC_FLAG); 854 void RTC_ClearFlag(uint32_t RTC_FLAG); 855 ITStatus RTC_GetITStatus(uint32_t RTC_IT); 856 void RTC_ClearITPendingBit(uint32_t RTC_IT); 857 858 #ifdef __cplusplus 859 } 860 #endif 861 862 #endif /*__STM32F37X_RTC_H */ 863 864 /** 865 * @} 866 */ 867 868 /** 869 * @} 870 */ 871 872 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 873