bluetooth code size enormous

ppisljar
Posts: 18
Joined: Wed Feb 22, 2017 4:36 pm

bluetooth code size enormous

Postby ppisljar » Wed May 24, 2017 3:39 pm

I tried to play with bluetooth and created this sketch:

Code: Select all

#include <Arduino.h>
#include "bt.h"
#include "btm_api.h"
#include "esp_gap_ble_api.h"
#include "esp_bt_main.h"

static bool connect = false;
static void esp_gap_cb(esp_gap_ble_cb_event_t event, esp_ble_gap_cb_param_t *param)
{
    uint8_t *adv_name = NULL;
    uint8_t adv_name_len = 0;
    switch (event) {
    case ESP_GAP_BLE_SCAN_PARAM_SET_COMPLETE_EVT: {
        //the unit of the duration is second
        uint32_t duration = 30;
        esp_ble_gap_start_scanning(duration);
        break;
    }
    case ESP_GAP_BLE_SCAN_START_COMPLETE_EVT:
        //scan start complete event to indicate scan start successfully or failed
        if (param->scan_start_cmpl.status != ESP_BT_STATUS_SUCCESS) {
            ESP_LOGE("GAP", "Scan start failed");
        }
        break;
    case ESP_GAP_BLE_SCAN_RESULT_EVT: {
        esp_ble_gap_cb_param_t *scan_result = (esp_ble_gap_cb_param_t *)param;
        switch (scan_result->scan_rst.search_evt) {
        case ESP_GAP_SEARCH_INQ_RES_EVT:
            for (int i = 0; i < 6; i++) {
                ESP_LOGI("GAP", "%x:", scan_result->scan_rst.bda[i]);
            }
            ESP_LOGI("GAP", "Searched Adv Data Len %d, Scan Response Len %d\n", scan_result->scan_rst.adv_data_len, scan_result->scan_rst.scan_rsp_len);
            ESP_LOGI("GAP", "\n");
            adv_name = esp_ble_resolve_adv_data(scan_result->scan_rst.ble_adv,
                                                ESP_BLE_AD_TYPE_NAME_CMPL, &adv_name_len);
            ESP_LOGI("GAP", "Searched Device Name Len %d", adv_name_len);
            for (int j = 0; j < adv_name_len; j++) {
                ESP_LOGI("GAP", "%c", adv_name[j]);
            }

            break;
        case ESP_GAP_SEARCH_INQ_CMPL_EVT:
            break;
        default:
            break;
        }
        break;
    }

    case ESP_GAP_BLE_SCAN_STOP_COMPLETE_EVT:
        if (param->scan_stop_cmpl.status != ESP_BT_STATUS_SUCCESS){
            ESP_LOGE("GAP", "Scan stop failed");
        }
        else {
            ESP_LOGI("GAP", "Stop scan successfully");
        }
        break;

    case ESP_GAP_BLE_ADV_STOP_COMPLETE_EVT:
        if (param->adv_stop_cmpl.status != ESP_BT_STATUS_SUCCESS){
            ESP_LOGE("GAP", "Adv stop failed");
        }
        else {
            ESP_LOGI("GAP", "Stop adv successfully");
        }
        break;

    default:
        break;
    }
}

void setup()
{
    Serial.begin(115200);
    delay(5000);

    Serial.println("Starting BT");

    esp_bt_controller_config_t bt_cfg = BT_CONTROLLER_INIT_CONFIG_DEFAULT();
    esp_bt_controller_init(&bt_cfg);
    esp_bt_controller_enable(ESP_BT_MODE_BTDM);
    esp_bluedroid_init();
    esp_bluedroid_enable();

    esp_err_t status;

    //register the scan callback function to the gap module
    if ((status = esp_ble_gap_register_callback(esp_gap_cb)) != ESP_OK) {
        ESP_LOGE("GAP", "gap register error, error code = %x", status);
        return;
    }

    //register the callback function to the gattc module
    /*if ((status = esp_ble_gattc_register_callback(esp_gattc_cb)) != ESP_OK) {
        ESP_LOGE(GATTC_TAG, "gattc register error, error code = %x", status);
        return;
    }*/
}

int value = 0;

void loop()
{
}

... the binary size is enormous .. 1MB ... is this normal ? does it mean that for bluetooth anything we need partition size bigger than 1MB ? (doesn't play nicely with OTA then ... 2 times 2MB = 4MB ... thats all there is if i understand correctly ?

after running the app i get this errors:

Code: Select all

Starting BT
BTDM CONTROLLER VERSION: 010101
btip start
copy .data from 4000d890 to 3ffae6e0, len 00001830
E (51371) BT: Conrollset .bss 0x0 from 3ffb8000 to 3ffbff70, len 00007f70
BTDM ROM VERSION 0101
BD_ADDR: 24:0A:C4:03:86:6A
NVDS MAGIC FAILED
RF Init OK with coex
er not initialised

E (51386) BT: Bludroid not initialised

E (51389) GAP: gap register error, error code = 103
(note ... that happens even after i update my partition size:

Code: Select all

# Name,   Type, SubType, Offset,  Size, Flags
nvs,      data, nvs,     0x9000,  0x5000,
otadata,  data, ota,     0xe000,  0x2000,
app0,     app,  ota_0,   0x10000, 2M,
spiffs,   data, spiffs,  0x210000,0x1F0000,

ppisljar
Posts: 18
Joined: Wed Feb 22, 2017 4:36 pm

Re: bluetooth code size enormous

Postby ppisljar » Wed May 24, 2017 3:43 pm

copy .data from 4000d890 to 3ffae6e0, len 00001830

this looks like its accessing memory that doesn't exist .... :cry:

ppisljar
Posts: 18
Joined: Wed Feb 22, 2017 4:36 pm

Re: bluetooth code size enormous

Postby ppisljar » Wed May 24, 2017 3:54 pm

i tried to compile esp-idf example to verify the size .... and its 715kb (compared to 950kb with arduino) ... still quite huge for something that doesn't do much (if you want to use OTA with it ... you have like 300kb left for your other code (and other libs ... like wifi and stuff)

... but running the esp-idf example also doesn't seem to work ...

i get the following error: 'E (13698) BT: btc_search_callback BLE observe complete. Num Resp 0' after registering the callback functions

f.h-f.s.
Posts: 208
Joined: Thu Dec 08, 2016 2:53 pm

Re: bluetooth code size enormous

Postby f.h-f.s. » Wed May 24, 2017 5:54 pm

the esp-wroom comes with 4mb flash does it not?
Observe complete is not a error, it is the event case for when the time in esp_ble_gap_start_scanning(time) has passed.

iamatesla
Posts: 0
Joined: Tue Jun 27, 2017 2:07 pm

Re: bluetooth code size enormous

Postby iamatesla » Tue Jun 27, 2017 2:12 pm

I'm also running into this problem. I'm trying to compile and use the BLE stack with the WiFi stack as well as a good amount of other code. Is there any solution to this issue? A way to reduce the BLE binary size?

If there's no way to reduce the code size here, how do I tell the system / compiler to use more of the Flash? I'm using Platformio with with the Arduino framework for the ESP32. I've got the Sparkfun ESP32 Thing which should have 4MB Flash. The upload size limit seems to be hard fixed to 1MB in platformio.

tarafrost
Posts: 2
Joined: Mon Dec 18, 2017 5:17 pm

Re: bluetooth code size enormous

Postby tarafrost » Mon Dec 18, 2017 6:30 pm

I just tried to include bluetooth in my ESP32 project, and it bumped the executable size by half a meg (500K).

That is ridiculous!

I'm fast concluding that BLE on an ESP32 is unworkable. <sigh>

Will just have to use an ESP8266 with a HM-10 module instead.

Who is online

Users browsing this forum: No registered users and 6 guests