2018-09-19 02:44 AM
HAL_StatusTypeDef HAL_RTC_SetDate(RTC_HandleTypeDef *hrtc, RTC_DateTypeDef *sDate, uint32_t Format)
{
uint32_t datetmpreg = 0U;
/* Check the parameters */
assert_param(IS_RTC_FORMAT(Format));
/* Process Locked */
__HAL_LOCK(hrtc);
hrtc->State = HAL_RTC_STATE_BUSY;
if((Format == RTC_FORMAT_BIN) && ((sDate->Month & 0x10U) == 0x10U))
{
sDate->Month = (uint8_t)((sDate->Month & (uint8_t)~(0x10U)) + (uint8_t)0x0AU);
}
assert_param(IS_RTC_WEEKDAY(sDate->WeekDay));
if(Format == RTC_FORMAT_BIN)
{
assert_param(IS_RTC_YEAR(sDate->Year));
assert_param(IS_RTC_MONTH(sDate->Month));
assert_param(IS_RTC_DATE(sDate->Date));
datetmpreg = (((uint32_t)RTC_ByteToBcd2(sDate->Year) << 16U) | \
((uint32_t)RTC_ByteToBcd2(sDate->Month) << 8U) | \
((uint32_t)RTC_ByteToBcd2(sDate->Date)) | \
((uint32_t)sDate->WeekDay << 13U));
}
else
{
assert_param(IS_RTC_YEAR(RTC_Bcd2ToByte(sDate->Year)));
assert_param(IS_RTC_MONTH(datetmpreg));
assert_param(IS_RTC_DATE(datetmpreg));
datetmpreg = ((((uint32_t)sDate->Year) << 16U) | \
(((uint32_t)sDate->Month) << 8U) | \
((uint32_t)sDate->Date) | \
(((uint32_t)sDate->WeekDay) << 13U));
}
When "Format" is not RTC_FORMAT_BIN, assert_param(IS_RTC_MONTH(datetmpreg)); failed, as datetmpreg is 0.
2018-11-19 06:23 AM
Hello @TDao.19 ,
If you are using STM32CubeF4, please note that this bug is already tracked internally and should be fixed in coming releases.
If another package is used, please precise which one.
-Amel
To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.
2018-11-30 07:14 AM
Hey @Amel NASRI
I'm new to the community and was wondering if you are having a public bugfix tracker?
Closely to this post I think I found a similar assert problem in the STM32Cube_FW_L4_V1.13.0 package.
In stm32l4xx_ll_rtc.c the function LL_RTC_DATE_Init (line 390) is converting a BCD formatted month value to bin.
assert_param(IS_LL_RTC_MONTH(__LL_RTC_CONVERT_BCD2BIN(RTC_DateStruct->Month)));
(line 411)
The assert on the other hand is comparing the values to the BCD format:
#define IS_LL_RTC_MONTH(__VALUE__) (((__VALUE__) == LL_RTC_MONTH_JANUARY) \
|| ((__VALUE__) == LL_RTC_MONTH_FEBRUARY) \
|| ((__VALUE__) == LL_RTC_MONTH_MARCH) \
|| ((__VALUE__) == LL_RTC_MONTH_APRIL) \
|| ((__VALUE__) == LL_RTC_MONTH_MAY) \
|| ((__VALUE__) == LL_RTC_MONTH_JUNE) \
|| ((__VALUE__) == LL_RTC_MONTH_JULY) \
|| ((__VALUE__) == LL_RTC_MONTH_AUGUST) \
|| ((__VALUE__) == LL_RTC_MONTH_SEPTEMBER) \
|| ((__VALUE__) == LL_RTC_MONTH_OCTOBER) \
|| ((__VALUE__) == LL_RTC_MONTH_NOVEMBER) \
|| ((__VALUE__) == LL_RTC_MONTH_DECEMBER))
(line 106)
This works fine for january to september as these months contain the same value in the BCD and BIN format. But from october to december the assert fails as the BCD 0x10 got transformed to BIN 10 and so on.
Am I missing something?
Kind regards
2018-11-30 07:31 AM
#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 */
Additionally the faulty defines in stm32l4xx_ll_rtc.h.