Issue with Sleep Mode on EC200U_EU_AA Module and Task Suspension

Hello everyone,

I am working with the EC200U_EU_AA module and trying to enable Sleep Mode using the API provided in power_demo.c. To achieve this, I am using the ql_autosleep_enable() function.

I have ensured that:

  • There are no active wakelocks.
  • USB is disconnected.
  • All other threads are disabled, and only the power-related thread is running.

Despite this, the module continuously enters the ql_enter_sleep_cb interrupt and immediately exits via ql_exit_sleep_cb. This process keeps repeating in a loop.

Questions:

  1. What could be causing the module to continuously wake up from Sleep Mode?
  2. Additionally, when I try to suspend another thread using ql_rtos_task_suspend(), the module resets.
  • Is there any special consideration or requirement when suspending a task?

My Code:

Power Demo Thread

static void ql_power_demo_thread(void *param)
{
    ql_event_t event;
    int err;

    // Register sleep callback function
    ql_sleep_register_cb(ql_enter_sleep_cb);
    
    // Register wakeup callback function
    ql_wakeup_register_cb(ql_exit_sleep_cb);

#ifdef QL_APP_FEATURE_USB    
    // Register USB hotplug callback function
    ql_usb_bind_hotplug_cb(usb_hotplug_cb);
#endif

    while(1)
    {
        if(Enter_SLEEP_Mode == true)   
        {
            Enter_SLEEP_Mode = false;
            ql_uart_write(QL_UART_PORT_1, "autosleepex Enabled\r\n", 19);
            ql_autosleep_enable(QL_ALLOW_SLEEP);
        }
    }
}

Sleep Mode Callback

void ql_enter_sleep_cb(void* ctx)
{   
    ql_uart_write(QL_UART_PORT_1, "Entered Sleep Mode\r\n", 20); 

#ifdef QL_APP_FEATURE_GNSS
    ql_pin_set_func(QL_PIN_NUM_KEYOUT_5, QL_FUN_NUM_UART_2_CTS);  
    ql_gpio_set_level(GPIO_12, LVL_HIGH);   
    ql_gpio_set_level(GPIO_11, LVL_LOW);    
#endif
}

Wakeup Callback

void ql_exit_sleep_cb(void* ctx)
{   
    ql_uart_write(QL_UART_PORT_1, "exit sleep cb\r\n", 15); 
    
#ifdef QL_APP_FEATURE_GNSS
    ql_pin_set_func(QL_PIN_NUM_KEYOUT_5, QL_FUN_NUM_UART_3_TXD);
#endif    
}

Any insights or suggestions would be greatly appreciated.

Thanks in advance for your help!

Dear @tariq,

The reason why the module keeps waking up is that it’s going into a infinite while loop with no place for it to sleep. You can add something like ql_rtos_task_sleep_s() into the loop so the task have time to to to sleep.
Please refer to the original power_demo.c for the correct way to enter sleep mode.

ql_rtos_task_suspend() is actually not a recommended way to “suspend” a task as it might cause unexpected problems. We recommend using a semaphore to “control” a task.

Thanks.

my friend i want to the whole module to go to low power sleep mode not just to make one task to sleep
the code that uses in power_demo.c is like this

      switch(event.id)
      {
		case QUEC_SLEEP_ENETR_AUTO_SLEPP:
			
			err = ql_autosleep_enable(QL_ALLOW_SLEEP);
			require_action(err, continue, "failed to set auto sleep");

			err = ql_lpm_wakelock_unlock(wake_lock_1);
			require_action(err, continue, "lock1 unlocked failed");

			err = ql_lpm_wakelock_unlock(wake_lock_2);
			require_action(err, continue, "lock2 unlocked failed");		
			
			QL_POWERDEMO_LOG("set auto sleep mode ok");
			
		break;

		case QUEC_SLEEP_EXIT_AUTO_SLEPP:
			err = ql_autosleep_enable(QL_NOT_ALLOW_SLEEP);
			require_action(err, continue, "failed to set auto sleep");
		break;

		case QUEC_SLEEP_QUICK_POWER_DOWM:
			ql_power_down(POWD_IMMDLY);
		break;

		case QUEC_SLEEP_NORMAL_POWER_DOWM:
			ql_power_down(POWD_NORMAL);
		break;

		case QUEC_SLEEP_QUICK_RESET:
			ql_power_reset(RESET_QUICK);
		break;

		case QUEC_SLEEP_NORMAL_RESET:
			ql_power_reset(RESET_NORMAL);
		break;

		default:
		break;
	}

which is the same of my code except that it uses event for handling it.

my problem is that when the module reaches this code
ql_autosleep_enable(QL_ALLOW_SLEEP);
it will Repeatedly goes to sleep mode and wakes up it does not stays in sleep mode
how can i fix this problem?
appreciate your help.

Dear @tariq,

I understand that you want the whole module to go to sleep.
In order to go into low power mode, all tasks should be suspended or sleeping. As long as it has something to do (calling ql_autosleep_enable(QL_ALLOW_SLEEP); is also “something to do”), it will not go into sleep mode.
Using ql_rtos_task_sleep_s() or event wait etc. we make sure the task is not doing anything, giving the module a chance to sleep.