Debugging AVR / Arduino with ATMELICE / JTAGICE3 and avarice / avr-gdb

Hello
I am currently searching for a new toolchain for developing software for Ardunio, because Arudino IDE is so limited.

Last week I focused on PIO. But I had problems with the configuration of the debug tools, because the infos on Atmel-ICE — PlatformIO latest documentation are not maintained well. So I deinsalled PIO after 3 days and I switched to Microchip (AVR) Studio. But PIO has the killer feature → Unit Tests! So I installed PIO again and tried to get debugging working. But currently with no happy end.

My setup: Win 10 + VSC + PIO
platformio.ini:

[env:uno]
platform = atmelavr
board = uno
framework = arduino
debug_port = :4242
debug_tool = custom
debug_init_cmds =
target remote $DEBUG_PORT
file “$PROG_PATH”
load

First I tried to setup all under Windows. But I don’t get avarice build under Windows with Cygwin.

So I thought I must switch to linux. Lucky I have a Raspberry Pi on my desk. I installed avarice, modified platformio.ini

[env:uno]
platform = atmelavr
board = uno
framework = arduino
debug_port = :4242
debug_tool = custom

and I got avarice running with $ sudo avarice --edbg --debugwire --ignore-intr :4242 -d -P atmega328p on RPi.

But when I want to start a debug session from PIO I got following error:

GDB: Write 32 bytes to 0x0
jtagWrite jtagWrite(): numByte does not match page size

Again after searching in the internet I had the felling that avarice has a bug. On my Raspberry Pi avarice 2.13 is installed, but the latest one is 2.14.

So I started uninstalling avarice on RPi. But I saw that with the installation of avarice on RPi avr-gdb was also installed. So I tried avr-gdb with avarice on the RPi. And YESSS it looks good - no errors. I was able to upload the *.elf and set breakpoints. WOOW

But it seams for me that the version of avr-gdb is too old.

Following versions are used on RPi: avr-gdb 7.11.1
But the AVR toolchain which is included in PIO is using version 7.8.

Is there a plan for updating them?

Thanks in advance

In this case I would highly recommend a Linux virtual machine on your computer, like Xubuntu in VirtualBox, instead of a different machine entirely. You can also forward USB devices there. But that’s just for comfort and wouldn’t solve the problem here.

If you have a native toolchain that is newer than PIO’s, as a test, you can manually replace it. Usually to replace a toolchain, one deletes all the content in ~/.platformio/packages/toolchain-atmelavr except the package.json, then copies the new toolchain into said folder. But if you’re just interested in gdb, you should be able to go into said folder and then bin, then mv avr-gdb avr-backup-gdb and symlink your system avr-gdb to the PIO folder by ln -s $(which avr-gdb) avr-gdb, assuming avr-gdb is globally recognized command in the shell.

2 Likes

Danke Max
It is really hard work (for me) to setup up a nice working toolchain.

I follwed your suggestion to switch to Xubuntu. I only moved the older avr-gdb to avr-gdb-backup without setting the symlink → it works.

Then I tried to start a debug session with ATMELICE directly out of PIO with following ini:

[env:uno]
platform = atmelavr
board = uno
framework = arduino
upload_protocol = atmelice_isp
upload_flags = -e
upload_port = /dev/usb

But I always got the error:
*** [upload] could not open port /dev/usb: [Errno 2] No such file or directory: ‘/dev/usb’

I tried to start VSC with sudo → doesn’t help
I followed these steps: Redirecting... → doesn’t help

Because I found no solution for that yet I switched to run avarice on RPi…

aaaand it looks good. :slight_smile: but
the debug experence lacks.

When I set a break point, it doesn’t stop automatically in the source line. I always have to push the “pause” button in VSC, than it breaks on the breakpoint and I can watch vaiables.
I searched again in the internet where I found many things regarding that topic but I was unable to find a solution yet. For me it looks like that I have a configuration issue, because avarice writes follwing lines:


Got message seqno 10 (command_sequence == 10)
response: 12 80 00
read: 0e 00 78 00 12 40 00 01 00 00 01 00 00 30
Event serial 0x0078
ignoring break event

Do you have a hint where the problem is?

Thank you

Update: I build the latest version of avarice (currenlty 2.14) and avr-gdb (version 9.2) both for Linux and avr-gdb also for Windows.

I am able to make a debug session with avr-gdb under windows (with expat !!!) connected with avarice running on my RPI. But the debug experience is not the best when you have to control gdb over the terminal.

Under Windows it is the same with avr-gdb and avarice as under Linux.

I also tried to setup a toolchain under Ubuntu with PIO, avr-gdb and avarice with follwing ini:

[env:uno]
platform = atmelavr
board = uno
framework = arduino
debug_port = :4242
debug_tool = custom
debug_init_cmds =
  target remote $DEBUG_PORT
  file "$PROG_PATH"
  load
debug_server =
  avarice
  --edbg
  --debugwire
  --ignore-intr 
  :4242

But I get follwing error with ATMELICE:

AVaRICE version 2.13svn20160229, Mar 22 2020 15:34:12

JTAG config starting.
Found a device, serial number: J41800071463
Reported device ID: 0x950F
Configured for device ID: 0x950F atmega328p
JTAG config complete.
Preparing the target device for On Chip Debugging.
Waiting for connection on port 4242.
Connection opened by host 127.0.0.1, port 48114.
.pioinit:14: Error in sourced command file:
Remote connection closed