Author Topic: Error writing HID device  (Read 39435 times)

Jan Axelson

  • Administrator
  • Frequent Contributor
  • *****
  • Posts: 3033
    • Lakeview Research
Re: Error writing HID device
« Reply #15 on: February 18, 2011, 11:21:45 am »
Run USBCV if you haven't:

http://www.usb.org/developers/tools/

Test with different host controllers as we've suggested.

Jan

Guido Koerber

  • Frequent Contributor
  • ****
  • Posts: 72
Re: Error writing HID device
« Reply #16 on: February 19, 2011, 02:10:45 am »
Actually to catch a race condition in your code you may need access to the system on which the error happens plus a USB analyzer.

Finding such problems by reading code is likely equivalent to rewriting the whole protocol.

Jan Andersson

  • Member
  • ***
  • Posts: 15
Re: Error writing HID device
« Reply #17 on: March 11, 2011, 11:01:01 am »
Typically interrupt OUT endpoints are set up in hardware to NAK after receiving data until firmware retrieves the data and resets the endpoint to ACK new data. If that is happening correctly, the polling interval isn't an issue.
Is there some kind of "maximum time" a host will wait if the device keeps NAK:ing because it's busy processing a packet? I ask because I have found out that in one case it takes some 300 ms before ACK:ing a certain packet.

Jan Axelson

  • Administrator
  • Frequent Contributor
  • *****
  • Posts: 3033
    • Lakeview Research
Re: Error writing HID device
« Reply #18 on: March 11, 2011, 11:39:20 am »
The USB spec defines limits for control transfers. Otherwise it's up the driver. The Windows HID driver times out control transfers after 5 secs and interrupt transfers never. A keyboard might sit idle for hours, days, weeks, before someone decides to tap a key. The host doesn't know or care whether the NAK is because the endpoint is busy or has no data.

Jan

Jan Andersson

  • Member
  • ***
  • Posts: 15
Re: Error writing HID device
« Reply #19 on: April 14, 2011, 04:41:48 am »
After gaining physical access to a computer having the mentioned problem I finally found what most likely seems to be the cause. It is in the USB device's firmware. I use USB interrupt in combination with USB handling in the program's main loop. It was when issuing a select endpoint command in the main loop it failed getting an command-ready-ack from the USB Serial Engine. The reason for that was that I didn't know/foresee that the USB interrupt had to be temporarily turned off during the SE access, so a USB interrupt which also accessed the SE happened while the main loop was accessing the SE... The whole USB stack is based on an example, which didn't turn off the USB interrupt in the concerned functions, and I did not think about such a possibility, especially since it work on all our computers and most of the customers too...  :-[

Jan Axelson

  • Administrator
  • Frequent Contributor
  • *****
  • Posts: 3033
    • Lakeview Research
Re: Error writing HID device
« Reply #20 on: April 14, 2011, 10:58:29 pm »
I'm glad to hear you found the problem.

Jan