platformio / platform-atmelsam

Atmel SAM: development platform for PlatformIO
https://registry.platformio.org/platforms/platformio/atmelsam
Apache License 2.0
78 stars 105 forks source link

Uploading to Arduino MKR Zero (ABX00012) from KVM VM does not work #151

Closed pboguslawski closed 3 years ago

pboguslawski commented 3 years ago

Hello,

Uploading any program from PlatformIO with Atmel SAM 6.0.1 running inside KVM virtual machine (Debian 10 64-bit) to Arduino MKR Zero (redirected USB device from host to virtual machine) throws an error:

[...]
Auto-detected: /dev/ttyACM0
Forcing reset using 1200bps open/close on port /dev/ttyACM0
Waiting for the new upload port...
Uploading .pio/build/mkrzero/firmware.bin
No device found on ttyACM0
*** [upload] Error 1

USB device is visible in VM:

$ lsusb
Bus 002 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub
Bus 001 Device 003: ID 2341:804f Arduino SA 
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub

No such problem with Arduino Pro Mini nor Nano Every in the same VM.

No such problem with Arduino MKR Zero when uploading from PlatformIO with Atmel SAM 6.0.1 running on same physical host (not in VM).

Regards, Paweł

valeros commented 3 years ago

The board might change its VID:PID combination after entering its bootloader mode. If there is no such problem on your host machine, then you need to properly configure your USB filters so your board in both modes (regular and bootloader) will be visible in a VM.

pboguslawski commented 3 years ago

Board does not change its IDs; on host when mkrzero is executing blink:

$ lsusb | grep -i arduino
Bus 002 Device 014: ID 2341:804f Arduino SA 

on host when mkrzero is in bootloader mode (after 2x fast reset presses, when led is indicating bootloader mode correctly /dimming/):

$ lsusb | grep -i arduino
Bus 002 Device 015: ID 2341:004f Arduino SA 

When the problem occurs in VM, USB redirection is stable (in case of USB ID changes redirection would be broken). So the problem source seems to be different than USB ID changes.

valeros commented 3 years ago

Board does not change its IDs; on host when mkrzero is executing blink:

Hm, I see here two different PIDs 804f and 004f. You sure both devices are redirected? Anyway, could you please try to upload a simple blink using Arduino IDE in VM?

pboguslawski commented 3 years ago

I see here two different PIDs 804f and 004f

You're right - it's changing. But problem still exists.

When mkrzero is in regular mode (804f) and redirected to VM (blink is executing):

$ lsusb | grep -i arduino
Bus 003 Device 003: ID 2341:804f Arduino SA 

# here upload try and failure:
Looking for upload port...

Auto-detected: /dev/ttyACM0
Forcing reset using 1200bps open/close on port /dev/ttyACM0
Waiting for the new upload port...
Uploading .pio/build/mkrzero/firmware.bin
No device found on ttyACM0
*** [upload] Error 1

$ lsusb | grep -i arduino
Bus 003 Device 003: ID 2341:804f Arduino SA 

Blink executing and Arduino did not change its state (no USB disconnets nor ID changes in logs and lsusb output). So PlatformIO probably didn't manage to switch Arduino to bootloader mode.

When mkrzero is put in bootloader mode (004f) forced by 2x reset presses and then redirected to VM (still in bootloader mode):

# lsusb | grep -i arduino
Bus 003 Device 004: ID 2341:004f Arduino SA 

# here upload try and failure:
Auto-detected: /dev/ttyACM0
Forcing reset using 1200bps open/close on port /dev/ttyACM0
Waiting for the new upload port...
Uploading .pio/build/mkrzero/firmware.bin
No device found on ttyACM0
*** [upload] Error 1

# lsusb | grep -i arduino
Bus 003 Device 004: ID 2341:004f Arduino SA 

Arduino did not change its state (no USB disconnets nor ID changes in logs and lsusb output). So PlatformIO probably didn't manage to upload to Arduino even its already in bootloader mode waiting for firmware.

pboguslawski commented 3 years ago

could you please try to upload a simple blink using Arduino IDE in VM

Will try but need more time (Debian 10 in VM has older Arduino-IDE packaged that does not support mkrzero).

pboguslawski commented 3 years ago

Just checked that in Arch linux with kernel 5.11.4-arch1-1 (host & vm) on different computer that uploading using Arduino IDE 1.8.13 does not work either. Same error.

Seems it's not PlatformIO fault but some kind of incompatibility between mkrzero USB and USB redirection in VM.

Thank you for help!

valeros commented 3 years ago

As I mentioned above, mkrzero in regular and bootloader modes represents two different devices, you need to configure your VM's USB filters so the board in both modes is automatically attached to your VM.

pboguslawski commented 3 years ago

Changing IDs is not a cause of this problem - see

https://github.com/platformio/platform-atmelsam/issues/151#issuecomment-795339574