espressif / esp-idf

Espressif IoT Development Framework. Official development framework for Espressif SoCs.
Apache License 2.0
13.51k stars 7.26k forks source link

switching from ble to wifi (IDFGH-4365) #6201

Closed lky2431 closed 2 years ago

lky2431 commented 3 years ago

Hi,

I am writing a project using ESP32-WROVER. One of the feature is that i have to send a wifi and password from a mobile phone to the esp32 through ble gatt server. The wifi information is sucessfully received. However, there is "lock_acquire_generic" bug or sometimes "corrode heap" bug when the esp is setting the wifi information.

The code I use to receive the wifi information like: static void gatts_profile_event_handler(esp_gatts_cb_event_t event, esp_gatt_if_t gatts_if, esp_ble_gatts_cb_param_t *param) {..... }else if (res == SPP_IDX_SPP_WIFI_VAL){ ESP_LOGI(GATTS_TABLE_TAG,"message come"); ..... sta_on();

The code I use to switch to wifi like: void sta_on(){ ESP_ERROR_CHECK(esp_wifi_set_config(ESP_IF_WIFI_STA, &wifi_config) ); ESP_ERROR_CHECK(esp_wifi_start() ); } The wifi is already initialized and set to STA before. It work completely fine if I set using wifi but not bluetooth for first program. After sending the wifi information. I see the log below: 0x40084e86: lock_acquire_generic at C:/esp/components/newlib/locks.c:143

0x40084fbd: _lock_acquire_recursive at C:/esp/components/newlib/locks.c:171

0x40195755: _vfiprintf_r at /builds/idf/crosstool-NG/.build/HOST-x86_64-w64-mingw32/xtensa-esp32-elf/src/newlib/newlib/libc/stdio/vfprintf.c:853 (discriminator 2)

0x40190c3f: fiprintf at /builds/idf/crosstool-NG/.build/HOST-x86_64-w64-mingw32/xtensa-esp32-elf/src/newlib/newlib/libc/stdio/fiprintf.c:48

0x40190bba: __assert_func at /builds/idf/crosstool-NG/.build/HOST-x86_64-w64-mingw32/xtensa-esp32-elf/src/newlib/newlib/libc/stdlib/assert.c:58 (discriminator 8)

0x400962a9: get_next_block at C:/esp/components/heap/multi_heap.c:131 (inlined by) split_if_necessary at C:/esp/components/heap/multi_heap.c:284

0x4009667e: multi_heap_malloc_impl at C:/esp/components/heap/multi_heap.c:462

0x400846b1: heap_caps_malloc at C:/esp/components/heap/heap_caps.c:115

0x400846f0: heap_caps_malloc_default at C:/esp/components/heap/heap_caps.c:148

0x40096d42: _calloc_r at C:/esp/components/newlib/heap.c:73

0x40096d64: calloc at C:/esp/components/newlib/heap.c:37

0x400842ed: wifi_calloc at C:/esp/components/esp_wifi/esp32/esp_adapter.c:96

0x4008432c: wifi_zalloc_wrapper at C:/esp/components/esp_wifi/esp32/esp_adapter.c:102

0x401604e0: esp_wifi_set_config at ??:?

If seemed the problem is that the program cannot locate proper memory when I set the esp_wifi_config.

If anyone have similar experience on how to solve this, could you share some to me. I would be grateful about it. Thank you

TimXia commented 3 years ago

@lky2431 Could you please provide a demo to reproduce the issue? You can also try the blufi example in IDF. It does the same thing as you expected.

xulongzhuang commented 3 years ago

@lky2431 ,Please provide more detailed information, such as IDF version and commit ID, if there is a demo that can reproduce the problem, it would be better

Alvin1Zhang commented 3 years ago

@lky2431 Thanks for reporting, would you please help share if any updates for the issue? Thanks.

jack0c commented 2 years ago

@lky2431 It looks like a heap issue,there are several heap issues fixed,please update the latest release version

Alvin1Zhang commented 2 years ago

Thanks for reporting, feel free to reopen.