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
Thanks for quick and great replies. :)
In above code, USB_EndPoint2() is called twice Why it is called twice? Shouldn't it get called only once when I receive data on EP2?
Is there any flag that shows a buffer in an IN endpoint has been sent to host(and host is received it)?
And regarding processing time, device has a really wide range of processing time, from a few milliseconds to even 1.5 mins, But I don't think it really makes problems for my application side, if this delay won't make any problem in MCU itself(for example these process delays will happen in ISR because of library code).
>> In above code, USB_EndPoint2() is called twice > Why it is called twice? > Shouldn't it get called only once when I receive data on EP2?
Auu, my bad ... It's EP1 (IN endpoint), instead of EP2 (OUT endpoint) The OUT EP ISR is called once, when the OUT endpoint receives the request from host. The IN EP ISR is called twice, when the IN endpoint sends each packet to the host. > Is there any flag that shows a buffer in an IN endpoint has been sent to host(and host is received it)?
These Bits on USB engine registers are available for polling, when interrupt is not enabled on the endpoint.
UDP_ISR (Interrupt Status Register) - EPxINT bit (IN and OUT endpoint) or UDP_CSRx (Endpoint Control and Status Register) - TXCOMP (IN endpoint), RX_DATA_BK0 (OUT endpoint)
Tsuneo
Hi Tsuneo
Thanks for your great replies. :) I worked on my code for a lot and now I have no problem on sending and receiving small buffers(less than wMaxPacketSize). But I should say that I were not able to send any report that is bigger than wMaxPacketSize. Assume that I have set my INPUT and OUTPUT report size to 8 and report count to 128(so buffer is 128 bytes) and my wMaxPacketSize is 64. When I try to send data from host to device,I need to send them in 128 byte buffers(and trying to send less than this much generates errors), but I only receive first 64 bytes in my device. Similarly, when I need to read 128 bytes from device(less than that much is not allowed), I can only send first 64 bytes from device to endpoint, then because host side has not received enough data, it goes into deadlock for receiving reminder of data that never happens. Any idea how I can repair this problem? In addition, the is a flag for INPUT and OUTPUT reports called 'Byte Stream'. is it good to set this flag if all my report data is byte aligned?
I should say That was able to send 128 Byte buffer (bigger than wMaxPacketSize) from host to device on my OUTPUT report, so no problem for this part anymore... :) But my problem for INPUT report persists, and I cannot send data to host... :(
> When I try to send data from host to device,I need to send them in 128 byte buffers
Are you working on Windows? Then, the buffer size to pass to ReadFile()/Writefile() is 129 bytes (1 + 128). Report ID (1 byte) precedes before the 128 bytes body.
When the report descriptor on the device doesn't have any report ID, - Windows app: default report ID (0) precedes. - HID device: no report ID is attached.
Yes,I'm working on windows. And as I told in 2nd post, I have finally successfully transfered 128 bytes of data from host to device with no problem. But sending 128 bytes of data from device to host is still a problem that I cannot solve. My windows application needs to use a ReadFile with a 129 byte buffer length for getting data from device, but I cannot find a way to send a 128 byte report from device to host when wMaxPacketSize is 64.
> but I cannot find a way to send a 128 byte report from device to host when wMaxPacketSize is 64.
**sigh** I've already explained about the way in above post. See above code.
128 bytes input report is split into two 64 bytes packets. 1) The first packet is passed to the IN endpoint outside of the IN EP ISR. Usually, at the place where the input report is made up.
2) When the USB engine finishes to send the first packet, IN EP interrupt occurs. Then, the second packet is passed to the IN EP inside of the IN EP ISR.
3) When the USB engine finishes the second packet, another interrupt occurs, the IN EP ISR is called again. But this time, there is nothing to send. Therefore, a flag (or a counter) is required to do control this behavior.
This flag is set when the first packet is sent in 1) stage The IN EP ISR sees this flag. When it is set, it drops the flag and does 2) stage.
It seems that I forgot to say, but I have already tried this way of sending 128 Bytes of data to host by splitting it into two 64 bytes part and it didn't work.
How didn't it work?
Place a break point in the USB_EndPoint2() Is this ISR visited?
Aha, mistaken again.
Place a break point in the USB_EndPoint1() (IN EP) Is this ISR visited?