Author Topic: usbhid in lpc1769 requires some delay between the 2 64 bytes interrupt transfers  (Read 20058 times)

sudep

  • Member
  • ***
  • Posts: 8
hello.

i am using the lpc1769 microcontroller running at 120mhz to use it as an hid device with INTERRUPT end point for IN and OUT POINTS with 1msec and 64bytes transfer

, BUT i am facing one problem there i am unable to send multiple 64bytes frames at a time, i need to give some delay in between every frame

transmission this will affect the purpose of my project as i need to collect adc data with specified samples and frequency but for every time i need to

change the delay values for different sampling rate and samples number

Do any body know any clue about delay as the device should send all the data work without delay i have asked the same in the lpc forum but they are not
interested to answer this type of questions  at all.  :(

ex:
for(i=0;i<5;i++0)
{
usbwriteEP(0x81,64);
Delay(15000);//why i need this
Delay(16000);
}

regards

Jan Axelson

  • Administrator
  • Frequent Contributor
  • *****
  • Posts: 3033
    • Lakeview Research
An endpoint can send data only on receiving an IN token packet from the host.

In the endpoint descriptor, set bInterval to the minimum allowed value: 10 for low speed and 1 for full or high speed.

Each call to ReadFile or FileStream read adds overhead, so send the data in fewer, longer reports (edit the report descriptor) and/or increase the ReadFile/FileStream buffer size to enable reading multiple reports at once. (ReadFile/Filestream read return as many reports as are available, up to the passed buffer size.)

Windows and other PC OSes aren't real-time. Do any real-time processing in the device, then transfer the data to the PC.

sudep

  • Member
  • ***
  • Posts: 8
hello thanks for your reply

on the PC side i am using the labview code to open the usb device and get the data from my controller

1.both the endpoints are operating on interrupt transfer so i am not sending any IN request from my labview code as the code will be polling the
   the host to get the data if the data sent from the device.

2. in my labview code i can not increase the  buffer size of 64bytes to more  as i need to get the bytes convert that to 16 bit and represent on the graph So in that sense

sudep

  • Member
  • ***
  • Posts: 8
hello thanks for your reply
this is some how a lengthy reply by me but i request you to go through it with slowly

on the PC side i am using the labview code to open the usb device and get the data from my controller

1.both the endpoints are operating on interrupt transfer so i am not sending any IN request from my labview code as the code will be polling the
   the host to get the data if the data sent from the device.

2. in my labview code i can not increase the  buffer size of 64bytes to more  as i need to get the bytes convert that to 16 bit and represent on the graph So   
    in that sense if i increase buffer size the zero will be ploting on the graph .

3. on my controller side programming i am using interrupt transfers for the IN and OUT EP's with 1msec interval with report size of 8 bits and reports length of   
    64 bytes So if i have to send the 200 bytes of data then i will iterate for 2 or 3 times  in the chunks of 64 bytes only So there i am getting the problem as
    without delay all the data is not going out means for 3 iterations of 64 bytes (total 3 x 64 =  192) bytes on my pc side i will get around  80 to 130 bytes
    only.
4. i have tried with giving some delay between the 2 successive data read on my PC labview coding also but that also not working to get full data without
   the mis.
5.   On my controller side i will get all the data out only in the debug mode running with the breakpoints only not in release mode.

So the overview of all this tests is the data transmission requires some delay but i dont want that and also the program flow should not deserve that..

regards :-\
 

Jan Axelson

  • Administrator
  • Frequent Contributor
  • *****
  • Posts: 3033
    • Lakeview Research
Is the problem:

the host application isn't seeing some of the data the device sends

or

the host application is getting all of the data but too slowly?

sudep

  • Member
  • ***
  • Posts: 8
hi
i am unable to figure out the exact problem on the host side but may be host is slow i am attaching the descriptors for controller device plz go through that if possible in the meanwhile i will increase the data buffer size on my host appln and will check whether that will solves the problem

#define HID_INPUT_REPORT_BYTES        64 //64           /* size of report in Bytes */
#define HID_OUTPUT_REPORT_BYTES     20 //64           /* size of report in Bytes */
#define HID_FEATURE_REPORT_BYTES    64 //64 //64           /* size of report in Bytes */

#define EP1 1
#define EP4 4
#define EP  EP1

#if EP == EP1
#define HID_EP_DATA_IN        0x81   //0x84// 0x81
#define HID_EP_DATA_OUT      0x01  //0x04//0X01
#endif


const uint8_t 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_ReportSize   ( 16                        ), // 16 bits

    HID_ReportCount  ( HID_INPUT_REPORT_BYTES    ),
    HID_Usage        ( 0x01                      ),
    HID_Input        ( HID_Data | HID_Variable | HID_Absolute ),

    HID_ReportCount  ( HID_OUTPUT_REPORT_BYTES   ),
    HID_Usage        ( 0x01                      ),
    HID_Output       ( HID_Data | HID_Variable | HID_Absolute ),

    HID_ReportCount  ( HID_FEATURE_REPORT_BYTES  ),
    HID_Usage        ( 0x01                      ),
    HID_Feature      ( HID_Data | HID_Variable | HID_Absolute ),

    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 */
  //USB_STRING_DESCRIPTOR_TYPE,
  WBVAL(0x0200), /* 2.00 */          /* bcdUSB */
  0x00,                              /* bDeviceClass */
  0x00,                              /* bDeviceSubClass */
  0x00,                              /* bDeviceProtocol */
  USB_MAX_PACKET0,                   /* bMaxPacketSize0 */
  WBVAL(0x1FC9),                     /* idVendor */
  WBVAL(0x8002),                     /* idProduct */
  //WBVAL(0x0001), /* 0.01 */        /* bcdDevice */
  WBVAL(0x0100), /* 0.01 */          /* bcdDevice */
  0x01,                              /* iManufacturer */
  0x02,                              /* iProduct */
  0x03,                              /* iSerialNumber */
  //0x00,                            /* iSerialNumber */
  0x01                               /* bNumConfigurations: one possible configuration*/
};

/* USB Configuration Descriptor */
/*   All Descriptors (Configuration, Interface, Endpoint, Class, Vendor) */
const uint8_t USB_ConfigDescriptor[] =
{
      /* Configuration 1 */
  USB_CONFIGUARTION_DESC_SIZE,       /* bLength              */
  USB_CONFIGURATION_DESCRIPTOR_TYPE, /* bDescriptorType      */ /* wTotalLength */
  WBVAL((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_SELF_POWERED,
  USB_CONFIG_POWER_MA(500),          /* 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      */ //ORIGINL
  //USB_DEVICE_CLASS_TMC,            /* bInterfaceClass      */ //SUDEEP
  HID_SUBCLASS_NONE,                 /* bInterfaceSubClass   */ //ORIGINL
  //0X03,                            /* bInterfaceSubClass   */ //SUDEEP
  HID_PROTOCOL_NONE,                 /* bInterfaceProtocol   */
  //0X00,                            /* iInterface           */
  0x04,                              /* iInterface           */

/* HID Class Descriptor */
/* HID_DESC_OFFSET = 0x0012 */
  HID_DESC_SIZE,                     /* bLength           */
  HID_HID_DESCRIPTOR_TYPE,           /* bDescriptorType   */
  //WBVAL(0x0110), /* 1.10 */        /* bcdHID            */
  WBVAL(0x0100), /* 1.10 */          /* 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_IN(EP),               /* bEndpointAddress */
  USB_ENDPOINT_TYPE_INTERRUPT,       /* bmAttributes     */
 // USB_ENDPOINT_TYPE_BULK,
  //WBVAL(0x40),                     /* wMaxPacketSize   */
   WBVAL(HID_INPUT_REPORT_BYTES),
   0x1,          /* 32ms */          /* bInterval        */

  /* Endpoint, HID Interrupt Out */
    USB_ENDPOINT_DESC_SIZE,          /* bLength          */
    USB_ENDPOINT_DESCRIPTOR_TYPE,    /* bDescriptorType  */
   // USB_ENDPOINT_OUT(1),           /* bEndpointAddress */
    USB_ENDPOINT_OUT(EP),            /* bEndpointAddress */
    USB_ENDPOINT_TYPE_INTERRUPT,     /* bmAttributes     */
   // USB_ENDPOINT_TYPE_BULK,
   // WBVAL(0x0040),                 /* wMaxPacketSize   */
    WBVAL(HID_OUTPUT_REPORT_BYTES),
    0x1,          /* 32ms */         /* bInterval        */
   /* Terminator */
    0                                /* bLength          */
};
/*
// USB String Descriptor (optional)
const uint8_t USB_StringDescriptor[] = {
// Index 0x00: LANGID Codes
  0x04,                              // bLength
  USB_STRING_DESCRIPTOR_TYPE,        // bDescriptorType
  WBVAL(0x0409), // US English      // wLANGID
// Index 0x01: Manufacturer
  (13*2 + 2),                        // bLength (13 Char + Type + lenght)
  USB_STRING_DESCRIPTOR_TYPE,        // bDescriptorType
  'N',0,
  'X',0,
  'P',0,
  ' ',0,
  'S',0,
  'E',0,
  'M',0,
  'I',0,
  'C',0,
  'O',0,
  'N',0,
  'D',0,
  ' ',0,
// Index 0x02: Product
  (18*2 + 2),                        // bLength ( 16 Char + Type + lenght)
  USB_STRING_DESCRIPTOR_TYPE,        // bDescriptorType
  'S',0,
  'M',0,
  ' ',0,
  'U',0,
  'S',0,
  'B',0,
  ' ',0,
  'D',0,
  'a',0,
  'q',0,
 '\n',0,
  'v',0,
  '1',0,
  '.',0,
  '0',0,
  '1',0,
  '3',0,
  ' ',0,

// Index 0x03: Serial Number
  (12*2 + 2),                        // bLength (12 Char + Type + lenght)
  USB_STRING_DESCRIPTOR_TYPE,        // bDescriptorType
  'D',0,
  'E',0,
  'M',0,
  'O',0,
  '0',0,
  '0',0,
  '0',0,
  '0',0,
  '0',0,
  '0',0,
  '0',0,
  '0',0,
// Index 0x04: Interface 0, Alternate Setting 0
  ( 3*2 + 2),                        // bLength (6 Char + Type + lenght)
  USB_STRING_DESCRIPTOR_TYPE,        // bDescriptorType
  'H',0,
  'I',0,
  'D',0,
};
*/

// USB String Descriptor (optional)
const uint8_t USB_StringDescriptor[] = {
// Index 0x00: LANGID Codes
  0x04,                               // bLength
  USB_STRING_DESCRIPTOR_TYPE,        // bDescriptorType
  WBVAL(0x0409), // US English       // wLANGID
// Index 0x01: Manufacturer
  (13*2 + 2),                        // bLength (13 Char + Type + lenght)
  USB_STRING_DESCRIPTOR_TYPE,        // bDescriptorType
  'S',0,
  'M',0,
  ' ',0,
  'P',0,
  'V',0,
  'T',0,
  ' ',0,
  'L',0,
  'T',0,
  'D',0,
  ' ',0,
  ' ',0,
  ' ',0,
// Index 0x02: Product
  (6*2 + 2),                        // bLength ( 16 Char + Type + lenght)
  USB_STRING_DESCRIPTOR_TYPE,        // bDescriptorType
  'S',0,
  'M',0,
  'D',0,
  'a',0,
  'q',0,
  '8',0,
  // Index 0x03: Serial Number
  (4*2 + 2),                        // bLength (12 Char + Type + lenght)
  USB_STRING_DESCRIPTOR_TYPE,        // bDescriptorType
  '1',0,
  'N',0,
  '1',0,
  '6',0,
  // Index 0x04: Interface 0, Alternate Setting 0
  ( 3*2 + 2),                        // bLength (6 Char + Type + lenght)
  USB_STRING_DESCRIPTOR_TYPE,        // bDescriptorType
  'H',0,
  'I',0,
  'D',0,
};
  :)

sudep

  • Member
  • ***
  • Posts: 8
hello do you people have any solution for the problems i am facing int he usb transmission

Jan Axelson

  • Administrator
  • Frequent Contributor
  • *****
  • Posts: 3033
    • Lakeview Research
The reason why I asked if you are seeing missing reports or if you just have lower throughput with all data present is that these are different problems that may have different causes.

To prevent missing reports:

Use HidD_SetNumInputBuffers to increase the buffer size.
Have the application read reports more often.
Use longer reports so you don't have to do a read operation as often.
Increase the size of the buffer in the call to ReadFile or FileStream reads. (The reads return as many reports as are available and will fit in the passed buffer.)
Use a larger bInterval in the endpoint descriptor so reports arrive less often.

For faster throughput:
Have the application read reports more often.
Use longer reports. (A single call to read a 256-byte report is faster than four calls to read a 64-byte report.)
Increase the size of the buffer in the call to ReadFile or FileStream reads.
Use a smaller bInterval in the endpoint descriptor so reports arrive more often.

Because you are using Labview, some or all of these options might not be available.

Also, be sure you understand:

The device endpoint, even for interrupt transfers, sends data only on receiving an IN token packet from the host. The HID driver sends periodic IN tokens to retrieve data and stores the data in a buffer at the driver. ReadFile and FileStream reads (or whatever API you use in LabView) do not cause any USB traffic, they just read data already retrieved and in the buffer.


sudep

  • Member
  • ***
  • Posts: 8
hi

i will look into the missing or slow rate usb problems later

but for your last suggestion ,   from the labview code i am not getting any IN token packet from the host as i can clearly see on the USBLYZER

while checking the firmware code on my controller when i cal the fucntion USBWriteEp(epnum,buffer,datalength(max 64)) it will just sending the data  as my

controller code is not waiting for an IN token to come.... whether that's a problem

Jan Axelson

  • Administrator
  • Frequent Contributor
  • *****
  • Posts: 3033
    • Lakeview Research
Software analyzers such as USBlyzer doesn't show low-level bus traffic such as IN token packets. A software analyzer can only show things at the driver level on the host computer.

sudep

  • Member
  • ***
  • Posts: 8
hi jan

i am unable to sync the communication between the mcu and the usb .

i will switch to high speed option on my mcu

do you know any idea of how to write descriptors and coding for the high speed usb transfer on the device

regards
 :(

Jan Axelson

  • Administrator
  • Frequent Contributor
  • *****
  • Posts: 3033
    • Lakeview Research
High speed requires Device Qualifier and Other Speed Configuration descriptors. MaxPacketSize for the default interface for HID remains 64. The code to transfer data should require no changes.

sudep

  • Member
  • ***
  • Posts: 8
hello if i add the Device Qualifier and Other Speed Configuration descriptors into my code whether i need to change in the usbcore program or not 

regards ???