https://github.com/kpcyrd/elf2nucleus
Integrate micronucleus into the cargo buildsystem, flash an AVR firmware from an elf file
https://github.com/kpcyrd/elf2nucleus
attiny85 avr rust rust-embedded
Last synced: 6 months ago
JSON representation
Integrate micronucleus into the cargo buildsystem, flash an AVR firmware from an elf file
- Host: GitHub
- URL: https://github.com/kpcyrd/elf2nucleus
- Owner: kpcyrd
- License: gpl-3.0
- Created: 2024-01-05T02:32:54.000Z (about 2 years ago)
- Default Branch: main
- Last Pushed: 2024-01-05T03:01:36.000Z (about 2 years ago)
- Last Synced: 2025-03-28T03:12:45.630Z (12 months ago)
- Topics: attiny85, avr, rust, rust-embedded
- Language: Rust
- Homepage: https://crates.io/crates/elf2nucleus
- Size: 54.7 KB
- Stars: 6
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# elf2nucleus
Integrate micronucleus into the cargo buildsystem, flash an AVR firmware from an elf file.
```toml
# ./.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:
```sh
RUSTC_BOOTSTRAP=1 cargo run --release
```
Please note that elf2nucleus builds on top of [micronucleus](https://github.com/micronucleus/micronucleus) which needs to be installed too.
This project was inspired by [elf2uf2-rs](https://github.com/JoNil/elf2uf2-rs) for the rp2040.
Also shoutout to [@cyber-murmel](https://github.com/cyber-murmel) who motivated me to develop this and helped me with AVR development.
[](https://repology.org/project/elf2nucleus/versions)
## Building firmware with cargo
To build an AVR firmware repository it's often enough to run:
```sh
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](https://github.com/kpcyrd/attiny85-hello-world).
## Flashing with elf2nucleus
To invoke elf2nucleus without cargo, you can run it like this:
```sh
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:
```sh
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:
```sh
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`