30 #ifndef __STM32F0XX_RTC_H
31 #define __STM32F0XX_RTC_H
38 #include "stm32f0xx.h"
55 uint32_t RTC_HourFormat;
58 uint32_t RTC_AsynchPrediv;
61 uint32_t RTC_SynchPrediv;
110 uint32_t RTC_AlarmMask;
113 uint32_t RTC_AlarmDateWeekDaySel;
116 uint8_t RTC_AlarmDateWeekDay;
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))
144 #define IS_RTC_ASYNCH_PREDIV(PREDIV) ((PREDIV) <= 0x7F)
154 #define IS_RTC_SYNCH_PREDIV(PREDIV) ((PREDIV) <= 0x7FFF)
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)
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))
186 #define IS_RTC_YEAR(YEAR) ((YEAR) <= 99)
195 #define RTC_Month_January ((uint8_t)0x01)
196 #define RTC_Month_February ((uint8_t)0x02)
197 #define RTC_Month_March ((uint8_t)0x03)
198 #define RTC_Month_April ((uint8_t)0x04)
199 #define RTC_Month_May ((uint8_t)0x05)
200 #define RTC_Month_June ((uint8_t)0x06)
201 #define RTC_Month_July ((uint8_t)0x07)
202 #define RTC_Month_August ((uint8_t)0x08)
203 #define RTC_Month_September ((uint8_t)0x09)
204 #define RTC_Month_October ((uint8_t)0x10)
205 #define RTC_Month_November ((uint8_t)0x11)
206 #define RTC_Month_December ((uint8_t)0x12)
207 #define IS_RTC_MONTH(MONTH) (((MONTH) >= 1) && ((MONTH) <= 12))
208 #define IS_RTC_DATE(DATE) (((DATE) >= 1) && ((DATE) <= 31))
218 #define RTC_Weekday_Monday ((uint8_t)0x01)
219 #define RTC_Weekday_Tuesday ((uint8_t)0x02)
220 #define RTC_Weekday_Wednesday ((uint8_t)0x03)
221 #define RTC_Weekday_Thursday ((uint8_t)0x04)
222 #define RTC_Weekday_Friday ((uint8_t)0x05)
223 #define RTC_Weekday_Saturday ((uint8_t)0x6)
224 #define RTC_Weekday_Sunday ((uint8_t)0x07)
225 #define IS_RTC_WEEKDAY(WEEKDAY) (((WEEKDAY) == RTC_Weekday_Monday) || \
226 ((WEEKDAY) == RTC_Weekday_Tuesday) || \
227 ((WEEKDAY) == RTC_Weekday_Wednesday) || \
228 ((WEEKDAY) == RTC_Weekday_Thursday) || \
229 ((WEEKDAY) == RTC_Weekday_Friday) || \
230 ((WEEKDAY) == RTC_Weekday_Saturday) || \
231 ((WEEKDAY) == RTC_Weekday_Sunday))
240 #define IS_RTC_ALARM_DATE_WEEKDAY_DATE(DATE) (((DATE) > 0) && ((DATE) <= 31))
241 #define IS_RTC_ALARM_DATE_WEEKDAY_WEEKDAY(WEEKDAY) (((WEEKDAY) == RTC_Weekday_Monday) || \
242 ((WEEKDAY) == RTC_Weekday_Tuesday) || \
243 ((WEEKDAY) == RTC_Weekday_Wednesday) || \
244 ((WEEKDAY) == RTC_Weekday_Thursday) || \
245 ((WEEKDAY) == RTC_Weekday_Friday) || \
246 ((WEEKDAY) == RTC_Weekday_Saturday) || \
247 ((WEEKDAY) == RTC_Weekday_Sunday))
257 #define RTC_AlarmDateWeekDaySel_Date ((uint32_t)0x00000000)
258 #define RTC_AlarmDateWeekDaySel_WeekDay ((uint32_t)0x40000000)
260 #define IS_RTC_ALARM_DATE_WEEKDAY_SEL(SEL) (((SEL) == RTC_AlarmDateWeekDaySel_Date) || \
261 ((SEL) == RTC_AlarmDateWeekDaySel_WeekDay))
271 #define RTC_AlarmMask_None ((uint32_t)0x00000000)
272 #define RTC_AlarmMask_DateWeekDay ((uint32_t)0x80000000)
273 #define RTC_AlarmMask_Hours ((uint32_t)0x00800000)
274 #define RTC_AlarmMask_Minutes ((uint32_t)0x00008000)
275 #define RTC_AlarmMask_Seconds ((uint32_t)0x00000080)
276 #define RTC_AlarmMask_All ((uint32_t)0x80808080)
277 #define IS_RTC_ALARM_MASK(MASK) (((MASK) & 0x7F7F7F7F) == (uint32_t)RESET)
286 #define RTC_Alarm_A ((uint32_t)0x00000100)
287 #define IS_RTC_ALARM(ALARM) ((ALARM) == RTC_Alarm_A)
288 #define IS_RTC_CMD_ALARM(ALARM) (((ALARM) & (RTC_Alarm_A)) != (uint32_t)RESET)
297 #define RTC_AlarmSubSecondMask_All ((uint8_t)0x00)
300 #define RTC_AlarmSubSecondMask_SS14_1 ((uint8_t)0x01)
302 #define RTC_AlarmSubSecondMask_SS14_2 ((uint8_t)0x02)
304 #define RTC_AlarmSubSecondMask_SS14_3 ((uint8_t)0x03)
306 #define RTC_AlarmSubSecondMask_SS14_4 ((uint8_t)0x04)
308 #define RTC_AlarmSubSecondMask_SS14_5 ((uint8_t)0x05)
310 #define RTC_AlarmSubSecondMask_SS14_6 ((uint8_t)0x06)
312 #define RTC_AlarmSubSecondMask_SS14_7 ((uint8_t)0x07)
314 #define RTC_AlarmSubSecondMask_SS14_8 ((uint8_t)0x08)
316 #define RTC_AlarmSubSecondMask_SS14_9 ((uint8_t)0x09)
318 #define RTC_AlarmSubSecondMask_SS14_10 ((uint8_t)0x0A)
320 #define RTC_AlarmSubSecondMask_SS14_11 ((uint8_t)0x0B)
322 #define RTC_AlarmSubSecondMask_SS14_12 ((uint8_t)0x0C)
324 #define RTC_AlarmSubSecondMask_SS14_13 ((uint8_t)0x0D)
326 #define RTC_AlarmSubSecondMask_SS14 ((uint8_t)0x0E)
328 #define RTC_AlarmSubSecondMask_None ((uint8_t)0x0F)
330 #define IS_RTC_ALARM_SUB_SECOND_MASK(MASK) (((MASK) == RTC_AlarmSubSecondMask_All) || \
331 ((MASK) == RTC_AlarmSubSecondMask_SS14_1) || \
332 ((MASK) == RTC_AlarmSubSecondMask_SS14_2) || \
333 ((MASK) == RTC_AlarmSubSecondMask_SS14_3) || \
334 ((MASK) == RTC_AlarmSubSecondMask_SS14_4) || \
335 ((MASK) == RTC_AlarmSubSecondMask_SS14_5) || \
336 ((MASK) == RTC_AlarmSubSecondMask_SS14_6) || \
337 ((MASK) == RTC_AlarmSubSecondMask_SS14_7) || \
338 ((MASK) == RTC_AlarmSubSecondMask_SS14_8) || \
339 ((MASK) == RTC_AlarmSubSecondMask_SS14_9) || \
340 ((MASK) == RTC_AlarmSubSecondMask_SS14_10) || \
341 ((MASK) == RTC_AlarmSubSecondMask_SS14_11) || \
342 ((MASK) == RTC_AlarmSubSecondMask_SS14_12) || \
343 ((MASK) == RTC_AlarmSubSecondMask_SS14_13) || \
344 ((MASK) == RTC_AlarmSubSecondMask_SS14) || \
345 ((MASK) == RTC_AlarmSubSecondMask_None))
354 #define IS_RTC_ALARM_SUB_SECOND_VALUE(VALUE) ((VALUE) <= 0x00007FFF)
363 #define RTC_TimeStampEdge_Rising ((uint32_t)0x00000000)
364 #define RTC_TimeStampEdge_Falling ((uint32_t)0x00000008)
365 #define IS_RTC_TIMESTAMP_EDGE(EDGE) (((EDGE) == RTC_TimeStampEdge_Rising) || \
366 ((EDGE) == RTC_TimeStampEdge_Falling))
374 #define RTC_Output_Disable ((uint32_t)0x00000000)
375 #define RTC_Output_AlarmA ((uint32_t)0x00200000)
377 #define IS_RTC_OUTPUT(OUTPUT) (((OUTPUT) == RTC_Output_Disable) || \
378 ((OUTPUT) == RTC_Output_AlarmA))
387 #define RTC_OutputPolarity_High ((uint32_t)0x00000000)
388 #define RTC_OutputPolarity_Low ((uint32_t)0x00100000)
389 #define IS_RTC_OUTPUT_POL(POL) (((POL) == RTC_OutputPolarity_High) || \
390 ((POL) == RTC_OutputPolarity_Low))
399 #define RTC_CalibOutput_512Hz ((uint32_t)0x00000000)
400 #define RTC_CalibOutput_1Hz ((uint32_t)0x00080000)
401 #define IS_RTC_CALIB_OUTPUT(OUTPUT) (((OUTPUT) == RTC_CalibOutput_512Hz) || \
402 ((OUTPUT) == RTC_CalibOutput_1Hz))
410 #define RTC_SmoothCalibPeriod_32sec ((uint32_t)0x00000000)
412 #define RTC_SmoothCalibPeriod_16sec ((uint32_t)0x00002000)
414 #define RTC_SmoothCalibPeriod_8sec ((uint32_t)0x00004000)
416 #define IS_RTC_SMOOTH_CALIB_PERIOD(PERIOD) (((PERIOD) == RTC_SmoothCalibPeriod_32sec) || \
417 ((PERIOD) == RTC_SmoothCalibPeriod_16sec) || \
418 ((PERIOD) == RTC_SmoothCalibPeriod_8sec))
427 #define RTC_SmoothCalibPlusPulses_Set ((uint32_t)0x00008000)
430 #define RTC_SmoothCalibPlusPulses_Reset ((uint32_t)0x00000000)
432 #define IS_RTC_SMOOTH_CALIB_PLUS(PLUS) (((PLUS) == RTC_SmoothCalibPlusPulses_Set) || \
433 ((PLUS) == RTC_SmoothCalibPlusPulses_Reset))
442 #define IS_RTC_SMOOTH_CALIB_MINUS(VALUE) ((VALUE) <= 0x000001FF)
451 #define RTC_DayLightSaving_SUB1H ((uint32_t)0x00020000)
452 #define RTC_DayLightSaving_ADD1H ((uint32_t)0x00010000)
453 #define IS_RTC_DAYLIGHT_SAVING(SAVING) (((SAVING) == RTC_DayLightSaving_SUB1H) || \
454 ((SAVING) == RTC_DayLightSaving_ADD1H))
456 #define RTC_StoreOperation_Reset ((uint32_t)0x00000000)
457 #define RTC_StoreOperation_Set ((uint32_t)0x00040000)
458 #define IS_RTC_STORE_OPERATION(OPERATION) (((OPERATION) == RTC_StoreOperation_Reset) || \
459 ((OPERATION) == RTC_StoreOperation_Set))
467 #define RTC_TamperTrigger_RisingEdge ((uint32_t)0x00000000)
468 #define RTC_TamperTrigger_FallingEdge ((uint32_t)0x00000001)
469 #define RTC_TamperTrigger_LowLevel ((uint32_t)0x00000000)
470 #define RTC_TamperTrigger_HighLevel ((uint32_t)0x00000001)
471 #define IS_RTC_TAMPER_TRIGGER(TRIGGER) (((TRIGGER) == RTC_TamperTrigger_RisingEdge) || \
472 ((TRIGGER) == RTC_TamperTrigger_FallingEdge) || \
473 ((TRIGGER) == RTC_TamperTrigger_LowLevel) || \
474 ((TRIGGER) == RTC_TamperTrigger_HighLevel))
483 #define RTC_TamperFilter_Disable ((uint32_t)0x00000000)
485 #define RTC_TamperFilter_2Sample ((uint32_t)0x00000800)
487 #define RTC_TamperFilter_4Sample ((uint32_t)0x00001000)
489 #define RTC_TamperFilter_8Sample ((uint32_t)0x00001800)
491 #define IS_RTC_TAMPER_FILTER(FILTER) (((FILTER) == RTC_TamperFilter_Disable) || \
492 ((FILTER) == RTC_TamperFilter_2Sample) || \
493 ((FILTER) == RTC_TamperFilter_4Sample) || \
494 ((FILTER) == RTC_TamperFilter_8Sample))
502 #define RTC_TamperSamplingFreq_RTCCLK_Div32768 ((uint32_t)0x00000000)
504 #define RTC_TamperSamplingFreq_RTCCLK_Div16384 ((uint32_t)0x00000100)
506 #define RTC_TamperSamplingFreq_RTCCLK_Div8192 ((uint32_t)0x00000200)
508 #define RTC_TamperSamplingFreq_RTCCLK_Div4096 ((uint32_t)0x00000300)
510 #define RTC_TamperSamplingFreq_RTCCLK_Div2048 ((uint32_t)0x00000400)
512 #define RTC_TamperSamplingFreq_RTCCLK_Div1024 ((uint32_t)0x00000500)
514 #define RTC_TamperSamplingFreq_RTCCLK_Div512 ((uint32_t)0x00000600)
516 #define RTC_TamperSamplingFreq_RTCCLK_Div256 ((uint32_t)0x00000700)
518 #define IS_RTC_TAMPER_SAMPLING_FREQ(FREQ) (((FREQ) ==RTC_TamperSamplingFreq_RTCCLK_Div32768) || \
519 ((FREQ) ==RTC_TamperSamplingFreq_RTCCLK_Div16384) || \
520 ((FREQ) ==RTC_TamperSamplingFreq_RTCCLK_Div8192) || \
521 ((FREQ) ==RTC_TamperSamplingFreq_RTCCLK_Div4096) || \
522 ((FREQ) ==RTC_TamperSamplingFreq_RTCCLK_Div2048) || \
523 ((FREQ) ==RTC_TamperSamplingFreq_RTCCLK_Div1024) || \
524 ((FREQ) ==RTC_TamperSamplingFreq_RTCCLK_Div512) || \
525 ((FREQ) ==RTC_TamperSamplingFreq_RTCCLK_Div256))
534 #define RTC_TamperPrechargeDuration_1RTCCLK ((uint32_t)0x00000000)
536 #define RTC_TamperPrechargeDuration_2RTCCLK ((uint32_t)0x00002000)
538 #define RTC_TamperPrechargeDuration_4RTCCLK ((uint32_t)0x00004000)
540 #define RTC_TamperPrechargeDuration_8RTCCLK ((uint32_t)0x00006000)
543 #define IS_RTC_TAMPER_PRECHARGE_DURATION(DURATION) (((DURATION) == RTC_TamperPrechargeDuration_1RTCCLK) || \
544 ((DURATION) == RTC_TamperPrechargeDuration_2RTCCLK) || \
545 ((DURATION) == RTC_TamperPrechargeDuration_4RTCCLK) || \
546 ((DURATION) == RTC_TamperPrechargeDuration_8RTCCLK))
554 #define RTC_Tamper_1 RTC_TAFCR_TAMP1E
556 #define RTC_Tamper_2 RTC_TAFCR_TAMP2E
559 #define IS_RTC_TAMPER(TAMPER) ((((TAMPER) & (uint32_t)0xFFFFFFD6) == 0x00) && ((TAMPER) != (uint32_t)RESET))
568 #define RTC_OutputType_OpenDrain ((uint32_t)0x00000000)
569 #define RTC_OutputType_PushPull ((uint32_t)0x00040000)
570 #define IS_RTC_OUTPUT_TYPE(TYPE) (((TYPE) == RTC_OutputType_OpenDrain) || \
571 ((TYPE) == RTC_OutputType_PushPull))
580 #define RTC_ShiftAdd1S_Reset ((uint32_t)0x00000000)
581 #define RTC_ShiftAdd1S_Set ((uint32_t)0x80000000)
582 #define IS_RTC_SHIFT_ADD1S(SEL) (((SEL) == RTC_ShiftAdd1S_Reset) || \
583 ((SEL) == RTC_ShiftAdd1S_Set))
591 #define IS_RTC_SHIFT_SUBFS(FS) ((FS) <= 0x00007FFF)
601 #define RTC_BKP_DR0 ((uint32_t)0x00000000)
602 #define RTC_BKP_DR1 ((uint32_t)0x00000001)
603 #define RTC_BKP_DR2 ((uint32_t)0x00000002)
604 #define RTC_BKP_DR3 ((uint32_t)0x00000003)
605 #define RTC_BKP_DR4 ((uint32_t)0x00000004)
606 #define IS_RTC_BKP(BKP) (((BKP) == RTC_BKP_DR0) || \
607 ((BKP) == RTC_BKP_DR1) || \
608 ((BKP) == RTC_BKP_DR2) || \
609 ((BKP) == RTC_BKP_DR3) || \
610 ((BKP) == RTC_BKP_DR4))
618 #define RTC_Format_BIN ((uint32_t)0x000000000)
619 #define RTC_Format_BCD ((uint32_t)0x000000001)
620 #define IS_RTC_FORMAT(FORMAT) (((FORMAT) == RTC_Format_BIN) || ((FORMAT) == RTC_Format_BCD))
629 #define RTC_FLAG_RECALPF ((uint32_t)0x00010000)
630 #define RTC_FLAG_TAMP2F ((uint32_t)0x00004000)
631 #define RTC_FLAG_TAMP1F ((uint32_t)0x00002000)
632 #define RTC_FLAG_TSOVF ((uint32_t)0x00001000)
633 #define RTC_FLAG_TSF ((uint32_t)0x00000800)
634 #define RTC_FLAG_ALRAF ((uint32_t)0x00000100)
635 #define RTC_FLAG_INITF ((uint32_t)0x00000040)
636 #define RTC_FLAG_RSF ((uint32_t)0x00000020)
637 #define RTC_FLAG_INITS ((uint32_t)0x00000010)
638 #define RTC_FLAG_SHPF ((uint32_t)0x00000008)
640 #define IS_RTC_GET_FLAG(FLAG) (((FLAG) == RTC_FLAG_RECALPF) || ((FLAG) == RTC_FLAG_SHPF) || \
641 ((FLAG) == RTC_FLAG_TAMP2F) || ((FLAG) == RTC_FLAG_TAMP1F) || \
642 ((FLAG) == RTC_FLAG_TSOVF) || ((FLAG) == RTC_FLAG_TSF) || \
643 ((FLAG) == RTC_FLAG_ALRAF) || ((FLAG) == RTC_FLAG_INITF) || \
644 ((FLAG) == RTC_FLAG_RSF) || ((FLAG) == RTC_FLAG_INITS))
645 #define IS_RTC_CLEAR_FLAG(FLAG) (((FLAG) != (uint32_t)RESET) && (((FLAG) & 0xFFFF86DF) == (uint32_t)RESET))
654 #define RTC_IT_TS ((uint32_t)0x00008000)
655 #define RTC_IT_ALRA ((uint32_t)0x00001000)
656 #define RTC_IT_TAMP ((uint32_t)0x00000004)
657 #define RTC_IT_TAMP1 ((uint32_t)0x00020000)
658 #define RTC_IT_TAMP2 ((uint32_t)0x00040000)
660 #define IS_RTC_CONFIG_IT(IT) (((IT) != (uint32_t)RESET) && (((IT) & 0xFFFF6FFB) == (uint32_t)RESET))
661 #define IS_RTC_GET_IT(IT) (((IT) == RTC_IT_TS) || ((IT) == RTC_IT_ALRA) || \
662 ((IT) == RTC_IT_TAMP1) || ((IT) == RTC_IT_TAMP2))
664 #define IS_RTC_CLEAR_IT(IT) (((IT) != (uint32_t)RESET) && (((IT) & 0xFFF96FFF) == (uint32_t)RESET))
704 ErrorStatus
RTC_AlarmCmd(uint32_t RTC_Alarm, FunctionalState NewState);
705 void RTC_AlarmSubSecondConfig(uint32_t RTC_Alarm, uint32_t RTC_AlarmSubSecondValue, uint8_t RTC_AlarmSubSecondMask);
719 uint32_t RTC_SmoothCalibPlusPulses,
720 uint32_t RTC_SmouthCalibMinusPulsesValue);
723 void RTC_TimeStampCmd(uint32_t RTC_TimeStampEdge, FunctionalState NewState);
729 void RTC_TamperCmd(uint32_t RTC_Tamper, FunctionalState NewState);
747 void RTC_ITConfig(uint32_t RTC_IT, FunctionalState NewState);