I have been through the USB sample code downloaded from the keil website and i have a few questions regarding how the endpoints are used
1) they have used a macro in the code to convert from logical endpoint number to endpoint address
#define IDX2EP(idx) ((((idx)<<7)&0x80)|(((idx)>>1)&0xF))
on working this out , i got a pattern of 0x00,0x80,0x01,0x81...0x0f,0x8f. How was this macro derived? There is nothing in the user manual about the actual addresses of endpoints.
2) Each of these addresses correspond to a memory location of 1 byte . Where do the incoming and outgoing packets go? there are variable packet sizes possible so i was under the assumption that the individual buffers for endpoints are of variable size . Where are these individual buffers located?
3) The code enables endpoints at 0x05 and 0x82 which correspond to logical endpoints 5 and 10. Why not 4 and 5 both of which correspond to logical endpoint 3 (4 is out and 5 is in) ? Does it make a difference which endpoint is enabled as long as it if of the required type (bulk/interrupt etc)?
4) I came across this macro
#define LE_WORD(x) ((x)&0xFF),((x)>>8)
I am not able to understand what it does. what does the comma mean? It was used at multiple locations. to get product and vendor ids, to get max packet size for an endpoint and also to get bcd USB value in device descriptor
thanks for your time.
Ok, quick update. I managed to get my hands on the device and tried changing the endpoint address to 0x85 (logical 5, in) instead of 0x82 (2,in) . It did not work :(
> I managed to get my hands on the device and tried changing the endpoint address to 0x85 (logical 5, in) instead of 0x82 (2,in) . It did not work :(
Did you change the endpoint address in the subroutines, not just on the endpoint descriptor?
For example of USBMem
mscuser.h /* MSC In/Out Endpoint Address */ #define MSC_EP_IN 0x82 #define MSC_EP_OUT 0x02
For example of USBHID,
usbuser.c /* * USB Set Configuration Event Callback * Called automatically on USB Set Configuration Request */ #if USB_CONFIGURE_EVENT void USB_Configure_Event (void) { if (USB_Configuration) { /* Check if USB is configured */ GetInReport(); USB_WriteEP(0x81, &InReport, sizeof(InReport)); } } #endif /* * USB Endpoint 1 Event Callback * Called automatically on USB Endpoint 1 Event * Parameter: event */ void USB_EndPoint1 (DWORD event) { switch (event) { case USB_EVT_IN: GetInReport(); USB_WriteEP(0x81, &InReport, sizeof(InReport)); break; } }
Tsuneo