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

(RP2040) tud_connected() and tud_mounted() stay true after disconnected #2478

Open
1 task done
acscd opened this issue Feb 18, 2024 · 4 comments
Open
1 task done

(RP2040) tud_connected() and tud_mounted() stay true after disconnected #2478

acscd opened this issue Feb 18, 2024 · 4 comments
Labels

Comments

@acscd
Copy link
Contributor

acscd commented Feb 18, 2024

Operating System

Linux

Board

Raspberry Pi Pico

Firmware

#include "Adafruit_TinyUSB.h"

void setup()
{
	pinMode(LED_BUILTIN, OUTPUT);
	Serial.begin(115200);
	Serial1.begin(115200); //for debug
}

void loop()
{
	digitalWrite(LED_BUILTIN, tud_connected());
}

What happened ?

tud_connected() and tud_mounted() correctly return FALSE before USB is connected, and TRUE when connected. However, they continue to return TRUE indefinitely after USB is no longer connected.

How to reproduce ?

  1. power up Pi Pico from an external source (I feed VBUS thru a diode)
  2. (LED stays off, tud_connected() returning FALSE)
  3. Connect Pico to USB host
  4. (LED turns on, tud_connected() returning TRUE)
  5. Disconnect USB
  6. (LED stays on, tud_connected() keeps returning true)
  7. Scratch head
  8. if USB is reconnected, LED will flicker off a couple of times, then stay on
  9. Scratch head some more

Debug Log as txt file (LOG/CFG_TUSB_DEBUG=2)

usb log.txt

Screenshots

No response

I have checked existing issues, dicussion and documentation

  • I confirm I have checked existing issues, dicussion and documentation.
@acscd acscd added the Bug 🐞 label Feb 18, 2024
@doctea
Copy link

doctea commented Apr 13, 2024

I'm seeing the same behaviour here too. I'm trying to figure out why sending MIDI notes to the host randomly stops working until I unplug and re-plug the USB, but as in the issue report, once connected tud_connected() and tud_mounted() continue to report that they are connected even when the USB cable is unplugged.

@acscd
Copy link
Contributor Author

acscd commented Apr 16, 2024

On the PI Pico, depending on your use case, this issue may be worked around by sensing VBUS instead; GPIO 24 is hardwired for that on the Pico. (WL_GPIO 2 on the PicoW) This will only work if VBUS is fed exclusively by USB though.

@doctea
Copy link

doctea commented May 4, 2024

On the PI Pico, depending on your use case, this issue may be worked around by sensing VBUS instead; GPIO 24 is hardwired for that on the Pico. (WL_GPIO 2 on the PicoW) This will only work if VBUS is fed exclusively by USB though.

Good to know; but in my case the +v USB pin is cut and the Pico (actually Seeed XIAO RP2040) is externally powered so this wouldn't be a suitable workaround.

@HiFiPhile
Copy link
Collaborator

Without VBUS there is no way to do disconnection detection.

#define FORCE_VBUS_DETECT 1

You should use tud_ready()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants