Skip to content

Instantly share code, notes, and snippets.

@JohnPhamous
Last active March 3, 2024 16:15
Show Gist options
  • Save JohnPhamous/62949081fc40c8d4f14dbb13b118ade3 to your computer and use it in GitHub Desktop.
Save JohnPhamous/62949081fc40c8d4f14dbb13b118ade3 to your computer and use it in GitHub Desktop.

AVR Programming on Linux/Mac OS

Dependencies for Mac

Mac users will need to install Homebrew. Homebrew is a package manager for MacOS.

ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

You will then need to install avr-libc from the avr repository.

brew tap osx-cross/avr

Now you can install it.

brew install avr-libc

You will also need avrdude to handle the C to hex code conversion and programming the microcontroller.

brew install avrdude --with-usb

Dependencies for Linux (Ubuntu)

You can install the avr dependencies with

sudo apt-get install gcc-avr binutils-avr avr-libc

If you want to use the debugging environment, you will install an additional package

sudo apt-get install gdb-avr

You will also need avrdude to handle the C to hex code conversion and programming the microcontroller.

sudo apt-get install avrdude

The build process

You will need to write your program in C. If we have a file called blink.c and we want to program our ATmega1284, we can run the following commands.

avr-gcc -g -Os -mmcu=atmega1284 -c blink.c

avr-gcc -g -mmcu=atmega1284 -o blink.elf blink.o

avr-objcopy -j .text -j .data -O ihex blink.elf blink.hex

avr-size --format=avr --mcu=atmega1284 blink.elf

You've now created the .hex file that will be used by your microcontroller. To program your program your microcontroller (assuming the 1284), you will run the following commands.

avrdude -c atmelice_isp -p m1284 -P /dev/ttyUSB0 -b 19200 -U flash:w:blink.hex

@NChilds86
Copy link

         gidday have tried to run the home-brew install link on my Mac via the link using my terminal and getting a return error 404 url not found. cheers

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment