Arduino Uno

if – like me – you've been through the ringer of 'intro to ...' courses in an engineering program, you probably have at least one of these AVR-based development boards stashed around somewhere. the obvious answer to a development environment is the official IDE, but the benefit provided loses a lot of its value outside of the educational/beginner context.

dependencies

pkgsCross.avr.stdenv.mkDerivation {
    # ...
    nativeBuildInputs = []; # packages executed by host
    buildInputs = []; # packages built into target
    # ...
}
sets CC=avr-gcc, using in a Makefile:
%.elf: %.c
    $(CC) -DF_CPU=16000000UL -mmcu=atmega328p $^ -o $@
a hex formatted file is often flashed to the device. using avr-objcopy,
%.hex: %.elf
    $(OBJCOPY) -O ihex -R .eeprom $^ $@

flashing

a hex file with avrdude
$ avrdude -F -V -c arduino -p ATMEGA328P -P $TTY -b $BAUD -U flash:w:$FILE.hex
e.g. TTY=/dev/ttyACM0, BAUD=115200.

code sample

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

int main (void) {
    DDRB |= _BV(DDB5);

    while (1) {
        PORTB |= _BV(PORTB5);
        _delay_ms(1000);
        PORTB &= ~_BV(PORTB5);
        _delay_ms(1000);
    }
}

emulation

with simavr
$ simavr --mcu atmega328p --freq 16000000 $FILE.elf

trace dumps

TODO

gdb debugging

TODO