Bluetooth causing board to crash

nzjeux26
Posts: 4
Joined: Wed Oct 06, 2021 8:43 am

Bluetooth causing board to crash

Postby nzjeux26 » Sun Oct 10, 2021 2:51 am

Hi, Since I was having real issues with my SPIFFS i thought i'd park it for today and try to get Bluetooth working so I can use it as input. But yet again I've been met with errors and cannot get past them.

I followed through the GATTS_Server tutorial in GitHub, everything compiles fine and looks good, except when i load it to the board it crashes with the following:
Core 0 register dump:
PC : 0x401398b1 PS : 0x00060930 A0 : 0x8011e640 A1 : 0x3ffe3480
A2 : 0x3f41c6d0 A3 : 0x0000005e A4 : 0x3f41c7d4 A5 : 0x3f41c72c
A6 : 0x3ffe3520 A7 : 0x3ffe3520 A8 : 0x801398b1 A9 : 0x3ffe3460
A10 : 0x00000000 A11 : 0x3ffe3528 A12 : 0x00000000 A13 : 0x00000001
A14 : 0x3ffe3508 A15 : 0x3ffe3500 SAR : 0x00000004 EXCCAUSE: 0x0000001c
EXCVADDR: 0x0000000c LBEG : 0x4000c2e0 LEND : 0x4000c2f6 LCOUNT : 0x00000000

Backtrace:0x401398ae:0x3ffe3480 0x4011e63d:0x3ffe34b0 0x4011e6c1:0x3ffe34e0 0x4011a949:0x3ffe3820 0x40119443:0x3ffe3be0 0x401195e8:0x3ffe3c00 0x40082609:0x3ffe3c40 0x400791d8:0x3ffe3c80 |<-CORRUPTED
Now after some searching, i *think* it's trying to access a memory point it's not allowed to, so i found a stack decoder on github but all i get is:
0x401398b1: __assert_func at /builds/idf/crosstool-NG/.build/HOST-x86_64-w64-mingw32/xtensa-esp32-elf/src/newlib/newlib/libc/stdlib/assert.c:58
This means nothing to me so I thought I would just start removing things until it doesn't happen, as it turns out it would keep happening until I took everything out!

Here is my code:

Code: Select all

// Initialize NVS
    esp_err_t err;
    err = nvs_flash_init();
    if (err == ESP_ERR_NVS_NO_FREE_PAGES || err == ESP_ERR_NVS_NEW_VERSION_FOUND) {
        ESP_ERROR_CHECK(nvs_flash_erase());
        err = nvs_flash_init();
    }
    ESP_ERROR_CHECK( err );

    esp_bt_controller_config_t bt_cfg = BT_CONTROLLER_INIT_CONFIG_DEFAULT();
    err = esp_bt_controller_init(&bt_cfg);
        if(err){
        printf("%s initialize controller failed\n", __func__);
        //ESP_LOGE(GATTS_TABLE_TAG, "%s enable controller failed\n", __func__);
        return;
    }
I have the rest in comments further down, but even just the above is enough to cause the crash.
Here are the includes i am using:

Code: Select all

#include <driver/gpio.h>
#include <esp_system.h>
#include <freertos/FreeRTOS.h>
#include <freertos/event_groups.h>
#include <freertos/task.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <esp_log.h>
#include <esp_sntp.h>
#include <nvs_flash.h>
#include "fonts.h"
#include "graphics.h"
#include "demos.h"
#include "graphics3d.h"
#include "input_output.h"

//#include "blue.h"
#include "esp_bt.h"
#include "esp_gap_ble_api.h"
//#include "bta_api.h"
#include "esp_gap_ble_api.h"
#include "esp_gatts_api.h"
#include "esp_bt_defs.h"
#include "esp_bt_main.h"
#include "esp_gatt_common_api.h"
#include "sdkconfig.h"
#include "esp_debug_helpers.h"
I have commented out BTA_api.h because even with a manual entry i cannot get VSCode to read it, I get
"cannot open source file "common/bt_target.h" (dependency of "bta_api.h")"

This is weird because all the Bluetooth headers are in the same file path. I don't think missed the BTA_API.h is enough to cause all my woes but it wouldn't surprise me.
**EDIT**

So as a test i also did the BLE Beacon example in the book Developing IoT Projects with ESP32, and it too caused the same result as above. So it's definitely something in the Bluetooth header files or something that is causing this.

Cheers

Who is online

Users browsing this forum: kaxx1975 and 168 guests