Toolchains

The Arduino Uno is a ubiquitous single-board microcontroller, omnipresent in beginner electronics and programming tutorials. Anyone that's been through engineering 'intro to ...' courses after 2010 likely has at least one of these.

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

With Nix,
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
#