ESP8266 Developer Zone The Official ESP8266 Forum 2018-11-02T11:47:09+08:00 https://bbs.espressif.com:443/feed.php?f=7&t=1134 2018-11-02T11:47:09+08:00 2018-11-02T11:47:09+08:00 https://bbs.espressif.com:443/viewtopic.php?t=1134&p=35205#p35205 <![CDATA[Re: [Resolved]wifi_fpm_do_sleep crashes]]> Statistics: Posted by JacksonLv — Fri Nov 02, 2018 11:47 am


]]>
2015-09-24T00:04:25+08:00 2015-09-24T00:04:25+08:00 https://bbs.espressif.com:443/viewtopic.php?t=1134&p=3824#p3824 <![CDATA[Re: wifi_fpm_do_sleep crashes]]> Statistics: Posted by tve — Thu Sep 24, 2015 12:04 am


]]>
2015-09-23T23:46:05+08:00 2015-09-23T23:46:05+08:00 https://bbs.espressif.com:443/viewtopic.php?t=1134&p=3823#p3823 <![CDATA[Re: wifi_fpm_do_sleep crashes]]>
You write "If ESP8266 entered the light sleep mode, it needs to be waked up via external GPIO", this is in contradiction to the SDK Programmng Guide description of wifi_fpm_do_sleep() (page 86) which states "Force ESP8266 enter sleep mode, and it will wake up automatically when time out."

Thanks!

Statistics: Posted by tve — Wed Sep 23, 2015 11:46 pm


]]>
2015-09-23T15:45:36+08:00 2015-09-23T15:45:36+08:00 https://bbs.espressif.com:443/viewtopic.php?t=1134&p=3818#p3818 <![CDATA[Re: wifi_fpm_do_sleep crashes]]>
Here is the documentation about sleep modehttp://bbs.espressif.com/viewtopic.php?f=51&t=645.

If ESP8266 entered the light sleep mode, it needs to be waked up via external GPIO before calling wifi_set_opmode(STATION_MODE); and wifi_station_connect();

Please have a try with the lib as attachment, we add an API to set the callback which will be entered after wake up from force sleep.

Code:

void wifi_fpm_set_wakeup_cb(void (*fpm_wakeup_cb_func)(void));


Example:

Code:

//sleep over.
void fpm_wakup_cb_func1(void)
{
   wifi_fpm_close();   //disable sleep function
   wifi_set_opmode(STATION_MODE);      //set wifi mode to station mode
   wifi_station_connect();         //connect ap
}

void user_func(...)

wifi_station_disconnect();
wifi_set_opmode(NULL_MODE);      //set wifi mode to null mode.
wifi_fpm_set_sleep_type(LIGHT_SLEEP_T);      //set force sleep type, clsoe rf&cpu
wifi_fpm_open();            //enable force sleep fucntion
wifi_fpm_set_wakeup_cb(fpm_wakup_cb_func1);   //Set fpm wakeup callback function
wifi_fpm_do_sleep(10*1000);         // do sleep
...
}
libpp_fpm_sdk_v1.4.0.zip

Statistics: Posted by ESP_Faye — Wed Sep 23, 2015 3:45 pm


]]>
2015-09-23T12:33:53+08:00 2015-09-23T12:33:53+08:00 https://bbs.espressif.com:443/viewtopic.php?t=1134&p=3817#p3817 <![CDATA[Re: wifi_fpm_do_sleep crashes]]>

Code:

wifi_station_disconnect();
wifi_set_opmode_current(NULL_MODE);
os_delay_us(1000);
os_printf("Sleep!\n");
os_delay_us(600);
wifi_fpm_set_sleep_type(LIGHT_SLEEP_T);
wifi_fpm_open();
int8_t err = wifi_fpm_do_sleep(100*1000);
if (err != 0) os_printf("Sleep error: %d\n", err);
os_printf("Back!\n");
wifi_set_opmode(STATION_MODE);
wifi_station_connect();

This does the sleep properly, but afterwards the wifi does not reconnect:

Code:

ip:192.168.0.114,mask:255.255.255.0,gw:192.168.0.1
fpm close 3
pm open phy_2,type:1 0 0
Sleep!
force slp enable,type: 1
pm close 7 0 2131886/3837583
fpm open,type:1 0
Sleep error: 0
Back!
fpm wk err: pm is open
fpm wk err: pm is open
fpm wk err: pm is open
f r0, fpm wk err: pm is open
fpm wk err: pm is open
fpm wk err: pm is open
fpm wk err: pm is open
scandone
state: 5 -> 0 (0)
fpm wk err: pm is open
fpm wk err: pm is open
fpm wk err: pm is open
rm 0
fpm wk err: pm is open
fpm wk err: pm is open
del if0
usl
mode : null
Wifi disconnected from ssid tv▒ 뫫      ▒WV▒▒▒
R֮▒k▒ū+▒W$%NJC▒▒LC▒▒pm,w1
wifi status=255

After this wifi_station_get_connect_status() always returns 255

Statistics: Posted by tve — Wed Sep 23, 2015 12:33 pm


]]>
2015-09-23T12:26:01+08:00 2015-09-23T12:26:01+08:00 https://bbs.espressif.com:443/viewtopic.php?t=1134&p=3816#p3816 <![CDATA[Re: wifi_fpm_do_sleep crashes]]>
Something I'm seeing is that after a reset I initialize fpm and it prints:

Code:

force slp enable,type: 1
fpm open,type:1 0
and then the wifi eventually connects and I see:

Code:

Wifi connected to ssid tve-home, ch 1
ip:192.168.0.114,mask:255.255.255.0,gw:192.168.0.1
fpm close 3
pm open phy_2,type:1 0 0

Why does it say "fpm close 3"? I didn't call wifi_fpm_close()

After this there is a failed sleep (notice sleep error -2):

Code:

state: 5 -> 0 (0)
rm 0
pm close 7 0 1381340/2756243
del if0
usl
mode : null
Sleep!
force slp enable,type: 1
Sleep error: -2
Back!
mode : sta(18:fe:34:a6:e8:8f)
add if0

At the next attempt sleep crashes:
Wifi connected to ssid tve-home, ch 1

Code:

ip:192.168.0.114,mask:255.255.255.0,gw:192.168.0.1
Wifi got ip:192.168.0.114,mask:255.255.255.0,gw:192.168.0.1
pm open phy_2,type:1 0 0
Sleep!
force slp enable,type: 1
pm2 684
▒@▒rjrA(▒

The crashing one has many fewer state transitions, it seems. Something I find suspicious in both cases is that "Sleep!" is printed before "force slp enable,type: 1" even though the code is

Code:

os_printf("Sleep!\n");
os_delay_us(600);
wifi_fpm_set_sleep_type(LIGHT_SLEEP_T);
int8_t err = wifi_fpm_do_sleep(100*1000);

This smells like a race condition somewhere?

Statistics: Posted by tve — Wed Sep 23, 2015 12:26 pm


]]>
2015-09-23T11:58:45+08:00 2015-09-23T11:58:45+08:00 https://bbs.espressif.com:443/viewtopic.php?t=1134&p=3815#p3815 <![CDATA[Re: wifi_fpm_do_sleep crashes]]> https://github.com/jeelabs/esp-pico/blo ... .c#L47-L54

Code:

    // before entering light sleep we have to turn off wifi
    wifi_station_disconnect();
    wifi_set_opmode_current(NULL_MODE);
    os_delay_us(1000);
    // print a message and sleep enough for the uart to send the characters out
    os_printf("Sleep!\n");
    os_delay_us(600);
    // enter sleep mode
    int8_t err = wifi_fpm_do_sleep(10*1000);
    if (err != 0) os_printf("Sleep error: %d\n", err);
    // and here we're back?
    os_printf("Back!\n");
    wifi_set_opmode(STATION_MODE);
    wifi_station_connect();

Do I have to repeat the call to wifi_fpm_set_sleep_type(XXX) ? I only have that once at initialization time together with wifi_fpm_open: https://github.com/jeelabs/esp-pico/blo ... .c#L96-L97

Statistics: Posted by tve — Wed Sep 23, 2015 11:58 am


]]>
2015-09-23T11:41:38+08:00 2015-09-23T11:41:38+08:00 https://bbs.espressif.com:443/viewtopic.php?t=1134&p=3814#p3814 <![CDATA[Re: wifi_fpm_do_sleep crashes]]>
In your log

Code:

Wifi got ip:192.168.0.114,mask:255.255.255.0,gw:192.168.0.1
 14094> wifi status=5 tick=0
fpm close 3
pm open phy_2,type:1 0 0
 18094> wifi status=5 tick=2
Sleep!
pm2 684

It seems that you did not call wifi_station_disconnect(); and wifi_set_opmode_current(NULL_MODE); before enter force sleep mode.
Otherwise,the log should be

Code:

ip:192.168.1.113,mask:255.255.255.0,gw:192.168.1.1
state: 5 -> 0 (0)


In your case, the ESP8266 is still in the staion mode and connected to a router. You need to call wifi_station_disconnect(); and wifi_set_opmode_current(NULL_MODE); before enter force sleep mode.

Code:

wifi_station_disconnect();
wifi_set_opmode_current(NULL_MODE);
wifi_fpm_set_sleep_type(XXX);
wifi_fpm_open();

Statistics: Posted by ESP_Faye — Wed Sep 23, 2015 11:41 am


]]>
2015-09-23T09:41:40+08:00 2015-09-23T09:41:40+08:00 https://bbs.espressif.com:443/viewtopic.php?t=1134&p=3810#p3810 <![CDATA[Re: wifi_fpm_do_sleep crashes]]> Statistics: Posted by tve — Wed Sep 23, 2015 9:41 am


]]>
2015-09-22T14:30:08+08:00 2015-09-22T14:30:08+08:00 https://bbs.espressif.com:443/viewtopic.php?t=1134&p=3799#p3799 <![CDATA[Re: wifi_fpm_do_sleep crashes]]> https://github.com/jeelabs/esp-pico and can be compiled using esp-open-sdk and esp_iot_sdk_v1.4.0. The paths to these components are defined in the Makefile. There are only 3 .c files involved (in the core directory) so you should be able to compile it easily using your tools of choice also. Note that the firmware assumes that the wifi station SSID and password are already configured in the flash. You can also find a compiled binary at https://github.com/jeelabs/esp-pico/rel ... /user1.bin (this should be loaded at 0x1000 and uses the 4MB OTA firmware partition model with 2x512KB partitions).

Here is a sample output:

Code:

 ets Jan  8 2013,rst cause:1, boot mode:(3,7)

load 0x40100000, len 1396, room 16
tail 4
chksum 0x89
load 0x3ffe8000, len 776, room 4
tail 4
chksum 0xe8
load 0x3ffe8308, len 540, room 4
tail 8
chksum 0xc0
csum 0xc0

2nd boot version : 1.4(b1)
  SPI Speed      : 80MHz
  SPI Mode       : QIO
  SPI Flash Size & Map: 32Mbit(512KB+512KB)
jump to run user1 @ 1000

r▒9l▒▒^!!!▒

** esp-pico master - 2015-09-21 23:01:49 - development
sleep enable,type: 1
force slp enable,type: 1
fpm open,type:1 0
Reset cause: 3=soft wdt
exccause=4 epc1=0x4021aace epc2=0x0 epc3=0x0 excvaddr=0x0 depc=0x0
Flash map 4MB:512/512, manuf 0xEF chip 0x4016
** esp-pico ready
mode : sta(18:fe:34:a6:e8:8f)
add if0
f r-1, scandone
state: 0 -> 2 (b0)
state: 2 -> 3 (0)
state: 3 -> 5 (10)
add 0
aid 4
cnt
  2094> wifi status=1 tick=0
  4094> wifi status=1 tick=0
  6094> wifi status=1 tick=0
state: 5 -> 2 (fa0)
rm 0
Wifi disconnected from ssid tve-home, reason group_key_update_timeout (15)
reconnect
state: 2 -> 0 (0)
f r-1, scandone
state: 0 -> 2 (b0)
state: 2 -> 3 (0)
state: 3 -> 5 (10)
add 0
aid 1
cnt
  8094> wifi status=2 tick=0

connected with tve-home, channel 1
dhcp client start...
Wifi connected to ssid tve-home, ch 1
 10094> wifi status=2 tick=0
 12094> wifi status=2 tick=0
ip:192.168.0.114,mask:255.255.255.0,gw:192.168.0.1
Wifi got ip:192.168.0.114,mask:255.255.255.0,gw:192.168.0.1
 14094> wifi status=5 tick=0
 16094> wifi status=5 tick=1
fpm close 3
pm open phy_2,type:1 0 0
 18094> wifi status=5 tick=2
 20094> wifi status=5 tick=3
 22094> wifi status=5 tick=4
Sleep!
pm2 684

 ets Jan  8 2013,rst cause:1, boot mode:(3,7)

load 0x40100000, len 1396, room 16
tail 4
chksum 0x89
load 0x3ffe8000, len 776, room 4
tail 4
chksum 0xe8
load 0x3ffe8308, len 540, room 4
tail 8
chksum 0xc0
csum 0xc0

2nd boot version : 1.4(b1)
  SPI Speed      : 80MHz
  SPI Mode       : QIO
  SPI Flash Size & Map: 32Mbit(512KB+512KB)
jump to run user1 @ 1000

r▒9l▒▒^!!!▒

** esp-pico master - 2015-09-21 23:01:49 - development
sleep enable,type: 1
force slp enable,type: 1
fpm open,type:1 0
Reset cause: 3=soft wdt
exccause=4 epc1=0x4021aace epc2=0x0 epc3=0x0 excvaddr=0x0 depc=0x0
Flash map 4MB:512/512, manuf 0xEF chip 0x4016

Statistics: Posted by tve — Tue Sep 22, 2015 2:30 pm


]]>
2015-09-21T15:28:13+08:00 2015-09-21T15:28:13+08:00 https://bbs.espressif.com:443/viewtopic.php?t=1134&p=3781#p3781 <![CDATA[Re: wifi_fpm_do_sleep crashes]]>
Yes, wifi_station_disconnect(); and wifi_set_opmode_current(NULL_MODE); are needed before calling force sleep function. We will add more description on this in the documentation.

Please provide your test code, we will have a try.

Statistics: Posted by ESP_Faye — Mon Sep 21, 2015 3:28 pm


]]>
2015-09-21T15:30:07+08:00 2015-09-21T15:19:51+08:00 https://bbs.espressif.com:443/viewtopic.php?t=1134&p=3780#p3780 <![CDATA[Re: wifi_fpm_do_sleep crashes]]>

Code:

wifi_station_disconnect();
wifi_set_opmode_current(NULL_MODE);

before the sleep, but that doesn't make a difference, it still crashes. I will have to simplify the code so you can make sense of it...

Statistics: Posted by tve — Mon Sep 21, 2015 3:19 pm


]]>
2015-09-21T15:06:32+08:00 2015-09-21T15:06:32+08:00 https://bbs.espressif.com:443/viewtopic.php?t=1134&p=3779#p3779 <![CDATA[[Resolved]wifi_fpm_do_sleep crashes]]>

Code:

static void ICACHE_FLASH_ATTR prSleepTimerCb(void *arg) {
   os_printf("Sleep!\n");
   os_delay_us(600); // time for "Sleep!" to be printed at 115200 baud
   int8_t err = wifi_fpm_do_sleep(1000*1000);
   if (err != 0) os_printf("Sleep error: %d\n", err);
   os_printf("Back!\n");
 }

void user_init(void) {
  ...
  os_timer_disarm(&prHeapTimer);
  wifi_fpm_set_sleep_type(LIGHT_SLEEP_T);
  wifi_fpm_open();
  os_timer_disarm(&prHeapTimer);
  os_timer_setfn(&prHeapTimer, prSleepTimerCb, NULL);
  os_timer_arm(&prHeapTimer, 20000, 0);
  ...
}


Some of the os_printf output:

Code:

   141> force slp enable,type: 1
   141> fpm open,type:1 0
...
  8831> connected with tve-home, channel 1
  8831> dhcp client start...
 11605> ip:192.168.0.114,mask:255.255.255.0,gw:192.168.0.1
 15125> Wifi check: mode=STA status=5
 17948> fpm close 3
 17948> pm open phy_2,type:2 0 0
 20141> Sleep!
 20142> pm2 684

 ets Jan  8 2013,rst cause:1, boot mode:(3,7)

Ooops, that's a crash! (The number at the left shows milliseconds since boot.)
The crash info is: Reset cause: 3=soft wdt , exccause=4 epc1=0x40221ac6 epc2=0x0 epc3=0x0 excvaddr=0x0 depc=0x0
The crash location is near the beginning of fpm_do_sleep:

Code:

40221aa8 <fpm_do_sleep>:
fpm_do_sleep():
40221aa8:       f0c112          addi    a1, a1, -16
40221aab:       006122          s32i    a2, a1, 0
40221aae:       016102          s32i    a0, a1, 4
40221ab1:       ff3485          call0   40220dfc <pm_is_open>
40221ab4:       011216          beqz    a2, 40221ac9 <fpm_do_sleep+0x21>
40221ab7:       fe7721          l32r    a2, 40221494 <fpm_attach+0x1e4>
40221aba:       fe7731          l32r    a3, 40221498 <fpm_attach+0x1e8>
40221abd:       aca242          movi    a4, 0x2ac
40221ac0:       7d5901          l32r    a0, 40201024 <_irom0_text_start+0x14>
40221ac3:       0000c0          callx0  a0
40221ac6:       ffff06          j       40221ac6 <fpm_do_sleep+0x1e>
40221ac9:       fd7941          l32r    a4, 402210b0 <pm_get_idle_wait_time+0x44>
40221acc:       4408            l32i.n  a0, a4, 16
40221ace:       e27c            movi.n  a2, -2
40221ad0:       02e0d7          bbsi    a0, 13, 40221ad6 <fpm_do_sleep+0x2e>
40221ad3:       0001c6          j       40221ade <fpm_do_sleep+0x36>
...

Help?

Statistics: Posted by tve — Mon Sep 21, 2015 3:06 pm


]]>