[Dev Log] Knock : Part 3

So I am lazy and I like working on a linux environment. Don't get me wrong I love the Atmel Studio, it's got a lot of stuff, it's easy to use and it's got a great programming/debugging tool. But command line has its own charm. So here I explore/log how I programmed a custom board using AVR ISP MKII.


Ah Mac OS X. You're so silly. Almost makes me want to punch you in the face. But, I won't, you're expensive and you have a great package manager called Machomebrew. So I simply used it and did this

DarkSector@DarkBook:~$ brew update
DarkSector@DarkBook:~$ brew install libusb avr-binutils avr-gcc avr-libc avra avrdude

Sweet, that went well. Now simply to go and write the code and generate the .hex or .elf files

Compiling and linking

AVR GCC, like the normal GCC follows the normal procedure of compiling linking etc. So this is the ATTiny2313 blink code and the set of commands to generate the hex file

//Author: DarkSector
#define F_CPU 1000000UL

#include <avr/io.h>
#include <util/delay.h>

int main(void) {

    DDRB |= _BV(DDB4);

    while(1) {

        PORTB |= _BV(PORTB4);
        PORTB &= ~(PORTB);

    return 0;

The commands are as follows

DarkSector@DarkBook:~/Code/AVR/c/blinky$ avr-gcc -g -Os -mmcu=attiny2313 -c blinky.c 
DarkSector@DarkBook:~/Code/AVR/c/blinky$ avr-gcc -g -mmcu=attiny2313 -o blinky.elf blinky.o
DarkSector@DarkBook:~/Code/AVR/c/blinky$ avr-objcopy -j .text -j .data -O ihex blinky.elf blinky.hex


I used this fuse calculator to calculate the fuses for the AVR. I should be looking at the datasheet and calculating the fuses using math but this is just to test if my stuff is working. After having calculated the fuse values, let's just go ahead and program the board

DarkSector@DarkBook:~/Code/AVR/c/blinky$ avrdude -p attiny2313 -c avrispmkII -P usb -U lfuse:w:0x64:m -U hfuse:w:0xdf:m -U efuse:w:0xff:m -e -D -U flash:w:blinky.hex -vvvv

This burns the .hex file on to the chip. Surprisingly it takes more time than the Atmel Studio Device Programmer. Once this worked and I rejoiced I erased the chip because the LED was hurting my eyes.

DarkSector@DarkBook:~/Code/AVR/c/blinky$ avrdude -p attiny2313 -c avrispmkII -P usb -U -e -vvvv

Interestingly the port is USB. On linux you might have something like /dev/ttyUSB1 or something. Anyway this is how I got it working on Mac OS X 10.9 (Mavericks). I am now going to create a BASH script and possibly experiment with AVRDUDE's config files. I might have to go through the make routine so that I don't have to go through the routine of linking etc.. Okay, time to get to it.

AVR GCC commands .