Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

USB descriptors not correctly updated if Bluetooth stack is initialized before Adafruit_TinyUSB #400

Open
tttapa opened this issue Mar 3, 2024 · 0 comments
Labels
Bug Something isn't working

Comments

@tttapa
Copy link

tttapa commented Mar 3, 2024

Operating System

Linux

Arduino IDE version

Arduino 2.3.2

Board

Raspberry Pi Pico (FQBN: rp2040:rp2040:rpipicow:usbstack=tinyusb,ipbtstack=ipv4btcble)

ArduinoCore version

https://github.com/earlephilhower/arduino-pico 3.7.2

TinyUSB Library version

2.3.0 (bundled with core)

Sketch as ATTACHED TXT

Sketch that reproduces the issue (minimal)
#define HID_REPORT_TYPE_INPUT HID_REPORT_TYPE_INPUT_bt
#define HID_REPORT_TYPE_OUTPUT HID_REPORT_TYPE_OUTPUT_bt
#define HID_REPORT_TYPE_FEATURE HID_REPORT_TYPE_FEATURE_bt
#define hid_report_type_t hid_report_type_t_bt
#include <btstack.h>
#undef HID_REPORT_TYPE_INPUT
#undef HID_REPORT_TYPE_OUTPUT
#undef HID_REPORT_TYPE_FEATURE
#undef hid_report_type_t

void power_on_hci() { hci_power_control(HCI_POWER_ON); }
#include <Adafruit_TinyUSB.h>

Adafruit_USBD_MIDI usb_midi;

void setup() {
#if 1 // When 1, USB MIDI does not work, when 0, it does work
  power_on_hci();
#endif
  pinMode(LED_BUILTIN, OUTPUT);
  usb_midi.begin();
}

void loop() { // Blink as a liveness check
  static bool state = false;
  digitalWrite(LED_BUILTIN, state = !state);
  Serial.printf("%s\n", state ? "on" : "off");
  delay(500);
}

Compiled Log as ATTACHED TXT

picow-usb-ble-problem.txt

What happened ?

→ Previously reported at earlephilhower/arduino-pico#2022, which contains more information

If the Bluetooth stack is initialized before calling the begin function on any of the Adafruit_TinyUSB instances, the descriptors that Adafruit_TinyUSB uses don't include the descriptors for any of those instances.

The Pico does show up correctly after forcing the USB bus to rescan (but just resetting the Pico does not help).

How to reproduce ?

  1. Select the Raspberry Pi Pico W in the IDE
  2. Enable the Bluetooth stack (Tools > IP/Bluetooth Stack: "IPv4 + Bluetooth")
  3. Enable Adafruit TinyUSB as USB stack (Tools > USB Stack: "Adafruit TinyUSB")
  4. Upload the sketch above (which includes an instance of Adafruit_USBD_MIDI).
  5. Verify that the board does not show up as a MIDI device, there's no hint of MIDI in the descriptors.

Some debugging was already done by earlephilhower in earlephilhower/arduino-pico#2022, where he was able to rule out any problems with the earlephilhower/arduino-pico core specifically, which is why I've opened an issue here.

From the previous issue:

earlephilhower
Yup, the Adafruit library of TinyUSB is not signaling the PC to re-read the descriptor when this happens and hence the PC will keep the old one. If you cause the USB bus to rescan, the device does show up properly:
[...]
So this is a TinyUSB issue most likely. Adafruit is making a new descriptor and informing TinyUSB about it, but for some reason TinyUSB can't tell the PC about it. Might want to ping them with this info, it may be a simple fix...

Debug Log

No response

Screenshots

No response

@tttapa tttapa added the Bug Something isn't working label Mar 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant