Hi, I'm trying to implement the generic USB mouse functionality on NXP LPC1756. Basing on Keil LED HID example, I modified the USB descriptor as following:
/* HID Report Descriptor */ const uint8_t HID_ReportDescriptor[] = { HID_UsagePage(0x01), HID_Usage(0x02), HID_Collection(HID_Application), HID_Usage(0x01), HID_Collection(HID_Physical), HID_UsagePage(HID_USAGE_PAGE_BUTTON), HID_UsageMin(1), HID_UsageMax(3), HID_LogicalMin(0), HID_LogicalMax(1), HID_ReportCount(3), HID_ReportSize(1), HID_Input(HID_Data | HID_Variable | HID_Absolute), HID_ReportCount(1), HID_ReportSize(5), HID_Input(HID_Constant), HID_UsagePage(HID_USAGE_PAGE_GENERIC), HID_Usage(HID_USAGE_GENERIC_X), HID_Usage(HID_USAGE_GENERIC_Y), //HID_Usage(HID_USAGE_GENERIC_WHEEL), HID_LogicalMin(-127), HID_LogicalMax(127), HID_ReportSize(8), HID_ReportCount(2), HID_Input(HID_Data | HID_Variable | HID_Relative), HID_EndCollection, HID_EndCollection }; const uint16_t HID_ReportDescSize = sizeof(HID_ReportDescriptor); /* USB Standard Device Descriptor */ const uint8_t USB_DeviceDescriptor[] = { USB_DEVICE_DESC_SIZE, /* bLength */ USB_DEVICE_DESCRIPTOR_TYPE, /* bDescriptorType */ WBVAL(0x0200), /* 2.00 */ /* bcdUSB */ 0x00, /* bDeviceClass */ 0x00, /* bDeviceSubClass */ 0x00, /* bDeviceProtocol */ USB_MAX_PACKET0, /* bMaxPacketSize0 */ WBVAL(0xc251), /* idVendor */ WBVAL(0x0116), /* idProduct */ WBVAL(0x0100), /* 1.00 */ /* bcdDevice */ 0x04, /* iManufacturer */ 0x20, /* iProduct */ 0x42, /* iSerialNumber */ 0x01 /* bNumConfigurations */ }; /* USB Configuration Descriptor */ /* All Descriptors (Configuration, Interface, Endpoint, Class, Vendor */ const uint8_t USB_ConfigDescriptor[] = { /* Configuration 1 */ USB_CONFIGUARTION_DESC_SIZE, /* bDescriptorType */ USB_CONFIGURATION_DESCRIPTOR_TYPE, /* bDescriptorType */ WBVAL( /* wTotalLength */ USB_CONFIGUARTION_DESC_SIZE + USB_INTERFACE_DESC_SIZE + HID_DESC_SIZE + USB_ENDPOINT_DESC_SIZE ), 0x01, /* bNumInterfaces */ 0x01, /* bConfigurationValue */ 0x00, /* iConfiguration */ USB_CONFIG_BUS_POWERED /*|*/ /* bmAttributes */ 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 */ 0x01, /* bNumEndpoints */ USB_DEVICE_CLASS_HUMAN_INTERFACE, /* bInterfaceClass */ HID_SUBCLASS_BOOT, /* bInterfaceSubClass */ HID_PROTOCOL_MOUSE, /* bInterfaceProtocol */ 0x00, /* iInterface */ /* HID Class Descriptor */ HID_DESC_SIZE, /* bLength */ HID_HID_DESCRIPTOR_TYPE, /* bDescriptorType */ WBVAL(0x0101), /* 1.01 */ /* 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(8), /* wMaxPacketSize */ 0x0A, /* 10ms */ /* bInterval */ /* Terminator */ 0 /* bLength */ };
Now, when connected to the PC, the Keil MCB1700 board appears as HID-Compliant mouse in Device Manager under Win7, so, I imagine, the descriptor is correct. On USBlyzer the device goes through the GET_DESCRIPTOR and SELECT_CONFIGURATION phases, putting a breakpoint in USB_Configure_Event() function confirms that. Unfortunately nothing happens after, the firmware is supposed to refresh IN report data when GetInReport() function is called at USB Endpoint 1 event. The problem is that this event never happens. In fact, it looks like the host never generates the interrupt condition. I'm missing something but I don't see where exactly to dig. Thanks to all for any eventual advise.
Dimitri
I think something is wrong with packed size. At the first BULK_OR_INTERRUPT_TRANSFER the USBlyzer shows the status code 0xc000000c - Occurrence of Buffer Overrun Error, followed by SYNC_RESET_PIPE_AND_CLEAR_STALL. Do you see any solution?
Here are settings for IN/OUT buffers.
In usbdesc.c
#define HID_INPUT_REPORT_BYTES 8 /* size of report in Bytes */ #define HID_OUTPUT_REPORT_BYTES 8 /* size of report in Bytes */ #define HID_FEATURE_REPORT_BYTES 8 /* size of report in Bytes */
In usbcfg.h
#define USB_MAX_PACKET0 8 #define USB_DMA 0 #define USB_DMA_EP 0x00000000 #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 0x0007 #define USB_CONFIGURE_EVENT 1 #define USB_INTERFACE_EVENT 0 #define USB_FEATURE_EVENT 0
Btw, do I need to set USB_DMA to '1'? The HID LED example uses DMA but I'm not sure if I need it in HID mouse app...
Thanks again!
Why have you commented out,
//HID_Usage(HID_USAGE_GENERIC_WHEEL),
?
Is there any reason why you aren't using latest Keil Middleware for that as there is available template prepared for mouse device?
About the wheel, technically I don't need it, for the moment there is no support on the firmware side but with or without does not change anything, I'm getting the same communication problem. There is no reason to not use the latest MDK with build-in USB support except the fact that we're using an old 4.x MDK purchased many years ago. For the moment I cannot justify the spending of thousands $ just for this particular project.
Well the easiest way is to capture USB descriptor of a USB mouse, and look at what your descriptors have different.