cancel
Showing results for 
Search instead for 
Did you mean: 

Bug with L4's Low Layer RTC month macros

kurta999
Senior
#define LL_RTC_MONTH_JANUARY               (uint8_t)0x01  /*!< January   */
#define LL_RTC_MONTH_FEBRUARY              (uint8_t)0x02  /*!< February  */
#define LL_RTC_MONTH_MARCH                 (uint8_t)0x03  /*!< March     */
#define LL_RTC_MONTH_APRIL                 (uint8_t)0x04  /*!< April     */
#define LL_RTC_MONTH_MAY                   (uint8_t)0x05  /*!< May       */
#define LL_RTC_MONTH_JUNE                  (uint8_t)0x06  /*!< June      */
#define LL_RTC_MONTH_JULY                  (uint8_t)0x07  /*!< July      */
#define LL_RTC_MONTH_AUGUST                (uint8_t)0x08  /*!< August    */
#define LL_RTC_MONTH_SEPTEMBER             (uint8_t)0x09  /*!< September */
#define LL_RTC_MONTH_OCTOBER               (uint8_t)0x10  /*!< October   */
#define LL_RTC_MONTH_NOVEMBER              (uint8_t)0x11  /*!< November  */
#define LL_RTC_MONTH_DECEMBER              (uint8_t)0x12  /*!< December  */

LL_RTC_MONTH_OCTOBER        (uint8_t)0x10 /*!< October  */

LL_RTC_MONTH_NOVEMBER       (uint8_t)0x11 /*!< November */

LL_RTC_MONTH_DECEMBER       (uint8_t)0x12 /*!< December */

Those values should be: 0xA, 0xB, 0xC - isn't it?

I'm able to set month to decimal 11, 12. But hex 11 12 is decimal 17, 18 which is instant assert fail in LL_RTC_DATE_Init.

1 ACCEPTED SOLUTION

Accepted Solutions
JCAIL
Associate

Hi dear customer and dear support,

The define is OK. It is BCD format and it is in line with the Hardware.

Now in LL, the API accepts two input formats (Binary or BCD) =>

ErrorStatus LL_RTC_DATE_Init(RTC_TypeDef *RTCx, uint32_t RTC_Format, LL_RTC_DateTypeDef *RTC_DateStruct)

1°) if user choose Format = RTC_FORMAT_BCD

The define is OK and value is directly put in register (after a shift).

2°) if user choose Format = RTC_FORMAT_BIN

if user do not use the define (BCD) but binary value, it is ok.

if user uses the define (BCD), it is converted to binary inside the driver by the following code :

if ((Format == RTC_FORMAT_BIN) && ((sDate->Month & 0x10U) == 0x10U))

{

 sDate->Month = (uint8_t)((sDate->Month & (uint8_t)~(0x10U)) + (uint8_t)0x0AU);

}

Now, there is only one assert and the assert should check binary value.

 if (Format == RTC_FORMAT_BIN)

 {

  ...

  assert_param(IS_RTC_MONTH(sDate->Month)); /* Binary */

  ...

 }

 else

 {

  ...

  assert_param(IS_RTC_MONTH(RTC_Bcd2ToByte(sDate->Month))); /* Binary */

  ...

 }

The problem is in the assert. Please use :

Use #define IS_LL_RTC_MONTH(__MONTH__) (((__MONTH__) >= 1U) && ((__MONTH__) <= 12U)) 

  

Best regards,

Jérôme Caillet

View solution in original post

5 REPLIES 5
Imen.D
ST Employee

Hello,

We will check your issue and we come back to you soon.

Kind Regards,

Imen

When your question is answered, please close this topic by clicking "Accept as Solution".
Thanks
Imen
kurta999
Senior

Yes, it's the same. Thanks.

JCAIL
Associate

Hi dear customer and dear support,

The define is OK. It is BCD format and it is in line with the Hardware.

Now in LL, the API accepts two input formats (Binary or BCD) =>

ErrorStatus LL_RTC_DATE_Init(RTC_TypeDef *RTCx, uint32_t RTC_Format, LL_RTC_DateTypeDef *RTC_DateStruct)

1°) if user choose Format = RTC_FORMAT_BCD

The define is OK and value is directly put in register (after a shift).

2°) if user choose Format = RTC_FORMAT_BIN

if user do not use the define (BCD) but binary value, it is ok.

if user uses the define (BCD), it is converted to binary inside the driver by the following code :

if ((Format == RTC_FORMAT_BIN) && ((sDate->Month & 0x10U) == 0x10U))

{

 sDate->Month = (uint8_t)((sDate->Month & (uint8_t)~(0x10U)) + (uint8_t)0x0AU);

}

Now, there is only one assert and the assert should check binary value.

 if (Format == RTC_FORMAT_BIN)

 {

  ...

  assert_param(IS_RTC_MONTH(sDate->Month)); /* Binary */

  ...

 }

 else

 {

  ...

  assert_param(IS_RTC_MONTH(RTC_Bcd2ToByte(sDate->Month))); /* Binary */

  ...

 }

The problem is in the assert. Please use :

Use #define IS_LL_RTC_MONTH(__MONTH__) (((__MONTH__) >= 1U) && ((__MONTH__) <= 12U)) 

  

Best regards,

Jérôme Caillet

Imen.D
ST Employee

Hello,

This issue is fixed in the available release STM32CubeL4 V1.14.0

Regards,

Imen

When your question is answered, please close this topic by clicking "Accept as Solution".
Thanks
Imen