Failing to allocate memory for RF calibration data when reiniting WIFI

mr1000
Posts: 23
Joined: Fri Jan 12, 2018 9:05 am

Failing to allocate memory for RF calibration data when reiniting WIFI

Postby mr1000 » Thu Feb 15, 2018 1:41 pm

Hi, the router I'm using is pretty bad and each X minutes I'm losing connection with the ESP32 (also happens with laptops so yes it's the router). The thing is I'm trying to implement some solution to let ESP32 reconnect itself.

So I modified the handler switch code but it fails with this error, allocating memory for RF calibration (when reiniting).
I have tried to change the main rtos stack to 16k but same result. Also tried esp_wifi_set_storage(WIFI_STORAGE_FLASH).

Here's the switch event handler code:
https://gist.github.com/anonymous/46dd1 ... 426d2c1352

And this is my WIFI initialisatio called in app_main()
https://gist.github.com/anonymous/2d023 ... b00369fe2c

And the error I get. At some point router fails and a beacon tiemout happens.

Code: Select all

I (913694) wifi: bcn_timout,ap_probe_send_start
I (916204) wifi: ap_probe_send over, resett wifi status to disassoc
I (916204) wifi: state: run -> init (1)
I (916204) wifi: pm stop, total sleep time: 0/909618396

I (916204) wifi: n:1 0, o:1 1, ap:255 255, sta:1 1, prof:1
I (916214) wifi: Sha desconnectat el wifi, fem un deinit i la resta de inits a veure si es reconnecta
I (916224) wifi: flush txq
I (916224) wifi: stop sw txq
I (916224) wifi: lmac stop hw txq
I (916224) wifi: Deinit lldesc rx mblock:10
I (916234) wifi: wifi firmware version: 403db1d
I (916234) wifi: config NVS flash: enabled
I (916234) wifi: config nano formating: disabled
I (916244) system_api: Base MAC address is not set, read default base MAC address from BLK0 of EFUSE
I (916254) system_api: Base MAC address is not set, read default base MAC address from BLK0 of EFUSE
I (916284) wifi: Init dynamic tx buffer num: 32
I (916284) wifi: Init data frame dynamic rx buffer num: 32
I (916284) wifi: Init management frame dynamic rx buffer num: 32
I (916284) wifi: wifi driver task: 3ffc9368, prio:23, stack:4096
I (916294) wifi: Init static rx buffer num: 10
I (916294) wifi: Init dynamic rx buffer num: 32
I (916304) wifi: wifi power manager task: 0x3ffc9db8 prio: 21 stack: 2560
I (916304) wifi: Setting WiFi configuration SSID Despatx63...
E (916314) phy_init: failed to allocate memory for RF calibration data
abort() was called at PC 0x401207f9 on core 0

Backtrace: 0x40087c54:0x3ffc47a0 0x40087d53:0x3ffc47c0 0x401207f9:0x3ffc47e0 0x400d9802:0x3ffc4800 0x400d9870:0x3ffc4830 0x400da077:0x3ffc4860 0x400ebbea:0x3f                                           fc4880

Rebooting...
ets Jun  8 2016 00:22:57

rst:0xc (SW_CPU_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
configsip: 0, SPIWP:0xee
clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
mode:DIO, clock div:2
load:0x3fff0018,len:4
load:0x3fff001c,len:5672
load:0x40078000,len:0
ho 12 tail 0 room 4
load:0x40078000,len:13716
entry 0x40078fb4
In the reboot it flashes ok and connects to wifi ok.

So what am I doing wrong, I'm not deinit wifi correctly ...?
I've seen many posts with problems with reconnecting to wifi, but not this one of allocating memory..

Any help will be much apreciated.
Thanks.

WiFive
Posts: 3529
Joined: Tue Dec 01, 2015 7:35 am

Re: Failing to allocate memory for RF calibration data when reiniting WIFI

Postby WiFive » Thu Feb 15, 2018 6:28 pm

That will use heap memory so print your free heap and check for memory leak

ESP_Angus
Posts: 2344
Joined: Sun May 08, 2016 4:11 am

Re: Failing to allocate memory for RF calibration data when reiniting WIFI

Postby ESP_Angus » Fri Feb 16, 2018 1:38 am

Hi mr1000,

I'm not sure that it's safe to fully de-initialize WiFi in the context of the event handler itself. You may have to signal a different task to do this, if you need to.

However, I think fully de-initializing shouldn't be necessary - that's fairly extreme "scorched earth" tactics!
  • Is calling esp_wifi_connect() from here not working somehow? This should be enough to reconnect, unless the router is rejecting connections outright (in which case it may not matter what the ESP32 does, you'll need to wait until the router accepts connections again.)
  • Is calling esp_wifi_stop() / esp_wifi_start() enough to work around whatever you are seeing?

... if you can get a "monitor mode" 802.11 capture using WireShark, this may provide some clues as to what the router is doing which is causing this problem in the first place.

mr1000
Posts: 23
Joined: Fri Jan 12, 2018 9:05 am

Re: Failing to allocate memory for RF calibration data when reiniting WIFI

Postby mr1000 » Tue Mar 06, 2018 3:20 pm

Hi, sorry for responding so late, I had other priority work, but now my hand are again over the esp32 :D
ESP_Angus wrote:Hi mr1000,

I'm not sure that it's safe to fully de-initialize WiFi in the context of the event handler itself. You may have to signal a different task to do this, if you need to.

However, I think fully de-initializing shouldn't be necessary - that's fairly extreme "scorched earth" tactics!
  • Is calling esp_wifi_connect() from here not working somehow? This should be enough to reconnect, unless the router is rejecting connections outright (in which case it may not matter what the ESP32 does, you'll need to wait until the router accepts connections again.)
  • Is calling esp_wifi_stop() / esp_wifi_start() enough to work around whatever you are seeing?

... if you can get a "monitor mode" 802.11 capture using WireShark, this may provide some clues as to what the router is doing which is causing this problem in the first place.
When I used only esp_wifi_connect() in case: SYSTEM_EVENT_STA_DISCONNECTED, it got stuck in a loop that every 3 seconds that event was being triggered and it tries to connect but nothing happens, it just doesn't connect. I have tried 2 different routers with the exact same result.
I have tried also to trigger the esp_wifi_connect in a task different than the wifi handler, same result.


Now (in other task different than the wifi handler) I was trying to this sequence:

Code: Select all

esp_wifi_stop();
esp_wifi_start();
esp_wifi_connect();
But the RF calibration alloc memory error commented in the OP occurs in esp_wifi_start(). I really don't know that to do or what to try now.

Also, how can I know which esp-idf version I'm using :oops: I know it's not the last, but maybe it's one too deprecated and I've read over github posts that last ones fix problems like this (?) so maybe I should try that...

Thanks again,
m


EDIT 16/03/2018: it seems my coworker solved the problem, was a heap problem, our application sends POST each X time and I wasn't freeing the memory of the needed structs so at some points the ESP32 crashes

Who is online

Users browsing this forum: Bing [Bot] and 114 guests