#avr #serial #thread #pin #atmel #stack #oxide

nightly avr-oxide

An extremely simple Rusty operating system for AVR microcontrollers

14 releases

0.4.1 Apr 18, 2023
0.4.0 Jun 19, 2022
0.3.1 Apr 26, 2022
0.2.2 Jan 16, 2022
0.0.0 Aug 22, 2021

#417 in Hardware support

Download history 31/week @ 2023-06-07 14/week @ 2023-06-14 43/week @ 2023-06-21 21/week @ 2023-06-28 34/week @ 2023-07-05 32/week @ 2023-07-12 28/week @ 2023-07-19 9/week @ 2023-07-26 5/week @ 2023-08-02 11/week @ 2023-08-09 24/week @ 2023-08-16 19/week @ 2023-08-23 21/week @ 2023-08-30 26/week @ 2023-09-06 8/week @ 2023-09-13 7/week @ 2023-09-20

62 downloads per month
Used in 2 crates


11K SLoC

Contains (ELF exe/lib, 33KB) crtatmega4809.o, (static library, 29KB) libatmega4809.a


An extremely simple Rust runtime for AVR microcontrollers.

For more information and documentation, see the AVRoxide site.


AVRoxide was borne out of my frustration with attempting to develop for an Arduino Nano Every microcontroller board using the Rust programming language.

The Arduino Nano Every uses a different version of AVR microcontroller to the other Arduino family of boards - the ATmega4809. While there are HAL[^1] crates available for various Arduino boards, none of them works with this microcontroller, and that's a shame - it's actually a super nice chip and a good upgrade on the ones used in the 'traditional' Arduino boards. So, support for it in Rust would obviously be nice to have.

How we got here

Naturally, the first thing I tried to do was to adapt some of the existing HALs to work with the Nano Every. But this turned out to be a little trickier than I anticipated, and in any event I discovered there were some things that I didn't like about those HALs. This is in no way a reflection on the quality of thoes HALs - much more a reflection on my Rust abilities - but I found I wanted something a little simpler and easier to understand.

And so, the idea of putting together my own HAL come to mind. But, I also wanted to move a little higher up the pipeline - not just to abstract away the hardware, but also to put in place some standard patterns for things like a standard event loop that would hide some of the details of things like interrupt handling from the application developer.

Thus, AVRoxide is born! The Rusty runtime for AVR microcontrollers.

Supported Microcontrollers

  • ATmega 4809 (used on Arduino Nano Every)
  • ATmega 328P (used on Arduino Uno, Arduino Pro Mini and Arduino Nano)

Note that '328P support is currently at a very, very early stage, with only basic port pins and serial USARTs working. This chip also brings a new set of Rust/LLVM code generation bugs and challenges, and I haven't worked out how to deal with them all yet.


Getting started guides are at https://avroxi.de/categories/gettingstarted/


This is a work in progress

It currently is functional, with a whole bunch of caveats about the readiness of Rust on AVR generally, and usable to build simple programs.

The intention is to expand it beyond the minimal set of devices currently supported, in due course.

Now and forever - use at your own risk :-).

THERE ARE HEISENBUGS Particularly involving multithreading. Since I have reached a point of total exasperation attempting to track them down, for the timebeing I'm going to worry about other things and hope I come across the solution while working on something else. So, really really, don't use this for anything critical right now - consider it an adventure game :-).

Rust Toolchain

AVRoxide is built using the nightly Rust toolchain for AVR. Since 10th May 2022, you can use the regular nightly toolchain - thank you to Patryk27 for getting it working!


A new bug was released in October 2022, and the last working version of the toolchain is nightly-2022-10-22. You can force your builds to use this by adding the following to your rust-toolchain.toml:

channel = "nightly-2022-10-22"

If you want to follow the progress of the fix to this bug, you can see it here - pull #106619

A Docker image containing a known-working version of the toolchain is also available on Docker Hub. This is the version used in my CICD to test the build; if you want to verify you can pull the same version using:

docker pull snowgoons/avr-rustbuilder:nightly-2023-04-18

Note that despite the later image date, this image also has the working nightly-2022-10-22 toolchain and sources pre-installed.

[^1]: Hardware Abstraction Layer


~38K SLoC