arduino / ArduinoCore-avr

The Official Arduino AVR core
https://www.arduino.cc
1.25k stars 1.06k forks source link

arduino-usbserial: non-working Product string #431

Open agners opened 3 years ago

agners commented 3 years ago

When using an Arduino Mega 2560 R3 is connected to a Raspberry Pi running the U-Boot boot loader, it crashes the boot loader during USB enumeration:

Starting the controller
USB XHCI 1.00
scanning bus xhci_pci for devices...
Unexpected XHCI event TRB, skipping... (3affe040 00000000 13000000 02008401)

Debugging the problem showed that Arduino (or rather the ATmega16U2) announces a product string but does not report one when trying to get the product string (string id 2). This seems to be reproducible on Linux, but Linux seems to recover from the problem:

[285133.943073] usb 3-2: new full-speed USB device number 7 using xhci_hcd
[285134.118097] usb 3-2: New USB device found, idVendor=2341, idProduct=0042, bcdDevice= 0.01
[285134.118103] usb 3-2: New USB device strings: Mfr=1, Product=2, SerialNumber=220
[285134.118106] usb 3-2: Manufacturer: Arduino (www.arduino.cc)
[285134.118108] usb 3-2: SerialNumber: 85433333231351B0B2B1
[285134.164149] cdc_acm 3-2:1.0: ttyACM0: USB ACM device

Note the Product=2, but there is no Product: ... line. The device does not report a USB product string

This can be seen in Wireshark nicely, the string request for Descriptor Index: 0x02 does not get a proper Response STRING back. Linux seems to retry 6 times and then giving up and continuing with Descriptor Index: 0x01, which seems to work:

image

Wireshark trace: ArduinoMega2560-NoProductString.tar.gz

Not sure if this is violating the USB spec or just not being nice, but I think a fix should be rather trivial.

I am not 100% sure where the firmware for the ATmega16U2 of the Arduino Mega R3 comes from, but I assume its from firmwares/atmegaxxu2/arduino-usbserial/? If so, then it seems that there is a preprocesssor define missing in the product string descriptor table: https://github.com/arduino/ArduinoCore-avr/blob/9f8d27f09f3bbd1da1374b5549a82bda55d45d44/firmwares/atmegaxxu2/arduino-usbserial/Descriptors.c#L215

My device's product ID is 0x0042 but ARDUINO_MEGA2560_PID seems to be 0x0010....

(this has been noticed when using Arduino Mega connected to systems running Home Assistant OS: https://github.com/home-assistant/operating-system/issues/1011)

WestfW commented 2 years ago

Does an Uno work? I dumped the .hex files, and I didn't see a board-type string in either one...

Arduino-COMBINED-dfu-usbserial-atmega16u2-Uno-Rev3.hex:     file format ihex

Contents of section .sec1:
 :
 00c0 10042402 06052406 00010705 82030800  ..$...$.........
 00d0 ff090401 00020a00 00000705 04024000  ..............@.
 00e0 01070583 02400001 04030904 32034100  .....@......2.A.       // Here's the vendor string.  But no "Uno" anywhere!
 00f0 72006400 75006900 6e006f00 20002800  r.d.u.i.n.o. .(.
 0100 77007700 77002e00 61007200 64007500  w.w.w...a.r.d.u.
 0110 69006e00 6f002e00 63006300 29000000  i.n.o...c.c.)...
 0120 00001124 1fbecfef d2e0debf cdbf11e0  ...$............
 0130 a0e0b1e0 eceaffe0 02c00590 0d92a631  ...............1
 0140 b107d9f7 12e0a6e1 b1e001c0 1d92af32  ...............2
 0150 b107e1f7 f1d028c7 53cf9c01 dc01ae57  ......(.S......W
 0160 bf4fed91 fc911197 41911196 fc93ee93  .O......A.......
 0170 80589f4f e817f907 11f42d93 3c939fb7  .X.O......-.<...
mcuee commented 2 years ago

@WestfW Uno should have the same issue. After all, they share the same 10-year old codes. https://github.com/arduino/ArduinoCore-avr/tree/master/firmwares/atmegaxxu2

There is one more issue with the DFU bootloader here. It seems not able to read the AVR chip signature.