Hello, Im writing a usb communication tool on the LPC2368 for smartcard devices. I still don't get any communication between the host and the smartcard device for couple of weeks know. It seems like the program is be missing something and i dont know what.
Do you Know where I can find any smartcard USB application for arm7 microcontroller?
Can anybody help me on it? If necessary I will post the fully commented code that I have written.
Thanks in advance
Hello Tsuneo,
You were right, the main problem was the endpoint configuration.I have changed it to 0x81(Interrupt IN), 0x02(Bulk OUT) and 0x82(Bulk IN). besides that, I changed in usbcfg.h:
#define USB_EP_EVENT 0x0007
The Interrupt IN seems to work, since I can catch the IN message in the USB Sniffer but the BULK endpoints don't work!! The program does'nt reach the Bulk interrupt Events in usbuser.c!
void USB_EndPoint2 (DWORD event) { Biib(250); switch (event) { case USB_EVT_IN: USB_DataInStage2(); break; case USB_EVT_OUT: USB_DataOutStage2(); break; } } void USB_DataInStage2 (void) { DWORD cnt; if (EP2DataSnd.Count > USB_MAX_PACKET0) { cnt = USB_MAX_PACKET0; } else { cnt = EP2DataSnd.Count; } cnt = USB_WriteEP(0x82, EP2DataSnd.pData,cnt); EP2DataSnd.pData += cnt; EP2DataSnd.Count -= cnt; } /* Receive the datas from the Host (Bulk-Out Endpoint, 0x02) */ void USB_DataOutStage2 (void) { DWORD cnt; if(EP2DataRcv.Count==0) EP2DataRcv.pData = (unsigned char*)RXBuffer; cnt = USB_ReadEP(0x02, EP2DataRcv.pData); EP2DataRcv.pData += cnt; EP2DataRcv.Count += cnt; if(EP2DataRcv.Count >= RECEIVE_BUFFER_MAX) { EP2DataRcv.pData = (unsigned char*)RXBuffer; EP2DataRcv.Count = 0; } }
Do you have any idea about how to fix it?
Thanks a lot
> The Interrupt IN seems to work, since I can catch the IN message in the USB Sniffer but the BULK endpoints don't work!!
The interrupt IN EP is always polled by host to notify event from the device. When you write some data to the EP, it is always sent to host at the next interval.
Bulk IN/OUT EP are used to exchange command - response. Until host sends a command to the device over bulk OUT EP, no data (response) is transfered from bulk IN EP.
I recommend you to establish the descriptor first. Wrong parameters on the descriptor may block the operation over bulk OUT/IN. > Yes I have verified the reader is bus-powered!
I pointed out REMOTE WAKEUP bit, not the self/bus-powered bit. As you set remote-wakeup bit to 1, host will send Set_Feature( DEVICE_REMOTE_WAKEUP ) and Clear_Feature( DEVICE_REMOTE_WAKEUP ) requests. When your device fails to handle these requests, the connection is cut off.
If you don't use remote wakeup on your device, change bmAttributes field of the config descriptor from 0xA0 to 0x80
#define WBVAL1(x) ((x >> 24) & 0xFF), ((x >> 16) & 0xFF), ((x >> 8) & 0xFF), (x & 0xFF) //DWORD to 4 bytes
The endian is reversed. USB takes little endian - low-byte first Fix it, as follows,
#define WBVAL1(x) (x & 0xFF), ((x >> 8) & 0xFF), ((x >> 16) & 0xFF), ((x >> 24) & 0xFF) //DWORD to 4 bytes
The #defines for Smartcard Class Descriptor are messed up, anyway. As the start point, copy the values from the CCID example of ST micro. After realizing more about this class, modify it as you like.
Tsuneo