Embedded Rust on ESP32
Published: 2023-10-21 11:41:51

---
title: Embedded Rust on ESP32
published: true
date: 2023-09-04 17:39:39 UTC
tags: 
canonical_url: 
---

 ![Rust on ESP32](https://images.unsplash.com/photo-1599481238505-b8b0537a3f77?crop=entropy&cs=tinysrgb&fit=max&fm=jpg&ixid=M3wxMTc3M3wwfDF8c2VhcmNofDgyfHxyb2JvdHxlbnwwfHx8fDE2OTM4NDkxMzF8MA&ixlib=rb-4.0.3&q=80&w=2000)

A while back, I bought a STM32F3 Discovery board, fully intending to use it to complete the [Discovery Book](https://docs.rust-embedded.org/discovery/?ref=weekly-typed.com).  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](https://www.youtube.com/@VolosProjects?ref=weekly-typed.com), 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](https://this-week-in-rust.org/?ref=weekly-typed.com), I got a little excited.

As it happens, Espressif (the company that makes ESP32) and the [Rust on ESP Community](https://github.com/esp-rs?ref=weekly-typed.com) 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](https://esp-rs.github.io/book/introduction.html?ref=weekly-typed.com) (book)  
[Embedded Rust on Espressif](https://esp-rs.github.io/std-training?ref=weekly-typed.com) (book/training from Espressif)

## Wokwi

[Wokwi](https://wokwi.com/?ref=weekly-typed.com) 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](https://wokwi.com/rust?ref=weekly-typed.com).  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](www.weekly-typed.com/rust-on-esp32)