DEV Community

Weekly Typed
Weekly Typed

Posted on • Originally published at weekly-typed.com on

Embedded Rust on ESP32

Rust on ESP32

A while back, I bought a STM32F3 Discovery board, fully intending to use it to complete the Discovery Book. Unfortunately, it took a long time to ship, and most of the novelty had worn off by the time I got started. I barely completed the introductory, blinking LED project, and the Discovery board has been sitting in a drawer ever since.

These interests of mine tend to be cyclical, though, and embedded development finally came back up recently. I was seeing some interesting projects on YouTube channels like Volos Projects, that introduced me to ESP32 and the associated line of development boards. It turns out ESP32 boards have some neat features, like wifi and bluetooth. They are also super popular. So when, I noticed regular updates to esp-hal showing up in This Week in Rust, I got a little excited.

As it happens, Espressif (the company that makes ESP32) and the Rust on ESP Community have been going pretty hard to make Rust on ESP easy.

Here's a bit about what I've learned.

A proper hosted environment

Look, programming on bare metal sounds cool. It sounds super hackery. But I don't want to dive into that right off the bat. I do want some guardrails so I don't lose my way. But, at the same time, I'm not really drawn to dev boards like Arduino and Raspberry Pi. The vibe I get from them is a high level of abstraction.

ESP32 development has great Rust support, and the level of abstraction is right where I want it. The Espressif Integrated Development Framework (ESP-IDF) provides a base layer of components that makes it a lot easier to build applications, including a "newlib" that enables use of Rust's standard library std.

ESP-IDF also Includes an implementation of FreeRTOS. So you can write proper async code, instead of complex timers to make things happen at the right time. Again, it's all about building cool projects without too much headache.

Books

Rust on ESP Book (book)

Embedded Rust on Espressif (book/training from Espressif)

Wokwi

Wokwi is like Codepen for embedded projects. It's one part website and one part VS Code extension. On the site, you can view, clone and create new projects, and use in-browser code editor and simulator to get a simple project running with no fuss. The VS Code extension basically integrates the simulator into your editor.

From their docs:

Wokwi simulates a wide variety of hardware components, including microcontrollers, sensors, displays, and more. It supports the following architectures: ARM, AVR, RISC-V, and Xtensa.

And there is a whole page dedicated to Rust projects. It's an awesome way to get started without buying anything! You can get started and have a blinking LED project in a couple seconds. And when you're ready, you can even flash your board directly from Wokwi.

Easy project setup

The esp-rs project has a set of project template that make creating new projects a breeze. You can use them with cargo-generate, and after answering a few questions, you'll be set up with either a no_std or std project, complete with configs Dev Containers that integrate with Wokwi simulator! You couldn't get much simpler.

Summary

So ESP32 checks a lot of boxes for me. It's an affordable, powerful microcontroller that has dev boards with lots of cool features. There is ample Rust support, and good learning resources. You can get started quickly with Wokwi, learn embedded development by building cool things. All without resorting to Python or C/C++.

See the original post over at my blog, Weekly Typed

Top comments (0)