Skip to content
New issue

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

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

Already on GitHub? # to your account

rp usb_raw example can end up in a "USB device not recognized" state #3868

Open
JonathanLindsey opened this issue Feb 10, 2025 · 0 comments
Open

Comments

@JonathanLindsey
Copy link

JonathanLindsey commented Feb 10, 2025

Environment

  • RP2040 powered by USB AND an external power source.
  • Windows 11

Steps to reproduce

  1. Deploy embassy's usb_raw example on the RP2040 with:
cd examples\rp
cargo run --release --bin usb_raw
  1. Create a separate project with the main.rs and cargo.toml below. These are based on the nusb example from the usb_raw example documentation. Modifications are that
  2. The control_in section has been removed.
  3. block_on(interface.control_out {......}); has been replaced with interface.control_out_blocking(Control {...}, data, Duration::......);.
  4. A loop {...} has been added around the control_out section.
  5. Run the nusb code with cargo run.
  6. Stop the nusb code.
  7. Run the nusb code.
  8. If it continues to work, repeat stop and re-run the nusb code until you start seeing errors.
  9. Notice Err(Cancelled) output from the nusb code. Stop the nusb code.
  10. With the RP2040 externally powered, disconnect and reconnect the USB cable.
  11. Notice the "USB device not recognized" Windows notification.
    Image

nusb main.rs

use std::time::Duration;

use futures_lite::future::block_on;
use nusb::transfer::{Control, ControlIn, ControlOut, ControlType, Recipient};

fn main() {
    let di = nusb::list_devices()
        .unwrap()
        .find(|d| d.vendor_id() == 0xc0de && d.product_id() == 0xcafe)
        .expect("no device found");
    let device = di.open().expect("error opening device");
    let interface = device.claim_interface(0).expect("error claiming interface");

    loop {
        // Send "hello world" to device
        let result = interface.control_out_blocking(Control {
            control_type: ControlType::Vendor,
            recipient: Recipient::Interface,
            request: 100,
            value: 200,
            index: 0,
        }, b"hello world", Duration::from_millis(1000));
        println!("{result:?}");
    }
}

nusb Cargo.toml

[package]
name = "embassy-pc-nusb"
version = "0.1.0"
edition = "2021"

[dependencies]
futures-lite = "2.6.0"
nusb = "0.1.12"

Expected behavior

This may or may not be a bug in, or improper use of, nusb. However, I was expecting the following on the embassy side regardless of anything else.

  1. It looks like this might be a bug causing the RP code to freeze or exit. The RP could be running (more or less) mission critical code apart from being a USB device. I expect other mission critical code to continue running. I have not checked if this is the case or not.
  2. When I disconnect and reconnect the USB cable, I expect the device to reconnect, be recognized, and everything work.
  3. Stopping the nusb code and restarting it just works (unless this is a bug in, or improper use of, nusb).
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant