Last active
October 31, 2020 16:30
-
-
Save jonahbron/640a825dd9a526d3a1c24f2c20ca44ac to your computer and use it in GitHub Desktop.
Install AVR Rust and Compile Blink
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
git clone [email protected]: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 [email protected]: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 |
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
Installing the gcc avr toolchain can be done on Ubuntu with:
apt install gcc-avr avr-libc binutils-avr avrdude
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
The reason for using the stage0 version of
cargo
is that it's version (1.36.0-beta) is compatible with the 1.37.0rustc
from theavr-support
branch.If you use a current (1.42.0 for example) version of
cargo
it will pass incompatible flags--error-format=json --json=diagnostic-rendered-ansi
to 1.37.0rustc
:The
error: Unrecognized option: 'json'
errors refer to the incompatible--json
flags.