3.3. Example - Building the blink program for AVR

This shell snippet shows an example that will build the LED blinking example for AVR.

# fetch and prepare the blink crate (only needs to be done once).
$ git clone https://github.com/avr-rust/blink.git
$ cd blink
$ rustup override set nightly

# Configure the 'ruduino' crate with a MCU frequency of 16MHz
$ export AVR_CPU_FREQUENCY_HZ=16000000

# compile the blink crate to an ELF file targeting atmega328p.
$ cargo build -Z build-std=core --target avr-atmega328p.json --release

After compilation, the final ELF executable will be available at target/avr-atmega328p/release/blink.elf, ready to be flashed to a device or ran inside a simulator.

$ file target/avr-atmega328p/release/blink.elf
target/avr-atmega328p/release/blink.elf: ELF 32-bit LSB executable, Atmel AVR 8-bit, version 1 (SYSV), statically linked, with debug_info, not stripped

Other AVR microcontroller models may be targeted by simply copying and modifying avr-atmega328p.json.