webusb / arduino

WebUSB demos running on Arduino (and compatible) hardware.
576 stars 152 forks source link

Fix control transfers on SAMD #80

Open reillyeon opened 3 years ago

reillyeon commented 3 years ago

On SAMD-based boards it appears that the entire control transfer reply needs to be passed to USB_SendControl() at once. The original code took advantage of making multiple calls to construct replies from smaller chunks. This has been rewritten to construct and send the entire responce at once.

Fixes #79.

reillyeon commented 3 years ago

@TedNIVAN, can you verify this fix on your SAMD board? I don't have an AVR board to test on at the moment. @jpliew, is there any chance you could give me a hand verifying this?

TedNIVAN commented 3 years ago

@TedNIVAN, can you verify this fix on your SAMD board? I don't have an AVR board to test on at the moment. @jpliew, is there any chance you could give me a hand verifying this?

@reillyeon Didn't work for me.

reillyeon commented 3 years ago

Thanks for checking. It looks like something else is broken here as well.

TedNIVAN commented 3 years ago

Alright. Please let me know if you managed to figure it out.

gpelizzo commented 3 years ago

Hi, let m know if I can help. I've few SAMD boards for testing. Cheers

jpliew commented 3 years ago

Before this pull request I was also facing symptoms like #41, #60, #69

Tested this pull request with the following

  1. Windows 8.1 & 10, Linux
  2. Chrome Version 87.0.4280.88 (Official Build) (64-bit)
  3. ATmega32U4
  4. SAMD (Adafruit Feather M0 Express)

Tested all working fine.

This pull request should fix issue #41, #60, #69

I would like to suggest to have this pull request merged.

As for Android, this pull request works ok for the AVR (ATmega32U4) but not working for SAMD. In chrome://usb-internals Chrome can see the device, upon clicking Inspect the following screenshot shows the error

Screenshot_20201228-151425

jpliew commented 3 years ago

@TedNIVAN could you explain what exactly you want to do with your app and webusb please? It will me much easier if you can explain your use case and proper recommendation can be provided. From your app fruity market, I am not able to see how it is used with a webusb device.

jpliew commented 3 years ago

@reillyeon , I did a bit more digging on Android Chrome. Below are the logs, when clicking Get Device Configuration Descriptor on page chrome://usb-internals

My opinion is Android Chrome does not like the way Arduino SAMD's USBCore.cpp doing the _dry_run and _pack_message sending them all at once. 0x62 bytes (98 bytes) packet might have blown off the buffer already ??

Will you be able to check Android Chrome's (Version 87.0.4280.101) source why it behave differently than the desktop Chrome ?

SAMD When Clicking Get Configuration Descriptor

handleStandardSetup
        GET_DESCRIPTOR
                bmRequestType=  0x80
                bRequest=       0x6
                wValueL=        0x0
                wValueH=        0x1
                wIndex=         0x0
                wLength=        0x12
        PluggableUSB().getDescriptor=0
        USB_DEVICE_DESCRIPTOR_TYPE
                sendControl len=0x12
                12 01 10 02 EF 02 01 40 9A 23 1B 80 00 01 01 02 03 01
handleStandardSetup
        GET_DESCRIPTOR
                bmRequestType=  0x80
                bRequest=       0x6
                wValueL=        0x0
                wValueH=        0x2
                wIndex=         0x0
                wLength=        0x4
        USB_CONFIGURATION_DESCRIPTOR_TYPE
                sendControl len=0x42
        dry_run
                sendControl len=0x17
        dry_run
                sendControl len=0x9
        pack_message
                sendControl len=0x42
        pack_message
                sendControl len=0x17
        pack_message
                sendControl len=0x62
                09 02 62 00 03 01 00 A0 32 08 0B 00 02 02 02 00 00 09 04 00 00 01 02 02 00 00 05 24 00 10 01 04 24 02 06 05 24 06 00 01 05 24 01 01 01 07 05 81 03 10 00 10 09 04 01 00 02 0A 00 00 00 07 05 02 02 40 00 00 07 05 83 02 40 00 00 09 04 02 00 02 FF 00 00 00 07 05 04 02 40 00 00 07 05 85 02 40 00 00

ATMEGA34U4 When Clicking Get Configuration Descriptor

handleStandardSetup
        GET_DESCRIPTOR
                bmRequestType=  0x80
                bRequest=       0x6
                wValueL=        0x0
                wValueH=        0x2
                wIndex=         0x0
                wLength=        0x9
        USB_CONFIGURATION_DESCRIPTOR_TYPE
                sendControl len=0x42
                08 0B 00 02 02 02 01 00 09 04 00 00 01 02 02 00 00 05 24 00 10 01 05 24 01 01 01 04 24 02 06 05 24 06 00 01 07 05 81 03 10 00 40 09 04 01 00 02 0A 00 00 00 07 05 02 02 40 00 00 07 05 83 02 40 00 00
                sendControl len=0x17
                09 04 02 00 02 FF 00 00 00 07 05 04 02 40 00 00 07 05 85 02 40 00 00
                sendControl len=0x9
                09 02 62 00 03 01 00 A0 FA
                sendControl len=0x42
                08 0B 00 02 02 02 01 00 09 04 00 00 01 02 02 00 00 05 24 00 10 01 05 24 01 01 01 04 24 02 06 05 24 06 00 01 07 05 81 03 10 00 40 09 04 01 00 02 0A 00 00 00 07 05 02 02 40 00 00 07 05 83 02 40 00 00
                sendControl len=0x17
                09 04 02 00 02 FF 00 00 00 07 05 04 02 40 00 00 07 05 85 02 40 00 00
handleStandardSetup
        GET_DESCRIPTOR
                bmRequestType=  0x80
                bRequest=       0x6
                wValueL=        0x0
                wValueH=        0x2
                wIndex=         0x0
                wLength=        0x62
        USB_CONFIGURATION_DESCRIPTOR_TYPE
                sendControl len=0x42
                08 0B 00 02 02 02 01 00 09 04 00 00 01 02 02 00 00 05 24 00 10 01 05 24 01 01 01 04 24 02 06 05 24 06 00 01 07 05 81 03 10 00 40 09 04 01 00 02 0A 00 00 00 07 05 02 02 40 00 00 07 05 83 02 40 00 00
                sendControl len=0x17
                09 04 02 00 02 FF 00 00 00 07 05 04 02 40 00 00 07 05 85 02 40 00 00
                sendControl len=0x9
                09 02 62 00 03 01 00 A0 FA
                sendControl len=0x42
                08 0B 00 02 02 02 01 00 09 04 00 00 01 02 02 00 00 05 24 00 10 01 05 24 01 01 01 04 24 02 06 05 24 06 00 01 07 05 81 03 10 00 40 09 04 01 00 02 0A 00 00 00 07 05 02 02 40 00 00 07 05 83 02 40 00 00
                sendControl len=0x17
                09 04 02 00 02 FF 00 00 00 07 05 04 02 40 00 00 07 05 85 02 40 00 00
Delonous commented 3 years ago

Any updates on this? I seem to be running into the same above errors in the screenshot on desktop chrome. On both gh-pages and samd-fix. Windows 10 Chrome 88.0.4324.182 MKR ZERO Arduino SAMD Boards 1.8.9

jpliew commented 3 years ago

@Delonous if you try the pull request, this fixes the SAMD issues on desktop.