Page 1 of 1

Reduce RAM usage of Bluetooth NimBLE stack

Posted: Tue May 23, 2023 11:10 am
by mauh72
Hi there,

I am writing an application on an ESP32-WROOM-32UE module with a lot of RAM usage and the NimBLE bluetooth stack does not fit into RAM anymore. I made some tests (reduced memory of other components, so that BLE fits) comparing my firmware with BLE and without BLE (ESP-IDF V5.0).

My results are, that activating the NimbleBLE stack with default values, occupies the following RAM:

During compile time (static allocated):
- IRAM: 47 KB
- DRAM: 14 KB

During runtime (allocated from heap)
- 88 KB

In sum, this is 149 KB.
I have tested some options in the sdkconfig, but these only made changes of max. 5 KB.

Is there a hidden option or some genious trick to reduce BLE memory footprint by factor of two or more?

Many thanks for ideas.
mauh72

Re: Reduce RAM usage of Bluetooth NimBLE stack

Posted: Mon Feb 19, 2024 9:50 am
by sunology_fieber
Hi,

Did you find this "hidden" option?

I'm using the Blufi example compiled using Nimble and Bludroid to compare Heap usage.
Using the same exact code, using Nimble requires 6 to 7 KB more Heap.

It reduces substantially the flash space tho.

I use the ESP IDF v5.1

Is this the expected behavior?

Regards,
Fieb44

Re: Reduce RAM usage of Bluetooth NimBLE stack

Posted: Mon Feb 19, 2024 1:36 pm
by MicroController
You can try 'optimizing' NimBLE's "Memory Settings" in menuconfig.

Re: Reduce RAM usage of Bluetooth NimBLE stack

Posted: Tue Feb 20, 2024 8:08 am
by sunology_fieber
Hi,

Indeed, the Memory Setting has a big impact. It reduced quite substantially the IRAM usage !
I gained approximately 20KB of heap. I reduced the Blocks and Buffer counts until my app didn't work.

The effectiveness of these optimizations may vary depending on your application. Further optimization is likely possible.

In comparison to my previously "optimized" Bluedroid config, using Nimble resulted in the following changes:
- reduced Flash usage by 167KB
- increased IRAM usage by 1.5KB
- reduced Total Heap usage by 8.5KB

Thank you for the suggestion!