21 #ifndef __STM32F4xx_HAL_RTC_H
22 #define __STM32F4xx_HAL_RTC_H
162 #if (USE_HAL_RTC_REGISTER_CALLBACKS == 1)
163 typedef struct __RTC_HandleTypeDef
176 #if (USE_HAL_RTC_REGISTER_CALLBACKS == 1)
177 void (* AlarmAEventCallback) (
struct __RTC_HandleTypeDef * hrtc);
179 void (* AlarmBEventCallback) (
struct __RTC_HandleTypeDef * hrtc);
181 void (* TimeStampEventCallback) (
struct __RTC_HandleTypeDef * hrtc);
183 void (* WakeUpTimerEventCallback) (
struct __RTC_HandleTypeDef * hrtc);
185 void (* Tamper1EventCallback) (
struct __RTC_HandleTypeDef * hrtc);
187 void (* Tamper2EventCallback) (
struct __RTC_HandleTypeDef * hrtc);
189 void (* MspInitCallback) (
struct __RTC_HandleTypeDef * hrtc);
191 void (* MspDeInitCallback) (
struct __RTC_HandleTypeDef * hrtc);
197 #if (USE_HAL_RTC_REGISTER_CALLBACKS == 1)
203 HAL_RTC_ALARM_A_EVENT_CB_ID = 0x00u,
204 HAL_RTC_ALARM_B_EVENT_CB_ID = 0x01u,
205 HAL_RTC_TIMESTAMP_EVENT_CB_ID = 0x02u,
206 HAL_RTC_WAKEUPTIMER_EVENT_CB_ID = 0x03u,
207 HAL_RTC_TAMPER1_EVENT_CB_ID = 0x04u,
208 HAL_RTC_TAMPER2_EVENT_CB_ID = 0x05u,
209 HAL_RTC_MSPINIT_CB_ID = 0x0Eu,
210 HAL_RTC_MSPDEINIT_CB_ID = 0x0Fu
211 }HAL_RTC_CallbackIDTypeDef;
231 #define RTC_HOURFORMAT_24 0x00000000U
232 #define RTC_HOURFORMAT_12 0x00000040U
240 #define RTC_OUTPUT_DISABLE 0x00000000U
241 #define RTC_OUTPUT_ALARMA 0x00200000U
242 #define RTC_OUTPUT_ALARMB 0x00400000U
243 #define RTC_OUTPUT_WAKEUP 0x00600000U
251 #define RTC_OUTPUT_POLARITY_HIGH 0x00000000U
252 #define RTC_OUTPUT_POLARITY_LOW 0x00100000U
260 #define RTC_OUTPUT_TYPE_OPENDRAIN 0x00000000U
261 #define RTC_OUTPUT_TYPE_PUSHPULL 0x00040000U
269 #define RTC_HOURFORMAT12_AM ((uint8_t)0x00)
270 #define RTC_HOURFORMAT12_PM ((uint8_t)0x40)
278 #define RTC_DAYLIGHTSAVING_SUB1H 0x00020000U
279 #define RTC_DAYLIGHTSAVING_ADD1H 0x00010000U
280 #define RTC_DAYLIGHTSAVING_NONE 0x00000000U
288 #define RTC_STOREOPERATION_RESET 0x00000000U
289 #define RTC_STOREOPERATION_SET 0x00040000U
297 #define RTC_FORMAT_BIN 0x00000000U
298 #define RTC_FORMAT_BCD 0x00000001U
307 #define RTC_MONTH_JANUARY ((uint8_t)0x01)
308 #define RTC_MONTH_FEBRUARY ((uint8_t)0x02)
309 #define RTC_MONTH_MARCH ((uint8_t)0x03)
310 #define RTC_MONTH_APRIL ((uint8_t)0x04)
311 #define RTC_MONTH_MAY ((uint8_t)0x05)
312 #define RTC_MONTH_JUNE ((uint8_t)0x06)
313 #define RTC_MONTH_JULY ((uint8_t)0x07)
314 #define RTC_MONTH_AUGUST ((uint8_t)0x08)
315 #define RTC_MONTH_SEPTEMBER ((uint8_t)0x09)
316 #define RTC_MONTH_OCTOBER ((uint8_t)0x10)
317 #define RTC_MONTH_NOVEMBER ((uint8_t)0x11)
318 #define RTC_MONTH_DECEMBER ((uint8_t)0x12)
326 #define RTC_WEEKDAY_MONDAY ((uint8_t)0x01)
327 #define RTC_WEEKDAY_TUESDAY ((uint8_t)0x02)
328 #define RTC_WEEKDAY_WEDNESDAY ((uint8_t)0x03)
329 #define RTC_WEEKDAY_THURSDAY ((uint8_t)0x04)
330 #define RTC_WEEKDAY_FRIDAY ((uint8_t)0x05)
331 #define RTC_WEEKDAY_SATURDAY ((uint8_t)0x06)
332 #define RTC_WEEKDAY_SUNDAY ((uint8_t)0x07)
340 #define RTC_ALARMDATEWEEKDAYSEL_DATE 0x00000000U
341 #define RTC_ALARMDATEWEEKDAYSEL_WEEKDAY 0x40000000U
349 #define RTC_ALARMMASK_NONE 0x00000000U
350 #define RTC_ALARMMASK_DATEWEEKDAY RTC_ALRMAR_MSK4
351 #define RTC_ALARMMASK_HOURS RTC_ALRMAR_MSK3
352 #define RTC_ALARMMASK_MINUTES RTC_ALRMAR_MSK2
353 #define RTC_ALARMMASK_SECONDS RTC_ALRMAR_MSK1
354 #define RTC_ALARMMASK_ALL 0x80808080U
362 #define RTC_ALARM_A RTC_CR_ALRAE
363 #define RTC_ALARM_B RTC_CR_ALRBE
371 #define RTC_ALARMSUBSECONDMASK_ALL 0x00000000U
374 #define RTC_ALARMSUBSECONDMASK_SS14_1 0x01000000U
376 #define RTC_ALARMSUBSECONDMASK_SS14_2 0x02000000U
378 #define RTC_ALARMSUBSECONDMASK_SS14_3 0x03000000U
380 #define RTC_ALARMSUBSECONDMASK_SS14_4 0x04000000U
382 #define RTC_ALARMSUBSECONDMASK_SS14_5 0x05000000U
384 #define RTC_ALARMSUBSECONDMASK_SS14_6 0x06000000U
386 #define RTC_ALARMSUBSECONDMASK_SS14_7 0x07000000U
388 #define RTC_ALARMSUBSECONDMASK_SS14_8 0x08000000U
390 #define RTC_ALARMSUBSECONDMASK_SS14_9 0x09000000U
392 #define RTC_ALARMSUBSECONDMASK_SS14_10 0x0A000000U
394 #define RTC_ALARMSUBSECONDMASK_SS14_11 0x0B000000U
396 #define RTC_ALARMSUBSECONDMASK_SS14_12 0x0C000000U
398 #define RTC_ALARMSUBSECONDMASK_SS14_13 0x0D000000U
400 #define RTC_ALARMSUBSECONDMASK_SS14 0x0E000000U
402 #define RTC_ALARMSUBSECONDMASK_NONE 0x0F000000U
411 #define RTC_IT_TS 0x00008000U
412 #define RTC_IT_WUT 0x00004000U
413 #define RTC_IT_ALRB 0x00002000U
414 #define RTC_IT_ALRA 0x00001000U
415 #define RTC_IT_TAMP 0x00000004U
416 #define RTC_IT_TAMP1 0x00020000U
417 #define RTC_IT_TAMP2 0x00040000U
425 #define RTC_FLAG_RECALPF 0x00010000U
426 #define RTC_FLAG_TAMP2F 0x00004000U
427 #define RTC_FLAG_TAMP1F 0x00002000U
428 #define RTC_FLAG_TSOVF 0x00001000U
429 #define RTC_FLAG_TSF 0x00000800U
430 #define RTC_FLAG_WUTF 0x00000400U
431 #define RTC_FLAG_ALRBF 0x00000200U
432 #define RTC_FLAG_ALRAF 0x00000100U
433 #define RTC_FLAG_INITF 0x00000040U
434 #define RTC_FLAG_RSF 0x00000020U
435 #define RTC_FLAG_INITS 0x00000010U
436 #define RTC_FLAG_SHPF 0x00000008U
437 #define RTC_FLAG_WUTWF 0x00000004U
438 #define RTC_FLAG_ALRBWF 0x00000002U
439 #define RTC_FLAG_ALRAWF 0x00000001U
457 #if (USE_HAL_RTC_REGISTER_CALLBACKS == 1)
458 #define __HAL_RTC_RESET_HANDLE_STATE(__HANDLE__) do{\
459 (__HANDLE__)->State = HAL_RTC_STATE_RESET;\
460 (__HANDLE__)->MspInitCallback = NULL;\
461 (__HANDLE__)->MspDeInitCallback = NULL;\
464 #define __HAL_RTC_RESET_HANDLE_STATE(__HANDLE__) ((__HANDLE__)->State = HAL_RTC_STATE_RESET)
472 #define __HAL_RTC_WRITEPROTECTION_DISABLE(__HANDLE__) \
474 (__HANDLE__)->Instance->WPR = 0xCAU; \
475 (__HANDLE__)->Instance->WPR = 0x53U; \
483 #define __HAL_RTC_WRITEPROTECTION_ENABLE(__HANDLE__) \
485 (__HANDLE__)->Instance->WPR = 0xFFU; \
493 #define __HAL_RTC_ALARMA_ENABLE(__HANDLE__) ((__HANDLE__)->Instance->CR |= (RTC_CR_ALRAE))
500 #define __HAL_RTC_ALARMA_DISABLE(__HANDLE__) ((__HANDLE__)->Instance->CR &= ~(RTC_CR_ALRAE))
507 #define __HAL_RTC_ALARMB_ENABLE(__HANDLE__) ((__HANDLE__)->Instance->CR |= (RTC_CR_ALRBE))
514 #define __HAL_RTC_ALARMB_DISABLE(__HANDLE__) ((__HANDLE__)->Instance->CR &= ~(RTC_CR_ALRBE))
525 #define __HAL_RTC_ALARM_ENABLE_IT(__HANDLE__, __INTERRUPT__) ((__HANDLE__)->Instance->CR |= (__INTERRUPT__))
536 #define __HAL_RTC_ALARM_DISABLE_IT(__HANDLE__, __INTERRUPT__) ((__HANDLE__)->Instance->CR &= ~(__INTERRUPT__))
547 #define __HAL_RTC_ALARM_GET_IT(__HANDLE__, __INTERRUPT__) (((((__HANDLE__)->Instance->ISR)& ((__INTERRUPT__)>> 4U)) != RESET)? SET : RESET)
560 #define __HAL_RTC_ALARM_GET_FLAG(__HANDLE__, __FLAG__) (((((__HANDLE__)->Instance->ISR) & (__FLAG__)) != RESET)? SET : RESET)
571 #define __HAL_RTC_ALARM_CLEAR_FLAG(__HANDLE__, __FLAG__) ((__HANDLE__)->Instance->ISR) = (~((__FLAG__) | RTC_ISR_INIT)|((__HANDLE__)->Instance->ISR & RTC_ISR_INIT))
583 #define __HAL_RTC_ALARM_GET_IT_SOURCE(__HANDLE__, __INTERRUPT__) (((((__HANDLE__)->Instance->CR) & (__INTERRUPT__)) != RESET) ? SET : RESET)
589 #define __HAL_RTC_ALARM_EXTI_ENABLE_IT() (EXTI->IMR |= RTC_EXTI_LINE_ALARM_EVENT)
595 #define __HAL_RTC_ALARM_EXTI_DISABLE_IT() (EXTI->IMR &= ~(RTC_EXTI_LINE_ALARM_EVENT))
601 #define __HAL_RTC_ALARM_EXTI_ENABLE_EVENT() (EXTI->EMR |= RTC_EXTI_LINE_ALARM_EVENT)
607 #define __HAL_RTC_ALARM_EXTI_DISABLE_EVENT() (EXTI->EMR &= ~(RTC_EXTI_LINE_ALARM_EVENT))
613 #define __HAL_RTC_ALARM_EXTI_ENABLE_FALLING_EDGE() (EXTI->FTSR |= RTC_EXTI_LINE_ALARM_EVENT)
619 #define __HAL_RTC_ALARM_EXTI_DISABLE_FALLING_EDGE() (EXTI->FTSR &= ~(RTC_EXTI_LINE_ALARM_EVENT))
625 #define __HAL_RTC_ALARM_EXTI_ENABLE_RISING_EDGE() (EXTI->RTSR |= RTC_EXTI_LINE_ALARM_EVENT)
631 #define __HAL_RTC_ALARM_EXTI_DISABLE_RISING_EDGE() (EXTI->RTSR &= ~(RTC_EXTI_LINE_ALARM_EVENT))
637 #define __HAL_RTC_ALARM_EXTI_ENABLE_RISING_FALLING_EDGE() do { __HAL_RTC_ALARM_EXTI_ENABLE_RISING_EDGE(); \
638 __HAL_RTC_ALARM_EXTI_ENABLE_FALLING_EDGE();\
645 #define __HAL_RTC_ALARM_EXTI_DISABLE_RISING_FALLING_EDGE() do { __HAL_RTC_ALARM_EXTI_DISABLE_RISING_EDGE();\
646 __HAL_RTC_ALARM_EXTI_DISABLE_FALLING_EDGE();\
653 #define __HAL_RTC_ALARM_EXTI_GET_FLAG() (EXTI->PR & RTC_EXTI_LINE_ALARM_EVENT)
659 #define __HAL_RTC_ALARM_EXTI_CLEAR_FLAG() (EXTI->PR = RTC_EXTI_LINE_ALARM_EVENT)
665 #define __HAL_RTC_ALARM_EXTI_GENERATE_SWIT() (EXTI->SWIER |= RTC_EXTI_LINE_ALARM_EVENT)
688 #if (USE_HAL_RTC_REGISTER_CALLBACKS == 1)
752 #define RTC_TR_RESERVED_MASK 0x007F7F7FU
753 #define RTC_DR_RESERVED_MASK 0x00FFFF3FU
754 #define RTC_INIT_MASK 0xFFFFFFFFU
755 #define RTC_RSF_MASK 0xFFFFFF5FU
756 #define RTC_FLAGS_MASK ((uint32_t)(RTC_FLAG_TSOVF | RTC_FLAG_TSF | RTC_FLAG_WUTF | \
757 RTC_FLAG_ALRBF | RTC_FLAG_ALRAF | RTC_FLAG_INITF | \
758 RTC_FLAG_RSF | RTC_FLAG_INITS | RTC_FLAG_WUTWF | \
759 RTC_FLAG_ALRBWF | RTC_FLAG_ALRAWF | RTC_FLAG_TAMP1F | \
760 RTC_FLAG_RECALPF | RTC_FLAG_SHPF))
762 #define RTC_TIMEOUT_VALUE 1000
764 #define RTC_EXTI_LINE_ALARM_EVENT ((uint32_t)EXTI_IMR_MR17)
777 #define IS_RTC_HOUR_FORMAT(FORMAT) (((FORMAT) == RTC_HOURFORMAT_12) || \
778 ((FORMAT) == RTC_HOURFORMAT_24))
779 #define IS_RTC_OUTPUT(OUTPUT) (((OUTPUT) == RTC_OUTPUT_DISABLE) || \
780 ((OUTPUT) == RTC_OUTPUT_ALARMA) || \
781 ((OUTPUT) == RTC_OUTPUT_ALARMB) || \
782 ((OUTPUT) == RTC_OUTPUT_WAKEUP))
783 #define IS_RTC_OUTPUT_POL(POL) (((POL) == RTC_OUTPUT_POLARITY_HIGH) || \
784 ((POL) == RTC_OUTPUT_POLARITY_LOW))
785 #define IS_RTC_OUTPUT_TYPE(TYPE) (((TYPE) == RTC_OUTPUT_TYPE_OPENDRAIN) || \
786 ((TYPE) == RTC_OUTPUT_TYPE_PUSHPULL))
787 #define IS_RTC_HOUR12(HOUR) (((HOUR) > 0U) && ((HOUR) <= 12U))
788 #define IS_RTC_HOUR24(HOUR) ((HOUR) <= 23U)
789 #define IS_RTC_ASYNCH_PREDIV(PREDIV) ((PREDIV) <= 0x7FU)
790 #define IS_RTC_SYNCH_PREDIV(PREDIV) ((PREDIV) <= 0x7FFFU)
791 #define IS_RTC_MINUTES(MINUTES) ((MINUTES) <= 59U)
792 #define IS_RTC_SECONDS(SECONDS) ((SECONDS) <= 59U)
794 #define IS_RTC_HOURFORMAT12(PM) (((PM) == RTC_HOURFORMAT12_AM) || ((PM) == RTC_HOURFORMAT12_PM))
795 #define IS_RTC_DAYLIGHT_SAVING(SAVE) (((SAVE) == RTC_DAYLIGHTSAVING_SUB1H) || \
796 ((SAVE) == RTC_DAYLIGHTSAVING_ADD1H) || \
797 ((SAVE) == RTC_DAYLIGHTSAVING_NONE))
798 #define IS_RTC_STORE_OPERATION(OPERATION) (((OPERATION) == RTC_STOREOPERATION_RESET) || \
799 ((OPERATION) == RTC_STOREOPERATION_SET))
800 #define IS_RTC_FORMAT(FORMAT) (((FORMAT) == RTC_FORMAT_BIN) || ((FORMAT) == RTC_FORMAT_BCD))
801 #define IS_RTC_YEAR(YEAR) ((YEAR) <= 99U)
802 #define IS_RTC_MONTH(MONTH) (((MONTH) >= 1U) && ((MONTH) <= 12U))
803 #define IS_RTC_DATE(DATE) (((DATE) >= 1U) && ((DATE) <= 31U))
804 #define IS_RTC_WEEKDAY(WEEKDAY) (((WEEKDAY) == RTC_WEEKDAY_MONDAY) || \
805 ((WEEKDAY) == RTC_WEEKDAY_TUESDAY) || \
806 ((WEEKDAY) == RTC_WEEKDAY_WEDNESDAY) || \
807 ((WEEKDAY) == RTC_WEEKDAY_THURSDAY) || \
808 ((WEEKDAY) == RTC_WEEKDAY_FRIDAY) || \
809 ((WEEKDAY) == RTC_WEEKDAY_SATURDAY) || \
810 ((WEEKDAY) == RTC_WEEKDAY_SUNDAY))
811 #define IS_RTC_ALARM_DATE_WEEKDAY_DATE(DATE) (((DATE) > 0U) && ((DATE) <= 31U))
812 #define IS_RTC_ALARM_DATE_WEEKDAY_WEEKDAY(WEEKDAY) (((WEEKDAY) == RTC_WEEKDAY_MONDAY) || \
813 ((WEEKDAY) == RTC_WEEKDAY_TUESDAY) || \
814 ((WEEKDAY) == RTC_WEEKDAY_WEDNESDAY) || \
815 ((WEEKDAY) == RTC_WEEKDAY_THURSDAY) || \
816 ((WEEKDAY) == RTC_WEEKDAY_FRIDAY) || \
817 ((WEEKDAY) == RTC_WEEKDAY_SATURDAY) || \
818 ((WEEKDAY) == RTC_WEEKDAY_SUNDAY))
819 #define IS_RTC_ALARM_DATE_WEEKDAY_SEL(SEL) (((SEL) == RTC_ALARMDATEWEEKDAYSEL_DATE) || \
820 ((SEL) == RTC_ALARMDATEWEEKDAYSEL_WEEKDAY))
821 #define IS_RTC_ALARM_MASK(MASK) (((MASK) & 0x7F7F7F7FU) == (uint32_t)RESET)
822 #define IS_RTC_ALARM(ALARM) (((ALARM) == RTC_ALARM_A) || ((ALARM) == RTC_ALARM_B))
823 #define IS_RTC_ALARM_SUB_SECOND_VALUE(VALUE) ((VALUE) <= 0x00007FFFU)
825 #define IS_RTC_ALARM_SUB_SECOND_MASK(MASK) (((MASK) == RTC_ALARMSUBSECONDMASK_ALL) || \
826 ((MASK) == RTC_ALARMSUBSECONDMASK_SS14_1) || \
827 ((MASK) == RTC_ALARMSUBSECONDMASK_SS14_2) || \
828 ((MASK) == RTC_ALARMSUBSECONDMASK_SS14_3) || \
829 ((MASK) == RTC_ALARMSUBSECONDMASK_SS14_4) || \
830 ((MASK) == RTC_ALARMSUBSECONDMASK_SS14_5) || \
831 ((MASK) == RTC_ALARMSUBSECONDMASK_SS14_6) || \
832 ((MASK) == RTC_ALARMSUBSECONDMASK_SS14_7) || \
833 ((MASK) == RTC_ALARMSUBSECONDMASK_SS14_8) || \
834 ((MASK) == RTC_ALARMSUBSECONDMASK_SS14_9) || \
835 ((MASK) == RTC_ALARMSUBSECONDMASK_SS14_10) || \
836 ((MASK) == RTC_ALARMSUBSECONDMASK_SS14_11) || \
837 ((MASK) == RTC_ALARMSUBSECONDMASK_SS14_12) || \
838 ((MASK) == RTC_ALARMSUBSECONDMASK_SS14_13) || \
839 ((MASK) == RTC_ALARMSUBSECONDMASK_SS14) || \
840 ((MASK) == RTC_ALARMSUBSECONDMASK_NONE))