Rust on Espressif chips - 17-10-2022

This is the next quarterly update of esp-rs effort, detailing the progress over Q3 2022.

Rust Compiler & LLVM

The Rust compiler fork and LLVM have seen a few changes and fixes over the last quarter. Firstly, we have a new way to install the Xtensa-enabled toolchain, introducing espup. espup is a new Rust-based installer that replaces the unwieldy bash scripts we were previously using; we're still maintaining those for the time being but the future will be espup.

A few issues have been spotted in the last quarter, the first related to the alignment of 128bit arguments on the Xtensa arch which caused #137 & #135. The second was a loop miscompilation issue in the code generated by the LLVM backend which caused #134 & #127. This has now been fixed in LLVM and will be released with Rust 1.65.0. Finally, there are some code generation issues around printing floats which can be seen in #136, this is an ongoing issue that I haven't gotten to the bottom of.

Lastly, we have some progress to report on the LLVM Xtensa upstreaming - it's moving! Eight of the ten initial patches have been approved thanks to some new reviewing effort upstream. Since then Cadence (the IP holder for Xtensa) has publically released an ISA summary which is fantastic news for the open source community in general but especially us as there is now an official document that reviewers can use to review our backend. We started a new RFC to finally get the initial patches merged upstream.

esp-hal & bare metal

esp-hal development has been coming along nicely! We even released our first and second releases during this quarter, which is quite the milestone as we now believe that the HAL is in a good enough spot for it to be experimented with.

  • Very basic support for running applications on the other core #96
  • ADC support #97 #98
  • Allow for configuring the UART #99 #102
  • Vectored interrupts #103 #118
  • Direct-boot support for the ESP32-S3 #107
  • CPU clock settings #110 #111
  • LEDC support #114
  • Critical section implementations #151
  • embedded_hal@1.0.0-alpha.x traits implemented for most peripherals (multiple PRs)
  • A large number of bug fixes, smaller features, refactoring, etc. (multiple PRs)

esp-wifi

esp-wifi has had a lot of attention in the last quarter, plenty of fixes and improvements to make it more reliable, as well as adding new target support!

  • Remove global allocator #73
  • Reduce project size by using size optimized WiFi blobs #66
  • Switch the Bluetooth stack to bleps #65
  • Add WiFi support for the ESP32-S2 #62
  • Add WiFi support for the ESP32-S3 #55
  • Remove bespoke code in favour of relying on esp-hal where possible (multiple PRs)
  • Fix order of magnitude timestamp creation error #44

esp-storage

esp-storage is a new crate that implements the embedded-storage traits for Espressif chips. This is useful for writing data to internal flash, which could be paired up with flash aware filesystem.

Tooling

espflash

Espflash has seen some great improvements over the last quarter. We're building up to a 2.0 release soon which will feature a much improved, and importantly, consistent CLI.

  • Support for ESP32-C2 added #204
  • Support for using stub loaders added #216
  • Improved support for ESP-IDF partition tables (multiple PRs)
  • Support for flashing the ESP32-S2 via CDC UART #228
  • Support for erasing OTA data #229
  • Support flashing via the built-in UART peripherals on Raspberry Pi #234
  • Relicensed under MIT/Apache-2.0 #235
  • CLI interface redesign #239
  • A large number of bug fixes, smaller features, refactoring, etc. (multiple PRs)

Rust flasher stub

Flashing stubs are small programs that the flashing tool uploads to the chip to improve the features or speed of flashing. The stubs available for Espressif chips are currently written in C and can be found here. These stubs have grown organically over the years and we've wanted to rewrite them for a while. We took this opportunity to write them in Rust! You can find the project here, which currently only has a stub for the esp32c3, but esp32 support is being worked on.

Wokwi

Wokwi now has in-browser support for building Rust applications for Espressif chips. Check out wokwi.com/rust and play around with some examples in the comfort of your browser!

wokwi-server, the cargo runner for running applications in Wokwi has been updated to v0.2.0. This includes bumping Tokio to the latest stable and providing prebuilt binaries on the releases page.

Espressif DevCon 2022

Espressif is excited to be hosting our first-ever conference this year! It's a two-day event starting on the 19th of October! I will be talking about Rust at Espressif along with some of my colleagues. Be sure to register here then drop in and say hi!

  • 19th October 13:05 CEST - Rust on Espressif Chips - Scott Mabin
  • 19th October 14:30 CEST - Your browser is ESP32 - Uri Shaked
  • 20th October 16:45 CEST - Paradigm Shift to Cloud-Based Embedded Development - Juraj Michálek, Sergio Gasquez

What's next?

Continue to improve the Rust Xtensa fork, and push for LLVM upstreaming, maybe we'll see Xtensa (as an experimental target) in upstream Rust sooner than we thought! On a side note, we've started an "awesome" list of awesome esp rust things - check it out here.