Hi, Mark,
Actually I am not a big fan of Freescale USB stack. I was struggling with it for several months.
I know the timeout issue for USB send/receive routines. To be frank, I have no idea why it takes so long. The constant for _usb_khci_task() is clueless, at least I don't wanna to touch the code.
I used to worry about if USB receiver is kept waiting for bytes which will not come in the same transfer until it get timeout. However, I found we can avoid that since our firmware acts as USB host, and ADB transfer always defines data length in its message body, which can be used as parameter for next usb tranfer IN.
In fact, when host sends out ADB message, it always expects to receive an ADB message (length as 24). After receiving an ADB message (A_CNXN/A_OKAY/A_AUTH/A_WRTE/A_CLSE), the host can parse data length from 0 to any value defined in its message. So you can define it as parameter in the following receiver function.
So it goes on and on. If your code find it always timeout in khci, it maybe a problem of your state machine.
The real problem is how to handle an unknown length data stream in other applications. But FSL offers many reference designs from PHDC, CDC and printer. Among them, PHDC is more generic implementation.
It is only my personal opinion. And I am not good at FSL stack. My code is just WORKING, it still requires more improvements.
ADB is a good protocol, anyway. Let us review its flowchart (o is out, i is in) :
o> "CNXN"
o> "host::microbridge"
x i< "CNXN", !connected, connection=null, message
x i< "device::" !connected, connection=null, data
o> "OPEN"
o> "tcp:4567"
x i< "OKAY" connected, connection=valid, message
o> "WRTE"
o> data
x i< "OKAY" connected, connection=valid, message
x i< "WRTE" connected, connection=valid, message
x i< data connected, connection=valid, data
o> "OKAY"
o> "CLSE"
x i< "CLSE" connected, connection=valid, message
You will find the only issue is, A_WRTE from Android will be transferred in when we expecting A_OKAY from it for previous A_WRTE from host. That is easy to handle.
BTW, good choice for K20 based ADB design.
KL25Z has no FLEX memory and I2S, so my design is only for low-end applications.