fix(ble): Make BLE memory management automatic#12287
Conversation
👋 Hello lucasssvaz, we appreciate your contribution to this project! 📘 Please review the project's Contributions Guide for key guidelines on code, documentation, testing, and more. 🖊️ Please also make sure you have read and signed the Contributor License Agreement for this project. Click to see more instructions ...
Review and merge process you can expect ...
|
Test Results 90 files 90 suites 33m 56s ⏱️ Results for commit adaff17. ♻️ This comment has been updated with latest results. |
b140169 to
4fe8e69
Compare
Memory usage test (comparing PR against master branch)The table below shows the summary of memory usage change (decrease - increase) in bytes and percentage for each target.
Click to expand the detailed deltas report [usage change in BYTES]
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
@lucasssvaz @me-no-dev I just updated my project from 3.0.7 to 3.3.8. When I did, code that worked before the update was suddenly bricking my devices. Needed to put them in boot mode to recover them. Took me awhile to narrow the problem down to BLE, and narrow the problem down the 3.3.7, and narrow it down to this PR. My project uses ArduinoBLE which does not have the new header file included yet. This PR is a breaking change for ArduinoBLE and libraries like it. |
|
@SaintSampo You can override the memory management if needed https://github.com/espressif/arduino-esp32/blob/master/cores/esp32/esp32-hal-bt.c#L23-L28. The proper fix is to include esp32-hal-bt-mem.h in ArduinoBLE. This was broken before and now is fixed. |
|
Yea it was easy enough for me to include |
Description of Change
This pull request refactors how Bluetooth (BT) controller memory is managed and detected in the ESP32 Arduino core. It introduces a new mechanism for automatically detecting when BT libraries are linked, allowing the core to release unused BT memory by default unless a BT library is present or the user explicitly overrides the behavior. Additionally, it removes the
free_bt_memoryexample and its associated files, as the new mechanism makes manual overrides less necessary.Core changes to BT memory management:
esp32-hal-bt-mem.hthat defines a constructor to automatically set a flag (_btLibraryInUse) when any BT library is linked, allowing the core to detect BT usage at link time.btInUse()inesp32-hal-bt.cto return the value of_btLibraryInUseinstead of always keeping BT memory; users can still override this function if needed. [1] [2]BLEDevice.cpp,BluetoothSerial.cpp,SimpleBLE.cpp) to include the newesp32-hal-bt-mem.hheader, ensuring the flag is set when these libraries are used. [1] [2] [3]Removal of
free_bt_memoryexample:idf_component_examples/free_bt_memoryexample, including its configuration, source code, and documentation, as the new automatic detection makes it obsolete. [1] [2] [3] [4] [5] [6] [7] [8]FreeBTMemoryexample from the BLE library and its CI configuration. [1] [2]Minor API improvement:
BLEDevice::init()method signature to provide a default argument, improving usability.Test Scenarios
Tested locally with Hello world.
Before fix:
HEAP:lifetime min:4399796, larg. free bl.:4128756, free:4404756 (alloc: 35916), blocks free: 6 (alloc: 93, total: 99), STACK:lifetime min: 7172 (8192)After fix:
HEAP:lifetime min:4418508, larg. free bl.:4128756, free:4423468 (alloc: 35916), blocks free: 6 (alloc: 93, total: 99), STACK:lifetime min: 7180 (8192)Around +20kB of free heap.
Related links
Closes #12284