Page 1 of 1

Enabling Bluetooth in Menuconfig breaks code

Posted: Sat Jan 18, 2025 3:45 pm
by mitchk
I am working on a project that I was hoping to use an ESP32-C2 part for. I have some initial code that is connecting to Firebase and working as expected. When I enable NimBLE in Menuconfig (BLE will be used for provisioning) the code fails apparently due to a memory allocation failure due to insufficient heap memory. This code is not using Bluetooth in any way yet just having it enabled in Menuconfig causes the failure. It seems that RAM is being allocated at compile time. Is there any way to release those resources when they are not actually being used?

Re: Enabling Bluetooth in Menuconfig breaks code

Posted: Sat Jan 18, 2025 8:42 pm
by MicroController
Is there any way to release those resources when they are not actually being used?
Yes: esp_bt_mem_release().

Re: Enabling Bluetooth in Menuconfig breaks code

Posted: Sat Jan 18, 2025 9:05 pm
by mitchk
Thanks. I had tried that earlier and assumed it wasn't doing anything if the Bluetooth controller wasn't active as I was still seeing a failure connecting to Firebase. However, when I check the free heap before and after releasing the BT memory there is a small but observable difference.

I (1457) Heap: Free heap size: 121604 bytes
D (1457) BLE_INIT: Release BT BSS [0x3fcb34dc] - [0x3fcb4588], len 4268
D (1467) BLE_INIT: Release BT Controller BSS [0x3fcb34b0] - [0x3fcb34dc], len 44
D (1477) BLE_INIT: Release BT Data [0x3fcb33d4] - [0x3fcb34ac], len 216
D (1487) BLE_INIT: Release BT Controller Data [0x3fcb33b0] - [0x3fcb33d4], len 36
I (1507) Heap: Free heap size: 124212 bytes

But my Firebase connection is still failing except now the error code is different it is a certificate verification error rather than a memory allocation error. None of the Firebase code has changed. Whether it succeeds or fails and how it fails is all tying back to how Bluetooth is enabled/configured.