Description
My goal is to debug an ATXMega128a1u on Windows and macOS with firmware compile with avr-gcc. I would love for this to be using avarice, since our whole dev/build system is set up with cmake standalone on the command line already.
avarice 2.13 is available on homebrew, but support for the usb/edbg transport selection (avarice -4 --jtag usb
) was only added in 2.14. I have been really struggling to get avarice compiled with this support, both on windows and macOS. This focuses on macOS as this is more desired.
tl;dr:
I can get this compiling on Apple Silicon, but the call to hid_enumerate
to find USB-attached debuggers is always empty.
Details
I can get the ./Bootstrap
, ./configure
, make
chain working on macOS. This compiles a working avarice, however executing avarice -4 --jtag usb
gives me the message:
avarice has not been compiled with libusb support
After digging, I found that autoconf was not setting HAVE_LIBUSB
due to a failed link check for the usb_get_string_simple
function. I verified that I had both libusb and libusb-compat installed through brew (the latter has the usb_get_string_simple
in its header file), but was still seeing this output from running the configure script:
checking for bfd_init in -lbfd... no
checking for usb_get_string_simple in -lusb... no
checking for libusb20_dev_open in -lusb... no
checking for library containing hid_init... no
I fixed this by providing the proper -I
and -L
paths to the configure invocation, since it clearly wasn't finding them in the homebrew (I also started including -ggdb
for debug symbols to debug these issues later on):
./configure \
CFLAGS="-ggdb -I/opt/homebrew/opt/libusb-compat/include" \
CXXFLAGS="-ggdb -I/opt/homebrew/opt/libusb-compat/include " \
LDFLAGS="-L/opt/homebrew/opt/libusb-compat/lib"
Configure script then properly output checking for usb_get_string_simple in -lusb... yes
. When I ran make
however, it would fail at the link step, saying it was trying to link to my libusb but it was arm64 and it was looking for x86_64. This was when I realised that avarice is trying to compile as x86_64, not native Apple Silicon. My fix for this is pretty gross but I launched a shell with rosetta (arch -x86_64 zsh
), then manually installed brew into the normal Intel mac location /usr/local
. When I used the Intel brew to install libusb and libusb-compat into the "old normal" locations of /usr/local/lib
and /usr/local/include
, I could re-run configure without passing manual args. make
also worked properly.
Running the avarice binary with the usb
arg now didn't say it had no libusb support, but it exited silently. Using lldb I realised that it also needed hidapi linked in (see the checking for library containing hid_init
line in the configure script output near the top). I installed this through Intel brew and verified that that no
became a yes
on a reconfigure.
Now I am finally stuck. The binary runs fine, but the call to hid_enumerate
to look for attached debuggers (jtag2usb.cc:639) always returns an empty list. I've tried with both an Atmel Ice and an ATXmega128a1u Xplained Pro board attached. I've also tried running the built avarice from an x86_64 Rosetta shell and from a native Apple Silicon shell, both have same issue.
So somehow this call is silently failing to properly enumerate the connected devices, but I'm not sure how else to continue debugging this. Alternatively, if someone just gives me a 2.14 binary for macOS (and windows) with libusb support compiled in and verified working, I will be happy and I don't need to do it myself!