SAMD21 USB host not working
Operating System
Windows 10
Commit SHA
331c263400dd5ccf77264cab1fa6bbd9f374b44e
Board
Adafruit Feather M0 (RFM95)
Firmware
https://github.com/maxgerhardt/samd21-usb-host-repro/
What happened ?
When starting up the TinyUSB stack configured for just USB host, and with only the CDC host driver enabled, no hubs, the enumeration of USB devices files with a timeout.
When using the same hardware with the USBHost library (https://github.com/arduino/ArduinoCore-samd/tree/master/libraries/USBHost/examples/USB_desc), it can enumerate the USB device just fine.
Starting USB Descriptor test
Initializing USB
01
--
Device descriptor:
Descriptor Length:12
Descriptor type:01
USB version:0110
Device class:00
Device Subclass:00
Device Protocol:00
Max.packet size:40
Vendor ID:10C4
Product ID:EA60
Revision ID:0100
..
How to reproduce ?
- Download reference firmware repo in VSCode + PlatformIO extension
- Plug in Adafruit Feather M0 via USB port, quickly double-press RESET button to get it into USB bootloader mode
- Upload firmware via project tasks -> Upload
- Unplug the USB cable from the Feather M0
- Use a USB-to-UART adapter with VCC, GND and RX connected to "USB", "GND" and "TX1" of the Feather (gives the Feather power and can read debug logs)
- use a micro USB OTG adapter to get a female USB-A port on on the Feather
- plug in a device (example: CP2102 adapter)
Debug Log as txt file (LOG/CFG_TUSB_DEBUG=2)
TinyUSB Dual Device Info Example
Enabling USB clock
Setting USB handler
Beginning USB host
USBH init on controller 0, speed = Full
sizeof(usbh_data_t) = 28
sizeof(usbh_device_t) = 94
sizeof(hcd_event_t) = 12
sizeof(tuh_xfer_t) = 24
sizeof(tu_fifo_t) = 12
sizeof(tu_edpt_stream_t) = 20
Got 1 host drivers
CDC init
sizeof(cdch_interface_t) = 200
Initialized all drivers, now initing controller
Resetting USB controller
Done restting USB controller
Waiting for USB sync
Got USB sync
Enabling USB interrupts now
Beginning USB host done
[0:] USBH Device Attach
Full Speed
[0:0] Open EP0 with Size = 8
Get 8 byte of Device Descriptor
[0:0] Get Descriptor: 80 06 00 01 00 00 08 00
[:0] on EP 00 with 8 bytes: OK
[:0] on EP 80 with 8 bytes: OK
[0:0] Control data:
0000: 12 01 10 01 00 00 00 40 |.......@|
[:0] on EP 00 with 0 bytes: TIMEOUT
Screenshots
I have checked existing issues, discussion and documentation
- [x] I confirm I have checked existing issues, discussion and documentation.
Note: The config of the project in regards to CFG_TUH_HUB matches what is being told about TIMEOUTS in exactly the original PR https://github.com/hathach/tinyusb/pull/2573.
I use the exact same pin mode setup and clock setup as the USBHost library (this, ref), since I work within the context of the Adafruit SAMD core and don't include the family.c of the SAMD21 family from this repo.
The board has a 32.768 kHz crystal oscillator on-board, which is used during clock setup as reference for the delay-locked-loop DFLL48M. (CRYSTALLESS is not defined for the variant in this section).
I have tried several things:
- turning on the
HCD_SAMD_FAKE_FNUMdriver option - substituting the "local pad calibration" from the working USBHost library
- starting USB peripheral in "forced FS mode" instead of "normal" mode (
USB_HOST_CTRLB_SPDCONF_NORMAL)
None of which has made a difference.
thanks for detailed report, can you do the quick check and run this repo stock example with cmake build e.g host/cdc_msc_hid or host/device_info to see if that works. Arduino core may need more glueing.
PS: I haven't tried to run tinyusb with host most on arduinocore either. Maybe this is time to add that support
I compiled the host/device_info example from 331c263400dd5ccf77264cab1fa6bbd9f374b44e for the feather_m0_express, with the addition that I changed
https://github.com/hathach/tinyusb/blob/331c263400dd5ccf77264cab1fa6bbd9f374b44e/hw/bsp/samd21/boards/feather_m0_express/board.h#L47-L49
to be
// UART
#define UART_SERCOM 0
#define UART_RX_PIN 11
#define UART_TX_PIN 10
This seems to be a bug in all SAMD board.h, the UART_SERCOM is left undefined so it doesn't trigger the right code to activate UART logging, on top of that all RX / TX pins seem wrong; On the Feather M0 (and the same on my board), TX = PA10, RX = PA11, as schematics say.
I ran the example with examples\host\device_info\src\tusb_config.h modified with
#define CFG_TUSB_DEBUG 2
and
#define CFG_TUH_HUB 0
to respect the issue as linked in the original PR.
Uploaded it over USB with bossac
C:\Users\Max\.platformio\packages\[email protected]\bossac --info --debug --port "COM40" --write --verify --reset --erase -U true "C:\Users\Max\temp\tinyusb\examples\build\feather_m0_express\host\device_info\RelWithDebInfo\device_info.bin"
Output over UART and when connecting the same USB device (USB-to-serial adapter) was
TinyUSB Device Info Example
USBH init on controller 0, speed = Auto
sizeof(usbh_data_t) = 28
sizeof(usbh_device_t) = 94
sizeof(hcd_event_t) = 12
sizeof(tuh_xfer_t) = 24
sizeof(tu_fifo_t) = 12
sizeof(tu_edpt_stream_t) = 20
[0:] USBH Device Attach
Full Speed
[0:0] Open EP0 with Size = 8
Get 8 byte of Device Descriptor
[0:0] Get Descriptor: 80 06 00 01 00 00 08 00
[:0] on EP 00 with 8 bytes: OK
[:0] on EP 80 with 8 bytes: OK
[0:0] Control data:
0000: 12 01 10 01 00 00 00 40 |.......@|
[:0] on EP 00 with 0 bytes: TIMEOUT
which is exactly equal to the one I got in my attempt with the Arduino USB core.
thank you for confirmation, I will test and get back to you later. I think I tested with samd51 previously, will try with the M0 this time.