2

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();
    }
}
artless noise
  • 21,212
  • 6
  • 68
  • 105
IGtti
  • 49
  • 6

1 Answers1

0

Found a topic related to the BASEPRI, which allows to disable the interrupts by priority groups. The code bellow is working, but I did not get correctlly the BASEPRI logic. The RTC_Alarm has priority 5, in this case the __set_BASEPRI should have the priority parameter less than 5. But it only works when I used bigger than 5.

Please, any explanation for this?

              HAL_NVIC_SetPriority(RTC_Alarm_IRQn, 5, 0);
              HAL_NVIC_EnableIRQ(RTC_Alarm_IRQn);
              SET_Alarm_A(gui8_EETIMEPUBINTERVAL);          // Set RTC Alarm with the TIMEPUBINTERVAL
              HAL_ADC_DeInit(&hadc1);
              vTaskSuspendAll();
              HAL_SuspendTick();
              __set_BASEPRI(6 << 4);            // RTC Alarm A has priority 5 (do not know how it is working. It should be a value smaller than 5 ??!)
              __disable_irq();                  // Disable all interrupts except the RTC Alarm (due to the priority block)

              HAL_PWREx_EnterSTOP1Mode(PWR_STOPENTRY_WFI);          // Enter Stop1 mode, wait for RTC Alarm to wake up

              __set_BASEPRI(0);
              __enable_irq();                   // Enable all interrupts
              SystemClock_Config();             // Resume the clock configuration, affected after the Stop Mode
              MX_ADC1_Init();                   // It was Clocked-off during STOP1 Mode
              HAL_ResumeTick();
              xTaskResumeAll();
IGtti
  • 49
  • 6