Toolchains
Arduino Uno
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
# ...
}
CC=avr-gcc
, using in a Makefile
:
%.elf: %.c
$(CC) -DF_CPU=16000000UL -mmcu=atmega328p $^ -o $@
avr-objcopy
,
%.hex: %.elf
$(OBJCOPY) -O ihex -R .eeprom $^ $@
flashing
a hex file withavrdude
$ avrdude -F -V -c arduino -p ATMEGA328P -P $TTY -b $BAUD -U flash:w:$FILE.hex
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
withsimavr
$ simavr --mcu atmega328p --freq 16000000 $FILE.elf