STM32L0 LoRaWAN -> Whenever I set date and time to internal RTC, my system will crash

43 Views Asked by At

I'm currently working with an STM32L082xx LoRaWAN microcontroller, and I'm facing a challenge related to the internal Real-Time Clock (RTC). Specifically, whenever I attempt to set the date and time using the internal RTC, my system crashes. I've reviewed the code and checked for potential issues, but I haven't been able to identify the root cause. Has anyone in the STM32 community encountered a similar problem when configuring the internal RTC? If so, could you share any insights, potential reasons for this behavior, or troubleshooting steps that might help me resolve this issue? Your assistance would be greatly appreciated as I work to address this problem in my project.

Here's my set date and time function:

/**
* @fn ErrorStatus RTC_SetTimeAndDate(void)

* @brief Function to use Set date and time into Internal RTC
*
* @return SUCCESS / ERROR
*/

ErrorStatus RTC_SetTimeAndDate(void)
{
    RTC_TimeTypeDef sTime;
    RTC_DateTypeDef sDate;
    if(HAL_RTCEx_BKUPRead(&hrtc, RTC_BKP_DR1) != 0x32F2)
  {
    /** Set the Time and Date **/
    sTime.Hours = AppControl.mRTC.mTime.mHours; // BUILD_HOUR;
    sTime.Minutes = AppControl.mRTC.mTime.mMinutes; // BUILD_MIN;
    sTime.Seconds = AppControl.mRTC.mTime.mSeconds; // BUILD_SEC;
    sTime.SubSeconds = 0; // (AppControl.mRTC.mTime.m100thSeconds * 10); // BUILD_SEC;
    sTime.TimeFormat = RTC_HOURFORMAT_24;
    sTime.DayLightSaving = RTC_DAYLIGHTSAVING_NONE;
    sTime.StoreOperation = RTC_STOREOPERATION_RESET;
    if (HAL_RTC_SetTime(&hrtc, &sTime, RTC_FORMAT_BIN) != HAL_OK)
    {
      return ERROR;
    }
    sDate.WeekDay = AppControl.mRTC.mDate.mWeekDays; // RTC_GetCurrentDayOfWeek(BUILD_DAY, BUILD_MONTH, BUILD_YEAR);
    sDate.Month = AppControl.mRTC.mDate.mMonths; // BUILD_MONTH;
    sDate.Date = AppControl.mRTC.mDate.mDays; // BUILD_DAY;
    sDate.Year = (AppControl.mRTC.mDate.mYears - 2000); // (BUILD_YEAR - 2000);
    if (HAL_RTC_SetDate(&hrtc, &sDate, RTC_FORMAT_BIN) != HAL_OK)
    {
      return ERROR;
    }
}
    HAL_RTCEx_BKUPWrite(&hrtc, RTC_BKP_DR1, 0x32F2); // backup register
    return SUCCESS;
}
0

There are 0 best solutions below