cancel
Showing results for 
Search instead for 
Did you mean: 

Modifying HID sample for 64Byte IN and OUT reports

rishi2
Associate III
Posted on August 21, 2012 at 15:29

I was trying to add OUT report to existing HID mouse sample on STM OTG Device library 2.1.0. I am using STM3241G-EVAL.

Here are my descriptors...

 0x09, /* bLength: Configuration Descriptor size */

  USB_CONFIGURATION_DESCRIPTOR_TYPE, /* bDescriptorType: Configuration */

  USB_HID_CONFIG_DESC_SIZ,

  /* wTotalLength: Bytes returned */

  0x00,

  0x01,         /*bNumInterfaces: 1 interface*/

  0x01,         /*bConfigurationValue: Configuration value*/

  0x00,         /*iConfiguration: Index of string descriptor describing

  the configuration*/

  0x80, //0xE0,         /*bmAttributes: bus powered and Support Remote Wake-up */

  0xFA, //0x32,         /*MaxPower 100 mA: this current is used for detecting Vbus*/

  

  /************** Descriptor of custom interface ****************/

  /* 09 */

  0x09,         /*bLength: Interface Descriptor size*/

  USB_INTERFACE_DESCRIPTOR_TYPE,/*bDescriptorType: Interface descriptor type*/

  0x00,         /*bInterfaceNumber: Number of Interface*/

  0x00,         /*bAlternateSetting: Alternate setting*/

  0x02, //0x01,         /*bNumEndpoints*/

  0x03,         /*bInterfaceClass: HID*/

  0x00, //0x01,         /*bInterfaceSubClass : 1=BOOT, 0=no boot*/

  0x00, //0x02,         /*nInterfaceProtocol : 0=none, 1=keyboard, 2=mouse*/

  0,            /*iInterface: Index of string descriptor*/

  /******************** Descriptor of custom HID ********************/

  /* 18 */

  0x09,         /*bLength: HID Descriptor size*/

  HID_DESCRIPTOR_TYPE, /*bDescriptorType: HID*/

  0x11,         /*bcdHID: HID Class Spec release number*/

  0x01,

  0x00,         /*bCountryCode: Hardware target country*/

  0x01,         /*bNumDescriptors: Number of HID class descriptors to follow*/

  0x22,         /*bDescriptorType*/

  HID_MOUSE_REPORT_DESC_SIZE,/*wItemLength: Total length of Report descriptor*/

  0x00,

  /******************** Descriptor of IN endpoint ********************/

  /* 27 */

  0x07,          /*bLength: Endpoint Descriptor size*/

  USB_ENDPOINT_DESCRIPTOR_TYPE, /*bDescriptorType:*/

  

  HID_IN_EP,     /*bEndpointAddress: Endpoint Address (IN)*/

  0x03,          /*bmAttributes: Interrupt endpoint*/

  HID_IN_PACKET, /*wMaxPacketSize: 64 Byte max */

  0x00,

  0x0A,          /*bInterval: Polling Interval (10 ms)*/

  /* 34 */

//********************Descriptor of OUT endpoint ********************/

   0x07,          /* bLength: Endpoint Descriptor size */

   USB_ENDPOINT_DESCRIPTOR_TYPE, /* bDescriptorType: */

   HID_OUT_EP,          /* bEndpointAddress: Endpoint Address (OUT) */

   0x03,          /* bmAttributes: Interrupt endpoint */

   HID_OUT_PACKET,       /* wMaxPacketSize: 64 Bytes max  */       

   0x00,

   0x0A,          /* bInterval: Polling Interval (1 ms) */  

/* 41 */

And report descriptor is as follows : [

  0x06, 0x00, 0xff,                   // USAGE_PAGE (Vendor Defined Page 1)

    0x09, 0x01,                         // USAGE (Vendor Usage 1)

    0xa1, 0x01,                         // COLLECTION (Application)

                                        // ------ common globals ------

    0x15, 0x00,                         //   LOGICAL_MINIMUM (0)

    0x26, 0xff, 0x00,                   //   LOGICAL_MAXIMUM (255)

    0x75, 0x08,                         //   REPORT_SIZE (8)   - bits

                                        // ------ input report ------

    0x95, 0x40 //   REPORT_COUNT      - bytes

    0x09, 0x01,                         //   USAGE (Vendor Usage 1)

    0x81, 0x02,                         //   INPUT (Data,Var,Abs)

                                        // ------ output report ------

    0x95, 0x40, //   REPORT_COUNT      - bytes

    0x09, 0x01,                         //   USAGE (Vendor Usage 1)

    0x91, 0x02,                         //   OUTPUT (Data,Var,Abs)

    0xc0                                // END_COLLECTION

And added the Data out funcxtion as follows :

static uint8_t  USBD_HID_DataOut( void *pdev, uint8_t epnum )

{

  

  if ( epnum != (HID_OUT_EP & 0x0F) )

    return USBD_FAIL;

  /* Get the received data buffer and update the counter */

  pointertoUSBPACKET = ((USB_OTG_CORE_HANDLE*)pdev)->dev.out_ep[epnum].xfer_count;

  

  //try to send it back... 

  //USBD_HID_SendReport (&USB_OTG_dev,USBPACKET,pointertoUSBPACKET);

  /* Prepare Out endpoint to receive next packet */

  DCD_EP_PrepareRx(pdev,

                   HID_OUT_EP,

                   (uint8_t*)(USBPACKET),

                   HID_OUT_PACKET);

  return USBD_OK;

}

My device succesfully enumerates, but i can not read/write reports.

I am trying to send the reports from SysTick_Handler.

The problem is when i try to get report/set report using SimpleHIDWrite, it always fails with ''A device attached to the system is not functioning'' (1F)

Another thing i noticed if i try to write using SimpleHIDWrite and first byte is 0 then i get the control in USBD_HID_DataOut() but pointertoUSBPACKET always gets 0. And if i change the first byte to anything other than 0 it always fails with ''Parameter is incorrect (57)''. 

So in report descriptor do we need to have the Report IDs , is it mandatory?

Please give me some pointers, thanks

#usb #hid #custom-usb-hid
0 REPLIES 0