Author Topic: HID device. Can't read data  (Read 15656 times)

puppdn

  • Member
  • ***
  • Posts: 19
HID device. Can't read data
« on: October 06, 2016, 09:04:54 am »
Hu Jan and everyone. I believe you're can help me.

Here is set of descriptors
Code: [Select]
const uint8_t HID_DeviceDescriptor[0x12] =   {
    0x12,         // overall descriptor length
    USB_DEVICE_DESCRIPTOR_TYPE, // bDescriptorType -  Device descriptor
    0x00, 0x02,                 // bcdUSB usb 2.0
// class, subclass
    0x00,                       //bDeviceClass
    0x00,                       //bDeviceSubClass
    0x00,                       //bDeviceProtocol
    0x40,                       //bMaxPacketSize - max size of packets
// vid pid
    0x25, 0x09,                 //idVendor
    0x37, 0x12,                 //idProduct
    0, 0x01,                 // bcdDevice rel. DEVICE_VER_H.DEVICE_VER_L 
    1,                          //Index of string descriptor describing manufacturer //old value 1
    2,                          //Index of string descriptor describing product //old value 2
    3,                          //Index of string descriptor describing the device serial number //old value 3
    0x01                        // bNumConfigurations - configurations.
};


const uint8_t HID_ConfigDescriptor[0x29] =  {//CustomHID_ConfigDescriptor
0x09,//config descr standart value
0x02,// Type (config descr)
0x22,//Totallength low half word (the length of the configuration descriptor, )
0x00,//Totallength hi half word (the interface descriptor, the HID descriptor, and one endpoint descriptor.)
0x01,//NumInterfaces This item defines the number of interface settings contained in this configuration.
0x01,//bConfigurationValue (Used in Get_Configuration and Set_Configuration to identify this configuration.)
0xB1,//iConfiguration (string index for a string that describes this configuration.) old 0x01
0x80,//bmAttributes
0x32,//MaxPower (in 2 mA units) (100ma)
0x09,// bLength
0x04,// bDescriptorType (Interface)
0x00,// bInterfaceNumber (only one interface)
0x00,// bAlternateSetting (for multiply interfaces)
0x01,// bNumEndpoints (only one EP)
0x03,// bInterfaceClass (3 = HID)
0x00,// bInterfaceSubClass
0x00,// bInterfaceProcotol
0xC1, // iInterface old 0x00
0x09, // bLength
0x21, // bDescriptorType
0x01,// bcdHID low
0x01,// bcdHID hi
0x00,// bCountryCode
0x01,//bNumDescriptors
0x22,// bDescriptorType - Hid report descriptor
Custom_HID_RepDesc_LEN_INOUT,// total length of report low//this is total length of report descriptor
0x0,// total length of report  hi
0x07,//EP descr
0x05,// bDescriptorType (EP)
0x01,//ep address and direction  addr=1 dir=OUT (old 0x81 addr=1 dir=IN)
0x03,//bmAttributes
0x0A,// MaxPacketSize (low)//old 2
0x00,// MaxPacketSize (hi)
10,// bInterval
0x07,//EP descr
0x05,// bDescriptorType (EP)
0x81,//ep address and direction  addr=1 dir=IN
0x03,//bmAttributes
0x0A,// MaxPacketSize (low)//old 2
0x00,// MaxPacketSize (hi)
10// bInterval
};

const uint8_t  Custom_HID_ReportDescriptorINOUT[Custom_HID_RepDesc_LEN_INOUT] = {
   0x05, 0x01,                    // USAGE_PAGE (Generic Desktop)
    0x09, 0x00,                    // USAGE (Undefined)
    0xa1, 0x01,                    // COLLECTION (Application)
    0x15, 0x00,                    //   LOGICAL_MINIMUM (0)
    0x26, 0xff, 0x00,              //   LOGICAL_MAXIMUM (255)
    0x75, 0x08,                    //   REPORT_SIZE (8)
    0x95, 0x02,                    //   REPORT_COUNT (2)
    0x09, 0x00,                    //   USAGE (Undefined)
    0x81, 0x82,                    //   INPUT (Data,Var,Abs,Vol)
    0x95, 0x05,                    //   REPORT_COUNT (5)
    0x09, 0x00,                    //   USAGE (Undefined)
    0x91, 0x82,                    //   OUTPUT (Data,Var,Abs,Vol)
    0xc0                           //   END_COLLECTION
};//

My device recognized by Windows and I can send bytes:
Code: [Select]
HANDLE file=CreateFile(ptrDetail->DevicePath,GENERIC_READ|GENERIC_WRITE,
                                       FILE_SHARE_WRITE|FILE_SHARE_READ,
                                       (LPSECURITY_ATTRIBUTES)NULL,
                                       OPEN_EXISTING,
                                       FILE_ATTRIBUTE_NORMAL,
                                       0);


char arr[6] = {0x0,0x31,0x02,0xA1,0xA2,0x13};/

WriteFile(file,arr,6,&sended,NULL);

But I can't perform Readfile():
Code: [Select]
char rxArr[20];           
DWORD received;
memset(rxArr, 0, 20);
ReadFile(file,rxArr,3,&received,NULL);
Here program causing loop and I can't retrieve answer.
I.e. Reading not working.
If look at USB BUS using logic analyzer i see OUT packet when program perforw WriteFile() (PId, Address etc. all OK)
When host perform ReadFile() - NOTHING.
I think USB driver block my request.

Jan Axelson

  • Administrator
  • Frequent Contributor
  • *****
  • Posts: 3033
    • Lakeview Research
Re: HID device. Can't read data
« Reply #1 on: October 06, 2016, 04:39:54 pm »

puppdn

  • Member
  • ***
  • Posts: 19
Re: HID device. Can't read data
« Reply #2 on: October 06, 2016, 11:44:04 pm »
I mean when my program run to readfile() func. (I'm use console app)  the cursor blink and program does not continue to next functions. Seems like readfile waiting for.. response from whatever

Jan Axelson

  • Administrator
  • Frequent Contributor
  • *****
  • Posts: 3033
    • Lakeview Research
Re: HID device. Can't read data
« Reply #3 on: October 07, 2016, 09:35:09 am »
If the IN endpoint returns NAKs in response to IN token packets, ReadFile will hang.

Are you using a hardware analyzer that will show IN token packets from the host and NAK responses from the device?

If not, use whatever debugging tools you have (monitor program, watch variables) to determine if the device is seeing IN token packets and if so, how it is responding to them.

 

puppdn

  • Member
  • ***
  • Posts: 19
Re: HID device. Can't read data
« Reply #4 on: October 07, 2016, 11:07:44 am »
Yes, I'm using Sales logic, that show all, that happens at usb bus. I can see enumeration process(setup, in transactions, sync, so and etc) If I perform writefile - all perfect, I see address, ep number, PID out, seeded data, ACK from mcu - all perfect. After that I perform readfile() and nothing I can see. No PID in, no address,  no data no acknowledgement - nothing.

Jan Axelson

  • Administrator
  • Frequent Contributor
  • *****
  • Posts: 3033
    • Lakeview Research
Re: HID device. Can't read data
« Reply #5 on: October 07, 2016, 12:35:43 pm »
The interface descriptor has:

0x01,// bNumEndpoints (only one EP)

Should be 0x02

puppdn

  • Member
  • ***
  • Posts: 19
Re: HID device. Can't read data
« Reply #6 on: October 07, 2016, 03:23:46 pm »
Quote
The interface descriptor has:

0x01,// bNumEndpoints (only one EP)

Should be 0x02

Hm... But i have 0-EP (Control) and 1-EP (Interrupt) (The two endpoints, okay). My device can transmit and receive trough 0-EP (100% worked), and i can only transmit to 1-EP (50% worked).
Here says:
https://msdn.microsoft.com/ru-ru/library/ff540065(v=vs.85).aspx

bNumEndpoints
The number of endpoints that are used by the interface, excluding the default status endpoint.


I will try change (at Monday) bNumEndpoint field to 0x02, but seems it's not helpful. Anyway thank you wery much for your replies. to get to work the device.
P.S. Sorry for my poor language  :)

Jan Axelson

  • Administrator
  • Frequent Contributor
  • *****
  • Posts: 3033
    • Lakeview Research
Re: HID device. Can't read data
« Reply #7 on: October 07, 2016, 09:09:47 pm »
bNumEndpoint is the number of endpoint descriptors in the interface, for example, endpoint 1 IN and endpoint 1 OUT.

The terminology used in the USB spec and other documentation is confusing and inconsistent.


puppdn

  • Member
  • ***
  • Posts: 19
Re: HID device. Can't read data
« Reply #8 on: October 08, 2016, 02:53:19 am »
Quote
The terminology used in the USB spec and other documentation is confusing and inconsistent.
I agree.

Jan Axelson

  • Administrator
  • Frequent Contributor
  • *****
  • Posts: 3033
    • Lakeview Research
Re: HID device. Can't read data
« Reply #9 on: October 09, 2016, 02:08:39 pm »
 :)

puppdn

  • Member
  • ***
  • Posts: 19
Re: HID device. Can't read data
« Reply #10 on: October 10, 2016, 04:46:11 am »
I tried to change bNumEndpoint, load firmware in device.  Windows perform all required requests, and then Windows show error, like device was not succeed installed. In device manager my device have yellow triangle and error code 10.

Update:
In usbview I can see only devuce descriptor, ep descriptor and connection status.
« Last Edit: October 10, 2016, 06:58:12 am by puppdn »

Jan Axelson

  • Administrator
  • Frequent Contributor
  • *****
  • Posts: 3033
    • Lakeview Research
Re: HID device. Can't read data
« Reply #11 on: October 10, 2016, 10:07:04 am »
To force Windows to forget the previous descriptors, with the device attached, open Windows Device Manager and uninstall the device (under Driver). Then reattach.

puppdn

  • Member
  • ***
  • Posts: 19
Re: HID device. Can't read data
« Reply #12 on: October 10, 2016, 10:19:43 am »
I'm just change PID of device in firmvare and OS perform installing device as new device.
In USBView presented:
Quote
Device Descriptor:
bcdUSB:             0x0200
bDeviceClass:         0x00
bDeviceSubClass:      0x00
bDeviceProtocol:      0x00
bMaxPacketSize0:      0x40 (64)
idVendor:           0x0925
idProduct:          0x1234
bcdDevice:          0x0100
iManufacturer:        0xA1
iProduct:             0xA2
iSerialNumber:        0xA3
bNumConfigurations:   0x01

ConnectionStatus: DeviceConnected
Current Config Value: 0x01
Device Bus Speed:     Full
Device Address:       0x04
Open Pipes:              1

Endpoint Descriptor:
bEndpointAddress:     0x81  IN
Transfer Type:   Interrupt
wMaxPacketSize:     0x000A (10)
bInterval:            0x0A
That's all. No interface descriptor, no configuration descriptor. But USBView must show all descriptors.
For example - mouse:
Quote
Device Descriptor:
bcdUSB:             0x0200
bDeviceClass:         0x00
bDeviceSubClass:      0x00
bDeviceProtocol:      0x00
bMaxPacketSize0:      0x08 (8 )
idVendor:           0x046D (Logitech Inc.)
idProduct:          0xC077
bcdDevice:          0x7200
iManufacturer:        0x01
0x0409: "Logitech"
iProduct:             0x02
0x0409: "USB Optical Mouse"
iSerialNumber:        0x00
bNumConfigurations:   0x01

ConnectionStatus: DeviceConnected
Current Config Value: 0x01
Device Bus Speed:     Low
Device Address:       0x02
Open Pipes:              1

Endpoint Descriptor:
bEndpointAddress:     0x81  IN
Transfer Type:   Interrupt
wMaxPacketSize:     0x0004 (4)
bInterval:            0x0A

Configuration Descriptor:
wTotalLength:       0x0022
bNumInterfaces:       0x01
bConfigurationValue:  0x01
iConfiguration:       0x00
bmAttributes:         0xA0 (Bus Powered Remote Wakeup)
MaxPower:             0x32 (100 Ma)

Interface Descriptor:
bInterfaceNumber:     0x00
bAlternateSetting:    0x00
bNumEndpoints:        0x01
bInterfaceClass:      0x03 (HID)
bInterfaceSubClass:   0x01
bInterfaceProtocol:   0x02
iInterface:           0x00

HID Descriptor:
bcdHID:             0x0111
bCountryCode:         0x00
bNumDescriptors:      0x01
bDescriptorType:      0x22
wDescriptorLength:  0x002E

Endpoint Descriptor:
bEndpointAddress:     0x81  IN
Transfer Type:   Interrupt
wMaxPacketSize:     0x0004 (4)
bInterval:            0x0A

Jan Axelson

  • Administrator
  • Frequent Contributor
  • *****
  • Posts: 3033
    • Lakeview Research
Re: HID device. Can't read data
« Reply #13 on: October 10, 2016, 08:17:57 pm »
What does the analyzer show during enumeration? Does the host read all of the descriptors and send a Set Configuration request with a value of 1 and does the device ACK the request?

puppdn

  • Member
  • ***
  • Posts: 19
Re: HID device. Can't read data
« Reply #14 on: October 11, 2016, 11:05:38 am »
Strange behaviour :
If I define only 1 OUT EP - everything ok.
If only 1 OUT EP -everything bad.
If I change ep address 0x81 -> 0x01, and in report descriptor
Quote
   const uint8_t  Custom_HID_ReportDescriptorINOUT[Custom_HID_RepDesc_LEN_INOUT] = {
      0x05, 0x01,                    // USAGE_PAGE (Generic Desktop)
    0x09, 0x00,                    // USAGE (Undefined)
    0xa1, 0x01,                    // COLLECTION (Application)
    0x15, 0x00,                    //   LOGICAL_MINIMUM (0)
    0x26, 0xff, 0x00,              //   LOGICAL_MAXIMUM (255)
    0x75, 0x08,                    //   REPORT_SIZE (8)
    0x95, 0x02,                    //   REPORT_COUNT (2)
    0x09, 0x00,                    //   USAGE (Undefined)
    0x81, 0x82,                    //   INPUT (Data,Var,Abs,Vol)
    0xc0                           //   END_COLLECTION
};//
Change input ->output, according 0x81,0x82 ->0x91,0x82
Host sent requests, but device no respond.