Rust challenge 55/100 - running rust on esp32
Table of content
What is this
The rules of the game are explained in my original.
55th Challenge
Challenge
Run hello world on an esp32 using rust.
Solution
We need to add some addtional toolchain pieces that are not in a default cargo installation the following command so that esp32 binaries can be built:
Call cargo install -f ldproxy espflash espmonitor
At the end, I missed it on my first install, the script tells you to add two lines to your .bashrc
(or whatever shell you are using). This is important! It will not work otherwise.
Lets start from a template:
The template, looks like this, when running tree -L 3
Next lets go into the dir cd esp
and run rustup override set esp
so that we just use esp stuff inside this directory. Output will be
info: override toolchain for '../100-rust-snippets/esp' set to 'esp'
Next add wifi pass and ssid using env. variables again, or the compiler will hit you with the following error
|
100 | const SSID: &str = env!("RUST_ESP32_STD_DEMO_WIFI_SSID");
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: this error originates in the macro `env` (in Nightly builds, run with -Z macro-backtrace for more info)
error: environment variable `RUST_ESP32_STD_DEMO_WIFI_PASS` not defined
--> src/main.rs:103:20
|
103 | const PASS: &str = env!("RUST_ESP32_STD_DEMO_WIFI_PASS");
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Next try to build with cargo build --release
and it should work.
There are a number of runners as usual. I had success running espflash target/xtensa-esp32-espidf/debug/rust-esp32-std-demo
and selecting the right usb port. Warning: I had to hold down the reset button and release to succesfully flash, to get the thing running. Do this when the expflash app is trying to connect. Output should be as follows:
Thats pretty much it, run èspflash serial-monitor
, hold reset button if needed and you should get something like the following:
Hello from Rust!
More complex print ["foo", "bar"]
Result: 0, 1
See the repo on github