TM STM32Fxxx HAL Libraries  v1.0.0
Libraries for STM32Fxxx (F0, F4 and F7 series) devices based on HAL drivers from ST from Tilen Majerle
tm_stm32_rtc.h
1 
37 #ifndef TM_RTC_H
38 #define TM_RTC_H 100
39 
40 /* C++ detection */
41 #ifdef __cplusplus
42 extern "C" {
43 #endif
44 
98 #include "stm32fxxx_hal.h"
99 #include "defines.h"
100 #include "attributes.h"
101 
111 /* RTC clock is: f_clk = RTCCLK(LSI or LSE) / ((RTC_SYNC_PREDIV + 1) * (RTC_ASYNC_PREDIV + 1)) */
112 /* Sync pre division for clock */
113 #ifndef RTC_SYNC_PREDIV
114 #define RTC_SYNC_PREDIV 0x3FF
115 #endif
116 /* Async pre division for clock */
117 #ifndef RTC_ASYNC_PREDIV
118 #define RTC_ASYNC_PREDIV 0x1F
119 #endif
120 /* NVIC global Priority set */
121 #ifndef RTC_NVIC_PRIORITY
122 #define RTC_NVIC_PRIORITY 0x04
123 #endif
124 /* Sub priority for wakeup trigger */
125 #ifndef RTC_NVIC_WAKEUP_SUBPRIORITY
126 #define RTC_NVIC_WAKEUP_SUBPRIORITY 0x00
127 #endif
128 /* Sub priority for alarm trigger */
129 #ifndef RTC_NVIC_ALARM_SUBPRIORITY
130 #define RTC_NVIC_ALARM_SUBPRIORITY 0x01
131 #endif
132 
146 typedef struct {
147  uint8_t Seconds;
148  uint16_t Subseconds;
150  uint8_t Minutes;
151  uint8_t Hours;
152  uint8_t WeekDay;
153  uint8_t Day;
154  uint8_t Month;
155  uint8_t Year;
156  uint32_t Unix;
157 } TM_RTC_t;
158 
162 typedef enum {
166 
170 typedef enum {
174 
178 typedef enum {
190 } TM_RTC_Int_t;
191 
196 typedef enum {
200 
204 typedef enum {
208 
212 typedef enum {
213  TM_RTC_Alarm_A = 0x00,
216 
220 typedef struct {
222  uint8_t Seconds;
223  uint8_t Minutes;
224  uint8_t Hours;
225  uint8_t Day;
230 
250 uint32_t TM_RTC_Init(TM_RTC_ClockSource_t source);
251 
257 uint32_t TM_RTC_GetUnixTimeStamp(TM_RTC_t* data);
258 
268 
276 
286 
303 
311 
319 uint8_t TM_RTC_GetDaysInMonth(uint8_t month, uint8_t year);
320 
327 uint16_t TM_RTC_GetDaysInYear(uint8_t year);
328 
341 void TM_RTC_WriteBackupRegister(uint8_t location, uint32_t value);
342 
354 uint32_t TM_RTC_ReadBackupRegister(uint8_t location);
355 
364 
371 
379 void TM_RTC_WakeupHandler(void);
380 
388 void TM_RTC_AlarmAHandler(void);
389 
397 void TM_RTC_AlarmBHandler(void);
398 
411 /* C++ detection */
412 #ifdef __cplusplus
413 }
414 #endif
415 
416 #endif
417 
RTC Struct for date/time.
Definition: tm_stm32_rtc.h:146
uint8_t TM_RTC_GetDaysInMonth(uint8_t month, uint8_t year)
Gets number of days in month.
Definition: tm_stm32_rtc.h:179
Definition: tm_stm32_rtc.h:214
uint8_t Hours
Definition: tm_stm32_rtc.h:224
void TM_RTC_AlarmBHandler(void)
RTC Alarm B handler function. Called when interrupt is triggered for alarm B.
void TM_RTC_AlarmAHandler(void)
RTC Alarm A handler function. Called when interrupt is triggered for alarm A.
Definition: tm_stm32_rtc.h:187
TM_RTC_Int_t
RTC Interrupt enumeration.
Definition: tm_stm32_rtc.h:178
TM_RTC_Result_t TM_RTC_SetDateTime(TM_RTC_t *data, TM_RTC_Format_t format)
Sets date and time to internal RTC registers.
Definition: tm_stm32_rtc.h:186
uint8_t Day
Definition: tm_stm32_rtc.h:153
Definition: tm_stm32_rtc.h:189
TM_RTC_ClockSource_t
Select RTC clock source.
Definition: tm_stm32_rtc.h:196
Definition: tm_stm32_rtc.h:180
uint8_t Minutes
Definition: tm_stm32_rtc.h:223
TM_RTC_Result_t
RTC Result enumeration.
Definition: tm_stm32_rtc.h:162
TM_RTC_Result_t TM_RTC_Interrupts(TM_RTC_Int_t int_value)
Selects RTC wakeup interrupts interval.
TM_RTC_AlarmType_t Type
Definition: tm_stm32_rtc.h:221
Definition: tm_stm32_rtc.h:205
uint8_t Seconds
Definition: tm_stm32_rtc.h:147
Definition: tm_stm32_rtc.h:183
uint16_t Subseconds
Definition: tm_stm32_rtc.h:148
TM_RTC_Result_t TM_RTC_GetDateTime(TM_RTC_t *data, TM_RTC_Format_t format)
Gets date and time from internal RTC registers.
Definition: tm_stm32_rtc.h:188
uint8_t Year
Definition: tm_stm32_rtc.h:155
uint32_t TM_RTC_ReadBackupRegister(uint8_t location)
Reads RTC backup register value. This method allows you to read 32bit value from backup register 0 - ...
TM_RTC_AlarmType_t
RTC Alarm type.
Definition: tm_stm32_rtc.h:204
Definition: tm_stm32_rtc.h:198
Definition: tm_stm32_rtc.h:197
Definition: tm_stm32_rtc.h:163
Definition: tm_stm32_rtc.h:206
TM_RTC_Alarm_t
Alarm identifier you will use for Alarm functions.
Definition: tm_stm32_rtc.h:212
Definition: tm_stm32_rtc.h:171
TM_RTC_Result_t TM_RTC_EnableAlarm(TM_RTC_Alarm_t Alarm, TM_RTC_AlarmTime_t *AlarmTime, TM_RTC_Format_t format)
Enables alarm A or alarm B.
uint8_t Seconds
Definition: tm_stm32_rtc.h:222
uint8_t Month
Definition: tm_stm32_rtc.h:154
Definition: tm_stm32_rtc.h:213
Definition: tm_stm32_rtc.h:184
Definition: tm_stm32_rtc.h:164
TM_RTC_Result_t TM_RTC_GetDateTimeFromUnix(TM_RTC_t *data, uint32_t unix)
Gets formatted time from seconds till 01.01.1970 00:00:00 It fills struct with valid data...
TM_RTC_Result_t TM_RTC_DisableAlarm(TM_RTC_Alarm_t Alarm)
Disables specific alarm.
uint8_t Minutes
Definition: tm_stm32_rtc.h:150
uint32_t TM_RTC_GetUnixTimeStamp(TM_RTC_t *data)
Gets number of seconds from date and time since 01.01.1970 00:00:00.
uint32_t TM_RTC_Init(TM_RTC_ClockSource_t source)
Initializes RTC and starts counting.
Definition: tm_stm32_rtc.h:182
RTC structure for alarm time.
Definition: tm_stm32_rtc.h:220
Definition: tm_stm32_rtc.h:181
TM_RTC_Format_t
RTC date and time format.
Definition: tm_stm32_rtc.h:170
void TM_RTC_WakeupHandler(void)
RTC Wakeup handler function. Called when wakeup interrupt is triggered.
Definition: tm_stm32_rtc.h:172
uint8_t Hours
Definition: tm_stm32_rtc.h:151
uint8_t Day
Definition: tm_stm32_rtc.h:225
Definition: tm_stm32_rtc.h:185
TM_RTC_Result_t TM_RTC_SetDateTimeString(char *str)
Sets date and time using string formatted date time.
uint8_t WeekDay
Definition: tm_stm32_rtc.h:152
void TM_RTC_WriteBackupRegister(uint8_t location, uint32_t value)
Writes RTC backup register value. This method allows you to write 32bit value from backup register 0 ...
uint16_t TM_RTC_GetDaysInYear(uint8_t year)
Gets number of days in specific year.
uint32_t Unix
Definition: tm_stm32_rtc.h:156