Rust for Embedded Systems and IoT
Marius Elveg?rd
Disiplinleder Digital ?stlandet, Lokasjonsleder Asker, Senior FPGA-utvikler hos Inventas, UVVM SG
Many embedded systems today are still built in C and C++, mainly because these languages provide the low-level control often needed in domains such as automotive, maritime electronics, and medical devices. Memory management can be a serious challenge, as even small mistakes may lead to major malfunctions. Rust offers an alternative approach by giving developers fine-grained control over hardware while enforcing a safer way to handle memory and concurrency.
C/C++ to Rust
One of Rust’s main strengths is how it deals with pointers. While C and C++ allow you to create and modify pointers in risky ways, Rust requires clear ownership and borrowing rules. Allocated data structures are deallocated automatically when they go out of use, and the compiler prevents you from creating dangling references. It achieves this without needing a garbage collector; instead, compile-time checks ensure safety without introducing unpredictable overhead.
Rust’s approach to concurrency is another plus. Instead of sharing data freely between threads, Rust requires shared data to be protected by synchronisation primitives to avoid the possibility of data races. This reduces race conditions. In real-time or safety-critical work, having that level of control is essential, and Rust provides it without numerous extra runtime checks.
In many projects, abandoning C or C++ entirely is not realistic. Existing code has already been tested, and rewriting it can introduce new risks. A practical compromise is to develop new modules in Rust and integrate them into the established codebase. Rust’s Foreign Function Interface (FFI) enables this, though any latent issues in the older code can still affect the system, so careful testing remains important.
领英推荐
Rust in IoT
Rust is well-suited for IoT applications, where devices often rely on limited battery power and must operate for extended periods with minimal maintenance. Compared to traditional C/C++ implementations, Rust offers improved memory safety and more efficient resource management without sacrificing performance. Replacing parts of a project written in C or C++ with Rust can reduce both memory and CPU usage, leading to longer battery life and better responsiveness. Multiple studies show that Rust typically scores highly on energy efficiency, which is vital for IoT applications.
Rust comes with a steeper learning curve than many high-level languages. It handles memory and concurrency directly instead of relying on a garbage collector, which means developers must adjust to its strict ownership system. Also, the ecosystem for embedded and IoT work may have fewer libraries and tools compared to more established communities like those for C or Python.
Challenges and Next Steps
It is important to handle errors properly, and if Rust encounters a “panic,” it can shut down the program unless you have a recovery plan. In some critical systems, advanced static analysis or special design patterns are vital to guard against crashes.
While these challenges exist, Rust is proving itself as a strong choice for embedded systems and IoT. It offers the speed of C, backed by a compiler that guards against data races and other memory-related issues. As more companies adopt Rust for various applications, the language and its tooling continue to mature.
Did you know that you can also write functions in Rust and use them in co-simulations in VHDL? I did a presentation on this topic at FPGA Forum 2025, where I demonstrated how Rust can be used together with HDLRegression to streamline co-simulation workflows.
In Norway and around the world, embedded developers are seeing that Rust can reduce unpredictable bugs and help build efficient, reliable solutions. If you need high safety, strong performance, and careful resource usage, Rust is well worth considering.
#rust #embedded #esw #iot Inventas