Rust on Espressif chips - 28-04-2023
This is the next quarterly update of esp-rs effort, detailing the progress over Q1 2023.
Rust Compiler & LLVM
We have fixed several issues in the LLVM Xtensa backend, mainly relating to the hardware loop optimization feature used on the ESP32 and ESP32-S3 chips #161 #164. We spotted an issue with the 1.67 release where debug builds no longer worked on the ESP32, however, this turned out to be a linker script issue in esp-hal #158.
In the last post, we mentioned that the first 10 LLVM Xtensa patches had been committed upstream, since then we have been preparing the next set and now have 20 patches in review upstream. You can track the progress, as well as review the patches here.
esp-hal - no_std
First, there were updates to the embedded-hal-async
and embassy-*
dependencies, as well as an update to embedded-hal@1.0.0-alpha.10
and embedded-hal-nb@1.0.0-alpha.2
, bringing in the latest changes and improvements from the embedded-hal ecosystem #488 #487.
Initial ESP32-H2 support was added with #482 with the addition of soc/efuse methods in #486. Debug assist support was added to aid in debugging stack overflow issues #484. Additional updates were made to fix comparison errors, decoding of wakeup cause using bitflags, as well as adding support for the RSA peripheral #473 #472 #467.
Improvements were made to the linker scripts, documentation, and clock control for peripherals such as timg
, wdt
, sha
, usb-serial-jtag
, and uart
#470 #463 #461. Fixes were made to clock enabling for ESP32-C6 and 802.15.4 clock enabling for ESP32-C6 #458.
Updates were made to the PACs (Peripheral Access Crates) to the latest versions, and the esp-hal-smartled
package was extracted and CI checks were added for it #447 #436 #429. Other changes included fixing warnings, cleaning up the RTC driver, removing r0 dependency, and unifying linker scripts for better organization and maintenance #440 #439 #443.
esp-wifi - no_std
We have made significant progress in enhancing packet dumps #165 and using a more reasonable default MTU, as well as incorporating features to change MTU #164. Additionally, we have implemented async BLE functionality #161 and added missing ROM functions for ESP32-S3/ESP32-S2 support #160.
We now utilize types from core::ffi::
since they have been stabilized #159 and incorporated the use of HAL's radio clock control #153. We have also refactored Socket::write
to prevent infinite loops during long writes #151 and updated examples for better organization and clarity #146.
In terms of new features, we have added support for ESP32-C6 WiFi #142, implemented basic AP functionality #134, and incorporated ESP-NOW support #121. We have also made improvements to asynchronous WiFi functionality, including connect/disconnect/scan/wait_for_event
capabilities #129 and fixed a bug ensuring that internal WiFi buffers are properly freed #128.
Furthermore, we have made updates to dependencies, such as upgrading to Smoltcp 0.9 #124, and reorganizing low-level bindings into a separate package for better modularity #117. We have also addressed various bug fixes and optimizations, including disabling LTO for improved performance #116 and refactoring the WiFi device for better code structure #115.
TLS - no_std
The standard library has had TLS support for a while, but it's not flawless. However, we lacked TLS support for no_std applications. While we're enthusiastic about the potential of the embedded-tls crate, it's not yet suitable for widespread use. As a substitute, we created esp-mbedtls, a crate for using MbedTLS on ESP32s in no_std applications.
esp-idf - std
Over the past quarter, we have been busy improving the functionality and usability of the esp-idf-hal library. We fixed thread priority with pull request #235, and improved our CI with pull request #226. Additionally, we added an spi::config::BitOrder
enum to make SPI configuration more flexible with pull request #222.
We also implemented several new features, such as setting the LedcTimerDriver
frequency with pull request #219, and implementing async Wait traits from embedded-hal-async with pull request #218. We also added alerts and modes support for TWAI with pull request #216, and implemented a general purpose delay provider with pull request #210.
Finally, we made several improvements to existing functionality, including allowing setting a timeout for i2c to accommodate devices with longer clock stretching with pull request #211, and changing the LEDC Clock enum name/typedef in esp-idf master with pull request #208. We also implemented PCNT for the v4 esp-idf api (which will work for v5 with v4 api) with pull request #157.
Tooling
espflash
Over the past quarter, we and the community have been busy making several improvements and fixes to espflash
. We started by adding a note about permissions on Linux in pull request #391 to ensure that users are aware of the necessary permissions when flashing ESP devices on Linux systems. In pull request #389, we made the default flashing frequency target specific to improve the flashing process. We also generated shell completions in pull request #388 to enhance the usability of the espflash
tool.
In addition to these improvements, we also focused on fixing issues and bugs. We fixed the config file parsing in pull request #382 and updated the toml
dependency while fixing errors and feature gating ctrlc
dependency in pull request #378. We also resolved issues with Raspberry CI in pull request #377 to ensure smooth integration and testing. Furthermore, we made image header improvements and bugfixes in pull request #375, fixed chip revision check during flashing for the ESP8266 in pull request #373, and restored the cursor when exiting from serial port selection via Ctrl-C in pull request #372.
In terms of new features, we added support for ESP32-H2 in pull request #371 and introduced an ESPFLASH_PORT
environment variable in pull request #366 for added flexibility. We also updated the documentation in pull request #368 to provide up-to-date and accurate information to users. Additionally, we made several fixes and improvements in pull requests such as #363, #359, #358, #354, and #353 to ensure the stability and reliability of the espflash
tool. Overall, our team has been actively working on addressing issues, adding new features, and improving the espflash
repository to provide a better experience for our users.
matter
matter is an open-source connectivity standard for smart home and Internet of things devices, that promises to make smart devices work with each other regardless of which company manufactures them. We at Espressif are very interested in supporting this. ESP-IDF has support for it with the esp-matter repository, which uses the C++ matter SDK, which we could of course write bindings to (we've already played around with this!) but ideally we'd love a pure Rust implementation.
Introducing matter-rs a pure Rust implementation of the matter protocol. Espressif's very own @kedars lead the development of this library, and it is now the official implementation adopted by the matter organization. There are many improvements and features to be added such as async
and no_std
support but it's a great start.