Memory consumption of bluetooth is enormous

rwel59
Posts: 75
Joined: Thu Oct 12, 2017 3:32 pm

Re: Memory consumption of bluetooth is enormous

Postby rwel59 » Fri Jan 19, 2018 1:49 am

do you have any comments on what 'lowest possible values' might mean? or thoughts on a process to determine?
Last edited by rwel59 on Fri Jan 19, 2018 1:53 am, edited 1 time in total.

rwel59
Posts: 75
Joined: Thu Oct 12, 2017 3:32 pm

Re: Memory consumption of bluetooth is enormous

Postby rwel59 » Fri Jan 19, 2018 1:50 am

any thoughts on what 'lowest possible values' might mean or how one might go about determining them?

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

Re: Memory consumption of bluetooth is enormous

Postby ESP_Angus » Fri Jan 19, 2018 2:52 am

rwel59 wrote:any thoughts on what 'lowest possible values' might mean or how one might go about determining them?
Regarding this item:
chegewara wrote:If you are using wifi then in menuconfig->wifi start with the lowest settings, it gives another 30-ish kB (by default settings are setup very high)
Each of these numeric config parameters has a min/max value. In menuconfig, you can press "?" when any item is highlighted to view the help (which includes a description and the min/max range). Press Esc to exit the help. You can also read through the options here:
http://esp-idf.readthedocs.io/en/v3.0-r ... html#wi-fi

Setting the minimum for each value will reduce the memory usage (although for some items it's the worst-case memory usage not the initial memory usage). The documentation for each item will help you decide what is worth tweaking.

Note that setting minimum values will impact WiFi throughput depending on circumstances (again, the help gives some description as to each item). The defaults are chosen to be a tradeoff between performance and memory usage.
chegewara wrote:- if you dont use SSL menuconfig->mbedTLS->TLS maximum message content length is set to 16kB, why? set it to lowest possible, another 15kB
If you don't use SSL/TLS then you don't need to worry about this parameter at all, as it's only used if you create a TLS session.

The max message content length defaults to 16kB because TLS specifies a maximum 16kB message size. This is actually 32kB of RAM per TLS connection, as there are two buffers per connection - RX and TX.

If both ESP-IDF and the other end of your TLS connection is configured to support the TLS Maximum Fragment Length Negotiation Extension, then you can safely set this to a smaller value with no risk of problems (except maybe slower throughput if you move a lot of bulk data). However, most common cloud providers don't enable this extension on their TLS gateways.

Even if you can't use maximum fragment length negotiation, you can set the maximum message content length smaller if you know for certain that the other end of the connection will never try to send more than this many bytes at a single time. However if the other end does happen to send a TLS message which doesn't fit in the available RX buffer, the TLS connection will fail and need to be re-established.

In this case, the minimum size is usually determined by the usage in the TLS handshake phase. This depends on which TLS cipher is negotiated for the connection, which in turn depends on the mbedTLS configuration and the other end's TLS configuration. I suggest determining this experimentally, maybe start with 4096 bytes and increase/decrease. Remember to leave some headroom if there's a chance you'll need to switch ciphers in the future.

This is also summarised in the help for the config item: http://esp-idf.readthedocs.io/en/v3.0-r ... ontent-len

User avatar
hassan789
Posts: 150
Joined: Thu Jun 29, 2017 2:15 am

Re: Memory consumption of bluetooth is enormous

Postby hassan789 » Mon Jun 11, 2018 10:20 pm

ESP_Angus wrote: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
Great tip! Run-time allocation is a life saver! This seems to be freeing ~70kB of heap.

User avatar
fly135
Posts: 606
Joined: Wed Jan 03, 2018 8:33 pm
Location: Orlando, FL

Re: Memory consumption of bluetooth is enormous

Postby fly135 » Tue Jun 12, 2018 1:13 am

Holy Moly! Glad I saw this. I was struggling with 55K of internal mem. Now I have 140K!!! :D

John A

human890209
Posts: 48
Joined: Wed Aug 15, 2018 8:56 am

Re: Memory consumption of bluetooth is enormous

Postby human890209 » Tue Oct 16, 2018 6:25 am

Hi,
Thank for your advice. I'm a newbie of using BT of ESP32
I'm using BluetoothSerial, I don't know what the BT mode is, BLE or Classic?
I can only find

Code: Select all

esp_spp_init(ESP_SPP_MODE_CB)
in the library.
So can I release some memory for BluetoothSerial by using

Code: Select all

esp_bt_mem_release(mode)
or

Code: Select all

esp_bt_controller_mem_release
?

Who is online

Users browsing this forum: Baidu [Spider], Bing [Bot], Google [Bot] and 22 guests