How it all started…
One of the classes I’m currently taking requires the setup of the AVR Toolchain on my personal rig. The instruction given by the professor claims that it will only work on “Intel Macs”, which got me wondering if it really is the case. Is it possible to install it on an M1 Mac? Thus, the journey down the rabbit hole started… with me sinking hours into researching for solutions that only a few people encountered online…
Thanks to the great work of many GitHub community members, the installation of the AVR Toolchain and GDB has nearly been flawless. The bug that I spent the majority of my time on was patched by the time I am writing this article. Although there are still some tweakings needed.
The majority of the steps mentioned in this article come from the instruction manual distributed by Professor Philip Brisk and his TAs, with some tweaks added.
1. Installing Xcode developer tools
Use this command to make sure you have the newest version of Xcode developer tools installed:
2. Installing Homebrew
Install Homebrew if you don’t have one installed.
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
3. Setting up avr-gcc, avr-gdb, simavr, avrdude
Add the repository containing AVR Toolchain for MacOS to Homebrew.
brew tap osx-cross/avr
Note: Please install these packages in the order listed below, as there will be dependency problems if you don’t.
brew install avr-gcc
brew install avr-gdb
brew install simavr
Note: if you encounter error like this: “osx-cross/avr/simavr is a head-only formula”, use the following command instead:
brew install --HEAD osx-cross/avr/simavr
brew install avrdude
Note: Running AVRDUDE on macOS High Sierra or higher will require some extra steps due to extra layers of security in most recent macOS updates. Follow the steps of this Medium post to be able to program your microcontroller.
4. Installing GTKWave
brew tap homebrew/cask
brew cask install gtkwave
You’ll also need Perl’s Switch module to run GTKWave, install them using:
sudo cpan install Switch
After installation, use this command to check where the Switch module is installed:
Note: If the output looks something like this:
/usr/local/Cellar/perl/..., copy it to
/Library/Perl/5.*/ using this command:
sudo cp /usr/local/Cellar/perl/5.*/lib/perl5/site_perl/5.*/Switch.pm /Library/Perl/5.*/
(5.* indicates your Perl version number, it may vary from machine to machine. Replace it as needed.)
You should now be able to run GTKWave using the following commands:
If it does run, you can add the following line to
or you can add this line too:
To apply the updated settings to your
~/.bash_profile, run the following command:
5. Installing GNU Debugger (GDB)
Now, this is where the tweaking begins…
First, make sure you have Python3 installed using the following command:
If it is not installed, use the following command to install it:
brew install python
Make a folder to install GDB (Replace <gdb-installation-folder> with a name of your folder):
Unzip the downloaded file into <gdb-installation-folder>.
Change directory into <gdb-installation-folder> and run the following commands:
(Replace <version number> with whatever version of GDB you downloaded)
sudo ./gdb-<version number>/configure --target=avr --with-python=python3
Now you will run into a compiler error that looks something like this:
Follow the warning and add
../.././gdb-9.2/sim/avr/../common/sim-core.c:75:2: error: implicitly declaring library function 'free' with type 'void (void *)' [-Werror,-Wimplicit-function-declaration]
../.././gdb-9.2/sim/avr/../common/sim-core.c:75:2: note: include the header or explicitly provide a declaration for 'free'
2 warnings and 1 error generated.
#include <stdlib.h> to the beginning of the files mentioned in the error message and recompile.
Note: Similar errors will show up multiple times as there are multiple files missing
#include <stdlib.h>. Correct all of them until it successfully compiles.
You’ve successfully set up the environment you needed! Enjoy! Leave a comment below if you encountered any problems!