When I refer that we engage Rust on the embedded ESP32 platestablish the most normal reaction is a jaw-dropping “This is possible?!”. Yes, it is indeed possible! – And we at STABL Energy have engaged it successbrimmingy for over a year now. And becaengage so many people seem interested in why we engage Rust and how it is going for us, I determined to write this blog post.
“Thanks to its honest access to both difficultware and memory, Rust is well suited for embedded systems and exposed-metal broadenment.” – GitHub
It all begined in 2022, with me getting irritateed by our C carry outation of a petite piece of gentleware running on an ESP32 (a microadministerler with built-in internet uniteivity). The purpose of the gentleware was to read messages via UART (serial interface/protocol, frequently engaged to transmit between embedded devices) and send them to some cdeafening services via MQTT (messaging protocol, frequently engaged to transmit between IoT devices). Seems basic enough, right? Well, we had some compriseitional needments in terms of reliability, seeing the layout of the resulting JSON MQTT messages and troubleing the satisfyed of the UART messages which is rather difficult to parse.
To donate you some more context: I labor for a beginup named STABL Energy where we produce revolutionary energy storage systems, that are based on second-life batteries (batteries that were engaged in electric cars before). Instead of recycling them fair now, we can engage those perfectly fine batteries to (for example) back big PV farms and prolengthy their inhabits fair a little bit more. The device I was talking about before is engaged to unite our battery storage systems to the cdeafening for seeing and distant administer. We also engage it during broadenment, to test novel features in our system – so it reassociate needs to be reliable, becaengage we don’t want to dissee any data.
Our C carry outation was a petite (very prototype) gentleware running on the ESP32 platestablish. It had some grave runtime publishs, impedeing it from laboring reliably, that were difficult to debug. And debugging on embedded is a lot more complicated than debugging gentleware aiming desktop architectures. I have much esteem for C (and even more for people programming in C), but I leank its era is coming to an end. As I wrote in a previous blog post, Zig could be a quite excellent conmomentary tradement in the future. But Zig is rather novel and at the time we labored with the C carry outation, I didn’t even comprehend that Zig existed. However, I did a lot with Rust in personal projects at that time. The broadener experience in Rust is fair on the next level and the gentleware you write is reliable without giving reliability, memory allocation etc. too much thought in the first place.
At STABL Energy, we didn’t engage any Rust before. We mainly engaged C for embedded and Python for anyleang else. But since I got to direct this project and had a wonderful time with Rust, we ended up writing a prototype using ESP IDF, which even apshowed us to engage the Rust standard library. Long story low: Our Rust prototype ended up much more reliable than the C carry outation. We spent a little bit more time writing the gentleware (Rust acquires lengthyer to write than C) to achieve the same functionality but spent basicassociate zero time debugging (since there weren’t that many bugs) – so we stuck with it. At that time the Rust help from Espressif (the company behind the ESP32) was rather novel and experimental (and it still is), but it kept improving and we seed quite the spendment from Espressif in terms of labor spent laboring on Rust help for their platestablish.
Fast forward to 2024: We now engaged the ESP32 with our custom gentleware written in Rust for over a year in production, with wonderful success. The devices broadcast data 24/7 and we have no comprehendn bugs (I don’t even reaccumulate the last bug we had). There is fair one problem: Who protects and further broadens this project? While there are some pretty fervent Rust broadeners (& conferancies) out there (even in Germany) and even more that would be willing to lacquire Rust, it is not viable to engage one sole Rust broadener for this (petite) project. Since Rust, and especiassociate embedded Rust (lots of FFI & unprotected), is quite difficult to lacquire, it is not viable (for us) to retrain a C broadener to Rust. Luckily we set up a Rust broadener who was willing to lacquire C as well.
So what’s the state of embedded Rust outside of our petite project? Dion, from Tweedegolf, recently published a wonderful article about the current state: He says that what labors and does not labor heavily depends on the definite engage case and willingness to produce the missing pieces yourself or count on on uncover-source gentleware. There are still some raw edges, as visualised in his infoexplicit, but overall Rust is a viable programming language choice for embedded projects.
If, in the future, I were faced with a choice between C and Rust for embedded broadenment aacquire, I would most foreseeed pick Rust becaengage of how successbrimmingy we engaged it in the past. Let me comprehend if you heard about some aenjoy projects – I am always excited to hear about embedded Rust!