AnsweredAssumed Answered

Bug in HAL RTC at IS_RTC_MONTH macro ?

Question asked by M.I.001 on Apr 18, 2017
Latest reply on Apr 20, 2017 by M.I.001



I am working with the HAL library using the RTC module. I think I found a bug in the stm32l1xx_hal_rtc.h file.


The file stm32l1xx_hal_rtc.h has the following code


#define RTC_MONTH_JULY ((uint8_t)0x07)
#define RTC_MONTH_AUGUST ((uint8_t)0x08)
#define RTC_MONTH_SEPTEMBER ((uint8_t)0x09)
#define RTC_MONTH_OCTOBER ((uint8_t)0x10) // ------------> But not 0x0A
#define RTC_MONTH_NOVEMBER ((uint8_t)0x11) // ------------> But not 0x0B
#define RTC_MONTH_DECEMBER ((uint8_t)0x12) // ------------> But not 0x0C


#define IS_RTC_MONTH(MONTH) (((MONTH) >= (uint32_t)1) && ((MONTH) <= (uint32_t)12))   


IS_RTC_MONTH macro checks if MONTH is <= 12, but RTC_MONTH_OCTOBER has value 0x10 which is 16 > 12, RTC_MONTH_NOVEMBER has value 0x11 (17 > 12) and RTC_MONTH_DECEMBER has value 0x12 (18 > 12). Therefore, the checks with these 3 months will fail.


The 2 available options are:

  • Check that MONTH is between 0x00 and 0x09 or 0x10 and 0x12.


Is it a bug?