(resolved) wifi failing on startup

User avatar
mzimmers
Posts: 506
Joined: Wed Mar 07, 2018 11:54 pm
Location: USA

(resolved) wifi failing on startup

Postby mzimmers » Thu Jan 16, 2020 5:04 pm

Hi all -

My app recently began failing due to a wifi error. This occurs shortly after startup, and is highly repeatable. I've done a web search for some of the keywords, but haven't found anything definitive. Any ideas what might cause this? It's kind of a show-stopper right now.

Code: Select all

I (27953) wifi: bcn_timout,ap_probe_send_start
I (30453) wifi: ap_probe_send over, resett wifi status to disassoc
I (30453) wifi: state: run -> init (c800)
I (30463) wifi: pm stop, total sleep time: 5281933 us / 26567647 us
Running on a WROVER, release/V4.0 of the IDF.

Thanks...
Last edited by mzimmers on Tue Jan 21, 2020 8:50 pm, edited 1 time in total.

User avatar
mzimmers
Posts: 506
Joined: Wed Mar 07, 2018 11:54 pm
Location: USA

Re: wifi failing on startup

Postby mzimmers » Thu Jan 16, 2020 8:02 pm

Here's a more complete copy of the log when this happens (the event_handler and setCommsState messages are mine):

Code: Select all

I (25453) wifi: bcn_timout,ap_probe_send_start
I (27963) wifi: ap_probe_send over, resett wifi status to disassoc
I (27963) wifi: state: run -> init (c800)
I (27963) wifi: pm stop, total sleep time: 14133508 us / 23963709 us

I (27963) wifi: new:<1,0>, old:<1,0>, ap:<255,255>, sta:<1,0>, prof:1
W (27973) Wifi: event_handler(): Wifi disconnected at Thu Jan 16 12:00:42 2020; reason code is 200.
I (27983) wifi: flush txq
I (27983) wifi: stop sw txq
I (27983) wifi: lmac stop hw txq
I (27983) Wifi: setCommsState() changing state to Disconnected.
W (27993) Wifi: event_handler(): Wifi stopped at Thu Jan 16 12:00:42 2020.
I (28003) Wifi: setCommsState() changing state to Stopped.
E (28023) phy_init: failed to allocate memory for RF calibration data
abort() was called at PC 0x4018cb9a on core 0

User avatar
mzimmers
Posts: 506
Joined: Wed Mar 07, 2018 11:54 pm
Location: USA

Re: wifi failing on startup

Postby mzimmers » Mon Jan 20, 2020 10:35 pm

BTT. I could really use some help with this one.

I increased the stack size to a ridiculous amount (0x8000 bytes) for my wifi task, which eliminated the stack overflow, though something seems wrong about this, given that it used to work with about 1/4 that amount of stack.

Then, through trial and error, I've identified a particular system call that returns an error:

Code: Select all

    memReport();
    wifi_init_config_t WIFI_INIT_CONFIG = WIFI_INIT_CONFIG_DEFAULT();
    err = esp_wifi_init(&WIFI_INIT_CONFIG);
    if (err != ESP_OK)
    {
        ESP_LOGE(TAG, "taskInit(): esp_wifi_init() returned 0x%x.", err);
        vTaskDelay(portMAX_DELAY);
    }
Returns this:

Code: Select all

I (2767) memreport: memReport(): there are 64960 MALLOC_CAP_32BIT bytes free.
I (2777) memreport: memReport(): there are 25120 MALLOC_CAP_8BIT bytes free.
I (2797) memreport: memReport(): there are 25120 MALLOC_CAP_DMA bytes free.
I (2807) memreport: memReport(): there are 0 MALLOC_CAP_SPIRAM bytes free.
I (2817) memreport: memReport(): there are 64960 MALLOC_CAP_INTERNAL bytes free.
I (2827) memreport: memReport(): there are 25120 MALLOC_CAP_DEFAULT bytes free.
I (2847) memreport: memReport(): there are 0 MALLOC_CAP_INVALID bytes free.
I (2867) wifi: wifi driver task: 3ffd8b9c, prio:23, stack:3584, core=0
I (2877) wifi: wifi firmware version: 581f422
I (2877) wifi: config NVS flash: enabled
I (2877) wifi: config nano formating: disabled
I (2877) wifi: Init dynamic tx buffer num: 32
I (2887) wifi: Init data frame dynamic rx buffer num: 32
I (2887) wifi: Init management frame dynamic rx buffer num: 32
I (2897) wifi: Init management short buffer num: 32
I (2897) wifi: Init static rx buffer size: 1600
W (2907) wifi: malloc buffer fail
I (2907) wifi: Init static rx buffer num: 9
I (2907) wifi: Init dynamic rx buffer num: 32
E (2917) wifi: Expected to init 10 rx buffer, actual is 9
I (2917) wifi: Deinit lldesc rx mblock:0
I (2927) wifi: Deinit lldesc rx mblock:0
I (2927) wifi: Deinit lldesc rx mblock:0
I (2927) wifi: Deinit lldesc rx mblock:0
E (2947) Wifi: taskInit(): esp_wifi_init() returned 0x101.
Where 0x101 is ESP_ERR_NO_MEM: out of memory.

Any idea what gives here? What memory am I out of that this call needs?

ESP_Sprite
Posts: 4032
Joined: Thu Nov 26, 2015 4:08 am

Re: wifi failing on startup

Postby ESP_Sprite » Tue Jan 21, 2020 9:18 am

My guess would be that 25K of 'default' internal memory is too little.

User avatar
mzimmers
Posts: 506
Joined: Wed Mar 07, 2018 11:54 pm
Location: USA

Re: wifi failing on startup

Postby mzimmers » Tue Jan 21, 2020 2:44 pm

Hi Sprite -

Thanks for the reply. Do we have any tools that help us profile memory use? I agree with your assessment, but I'm not sure how to go about fixing it.

User avatar
mzimmers
Posts: 506
Joined: Wed Mar 07, 2018 11:54 pm
Location: USA

Re: wifi failing on startup

Postby mzimmers » Tue Jan 21, 2020 8:49 pm

I'm going to mark this thread as resolved, as the problem isn't the wifi subsystem per se, but rather a memory shortage. I'll probably start a new thread on that topic shortly.

iParcelBox
Posts: 12
Joined: Sun Oct 27, 2019 3:12 pm

Re: (resolved) wifi failing on startup

Postby iParcelBox » Fri Jul 24, 2020 12:39 pm

I'd be very interested to hear how you resolved this issue? I'm seeing very similar behaviour on several of my devices, despite them being connected to robust AP with no RSSI issues. Randomly I'll see a bcn_timout error as per your logs above and then my ESP32-Wrover usually fails to reconnect to TCP/MQTT until after a reboot.

User avatar
mzimmers
Posts: 506
Joined: Wed Mar 07, 2018 11:54 pm
Location: USA

Re: (resolved) wifi failing on startup

Postby mzimmers » Fri Jul 24, 2020 2:16 pm

See the final paragraph in my final post here: viewtopic.php?f=13&t=15978. Hopefully this will help you.

iParcelBox
Posts: 12
Joined: Sun Oct 27, 2019 3:12 pm

Re: (resolved) wifi failing on startup

Postby iParcelBox » Sat Jul 25, 2020 5:39 pm

Thanks. I've tried reducing the stack size but it doesn't seem to have made any difference in my case.

User avatar
mzimmers
Posts: 506
Joined: Wed Mar 07, 2018 11:54 pm
Location: USA

Re: (resolved) wifi failing on startup

Postby mzimmers » Sun Jul 26, 2020 3:20 pm

You need to have enough of the "right" kind of memory for esp_wifi_init(). I'd suggest you put something like this:

Code: Select all

bytesFree = heap_caps_get_free_size(MALLOC_CAP_8BIT | MALLOC_CAP_SPIRAM);
    ESP_LOGI(TAG, "memReport(): there are %zu MALLOC_CAP_8BIT | MALLOC_CAP_SPIRAM bytes free.", bytesFree);
before your call to esp_wifi_init(). If you don't have about 70K, you don't have enough, and you'll have to go through your app to find ways to free some up. Sorry I can't be more specific.

Who is online

Users browsing this forum: Google [Bot], timmbo and 49 guests