Rust on a Digispark ATtiny85
The Digistump Digispark is a tiny, simple, and cheap development board using the ATtiny85 MCU. While the official version is no longer for sale, clones are easily found online for around $2 each.
Rahix’s avr-hal
already supports the
ATtiny85 on the Adafruit Trinket
board.
The Trinket is nearly identical to the Digispark, but with a different USB
bootloader, so avr-hal
’s cargo run
support won’t work. Instead, you’ll need
to convert the output binary and deploy it with the micronucleus
CLI tool.
Prerequisites#
Micronucleus
Download the latest Micronucleus CLI for your platform.
binutils for AVR
On Ubuntu: sudo apt install binutils-avr
On MacOS: brew tap osx-cross/avr && brew install avr-binutils
Build and Deploy a simple PWM demo#
git clone https://github.com/Rahix/avr-hal
cd examples/trinket
cargo build
avr-objcopy --output-target=ihex ../../target/avr-attiny85/debug/trinket-simple-pwm.elf ../../target/avr-attiny85/debug/trinket-simple-pwm.hex
micronucleus --timeout 60 --run --no-ansi ../../target/avr-attiny85/debug/trinket-simple-pwm.hex
- Plug in your Digispark. Once the application is uploaded, the LED will start pulsing.
I’ve found that the Rust PWM example compiles to a much larger binary than the equivalent C code using Arduino libraries. (1265 bytes in Rust vs 888 bytes in C). I’m new to embedded Rust, so please let me know in the comments if you have any tips or resources for getting the size down.