BLEDevice.h memory allocation issue

I'm trying to figure out if there's a way to prevent BLEDevice.h from allocating memory when not in use since it allocates ~25K even if init has not been called.

Test environment:

  • board: esp32-c3-devkitc-02
  • framework: arduino-esp32

I've also tried to force a deinit():

  BLEDevice::init(CONFIG_SYSTEM_NAME);
  BLEDevice::deinit(true);

but it's not working. Is there any solution/work-around to address this?

Thanks.

What do you mean by "allocating"? Program memory? RAM?

It's about RAM.

If I exclude BLE from the project:

RAM:   [=         ]  13.4% (used 43748 bytes from 327680 bytes)
Flash: [===       ]  32.5% (used 1301396 bytes from 4005888 bytes)

(esp_get_free_heap_size())
@IO::Sys::Diagnostics [System.BytesFree 207092]

When including:

RAM:   [==        ]  19.6% (used 64388 bytes from 327680 bytes)
Flash: [=====     ]  49.2% (used 1970626 bytes from 4005888 bytes)

(esp_get_free_heap_size())
[2024-04-30T18:33:09.288Z] @IO::Sys::Diagnostics [System.BytesFree 175224]

Compiling with the --verbose flag gave me more clues and it seems that the amount of BLE statically allocated variables are the reason behind this extra RAM usage.

// With BLE
.dram0.bss                47640
// Withouth BLE
.dram0.bss                28368

So I guess the only way to optimize this would be modifying Bluetooth stack source code.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.