|
From: 姜义 <jia...@gm...> - 2009-10-14 04:19:41
|
HI, I have encoutered a strange problem when I debug a my application using
libusb-win32. The application talk with fx2lp, send some commands to
endpoint 0x02, and read results from endpoint 0x86. The firmware is compiled
by SDCC.
The problem is that every command can be sent to fx2lp correctly, and the
results can be read from fx2lp. But each time the application read from
endpoint 0x86, it reads something unwanted. I have examined the data to be
sent to host in the fx2 firmware before arm endpoint 0x86.
But if I use Cypress's generic driver and CyConsole to debug the firmware,
everything is OK. CyConsole can read what fx2lp sent to it.
Also if I use endpoint 0x88 instead of 0x86, everything is OK. The
application (using libusb-win32 API) can read what fx2lp sent to it.
Could anyone please give me some suggestions ? Thanks in advance.
Here is the descriptor
.area DSCR (CODE)
.even ; descriptors must be 2-byte aligned for SUDPTR{H,L} to
work
_DeviceDscr:
.db DSCR_DEVICE_LEN ;; Descriptor length
.db DSCR_DEVICE ;; Decriptor type
.dw 0x0002 ;; Specification Version (BCD)
.db 0x00 ;; Device class
.db 0x00 ;; Device sub-class
.db 0x00 ;; Device sub-sub-class
.db 64 ;; Maximum packet size
.dw 0xB404 ;; Vendor ID
.dw 0x0410 ;; Product ID (Sample Device)
.dw 0x0000 ;; Product version ID
.db 1 ;; Manufacturer string index
.db 2 ;; Product string index
.db 0 ;; Serial number string index
.db 1 ;; Number of configurations
_DeviceQualDscr:
.db DSCR_DEVQUAL_LEN ;; Descriptor length
.db DSCR_DEVQUAL ;; Decriptor type
.dw 0x0002 ;; Specification Version (BCD)
.db 0 ;; Device class
.db 0 ;; Device sub-class
.db 0 ;; Device sub-sub-class
.db 64 ;; Maximum packet size
.db 1 ;; Number of configurations
.db 0 ;; Reserved
_HighSpeedConfigDscr:
.db DSCR_CONFIG_LEN ;; Descriptor length
.db DSCR_CONFIG ;; Descriptor type
;; Total Length (LSB)
.db (_HighSpeedConfigDscrEnd-_HighSpeedConfigDscr) % 256
;; Total Length (MSB)
.db (_HighSpeedConfigDscrEnd-_HighSpeedConfigDscr) / 256
.db 1 ;; Number of interfaces
.db 1 ;; Configuration number
.db 0 ;; Configuration string
.db 0b10100000 ;; Attributes (b7 - buspwr, b6 - selfpwr,
b5 - rwu)
.db 250 ;; Power requirement (div 2 ma)
;; Interface Descriptor
.db DSCR_INTRFC_LEN ;; Descriptor length
.db DSCR_INTRFC ;; Descriptor type
.db 0 ;; Zero-based index of this interface
.db 0 ;; Alternate setting
.db 4 ;; Number of end points
.db 0xff ;; Interface class
.db 0 ;; Interface sub class
.db 0 ;; Interface sub sub class
.db 0 ;; Interface descriptor string index
;; Endpoint Descriptor
.db DSCR_ENDPNT_LEN ;; Descriptor length
.db DSCR_ENDPNT ;; Descriptor type
.db 0x02 ;; Endpoint number, and direction
.db ET_BULK ;; Endpoint type
.db 0x00 ;; Maximun packet size (LSB)
.db 0x02 ;; Max packect size (MSB)
.db 0x00 ;; Polling interval
;; Endpoint Descriptor
.db DSCR_ENDPNT_LEN ;; Descriptor length
.db DSCR_ENDPNT ;; Descriptor type
.db 0x04 ;; Endpoint number, and direction
.db ET_BULK ;; Endpoint type
.db 0x00 ;; Maximun packet size (LSB)
.db 0x02 ;; Max packect size (MSB)
.db 0x00 ;; Polling interval
;; Endpoint Descriptor
.db DSCR_ENDPNT_LEN ;; Descriptor length
.db DSCR_ENDPNT ;; Descriptor type
.db 0x86 ;; Endpoint number, and direction
.db ET_BULK ;; Endpoint type
.db 0x00 ;; Maximun packet size (LSB)
.db 0x02 ;; Max packect size (MSB)
.db 0x00 ;; Polling interval
;; Endpoint Descriptor
.db DSCR_ENDPNT_LEN ;; Descriptor length
.db DSCR_ENDPNT ;; Descriptor type
.db 0x88 ;; Endpoint number, and direction
.db ET_BULK ;; Endpoint type
.db 0x00 ;; Maximun packet size (LSB)
.db 0x02 ;; Max packect size (MSB)
.db 0x00 ;; Polling interval
_HighSpeedConfigDscrEnd:
_FullSpeedConfigDscr:
.db DSCR_CONFIG_LEN ;; Descriptor length
.db DSCR_CONFIG ;; Descriptor type
;; Total Length (LSB)
.db (_FullSpeedConfigDscrEnd-_FullSpeedConfigDscr) % 256
;; Total Length (MSB)
.db (_FullSpeedConfigDscrEnd-_FullSpeedConfigDscr) / 256
.db 1 ;; Number of interfaces
.db 1 ;; Configuration number
.db 0 ;; Configuration string
.db 0b10000000 ;; Attributes (b7 - buspwr, b6 -
selfpwr, b5 - rwu)
.db 250 ;; Power requirement (div 2 ma)
;; Interface Descriptor
.db DSCR_INTRFC_LEN ;; Descriptor length
.db DSCR_INTRFC ;; Descriptor type
.db 0 ;; Zero-based index of this interface
.db 0 ;; Alternate setting
.db 4 ;; Number of end points
.db 0xff ;; Interface class
.db 0 ;; Interface sub class
.db 0 ;; Interface sub sub class
.db 0 ;; Interface descriptor string index
;; Endpoint Descriptor
.db DSCR_ENDPNT_LEN ;; Descriptor length
.db DSCR_ENDPNT ;; Descriptor type
.db 0x02 ;; Endpoint number, and direction
.db ET_BULK ;; Endpoint type
.db 0x40 ;; Maximun packet size (LSB)
.db 0x00 ;; Max packect size (MSB)
.db 0x00 ;; Polling interval
;; Endpoint Descriptor
.db DSCR_ENDPNT_LEN ;; Descriptor length
.db DSCR_ENDPNT ;; Descriptor type
.db 0x04 ;; Endpoint number, and direction
.db ET_BULK ;; Endpoint type
.db 0x40 ;; Maximun packet size (LSB)
.db 0x00 ;; Max packect size (MSB)
.db 0x00 ;; Polling interval
;; Endpoint Descriptor
.db DSCR_ENDPNT_LEN ;; Descriptor length
.db DSCR_ENDPNT ;; Descriptor type
.db 0x86 ;; Endpoint number, and direction
.db ET_BULK ;; Endpoint type
.db 0x40 ;; Maximun packet size (LSB)
.db 0x00 ;; Max packect size (MSB)
.db 0x00 ;; Polling interval
;; Endpoint Descriptor
.db DSCR_ENDPNT_LEN ;; Descriptor length
.db DSCR_ENDPNT ;; Descriptor type
.db 0x88 ;; Endpoint number, and direction
.db ET_BULK ;; Endpoint type
.db 0x40 ;; Maximun packet size (LSB)
.db 0x00 ;; Max packect size (MSB)
.db 0x00 ;; Polling interval
_FullSpeedConfigDscrEnd:
And here is the TD_Init:
void TD_Init(void) // Called once at startup
{
USE_USB_INTS();
// set the CPU clock to 48MHz
CPUCS = ((CPUCS & ~bmCLKSPD) | bmCLKSPD1) ;
// enable CLKOUT
CPUCS |= bmCLKOE;
IFCONFIG = 0xC0;
EP1OUTCFG = 0xA0;
SYNCDELAY;
EP1INCFG = 0xA0;
SYNCDELAY; //see TRM section 15.14
EP2CFG = 0xA2; //512 Bytes, double buffered, out
SYNCDELAY;
EP4CFG = 0xA0; //512 Bytes(fixed), double buffeeed(fixed), out
SYNCDELAY;
EP6CFG = 0xE2; //512 Bytes, double buffered, in
SYNCDELAY;
EP8CFG = 0xE0; //512 Bytes(fixed), double buffeeed(fixed), in
SYNCDELAY;
/* To re-arm the endpoint buffer for a future OUT transfer, the
* firmware simply writes any value to EP0BCL. */
// out endpoints do not come up armed. Arm EP1, EP2 and EP4 OUT
endpoints
EP1OUTBC = 0x40;
// arm the EP1 OUT endpoint by writing to the byte ep2_cnt
// since the defaults are double buffered we must write dummy byte
ep2_cnts twice
SYNCDELAY;
EP2BCL = 0x80; // arm EP2OUT by writing byte ep2_cnt w/skip.
SYNCDELAY;
EP2BCL = 0x80;
SYNCDELAY;
EP4BCL = 0x80; // arm EP4OUT by writing byte ep2_cnt w/skip.
SYNCDELAY;
EP4BCL = 0x80;
// Enable EP2, EP4 and EP1 OUT Endpoint interrupts
// EPIE |= bmBIT3 |bmBIT4 | bmBIT5;
// Enable EP6, EP8 and EP1 IN Endpoint interrupts
// EPIE |= bmBIT6 |bmBIT7 | bmBIT2;
EPIE = 0x00;
// enable dual autopointer feature
AUTOPTRSETUP = 0x07;
PORTACFG = 0x00;
PORTCCFG = 0x00;
PORTECFG = 0x00;
/* all port as output */
OEA = 0xFF;
OEB = 0xFF;
OED = 0x80;
}
And this is the code to send results back to host:
uint8_t fake_cmd(uint8_t bytes_len)
{
AUTOPTRH2 = MSB(&EP6FIFOBUF);
AUTOPTRL2 = LSB(&EP6FIFOBUF);
EAUTODDAT2 = 0;
EAUTODDAT2 = 1;
EAUTODDAT2 = 2;
EAUTODDAT2 = 3;
EAUTODDAT2 = 4;
EAUTODDAT2 = 5;
EAUTODDAT2 = 6;
EAUTODDAT2 = 7;
EP6BCH=0;
SYNCDELAY;
EP6BCL=8;
SYNCDELAY;
return 8;
}
--
--------------------
Best Regards
Jason
|