Author Topic: HID Control Transfer Fails  (Read 22617 times)

Des

  • Member
  • ***
  • Posts: 2
HID Control Transfer Fails
« on: January 13, 2013, 05:09:43 pm »
I'm using generic_hid_cs_50 straight "'out of the box" and cannot get control transfers to work.
I can find the hid device no problem and communicate via interrupt transfers.
It appears that HidD_SetOutputReport is unsuccessful when I select "Use ControlTransfers Only".
I believe the hidHandle is valid and open as per the debugger. Although I don't really understand SafeFileHandle
The outputReportBuffer looks fine (a byte[65] array)
The outputReportBuffer.Length is 65 so I'm passing 65+1 to the HidD_SetOutputReport API function.
The function returns Success=False so of course the communications gets closed and the subsequent request for the input report encounters a closed handle generating errors.

Why is the following HidD_SetOutputReport call unsuccessful ?
                 success = HidD_SetOutputReport(hidHandle, outputReportBuffer, outputReportBuffer.Length + 1);
I've tried it on Vista and Windows7.  Is there some permissions problem with the OS ?

Thanks in advance

Jan Axelson

  • Administrator
  • Frequent Contributor
  • *****
  • Posts: 3033
    • Lakeview Research
Re: HID Control Transfer Fails
« Reply #1 on: January 13, 2013, 06:20:29 pm »
Does your HID's firmware support the HID-class Set_Report request?

If so, what is the error message or what does a protocol analyzer show?

Des

  • Member
  • ***
  • Posts: 2
Re: HID Control Transfer Fails
« Reply #2 on: January 14, 2013, 03:28:20 pm »
I believe so. I'm using the Microchip GenericHID firmware 2.7b. 
It looks like it's got the routines to handle the HID requests like Get_Report, Set_Report etc
I even tried loading a clean copy of the F/W in a different microcontroller part number and still the Control Transfers fail.
Finding the HID and interrupt transfers are working fine.

Thank you

Jan Axelson

  • Administrator
  • Frequent Contributor
  • *****
  • Posts: 3033
    • Lakeview Research
Re: HID Control Transfer Fails
« Reply #3 on: January 14, 2013, 05:32:45 pm »
Use my generic HID firmware here:

http://lvr.com/hidpage.htm#MyExampleCode

embeddedaebi

  • Member
  • ***
  • Posts: 6
Re: HID Control Transfer Fails
« Reply #4 on: January 29, 2013, 05:09:53 am »
Hello
I am also developing a simple usb HID device. I am using Atmel At89c5131a controller. I trying to send 'aebi' from PC to device and then loopback from device to PC. I am able to send 'aebi' from device to PC by storing 'aebi' in the controller and using HidD_GetInputReport in PC application, but I am not able to send 'aebi' from PC to device using HidD_SetOutputReport. I get a CRC error 23 (which is due to firmware issues). Then I was trying to see if the controller is getting the Set_report request or not by setting LED which showed that the controller is not getting the request as the LED was not getting ON.
What can be the issues?
Also I am not able to receive and send data using Readfile  and Writefile respectively. Please help!!! 

Jan Axelson

  • Administrator
  • Frequent Contributor
  • *****
  • Posts: 3033
    • Lakeview Research
Re: HID Control Transfer Fails
« Reply #5 on: January 29, 2013, 09:36:55 am »
Does your device firmware support the HID-class Set Report request? Does the HID's report descriptor define a 4-byte Output report?

A hardware-based protocol analyzer will show what is happening on the bus.

If you don't have an analyzer, use whatever debugging tools you have to isolate the problem. It sounds like you've made a start. Use the LED to debug further up the line, for example on detecting the request (before branching to code to handle the request). Same advice for ReadFile and WriteFile.

embeddedaebi

  • Member
  • ***
  • Posts: 6
Re: HID Control Transfer Fails
« Reply #6 on: January 29, 2013, 11:41:51 pm »
0x06,0x00,0xff,        // vendor defined usage page   
      0x09,0x01,        // vendor usage 1
      0xA1,0x01,       // collection application
       0x09,0x01,       // usage 
      0x15,0x00,        // logical minimum 0
0x26,0xff,0x00,        // logical maximum 255
      0x75,0x08,        // report size 8
      0x95,0x04,        // report count 4     
0x92,0x03,0x01,      // output( data,variable,buffered)
0xC0                      // end

This is the output report descriptor.
The input report descriptor that worked with Get_report was the same, just 0x92 was replaced by 0x82.
The firmware supports Set_Report request.

void usb_hid_set_report (void)
{
  P3=0x00;
  usb_reset_endpoint(EP_CONTROL);
  Usb_clear_rx_setup();
 
  while(!Usb_rx_complete() );
  buffer[0]=Usb_read_byte();                // read the 4 bytes of report. As report id is 0, so it will not travel on the bus. so I haven't
  buffer[1]=Usb_read_byte();               //  accounted it.
  buffer[2]=Usb_read_byte();
  buffer[3]=Usb_read_byte();
  Usb_clear_rx();
  Usb_set_tx_ready();                          // send a zero length packet for STATUS phase
  while(!(Usb_tx_complete()));
  Usb_clear_tx_complete();


The corresponding VC++ code is

{
unsigned char bufO[]={'0','a','e','b','i'};
PVOID pbuf=&bufO;
DeviceHandle=CreateFile(detailData->DevicePath,0, FILE_SHARE_READ|FILE_SHARE_WRITE,                         
                                                                             (LPSECURITY_ATTRIBUTES)NULL,OPEN_EXISTING, 0, NULL);      
DWORD BytesWritten=0;
if (MyDeviceDetected)
{
   if(HidD_SetOutputReport(DeviceHandle,bufO,sizeof(bufO)))
      cout<<"\n Data Written \n";
   else
        {
          cout<<"\n Data not Written \n";
      GetLastError();
   }
}
}


embeddedaebi

  • Member
  • ***
  • Posts: 6
Re: HID Control Transfer Fails
« Reply #7 on: January 30, 2013, 12:04:28 am »
I tried out your suggestions. It seems that setup packet of SET_REPORT is not being received by the controller.
Is it possible that host doesn't send the request due to some reason but returns the error as CRC error 23 ?

Jan Axelson

  • Administrator
  • Frequent Contributor
  • *****
  • Posts: 3033
    • Lakeview Research
Re: HID Control Transfer Fails
« Reply #8 on: January 30, 2013, 11:11:23 am »
The HidD_SetOutputReport buffer should equal the report length + 1 with the first byte = 0 assuming the default report ID.

In my experience, "CRC error" can be due to other errors besides CRC.

embeddedaebi

  • Member
  • ***
  • Posts: 6
Re: HID Control Transfer Fails
« Reply #9 on: January 31, 2013, 12:50:20 am »
Thanx for replying Jan.

On making the output report as a structure, I am able to receive the request SET_REPORT.

struct ReportOut
   {
   unsigned int id;
      char ch[4];

   }report,*preport;
   report.id=0;
   char str[]="aebi";
    memcpy(&(report.ch),&str,(sizeof(str)+1));
   
But I am receiving just 'a' and that too on the 4th position of the receiving( buffer[3]). I expect that buffer[3] should be 'i'. What can I do for this?
I think there is some problem in the report descriptor.
{ 0x06,0x00,0xff,           
      0x09,0x01,       
      0xA1,0x01,         
      0x09,0x01,
      0x15,0x00,         
      0x26,0xff,0x00,         
      0x75,0x08,         
      0x95,0x04,       
      0x82,0x03,0x01,
     0x09,0x02,
      0x15,0x00,         
      0x26,0xff,0x00,         
      0x75,0x08,         
      0x95,0x04,       
      0x92,0x03,0x01,
     0xC0
     }   

I just want to send 4 byte data in the input report and 4 byte data in output report. Please help!!

embeddedaebi

  • Member
  • ***
  • Posts: 6
Re: HID Control Transfer Fails
« Reply #10 on: January 31, 2013, 05:54:59 am »
After lots of hit and trial , I am able to send and receive 4 characters. Now I have to send long integer. To do this I write the individual bytes of long integer into the endpoint and  then send. What I receive on the PC are some special characters like '>' or smiley.
What could be the problem? The codes are-

data_to_send =0x12345678;
Usb_write_byte(((Uchar*)&data_to_send)[0]);
Usb_write_byte(((Uchar*)&data_to_send)[1]);
Usb_write_byte(((Uchar*)&data_to_send)[2]);
Usb_write_byte(((Uchar*)&data_to_send)[3]);
send_data();

corresponding to this in host application code:


if (! (HidD_GetInputReport)(DeviceHandle, bufI,NumberOfBytesRead))
   cout<<endl<<GetLastError();
else
{
   for(i=0;i<5 ;i++)
      cout<<bufI;                                                                                 // This gives special characters like '>' in output.
         cout<<endl<<(long int)bufI;                                                                     // This gives output as 1244844.                  
}

Jan Axelson

  • Administrator
  • Frequent Contributor
  • *****
  • Posts: 3033
    • Lakeview Research
Re: HID Control Transfer Fails
« Reply #11 on: January 31, 2013, 10:44:32 am »
Text encoding issue?

http://msdn.microsoft.com/en-us/library/system.text.encoding(v=vs.110).aspx

Use a breakpoint and look at the data when HidD_GetInputReport retrieves it.