Hi Avelino
Each time the USB host sends a new SETUP it needs the data token to be re-synchronised since the next transmitted one is DATA0 and the next received one will be DATA1.
If you have incorrect data tokens being sent or expected the transfers will fail, which is presumably what is happening.
It makes sense to monitor the operation with a USB analyser since such problems will be easily to identify.
You can also take a look at the uTasker project since it contains USB host mode operation and emulation of this and the USB host controller which allows the driver code to be checked: It will immediately signal problems with data toggling errors.
This is what the emulation of the connection of a (non-formatted) memory stick looks like:
USB FS device detected
USB device information ready:
USB2.0 device with 64 byte pipe
Vendor/Product = 0x1d0d/0x0213
Manufacturer = "TDKMedia"
Product = "CDC "
Serial Number = "12345"
Bus-powered device (max. 200mA) with 1 interface(s)
Mass Storage Class : Sub-class = 0x06 interface protocol = 0x50
Endpoints:
2 = BULK IN with size 64
2 = BULK OUT with size 64
3 = INTERRUPT IN with size 2 (polling interval = 1ms)
Enumerated (1)
LUN = 1
UFI INQUIRY -> Status transport - Passed
UFI REQUEST SENSE -> Status transport - Passed
UFI FORMAT CAP. -> (3:512:16777216) Status transport - Passed
UFI READ CAP. -> (16785408:1016575) Status transport - Passed
Mem-Stick mounting...
Non-formatted Memory stick
whereby the endpoint 0 transmissions during the enumeration phase are:
SETUP [DATA0] 0x80 0x06 0x00 0x01 0x00 0x00 0x12 0x00
[DATA1] ZERO-DATA
SETUP [DATA0] 0x00 0x05 0x01 0x00 0x00 0x00 0x00 0x00
SETUP [DATA0] 0x80 0x06 0x00 0x02 0x00 0x00 0xFF 0x00
[DATA1] ZERO-DATA
SETUP [DATA0] 0x80 0x06 0x00 0x03 0x00 0x00 0x21 0x00
[DATA1] ZERO-DATA
SETUP [DATA0] 0x80 0x06 0x01 0x03 0x09 0x04 0x21 0x00
[DATA1] ZERO-DATA
SETUP [DATA0] 0x80 0x06 0x02 0x03 0x09 0x04 0x21 0x00
[DATA1] ZERO-DATA
SETUP [DATA0] 0x80 0x06 0x03 0x03 0x09 0x04 0x21 0x00
[DATA1] ZERO-DATA
SETUP [DATA0] 0x00 0x09 0x01 0x00 0x00 0x00 0x00 0x00
SETUP [DATA0] 0xA1 0xFE 0x00 0x00 0x00 0x00 0x01 0x00
[DATA1] ZERO-DATA
If you use the open source version as reference you can either cut out the parts of the enumeration state-machine that you don't want or copy its operation to your environment.
The minimal frames that you are sending would be :
SETUP [DATA0] 0x00 0x05 0x01 0x00 0x00 0x00 0x00 0x00
and
SETUP [DATA0] 0x00 0x09 0x01 0x00 0x00 0x00 0x00 0x00
Regards
Mark
Kinetis: http://www.utasker.com/kinetis.html
Kinetis K20:
- http://www.utasker.com/kinetis/FRDM-K20D50M.html
- http://www.utasker.com/kinetis/TWR-K20D50M.html
- http://www.utasker.com/kinetis/TWR-K20D72M.html
- http://www.utasker.com/kinetis/TEENSY_3.1.html
- http://www.utasker.com/kinetis/tinyK20.html
Free Open Source solution: https://github.com/uTasker/uTasker-Kinetis
Working project in 15 minutes video: https://youtu.be/K8ScSgpgQ6M
For better, faster, cheaper product developments consider the uTasker developer's version, professional Kinetis support, one-on-one training and complete fast-track project solutions to set you apart from the herd : http://www.utasker.com/support.html