no-std avr-device

Register access crate for AVR microcontrollers

17 releases

0.5.4 Jan 28, 2024
0.5.3 Nov 17, 2023
0.5.2 Aug 24, 2023
0.5.1 Apr 8, 2023
0.1.1 Jul 31, 2020

#35 in Embedded development

Download history 743/week @ 2024-02-26 734/week @ 2024-03-04 791/week @ 2024-03-11 840/week @ 2024-03-18 671/week @ 2024-03-25 980/week @ 2024-04-01 648/week @ 2024-04-08 907/week @ 2024-04-15 939/week @ 2024-04-22 816/week @ 2024-04-29 711/week @ 2024-05-06 866/week @ 2024-05-13 826/week @ 2024-05-20 818/week @ 2024-05-27 833/week @ 2024-06-03 616/week @ 2024-06-10

3,237 downloads per month
Used in avr-progmem


805K SLoC

avr-device crates.io page docs.rs Continuous Integration

Auto-generated wrappers around registers for AVR microcontrollers.


Add the following to Cargo.toml:

version = "0.5.4"
features = ["atmega32u4"]

Via the feature you can select which chip you want the register specifications for. The following list is what is currently supported:

ATmega ATmega USB ATmega 0,1 Series AT90 ATtiny
atmega8 atmega8u2 atmega4808 at90usb1286 attiny13a
atmega48p atmega32u4 atmega4809 attiny167
atmega64 attiny202
atmega644 attiny402
atmega88p attiny404
atmega168 attiny44a
atmega324pa attiny84
atmega328p attiny85
atmega328pb attiny88
atmega32a attiny816
atmega1280 attiny828
atmega1284p attiny841
atmega128a attiny84a
atmega128rfa1 attiny861
atmega2560 attiny1614
atmega164pa attiny2313

Build Instructions

The version on crates.io is pre-built. The following is only necessary when trying to build this crate from source.

You need to have atdf2svd (= 0.3.3), svd2rust (= 0.28), form (>= 0.8), rustfmt(for the nightly toolchain) and svdtools (>= 0.1.9) installed:

cargo install atdf2svd --version 0.3.3
cargo install svd2rust --version 0.28.0
cargo install form
rustup component add --toolchain nightly rustfmt
pip3 install --user svdtools

# check svdtools
svd --version
# if a "command not found" error is printed instead of a version,
# either svdtools is installed incorrectly, or its installation path is missing from the PATH variable.
# Temporary solution to PATH variable issue is to manually add the path. Like so:
export PATH=$PATH:~/.local/bin

Next, clone this repo and build the device definitions:

git clone https://github.com/Rahix/avr-device
cd avr-device
# You can build for just one specific chip using
# make atmega32u4
# I suggest building documentation as well
cargo +nightly doc --features <chip> --open


avr-device is generated using atdf2svd and svd2rust. The vendor-provided atdf files can be found in vendor/. The intermediate svd files are patched by svdpatch.py (Adapted from svdpatch.py in stm32-rs) with device-dependent patches in patch/, mainly to improve undescriptive names and missing descriptions.

Adding a new Chip

To add a new chip, download the atdf from http://packs.download.atmel.com/ (or avr-mcu/packs/) and place it in vendor/. Be sure to name it like the Rust module that should be generated. Next, you need to integrate it into the base crate and build system. Follow what was done in commit 290613454fbd ("Add basic support for ATmega64"). Please adhere to the alphabetical sorting that is present so far.

Next, you must create a <chipname>.yaml in patch/ which has at least the following content:

_svd: ../svd/<chipname>.svd

If more patches need to be applied (most likely!), they should be added into this file as well. The patching format is documented in the svdtools README. Ideally, try to reuse the exisiting patches in patch/common/ or patch/timer/.

Finally, try building the crate for your MCU with make <chipname>.


avr-device is licensed under either of

at your option.

The vendored atdf files are licensed under the Apache License, Version 2.0 (LICENSE-VENDOR).