Page 1 of 1

SDK 2.1 ligth sleep mode

Posted: Mon Jan 15, 2018 6:43 pm
by JulienInnovel
Hello,

I'm using the new SDK 2.1 since this morning.
Until the new sdk (using the SDK 2.0), I was able to use the light sleep mode by doing this :

void fpm_wakup_cb(void)
{
wifi_fpm_close(); // disable force sleep function
wifi_set_opmode(STATION_MODE); // set station mode
wifi_station_connect(); // connect to AP
os_timer_arm(&s_Timer, TIMER_TIME_MS, 1);
uart_rx_intr_enable(UART1);
os_printf("WakeUp !\n");
}

void ICACHE_FLASH_ATTR prepare_to_sleep(void)
{
int8_t err;

os_timer_disarm(&s_Timer);
LED_OFF;
os_printf("Go to sleep mode...\n\n");
uart_rx_intr_disable(UART1);
wifi_station_disconnect();
//wifi_set_opmode(NULL_MODE); // set WiFi mode to null mode.
wifi_set_opmode_current(NULL_MODE);
wifi_fpm_set_sleep_type(LIGHT_SLEEP_T); // light sleep
wifi_fpm_open(); // enable force sleep
wifi_fpm_set_wakeup_cb(fpm_wakup_cb); // Set wakeup callback
UART_CheckOutputFinished(UART1, 1000000);
wifi_fpm_do_sleep(30 * 1000 * 1000);
}

Each time I call function prepare_to_sleep, the ESP enter sleep mode and wake up after 30s.
But, since the new SDK 2.1, it doesn't work...
Sometimes the wakeup is done juste after the sleep, like if sleep timeout is 1us, and sometimes no wakeup from sleep...

Maybe I do something wrong...

Thanks for your help,
Best regards

Re: SDK 2.1 ligth sleep mode

Posted: Wed Jan 17, 2018 4:16 pm
by Her Mary
What is the UART_CheckOutputFinished?
If it is a timer, the timer will stop the ESP to enter light sleep mode.

Re: SDK 2.1 ligth sleep mode

Posted: Thu Feb 08, 2018 9:12 pm
by JulienInnovel
Hi,

Here is the function :

Code: Select all

bool ICACHE_FLASH_ATTR
UART_CheckOutputFinished(uint8 uart_no, uint32 time_out_us)
{
    uint32 t_start = system_get_time();
    uint8 tx_fifo_len;
    uint32 tx_buff_len;
    while(1){
        tx_fifo_len =( (READ_PERI_REG(UART_STATUS(uart_no))>>UART_TXFIFO_CNT_S)&UART_TXFIFO_CNT);
        if(pTxBuffer){
            tx_buff_len = ((pTxBuffer->UartBuffSize)-(pTxBuffer->Space));
        }else{
            tx_buff_len = 0;
        }
      
        if( tx_fifo_len==0 && tx_buff_len==0){
            return TRUE;
        }
        if( system_get_time() - t_start > time_out_us){
            return FALSE;
        }
   WRITE_PERI_REG(0X60000914, 0X73);//WTD
    }   
}