I am trying to enter in STOP mode and wakeup using the RTC Alarm.
It works fine when testing the code before starting the FreeRTOS Kernel.
After starting the FreeRTOS Kernel the wakeup does not work, the system continues in STOP mode.
I believe the problem is the disbled RTC Alarm Interrupt. I've tried enabling it, but it´s still not waking up.
Any indication about the problem?
Here is the part of the code before and after entering in STOP1Mode
taskDISABLE_INTERRUPTS();
HAL_SuspendTick();
HAL_NVIC_EnableIRQ(RTC_Alarm_IRQn);
HAL_NVIC_ClearPendingIRQ(RTC_Alarm_IRQn);
SET_Alarm_A();
HAL_PWREx_EnterSTOP1Mode(PWR_STOPENTRY_WFI);
SystemClock_Config();
HAL_ResumeTick();
taskENABLE_INTERRUPTS();
And the SET_Alarm_A function:
void SET_Alarm_A(uint8_t ui8_MinuteAlarm)
{
uint8_t ui8_AlarmInterval;
RTC_AlarmTypeDef sAlarm = {0};
RTC_TimeTypeDef sTime = {0};
RTC_DateTypeDef sDate = {0};
// Get updated time from RTC
HAL_RTC_GetTime(&hrtc, &sTime, RTC_FORMAT_BIN); // Get current Time
HAL_RTC_GetDate(&hrtc, &sDate, RTC_FORMAT_BIN); // Get current Date. It is mandatory to read the Date after Time, even if not used
gui8_RTChours = sTime.Hours; // Take the current RTC Hours
gui8_RTCminutes = sTime.Minutes; // Take the current RTC Minutes
gui8_RTCseconds = sTime.Seconds; // Take the current RTC Seconds
ui8_AlarmInterval = gui8_RTCminutes + ui8_MinuteAlarm; // update the timing interval for next cycle
if(ui8_AlarmInterval > 59U) { // check for values over 59
ui8_AlarmInterval = ui8_AlarmInterval - 60U; // calculate and compensate the overflow
}
sAlarm.AlarmTime.Hours = 0x0;
sAlarm.AlarmTime.Minutes = ui8_AlarmInterval;
sAlarm.AlarmTime.Seconds = 0x0;
sAlarm.AlarmTime.SubSeconds = 0x0;
sAlarm.AlarmTime.DayLightSaving = RTC_DAYLIGHTSAVING_NONE;
sAlarm.AlarmTime.StoreOperation = RTC_STOREOPERATION_RESET;
sAlarm.AlarmMask = RTC_ALARMMASK_DATEWEEKDAY|RTC_ALARMMASK_HOURS|RTC_ALARMMASK_SECONDS; // Compares Minutes only
sAlarm.AlarmSubSecondMask = RTC_ALARMSUBSECONDMASK_ALL;
sAlarm.AlarmDateWeekDaySel = RTC_ALARMDATEWEEKDAYSEL_DATE;
sAlarm.AlarmDateWeekDay = 0x1;
sAlarm.Alarm = RTC_ALARM_A;
if (HAL_RTC_SetAlarm_IT(&hrtc, &sAlarm, RTC_FORMAT_BIN) != HAL_OK)
{
Error_Handler();
}
}