The RTC on my STM32L476RG MCU does not reliably cause a repetitive interrupt.
I just had a problem where my RTC timer did not fire the callback as it should. Most of the time it works fine, but yesterday on a customers system, it did not. The log shows the callback occurred, then the callback reinitialized the timer (in Start_RTC_Wakeup_Timer) just as it has thousands of times before. But after it was restarted this time, the callback never fired again. The log showed the system continued doing other things just as it should. The system was not locked up. The only problem was the RTC never fired again.
This failure was rather catastrophic because the RTC was supposed to kick off a number of important processes.
What would cause this? Do I need to have a timer to monitor the RTC and restart the system if this happens again. Doesn't seem like I should need to do this...
Clark
My RTC code is this:
// initialization
static void MX_RTC_Init(void)
{
/* USER CODE BEGIN RTC_Init 0 */
/* USER CODE END RTC_Init 0 */
RTC_TimeTypeDef sTime = {0};
RTC_DateTypeDef sDate = {0};
/* USER CODE BEGIN RTC_Init 1 */
/* USER CODE END RTC_Init 1 */
/** Initialize RTC Only
*/
hrtc.Instance = RTC;
hrtc.Init.HourFormat = RTC_HOURFORMAT_24;
hrtc.Init.AsynchPrediv = 127;
hrtc.Init.SynchPrediv = 255;
hrtc.Init.OutPut = RTC_OUTPUT_DISABLE;
hrtc.Init.OutPutRemap = RTC_OUTPUT_REMAP_NONE;
hrtc.Init.OutPutPolarity = RTC_OUTPUT_POLARITY_HIGH;
hrtc.Init.OutPutType = RTC_OUTPUT_TYPE_OPENDRAIN;
if (HAL_RTC_Init(&hrtc) != HAL_OK)
{
Error_Handler();
}
Initialize in main like this:
rtcWakeUpCounter = 29; // wakeup every 30 seconds
Start_RTC_Wakup_Timer();
void Start_RTC_Wakup_Timer(void)
{
/* Enable wakeup source for analog scan */
HAL_RTCEx_DeactivateWakeUpTimer(&hrtc);
HAL_RTCEx_SetWakeUpTimer_IT(&hrtc, rtcWakeUpCounter, RTC_WAKEUPCLOCK_RTCCLK_DIV16 RTC_WAKEUPCLOCK_CK_SPRE_16BITS);
SaveLogToSD("Reset / start RTC wakeup timer");
}
void HAL_RTCEx_WakeUpTimerEventCallback(RTC_HandleTypeDef *hrtc) { // fires every 30 seconds
SaveLogToSD("********** RTC wakeup **********");
// Do a few things here.....
Start_RTC_Wakup_Timer();
}