Embedding Rust Language applications on the i.MX RT

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Embedding Rust Language applications on the i.MX RT

5,451 Views
fweller
Contributor V

Applications built with the Rust programming language ( https://www.rust-lang.org/ ) have become very popular lately in the safety industrial ecosystem.  The typical way to design a computer system that runs Rust applications is with a MPU running Linux. We think that for our applications, the performance of a higher-end i.MX RT would be more than sufficient. The issue that we see presently is that NXP does not offer a tested solution for enabling Rust applications on the i.MX RT. 

Can anyone recommend a solution that is KNOWN to work well on a higher-end i.MX RT?  And on which RTOS (FreeRTOS, Zephyr, etc?) would the solution work?

I spent some time searching online to see if others have already tried implementing Rust applications on a microcontroller RTOS instead of Linux.  The results are below.  None of the below solutions appear in my opinion to be fully trustworth, so I would greatly appreciate comments about success or failures using these or other methods

 

imxrt-hal

Rust for NXP i.MX RT

https://github.com/imxrt-rs/imxrt-hal

 

svd2rust

Generate Rust register maps (`struct`s) from SVD files

https://github.com/rust-embedded/svd2rust

https://community.nxp.com/t5/i-MX-RT/Is-there-an-SVD-file-for-i-MXRT1050/m-p/772462

 

freertos-rust

Create to use FreeRTOS in rust projects. The freertos-cargo-build crate can be used to build and link FreeRTOS from source inside build.rs.

https://crates.io/crates/freertos-rust

https://github.com/lobaro/FreeRTOS-rust

 

freertos.rs

A Rust wrapper for FreeRTOS.

http://www.hashmismatch.net/freertos-meets-rust/

https://github.com/hashmismatch/freertos.rs

 

zephyr-rust

Rust on Zephyr RTOS

https://github.com/tylerwhall/zephyr-rust

 

cbindgen

Embedding Rust Into Zephyr Firmware Using C-bindgen

https://www.jaredwolff.com/embedding-rust-into-zephyr-using-cbindgen/

A project for generating C bindings from Rust code

https://github.com/eqrion/cbindgen

 

 

2 Replies

4,985 Views
erling
Contributor III

Great question. I would love to hear more on this topic. I think imxrt-rs looks interesting but I dont think anyone is interested in using Rust for toggling GPIO pins or just doing plain UART communcation. What is interesting is to use Rust for application-level code not for low-level peripheral interfacing. I would love to see an easy way to combine Rust with SDK, FreeRTOS and lwIP (which are all written in C). It would be very useful if we could experiment with adding bits and pieces of Rust into our application, whilst keeping "int main()" in C.

I think your question, Rob, about ThreadX and Zephyr as alternatives to Rust are missing the point. Rust is a programming langauge not a RTOS. Using Zephyr wont save you from an out-of-bands array access, Rust will.

0 Kudos

5,147 Views
robSanders
NXP Employee
NXP Employee

There are a number of other resources that can be found on Rust documentation site.  

NXP device HALs, utilities, and peripheral access APIs - a variety of LPC, Kinetis, and i.MX RT devices are supported, although some projects are more active than others. There are some examples as well littered throughout the interwebs.

The most active projects with working examples currently (Dec. '21) appear to be lpc8xx-hal and imxrt-rs repos, the latter of which was created with teensy heavily in mind.

All of these are implementations of embedded-hal, so one could take a more platform agnostic approach and use other implemtations listed as a reference guide. 

All that being said - is there a particular reason you are looking at Rust beyond it's popularity for address safety in industrial systems? Azure RTOS (formerly ThreadX) and Zephyr both attempt to tackle those issues, and NXP officially supports those platforms for the higher end systems you are looking at.

Given NXP's continued (and extensive) support of FreeRTOS and strong investment in Zephyr as a founding member - I would think solutions built on these might prove most fruitful for the time being if you are set on Rust.

0 Kudos