adafruit / Adafruit_TinyUSB_Arduino

Arduino library for TinyUSB
MIT License
470 stars 124 forks source link

WebUSB serial example broken (regression) #176

Closed maxgerhardt closed 2 years ago

maxgerhardt commented 2 years ago

Operating System

Windows 10

IDE version

1.8.16

Board

Adafruit Feather RP2040

ArduinoCore version

2.2.0

TinyUSB Library version

1.12.0

Sketch (attached txt file)

examples/WebUSB/webusb_serial/webusb_serial.ino

What happened ?

When compiling and uploading the Web USB serial example to a RP2040 board using the Arduino-Pico core in the latest 2.2.0 version, which uses Adafruit TinyUSB version 1.11.0, the received text in the WebUSB Serial example page does not contain linebreaks.

When overwriting the library files in C:\Users\<user>\AppData\Local\Arduino15\packages\rp2040\hardware\rp2040\2.2.0\libraries\Adafruit_TinyUSB_Arduino with the 1.10.0 release, the problem goes away.

The issue is also present in the latest 1.12.0 release, tested with the same procedure. Per this the first broken version is 1.10.2.

Thus, "something" broke in between these two versions.

How to reproduce ?

  1. Open the Arduino IDE
  2. Install Arduino-Pico core per https://github.com/earlephilhower/arduino-pico#installing-via-arduino-boards-manager
  3. Use Tools settings per Arduino IDE screenshot below
  4. Open reference example sketch
  5. Have a RP2040 board connected
  6. Press upload
  7. Sketch should upload and, on Windows, show the "Device is ready to be connected.." notification
  8. Click on it to be forwarded to https://adafruit.github.io/Adafruit_TinyUSB_Arduino/examples/webusb-serial/index.html using Microsoft Edge as the browser (does not work in Firefox)
  9. Click on "Connect"
  10. Observe "Receiver" output on the right-hand window

Debug Log

Debug log with good 1.10.0 version: output_good.txt

Debug log with bad 1.12.0 version: output_bad.txt

Logs were generated by setting CFG_TUSB_DEBUG to 2. Timestamps were added in by the HTerm terminal program.

Screenshots

Behavior in 1.10.0 (good):

grafik

Behavior in 1.10.2 up to latest 1.12.0 (bad) (confirmed in https://github.com/earlephilhower/arduino-pico/issues/642#issuecomment-1162541777):

grafik

Arduino IDE config:

grafik

hathach commented 2 years ago

thank you very much for detail report on the issue. This is actually the landing page web issue, it didn't break line properly when multiple lines are sent in packet

The reason that the older version of tinyusb (hardly) does not cause this, is the new usb improve the write performance of vendor class. The later tinyusb cached and does not flush() every write (similar to Serial, it will only flush when 64 bytes are accumulated or flush() is actively called from user. Note: Serial.flush() is normally called behind the scene).

I hope this clear thing up. pr #180 should fix this, if you have time to test it out, please let me know your result.

maxgerhardt commented 2 years ago

Sadly the PR doesn't help, using the webpage and Adafruit TinyUSB library from that branch results in the same looking

grafik

Except that somehow now there's heartbeat message in front of "TInyUSB Web USB Serial example".

Tested using

[env:adafruit_feather]
platform = https://github.com/maxgerhardt/platform-raspberrypi.git
framework = arduino
board = adafruit_feather
board_build.core = earlephilhower
board_build.filesystem_size = 0.5m
debug_build_flags = -O0 -g3 -ggdb3
platform_packages = 
   framework-arduinopico@https://github.com/maxgerhardt/arduino-pico.git
build_flags =
   -DUSE_TINYUSB 
lib_deps = 
   https://github.com/adafruit/Adafruit_TinyUSB_Arduino.git#fix-webusb-example

in Microsoft Edge

hathach commented 2 years ago

the issue is with the sketch and the landing page. can you confirm

  1. You run the updated webusb_serial in the PR
  2. use the new landing page it suggest which is https://example.tinyusb.org/webusb-serial/index.html
  3. If possible please test with Arduino
maxgerhardt commented 2 years ago

Yes the PlatformIO compiled firmware works with the above ini when visiting https://example.tinyusb.org/webusb-serial/index.html with it --

grafik

however, as shown in the screenshot I did take the landing page from the PR, not the adafruit website or the one from the master branch. So what's hosted on https://example.tinyusb.org/webusb-serial/index.html is not equal to what's in the PR?

grafik

(exact same firmware)

hathach commented 2 years ago

included in docs/ is not the landing page from the sketch, it should suggest the one from tinyusb. But I will update it anyway. Thank you for confirming.

hathach commented 2 years ago

local page is updated as well with the pr. Thank you for your issue