Rust для arduino

Jake Goulding

We have an Arduino Uno that’s been sitting around gathering dust for a little while, so I decided to see how Rust worked on it.

A bit of searching led to a fork of Rust with AVR support, AVR-Rust. This is built on top of a fork of LLVM with AVR support, AVR-LLVM. Both of these projects are led by Dylan McKay.

The current documentation for AVR-Rust is a bit lacking, and it was forked from a development version of Rust 1.4. The current development version is Rust 1.7, making the fork about 4.5 months old. However, the changes to LLVM are in the process of being merged into upstream, laying the groundwork for merging the changes into Rust as well.

Let’s start out by doing the bare minimum and try to get a version of rustc that can target the AVR chip:

You’ll note that there’s nothing AVR specific here. Every Rust compiler is actually a cross-compiler, a compiler that executes on one architecture but produces code for another architecture. Because this fork of Rust has support files for AVR, it will be able to produce the correct executable code.

So I did what any sane person would do – I started changing code without knowing exactly what the failure was or what the code I was changing did.

First I tried updating the branch of LLVM that AVR-Rust uses. There are two branches in the repository – avr-support is more actively updated and avr-rust-support lags behind.

Merging avr-support into avr-rust-support went smoothly, but the Rust LLVM driver code needed to be updated to handle the newer LLVM version. I grabbed the diff from the main Rust repository and applied that. This seemed to work, but then I got a segfault from the stage 1 Rust compiler, deep in the internals of LLVM.

So I continued changing more stuff!

I merged current Rust into the AVR fork of Rust and resolved the merge conflicts as best I could figure out. After fixing a few new errors and some poor merge conflicts, I was on my way. Until I hit the segfault again.

That means it’s actually time to try to figure out where the segfault was coming from. I configured another build with some debug information:

And built. This takes a long time, as nothing gets optimized. And then it turns out that doing this also hides the segfault. Ugh.

However, I do get to a new error:

Fortunately, I know where to tweak that in the source. The downside is I’ll need to wait for another long build cycle…

Posted by Jake Goulding Jan 2 nd , 2016 arduino, rust


Rust для arduino

On my first stream of the new year (2021), I ended up having a new camera and I realized that it could zoom in. I thought and said «Wouldn’t it be cool to have a little switch that could do the Zoom so I could turn it and it would zoom in?» This was an ambitious goal so for now to learn I decided to take a step back and learn how to work with and RGB LED and understand more about the code.

I’m going to break this down into two parts: 1) how I setup up the hardware and 2) how I setup the software.



The material I used:

  • Arduino Uno
  • Breadboard (Standard Soderless)
  • Wires (6, at least)
  • Resistor (3, 330 Ohm)

Here is a photo of the final product:

Setting up the Board

If you’ve never done the wiring for a board before or wanted to have a written copy of what I did in the photo, this is for you!

I put the RGB LED into slots C4, C5, C6, and C7. When putting in the RGB LED I wanted to be sure that the longest leg (which represents ground, GND) is in C5. Every other leg represents Red (C4), Green (C6), and Blue (C7).

From there, I took my resistors in the same row as each leg that represents RGB, where the orange strips were facing towards the RGB LED and the grey and black were facing away. Because you can only connect so many parts in a terminal row together, I split my resistors across the two terminal strips so I can have additional wiring and not feel too cramp.

On the second terminal strip, I place wires next to each resistor and connected them to digital PWM pins (D11 — D9). So when dealing with Red, that would go from H4 to DP11 (on the arduino). Blue would go from H6 to DP10 and Green would go from H7 to DP9.

To get power all set up, I put a wire into GND and on the bus strip opposite of where I put the LED. Once it goes into the negative column it wires up that entire column. Before putting in the power, I also connected a wire from the GND column I hooked up to E5 so the LED would have its GND leg connected. Then the last wire before it is all set up is the 5V to the positive bus strip.

From there, it is all hooked up and so I plugged my Arduino into my computer so when I finish writing the program, I can just immediately flash it and get the program on there.


When writing a program using the avr-hal crate, it means that we don’t need to use the standard library and we will disable emitting a main symbol for our binary (though still) have a main function.

We’ll then make sure to add in our arduino_uno package and panic_halt . panic_halt helps direct what should happen if we panic so not to completely destroy all our work. When we have these two packages we will want to add an attribute to our function so to indicate where the entry point for the program should be.

From there, we can grab in our peripherals from arduino_uno and create an instance of the pins. We will also want to have a loop which is necessary for an Arduino program but doesn’t need to contain anything in it:

We’re going to activate the digital pins that we need, which were the digital pins 9-11. We’re going to be sure they act as the output pins but then also transform them into using PWM. That way we can control the variability of power we need to send so it can adjust the brightness of any of them.

This will make sure that all your pins are turned on and ready to be set for duty! set_duty allows you to set a value of 0-255 for the LED, anything more than that won’t get registered:


Can You Program Arduino with Rust?

When getting into the programming world to develop my Arduino projects, the last thing I heard was from RUST. One of the advantages of RUST is that it has memory efficiency and does not require garbage collection of data space at runtime, which seems to be of benefit for the kind of projects I was into and led me to think of the possibilities to program Arduino with RUST.

So, can you program Arduino with Rust? Yes, you can program Arduino with RUST and enjoy its benefits of memory-safety, concurrency, reliability, and speed for your projects. RUST can only compile to the ARM-Architectural devices and despite Arduino boards aren’t based on the ARM chip, the AVR-RUST Team agreement and relationship has made it possible for both to be compatible.

But, is it RUST easy to learn? Yes, if you already use C++ to do your Arduino projects, the switch seems even more streamlined and smooth. You’ll enjoy creating exciting projects with Arduino, once you know the basics of RUST.

About Arduino

Arduino is a microcontroller that provides a bridge to connect hardware and software. The basic idea and performance of an Arduino board are to take input signals (be it code, from the environment, etc.) and convert them into output signals (responses and actions).

One can do all this by programming Arduino through its software Arduino IDE and modifying its hardware (the Arduino board), as needed.

Nowadays, due to its accessible prices and open source philosophy, Arduino gives access and an opportunity to many people around the world (from students to established engineers) for experimenting, explore new frontiers and even showcase base ideas, gadgets, and useful projects.

But, let’s dive deep into what is the relationship of Rust with Arduino, without bringing too much tech, of course.

I wrote a guide on which languages are the easiest to learn and work with for Arduino. Check it out here:

About RUST

A Programming Language

While RUST is not the name you often hear even if you are into reading some of the tech-papers or news articles, it is a powerful language. The advantage of RUST is that it has memory efficiency and does not require garbage collection of data space at runtime.

Hence, being memory efficient, RUST offers memory-safety. While you can benefit from this principle RUST has, there are other features you enjoy going with RUST also.

The incredible user-friendly environment and easy to understand error throwing messages of Rust make life easier.

RUST is more like the IOS version of the software; while C and C++ act more like Android and are open to being hacked and lack privacy factors, RUST offers the programmers safety of memory and thread.

Another feature that RUST brings is that it is an excellent language for embedded systems, which means it can quickly and efficiently work with other hardware devices and tech-architectures.

A Cross-Compiler

RUST is a cross compiler meaning that writing code, or instructions, on the architecture provided by RUST, you can enable, or generate, code for another architecture. This feature makes RUST flexible while still safe because of its memory-safety principle.

AVR-Rust Relationship

As said above, the cross-compiling feature of RUST makes it possible to run instruction on another compiler running on a different CPU or architecture.

While the technical relationship of AVR and RUST is not official, because of the team efforts of RUST working with AVR environment, this has become possible.

Something to keep in mind about AVR and RUST!

RUST does not support all architects; it can only compile to the ARM-Architectural devices and hardware.

The Embedded Device Working Group has maintained and established some rules and policies—just like the SI Units for measurements—which brings different devices built on some basic principles for the sake of integration of various hardware, software, and interface.

Arduino board is not based on the ARM chip; it’s based on the famous chip ATMega328; this chip is an 8-bit AVR.

For the rules of the game, Arduino should not work with RUST, but it does because of the AVR-RUST Team agreement and relationship.

How do They Work With Each Other?

To mediate between the “chip” and the drivers, the AVR-RUST team built AVR-HAL, which enables the to-and-fro work motion.

Why AVR have any relationship with RUST at all?

The main reason for such a relationship is because of what RUST offers. It has the features of low-level languages, for example, C and C++, but it provides the high-end outcomes of high-level languages.

With this main feature and philosophy on which RUST was built in 2006 by Graydon Hoare, and when Mozilla officially announced it in 2010, it offers speed, concurrency, and safety. From a safety perspective, it means that it doesn’t leave a lot of footprints.

This philosophy enables a behavioral pattern in the developers and a bright future in their relationship.

This underlying philosophy of RUST starts—or will begin—a behavioral effect in the developers and programmers.

When developers feel safe with the hardware and software, and knows them to be reliable, they try to try more experiments and developments by using them.

The safety and reliability of RUST, plus aesthetics, flexibility, and security of Arduino, asked for such a relationship between these two.

With this relationship, the future of robotics and technical projects is something the RUST team can be a part of.

Why the Basic Features of RUST Offer Bright Future for Embedded Programming?

Embedded programming is not a piece of cake. It is hard because of the programming architectures of previously used programming languages invited a lot of compiler-crashes, errors, buffers, and virus-attacks. These types of nuisances occurred due to random memory allocation of C and C++ languages.

Moreover, the safety of memory is something not guaranteed by the C-family. Because of these problems, programmers and developers could not unleash a lot of functions and features. With RUST landing in the programming world, developers can feel free to try new grounds of features and functionalities.

One other feature of RUST is that it brings concurrency. Multitasking because of the programming structure of RUST is now possible.

Benefits of Rust

We have established in this article that RUST provides:

  • Memory-Safety
  • Concurrency
  • Reliability
  • Speed
  • Great future for Robotics

These features make the AVR-RUST relationship meaningful, advantageous and offer a bright future for robot-posterity that will be run from Arduino and built from RUST.

Some Basic, Yet Significant Questions.

Can you program Arduino with Rust? The answer is yes, and a great future is likely possible because of the incredible safety and reliability features of Rust programming language
Is Rust challenging to learn? Should I do projects (Robots and whatnot) on my Arduino with Rust? The answer is a big yes, you should learn Rust as soon as possible as it holds the future of robotics. With Rust and Arduino, you can accomplish great ground-breaking projects.

Learning Rust for Arduino

For programming, you’ll have to learn a very user-friendly low-level language programming syntax, which isn’t very difficult because a lot of the Rust syntax world is like that of the C-language family.

If you already use C++ to do projects on Arduino, the switch seems even more streamlined and smooth. You’ll enjoy creating exciting projects with Arduino, once you know the basics of Rust.


It is now clearly established that programming Arduino with Rust is not only possible, but together both are creating the possibility of a great and bright future, which was not possible with using previous programming languages.

As a project-maker or even Arduino-lover, learning Rust now would prove to be a very significant and timely decision. Programming with Rust is easy, and yet it can affect your project positively.

You can download the IDE compatibility files and start working for the basic and simple projects on Arduino as a start.

More to Come

With time, Rust and Arduino are likely to become go together. Rust is going to become “smoother” for the Arduino family and environment.

Developers and project-makers who love doing projects on Arduino will find great comfort working with Rust and Arduino at the same time in the year to come.

For your project safety and reliability, mastering RUST for your Arduino projects will be a great decision.

Still hungry for more info on this topic? Check these:

Engineer and electronics enthusiast. Enjoys solving problems with electronics and programming.

Recent Posts

When working with small computers it can be important to monitor the amount of memory and storage space that is available to the programs running on the device. Small and embedded computers often.

«If it fits, it works» — this is not a philosophy that I’ve found to put your Raspberry Pi project at risk of not working. Even though the Raspberry Pi uses a USB connector for its power source, it.


Unleashing the power of small computers. I believe cheap small computers have incredible potential and I want to help unleash that potential with you.

Hi! My name’s Chris, I’m an engineer, a consultant, and I enjoy getting things done with electronics. I’m here to help you unlock the value of small computers and embedded computer systems.