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
In above post, the first packet is passed to IN EP using USB_WriteEP() in the OUT EP ISR. This scheme is fine when it doesn't take so much time to generate the input report. But if it takes so long, waiting in the ISR is not a good idea. In such case, USB_WriteEP() moves to elsewhere, at the place where the report generation finishes.
Suppose that the request orders 64 x 2 bytes samples from ADC, starting at the arrival of the request. - The parser on the OUT EP ISR starts ADC. The ISR just finishes. - In the ADC ISR, the report buffer is filled one sample by one. - In the ADC ISR, USB_WriteEP() is called for the first packet, when the 64th sample is filled to the buffer. - The second packet is sent in the IN EP ISR, like above.
In this way, you can move USB_WriteEP() to anywhere, on the place it fits best.
Similarly, USB_ReadEP() is placed on anywhere. Suppose that your firmware doesn't want to be disturbed by the next request, until current process finishes. - In the OUT EP ISR, just raise a flog, without calling USB_ReadEP(). - The flag is checked in timer-ed polling or main-loop polling, when current process finishes. In this polling routine, USB_ReadEP() is called to starts next process.
While the OUT endpoint is occupied by the last packet, the USB engine returns NAK (not ready) to the host. Host waits until the endpoint becomes empty (NAK flow control). No packet is lost. When you move USB_ReadEP() and/or USB_WriteEP() out of the endpoint ISR, you have to care of atomic access of these functions, so as not to re-enter to these routines each other. USB_ReadEP() and USB_WriteEP() are used in the several part of USB ISR in the USB stack.
To use these functions in an ISR of ADC, timer, etc., the interrupt priority of these ISRs should be same as those of USB interrupt. To use them on main-loop task, SWI is applied for these functions. For SWI, see the discussion on this topic, from the post on 26-Sep-2009 03:46 GMT http://www.keil.com/forum/docs/thread15613.asp
Tsuneo