2009-12-16 01:06 PM
HID demo : can't increase packet size
2011-05-17 04:11 AM
Hi,
I am trying to modify the STM32 HID example to send more than two bytes of data at a time. My reports are set to a count of 8 with a size of 8 (8 bytes). I had thought that setting the endpoint descriptor packet sizes of CustomHID_ConfigDescriptor from: 0x02, /* wMaxPacketSize: 2 Bytes max */ to 0x08, /* wMaxPacketSize: 8 Bytes max */ and then calling the following: UserToPMABufferCopy(Send_Buffer, ENDP1_TXADDR, 8); SetEPTxCount(ENDP1, 8); SetEPTxValid(ENDP1); to trigger a input report would work... but sadly it does not. What I have found to work is that by leaving the packet size to 2 in the CustomHID_ConfigDescriptor and calling the following: UserToPMABufferCopy(Send_Buffer, ENDP1_TXADDR, 2); SetEPTxCount(ENDP1, 2); SetEPTxValid(ENDP1); sleep(50); four times does work... but this is less than ideal and requires application timing. Seemingly I cannot send more than 2 bytes at a time but cannot locate in the USB library where this is modified. Any help would be greatly appreciated.2011-05-17 04:11 AM
Hi,
Thanks for the reply. Things have moved on slightly and now I am trying to Output 64 bytes at a time. Unfortunately I already modified the endpoints in usb_prop.c (Not sure what I did was correct but from the end point 0 I thought it might) Forgive the fragmented code (taken from several files) but I have the following configured (based upon modifications of the HID example): Endpoint configuration: /* EP0 */ /* rx/tx buffer base address */ #define ENDP0_RXADDR (0x18) #define ENDP0_TXADDR (0x58) /* EP1 */ /* tx buffer base address */ #define ENDP1_TXADDR (0x100) #define ENDP1_RXADDR (0x140) //****** was previously 0x104 /* Initialize Endpoint 1 */ SetEPType(ENDP1, EP_INTERRUPT); SetEPTxAddr(ENDP1, ENDP1_TXADDR); SetEPRxAddr(ENDP1, ENDP1_RXADDR); SetEPTxCount(ENDP1, 64); //****** was previously 2 SetEPRxCount(ENDP1, 64); //****** was previously 2 SetEPRxStatus(ENDP1, EP_RX_VALID); SetEPTxStatus(ENDP1, EP_TX_NAK); Endpoaint callback routine void EP1_OUT_Callback(void) { BitAction Led_State; static u8 bytes_rx = 0; PMAToUserBufferCopy(Receive_Buffer, ENDP1_RXADDR, 64); //****** was previously 2 Where the Receive_Buffer is 256 bytes Config Descriptor: /* 27 */ 0x07, /* bLength: Endpoint Descriptor size */ USB_ENDPOINT_DESCRIPTOR_TYPE, /* bDescriptorType: */ 0x81, /* bEndpointAddress: Endpoint Address (IN) */ 0x03, /* bmAttributes: Interrupt endpoint */ 0x40, /* wMaxPacketSize: 2 Bytes max -****** was previously 2 */ 0x00, 0x20, /* bInterval: Polling Interval (32 ms) */ Report Descriptor: /* ADC IN */ 0x85, 0x07, /* REPORT_ID (7) */ 0x09, 0x07, /* USAGE (ADC IN) */ 0x15, 0x00, /* LOGICAL_MINIMUM (0) */ 0x26, 0xff, 0x00, /* LOGICAL_MAXIMUM (255) */ 0x75, 0x08, /* REPORT_SIZE (8) */ 0x95, 63, /* REPORT_COUNT (1) -****** was previously 2 */ 0x81, 0x82, /* INPUT (Data,Var,Abs,Vol) */ 0x85, 0x07, /* REPORT_ID (7) */ 0x09, 0x07, /* USAGE (ADC in) */ 0xb1, 0x82, /* FEATURE (Data,Var,Abs,Vol) */ /* 161 */ But when I send the 64 bytes via the PC aplication the EP1_OUT_Callback is called 8 seperate times with the buffer read only copying 8 bytes at a time. Is there anything else I should be doing? I have tried this on the HID Demonstartor PC app and also with the C# application on [ This message was edited by: lucauwf on 08-05-2009 18:04 ]2011-05-17 04:11 AM
Check the defines on usb_conf.h ( ENDP1_TXADDR ...)
The adresses need to match the size.2011-05-17 04:11 AM
I saw that too. In my source the address for the TX buffer is located at 0x100 and the RX at 0x104. Clearly the separation between these two, if you would like to transmit say 64 bytes, is not enough. I've changed this, but what if there is something else located close to the RX buffer say another buffer or variable at 0x106?
Anyways, I've changed this and still only managed to transmit 64 bytes from the device to the host. But no success from the host to the device. If I do try and transmit 64 bytes from the host to the device, I do receive an interrupt but from that point the code gets lost. This is an indication that there is a buffer overrun and that the USB ISR is writing data where it is not supposed to. I don't know why these guys did not allocate memory for the USB buffers. The compiler may just as well use that space without you knowing it. lucauwf, looking at your code, the descriptors look correct. So I think you have the same problem as me (The buffers). I think if one go and allocate memory for the RX (OUT) and TX (IN) buffers by defining them and their size it is possible to WIN!2011-05-17 04:11 AM
''I think if one go and allocate memory for the RX (OUT) and TX (IN) buffers
by defining them and their size it is possible to WIN!'' Judging from the Ref manual the buffers need to be located in this address area. Incidentally I reduced the TX buffer size and located the RX buffer accordingly (in case the buffers were too large) and still had the same issue. I believe something else may be the cause. :-[ Right now I'm just living with the 8 interrupt calls I'll try to have another look later.2011-05-17 04:11 AM
I would like to confirm that the combination of changes in this post DO allow you to transfer 64 bytes on both the IN and OUT endpoints.
Thanks to pappu_pandit's finding. Changes required to allow 64 byte transfers: 1.) Change Descriptors accordingly (ST's report descriptors are a mess!!) I use the following report desciptors: 0x85, IN_CONTROL, // Report ID (6) 0x95, IN_CONTROL_SIZE, // REPORT_COUNT (2) 0x75, 0x08, // REPORT_SIZE (8) 0x26, 0xff, 0x00, // LOGICAL_MAXIMUM (255) 0x15, 0x00, // LOGICAL_MINIMUM (0) 0x09, 0x01, // USAGE (Vendor Usage 1) 0x81, 0x02, // INPUT (Data,Var,Abs) /*21*/ 0x85, OUT_CONTROL, // Report ID (7) 0x95, OUT_CONTROL_SIZE, // REPORT_COUNT (2) 0x75, 0x08, // REPORT_SIZE (8) 0x26, 0xff, 0x00, // LOGICAL_MAXIMUM (255) 0x15, 0x00, // LOGICAL_MINIMUM (0) 0x09, 0x01, // USAGE (Vendor Usage 1) 0x91, 0x02, // OUTPUT (Data,Var,Abs) /*36*/ 0x85, IN_DATA, // Report ID (1) 0x95, IN_DATA_SIZE, // REPORT_COUNT (64) 0x75, 0x08, // REPORT_SIZE (8) 0x26, 0xff, 0x00, // LOGICAL_MAXIMUM (255) 0x15, 0x00, // LOGICAL_MINIMUM (0) 0x09, 0x01, // USAGE (Vendor Usage 1) 0x81, 0x02, // INPUT (Data,Var,Abs) /*51*/ 0x85, OUT_DATA, // Report ID (2) 0x95, OUT_DATA_SIZE, // REPORT_COUNT (64) 0x75, 0x08, // REPORT_SIZE (8) 0x26, 0xff, 0x00, // LOGICAL_MAXIMUM (255) 0x15, 0x00, // LOGICAL_MINIMUM (0) 0x09, 0x01, // USAGE (Vendor Usage 1) 0x91, 0x02, // OUTPUT (Data,Var,Abs) /*66*/ 0xC0 // end Application Collection /*67*/ 2.) Change both TX and RX cases UserToPMABufferCopy(Send_Buffer, ENDP1_TXADDR, 64); SetEPTxCount(ENDP1, 64); 3.) Change Ctrl_Info.Usb_wLength = 64 Enjoy! [ This message was edited by: mcp on 10-06-2009 14:31 ]2011-05-17 04:11 AM
Hi,
If you have done properly everythinjg for IN/OUT buffers then still you have to do this ... Here is how in a control transfer you can receive the data ... In file .... usb_prop.c when u parse the usb packet ... else if ((Type_Recipient == (CLASS_REQUEST | INTERFACE_RECIPIENT)) && RequestNo == SET_REPORT) { switch(pInformation->USBwValues.bw.bb0) { /* Check for report ID */ case USB_CONFIG_PKT: { CopyRoutine = CustomHID_GetData; break; } case USB_BRIGHTPKTOUT_NUM: { CopyRoutine = CustomHID_GetBrightness; break; } default: break; } } u8 *CustomHID_FirmwareRev(u16 Length) { if (Length == 0) { pInformation->Ctrl_Info.Usb_wLength = 64;//here u should give how many bytes to receive return NULL; } else { return (u8 *)(DataToHost); } }2011-05-17 04:11 AM
Hi,
I am trying the HID demo code for STM32F10X-128-Eval demo board. What I want to do is to increase the packet size for input/output transfer to 40 bytes. I modified my code but only the input packet size increased to 40 bytes, the output packet size always is 2 bytes. My code as following: In the usb_desc.c /* USB Standard Device Descriptor */ const u8 CustomHID_DeviceDescriptor[CUSTOMHID_SIZ_DEVICE_DESC] = { 0x12, /*bLength */ USB_DEVICE_DESCRIPTOR_TYPE, /*bDescriptorType*/ 0x00, /*bcdUSB */ 0x02, 0x00, /*bDeviceClass*/ 0x00, /*bDeviceSubClass*/ 0x00, /*bDeviceProtocol*/ 0x40, /*bMaxPacketSize40*/ 0x83, /*idVendor (0x0483)*/ 0x04, 0x50, /*idProduct = 0x5750*/ 0x57, 0x00, /*bcdDevice rel. 2.00*/ 0x02, 1, /*Index of string descriptor describing manufacturer */ 2, /*Index of string descriptor describing product*/ 3, /*Index of string descriptor describing the device serial number */ 0x01 /*bNumConfigurations*/ } ; /* CustomHID_DeviceDescriptor */ /* USB Configuration Descriptor */ /* All Descriptors (Configuration, Interface, Endpoint, Class, Vendor */ const u8 CustomHID_ConfigDescriptor[CUSTOMHID_SIZ_CONFIG_DESC] = { 0x09, /* bLength: Configuation Descriptor size */ USB_CONFIGURATION_DESCRIPTOR_TYPE, /* bDescriptorType: Configuration */ CUSTOMHID_SIZ_CONFIG_DESC, /* wTotalLength: Bytes returned */ 0x00, 0x01, /* bNumInterfaces: 1 interface */ 0x01, /* bConfigurationValue: Configuration value */ 0x00, /* iConfiguration: Index of string descriptor describing the configuration*/ 0xC0, /* bmAttributes: Bus powered */ 0x32, /* MaxPower 100 mA: this current is used for detecting Vbus */ /************** Descriptor of Custom HID 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, /* bNumEndpoints */ 0x03, /* bInterfaceClass: HID */ 0x00, /* bInterfaceSubClass : 1=BOOT, 0=no boot */ 0x00, /* nInterfaceProtocol : 0=none, 1=keyboard, 2=mouse */ 0, /* iInterface: Index of string descriptor */ /******************** Descriptor of Custom HID HID ********************/ /* 18 */ 0x09, /* bLength: HID Descriptor size */ HID_DESCRIPTOR_TYPE, /* bDescriptorType: HID */ 0x10, /* bcdHID: HID Class Spec release number */ 0x01, 0x00, /* bCountryCode: Hardware target country */ 0x01, /* bNumDescriptors: Number of HID class descriptors to follow */ 0x22, /* bDescriptorType */ CUSTOMHID_SIZ_REPORT_DESC,/* wItemLength: Total length of Report descriptor */ 0x00, /******************** Descriptor of Custom HID endpoints ******************/ /* 27 */ 0x07, /* bLength: Endpoint Descriptor size */ USB_ENDPOINT_DESCRIPTOR_TYPE, /* bDescriptorType: */ 0x81, /* bEndpointAddress: Endpoint Address (IN) */ 0x03, /* bmAttributes: Interrupt endpoint */ 0x28, /* wMaxPacketSize: 2 Bytes max */ 0x00, 0x20, /* bInterval: Polling Interval (32 ms) */ /* 34 */ 0x07, /* bLength: Endpoint Descriptor size */ USB_ENDPOINT_DESCRIPTOR_TYPE, /* bDescriptorType: */ /* Endpoint descriptor type */ 0x01, /* bEndpointAddress: */ /* Endpoint Address (OUT) */ 0x03, /* bmAttributes: Interrupt endpoint */ 0x28, /* wMaxPacketSize: 2 Bytes max */ 0x00, 0x20, /* bInterval: Polling Interval (20 ms) */ /* 41 */ } ; /* CustomHID_ConfigDescriptor */ const u8 CustomHID_ReportDescriptor[CUSTOMHID_SIZ_REPORT_DESC] = { 0x05, 0x8c, /* USAGE_PAGE (ST Page) */ 0x09, 0x01, /* USAGE (Demo Kit) */ 0xa1, 0x01, /* COLLECTION (Application) */ /* 6 */ /* Led 1 */ 0x85, 0x01, /* REPORT_ID (1) */ 0x09, 0x01, /* USAGE (LED 1) */ 0x15, 0x00, /* LOGICAL_MINIMUM (0) */ 0x25, 0x01, /* LOGICAL_MAXIMUM (1) */ 0x75, 0x08, /* REPORT_SIZE (8) */ 0x95, 0x01, /* REPORT_COUNT (1) */ 0xB1, 0x82, /* FEATURE (Data,Var,Abs,Vol) */ 0x85, 0x01, /* REPORT_ID (1) */ 0x09, 0x01, /* USAGE (LED 1) */ 0x91, 0x82, /* OUTPUT (Data,Var,Abs,Vol) */ /* 26 */ /* Led 2 */ 0x85, 0x02, /* REPORT_ID 2 */ 0x09, 0x02, /* USAGE (LED 2) */ 0x15, 0x00, /* LOGICAL_MINIMUM (0) */ 0x25, 0x01, /* LOGICAL_MAXIMUM (1) */ 0x75, 0x08, /* REPORT_SIZE (8) */ 0x95, 0x01, /* REPORT_COUNT (1) */ 0xB1, 0x82, /* FEATURE (Data,Var,Abs,Vol) */ 0x85, 0x02, /* REPORT_ID (2) */ 0x09, 0x02, /* USAGE (LED 2) */ 0x91, 0x82, /* OUTPUT (Data,Var,Abs,Vol) */ /* 46 */ /* Led 3 */ 0x85, 0x03, /* REPORT_ID (3) */ 0x09, 0x03, /* USAGE (LED 3) */ 0x15, 0x00, /* LOGICAL_MINIMUM (0) */ 0x25, 0x01, /* LOGICAL_MAXIMUM (1) */ 0x75, 0x08, /* REPORT_SIZE (8) */ 0x95, 0x01, /* REPORT_COUNT (1) */ 0xB1, 0x82, /* FEATURE (Data,Var,Abs,Vol) */ 0x85, 0x03, /* REPORT_ID (3) */ 0x09, 0x03, /* USAGE (LED 3) */ 0x91, 0x82, /* OUTPUT (Data,Var,Abs,Vol) */ /* 66 */ /* Led 4 */ 0x85, 0x04, /* REPORT_ID 4) */ 0x09, 0x04, /* USAGE (LED 4) */ 0x15, 0x00, /* LOGICAL_MINIMUM (0) */ 0x25, 0x01, /* LOGICAL_MAXIMUM (1) */ 0x75, 0x08, /* REPORT_SIZE (8) */ 0x95, 0x01, /* REPORT_COUNT (1) */ 0xB1, 0x82, /* FEATURE (Data,Var,Abs,Vol) */ 0x85, 0x04, /* REPORT_ID (4) */ 0x09, 0x04, /* USAGE (LED 4) */ 0x91, 0x82, /* OUTPUT (Data,Var,Abs,Vol) */ /* 86 */ /* ADC IN */ 0x85, 0x05, /* REPORT_ID (7) */ 0x09, 0x05, /* USAGE (ADC IN) */ 0x15, 0x00, /* LOGICAL_MINIMUM (0) */ 0x26, 0xff, 0x00, /* LOGICAL_MAXIMUM (255) */ 0x75, 0x08, /* REPORT_SIZE (8) */ 0x95, 39, 0x81, 0x82, /* INPUT (Data,Var,Abs,Vol) */ 0x85, 0x05, /* REPORT_ID (7) */ 0x09, 0x05, /* USAGE (ADC in) */ 0xb1, 0x82, /* FEATURE (Data,Var,Abs,Vol) */ /* 161 */ 0xc0 /* END_COLLECTION */ }; /* CustomHID_ReportDescriptor */ In the usb_conf.h -> change the address for Endpoint 1 #define ENDP1_TXADDR (0x100) #define ENDP1_RXADDR (0x150) In the usb_prop.c ->change the size for endpoint 1 to 40 bytes /* Initialize Endpoint 1 */ SetEPType(ENDP1, EP_INTERRUPT); SetEPTxAddr(ENDP1, ENDP1_TXADDR); SetEPRxAddr(ENDP1, ENDP1_RXADDR); SetEPTxCount(ENDP1, 40); SetEPRxCount(ENDP1, 40); SetEPRxStatus(ENDP1, EP_RX_VALID); SetEPTxStatus(ENDP1, EP_TX_NAK); Could somebody help? Thank you very much. MThe.2011-05-17 04:11 AM
Did you even bother to read and try the last post before yours?