`avr-hal` logo

`avr-hal`

Free

HAL for AVR microcontroller family and AVR-based boards

FreeFree tier
Type
Open Source

About `avr-hal`

avr-hal is a Hardware Abstraction Layer (HAL) for AVR microcontrollers and common boards like Arduino, written in Rust. It builds on the avr-device crate and provides embedded-hal abstractions for ATmega and ATtiny families. The repository includes arduino-hal (a batteries-included HAL for Arduino-like boards), MCU-specific HALs (atmega-hal, attiny-hal), a generic crate (avr-hal-generic) for driver development, and ravedude—a utility that integrates flashing and serial console into the cargo workflow. It offers numerous examples for common hardware and a project template (avr-hal-template) to quickly start new projects.

Key Features

Provides embedded-hal abstractions for AVR microcontrollers (ATmega, ATtiny)
Batteries-included arduino-hal for Arduino Uno, Nano, Mega, etc.
Includes ravedude utility for seamless flashing and serial console via cargo
Extensive examples directory for common hardware (e.g., blink, UART, I2C)
avr-hal-generic crate for writing drivers compatible with any AVR chip
Project template (avr-hal-template) for quick setup with cargo-generate
Based on avr-device and supports nightly Rust via rust-toolchain.toml

Pros & Cons

Pros
  • Open source (MIT/Apache-2.0 license) with an active GitHub community
  • Built on the well-established embedded-hal traits for portability
  • Ravedude simplifies the build-flash-monitor loop, similar to Arduino IDE
  • Supports a wide range of AVR MCUs (ATmega, ATtiny) and common Arduino boards
  • Includes many examples that are easy to adapt for different boards
Cons
  • Requires nightly Rust compiler (stable not supported for AVR targets)
  • Not all examples have been ported to every supported board
  • Limited to AVR architecture; not applicable for ARM or other MCUs
  • Ecosystem less mature than the C/C++ Arduino ecosystem in terms of library availability

Best For

Embedded Rust development on AVR microcontrollers (Arduino, custom boards)Learning embedded systems programming with RustBuilding IoT devices and sensor interfaces using AVR chipsReplacing C/C++ Arduino sketches with safer Rust codeDeveloping hardware drivers that work across multiple AVR families

FAQ

How do I install dependencies for avr-hal on Ubuntu?
Run: sudo apt install avr-libc gcc-avr pkg-config avrdude libudev-dev build-essential
How can I start a new project using avr-hal?
Use the avr-hal-template with cargo-generate: cargo install cargo-generate; cargo generate --git https://github.com/Rahix/avr-hal-template.git
What tool is used to flash code to the board?
Ravedude is included; it integrates avrdude into cargo. After configuration, run 'cargo run --bin <example>' to build and flash.
Which AVR microcontrollers are supported?
The avr-hal supports many ATmega and ATtiny MCUs. See the mcu/atmega-hal and mcu/attiny-hal crates for specific lists.