
Rust bare metal on ARM microcontroller - AndrewDucker
http://antoinealb.net/programming/2015/05/01/rust-on-arm-microcontroller.html
======
steveklabnik
We've been actively working on stabilizing #![no_std], as well as making
cross-compilation easier. In the future, ideally, you'll just need

    
    
        $ cargo build --target thumbv7em-none-eabi
    

instead of

    
    
        $ rustc -C opt-level=2 -Z no-landing-pads --target thumbv7em-none-eabi -g --emit obj -L libcore-thumbv7m -o runtime.o runtime.rs
    

or other shenanigans. You can run that Cargo command right now, but you still
need to do a little bit of work first.

~~~
antoinealb
Nice! Any pointer to a documentation / wiki explaining how to use it ?

~~~
steveklabnik
"it" being --target? [https://github.com/rust-
lang/rfcs/blob/master/text/0131-targ...](https://github.com/rust-
lang/rfcs/blob/master/text/0131-target-specification.md) is the original RFC.
Off the top of my head, I think that's it for now. Since cross compilation is
getting easier in the future, I haven't invested a lot of time into writing
docs now.

------
Animats
Very nice. When this gets cleaned up, and Rust stabilizes a bit more, it
should be promoted for the Arduino Due. The Due is a minimal ARM machine, a
step up from the Atmel CPUs but well below the level required to run Linux.

Safety at the Rust level is very valuable in embedded work. Debugging small
embedded machines is not fun.

~~~
petra
I agree. I wonder though - why all the rust projects go bare metal, instead of
integrating a c based RTOS using rustbingen ? Seems like the fastest way to
get cross-platform, which is key for many developers - and speed rust's
adoption - making bare metal much easier.

~~~
elcritch
A C based rtos inherits all the difficulties present in C. Ideally Rust is
interesting, to me, as an ideal language to write the RTOS itself in. Once you
get through the low level details, writing a (simple) schedule system is not
hard and would be more flexible due to the better types safety in Rust. Also C
is difficult for DSLs, Rust should be better. That's the dream at least.

~~~
petra
>> A C based rtos inherits all the difficulties present in C.

Can you please expand on that, especially assuming(a big assumption) that the
c code you're interfacing is high quality , with rare bugs ?

~~~
antoinealb
Even assuming the existing code is high quality, there is still a lot of
problems with pointer ownership and type checking which Rust removes.

Personally I think the best way is to wrap existing C code into higher level,
safer Rust APIs.

~~~
elcritch
Exactly, even the most disciplined code base will have errors. Rust type
system "automates" the process that many well designed C code bases will do by
convention (e.g. borrowing and keeping ownership localised).

While wrapping C libraries in safer Rust APIs is useful for many application,
having something as fundamental as time-sharing, task interruption, etc would
be much better if written in Rust and care is taken to define simple semantics
for the system (e.g. like the recent HN post regarding state-machine based
asynchronous IO in Rust).

------
andars
Rust does look promising for embedded applications. Ideally, I'd like to be
able to use it to program Pebble applications. I managed to get a simple
executable written in rust to write to the screen a few months ago, but
haven't been able to get even slightly more complex things to work. Hopefully
the hard work of rust devs will make this easier in the future.

~~~
CyberDildonics
How would they make it easier?

~~~
andars
Erm, see steveklabnik's comment on this story. It is sort of a complex process
right now in that you have to build libcore yourself and then try to link
everything together (for me, that mostly involves trying something and then
crossing my fingers, because my knowledge of that level of tooling is
limited). I've heard several times that rust devs are hoping to make cross
compilation easier.

------
alnsn
This is going to be interesting. Rust on top of rumprun bare-metal unikernel
[https://twitter.com/gandro23/status/645734117699624960](https://twitter.com/gandro23/status/645734117699624960)

