41#if defined(STM32_CORE_VERSION) && (STM32_CORE_VERSION <= 0x020C0000)
42 #error "This library is not compatible with core version used. Please update the core."
46#if (!defined(HAL_RTC_MODULE_ENABLED) && (!defined(USE_HAL_RTC_MODULE) || \
47 (defined(USE_HAL_RTC_MODULE) && (USE_HAL_RTC_MODULE == 0))))
48#error "HAL RTC module is not enabled."
55#define STM32_RTC_VERSION_MAJOR (0x02U)
56#define STM32_RTC_VERSION_MINOR (0x00U)
57#define STM32_RTC_VERSION_PATCH (0x00U)
64#define STM32_RTC_VERSION_EXTRA (0x00U)
65#define STM32_RTC_VERSION ((STM32_RTC_VERSION_MAJOR << 24U)\
66 |(STM32_RTC_VERSION_MINOR << 16U)\
67 |(STM32_RTC_VERSION_PATCH << 8U )\
68 |(STM32_RTC_VERSION_EXTRA))
71#if defined(RCC_RTC_WDG_BLEWKUP_CLKSOURCE_HSI64M_DIV2048) || defined(RCC_RTC_WDG_SUBG_LPAWUR_LCD_LCSC_CLKSOURCE_DIV512)
72#define IS_CLOCK_SOURCE(SRC) (((SRC) == STM32RTC::LSI_CLOCK) || ((SRC) == STM32RTC::LSE_CLOCK) ||\
73 ((SRC) == STM32RTC::HSI_CLOCK))
75#define IS_CLOCK_SOURCE(SRC) (((SRC) == STM32RTC::LSI_CLOCK) || ((SRC) == STM32RTC::LSE_CLOCK) ||\
76 ((SRC) == STM32RTC::HSE_CLOCK))
78#define IS_HOUR_FORMAT(FMT) (((FMT) == STM32RTC::HOUR_12) || ((FMT) == STM32RTC::HOUR_24))
125#if defined(RCC_RTC_WDG_BLEWKUP_CLKSOURCE_HSI64M_DIV2048) || defined(RCC_RTC_WDG_SUBG_LPAWUR_LCD_LCSC_CLKSOURCE_DIV512)
126 HSI_CLOCK = ::HSI_CLOCK,
135#if defined(ALARM_B_AVAILABLE)
169#if !defined(USE_HALV2_DRIVER)
177 return RTC_GetHandle();
258 void attachSecondsInterrupt(voidFuncPtrParam callback);
260 void detachSecondsInterrupt(
void);
270 void attachSubSecondsUnderflowInterrupt(voidFuncPtrParam callback);
272 void detachSubSecondsUnderflowInterrupt(
void);
309 void getTime(uint8_t *hours, uint8_t *minutes, uint8_t *seconds, uint32_t *subSeconds,
AM_PM *period =
nullptr);
338 void getDate(uint8_t *weekDay, uint8_t *day, uint8_t *month, uint8_t *year);
422 void setTime(uint8_t hours, uint8_t minutes, uint8_t seconds, uint32_t subSeconds = 1000,
AM_PM period =
AM);
450 void setDate(uint8_t day, uint8_t month, uint8_t year);
458 void setDate(uint8_t weekDay, uint8_t day, uint8_t month, uint8_t year);
513 void setAlarmTime(uint8_t hours, uint8_t minutes, uint8_t seconds, uint32_t subSeconds,
Alarm name);
611 return RTC_IsConfigured();
644 static bool _timeSet;
652 uint32_t _subSeconds;
661 uint8_t _alarmMinutes;
662 uint8_t _alarmSeconds;
663 uint32_t _alarmSubSeconds;
667#if defined(ALARM_B_AVAILABLE)
670 uint8_t _alarmBHours;
671 uint8_t _alarmBMinutes;
672 uint8_t _alarmBSeconds;
673 uint32_t _alarmBSubSeconds;
void attachInterrupt(voidFuncPtrParam callback, void *data=nullptr, Alarm name=ALARM_A)
Attaches a callback and user data to an RTC alarm.
uint8_t getAlarmDay(Alarm name=ALARM_A)
Returns the alarm day of the month.
void setAlarmDay(uint8_t day, Alarm name=ALARM_A)
Sets the alarm day of the month.
void setAlarmTime(uint8_t hours, uint8_t minutes, uint8_t seconds, uint32_t subSeconds=0, AM_PM period=AM, Alarm name=ALARM_A)
Sets an alarm time.
void setAlarmDate(uint8_t day, uint8_t month, uint8_t year, Alarm name=ALARM_A)
Sets the alarm day; the month and year are ignored.
void detachInterrupt(Alarm name=ALARM_A)
Detaches the callback from an RTC alarm.
void getTime(uint8_t *hours, uint8_t *minutes, uint8_t *seconds, uint32_t *subSeconds, AM_PM *period=nullptr)
Reads the current time.
uint32_t getSubSeconds(void)
Returns the current subsecond value in milliseconds.
void disableAlarm(Alarm name=ALARM_A)
Disables an RTC alarm.
bool isAlarmEnabled(Alarm name=ALARM_A)
Reports whether the selected alarm is enabled.
void setTime(uint8_t hours, uint8_t minutes, uint8_t seconds, uint32_t subSeconds=1000, AM_PM period=AM)
Sets the current time.
void setAlarmTime(uint8_t hours, uint8_t minutes, uint8_t seconds, uint32_t subSeconds, Alarm name)
Sets an alarm time and subsecond value.
void setBinaryMode(Binary_Mode mode)
Selects BCD, binary, or mixed RTC operation.
Binary_Mode
Selects BCD, binary, or combined RTC mode.
Definition STM32RTC.h:101
@ MODE_BIN
Definition STM32RTC.h:103
@ MODE_BCD
Definition STM32RTC.h:102
@ MODE_MIX
Definition STM32RTC.h:104
Alarm
Identifies an RTC alarm.
Definition STM32RTC.h:133
@ ALARM_A
Definition STM32RTC.h:134
void setWeekDay(uint8_t weekDay)
Sets the current weekday.
uint8_t getDay(void)
Returns the current day of the month.
void setAlarmHours(uint8_t hours, AM_PM period=AM, Alarm name=ALARM_A)
Sets the alarm hours value and optional AM/PM period.
uint8_t getYear(void)
Returns the current year value.
void setAlarmSubSeconds(uint32_t subSeconds, Alarm name=ALARM_A)
Sets the alarm subsecond value in milliseconds.
void setAlarmEpoch(time_t ts, Alarm_Match match=MATCH_DHHMMSS, uint32_t subSeconds=0, Alarm name=ALARM_A)
Configures an alarm from an epoch timestamp.
void setAlarmSeconds(uint8_t seconds, Alarm name=ALARM_A)
Sets the alarm seconds value.
bool isFormat_24hour(void)
Reports whether the current hour format is 24-hour.
Definition STM32RTC.h:617
bool isConfigured(void)
Reports whether the RTC peripheral is configured.
Definition STM32RTC.h:609
uint8_t getWeekDay(void)
Returns the current weekday.
uint8_t getAlarmYear(void)
Returns zero; STM32 RTC alarms do not match a year.
void setClockSource(Source_Clock source, uint32_t predivA=(PREDIVA_MAX+1), uint32_t predivS=(PREDIVS_MAX+1))
Selects the RTC clock source and its prescalers.
uint8_t getSeconds(void)
Returns the current seconds value.
uint8_t getAlarmMonth(void)
Returns zero; STM32 RTC alarms do not match a month.
void operator=(STM32RTC const &)=delete
void setSubSeconds(uint32_t subSeconds)
Sets the current subsecond value in milliseconds.
uint32_t getAlarmSubSeconds(Alarm name=ALARM_A)
Returns the alarm subsecond value in milliseconds.
void setYear(uint8_t year)
Sets the current year value.
uint8_t getHours(AM_PM *period=nullptr)
Returns the current hours value.
void setAlarmYear(uint8_t year)
Compatibility method; the year is ignored by STM32 RTC alarms.
void setHours(uint8_t hours, AM_PM period=AM)
Sets the current hour value and optional AM/PM period.
RTC_HandleTypeDef * getHandle(void)
Returns the STM32 HAL RTC handle.
Definition STM32RTC.h:175
void setSeconds(uint8_t seconds)
Sets the current seconds value.
void setAlarmEpoch(time_t ts, Alarm_Match match, Alarm name)
Configures an alarm from an epoch timestamp.
uint8_t getMinutes(void)
Returns the current minutes value.
uint8_t getAlarmHours(AM_PM *period=nullptr, Alarm name=ALARM_A)
Returns the alarm hours value and optionally its AM/PM period.
time_t getEpoch(uint32_t *subSeconds=nullptr)
Returns the current Unix epoch time.
Source_Clock
Selects the input clock source for the RTC.
Definition STM32RTC.h:122
@ HSE_CLOCK
Definition STM32RTC.h:128
@ LSI_CLOCK
Definition STM32RTC.h:123
@ LSE_CLOCK
Definition STM32RTC.h:124
Source_Clock getClockSource(void)
Returns the selected RTC input clock source.
friend class STM32LowPower
Definition STM32RTC.h:636
void setAlarmTime(uint8_t hours, uint8_t minutes, uint8_t seconds, Alarm name)
Sets an alarm time without a subsecond value.
void setMonth(uint8_t month)
Sets the current month.
void setMinutes(uint8_t minutes)
Sets the current minutes value.
uint8_t getAlarmHours(Alarm name)
Returns the alarm hours value.
time_t getAlarmEpoch(Alarm name)
Returns the configured alarm's epoch timestamp.
void setDay(uint8_t day)
Sets the current day of the month.
void setAlarmHours(uint8_t hours, Alarm name)
Sets the alarm hours value.
void getDate(uint8_t *weekDay, uint8_t *day, uint8_t *month, uint8_t *year)
Reads the current date.
static STM32RTC & getInstance()
Returns the singleton RTC controller.
Definition STM32RTC.h:144
void setAlarmMinutes(uint8_t minutes, Alarm name=ALARM_A)
Sets the alarm minutes value.
void getPrediv(uint32_t *predivA, uint32_t *predivS)
Reads the configured or calculated RTC prescalers.
void begin(Hour_Format format=HOUR_24)
Initializes the RTC without resetting its current time.
void setEpoch(time_t ts, uint32_t subSeconds=0)
Sets the RTC from a Unix epoch timestamp.
AM_PM
Selects the AM or PM period in 12-hour format.
Definition STM32RTC.h:95
@ PM
Definition STM32RTC.h:97
@ AM
Definition STM32RTC.h:96
void begin(bool resetTime, Hour_Format format=HOUR_24)
Initializes the RTC and optionally resets its time.
void setPrediv(uint32_t predivA, uint32_t predivS)
Sets the RTC prescalers.
Alarm_Match
Selects which RTC fields must match for an alarm.
Definition STM32RTC.h:108
@ MATCH_DHHMMSS
Definition STM32RTC.h:114
@ MATCH_YYMMDDHHMMSS
Definition STM32RTC.h:118
@ MATCH_SS
Definition STM32RTC.h:111
@ MATCH_HHMMSS
Definition STM32RTC.h:113
@ MATCH_SUBSEC
Definition STM32RTC.h:110
@ MATCH_OFF
Definition STM32RTC.h:109
@ MATCH_MMDDHHMMSS
Definition STM32RTC.h:117
@ MATCH_MMSS
Definition STM32RTC.h:112
void setAlarmMonth(uint8_t month)
Compatibility method; the month is ignored by STM32 RTC alarms.
Binary_Mode getBinaryMode(void)
Returns the current RTC operating mode.
STM32RTC(STM32RTC const &)=delete
void end(void)
Deinitializes the RTC and clears registered callbacks.
void setDate(uint8_t day, uint8_t month, uint8_t year)
Sets the current date without changing the weekday.
uint8_t getAlarmMinutes(Alarm name=ALARM_A)
Returns the alarm minutes value.
uint8_t getAlarmSeconds(Alarm name=ALARM_A)
Returns the alarm seconds value.
void setY2kEpoch(time_t ts)
Sets the RTC from seconds since the Y2K epoch.
void setDate(uint8_t weekDay, uint8_t day, uint8_t month, uint8_t year)
Sets the current weekday and date.
bool isTimeSet(void)
Reports whether the library has set the current time.
Definition STM32RTC.h:631
void attachInterrupt(voidFuncPtrParam callback, Alarm name)
Attaches a callback to an RTC alarm.
Hour_Format
Selects the RTC hour display format.
Definition STM32RTC.h:89
@ HOUR_24
Definition STM32RTC.h:91
@ HOUR_12
Definition STM32RTC.h:90
void standbyMode()
Compatibility method; use the STM32LowPower library for standby mode.
time_t getAlarmEpoch(uint32_t *subSeconds=nullptr, Alarm name=ALARM_A)
Returns the configured alarm's epoch timestamp.
void enableAlarm(Alarm_Match match, Alarm name=ALARM_A)
Enables an RTC alarm with the requested match fields.
uint8_t getMonth(void)
Returns the current month.
void setAlarmTime(uint32_t subSeconds, Alarm name=ALARM_A)
Sets an alarm using a subsecond value.
time_t getY2kEpoch(void)
Returns the current time as seconds since the Y2K epoch.