Pragmatic Bare Metal Rust
hashmismatch.net
hashmismatch.net
My day to day work largely involves maintaining and improving various process models (largely written in C or Fortran) which feed into our operating guidance systems.
I'm really curious to try running rust code on the popular ESP8266 module (http://makezine.com/2015/04/01/esp8266-5-microcontroller-wi-... and http://www.esp8266.com/), but I think the board's xtensa architecture and LLVM's lack of support for it means its a non-starter. If anyone is a LLVM guru, is there any hope of compiling code for xtensa architecture and ABI? Or is there any crazy way to get LLVM to compile rust into plain old C code that can then be compiled with the modified GCC toolchain that supports the ESP8266's xtensa architecture?
Rust can emit to LLVM-IR via `--emit llvm-ir` when compiling your Rust program, but I think the IR that gets produced isn't platform agnostic.
[1] Disclosure I contribute to that repo when allowed to :-)
Observe:
http://source.winehq.org/git/wine.git/blob/master:/dlls/msvc...
[0] https://zinc.rs/
If I'm not wrong, it will be merged with the official version soon.
I have been working with Matt Coffin some on getting this working. Feel free to increase its chances of merging by helping us test any of the supported boards (Freescale K20, NXP LPC17xx, SAM3x (on a branch), STM32F4, STM32l1, TI Tiva C).
I plan on putting together an RFC for how we can modify zinc (or provide documentation) to make it easier for individuals to create both libraries and projects that work well with zinc, but do not require modifying zinc itself.
The Due has 512KB of room for code which is quite a lot (for microcontrollers).
See: http://mainisusuallyafunction.blogspot.com/2015/01/151-byte-...
The end of the market with tiny micros and extremely simple applications (like just blinking LEDs) is likely to never be well suited to Rust, but doesn't gain much from it anyway.
* I don't think a few tens of bytes is realistic for a real application that needs to set up the stack, timers, and then blink some LEDs (https://github.com/mcoffin/zinc/blob/new-build/examples/app_... / https://github.com/mcoffin/zinc/blob/new-build/examples/app_...)
* Assuming the code size overhead does not continue to bloat after some initial overhead, I think rust can still be very competitive. Although modern embedded systems are still very constrained, the days of 8-bit micros are basically over. You can buy a 32-bit ARM micro for nearly the same cost with sufficient RAM/Flash to run rust well.
* Looking back, I think the size of blink should actually be closer to 600 bytes. Will need to investigate: http://zinc.rs/stats/
Some utility to assist bulk conversion from C to Rust would be nice. That way Rust-based firmware could be reality in 2025. :-)
One of the problems with this is that Rust's guarnatees usually really affect your design. I'd imagine that a bulk C -> Rust translator would have to use `unsafe` all over the place.
Doesn't mean that it wouldn't be useful, but I wonder if slowly replacing APIs bit by bit isn't a better approach overall.
My experience with code automatically converted has not been good.