DEV Community

Cover image for How to run Rust on Arduino Uno

How to run Rust on Arduino Uno

creativcoder on August 20, 2020

Originally posted on: creativcoder.dev At the time of writing this, about a month ago, the rust-avr fork was merged upstream. This means that you ...
Collapse
 
tcallred profile image
tcallred

For those trying to flash to a device from windows, you can use this command if you have the Arduino IDE installed:

"C:\Program Files (x86)\Arduino\hardware\tools\avr/bin/avrdude" -C"C:\Program Files (x86)\Arduino\hardware\tools\avr/etc/avrdude.conf" -v -patmega328p -carduino -PCOM3 -b115200 -D -Uflash:w:C:\Users\path\to\project\rust-arduino-blink\target\avr-atmega328p\debug\rust-arduino-blink.elf:e'

Collapse
 
jdrouet profile image
Jérémie Drouet

Hi! Nice article!
I ran into a problem though when trying to build: language item required, but not found: eh_personality
Any idea of why?

Collapse
 
theomartos profile image
Théo Martos

Hi ! I ran into the same problem and bottom line I found the solution here : os.phil-opp.com/freestanding-rust-...

Collapse
 
meonlol profile image
meonlol

Yest that's the solution. The article forgot to mention the panic = "abort" under [profile.dev] and [profile.release, but it's in the git repo:
github.com/creativcoder/rust-ardui...

Collapse
 
kgrech profile image
Konstantin Grechishchev • Edited

Thank you for the great article! I've also found it useful to learn how to link a C++ Arduino library to the rust project.

Collapse
 
modelerr profile image
Gray David • Edited

Thank to the post,but I met some problems when building this project.
It says it cannot find macro 'llvm_asm'.I don't know if is this caused by the source mirror I'm using(tuna.tshinghua.edu.cn).

rror: cannot find macro `llvm_asm` in this scope
  --> /home/awa/.cargo/registry/src/mirrors.tuna.tsinghua.edu.cn-df7c3c540f42cdbd/avr-device-0.2.3/src/interrupt.rs:18:22
   |
18 |             unsafe { llvm_asm!("cli" :::: "volatile") };
   |                      ^^^^^^^^

Enter fullscreen mode Exit fullscreen mode

Then I found this:

error[E0635]: unknown feature `llvm_asm`
  --> /home/awa/.cargo/registry/src/mirrors.tuna.tsinghua.edu.cn-df7c3c540f42cdbd/avr-device-0.2.3/src/lib.rs:31:12
   |
31 | #![feature(llvm_asm)]
   |            ^^^^^^^^

Enter fullscreen mode Exit fullscreen mode

What does this mean?

Collapse
 
mikla profile image
Artsiom Miklushou

Thanks for the article!

I'm getting an error:

error: ran out of registers during register allocation
Enter fullscreen mode Exit fullscreen mode

macos catalina.

Collapse
 
ea2305 profile image
Elihu Cruz

Not sure if can it apply, but on windows, I got the same error and I solved it by changing the nightly version rustup override set nightly-2021-01-07
Here is the AVR reference, I hope it can be useful: github.com/Rahix/avr-hal#starting-...

Collapse
 
xphoniex profile image
Dave

you're getting this error because Cargo.toml is missing:

[profile.dev]
panic = "abort"
lto = true
opt-level = "s"
Enter fullscreen mode Exit fullscreen mode

anyway, this can't be compiled anymore:

   Compiling avr-device v0.2.3
error: cannot find macro `llvm_asm` in this scope
  --> /.cargo/registry/src/github.com-1ecc6299db9ec823/avr-device-0.2.3/src/interrupt.rs:18:22
   |
18 |             unsafe { llvm_asm!("cli" :::: "volatile") };
   | 
Enter fullscreen mode Exit fullscreen mode

and you need to switch from arduino-uno crate to arduino-hal. (example)

Collapse
 
marquesbruno profile image
Bruno Marques

Hi and thanks for this article!

I had to add the json extension to avr-atmega328p file.
I can't get cargo to build the project however, I get the following error:
error: "/home/bruno/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/Cargo.lock" does not exist, unable to build with the standard library, try:
rustup component add rust-src --toolchain nightly-x86_64-unknown-linux-gnu

I did set the #![no_std] in main.rs

Collapse
 
nearos profile image
Nearos • Edited

Trying this on fedora I get RUST_COMPILER_RT_ROOT is not set.
Any suggestions? (Actually I get that after I include a crate for compiler_builtins. At first it says "can't find crate 'compiler_builtins'")

Collapse
 
wlcvs profile image
Wallacy

not sure but this looks like some problem in the system PATH variable

Collapse
 
kuroiyatsu profile image
Mr. Johnson • Edited

I am running Ubuntu and I cannot get this to build. I just receive the following error:

LLVM ERROR: Not supported instr: >
error: could not compile 'compiler_builtins'

Not finding anything useful online to help me get past this.

Collapse
 
kuroiyatsu profile image
Mr. Johnson

An update from my previous post. There appears to have been a regression with the Rust compiler that causes this issue, unless I am misunderstanding this:

github.com/rust-lang/compiler-buil...