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 connected but cannot transferIn or transferOUt #245

Closed
bongbui321 opened this issue Feb 12, 2024 · 1 comment
Closed

USB connected but cannot transferIn or transferOUt #245

bongbui321 opened this issue Feb 12, 2024 · 1 comment

Comments

@bongbui321
Copy link

bongbui321 commented Feb 12, 2024

Hello I'm trying to connect and talk to qualcomm chips in EDL mode which has vid and pid as follows (0x05c6, 0x9008). I have successfully connected to the device using requestDevices filtering based on those vid and pid and classcode of 0xff. at first, I was unable to claim the usb interface since I believe my computer is acquiring it so I used pyusb to detach the kernel driver from the device and was able to connect (get the epIn and epOut) and acquiring the interface as shown below.
image

However, when I try to transferIn or transferOut using await, it stucks there and never returns (indicated by the "Transferring Out..." in the picture above.

I also checked that I acquired the device using this code

get connected() {
    return (
      this.device !== null &&
      this.device.opened &&
      this.device.configurations[0].interfaces[0].claimed
    );
  }
 async _usbRead(resplen = null){
    let respData = { text : "", };

    if ((resplen === null)) { resplen = this.epIn.packetSize; }

    while (respData.text.length < resplen) {
      try {
        console.log("Transferring In...");
        let respPacket = await this.device?.transferIn(this.epIn?.endpointNumber, resplen);
        console.log("get respPacket");
        let response = new TextDecoder().decode(respPacket.data);
        console.log("get response");
        respData.text  = response;
        console.log("added response");
      } catch (error) {
        if (error.includes("timed out")) {
          console.error("Timed out");
          return new TextEncoder().endcode("");
        } else if (error.includes("Overflow")) {
          console.error("USB Overflow");
          return new TextEncoder().endcode("");
        }
      }
    }
    return new TextEncoder().encode(respData);
  }

  async _usbWrite(cmdPacket, pktSize=null) {
    if (!(pktSize === null)) { pktSize = this.epOut?.packetSize; }
    //let cmdPacket = new TextEncoder().encode(cmd);
    let offset = 0;
    while (offset < cmdPacket.length){
      try {
        console.log("Transferring Out...")
        //console.log(cmdPacket.slice(offset, offset 4));
        await this.device?.transferOut(this.epOut?.endpointNumber, cmdPacket);
        offset  = pktSize;
      } catch (error) {
        console.error(error);
        //return new TextEncoder().encode("");
        return false;
      }
    }
    return true;
  }`

This is how I defined the transfer in and out functions.

@reillyeon
Copy link
Collaborator

I'm closing this issue as off-topic because it is not a specification issue, but either a question on how to use the API or an implementation issue. Questions about how to use the API should be posted to sites like StackOverflow where a wider audience of developers can help you answer them. Specification editors like me do monitor StackOverflow and will file specification issues if the question raised indicates that there is a problem with or feature missing from the specification. If the problem you are encountering suggests an implementation issue that should be filed against the implementation you are using, such as Chromium.

The behavior you are seeing likely indicates an issue with the device causing it not to acknowledge the transfer OUT request. Using a tool like Wireshark you can inspect the requests being processed by your USB controller to confirm that the transfer is being sent but has not received a reply. Using a hardware USB analyser you could further inspect the particular NAK reply the device is likely sending.

Note that if the transferOut() call did succeed, cmdPacket is not being updated so further transfers would retransmit the full buffer and not use the offset.

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

No branches or pull requests

2 participants