Hi,
I'm facing another problem with my SMT32F103 processor, using the usb interface. My endpoint(out) is not working at all.
If I use WriteFile() in my visual c++ project to write some data to the endpoint(out) or to the endpoint(0) nothing happens. I've used one usb sniffer to see if there's any kind of usb traffic using WriteFile() but there's nothing... The initialization is working; all endpoints(IN) are also working as expected.
Here's my keyboard report descriptor:
const BYTE HID_ReportDescriptor[] = { HID_UsagePage ( 0x01 ), //generic desctip HID_Usage ( 0x06 ), //keyboard HID_Collection ( HID_Application ), HID_ReportSize ( 8 ), // 8 bits HID_LogicalMin ( 0x00 ), // value range: 0 - 0xFF HID_LogicalMax ( 0x03 ), // value range: 0 - 0xFF HID_ReportCount ( 1 ), HID_UsagePage ( 0x07), HID_Usage( 0x00 ), // key null - not pressed HID_Usage( 0x2C ), // Space bar HID_Usage( 0x51 ), // Down arrow HID_Usage( 0x52 ), // Up arrow HID_Input ( HID_Data | HID_Array ), /* output report 1byte [0x00, 0xFF] */ HID_LogicalMaxS ( 0xFF ), // value range: 0 - 0xFF HID_UsagePageVendor( 0x01 ), // Vendor specific page HID_Usage ( 0x01 ), HID_Output ( HID_Data | HID_Variable | HID_Absolute ), HID_EndCollection, }; /* I've two report descriptors but the second one has only one endpoint(in) which is working */ //report descriptor touchscreen const BYTE HID_ReportDescriptor2[] = { HID_UsagePage ( 0x01 ), //generic desktop HID_Usage ( 0x02 ), //mouse HID_Collection ( HID_Application ), HID_Usage ( 0x01 ), //pointer HID_Collection ( HID_Physical ), HID_UsagePage ( 0x01 ), //usage page (generic desktop HID_Usage ( 0x30 ), //usage(x) HID_Usage ( 0x31 ), //usage(y) HID_LogicalMin ( 0x00 ), // HID_LogicalMaxS ( 800 ), // HID_PhysicalMinS ( 0x0000 ), // HID_PhysicalMaxL ( 32767 ), // HID_UnitS ( 0x0000 ), HID_ReportSize ( 16 ), // 8 bits HID_ReportCount ( 2 ), HID_Input ( HID_Data | HID_Variable | HID_Absolute | HID_NullState | HID_NoPreferred), HID_EndCollection, HID_EndCollection };
Maybe there someone of you will find some errors.
Here are the other usb descriptors:
/* USB Standard Device Descriptor */ const BYTE USB_DeviceDescriptor[] = { USB_DEVICE_DESC_SIZE, /* bLength */ USB_DEVICE_DESCRIPTOR_TYPE, /* bDescriptorType */ WBVAL(0x0200), /* bcdUSB - usb version 2.0 */ 0x00, /* bDeviceClass */ 0x00, /* bDeviceSubClass */ 0x00, /* bDeviceProtocol */ USB_MAX_PACKET0, /* bMaxPacketSize0 */ WBVAL(0xC312), /* idVendor */ WBVAL(0x3F1B), /* idProduct */ WBVAL(0x010), /* 1.00 */ /* bcdDevice */ 0x01, /* iManufacturer */ 0x02, /* iProduct */ 0x03, /* iSerialNumber */ 0x01 /* bNumConfigurations */ }; /* 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 + USB_ENDPOINT_DESC_SIZE + USB_ENDPOINT_DESC_SIZE + /* interface two: descriptor length */ USB_INTERFACE_DESC_SIZE + HID_DESC_SIZE + USB_ENDPOINT_DESC_SIZE ), 0x02, /* bNumInterfaces */ 0x01, /* bConfigurationValue */ 0x00, /* iConfiguration */ USB_CONFIG_SELF_POWERED //USB_CONFIG_BUS_POWERED /*|*/ /* bmAttributes */ /*USB_CONFIG_REMOTE_WAKEUP*/, USB_CONFIG_POWER_MA(0), //USB_CONFIG_POWER_MA(100), /* bMaxPower */ /* ************************* Interface 0, Alternate Setting 0, HID Class keyboard *********************************** */ 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 */ 0x04, //HID string /* iInterface */ /* HID Class Descriptor */ 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(0x0008), 0x05, /* 5ms */ /* bInterval */ /* Endpoint, HID Interrupt In */ USB_ENDPOINT_DESC_SIZE, /* bLength */ USB_ENDPOINT_DESCRIPTOR_TYPE, /* bDescriptorType */ USB_ENDPOINT_OUT(1), /* bEndpointAddress */ USB_ENDPOINT_TYPE_INTERRUPT, /* bmAttributes */ WBVAL(0x0008), /* wMaxPacketSize (max. datenpaketgröße: 1x 8 bytes -> entspricht unsigned char */ 0x05, /* 5ms */ /* bInterval */ /* second interface */ /* Interface 1, Alternate Setting 0, HID Class */ USB_INTERFACE_DESC_SIZE, /* bLength */ USB_INTERFACE_DESCRIPTOR_TYPE, /* bDescriptorType */ 0x01, /* bInterfaceNumber -> zweites interface im configuration descriptor */ 0x00, /* bAlternateSetting */ 0x01, /* bNumEndpoints -> wieviele endpoints besitzt dieses interface */ USB_DEVICE_CLASS_HUMAN_INTERFACE, /* bInterfaceClass */ HID_SUBCLASS_NONE, /* bInterfaceSubClass */ HID_PROTOCOL_NONE, /* bInterfaceProtocol */ 0x00, /* iInterface */ /* HID Class Descriptor */ 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_2), /* wDescriptorLength */ /* Endpoint, HID Interrupt In */ USB_ENDPOINT_DESC_SIZE, /* bLength */ USB_ENDPOINT_DESCRIPTOR_TYPE, /* bDescriptorType */ USB_ENDPOINT_IN(2), /* bEndpointAddress */ USB_ENDPOINT_TYPE_INTERRUPT, /* bmAttributes */ WBVAL(0x0020), /* wMaxPacketSize */ 0x0A, /* 8ms */ /* bInterval */ /* Terminator */ 0 /* bLength */ };
Another strange problem is that I couldn't create a device-handle with both settings (GENERIC_READ | GENERIC_WRITE). Only GENERIC_WRITE is working during my initialization in visual studio.
// /* Get Device Interface Details */ ok = SetupDiGetDeviceInterfaceDetail(DevInfo, &DevData, DevDetail, Length, NULL, NULL ); if (!ok) continue; /* Create File for Device Read/Write */ DevHandle = CreateFile(DevDetail->DevicePath, GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, (LPSECURITY_ATTRIBUTES)NULL, OPEN_EXISTING, 0, NULL ); if (DevHandle == INVALID_HANDLE_VALUE) continue;
best regards Jan
(here's my previous post about this topic: http://www.keil.com/forum/17238/)
I've found some interesting things: you can't access a system mouse / keyboard by WriteFile()... only feature reports will work.
Another solution is to add a second interface (third interfac in my case) to this device. Is the order of these interfaces important??? Are there any further things I have to look at?
Maybe someone can attach a small example to get access to my keyboard device by WriteFile()...