if--like me--you've been through the ringer of 'intro to ...'-esque courses in engineering, you probably have one of these AVR-based microcontrollers 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
#include
int main (void) {
DDRB |= _BV(DDB5);
for (;;) {
PORTB |= _BV(PORTB5);
_delay_ms(1000);
PORTB &= ~_BV(PORTB5);
_delay_ms(1000);
}
}
emulation
with simavr
$ simavr --mcu atmega328p --freq 16000000 $FILE.elf