Hacker News new | past | comments | ask | show | jobs | submit login
Rust on Espressif chips (mabez.dev)
155 points by childintime on July 1, 2023 | hide | past | favorite | 20 comments



Oh shit, I have some ESP32s from my COVID isolation AliExpress shopaholigasm.

"ESP32 ESP32-CAM WiFi"

"ESP8266 ESP32 ESP-32S"

"SX1276 ESP32 with LoRa 868MHz-915MHz"

Remember Chinese disposable brand sites tend to disappear without warning, so you always have to archive everything they have on their support sites, i.e., datasheets, code, examples, doc, diagrams, etc.


I've never worked with Rust, but I'm very familiar with ESP32+VSCode/ESP-IDF, and eager to use something more high-level but still stable enough for unattended network-connected appliances

is this a good time to learn and start writing for the ESP32 in Rust, or should I wait a little more?


It's probably fine. I started using Go (tinygo) for microcontroller projects a few years ago and haven't looked back. If people can make Go work, I'm sure Rust is fine.


Tried. No wifi support for my board (esp-eye) no I2S for audio. Very limited. Too bad because I really enjoy working in Go compared to micropython.


Interesting. I did Wifi once but used an RP2040 with some sort of ESP32 flahshed with some firmware designed to let Android sketches use Wifi. (The actual wifi was done by another ESP32. BOM efficient? Nope. Easy? Yup. If $1 per part ever makes a difference to me, I guess I'll just use C.)


Have you tried AtomVM? [0]

[0] https://github.com/atomvm/AtomVM


This is a great time, in my opinion. Don't expect perfection, but things are really far along.


For a second I thought this would be about an issue with damage from iron oxide on Espressif chips.

Yes, it's a weekend and also a holiday today ;-)


This is a very timely article, since I’ve been trying to figure out how to get Embassy to work on any of the various ESP32 boards I have this weekend.

Is there any good guide for getting Rust working on ESP32? (the old Xtensa dual core model, or the newer C3 or C6 models)

I’ve also been looking at maybe trying an RP2040 board I have, but the Getting Started[0] guide seems very incomplete. It doesn’t even seem to mention that you need a nightly build of Rust, but I’m pretty sure you do.

I also doubt that running “cargo run” is going to result in an example being loaded onto any development board, so that seems like a confusing thing to show in the guide.

[0]: https://embassy.dev/book/dev/getting_started.html


“cargo run” does in fact flash the dev board. Cargo allows configuring a custom runner, which is what the embassy examples do [0].

[0]: https://github.com/embassy-rs/embassy/blob/main/examples/stm...


Ah, neat. That is a cool feature I didn’t know cargo had!


For ESP chips in general, the Rust on ESP Book [0] is pretty solid. Little short. I've been playing with writing a Watchy firmware in Rust (Watchy uses the dual-Xtensa ESP32-PICO-D4), and this was a great starting point.

[0] https://esp-rs.github.io/book/installation/index.html


I’ll definitely take a look!


I’m very excited about trying rust on these devices. Are there any examples out there of projects using this in a more or less mature shape?


Yes! The training developed with Ferrous Systems (https://esp-rs.github.io/std-training/) contains several examples, and you can find many community projects in https://github.com/esp-rs/awesome-esp-rust#projects


Afaik there while there are some OSS projects they aren't necessarily mature.

The no_std hal is still a bit of a moving target so it's not as beginner friendly, the most mature here seems to be the SlimeVR firmware: https://github.com/SlimeVR/SlimeVR-Rust/tree/main/firmware

For std hal there are a few more, OFMon being a good one: https://github.com/arashsm79/OFMon


I have a bunch of various ESP32‘s lying around and I’ve been getting by with copy pasted arduino code.

Works fine for most things but I’ve also told myself many times now that I would like to dive deeper when I find the time.

My background is in web and Java. Never done C or C++.

Is rust on esp already good enough for a beginner?


Rust makes use of some more advanced type features than Java has. You’ll want to focus on some of the differences between traits and interfaces. Additionally, in Java you’re probably used to a lot of runtime dynamism, this is possible in Rust, but not something you usually need to use. To understand this better, look at dyn object safety.

The biggest thing in Rust that you need to become familiar with from Java is the ownership system. First, Java is a default copy-by-reference language, whereas Rust is move by default. So learn the difference between, T, &T, and &mut T. Learning the ownership system will make you disappointed in Java’s thread-safety story. Rust makes thread safety and multiple references to values very obvious and you need to be explicit about how things should be shared. This will probably be your biggest hurtle, based on my experience.

Read the book, these concepts are all explained very nicely: https://doc.rust-lang.org/book/


Don't know the answer to your question, but depending on what you want out of it, I find esphome with inlined C++ more than enough for most cases (for anyone that knows how to code in general).

It's mostly declarative, like writing a kubernetes helm chart with some templating, which should be somewhat at home for web folks.


You can run python (micropython), javascript (espruino) or lua on ESP32. If you're just tinkering/playing around, those are great options.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: