bluekitchen / btstack

Dual-mode Bluetooth stack, with small memory footprint.
http://bluekitchen-gmbh.com
Other
1.74k stars 618 forks source link

how to use btstack work with esp-hosted? #470

Closed zhou88mang closed 1 year ago

zhou88mang commented 1 year ago

i wanted to use btstack to control esp32 , i just want to realize two functions ---- gap_inqury and hfp_ag, and on esp32, it runs esp-hosted project. HCI over Uart, and my main control is stm32f412, I've made some attempts. But it didn't work very well this is some log: [00:00:02.737] LOG -- hci.c.1728: Resend HCI Reset [00:00:02.742] CMD => 03 0C 00 [00:00:02.745] EVT <= 6E 00 [00:00:02.943] LOG -- hci.c.1728: Resend HCI Reset [00:00:02.948] CMD => 03 0C 00 [00:00:02.951] EVT <= 6E 00 [00:00:03.149] LOG -- hci.c.1728: Resend HCI Reset [00:00:03.154] CMD => 03 0C 00 [00:00:03.157] EVT <= 6E 00 [00:00:03.160] SCO <= 00 04 0E 05 03 0C 00 04 0E 04 05 03 0C 00 04 0E 04 [00:00:03.355] LOG -- hci.c.1728: Resend HCI Reset [00:00:03.360] CMD => 03 0C 00 [00:00:03.363] EVT <= 6E 00 can you give me some related examples ? thanks

mringwal commented 1 year ago

Using BTstack with esp-hosted is not different from using other Bluetooth Controllers over UART. See e.g. the F4 port. the problem could be that the ESP32 emits non-HCI data after startup. In the HCI Log, this line

[00:00:03.160] SCO <= 00 04 0E 05 03 0C 00 04 0E 04 05 03 0C 00 04 0E 04

contains the correct response, but it's shifted

BTstack expects the following after HCI on the UART

04 0E 04 05 03 0C 00

You could first restart the ESP32, wait a bit, then make sure there are no extra bytes in the incoming UART buffer.