Heap error from BLE GATT client

afrohl
Posts: 2
Joined: Tue Aug 15, 2017 9:56 pm

Heap error from BLE GATT client

Postby afrohl » Thu Aug 17, 2017 9:10 pm

Hi all,

I'm trying to make a BLE scanner that first uses GAP to get a list of devices, stores those devices, then connects to each one with GATT to get the list of services. After some time (about 10 minutes) i get this error

Code: Select all

E (126648) BT: bta_gattc_conn_cback() - cif=3 connected=0 conn_id=3 reason=0x0016
assertion "!is_free(pb)" failed: file "/esp/esp-idf/components/heap/./multi_heap.c", line 350, function: multi_heap_free
abort() was called at PC 0x400d4e73 on core 0

Backtrace: 0x40087c98:0x3ffd83a0 0x40087d63:0x3ffd83c0 0x400d4e73:0x3ffd83e0 0x400876fb:0x3ffd8410 0x40081d96:0x3ffd8430 0x400822a9:0x3ffd8450 0x4000bec7:0x3ffd8470 0x40106cad:0x3ffd8490 0x40105932:0x3ffd84b0 0x400eec16:0x3ffd84d0
0x40087c98: invoke_abort at /esp/esp-idf/components/esp32/./panic.c:546

0x40087d63: abort at /esp/esp-idf/components/esp32/./panic.c:546

0x400d4e73: __assert_func at /Users/ivan/e/newlib_xtensa-2.2.0-bin/newlib_xtensa-2.2.0/xtensa-esp32-elf/newlib/libc/stdlib/../../../.././newlib/libc/stdlib/assert.c:63 (discriminator 8)

0x400876fb: multi_heap_free at /esp/esp-idf/components/heap/./multi_heap.c:350 (discriminator 1)

0x40081d96: heap_caps_free at /esp/esp-idf/components/heap/./heap_caps.c:172

0x400822a9: _free_r at /esp/esp-idf/components/newlib/./syscalls.c:33

0x40106cad: GKI_freebuf at /esp/esp-idf/components/bt/bluedroid/gki/gki_buffer.c:411

0x40105932: bta_sys_event at /esp/esp-idf/components/bt/bluedroid/bta/sys/bta_sys_main.c:632

0x400eec16: btu_task_thread_handler at /esp/esp-idf/components/bt/bluedroid/stack/btu/btu_task.c:558

The flow of my code goes as follows:

app_main() creates a task running the function scannerTask()
scannerTask() maintains a loop during which esp_ble_gap_start_scanning(duration);
This task blocks with xTaskNotifyGive()
Every ESP_GAP_BLE_SCAN_RESULT_EVT creates a new task to add device info to an array if the device is not already in the array
Then

Code: Select all

 case ESP_GAP_SEARCH_INQ_CMPL_EVT :   xTaskNotifyGive( scannerTaskHandle ); break 
will unblock the scannerTask
The scannerTask will go through each element in the array and esp_ble_gattc_open(client_if , devices.MAC, true)
The heap error occurs (albeit irregularly) after esp_ble_gattc_close (client_if, conn_id) where conn_id is received from the params passed to the gatt callback handler.

I ordered a JTAG adapter but trying to debug before it gets here has been difficult. I've tried printing the free heap space and it has plenty of space. Any advice on this is much appreciated.

Thanks.

Who is online

Users browsing this forum: Baidu [Spider] and 105 guests