earlephilhower / arduino-pico

Raspberry Pi Pico Arduino core, for all RP2040 boards
GNU Lesser General Public License v2.1
1.92k stars 402 forks source link

Bluetooth reconnect fails #2188

Closed ullibak closed 2 months ago

ullibak commented 2 months ago

Hi

Tried the example libraries/BluetoothAudio/examples/A2DPSink/A2DPSink.ino and changed it to output over I2S. I use an iPhone (latest firmware version) as a source.

It connects fine and plays music. But when I disconnect the device in the Bluetooth menu on the iPhone and try to reconnect again, it always fails. The pico seems to crash after a Bluetooth disconnect. After a power cycle, the connection can be established again.

This problem is not unknown and seems to be a bug in BTstack. A workaround for the Pico SDK has been proposed in https://github.com/joba-1/PicoW_A2DP/tree/main After any Bluetooth disconnect, the Pico is reset.

There is a callback function "connectCB" that in my understanding should print "A2DP connection stopped" in the serial monitor after a disconnect. I thougt about placing a reset routine in this function. But there ist no output to the serial monitor on disconnect. So either the pico crashes before the code comes to this point or the Bluetooth disconnect does not trigger this callback function.

How could a reset after a loss of the Bluetooth connection be implemented in an easy way? Or is there another workaround for this issue?

Thanks!

earlephilhower commented 2 months ago

This one is actually the SDK not liking an IRQ being removed from within a different IRQ, not BT related really other than the fact that BT causes the removal from IRQ context (most apps would not be in an IRQ).

The BT thing is that it has trouble pairing to different phone than it paired to the first time. Same issue as #1817. Sometimes it works fine, sometimes BT gets into a weird state. A reboot does seem to make it work again, so the issue is not in the TLV (BT key storage in flash) but something in the BTStack internal state.