Skip to content

BluetoothSerial / esp_bt_mem_release / memory consumption in arduino api #6451

Closed
@ferbar

Description

@ferbar

Related area

BT, BluetoothSerial

Hardware specification

any

Is your feature request related to a problem?

Using BluetoothSerial is taking about 140kB ram of the ESP32. That could be reduced by recompiling the arduino esp idf with a reduced set of options or by using esp_bt_mem_release(BTLE) for example if bluetooth LE isn't required. Since recompiling takes a lot of time I would suggest some options in the ESP32 arduino sdk.

Describe the solution you'd like

When btInUse() is returning true about 70kB ram are in use since boot. When btStart() is called additional 70kB are required. If BluetoothSerial is used, I don't think that BTLE will be used in general, so I suggest an option to BluetoothSerial or BluetoothSerial::begin to disable BTLE and BluetoothSerial::end to disable BT in general (and call esp_bt_mem_release())

a) btStart() has to be changed because of
esp_bt_controller_config_t cfg = BT_CONTROLLER_INIT_CONFIG_DEFAULT();
.mode = ESP_BT_MODE_CLASSIC_BT,

b) esp_bt_mem_release() has to be called before esp_bt_controller_init() and after BluetoothSerial::end()

I already have those modifications and would file a PR when #6380 is merged.
@me-no-dev: what do you think about

  • add a btStartMode(BT_classic / BTLE / DM) -> releases BTLE or BT_classic ram if not used
  • add a btStop_memrelease() -> which frees every BT ram
  • Is there any reason why esp32-hal-bt.c is a .c, not .cpp file (I'm asking because overloading those functions would be more convinient)
  • everything could be done in BluetoothSerial.cpp, however I think esp32-hal-bt.h: btStart() / btStop is be the right place.

Thanks!

Describe alternatives you've considered

No response

Additional context

No response

I have checked existing list of Feature requests and the Contribution Guide

  • I confirm I have checked existing list of Feature requests and Contribution Guide.

Activity

antoinnneee

antoinnneee commented on Mar 23, 2022

@antoinnneee

I have the same issue. I need ~50Ko more memory for my project, and I'm lock due to bluetooth ram usage. I'm not using BLE in project.

For you're question : "Is there any reason why esp32-hal-bt.c is a .c, not .cpp file (I'm asking because overloading those functions would be more convinient)"
All the esp32 frameworks is built with C. And it's a better to keep C for performance and ram usage.
Almost all uC use C instead of C++. From my experience, Cpp in uC is rare. I just have 2 or 3 ref that use cpp against a ton of other that work with C. In addition, I much prefer C programming for embedded programs. I write code much faster. But that's just an opinion

Another possible optimization. Is to let the user choose what to use in the Bluetooth lib. For example, I only need Bluetooth spp, but bluedroid has Bluetooth HID, A2DP, HFP, ...

VojtechBartoska

VojtechBartoska commented on Mar 31, 2022

@VojtechBartoska
Contributor

@ferbar Thaks for contribution and your PR, let's wait till your proposed PR is reviewed.

VojtechBartoska

VojtechBartoska commented on May 4, 2022

@VojtechBartoska
Contributor

PR was merged.

Edit: I just closed it but I now see it was something else. So the question is, are there any updates on this?

Repository owner moved this from In Progress to Done in Arduino ESP32 Core Project Roadmapon May 4, 2022

15 remaining items

Loading
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    Status

    Done

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @antoinnneee@ferbar@garageeks@SimonPVS@VojtechBartoska

        Issue actions

          BluetoothSerial / esp_bt_mem_release / memory consumption in arduino api · Issue #6451 · espressif/arduino-esp32