Memory consumption of bluetooth is enormous

jumjum123
Posts: 97
Joined: Mon Oct 17, 2016 3:11 pm

Memory consumption of bluetooth is enormous

Postby jumjum123 » Mon Sep 25, 2017 9:01 pm

Startet to add BLE support to an application.
Memory consumption in RAM(>64K) and in Flash(>500k) is enormous.

Size of Flash raised from 800kb to more than 1300kb only by adding a simple BLE_UART
Today this looks like being a showstopper for using BLE in my application.

ESP_Angus
Posts: 538
Joined: Sun May 08, 2016 4:11 am

Re: Memory consumption of bluetooth is enormous

Postby ESP_Angus » Mon Sep 25, 2017 11:13 pm

It is possible to release some of the RAM used by the Bluetooth stack if running with BLE only.

In IDF v2.1, this is done by setting "Release DRAM from Classic BT controller" under Component Config -> Bluetooth -> Bluedroid Bluetooth Stack.

In current master & IDF v3.0, this is done via esp_bt_controller_mem_release() function call: https://esp-idf.readthedocs.io/en/lates ... _bt_mode_t

Lucas.Hutchinson
Posts: 57
Joined: Tue Apr 26, 2016 5:10 am

Re: Memory consumption of bluetooth is enormous

Postby Lucas.Hutchinson » Tue Sep 26, 2017 3:14 am

What is your log print level set to?

If it is set to verbose, you will find the bin size to be quite large. If you set this to info, warning or error, you will likely find the size will drop.

Also check the following options in your menuconfig:
  1. "Component config-> Bluetooth-> Bluedorid Bluetooth stack enabled-> Bluedriod memory debug" Set to disabled
  2. "Component config-> Bluetooth-> Bluedorid Bluetooth stack enabled->Close the bluedroid bt stack log print" Set to enabled
  3. "Component config-> Bluetooth-> Bluedorid Bluetooth stack enabled-> Classic Bluetooth" Set to disabled (if you are not suing classic bluetooth)
  4. "Component config-> Bluetooth-> Bluedorid Bluetooth stack enabled-> Include BLE Security module (SMP)" Set to disabled (only if you do not intend to use SMP)

BuddyCasino
Posts: 226
Joined: Sun Jun 19, 2016 12:00 am

Re: Memory consumption of bluetooth is enormous

Postby BuddyCasino » Tue Sep 26, 2017 9:20 am

ESP_Angus wrote:In current master & IDF v3.0, this is done via esp_bt_controller_mem_release() function call: https://esp-idf.readthedocs.io/en/lates ... _bt_mode_t


Not sure I understood the documentation, is BT memory now completely dynamic? Is it possible to re-enable BT again after calling

Code: Select all

esp_bt_controller_mem_release(ESP_BT_MODE_BTDM)
, or is that a one-off thing where BT will be unavailable forever after?

ESP_igrr
Posts: 837
Joined: Tue Dec 01, 2015 8:37 am

Re: Memory consumption of bluetooth is enormous

Postby ESP_igrr » Tue Sep 26, 2017 9:32 am

It is not fully dynamic. The act of releasing BT memory adds this memory as new region(s) to the heap allocator. Once that is done, we can assume that some code can call 'malloc' and get a pointer allocated in that region of memory. Since there is no way of reversing this (unless one is using a VM with a moving garbage collector) we can never use this released region for BT again.
This change was mainly done to satisfy requirements of environments such as micropython and Arduino, which need to postpone the decision of enabling BT until runtime.

jumjum123
Posts: 97
Joined: Mon Oct 17, 2016 3:11 pm

Re: Memory consumption of bluetooth is enormous

Postby jumjum123 » Tue Sep 26, 2017 10:50 am

Thanks a lot for the feedback

@ESP_ANGUS this was the first I had to do, even to get an empty BLE, without any GAP/GATT starting.
Size of free heap during startup is less than after start. This made it impossible to start without this change.

@Lucas started to check your recommendations
Log Level and Classic Bluetooth have already been changed in my tests.
SInce a lot of changes have been done during testing, I prefer to start from zero again.
Therefore it will take some time before I can give feedback

BTW setting Compiler options --> Optimization level to Release also saves some bytes

Who is online

Users browsing this forum: No registered users and 4 guests