Avrdude is the workhorse for programming AVR chips from Atmel (now Microchip). It works flawlessly on all platforms with a huge number of different programmers. There are a few exceptions, though. The Atmel-ICE, a very decent programmer and debugger, could not be used under macOS (>10.13). But finally there seems to be light …

Before Sierra (10.12), one could interface to the Atmel-ICE without any problem. Under High Sierra (10.13), one needed a kernel extension. And with Mojave (10.14), Catalina (10.15) and Big Sur (11), you just did not have a chance. The reason for that is that Atmel-ICE is a USB HID (a human interface device) and these devices are grabbed by macOS, when they plugged in. The typical error message you got when running avrdude was:

     avrdude: usbdev_open(): Found Atmel-ICE CMSIS-DAP, serno: Jxxxxxxxxxxx
     avrdude: usbdev_open(): error claiming interface 0: Permission denied
     avrdude: usbdev_open(): no usable interface found 

Brian Good noted in March 2021 that the way to go is to use the HIDAPI library, which permits access to HID devices. So he came up with installing the HIDAPI library and patching a GitHub copy of the original avrdude code, which resulted in a working version of avrdude. I tried it out and it worked. Hurrah!

Joerg Wunsch, one of the original authors of avrdude noted in an exchange about the problem that the patch is already in the official code base. I tried it out and failed initially. The next day it worked — I do not know why.

To make life easier for everybody, I decided to design a homebrew formula that is able to download the right version of avrdude with HIDAPI included. If you have not heard of homebrew, or you have not installed it yet, it is high time to do so. It is the way to get all the goodies that have been developed for Unix, which Apple has missed including.

While trying to develop the right formula, I learned a bit about homebrew and finally came up with the following recipe for you. First uninstall your current copy of avrdude installed by homebrew:

      brew uninstall avrdude

After that, install a version, which is generated from the most recent code:

      brew install --HEAD felias-fogg/arduino/avrdude

If there are error messages, you might need to remove older versions of avrdude and then link the installed files to /usr/local using:

      brew link avrdude

By now, you should be able to use the Atmel-ICE using avrdude, e.g.:

     avrdude -c atmelice_isp -p m328p -v -t

When you want to use the new version of avrdude also in the Arduino IDE, you may want to symlink to your newly installed avrdude binary:

rm /Applications/Arduino.app/Contents/Java/hardware/tools/avr/bin/avrdude
ln -sf /usr/local/bin/avrdude /Applications/Arduino.app/Contents/Java/hardware/tools/avr/bin/

It turns out that the last suggestion (which I struck out) is wrong for three reasons. First, the Arduino IDE on the Mac uses the avrdude binaries stored under ~/Library/Arduino15/packages/arduino/tools/avrdude/6.3.0-arduino18/bin/avrdude. Second, the current Arduino version of avrdude, which is maintained in this GitHub repository, is able to talk with the Atmel-ICE. However, it seems to contain bugs that have been corrected in the official code base. Namely, the Arduino avrdude version cannot read fuses or lock bits right after lock bits have been changed using the Atmel-ICE. Third, the Arduino avrdude version reads undefined bits as zero instead of one. So, with the new version that I propose to use, you run into problems when you use the Arduino IDE command Burn Bootloader in the Tools menu. I do not care much, since I have not used this command and do not plan to use it in the future.

Views: 88