31 Aug 2019

How to setup AVR programming environment on macOS. Step-by-step guide

This is a lightweight and easy to setup AVR dev programming instruction where we will use AVR 8-bit Toolchain 3.6.2 - Mac OS X 64-bit and will not use the old CrossPack. By the way, GNU Toolchain Documentation is here.


Let's start!
----------------->

AVR Toolchain Installation (Compiler, Assembler, Linker, Librarian, C Library, etc)


1. Download sh script from here
2. Run it. sudo sh <path>/install_toolchain.sh

1. Download sh script from here
2. Run it. sudo sh <path>/avr_toolchain_install.sh
3. Reboot your machine and test it using the terminal command avr-gcc -v 

You should get the answer: gcc version 5.4.0 (AVR_8_bit_GNU_Toolchain_3.6.2_503)

AVR Programmer Installation (Avrdude)


Before this we need to install libusb, you can get it here (I use libusb-1.0.23.tar.bz2)
Unzip, navigate, install:
1. sudo ./configure
2. sudo make
3. sudo make install

then move through these steps:

1. Download the current release of avrdude here (I use avrdude-6.3)
2. Unzip the downloaded file. In a Terminal window, navigate to the avrdude directory: cd <path>/avrdude-6.3
3. Configure avrdude. type: sudo ./configure
4. Compile avrdude. type: sudo make
5. Install avrdude. type: sudo make install
6. Test it by feeding the terminal with  avrdude -version

You should get the answer: avrdude version 6.3


Thanks to all of avr funs we have done with the software part!

Compiling an Example (for the cutiest ATTiny13 chip)


1. Get the example here
2. Navigate to the example directory cd <path>/example
3. Compile the code: avr-gcc -Wall -g -Os -mmcu=attiny13 -o main.bin main.c
4. Check program and data memory size: avr-size -C main.bin
5. Generate a HEX file for a programmer: avr-objcopy -j .text -j .data -O ihex main.bin main.hex



Time to flash the chip!

Flashing the chip


1. Connect USBasp programmer (You don't need a driver on macOS)
2. Move into the project's directory
3. Open terminal and type: avrdude -p attiny13 -c usbasp -U flash:w:main.hex:i

You should get the answer: avrdude: error: program enable: target doesn't answer. 1 
That means we are ready to connect real MCU and try again



How to setup AVR programming environment on macOS.

Troubleshooting

1. ----------------------------------------
avrdude: error: program enable: target doesn't answer. 1
avrdude: initialization failed, rc=-1
Double check connections and try again, or use -F to override
this check.


Solution -> Use slow programming speed by adding flag B 1 - B 400 like this:
avrdude -p attiny13 -B 4 -c usbasp -U flash:w:main.hex:i


Files

Adafruit avrdude documentation is here.
All files are here

Popular Posts