13#if defined(STM32) && defined(HAL_RTC_MODULE_ENABLED)
26 auto time = halTime();
27 return static_cast<uint16_t
>(1000 * (time.SecondFraction - time.SubSeconds) / (time.SecondFraction + 1));
34 RTC_TimeTypeDef hal = halTime();
35#if !defined(STM32F0) && !defined(STM32F1)
36 hal.DayLightSaving = RTC_DAYLIGHTSAVING_NONE;
37 hal.StoreOperation = RTC_STOREOPERATION_RESET;
41 hal.SubSeconds = hal.SecondFraction - (hal.SecondFraction + 1) *
millisecond / 1000;
43 HAL_StatusTypeDef state = HAL_RTC_SetTime(m_hrtc, &hal, RTC_FORMAT_BIN);
46 if (state == HAL_ERROR)
51 else if (state == HAL_BUSY)
56 else if (state == HAL_TIMEOUT)
67 return halTime().Seconds;
73 RTC_TimeTypeDef hal = halTime();
74#if !defined(STM32F0) && !defined(STM32F1)
75 hal.DayLightSaving = RTC_DAYLIGHTSAVING_NONE;
76 hal.StoreOperation = RTC_STOREOPERATION_RESET;
79 HAL_StatusTypeDef state = HAL_RTC_SetTime(m_hrtc, &hal, RTC_FORMAT_BIN);
82 if (state == HAL_ERROR)
87 else if (state == HAL_BUSY)
92 else if (state == HAL_TIMEOUT)
103 return halTime().Minutes;
109 RTC_TimeTypeDef hal = halTime();
110#if !defined(STM32F0) && !defined(STM32F1)
111 hal.DayLightSaving = RTC_DAYLIGHTSAVING_NONE;
112 hal.StoreOperation = RTC_STOREOPERATION_RESET;
114 hal.Minutes =
minute % 60;
115 HAL_StatusTypeDef state = HAL_RTC_SetTime(m_hrtc, &hal, RTC_FORMAT_BIN);
118 if (state == HAL_ERROR)
123 else if (state == HAL_BUSY)
128 else if (state == HAL_TIMEOUT)
139 return halTime().Hours;
145 RTC_TimeTypeDef hal = halTime();
146#if !defined(STM32F0) && !defined(STM32F1)
147 hal.DayLightSaving = RTC_DAYLIGHTSAVING_NONE;
148 hal.StoreOperation = RTC_STOREOPERATION_RESET;
151 HAL_StatusTypeDef state = HAL_RTC_SetTime(m_hrtc, &hal, RTC_FORMAT_BIN);
154 if (state == HAL_ERROR)
159 else if (state == HAL_BUSY)
164 else if (state == HAL_TIMEOUT)
175 return halDate().Date;
181 RTC_DateTypeDef hal = halDate();
183 HAL_StatusTypeDef state = HAL_RTC_SetDate(m_hrtc, &hal, RTC_FORMAT_BIN);
186 if (state == HAL_ERROR)
191 else if (state == HAL_BUSY)
196 else if (state == HAL_TIMEOUT)
207 return halDate().Month;
213 RTC_DateTypeDef hal = halDate();
215 HAL_StatusTypeDef state = HAL_RTC_SetDate(m_hrtc, &hal, RTC_FORMAT_BIN);
218 if (state == HAL_ERROR)
223 else if (state == HAL_BUSY)
228 else if (state == HAL_TIMEOUT)
239 return halDate().Year + 2000;
245 RTC_DateTypeDef hal = halDate();
246 hal.Year =
static_cast<uint8_t
>(
year % 100);
247 HAL_StatusTypeDef state = HAL_RTC_SetDate(m_hrtc, &hal, RTC_FORMAT_BIN);
250 if (state == HAL_ERROR)
255 else if (state == HAL_BUSY)
260 else if (state == HAL_TIMEOUT)
269RTC_TimeTypeDef Stm32Rtc::halTime()
const
271 RTC_TimeTypeDef halTime;
272 HAL_StatusTypeDef state = HAL_RTC_GetTime(m_hrtc, &halTime, RTC_FORMAT_BIN);
275 if (state == HAL_ERROR)
280 else if (state == HAL_BUSY)
285 else if (state == HAL_TIMEOUT)
294RTC_DateTypeDef Stm32Rtc::halDate()
const
296 RTC_DateTypeDef halDate;
297 HAL_StatusTypeDef state = HAL_RTC_GetDate(m_hrtc, &halDate, RTC_FORMAT_BIN);
300 if (state == HAL_ERROR)
305 else if (state == HAL_BUSY)
310 else if (state == HAL_TIMEOUT)
Class for representing errors. Every error should have a unique source code. As a user feel encourage...
void setYear(uint16_t year) override
For set a new date.
uint16_t year() const override
Get the current year.
uint16_t millisecond() override
Get the milliseconds from the current time.
void setDay(uint8_t day) override
For set a new date.
uint8_t second() const override
Get the seconds from the current time.
void setHour(uint8_t hour) override
For set a new time.
uint8_t month() const override
Get the current month.
uint8_t day() const override
void setMonth(uint8_t month) override
For set a new date.
Stm32Rtc(RTC_HandleTypeDef &hrtc)
Constructor.
uint8_t hour() const override
Get the hours from the current time.
void setMinute(uint8_t minute) override
For set a new time.
void setMillisecond(uint16_t millisecond) override
For set a new time.
void setSecond(uint8_t second) override
For set a new time.
uint8_t minute() const override
Get the minutes from the current time.
@ SetMillisecond_HalTimeout
@ SetMillisecond_HalError