STM32F2 Standard Peripheral bibliotheek  1.0
ST Microelectronics bibliotheek documentatie voor de STM32F2 Standard Peripheral Library
 All Data Structures Files Functions Variables Enumerations Enumerator Groups
stm32f2xx_rtc.h
Go to the documentation of this file.
1 
29 /* Define to prevent recursive inclusion -------------------------------------*/
30 #ifndef __STM32F2xx_RTC_H
31 #define __STM32F2xx_RTC_H
32 
33 #ifdef __cplusplus
34  extern "C" {
35 #endif
36 
37 /* Includes ------------------------------------------------------------------*/
38 #include "stm32f2xx.h"
39 
48 /* Exported types ------------------------------------------------------------*/
49 
53 typedef struct
54 {
55  uint32_t RTC_HourFormat;
58  uint32_t RTC_AsynchPrediv;
61  uint32_t RTC_SynchPrediv;
64 
68 typedef struct
69 {
70  uint8_t RTC_Hours;
75  uint8_t RTC_Minutes;
78  uint8_t RTC_Seconds;
81  uint8_t RTC_H12;
84 
88 typedef struct
89 {
90  uint8_t RTC_WeekDay;
93  uint8_t RTC_Month;
96  uint8_t RTC_Date;
99  uint8_t RTC_Year;
102 
106 typedef struct
107 {
110  uint32_t RTC_AlarmMask;
113  uint32_t RTC_AlarmDateWeekDaySel;
116  uint8_t RTC_AlarmDateWeekDay;
122 
123 /* Exported constants --------------------------------------------------------*/
124 
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 
144 #define IS_RTC_ASYNCH_PREDIV(PREDIV) ((PREDIV) <= 0x7F)
145 
154 #define IS_RTC_SYNCH_PREDIV(PREDIV) ((PREDIV) <= 0x1FFF)
155 
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 
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 
186 #define IS_RTC_YEAR(YEAR) ((YEAR) <= 99)
187 
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 
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 
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 
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 
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 
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 
300 #define RTC_WakeUpClock_RTCCLK_Div16 ((uint32_t)0x00000000)
301 #define RTC_WakeUpClock_RTCCLK_Div8 ((uint32_t)0x00000001)
302 #define RTC_WakeUpClock_RTCCLK_Div4 ((uint32_t)0x00000002)
303 #define RTC_WakeUpClock_RTCCLK_Div2 ((uint32_t)0x00000003)
304 #define RTC_WakeUpClock_CK_SPRE_16bits ((uint32_t)0x00000004)
305 #define RTC_WakeUpClock_CK_SPRE_17bits ((uint32_t)0x00000006)
306 #define IS_RTC_WAKEUP_CLOCK(CLOCK) (((CLOCK) == RTC_WakeUpClock_RTCCLK_Div16) || \
307  ((CLOCK) == RTC_WakeUpClock_RTCCLK_Div8) || \
308  ((CLOCK) == RTC_WakeUpClock_RTCCLK_Div4) || \
309  ((CLOCK) == RTC_WakeUpClock_RTCCLK_Div2) || \
310  ((CLOCK) == RTC_WakeUpClock_CK_SPRE_16bits) || \
311  ((CLOCK) == RTC_WakeUpClock_CK_SPRE_17bits))
312 #define IS_RTC_WAKEUP_COUNTER(COUNTER) ((COUNTER) <= 0xFFFF)
313 
320 #define RTC_TimeStampEdge_Rising ((uint32_t)0x00000000)
321 #define RTC_TimeStampEdge_Falling ((uint32_t)0x00000008)
322 #define IS_RTC_TIMESTAMP_EDGE(EDGE) (((EDGE) == RTC_TimeStampEdge_Rising) || \
323  ((EDGE) == RTC_TimeStampEdge_Falling))
324 
331 #define RTC_Output_Disable ((uint32_t)0x00000000)
332 #define RTC_Output_AlarmA ((uint32_t)0x00200000)
333 #define RTC_Output_AlarmB ((uint32_t)0x00400000)
334 #define RTC_Output_WakeUp ((uint32_t)0x00600000)
335 
336 #define IS_RTC_OUTPUT(OUTPUT) (((OUTPUT) == RTC_Output_Disable) || \
337  ((OUTPUT) == RTC_Output_AlarmA) || \
338  ((OUTPUT) == RTC_Output_AlarmB) || \
339  ((OUTPUT) == RTC_Output_WakeUp))
340 
348 #define RTC_OutputPolarity_High ((uint32_t)0x00000000)
349 #define RTC_OutputPolarity_Low ((uint32_t)0x00100000)
350 #define IS_RTC_OUTPUT_POL(POL) (((POL) == RTC_OutputPolarity_High) || \
351  ((POL) == RTC_OutputPolarity_Low))
352 
360 #define RTC_CalibSign_Positive ((uint32_t)0x00000000)
361 #define RTC_CalibSign_Negative ((uint32_t)0x00000080)
362 #define IS_RTC_CALIB_SIGN(SIGN) (((SIGN) == RTC_CalibSign_Positive) || \
363  ((SIGN) == RTC_CalibSign_Negative))
364 #define IS_RTC_CALIB_VALUE(VALUE) ((VALUE) < 0x20)
365 
374 #define RTC_DayLightSaving_SUB1H ((uint32_t)0x00020000)
375 #define RTC_DayLightSaving_ADD1H ((uint32_t)0x00010000)
376 #define IS_RTC_DAYLIGHT_SAVING(SAVE) (((SAVE) == RTC_DayLightSaving_SUB1H) || \
377  ((SAVE) == RTC_DayLightSaving_ADD1H))
378 
379 #define RTC_StoreOperation_Reset ((uint32_t)0x00000000)
380 #define RTC_StoreOperation_Set ((uint32_t)0x00040000)
381 #define IS_RTC_STORE_OPERATION(OPERATION) (((OPERATION) == RTC_StoreOperation_Reset) || \
382  ((OPERATION) == RTC_StoreOperation_Set))
383 
390 #define RTC_TamperTrigger_RisingEdge ((uint32_t)0x00000000)
391 #define RTC_TamperTrigger_FallingEdge ((uint32_t)0x00000001)
392 #define IS_RTC_TAMPER_TRIGGER(TRIGGER) (((TRIGGER) == RTC_TamperTrigger_RisingEdge) || \
393  ((TRIGGER) == RTC_TamperTrigger_FallingEdge))
394 
402 #define RTC_Tamper_1 RTC_TAFCR_TAMP1E
403 #define IS_RTC_TAMPER(TAMPER) (((TAMPER) == RTC_Tamper_1))
404 
412 #define RTC_TamperPin_PC13 ((uint32_t)0x00000000)
413 #define RTC_TamperPin_PI8 ((uint32_t)0x00010000)
414 #define IS_RTC_TAMPER_PIN(PIN) (((PIN) == RTC_TamperPin_PC13) || \
415  ((PIN) == RTC_TamperPin_PI8))
416 
423 #define RTC_TimeStampPin_PC13 ((uint32_t)0x00000000)
424 #define RTC_TimeStampPin_PI8 ((uint32_t)0x00020000)
425 #define IS_RTC_TIMESTAMP_PIN(PIN) (((PIN) == RTC_TimeStampPin_PC13) || \
426  ((PIN) == RTC_TimeStampPin_PI8))
427 
434 #define RTC_OutputType_OpenDrain ((uint32_t)0x00000000)
435 #define RTC_OutputType_PushPull ((uint32_t)0x00040000)
436 #define IS_RTC_OUTPUT_TYPE(TYPE) (((TYPE) == RTC_OutputType_OpenDrain) || \
437  ((TYPE) == RTC_OutputType_PushPull))
438 
447 #define RTC_BKP_DR0 ((uint32_t)0x00000000)
448 #define RTC_BKP_DR1 ((uint32_t)0x00000001)
449 #define RTC_BKP_DR2 ((uint32_t)0x00000002)
450 #define RTC_BKP_DR3 ((uint32_t)0x00000003)
451 #define RTC_BKP_DR4 ((uint32_t)0x00000004)
452 #define RTC_BKP_DR5 ((uint32_t)0x00000005)
453 #define RTC_BKP_DR6 ((uint32_t)0x00000006)
454 #define RTC_BKP_DR7 ((uint32_t)0x00000007)
455 #define RTC_BKP_DR8 ((uint32_t)0x00000008)
456 #define RTC_BKP_DR9 ((uint32_t)0x00000009)
457 #define RTC_BKP_DR10 ((uint32_t)0x0000000A)
458 #define RTC_BKP_DR11 ((uint32_t)0x0000000B)
459 #define RTC_BKP_DR12 ((uint32_t)0x0000000C)
460 #define RTC_BKP_DR13 ((uint32_t)0x0000000D)
461 #define RTC_BKP_DR14 ((uint32_t)0x0000000E)
462 #define RTC_BKP_DR15 ((uint32_t)0x0000000F)
463 #define RTC_BKP_DR16 ((uint32_t)0x00000010)
464 #define RTC_BKP_DR17 ((uint32_t)0x00000011)
465 #define RTC_BKP_DR18 ((uint32_t)0x00000012)
466 #define RTC_BKP_DR19 ((uint32_t)0x00000013)
467 #define IS_RTC_BKP(BKP) (((BKP) == RTC_BKP_DR0) || \
468  ((BKP) == RTC_BKP_DR1) || \
469  ((BKP) == RTC_BKP_DR2) || \
470  ((BKP) == RTC_BKP_DR3) || \
471  ((BKP) == RTC_BKP_DR4) || \
472  ((BKP) == RTC_BKP_DR5) || \
473  ((BKP) == RTC_BKP_DR6) || \
474  ((BKP) == RTC_BKP_DR7) || \
475  ((BKP) == RTC_BKP_DR8) || \
476  ((BKP) == RTC_BKP_DR9) || \
477  ((BKP) == RTC_BKP_DR10) || \
478  ((BKP) == RTC_BKP_DR11) || \
479  ((BKP) == RTC_BKP_DR12) || \
480  ((BKP) == RTC_BKP_DR13) || \
481  ((BKP) == RTC_BKP_DR14) || \
482  ((BKP) == RTC_BKP_DR15) || \
483  ((BKP) == RTC_BKP_DR16) || \
484  ((BKP) == RTC_BKP_DR17) || \
485  ((BKP) == RTC_BKP_DR18) || \
486  ((BKP) == RTC_BKP_DR19))
487 
494 #define RTC_Format_BIN ((uint32_t)0x000000000)
495 #define RTC_Format_BCD ((uint32_t)0x000000001)
496 #define IS_RTC_FORMAT(FORMAT) (((FORMAT) == RTC_Format_BIN) || ((FORMAT) == RTC_Format_BCD))
497 
505 #define RTC_FLAG_TAMP1F ((uint32_t)0x00002000)
506 #define RTC_FLAG_TSOVF ((uint32_t)0x00001000)
507 #define RTC_FLAG_TSF ((uint32_t)0x00000800)
508 #define RTC_FLAG_WUTF ((uint32_t)0x00000400)
509 #define RTC_FLAG_ALRBF ((uint32_t)0x00000200)
510 #define RTC_FLAG_ALRAF ((uint32_t)0x00000100)
511 #define RTC_FLAG_INITF ((uint32_t)0x00000040)
512 #define RTC_FLAG_RSF ((uint32_t)0x00000020)
513 #define RTC_FLAG_INITS ((uint32_t)0x00000010)
514 #define RTC_FLAG_WUTWF ((uint32_t)0x00000004)
515 #define RTC_FLAG_ALRBWF ((uint32_t)0x00000002)
516 #define RTC_FLAG_ALRAWF ((uint32_t)0x00000001)
517 #define IS_RTC_GET_FLAG(FLAG) (((FLAG) == RTC_FLAG_TSOVF) || ((FLAG) == RTC_FLAG_TSF) || \
518  ((FLAG) == RTC_FLAG_WUTF) || ((FLAG) == RTC_FLAG_ALRBF) || \
519  ((FLAG) == RTC_FLAG_ALRAF) || ((FLAG) == RTC_FLAG_INITF) || \
520  ((FLAG) == RTC_FLAG_RSF) || ((FLAG) == RTC_FLAG_WUTWF) || \
521  ((FLAG) == RTC_FLAG_ALRBWF) || ((FLAG) == RTC_FLAG_ALRAWF) || \
522  ((FLAG) == RTC_FLAG_TAMP1F))
523 #define IS_RTC_CLEAR_FLAG(FLAG) (((FLAG) != (uint32_t)RESET) && (((FLAG) & 0xFFFFC0DF) == (uint32_t)RESET))
524 
532 #define RTC_IT_TS ((uint32_t)0x00008000)
533 #define RTC_IT_WUT ((uint32_t)0x00004000)
534 #define RTC_IT_ALRB ((uint32_t)0x00002000)
535 #define RTC_IT_ALRA ((uint32_t)0x00001000)
536 #define RTC_IT_TAMP ((uint32_t)0x00000004) /* Used only to Enable the Tamper Interrupt */
537 #define RTC_IT_TAMP1 ((uint32_t)0x00020000)
538 
539 #define IS_RTC_CONFIG_IT(IT) (((IT) != (uint32_t)RESET) && (((IT) & 0xFFFF0FFB) == (uint32_t)RESET))
540 #define IS_RTC_GET_IT(IT) (((IT) == RTC_IT_TS) || ((IT) == RTC_IT_WUT) || \
541  ((IT) == RTC_IT_ALRB) || ((IT) == RTC_IT_ALRA) || \
542  ((IT) == RTC_IT_TAMP1))
543 #define IS_RTC_CLEAR_IT(IT) (((IT) != (uint32_t)RESET) && (((IT) & 0xFFFD0FFF) == (uint32_t)RESET))
544 
552 #define RTC_DigitalCalibConfig RTC_CoarseCalibConfig
553 #define RTC_DigitalCalibCmd RTC_CoarseCalibCmd
554 
563 /* Exported macro ------------------------------------------------------------*/
564 /* Exported functions --------------------------------------------------------*/
565 
566 /* Function used to set the RTC configuration to the default reset state *****/
567 ErrorStatus RTC_DeInit(void);
568 
569 /* Initialization and Configuration functions *********************************/
570 ErrorStatus RTC_Init(RTC_InitTypeDef* RTC_InitStruct);
571 void RTC_StructInit(RTC_InitTypeDef* RTC_InitStruct);
572 void RTC_WriteProtectionCmd(FunctionalState NewState);
573 ErrorStatus RTC_EnterInitMode(void);
574 void RTC_ExitInitMode(void);
575 ErrorStatus RTC_WaitForSynchro(void);
576 ErrorStatus RTC_RefClockCmd(FunctionalState NewState);
577 
578 /* Time and Date configuration functions **************************************/
579 ErrorStatus RTC_SetTime(uint32_t RTC_Format, RTC_TimeTypeDef* RTC_TimeStruct);
580 void RTC_TimeStructInit(RTC_TimeTypeDef* RTC_TimeStruct);
581 void RTC_GetTime(uint32_t RTC_Format, RTC_TimeTypeDef* RTC_TimeStruct);
582 ErrorStatus RTC_SetDate(uint32_t RTC_Format, RTC_DateTypeDef* RTC_DateStruct);
583 void RTC_DateStructInit(RTC_DateTypeDef* RTC_DateStruct);
584 void RTC_GetDate(uint32_t RTC_Format, RTC_DateTypeDef* RTC_DateStruct);
585 
586 /* Alarms (Alarm A and Alarm B) configuration functions **********************/
587 void RTC_SetAlarm(uint32_t RTC_Format, uint32_t RTC_Alarm, RTC_AlarmTypeDef* RTC_AlarmStruct);
588 void RTC_AlarmStructInit(RTC_AlarmTypeDef* RTC_AlarmStruct);
589 void RTC_GetAlarm(uint32_t RTC_Format, uint32_t RTC_Alarm, RTC_AlarmTypeDef* RTC_AlarmStruct);
590 ErrorStatus RTC_AlarmCmd(uint32_t RTC_Alarm, FunctionalState NewState);
591 
592 /* WakeUp Timer configuration functions ***************************************/
593 void RTC_WakeUpClockConfig(uint32_t RTC_WakeUpClock);
594 void RTC_SetWakeUpCounter(uint32_t RTC_WakeUpCounter);
595 uint32_t RTC_GetWakeUpCounter(void);
596 ErrorStatus RTC_WakeUpCmd(FunctionalState NewState);
597 
598 /* Daylight Saving configuration functions ************************************/
599 void RTC_DayLightSavingConfig(uint32_t RTC_DayLightSaving, uint32_t RTC_StoreOperation);
600 uint32_t RTC_GetStoreOperation(void);
601 
602 /* Output pin Configuration function ******************************************/
603 void RTC_OutputConfig(uint32_t RTC_Output, uint32_t RTC_OutputPolarity);
604 
605 /* Coarse Calibration configuration functions *********************************/
606 ErrorStatus RTC_CoarseCalibConfig(uint32_t RTC_CalibSign, uint32_t Value);
607 ErrorStatus RTC_CoarseCalibCmd(FunctionalState NewState);
608 void RTC_CalibOutputCmd(FunctionalState NewState);
609 
610 /* TimeStamp configuration functions ******************************************/
611 void RTC_TimeStampCmd(uint32_t RTC_TimeStampEdge, FunctionalState NewState);
612 void RTC_GetTimeStamp(uint32_t RTC_Format, RTC_TimeTypeDef* RTC_StampTimeStruct,
613  RTC_DateTypeDef* RTC_StampDateStruct);
614 
615 /* Tampers configuration functions ********************************************/
616 void RTC_TamperTriggerConfig(uint32_t RTC_Tamper, uint32_t RTC_TamperTrigger);
617 void RTC_TamperCmd(uint32_t RTC_Tamper, FunctionalState NewState);
618 
619 /* Backup Data Registers configuration functions ******************************/
620 void RTC_WriteBackupRegister(uint32_t RTC_BKP_DR, uint32_t Data);
621 uint32_t RTC_ReadBackupRegister(uint32_t RTC_BKP_DR);
622 
623 /* RTC Tamper and TimeStamp Pins Selection and Output Type Config configuration
624  functions ******************************************************************/
625 void RTC_TamperPinSelection(uint32_t RTC_TamperPin);
626 void RTC_TimeStampPinSelection(uint32_t RTC_TimeStampPin);
627 void RTC_OutputTypeConfig(uint32_t RTC_OutputType);
628 
629 /* Interrupts and flags management functions **********************************/
630 void RTC_ITConfig(uint32_t RTC_IT, FunctionalState NewState);
631 FlagStatus RTC_GetFlagStatus(uint32_t RTC_FLAG);
632 void RTC_ClearFlag(uint32_t RTC_FLAG);
633 ITStatus RTC_GetITStatus(uint32_t RTC_IT);
634 void RTC_ClearITPendingBit(uint32_t RTC_IT);
635 
636 #ifdef __cplusplus
637 }
638 #endif
639 
640 #endif /*__STM32F2xx_RTC_H */
641 
650 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/