Enabling Bluetooth in Menuconfig breaks code

mitchk
Posts: 18
Joined: Fri Apr 28, 2017 8:31 pm

Enabling Bluetooth in Menuconfig breaks code

Postby mitchk » Sat Jan 18, 2025 3:45 pm

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?

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

Re: Enabling Bluetooth in Menuconfig breaks code

Postby MicroController » Sat Jan 18, 2025 8:42 pm

Is there any way to release those resources when they are not actually being used?
Yes: esp_bt_mem_release().

mitchk
Posts: 18
Joined: Fri Apr 28, 2017 8:31 pm

Re: Enabling Bluetooth in Menuconfig breaks code

Postby mitchk » Sat Jan 18, 2025 9:05 pm

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.

Who is online

Users browsing this forum: Bing [Bot] and 63 guests