Smaller Bluetooth Library for ESP32?

Greetings,

There was a previous thread on this subject that closed without a clear solution. I run out of program memory when I try to add bluetooth to my LoRa app which also uses WiFi. There is insufficient program space for both WiFi and BT. I noticed that the addition of the existing bluetooth library increases the size of program code by a whopping 500KB. Since the ESP32 has a built in BT module that I would imagine has the BT heavy lifting code in ROM space I wonder why the library is so memory hungry?

Does anyone here know why it uses so much space? I wonder if the BLE capability is what consumes the majority of the space? I just need standard BT which I imagine should mainly use calls to the BT API that is probably provided by the BT module.

Best Regards,
tma

1 Like

Isn't that just a guess?

Anyway, what are you hoping for? The Arduino core is only a wrapper around the Espressif API's. Would knowing the reason really help, if you can't rewrite the Espressif code (which must be titanic in scope and size).

Designers hesitate to put software stacks in ROM - then they can't be updated.

Then drop the WiFi.

Or use a HC-05.

Thank you for your interest and reply!

I read somewhere that the ESP32 built in BT is somewhat similar to the HC-0x modules which I have implemented in the past with an Android Nano with very little code overhead. So yes I guessed that the ESP32 BT implementation would be similar as opposed to a feature that would gobble up orders of magnitude more program space. Makes me wonder if the bulge is due to the BTLE mode capability although I now have the impression that I have probably only implemented regular BT mode. I was hoping to discover the existence of a scaled down BT library. It would be nice to find a specification for the BT library just to confirm that the 500KB code size that I have noticed is normal according to specs.

Best Regards,

Why not just write directly to the ESP32's API,
Bluetooth API - ESP32 - — ESP-IDF Programming Guide latest documentation?

I'm working on a Bluetooth project that uses the A2DP protocol to receive streaming audio from a smartphone. I'm pretty sure the HC0x devices don't support that. Bluetooth and BLE are huge systems.

Dump the library and try "NimBLE." in my cases, it is about 70% smaller. Active development. It has worked well for up. I think it is now in the arduino library system.

Greetings,

You folks have given me some new options to review and consider. Many thanks All for the enlightening info!

My LoRa application just transfers very short lines of text. Thus relatively simple compared to streaming applications, big file transfers, etc.

Sounds like NimBLE might be what I need as I think 150KB should fit - it never occurred to me that the BLE library might be a better fit for my application. But as standard BT has overhead to support heavy duty data transfer applications and BLE intended for small data transfers it does make sense.

The app does build OK if I eliminate WiFi but I would like to include it if possible so that I can access the LoRa node telemetry ADC data wirelessly via my LAN.

Thanks for the API spec URL! At first glance just using the API commands given in the spec directly might be all that I need to use for my simple short data message application. I need to spend some time looking at the commands.

Thanks again!
tma

WiFi and BLE with an ESP32 run on core0 of the main CPU. Does NimBLE run on core0? Or will NimBLE load to core1?

There is an official ESP32/Arduino forum if you want to ask there.

ESP32 Arduino - ESP32 Forum

I do not particularly believe you will get a definitive answer, but you are sure to get a lots of guesses based on the overall interest in BT:

Search found 493 matches: bluetooth

And in the Espressif/Arduino-ESP32/ section, a search for 'bluetooth' indicates 278 code hits.

Search · bluetooth · GitHub

The ESP32 binary BT blob is here:
GitHub - espressif/esp32-bt-lib: ESP32 Bluetooth stack (below HCI layer) precompiled libraries

Scanning a few hundred bytes of the file, we see some interesting strings:

arch_main.c BTDM ROM VERSION %04x
 BD_ADDR: %02X:%02X:%02X:%02X:%02X:%02X
 BTDM CONTROLLER VERSION: %06x
 19:41:53 Aug 30 2022 BTDM CONTROLLER DATE: %s %s
 BTDM CPUID 0x%08X
 Enable Classic BT
 Enable Low Energy
 Coex register bt cb faild
 Coex register schm btdm cb faild
 Coex register Wi-Fi channel change btdm cb faild
 Disable Classic BT
 Disable Low Energy
 0 Heap MSG [%p], Heap ENV [%p], Heap NORET [%p]
                             Uart ENV [%p], VHCI ENV [%p], PLF FUNCS [%p]
 btController 67ee4f0 ASSERT_WARN(%d %d), in %s at line %d ASSERT_PARAM(%d %d), in %s at line %d
 Warn f:%s l:%d p:%d %d
 lc_task.c ld_pscan.c ld_sscan.c ld_page.c ld_inq.c ld_csb_rx.c ld_acl.c ASSERT_ERR(%s), in %s at line %d
 ld_csb_rx.c.c ld_acl.c (localVal & ~((uint16_t)0x000007FF)) == 0 (((uint16_t)clkoff1 << 0) & ~((uint16_t)0x000007FF)) == 0 (EM_BT_RXDESC_OFFSET + ld_env.curr_rxdesc_index * REG_EM_BT_RXDESC_SIZE) == bt_et_currentrxdescptr_currentrxdescptr_getf()  GCC: (crosstool-NG crosstool-ng-1.22.0-78-g4b87650) 5.2.0           Xtensa_Info USE_ABSOLUTE_LITERALS=0
ABI=0

Many thanks for all the helpful links!

Best Regards,
tma

1 Like

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