Reduce RAM usage of Bluetooth NimBLE stack

mauh72
Posts: 1
Joined: Tue May 23, 2023 10:54 am

Reduce RAM usage of Bluetooth NimBLE stack

Postby mauh72 » Tue May 23, 2023 11:10 am

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

sunology_fieber
Posts: 2
Joined: Mon Feb 19, 2024 9:29 am

Re: Reduce RAM usage of Bluetooth NimBLE stack

Postby sunology_fieber » Mon Feb 19, 2024 9:50 am

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

MicroController
Posts: 1707
Joined: Mon Oct 17, 2022 7:38 pm
Location: Europe, Germany

Re: Reduce RAM usage of Bluetooth NimBLE stack

Postby MicroController » Mon Feb 19, 2024 1:36 pm

You can try 'optimizing' NimBLE's "Memory Settings" in menuconfig.

sunology_fieber
Posts: 2
Joined: Mon Feb 19, 2024 9:29 am

Re: Reduce RAM usage of Bluetooth NimBLE stack

Postby sunology_fieber » Tue Feb 20, 2024 8:08 am

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!

Who is online

Users browsing this forum: Baidu [Spider], Majestic-12 [Bot] and 137 guests