stm32duino / STM32RTC

Arduino RTC library for STM32.
127 stars 48 forks source link

Date set bug in stm32f1xx #9

Closed LieBtrau closed 6 years ago

LieBtrau commented 6 years ago

Hello,

I tried the epoch example. It works fine when you run it with the given date. Replacing the epoch with a current one, i.e. 1534017459 reveals a bug. The library refuses to set the date. Setting time works ok.

It starts to go wrong on line 444 of rtc.c: if(IS_RTC_YEAR(year) && IS_RTC_MONTH(month) && IS_RTC_DATE(day) && IS_RTC_WEEKDAY(wday)) {

The IS_RTC_WEEKDAY(wday) doesn't return a correct value. Diving deeper: rtc.h, line 105: #if defined(STM32F1xx) && !defined(IS_RTC_WEEKDAY). The weekdays for stm32f1xx are defined in this rtc.h, while for the other architectures this is done in the stm32(blablabla)_hal_rtc.h files. Strange...

A quick and dirty fix is adding the #defines of the weekdays in rtc.h. `

fpistm commented 6 years ago

Hi @LieBtrau, nice catch. I've proposed a Fix #10

LieBtrau commented 6 years ago

Hi @fpistm, I just uploaded your code to a BluePill. It works now with the UTC timestamp 1534017459 and with the current UTC timestamp.