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.
Firstly, i would like to apologize because i have made some fundamental mistakes while asking my question . i discovered these errors only yesterday when i went through the user manual and referred to "usb complete'.
1) Thank you for your post Mr John . I was under the impression that the endpoint address was a memory location on the device and was the place where incoming packets are stored.
3) I was confused between logical and physical endpoints To clarify , (apart from control ep) The endpoints enabled in the code are -
addr | physical ep | ( logical ep , dir ) | type |
[ 0x05 | 10 | (5 ,out ) | bulk ] [ 0x82 | 5 | (2 , in ) | bulk ] [ 0x8A | 21 | (10 , in) | interrupt ]
suppose instead of logical ep (5,out) i i change the address in the descriptor to (2, out) will it make a difference? {i don't have access to the machine as of now which is why i cannot try it myself}
Also, since bulk and interrupt are handled the same way on the device, suppose i replace (10,in) with (8,in) type -bulk im guessing it wont make a difference. am i right?
Thank you.
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