Blog IndexPosts by TagHome

Debugging ATTiny1616 with Atmel ICE

Posted <2025-10-18 Sat 14:12> by Aaron S. Jackson.

This is more of a reminder to myself, but maybe someone else will find it helpful too. I'll soon be working on a 2nd version of my ear-lectronics, adding a KXTJ3 accelerometer to animate the LEDs a bit. This will use I2C and I suspect it may be slightly problematic to get it working without debugging, so I was pretty keen to get that working first.

Things needed:

I tried a bunch of different forks of avarice before I found that, but still hit a problem which took me some time to figure out. It built fine but would exit immediately after starting. After some print statements and the following change:

diff --git a/src/main.cc b/src/main.cc
index 71110ff..31fa055 100644
--- a/src/main.cc
+++ b/src/main.cc
@@ -769,8 +769,9 @@ int main(int argc, char **argv)
        fprintf(stderr, "%s\n", msg);
        return 1;
       }
-    catch (jtag_exception&)
+    catch (jtag_exception& e)
     {
+      fprintf(stderr, "%s\n", e.what());
         // ignored; guarantee theJtagICE object will be deleted
         // correctly, as this says "good-bye" to the JTAG ICE mkII

Which actually allowed me to figure out what the problem was - I needed the hidapi-devel package, and then rebuild avarice. Then it worked fine!

My makefile is looking like this:

GCC = avr-gcc
OBJCOPY = avr-objcopy
DEVICE = attiny1616
PROGRAMMER = atmelice_updi
CLOCK = 200000
# CLOCK = 32000
CFLAGS = -Wall -mmcu=$(DEVICE) -DF_CPU=$(CLOCK)UL

MAIN = main

all: build flash

build:
    $(GCC) -Os $(CFLAGS) $(MAIN).c -o $(MAIN).o
    $(OBJCOPY) -O ihex $(MAIN).o $(MAIN).hex

flash:
    avrdude -v -p $(DEVICE) -c $(PROGRAMMER) -e -U flash:w:$(MAIN).hex:i

debug:
    $(GCC) -Og -ggdb $(CFLAGS) $(MAIN).c -o $(MAIN).o
    $(OBJCOPY) -O ihex $(MAIN).o $(MAIN).hex
    avrdude -v -p $(DEVICE) -c $(PROGRAMMER) -e -U flash:w:$(MAIN).hex:i
    echo "Run /usr/local/avr-binutils/bin/avr-gdb"
    avarice -u -4 :4242

clean: rm *.o *.hex

which means I can just run "make debug"

Also worth noting, I built gdb with a prefix to /usr/local/avr-binutils because I didn't want to replace the gdb from fedora repos.

Wanting to leave a comment?

Comments and feedback are welcome by email (aaron@nospam-aaronsplace.co.uk).

Related posts:

Tags: computing electronics

Blog IndexPosts by TagHome

Copyright 2007-2025 Aaron S. Jackson (compiled: Sat 18 Oct 14:23:33 BST 2025)