I working on a custom board with an ATmega238P using the Atmel-ICE debugger.
The source code is compliled using a Make file on Linux.
For debug pourposes, I want to use an IDE that provides debugging capabilities and since Atmel Studion is not working on Linux (+ I like VS Code and I used platformio on an ESP8266) I want to migrate my projet to Platformio.
My environment running inside an Xubuntu Virtual Machine.
With the command
lsusb
I verified that the debugger is connected to my VM
Bus 001 Device 002: ID 03eb:2141 Atmel Corp. ICE debugger
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 002 Device 003: ID 0e0f:0002 VMware, Inc. Virtual USB Hub
Bus 002 Device 002: ID 0e0f:0003 VMware, Inc. Virtual Mouse
Bus 002 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
I create a new project and I can compile my projet with the Arduino framework.
Debugging AVR chips with an Atmel-ICE is not supported out-of-the-box, upload is. The currently support debug methods for Atmel chips are by simulation (simavr) or by a serial GDB stub program loaded into the firmware (avr-stub).
but when I click on “Upload” from Platformio, I get this error:
Building .pio/build/ATmega328P/firmware.hex
Configuring upload protocol…
AVAILABLE: atmelice_isp
CURRENT: upload_protocol = atmelice_isp
Looking for upload port…
Use manually specified: usb
*** [upload] could not open port usb: [Errno 2] No such file or directory: ‘usb’
==================================================================================== [FAILED] Took 4.07 seconds ====================================================================================
The terminal process “pio ‘run’, ‘–target’, ‘upload’, ‘–environment’, ‘ATmega328P’” terminated with exit code: 1.
Terminal will be reused by tasks, press any key to close it.
AVAILABLE: atmelice_isp
CURRENT: upload_protocol = atmelice_isp
BeforeUpload(["upload"], [".pio\build\ATmega328P\firmware.hex"])
Use manually specified: usb
avrdude -e -v -p atmega328p -C C:\Users\Max\.platformio\packages\tool-avrdude\avrdude.conf -c atmelice_isp -b 115200 -D -P "usb" -U flash:w:.pio\build\ATmega328P\firmware.hex:i
avrdude: Version 6.3, compiled on Sep 12 2016 at 17:24:16
Copyright (c) 2000-2005 Brian Dean, http://www.bdmicro.com/
Copyright (c) 2007-2014 Joerg Wunsch
System wide configuration file is "C:\Users\Max\.platformio\packages\tool-avrdude\avrdude.conf"
Using Port : usb
Using Programmer : atmelice_isp
Overriding Baud Rate : 115200
avrdude: jtag3_open_common(): Did not find any device matching VID 0x03eb and PID list: 0x2141
avrdude done. Thank you.
Can you make sure your core and platforms are up to date? Open a CLI and do pio upgrade --dev and pio platform update atmelavr, then restart VSCode and retry.
We found 79.48KB of unnecessary PlatformIO system data (temporary files, unnecessary packages, etc.).
Use pio system prune --dry-run to list them or pio system prune to save disk space.
but I get the same error:
Configuring upload protocol…
AVAILABLE: atmelice_isp
CURRENT: upload_protocol = atmelice_isp
Looking for upload port…
Use manually specified: usb
*** [upload] could not open port usb: [Errno 2] No such file or directory: ‘usb’
==================================================================================== [FAILED] Took 5.63 seconds ====================================================================================
The terminal process “pio ‘run’, ‘–target’, ‘upload’, ‘–environment’, ‘ATmega328P’” terminated with exit code: 1.
Terminal will be reused by tasks, press any key to close it.
Should I install something related to “Atmel Ice”?
Oh wow this really is operating-system specific regarding the upload_port when the value is usb. PlatformIO performs a sanity-check whether that “file” is there before uploading.
Please add
board_upload.require_upload_port = no
to the platformio.ini.
However then -Pusb doesn’t show up in the avrdude invocation anymore – but it still seems to look for the right thing. Worth a try. In the meantime I’ll raise an issue.
Now the error is changed and it seems related to the upload with avrdude
avrdude: usbdev_open(): WARNING: failed to set configuration 1: Device or resource busy
avrdude: stk500v2_command(): command failed
avrdude: bad response to AVR sign-on command: 0xa0
avrdude: Target prepared for ISP, signed off.
avrdude: Now retrying without power-cycling the target.
avrdude: stk500v2_command(): command failed
avrdude: bad response to AVR sign-on command: 0xa0
avrdude: Target prepared for ISP, signed off.
avrdude: Now retrying without power-cycling the target.
avrdude: stk500v2_command(): command failed
avrdude: bad response to AVR sign-on command: 0xa0
avrdude: Target prepared for ISP, signed off.
avrdude: Now retrying without power-cycling the target.
avrdude: stk500v2_command(): command failed
avrdude: bad response to AVR sign-on command: 0xa0
avrdude: Target prepared for ISP, signed off.
avrdude: Now retrying without power-cycling the target.
avrdude: stk500v2_command(): command failed
avrdude: bad response to AVR sign-on command: 0xa0
avrdude: Failed to return from debugWIRE to ISP.
avrdude: initialization failed, rc=-1
Double check connections and try again, or use -F to override
this check.
Can you quickly test the original platformio.ini on Windows without the USB device being passed through? That would quickly rule out some error sources.
Ok, I installed evrything and now I get this error:
Configuring upload protocol…
AVAILABLE: atmelice_isp
CURRENT: upload_protocol = atmelice_isp
Looking for upload port…
Uploading .pio\build\ATmega328P\firmware.hex
avrdude: jtag3_open_common(): Did not find any device matching VID 0x03eb and PID list: 0x2141
avrdude done. Thank you.
*** [upload] Error 1
================================================================================================== [FAILED] Took 3.06 seconds ==================================================================================================
The terminal process “C:\Users\f.platformio\penv\Scripts\pio.exe ‘run’, ‘–target’, ‘upload’, ‘–environment’, ‘ATmega328P’” terminated with exit code: 1.
Terminal will be reused by tasks, press any key to close it.
avrdude can’t interface with Atmel-ICE when it’s loaded with the Atmel Studio drivers, it needs libusb drivers, per Atmel ice cannot upload (but debug works) - #12 by pfeerick. Also make sure the USB device wasn’t auto-forwarded to the VM.
Later edit: Zadig fixed the issue on windows with avrdude not detecting the atmel-ice - just replaced the “Atmel-ICE CMSIS-DAP” WinUSB driver with libusb-win32, and it works fine. Atmel studio doesn’t like it, but it will be just a matter of swapping the drivers back if I want to use it.
Not sure about the driver reinstall procedure though once the drivers are replaced using Zadig – might need just a re-insert or executing a driver install from Atmel Studio again to get the old drivers.
Well the same holds for Windows, no built-in support for the atmel-ice + AVR combination. AVARICE seems to be working better in Linux though. But a Windows-compiled version is also available and some docs.
I replaced the dirvers using Zadig tool and now the error is:
Configuring upload protocol…
AVAILABLE: atmelice_isp
CURRENT: upload_protocol = atmelice_isp
Looking for upload port…
Uploading .pio\build\ATmega328P\firmware.hex
avrdude: usbdev_send(): wrote -22 out of 7 bytes, err =
avrdude: jtag3_send(): failed to send command to serial port
avrdude: failed to sync with the JTAGICE3 in ISP mode
avrdude done. Thank you.
*** [upload] Error 1
================================================================================================== [FAILED] Took 1.48 seconds ==================================================================================================
The terminal process “C:\Users\fi.platformio\penv\Scripts\pio.exe ‘run’, ‘–target’, ‘upload’, ‘–environment’, ‘ATmega328P’” terminated with exit code: 1.
Terminal will be reused by tasks, press any key to close it.
avrdude: usbdev_send(): wrote -22 out of 7 bytes, err =
avrdude: jtag3_send(): failed to send command to serial port
avrdude: failed to sync with the JTAGICE3 in ISP mode
I’ve looked through the google results for avrdude: usbdev_send(): wrote -22 out of 7 bytes, err = but couldn’t find a definitive answer. Some say their programmer is bad, others say the -B bitrate fixed it, others say the installed drivers from Atmel Studio still interfered. No idea why avrdude is throwing that, and since I don’t have the programmer hardware I also can’t verify if it usually works. You may submit a bug request to AVR Downloader/UploaDEr - Bugs: Browse Items [Savannah] but since this is obviously not working well at all I’d recommend to either try pure Linux without the VM to see if Windows drivers are the issue or really Atmel Studio.