Skip to content

Instantly share code, notes, and snippets.

@jonahbron
Last active October 31, 2020 16:30
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jonahbron/640a825dd9a526d3a1c24f2c20ca44ac to your computer and use it in GitHub Desktop.
Save jonahbron/640a825dd9a526d3a1c24f2c20ca44ac to your computer and use it in GitHub Desktop.
Install AVR Rust and Compile Blink
git clone git@github.com:avr-rust/rust.git avr-rust
cd avr-rust
git checkout avr-support # 8405b30 at time of writing
cp config.toml.example config.toml
# Manually uncomment experimental-targets setting in config.toml
./x.py build
rustup toolchain link avr $(realpath $(find build -name 'stage2'))
cd ../../
wget https://downloads.arduino.cc/arduino-1.8.12-linux64.tar.xz
tar -xf arduino-1.8.12-linux64.tar.xz
git clone git@github.com:avr-rust/blink.git
cd blink
# set the linker to the toolchain from Arduino, and explicitly disable -pie
# use cargo built from avr-rust. Path will be different depending on system.
XARGO_RUST_SRC="$(realpath ../avr-rust/src)" \
RUSTFLAGS="-C linker=$(realpath $(../arduino-1.8.12/hardware/tools/avr/bin/avr-gcc)) -C link-args=-no-pie" \
rustup run avr ../avr-rust/build/x86_64-unknown-linux-gnu/stage0/bin/cargo xbuild --target avr-unknown-unknown --verbose
@bburky
Copy link

bburky commented Apr 9, 2020

The compiled .elf can be flashed with something along the lines of:

avr-objcopy -O ihex .\target\avr-atmega328p\release\blink.elf blink.hex
avrdude -patmega328p  -b 57600 -c stk500v1 -PCOM4 -U flash:w:blink.hex

@bburky
Copy link

bburky commented Apr 9, 2020

Installing the gcc avr toolchain can be done on Ubuntu with:

apt install gcc-avr avr-libc binutils-avr avrdude

@Rahix
Copy link

Rahix commented Apr 9, 2020

avr-objcopy -O ihex .\target\avr-atmega328p\release\blink.elf blink.hex

I added a script for this in avr-hal: mkhex.sh

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment