This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

size prob in USBHID

I need help with the USBHID example which is part of the the Keil MCB2300 Evaluation Board (using the Philips LPC2300 ARM processor).

I want to re-use this source code in my project, but this example sends only one byte at a time. I need to send and receive up to 64 bytes. It looks like the source code is prepared to handle more than one byte, however during the identification of the USB to the host computer, the length is fixed to one byte. How do I change the packet length for this example?

yes there is a one solution on forum,but still i can not understand properly.so if any one have sol. plz reply me.

  • Hello, you gotta change report desriptor to be similar to this (source comes from other project, but should help, this HID sends 64B and receives 64B):

    const char pxReportDescriptor[] =
    {
            0x06, 0x00, 0xFF,       // Usage Page Vendor defined page 1
            0x09, 0x00,             // Usage something (other than 0 is required if using undefined page)
            0xA1, 0x01,             // Collection App (seem to need a collection?)
    // Input Report
            0x09, 0x00,             // Usage Undefined
            0x75, 0x08,             // REPORT_SIZE      Data received is 8 Bits in Size
            0x95, REPORT_SIZE_IN,   // REPORT_COUNT     Report Count
            0x26, 0xFF, 0x00,       // LOGICAL_MAXIMUM  Max 255 // MIREK musi byt dvojbajtove aby to nepovazoval za zaporne cislo
            0x15, 0x00,             // LOGICAL_MINIMUM  Min 0
            0x81, 0x02,             // Input // MIREK: data, var, abs
    // Output Report
            0x09, 0x00,             // Usage Undefined
            0x91, 0x02,             // MIREK Output: data, var, abs
            0xC0
    };
    

    config descriptor should be similat to this:

    const char pxConfigDescriptor[] = {
            /* Configuration 1 descriptor */
            0x09,                   /* CbLength                                                                     */
            0x02,                   /* CbDescriptorType                                                     */
            0x22+7-0, 0x00,         /* CwTotalLength 2 EP + Control                         */
            0x01,                   /* CbNumInterfaces                                                      */
            0x01,                   /* CbConfigurationValue                                         */
            usbCONFIGURATION_STRING,/* CiConfiguration                                      */
            usbBUS_POWERED, /* CbmAttributes Bus powered + Remote Wakeup*/
            0x32,                   /* CMaxPower: 100mA                                                     */
    
            /* Joystick Interface Descriptor Requirement */
            0x09,                   /* bLength                                                                      */
            0x04,                   /* bDescriptorType                                                      */
            0x00,                   /* bInterfaceNumber                                                     */
            0x00,                   /* bAlternateSetting                                            */
            0x01+1-0,                       /* bNumEndpoints                                                        */
            0x03,                   /* bInterfaceClass: HID code                            */
            0x00,                   /* bInterfaceSubclass                                           */
            0x00,                   /* bInterfaceProtocol                                           */
            usbINTERFACE_STRING,    /* iInterface                                                   */
    
            /* HID Descriptor */
            0x09,                   /* bLength                                                                      */
            0x21,                   /* bDescriptor type: HID Descriptor Type        */
            0x11, 0x01,             /* bcdHID                                                                       */
            0x00,                   /* bCountryCode                                                         */
            0x01,                   /* bNumDescriptors                                                      */
            usbHID_REPORT_DESCRIPTOR,         /* bDescriptorType                    */
            sizeof( pxReportDescriptor), 0x00, /* wItemLength                       */
    
            // Endpoint 1 descriptor PIPE 1 -----------------------------------------------------------------------
            0x07,                   // bLength
            0x05,                   // bDescriptorType
            0x81,                   // bEndpointAddress, Endpoint 01 - IN
            0x03,                   // bmAttributes      Interrupt
            REPORT_SIZE_IN, 0x00,   // wMaxPacketSize: 3 bytes (x, y, z) // 08
            0x01,                   // bInterval
    
            // Endpoint 2 descriptor PIPE 2 -----------------------------------------------------------------------
            0x07,                   // bLength
            0x05,                   // bDescriptorType
            0x03,                   // bEndpointAddress, Endpoint 03 - OUT
            0x03,                   // bmAttributes      - Interrupt
            REPORT_SIZE_OUT, 0x00,          // wMaxPacketSize: 3 bytes (x, y, z)
            0x01    /**/            // bInterval
    };
    

    REPORT_SIZE_IN has to be set to 64
    REPORT_SIZE_OUT has to be set to 64

    BTW: You could probably use HHD USB monitor, download it's trial at: www.hhdsoftware.com/.../usb-monitor.html , it will show you sizes of enpoints.

    Have a nice day, Mirek

  • Hi,
    I use USBHID example for MCBSTR9 ARM9 Board, I want to make 1 more endpoint to write and change the packet size to 32. I can send the data at 32 byte but I can't read the data back.

    code in usbcfg.h

    #define USB_POWER           0
    #define USB_IF_NUM          4
    #define USB_EP_NUM          3
    //#define USB_MAX_PACKET0     8
    #define USB_MAX_PACKET0     32
    #define USB_DBL_BUF_EP      0x0000
    
    #define USB_POWER_EVENT     0
    #define USB_RESET_EVENT     1
    #define USB_SUSPEND_EVENT   0
    #define USB_RESUME_EVENT    0
    #define USB_WAKEUP_EVENT    0
    #define USB_SOF_EVENT       0
    #define USB_ERROR_EVENT     0
    //#define USB_EP_EVENT        0x0003
    #define USB_EP_EVENT        0x0007
    #define USB_CONFIGURE_EVENT 1
    #define USB_INTERFACE_EVENT 0
    #define USB_FEATURE_EVENT   0
    

    code in usbdesc.c


    /* USB Configuration Descriptor */
    /* All Descriptors (Configuration, Interface, Endpoint, Class, Vendor */
    const BYTE USB_ConfigDescriptor[] = {
    /* Configuration 1 */ USB_CONFIGUARTION_DESC_SIZE, /* bLength */ USB_CONFIGURATION_DESCRIPTOR_TYPE, /* bDescriptorType */ WBVAL( /* wTotalLength */ USB_CONFIGUARTION_DESC_SIZE + USB_INTERFACE_DESC_SIZE + HID_DESC_SIZE + 2*USB_ENDPOINT_DESC_SIZE ), 0x01, /* bNumInterfaces */ 0x01, /* bConfigurationValue */ 0x00, /* iConfiguration */ USB_CONFIG_BUS_POWERED /*|*/ /* bmAttributes */
    /*USB_CONFIG_REMOTE_WAKEUP*/, USB_CONFIG_POWER_MA(100), /* bMaxPower */
    /* Interface 0, Alternate Setting 0, HID Class */ USB_INTERFACE_DESC_SIZE, /* bLength */ USB_INTERFACE_DESCRIPTOR_TYPE, /* bDescriptorType */ 0x00, /* bInterfaceNumber */ 0x00, /* bAlternateSetting */ 0x02, /* bNumEndpoints */ USB_DEVICE_CLASS_HUMAN_INTERFACE, /* bInterfaceClass */ HID_SUBCLASS_NONE, /* bInterfaceSubClass */ HID_PROTOCOL_NONE, /* bInterfaceProtocol */ 0x5C, /* iInterface */
    /* HID Class Descriptor */
    /* HID_DESC_OFFSET = 0x0012 */ HID_DESC_SIZE, /* bLength */ HID_HID_DESCRIPTOR_TYPE, /* bDescriptorType */ WBVAL(0x0100), /* 1.00 */ /* bcdHID */ 0x00, /* bCountryCode */ 0x01, /* bNumDescriptors */ HID_REPORT_DESCRIPTOR_TYPE, /* bDescriptorType */ WBVAL(HID_REPORT_DESC_SIZE), /* wDescriptorLength */
    /* Endpoint, HID Interrupt In */ USB_ENDPOINT_DESC_SIZE, /* bLength */ USB_ENDPOINT_DESCRIPTOR_TYPE, /* bDescriptorType */ USB_ENDPOINT_IN(1), /* bEndpointAddress */ USB_ENDPOINT_TYPE_INTERRUPT, /* bmAttributes */ WBVAL(0x0020), /* wMaxPacketSize */ 0x20, /* 32ms */ /* bInterval */ /* Endpoint, HID Interrupt Out */ USB_ENDPOINT_DESC_SIZE, /* bLength */ USB_ENDPOINT_DESCRIPTOR_TYPE, /* bDescriptorType */ USB_ENDPOINT_OUT(2), /* bEndpointAddress */ USB_ENDPOINT_TYPE_INTERRUPT, /* bmAttributes */ WBVAL(0x0020), /* wMaxPacketSize */ 0x20, /* 32ms */ /* bInterval */
    /* Terminator */ 0 /* bLength */
    };

    and code in usbuser.c to use to read endpoint

    void USB_EndPoint1 (DWORD event) {
      USB_ReadEP(0x02, buffer1);
      USB_WriteEP(0x81, buffer1, sizeof(buffer1));
    }
    
    
    /*
     *  USB Endpoint 2 Event Callback
     *   Called automatically on USB Endpoint 2 Event
     *    Parameter:       event
     */
    
    void USB_EndPoint2 (DWORD event) {
      USB_ReadEP(0x02, buffer2);
      msg2 = buffer2;
      SetOutReport();
    }
    

    when I read the data back, I alway got 4 byte junk stuff before the real data.
    So can anyone help me?

    Thank you,

    John