STM32F4 disc board sleep mode

Hi all,
I know this is not the first post on the subject, but I have been trying for some time now to put my board into sleep mode and wake it up via an interrupt on a gpio but without success. I read a lot of posts and tried a lot of methods without success.
My goal is to put my card in sleep mode for an unknown duration while waiting for an interrupt to wake the board up.

According to my research I have to use the tickless mode of freertos. Here is what I’ve tried :
FreeRTOSconfig.h

#define configUSE_TICKLESS_IDLE 1
#define configEXPECTED_IDLE_TIME_BEFORE_SLEEP 100

My EXTI9_5_IRQHandler for PB9 : (works fine)

BaseType_t xHigherPriorityTaskWoken = pdFALSE;
  uint32_t current_time = HAL_GetTick();
  if (__HAL_GPIO_EXTI_GET_IT(STAT_ALIM_GPIO_PIN) != RESET) {
    __HAL_GPIO_EXTI_CLEAR_IT(STAT_ALIM_GPIO_PIN);
    if (current_time - last_interrupt_time > 50) {
      last_interrupt_time = current_time;
      if (HAL_GPIO_ReadPin(GPIOB, GPIO_PIN_9) == GPIO_PIN_RESET) {
        vTaskNotifyGiveFromISR(T_handleStatAlimInterrupt, &xHigherPriorityTaskWoken);
        portYIELD_FROM_ISR(xHigherPriorityTaskWoken);
      }
    }
  }
void vPortSuppressTicksAndSleep(TickType_t xExpectedIdleTime) {
  __disable_irq();
  __DSB();
  __ISB();

  if (eTaskConfirmSleepModeStatus() == eAbortSleep) {
    __enable_irq();
  } else {
    SysTick->CTRL &= ~SysTick_CTRL_ENABLE_Msk;

    HAL_PWR_EnterSLEEPMode(PWR_MAINREGULATOR_ON, PWR_SLEEPENTRY_WFI);
    SysTick->CTRL |= SysTick_CTRL_ENABLE_Msk;

    __enable_irq();
  }
}

And my task where I want to enter in sleep mode :slight_smile:

void User_handleStatAlimInterrupt(__unused void const *argument) {
  while (1) {
    ulTaskNotifyTake(pdTRUE, portMAX_DELAY);
    if(HAL_GPIO_ReadPin (STAT_ALIM_GPIO_PORT, STAT_ALIM_GPIO_PIN)) {
      USER_LOG_INFO("stat alim 1");

      vTaskSuspend(task1);
      vTaskSuspend(task2);

      __disable_irq();
      __HAL_GPIO_EXTI_CLEAR_FLAG(GPIO_PIN_9);
      __HAL_RCC_PWR_CLK_ENABLE();
      HAL_PWR_EnterSLEEPMode(PWR_MAINREGULATOR_ON, PWR_SLEEPENTRY_WFI);
      __enable_irq();
      USER_LOG_INFO("wake");

      vTaskResume(task1);
      vTaskResume(task2);

    }else{
      USER_LOG_INFO("stat alim 0");
    }
  }
}

My problem is, as soon as I go to sleep I wake up directly without having any interruption on my pin, any ideas?

Thanks

Can you try using the default vPortSuppressTicksAndSleep and use configPRE_SLEEP_PROCESSING to call HAL_PWR_EnterSLEEPMode?

Is it possible that an interrupt is pending which is waking the device up? Does the control go to any ISR as soon as you enable interrupts?