Hi Guys, I sit for days on my USB transfer. I work with a STM32F103C8 microcontroller. I want to build a transmission with 2 endpoints to transfer my Data from the (GUI) Host. My problem are the endpoints. I can not get data from the endpoint. It is the KEIL USB Library...
Here some code snippets:
//********************************Defines**************************************** #define USB_POWER 0 #define USB_IF_NUM 1 #define USB_EP_NUM 2 #define USB_MAX_PACKET0 8 #define USB_DBL_BUF_EP 0x0040 #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_CONFIGURE_EVENT 0 #define USB_INTERFACE_EVENT 1 #define USB_FEATURE_EVENT 0 #define USB_CLASS 1 #define USB_HID 1 #define USB_HID_IF_NUM 0 #define USB_MSC 0 #define USB_MSC_IF_NUM 0 #define USB_AUDIO 0 #define USB_ADC_CIF_NUM 0 #define USB_ADC_SIF1_NUM 1 #define USB_ADC_SIF2_NUM 2 #define USB_CDC 0 #define USB_CDC_CIF_NUM 0 #define USB_CDC_DIF_NUM 1 #define USB_CDC_BUFSIZE 64 //***************************My Buffer Variables************************************ uint8_t InReport[64]; uint8_t OutReport[64]; I get no call interrupt at this point void USB_EndPoint1 (U32 event) { GPIOB->BSRR |=(1<<1); //Set PB1 only for debuging with Osziloscope switch (event) { case USB_EVT_IN: GetInReport(); USB_WriteEP(0x81, InReport, sizeof(InReport)); break; case USB_EVT_OUT: USB_ReadEP(0x01, OutReport); SetOutReport(); break; } GPIOB->BSRR |=(1<<17); //Clear PB1 only for debuging with Osziloscope } const U8 HID_ReportDescriptor[] = { HID_UsagePageVendor( 0x00 ), HID_Usage ( 0x01 ), HID_Collection ( HID_Application ), HID_LogicalMin ( 0 ), //value range: 0 - 0xFF HID_LogicalMaxS ( 0xFF ), HID_ReportSize ( 8 ), // 8 bits HID_ReportCount ( 0x40 ), HID_Usage ( 0x01 ), HID_Input ( HID_Data | HID_Variable | HID_Absolute ), HID_ReportCount ( 0x40 ), HID_Usage ( 0x01 ), HID_Output ( HID_Data | HID_Variable | HID_Absolute ), HID_ReportCount ( 0x40 ), HID_Usage ( 0x01 ), HID_Feature ( HID_Data | HID_Variable | HID_Absolute ), HID_EndCollection, }; /* USB Standard Device Descriptor */ const U8 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(0x1C01), /* idProduct */ WBVAL(0x0100), /* 1.00 */ /* bcdDevice */ 0x01, /* iManufacturer */ 0x02, /* iProduct */ 0x03, /* iSerialNumber */ 0x01 /* bNumConfigurations: one possible configuration*/ }; const U8 USB_ConfigDescriptor[] = { //Configuration 1 USB_CONFIGUARTION_DESC_SIZE, /* bLength */ USB_CONFIGURATION_DESCRIPTOR_TYPE, /* bDescriptorType */ WBVAL(USB_CONFIGUARTION_DESC_SIZE + HID_DESC_SIZE + USB_INTERFACE_DESC_SIZE + USB_ENDPOINT_DESC_SIZE + USB_ENDPOINT_DESC_SIZE), // wTotalLength 0x01, /* bNumInterfaces */ 0x01, /* bConfigurationValue: 0x01 is used to select this configuration */ 0x00, /* iConfiguration: no string to describe this configuration */ USB_CONFIG_BUS_POWERED, /* bmAttributes */ USB_CONFIG_POWER_MA(100), /* bMaxPower, device power consumption is 100 mA */ // 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 */ 0, /* bInterfaceSubClass */ 0, /* bInterfaceProtocol */ 0, /*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 */ 0x40,0x00, /* wMaxPacketSize */ 0x01, /* 32ms */ /* bInterval */ //0x20 //Endpoint, HID Interrupt out USB_ENDPOINT_DESC_SIZE, /* bLength */ USB_ENDPOINT_DESCRIPTOR_TYPE, /* bDescriptorType */ USB_ENDPOINT_OUT(1), /* bEndpointAddress */ USB_ENDPOINT_TYPE_INTERRUPT , /* bmAttributes */ 0x40,0x00, /* wMaxPacketSize */ 0x01, /* 32ms */ /* bInterval *///0x20 /* Terminator */ 0 /* bLength */ };
//************************************************************************************ The USB Sniffer shows the correct port setting. But why the endpoint interrupt is not executed? I see data packets (every 1ms) at the USB data pin on the oscilloscope. But unfortunately, the device receives nothing... Who can help me in the initialization? I have read many Theards, but it does not work ..
Best Regards Peter
next
BOOL HID_GetReport (void) { /* ReportID = SetupPacket.wValue.WB.L; */ switch (SetupPacket.wValue.WB.H) { case HID_REPORT_INPUT: //GetInReport(); //EP0Buf[0] = InReport; //I Removed EP0 transmisson break; case HID_REPORT_OUTPUT: return (__FALSE); /* Not Supported */ case HID_REPORT_FEATURE: /* EP0Buf[] = ...; */ /* break; */ return (__FALSE); /* Not Supported */ } return (__TRUE); } BOOL HID_SetReport (void) { /* ReportID = SetupPacket.wValue.WB.L; */ switch (SetupPacket.wValue.WB.H) { case HID_REPORT_INPUT: return (__FALSE); /* Not Supported */ case HID_REPORT_OUTPUT: //OutReport = EP0Buf[0]; //I Removed EP0 transmisson //SetOutReport(); break; case HID_REPORT_FEATURE: return (__FALSE); /* Not Supported */ } return (__TRUE); } //*********************************USBSniffer Report*************************************** port 2 : USB-HID (Human Interface Device) Parameter Value Hardware ID USB\Vid_c251&Pid_1c01&Rev_0100 Setup Class HIDClass Class GUID {745A17A0-74D3-11D0-B6FE-00A0C90F57DA} PDO Name \Device\USBPDO-8 Service Name HidUsb Parameter Value Connection Information ConnectionIndex 0x2 CurrentConfigurationValue 0x1 Speed 0x1 (UsbFullSpeed) DeviceIsHub FALSE DeviceAddress 0x1 NumberOfOpenPipes 0x2 ConnectionStatus DeviceConnected Pipe #0 Endpoint Descriptor bLength 0x7 bEndpointAddress 0x81 [IN] bmAttributes 0x3 (USB_ENDPOINT_TYPE_INTERRUPT) wMaxPacketSize 0x40 bInterval 0x1 Pipe #1 Endpoint Descriptor bLength 0x7 bEndpointAddress 0x1 [OUT] bmAttributes 0x3 (USB_ENDPOINT_TYPE_INTERRUPT) wMaxPacketSize 0x40 bInterval 0x1 Device Descriptor bLength 0x12 bcdUSB 0x0200 (USB 2.0) bDeviceClass 0x0 bDeviceSubClass 0x0 bDeviceProtocol 0x0 bMaxPacketSize0 0x8 idVendor 0xC251 (Keil Software, Inc.) idProduct 0x1C01 bcdDevice 0x100 iManufacturer 0x1 (0x409: Keil Software) iProduct 0x2 (0x409: Keil MCBSTM32 HID) iSerialNumber 0x3 (0x409: 0001A0000000) bNumConfigurations 0x1 Parameter Value Configuration Descriptor bLength 0x9 bDescriptorType USB_CONFIGURATION_DESCRIPTOR_TYPE wTotalLength 0x29 bNumInterfaces 0x1 iConfiguration 0x0 bmAttributes 0x80 ( Bus_Powered ) MaxPower 0x32 Interface Descriptor bLength 0x9 bInterfaceNumber 0x0 bAlternateSetting 0x0 bNumEndpoints 0x2 bInterfaceClass 0x3 (Human Interface Device) bInterfaceSubClass 0x0 (No Subclass) bInterfaceProtocol 0x0 (None) iInterface 0x0 Endpoint Descriptor bLength 0x7 bEndpointAddress 0x81 [IN] bmAttributes 0x3 (USB_ENDPOINT_TYPE_INTERRUPT) wMaxPacketSize 0x40 bInterval 0x1 Endpoint Descriptor bLength 0x7 bEndpointAddress 0x1 [OUT] bmAttributes 0x3 (USB_ENDPOINT_TYPE_INTERRUPT) wMaxPacketSize 0x40 bInterval 0x1