This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Small question about HID USB device

Hi

I'm using USB HID library to implement an small HID device.
I already have read this library and USB 1.1 specification, but I still have a small problem.
I still cannot understand relation between 3 sizes in descriptor:
1- EP0 packet size(that you can specify in usbcfg.h)
2- Endpoint's wMaxPacketSize
3- maximum size of reports

In my case, I need to transfer 128 bytes of data to and from device. Then I have defined my reports like this:
ReportSize(8)
ReportCount(128)
But I still cannot get how wMaxPacketSize and EP0 packet size are related to these values.
From some samples, I saw that people set wMaxPacketSize to 64. But how I should transfer my reports if wMaxPacketsize is 64? or are they related at all?

Regards

Parents
  • > I'm using USB HID sample that is distributed with RealView as my base code.

    Then, this thread will help you.
    http://www.keil.com/forum/docs/thread15613.asp

    The first packet is sent / received by polling (or "timer-ed" polling)
    Latter packet(s) are exchanged in the endpoint interrupt



    > 1- Using bigger wMaxPacketSize(up to 64) will increase performance,isn't it?

    Yes.
    For interrupt transfer, the transaction of each "packet" occurs at the rate of bInterval value on the endpoint descriptor (*1). When you divide the report into more packets under smaller wMaxPacketSize, it takes longer duration to finish the transfer of the entire report.



    > 2- When my device is going to send and receive data is it possible to use EP0 for sending control and data to host and another endpoint for receiving data from host(2 endpoints) or I should use EP0 as control and 2 other endpoint for sending or receiving data(3 endpoints used).

    It's the time to learn USB terms and concepts, before we enter to the explanation ;-)
    See these web pages for "Transfer - Transaction - Packet"

    USB Made Simple - Data Flow (Packets - Transaction - Transfer)
    www.usbmadesimple.co.uk/ums_3.htm

    Transfer - Transaction - Packet
    www.cygnal.org/.../001627.html

    Transfers over single endpoint don't overlap each other.
    But transfers over different endpoints, including EP0, are independent and their period may be overlapped each other, at the unit of transactions.

    While the report transfer of multiple transactions over EP1 is going, your device may receives a request (control transfer) over EP0. This principle is same for EP0. Control transfer consists of two or three stages, SETUP, optional DATA, and STATUS. SETUP and STATUS stage is carried by single transaction, respectively. DATA stage may extend to multiple transactions, depending on the length of the data to be carried.

    These transfers may be mixed up on the bi-directional USB cable, at the unit of transactions. Therefore, your firmware have to expect that transfers over different endpoints take place simultaneously.

    Even if transfer takes longer, your firmware doesn't always need to spend all time for it. The USB engine takes care of the communication in background. Just when transaction finishes, the engine notifies it to your firmware. And then, your firmware processes the received "packet" (*2) over OUT endpoint, or it puts another "packet" to the IN endpoint.



    > if both possible,which one is better?

    Transfer over interrupt IN or OUT endpoint is better, for frequent transfer exchange.
    The request over EP0 is too heavy process to do it regularly, though it's coding is easy ;-).



    (*1) actually, major OS (Windows, MacOSX and Linux) reduces the interval into power of 2, which is nearest to the bInterval value (up to 32 ms).
    ie. 1, 2, 4, 8, 16 or 32 ms

    (*2) This "packet" is not exact USB term :-) It means the payload of a transaction. But we often use it like this.

    Tsuneo

Reply
  • > I'm using USB HID sample that is distributed with RealView as my base code.

    Then, this thread will help you.
    http://www.keil.com/forum/docs/thread15613.asp

    The first packet is sent / received by polling (or "timer-ed" polling)
    Latter packet(s) are exchanged in the endpoint interrupt



    > 1- Using bigger wMaxPacketSize(up to 64) will increase performance,isn't it?

    Yes.
    For interrupt transfer, the transaction of each "packet" occurs at the rate of bInterval value on the endpoint descriptor (*1). When you divide the report into more packets under smaller wMaxPacketSize, it takes longer duration to finish the transfer of the entire report.



    > 2- When my device is going to send and receive data is it possible to use EP0 for sending control and data to host and another endpoint for receiving data from host(2 endpoints) or I should use EP0 as control and 2 other endpoint for sending or receiving data(3 endpoints used).

    It's the time to learn USB terms and concepts, before we enter to the explanation ;-)
    See these web pages for "Transfer - Transaction - Packet"

    USB Made Simple - Data Flow (Packets - Transaction - Transfer)
    www.usbmadesimple.co.uk/ums_3.htm

    Transfer - Transaction - Packet
    www.cygnal.org/.../001627.html

    Transfers over single endpoint don't overlap each other.
    But transfers over different endpoints, including EP0, are independent and their period may be overlapped each other, at the unit of transactions.

    While the report transfer of multiple transactions over EP1 is going, your device may receives a request (control transfer) over EP0. This principle is same for EP0. Control transfer consists of two or three stages, SETUP, optional DATA, and STATUS. SETUP and STATUS stage is carried by single transaction, respectively. DATA stage may extend to multiple transactions, depending on the length of the data to be carried.

    These transfers may be mixed up on the bi-directional USB cable, at the unit of transactions. Therefore, your firmware have to expect that transfers over different endpoints take place simultaneously.

    Even if transfer takes longer, your firmware doesn't always need to spend all time for it. The USB engine takes care of the communication in background. Just when transaction finishes, the engine notifies it to your firmware. And then, your firmware processes the received "packet" (*2) over OUT endpoint, or it puts another "packet" to the IN endpoint.



    > if both possible,which one is better?

    Transfer over interrupt IN or OUT endpoint is better, for frequent transfer exchange.
    The request over EP0 is too heavy process to do it regularly, though it's coding is easy ;-).



    (*1) actually, major OS (Windows, MacOSX and Linux) reduces the interval into power of 2, which is nearest to the bInterval value (up to 32 ms).
    ie. 1, 2, 4, 8, 16 or 32 ms

    (*2) This "packet" is not exact USB term :-) It means the payload of a transaction. But we often use it like this.

    Tsuneo

Children