Using rust for embedded development is much more easier than setting up a C/C++ environment now. You will be able to program and flash your firmware to an Arduino in just a few minutes.
First setting up an environment may take a little while and then it is as swift as cloning a repository. Let's jump to the initial environment setup.
- Run this to install AVR compiler and library header files
sudo apt install avr-libc gcc-avr pkg-config avrdude
- We need cargo-generate to get project template from git
cargo install cargo-generate
- Also to run the program once you compiled it you can use the ravedude cargo package
cargo install ravedude
That's all. The configuration part is over.
Now whenever you want to start a new project you can just run
cargo generate --git https://github.com/Rahix/avr-hal-template.git
You will be prompted to enter a name for your project, and the board that you have.(Arduino Uno, Mega etc.,)
cargo run
will build and flash the program to your embedded system but before running it you need to tell the ravedude which of your serial port is connected to arduino.
export RAVEDUDE_PORT=/dev/ttyUSB0
Replace ttyUSB0 with the name of the port your arduino is connected to.
Once the default project from the template is flashed you will be greeted with the blinking led in your arduino. You can edit the src/main.rs
file to control the Universe... Nope! Just your Arduino.ð
That's how easy it is to start programming embedded systems in Rust.
P.S: I am new to blogging so if you find anything odd in this blog let me know.
Image Credit: https://commons.wikimedia.org/wiki/File:Arduino_Leonardo_PCB.jpg
Top comments (2)
Hello, very good tutorial, but how could I follow the same logic as this tutorial but on windows 10, I'm starting in Rust with Arduino and in the future with esp32
tinusaur.com/guides/avr-gcc-toolch...
stackoverflow.com/questions/171092...
You can try compiling after installing avr-gcc and pkg-config. Make sure to add it to PATH variable for rust compiler to access it.