Skip to content
embedded-hal abstractions for AVR microcontrollers
Rust Shell
Branch: master
Clone or download
Rahix i2c/uart: Fix macros for latest avr-device
By updating to svd2rust v1.16.1, a few previously safe function have
unfortunately become unsafe.  Wrap calls to them in unsafe blocks to
make avr-hal compile again.

Signed-off-by: Rahix <>
Latest commit 0aef1a6 Oct 21, 2019


embedded-hal implementations for AVR microcontrollers. Based on the register definitions from avr-device.


Go into ./boards/arduino-leonardo, and run the following commands:

# Tell rustc where the target description can be found
# (it is in this directory)
export RUST_TARGET_PATH="$(pwd)"

# Set the toolchain to your avr toolchain.  The name might
# be different, depending on how you installed avr-rust.

# xargo needs a path to the rust sources to build libcore.
export XARGO_RUST_SRC="/path/to/avr-rust/src"

# Now you are ready to build your first avr blink example!
xargo build --target avr-atmega32u4 --example leonardo-blink --release

# Finally, convert it into a .hex file that you can flash using avr-dude
../../ --release leonardo-blink

ls -l ../../target/leonardo-blink.hex

Starting your own project

You need at least the following:

  • A target description for the chip you are using. In most cases, just copy the one from this repo.
  • The Xargo.toml file, as found in this repo.
  • The Cargo profiles, as found in Cargo.toml of this repo.
  • Add the board-support-crate for your hardware as a dependency, and also include panic-halt to provide a panic implementation.

In the end, your Cargo.toml should contain the following:


panic-halt = "0.2.0"

path = "/path/to/avr-hal/boards/arduino-leonardo"

panic = "abort"
codegen-units = 1
incremental = false
lto = true

panic = "abort"
codegen-units = 1
debug = false
lto = true


This repository contains the following components:

  • A generic crate containing implementations that can be used chip-independently and macros to create chip-dependent instances of peripheral abstractions. This crate is named avr-hal-generic.
  • HAL crates for each chip in chips/. These make use of avr-hal-generic to create chip-specific definitions.
  • Board Support Crates for popular hardware in boards/. They, for the most part, just re-export functionality from the chip-HAL, with the names that are printed on the PCB.


The following peripherals are supported in avr-hal-generic:

  • A spinning delay implementation
  • PORTx peripherals as digital IO (v2)
  • A TWI based I2C implementation

HAL Status

The chip-HAL crates currently support the following peripherals:

  • atmega328p-hal
    • Spinning Delay
    • PORTB, PORTC, PORTD as digital IO (v2)
    • USART0 for serial communication
    • I2C using TWI
  • atmega32u4-hal
    • Spinning Delay
    • PORTB, PORTC, PORTD, PORTE, PORTF as digital IO (v2)
    • USART1 for serial communication
    • I2C using TWI
  • attiny85-hal
    • Spinning Delay
    • PORTB as digital IO (v2)

Supported Hardware

In boards/ there are crates for the following hardware. Please note that this project is in no way affiliated with any of the vendors.


This project is not affiliated with either Microchip (former Atmel) nor any of the Vendors that created the boards supported in this repository.


avr-hal is licensed under either of

at your option.

You can’t perform that action at this time.