Skip to content

Commit

Permalink
Fix: errota Read date after time.
Browse files Browse the repository at this point in the history
read RTC_TR will lock higher rancked RTC_DR causing freeze
  • Loading branch information
jasonyang-ee committed Jul 12, 2023
1 parent 22534db commit 254cd72
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 8 deletions.
12 changes: 5 additions & 7 deletions Application/Src/RTC.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,13 @@ void CustomRTC::setDate(uint8_t day, uint8_t month, uint8_t year) {
}

std::array<uint8_t, 3> CustomRTC::getDate() {
if (HAL_RTC_GetDate(&m_port, &m_date, RTC_FORMAT_BIN) != HAL_OK) {
serialCOM.sendString("RTC Get Date Error\n");
}
return {m_date.Date, m_date.Month, m_date.Year};
HAL_RTC_GetTime(&m_port, &m_time, RTC_FORMAT_BIN);
HAL_RTC_GetDate(&m_port, &m_date, RTC_FORMAT_BIN);
return {m_date.Month, m_date.Date, m_date.Year};
}

std::array<uint8_t, 3> CustomRTC::getTime() {
if (HAL_RTC_GetTime(&m_port, &m_time, RTC_FORMAT_BIN) != HAL_OK) {
serialCOM.sendString("RTC Get Time Error\n");
}
HAL_RTC_GetTime(&m_port, &m_time, RTC_FORMAT_BIN);
HAL_RTC_GetDate(&m_port, &m_date, RTC_FORMAT_BIN);
return {m_time.Hours, m_time.Minutes, m_time.Seconds};
}
2 changes: 1 addition & 1 deletion Core/Src/rtc.c
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ void MX_RTC_Init(void)
sTime.Seconds = 0x0;
sTime.SubSeconds = 0x0;
sTime.DayLightSaving = RTC_DAYLIGHTSAVING_ADD1H;
sTime.StoreOperation = RTC_STOREOPERATION_RESET;
sTime.StoreOperation = RTC_STOREOPERATION_SET;
if (HAL_RTC_SetTime(&hrtc, &sTime, RTC_FORMAT_BCD) != HAL_OK)
{
Error_Handler();
Expand Down

0 comments on commit 254cd72

Please sign in to comment.