Author Topic: Losing A Byte In Setup Packet On Control Write  (Read 14099 times)

RRRitchey

  • Member
  • ***
  • Posts: 5
Losing A Byte In Setup Packet On Control Write
« on: October 20, 2011, 05:40:58 pm »
Hello,
I am using the demo software winusb_cs.

I have a device where the driver is working.  I defined a RequestType as
0x41 and a Request as 0x83.  I set Value to 0x1122 and Index to 0x3344.
I also defined 16 bytes of dummy data to transfer.  When I do the transfer
I am losing the low byte of Index.  My received setup looks like

0x41 0x83 0x22 0x11 0x00 0x33 0x10

The data transfers fine.  I have attached the only file I changed.  I am
at a loss why I am loosing this one byte.  Thanks for any input.



[attachment deleted by admin]
« Last Edit: October 20, 2011, 06:19:20 pm by RRRitchey »

Jan Axelson

  • Administrator
  • Frequent Contributor
  • *****
  • Posts: 3033
    • Lakeview Research
Re: Losing A Byte In Setup Packet On Control Write
« Reply #1 on: October 20, 2011, 10:08:32 pm »

RRRitchey

  • Member
  • ***
  • Posts: 5
Re: Losing A Byte In Setup Packet On Control Write
« Reply #2 on: October 21, 2011, 10:25:40 am »
That is interesting. This is Coldfire bootloader demo code from Freescale, I have not changed it.  Since they do not supply the Windows side source I was trying to get something going using your code.  They pass a 32-bit memory address using Value and Index:
vStartAddr = *(dword *) &Setup_Pkt.wValue_l;
Somehow, I would image, they got this to work so that the byte is not masked.  Since I cannot get their Windows source code I cannot see what they did. Thanks for the insights.  I guess for now I will try to work around this somehow.

RRRitchey

  • Member
  • ***
  • Posts: 5
Re: Losing A Byte In Setup Packet On Control Write
« Reply #3 on: October 28, 2011, 11:37:25 am »
Hi,
I found this on another site after a lot of searching:

x41 is a vendor request, output, aimed at an interface.  When the target
is an interface, the wIndex field must contain the target interface number.
0xFC is probably not a valid interface number.
 
If you want to use all three fields for arbitrary purposes, send your
request to the device (0x40) or to "other" (0x43).

Jan Axelson

  • Administrator
  • Frequent Contributor
  • *****
  • Posts: 3033
    • Lakeview Research
Re: Losing A Byte In Setup Packet On Control Write
« Reply #4 on: October 28, 2011, 12:09:55 pm »
The USB 2.0 spec says:

9.3.4 wIndex
The contents of this field vary according to the request. It is used to pass a parameter to the device, specific
to the request.
The wIndex field is often used in requests to specify an endpoint or an interface.

So I think its use can vary depending on the request and the driver.

Jan


RRRitchey

  • Member
  • ***
  • Posts: 5
Re: Losing A Byte In Setup Packet On Control Write
« Reply #5 on: October 28, 2011, 12:19:22 pm »
Hi,
Yes, I understand this.  But if using WinUSB then if you want to use all 3 fields for other purposes it seems you cannot use 0x41 type.  The wIndex field will always get masked by WinUSB. For other request types, WinUSB will not mask the wIndex field.  I thought this might be helpful but maybe I should not have posted.

Jan Axelson

  • Administrator
  • Frequent Contributor
  • *****
  • Posts: 3033
    • Lakeview Research
Re: Losing A Byte In Setup Packet On Control Write
« Reply #6 on: October 28, 2011, 12:31:53 pm »
Of course that is useful information, thanks for posting it. I thought the previous poster on this topic had tried changing bmRequestType to specify the device, so I would be interested to know if it works for you.

Jan

RRRitchey

  • Member
  • ***
  • Posts: 5
Re: Losing A Byte In Setup Packet On Control Write
« Reply #7 on: November 09, 2011, 03:06:26 pm »
When I changed the vendor command to address the device (0b00000) instead of the specific interface (0b00001) the wIndex field was not masked.  It appears that WinUSB will mask the wIndex field and replace it with the interface number.  I am not sure what WinUSB's behavior is for "other element" addressing (0b00011).

Jan Axelson

  • Administrator
  • Frequent Contributor
  • *****
  • Posts: 3033
    • Lakeview Research
Re: Losing A Byte In Setup Packet On Control Write
« Reply #8 on: November 09, 2011, 03:09:14 pm »
That makes sense. Thanks for posting what you found!

Jan