elf2nucleus

Crates.ioelf2nucleus
lib.rself2nucleus
version0.1.0
sourcesrc
created_at2024-01-05 03:00:48.437988
updated_at2024-01-05 03:00:48.437988
descriptionFlash an AVR firmware from an elf file with micronucleus
homepage
repositoryhttps://github.com/kpcyrd/elf2nucleus
max_upload_size
id1089222
size191,950
(kpcyrd)

documentation

README

elf2nucleus

Integrate micronucleus into the cargo buildsystem, flash an AVR firmware from an elf file.

# ./.cargo/config.toml
[target.'cfg(target_arch = "avr")']
# Choose a default "cargo run" tool
runner = "elf2nucleus"

Adding this to your cargo config should then allow you to use the cargo-native run command for flashing, without further need for a Makefile:

RUSTC_BOOTSTRAP=1 cargo run --release

Please note that elf2nucleus builds on top of micronucleus which needs to be installed too.

This project was inspired by elf2uf2-rs for the rp2040.

Also shoutout to @cyber-murmel who motivated me to develop this and helped me with AVR development.

Building firmware with cargo

To build an AVR firmware repository it's often enough to run:

RUSTC_BOOTSTRAP=1 cargo build --release

cargo then compiles the firmware and puts it into an elf container file like this:

target/avr-attiny85/release/attiny85-hello-world.elf

For this .cargo/config.toml needs to be configured correctly, an example repository can be found at github.com/kpcyrd/attiny85-hello-world.

Flashing with elf2nucleus

To invoke elf2nucleus without cargo, you can run it like this:

elf2nucleus ./attiny85-hello-world.elf

If you don't want to flash with elf2nucleus and instead read the firmware from an elf file into a raw binary file you can specify an additional output file name:

elf2nucleus ./attiny85-hello-world.elf ./firmware.bin
micronucleus --type raw --run --no-ansi ./firmware.bin

Using Rust with micronucleus directly

At the time of writing, it's not possible to configure micronucleus as "cargo run" tool, because micronucleus can't read from elf files.

If you want to avoid using elf2nucleus you can use avr-objcopy to prepare the firmware file yourself:

avr-objcopy --output-target=ihex target/avr-attiny85/release/attiny85-hello-world.elf target/avr-attiny85/release/attiny85-hello-world.hex
micronucleus --timeout 60 --run --no-ansi target/avr-attiny85/release/attiny85-hello-world.hex

License

GPL-3.0-or-later

Commit count: 0

cargo fmt