Programming an Arduino UNO with the Atmel ICE from macOS command line (or S4A IDE)

Hardware always makes it into the Swift for Arduino IDE by going through a trial on the macOS command line first. I have various test rigs that I use to get hardware and systems working there first.

I found it pretty hard to find documentation on how to program using macOS / open source software (not using the AVR Studio IDE or MPLab).

I've just bought a shiny, new ATATMEL-ICE programmer/debugger with cables for $100 and I'm itching to get it working.

First task, make a simple blink program and upload it.

Lots of obstacles! I'm putting some of the things I've found in here, if for no other reason than to save people several hours of googling.

First, which program do we run to connect to the Atmel-ICE? It seems like for AVR, good old avrdude is OK. As is often the case, the cool community at Platform.IO have some discussion on it...

https://community.platformio.org/t/upload-and-debug-for-atmega328p-with-atmel-ice/18796/2

Next problem, which cable??

OK, this page from Atmel/Microchip seems to help:

https://microchipdeveloper.com/atmelice:connecting-to-avr-and-sam-target-devices

But now the 6-pin 100-mil ISP header can go in two ways round, which is right??

With a combination of this page: http://www.batsocks.co.uk/readme/isp_headers.htm and this: https://arduino.stackexchange.com/questions/30024/male-header-pins-on-arduino-uno it looks like the sticky out bit faces inward!


OK, that seems to give the right command line and connections, something like this...

avrdude -c atmelice_isp -p atmega328p -V -P usb -e -U flash:w:main.hex

But now I get strange permission errors...

avrdude: usbdev_open(): error claiming interface 0: Permission denied

avrdude: usbdev_open(): no usable interface found

avrdude: jtag3_open_common(): Did not find any device matching VID 0x03eb and PID list: 0x2141

So, someone else has seen this problem with macOS from High Sierra onwards

https://medium.com/@davidramsay/avrdude-and-atmel-ice-on-osx-10-3-high-sierra-a0185b4e280a

Note: I'd add more to this. Once you've downloaded Nicholas Sayer's kext and copied it to /Library/Extensions, you need to change the permissions on it to root.

To do this, in a terminal, do...

sudo su

...to get a root shell, then...

chown -R root /Library/Extensions/AtmelICE.kext

to change the permissions to match those required for a kext.

If (like me) you try to install it before doing this, you end up with a "cached" version of the kext that you can't change permissions on because it's in one of macOS's magic directories. To remove that version, clear the cache...

https://discussions.apple.com/thread/8639095


Finally, you'll need to use kextutil instead of kextload...

kextutil /Library/Extensions/AtmelICE.kext

And, if it isn't clear from Nicholas' instructions, loading the kernel extension will fail on the first tries because it won't like the code signing or notarising or something. Use the same trick you would do if you're opening a normal program that's not notarised... try it once, you get an error, go into System Preferences, Security, you'll see a mention that the kext tried to load, press the Allow anyway button. Then try loading it again.

This all seems bitrot up to Catalina. Big Sur and Monterrey probably change it again!

The reasons for Apple's super tight security are sound... malware would love a chance to jump in as kexts all over the place.. but it's sure hard...


Anyway... did all the above but it still didn't work.. Sigh.


Anyone feel free to comment.


Bonus points

***

How do we debug AVR chips?


Comments

Popular posts from this blog

Halloween LED lights on a plastic trick or treat cauldron

All about bootloaders

code signing, entitlements, bundles, sandboxes, hardened runtime, notarisation, app store security