stmhal: Fix setting of RTC: was BCD now BIN encoded.
Addresses issue #592.
This commit is contained in:
parent
c17fd70de9
commit
04b7cc4df0
20
stmhal/rtc.c
20
stmhal/rtc.c
@ -214,26 +214,26 @@ void rtc_init(void) {
|
||||
static void RTC_CalendarConfig(void) {
|
||||
// set the date to 1st Jan 2014
|
||||
RTC_DateTypeDef date;
|
||||
date.Year = 0x14;
|
||||
date.Month = RTC_MONTH_JANUARY;
|
||||
date.Date = 0x01;
|
||||
date.Year = 14;
|
||||
date.Month = 1;
|
||||
date.Date = 1;
|
||||
date.WeekDay = RTC_WEEKDAY_WEDNESDAY;
|
||||
|
||||
if(HAL_RTC_SetDate(&RTCHandle, &date, FORMAT_BCD) != HAL_OK) {
|
||||
if(HAL_RTC_SetDate(&RTCHandle, &date, FORMAT_BIN) != HAL_OK) {
|
||||
// init error
|
||||
return;
|
||||
}
|
||||
|
||||
// set the time to 00:00:00
|
||||
RTC_TimeTypeDef time;
|
||||
time.Hours = 0x00;
|
||||
time.Minutes = 0x00;
|
||||
time.Seconds = 0x00;
|
||||
time.Hours = 0;
|
||||
time.Minutes = 0;
|
||||
time.Seconds = 0;
|
||||
time.TimeFormat = RTC_HOURFORMAT12_AM;
|
||||
time.DayLightSaving = RTC_DAYLIGHTSAVING_NONE;
|
||||
time.StoreOperation = RTC_STOREOPERATION_RESET;
|
||||
|
||||
if (HAL_RTC_SetTime(&RTCHandle, &time, FORMAT_BCD) != HAL_OK) {
|
||||
if (HAL_RTC_SetTime(&RTCHandle, &time, FORMAT_BIN) != HAL_OK) {
|
||||
// init error
|
||||
return;
|
||||
}
|
||||
@ -316,7 +316,7 @@ mp_obj_t pyb_rtc_datetime(uint n_args, const mp_obj_t *args) {
|
||||
date.Month = mp_obj_get_int(items[1]);
|
||||
date.Date = mp_obj_get_int(items[2]);
|
||||
date.WeekDay = mp_obj_get_int(items[3]);
|
||||
HAL_RTC_SetDate(&RTCHandle, &date, FORMAT_BCD);
|
||||
HAL_RTC_SetDate(&RTCHandle, &date, FORMAT_BIN);
|
||||
|
||||
RTC_TimeTypeDef time;
|
||||
time.Hours = mp_obj_get_int(items[4]);
|
||||
@ -326,7 +326,7 @@ mp_obj_t pyb_rtc_datetime(uint n_args, const mp_obj_t *args) {
|
||||
time.TimeFormat = RTC_HOURFORMAT12_AM;
|
||||
time.DayLightSaving = RTC_DAYLIGHTSAVING_NONE;
|
||||
time.StoreOperation = RTC_STOREOPERATION_SET;
|
||||
HAL_RTC_SetTime(&RTCHandle, &time, FORMAT_BCD);
|
||||
HAL_RTC_SetTime(&RTCHandle, &time, FORMAT_BIN);
|
||||
|
||||
return mp_const_none;
|
||||
}
|
||||
|
@ -3,6 +3,28 @@ from pyb import RTC
|
||||
|
||||
rtc = RTC()
|
||||
print(rtc)
|
||||
|
||||
# make sure that 1 second passes correctly
|
||||
rtc.datetime((2014, 1, 1, 1, 0, 0, 0, 0))
|
||||
pyb.delay(1000)
|
||||
print(rtc.datetime()[:7])
|
||||
|
||||
def set_and_print(datetime):
|
||||
rtc.datetime(datetime)
|
||||
print(rtc.datetime()[:7])
|
||||
|
||||
# make sure that setting works correctly
|
||||
set_and_print((2000, 1, 1, 1, 0, 0, 0, 0))
|
||||
set_and_print((2000, 1, 31, 1, 0, 0, 0, 0))
|
||||
set_and_print((2000, 12, 31, 1, 0, 0, 0, 0))
|
||||
set_and_print((2016, 12, 31, 1, 0, 0, 0, 0))
|
||||
set_and_print((2016, 12, 31, 7, 0, 0, 0, 0))
|
||||
set_and_print((2016, 12, 31, 7, 1, 0, 0, 0))
|
||||
set_and_print((2016, 12, 31, 7, 12, 0, 0, 0))
|
||||
set_and_print((2016, 12, 31, 7, 13, 0, 0, 0))
|
||||
set_and_print((2016, 12, 31, 7, 23, 0, 0, 0))
|
||||
set_and_print((2016, 12, 31, 7, 23, 1, 0, 0))
|
||||
set_and_print((2016, 12, 31, 7, 23, 59, 0, 0))
|
||||
set_and_print((2016, 12, 31, 7, 23, 59, 1, 0))
|
||||
set_and_print((2016, 12, 31, 7, 23, 59, 59, 0))
|
||||
set_and_print((2099, 12, 31, 7, 23, 59, 59, 0))
|
||||
|
@ -1,2 +1,16 @@
|
||||
<RTC>
|
||||
(2014, 1, 1, 1, 0, 0, 1)
|
||||
(2000, 1, 1, 1, 0, 0, 0)
|
||||
(2000, 1, 31, 1, 0, 0, 0)
|
||||
(2000, 12, 31, 1, 0, 0, 0)
|
||||
(2016, 12, 31, 1, 0, 0, 0)
|
||||
(2016, 12, 31, 7, 0, 0, 0)
|
||||
(2016, 12, 31, 7, 1, 0, 0)
|
||||
(2016, 12, 31, 7, 12, 0, 0)
|
||||
(2016, 12, 31, 7, 13, 0, 0)
|
||||
(2016, 12, 31, 7, 23, 0, 0)
|
||||
(2016, 12, 31, 7, 23, 1, 0)
|
||||
(2016, 12, 31, 7, 23, 59, 0)
|
||||
(2016, 12, 31, 7, 23, 59, 1)
|
||||
(2016, 12, 31, 7, 23, 59, 59)
|
||||
(2099, 12, 31, 7, 23, 59, 59)
|
||||
|
Loading…
x
Reference in New Issue
Block a user