Skip to main content
kurta999
Senior
Jan 30, 2019 10:15 AM UTC
Solved

Bug with L4's Low Layer RTC month macros

#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.

This topic has been closed for replies.
JCAIL
JCAILBest answer
ST Employee
Feb 1, 2019 8:50 AM UTC

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

5 replies

ST Technical Moderator
Jan 30, 2019 10:52 AM UTC

Hello,

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

Kind Regards,

Imen

In order to give better visibility on the answered topics, please click on 'Best answer' on the reply which solved your issue or answered your question. Thanks
waclawek.jan
Super User
Jan 30, 2019 2:11 PM UTC
kurta999
kurta999Author
Senior
Jan 31, 2019 8:16 AM UTC

Yes, it's the same. Thanks.

JCAIL
JCAILBest answer
ST Employee
Feb 1, 2019 8:50 AM UTC

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

ST Technical Moderator
Apr 15, 2019 4:19 PM UTC

Hello,

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

Regards,

Imen

In order to give better visibility on the answered topics, please click on 'Best answer' on the reply which solved your issue or answered your question. Thanks