First Official SDK In Rust
Written by Harry Fairhead   
Wednesday, 05 March 2025

We are all being urged to work in Rust because its safer, but this is easier said than done. The embedded world really needs a memory-safe language, but Rust gets surprisingly little support from manufacturers. SDKs are written in C and not Rust. The good news is that Espressif is working to produce an official Rust-based SDK for its microprocessors and you can start to work with the beta now.

esprust

The world of embedded systems needs secure coding practices, but it can be out of reach due to the way development is supported via SDKs and tool chains. This has long been the province of C and nothing but C. Even C++ rarely gets a look in. If you want to work with Rust on a device such as the Raspberry Pi Pico, Arduino or any of the well-known products then you can usually find a way to compile a Rust program, but it will have to make use of the extensive C SDK which slighly negates the point of using Rust.

Around six years ago when Espressif started work on its SDK in Rust, it wasn't obvious how to do it. The Rust compiler didn't support the Xtensa processor found in its devices. At first the work was done by enthusiasts, primarily Scott Mabin, but as Espressif got more and more interested, it eventually hired some of the enthusiasts and formed an official Rust team.

At the time most Rust code supported ARM chips and not the Xtensa and RISC-V devices that Espressif uses. To cut a long but interesting story short, eventually the team settled on implementing esp-hal, an architecture- independent layer written in Rust. It wasn't long before they managed to add WiFi, BLE and ESP-NOW support - and working on a range of devices including Xtensa and RISC V targets. In addition they intend to support four core drivers to start with:

  1. GPIO
  2. UART
  3. SPI
  4. I2C

with the only major missing feature being PWM, which is particularly sophisticated on the ESP range of devices. The SDK also supports the time module and a few other APIs. If you want more then you have to opt for unstable features which should be stabilized over time.

To give you some idea of what the code looks like here is a simplified Blinky - i.e. flashing an LED connected to GPIO7:

#[main]
fn main() -> ! {
    let peripherals = esp_hal::init(esp_hal::Config::default());   
    let mut led = Output::new(peripherals.GPIO7, Level::Low);          led.set_high();
    let delay = Delay::new();
    loop {
        led.toggle();
        delay.delay_millis(500);
    }
}

You can see that this not only doesn't look like C, it doesn't look a lot like the Espressif IDF SDK - so there is much to learn.

How important is a Rust SDK?

Potentially very important. There are Rust projects for other manufacturers' devices but none, as far as I know, are backed by the manufacturer. For example, there is a project to implement Rust on the Pico without using the existing SDK, but for this to move to the mainstream Raspberry Pi would have to put some effort in.

If Espressif continues to back the new esp-hal then it could give them a significant edge in this particular part of the embedded market. If I were Raspberry Pi I would be fairly worried and might just do something to catch up.

esprust

 

More Information

esp-hal 1.0.0 beta announcement

Related Articles

Rust Foundation Update On Goals

Rust 1.83 Improves Const Context Code Handling

Rust 1.82 Improves Apple Support

RustConf Keynotes Announced

Is Rust Safe?

Rust Foundation Announces Safety-Critical Consortium

Rust 1.72 Stabilizes APIs

 

To be informed about new articles on I Programmer, sign up for our weekly newsletter, subscribe to the RSS feed and follow us on Twitter, Facebook or Linkedin.

 

Banner


Postman Launches AI Agent Builder
04/02/2025

Postman has launched AI Agent Builder, a tool for the Postman system that uses AI to give developers a way to create intelligent, AI-driven API agents by combining LLMs, APIs, and workflows.



GitClear Reveals AI's Negative Impact On Code Quality
05/03/2025

Code assistants are increasingly taking on the task of code-writing. While this might seem welcome, research from GitClear reveals a negative impact on code quality, with more use of copy and pas [ ... ]


More News

espbook

 

Comments




or email your comment to: comments@i-programmer.info

<ASIN:1871962919>

<ASIN:1871962927>

<ASIN:187196282X>

Last Updated ( Wednesday, 05 March 2025 )