Rust on the Arduino Due
github.comThe ability to run with a small runtime system on bare metal, microcontrollers and such makes Rust, in my opinion, one of the most interesting new languages out there right now.
Native code with a lean and mean runtime system has a lot of advantages over bytecode based virtual machines and slow interpreters.
This is an amazing feat with Rust being a modern open alternative to C! So far many have tried and failed. Rust developers have learned well and Rust seems to be on right track.
I've been working on this problem a while ago, but Virgil II didn't get much traction outside of a couple academic projects. It's here though:
Javascript is in a similar situation with node.js ported to a Cortex-M3 ARM microcontroller (similar to the Due) http://technical.io/
I've been working off and on porting the go runtime to a microcontroller, but still finicking with segmented stack support.
> Javascript is in a similar situation with node.js ported to a Cortex-M3 ARM microcontroller
Well, yes and no. Yes, there are JavaScript environments ported to different platforms, including microcontrollers. But no, JavaScript is not compiled to native code ahead of time nor does it run without a big runtime system.
While there is some technical trickery involved in getting JavaScript running on different platforms, I find the new LLVM-based languages that run on bare metal much more interesting.
Due to its nature, even the best of JavaScript implementations waste quite a lot of resources compared to native code. While computers are fast enough and have enough memory not to notice the difference, it's still consuming more battery power and producing more heat than executing native code. And it's power and thermals that have been the limiting factor of computational power for the past decade.
This is great -- I'm very pleased to see a challenger to C/++ step up in this space. And I'm starting to get really interested in Rust. It would be great to have a safer language to use in the place of C/++, particularly since the world seems to have decided to disregard Ada.
That said, it's important to note that this is not Rust on an AVR Arduino -- it's the Due, which sports an Arm Cortex M3. Targeting AVR which probably be much more difficult (at least that's what I've read). So you won't be able to get this running on your Uno.
LLVM doesn't target the AVR processors, and while there is a avr-llvm backend, I think it is still very early in the development cycle. It is quite possible that you could get it to work with some effort, but it is a lot more complex than targeting an ARM microcontroller.
With awesome boards like the Teensy 3.0 (Cortex M4, http://www.pjrc.com/store/teensy3.html) available on the cheap, not being on AVR isn't the huge disadvantage it once was. At least if you don't count the hardware people already have.
I agree, there's are some awesome Arm Cortex chips out on the market now, for not much money at all. And I agree it's not a huge disadvantage not being on AVR, I just wanted to make the point that Rust doesn't run on traditional Arduinos, since that's what most people would assume reading the headline.
Texas Instruments practically gives away their development boards. Here is their Stellaris Launchpad board with ARM Cortex-M4F-based MCU for just 8$! Much cheaper than even AVR arduinos! https://estore.ti.com/Stellaris-LaunchPad.aspx
What's more, these days you can even use the Arduino IDE for development on these boards. The Energia project has ported Wiring and Arduino IDE for TI boards. If I wasn't such a minimalist, I would get one (or two) in a heartbeat!
Edited: Forgot to paste the link.
The TI offerings look geared towards low power and are kind of anemic on the high end with up to only 32kB ram and 256kB flash. ST/NXP/Atmel have parts with over four times that (and the ST eval board is also only $15). I know you can do a lot with a little (I used to design with pic16), but for higher level languages without runtimes optimized for embedded (eg rust), I'd want all the room I could get.
MikroElektronika Embedded Solutions also sells Basic and Pascal compilers for embedded development.
Quite surprised. Exactly a year ago I was in hope that someone do something similar for Golang, but soon realized that it's impossible because Golang relies heavily on GC. Now this seems quite interesting.
This is not true.
There are companies selling development kits with GC enabled system programming languages, like Oberon, for embedded development.
http://www.astrobe.com/default.htm
Granted, ARM Cortex-M3 and NXP LPC2000 microcontrollers are more powerful than typical Arduino hardware, but one does not need to target all possible hardware out there.
http://technical.io/ even managed to run Node.JS on a Cortex-M3, but in the deeply-embedded world where performance/$ and real-time constraints matters, having a always-GC system like Golang (especially considering it's designed for cached cores) doesn't sound very promising.
However I did look Golang because it makes concurrency (quite important in embedded programming) easy. Now with Rust...
I'm more excited to see that the project is based off one for the STM32F4. I've got one of those lying around and I'm looking forward to trying this out. :)
The stm32f4 RULES. If you haven't got enough info on it, i'd just like to plug the subreddit I created specifically for the stm32f4: http://reddit.com/r/stm32f4
So far you're still stuck calling Wiring methods <digitalWrite, pinMode, etc...> from directly extern'd C. But a quick wrapper around the basic functions shouldn't be too hard and allows for a more rust-y (rust-ful?) experience.
I'm going to go with rustic. I think the phrase -a more rustic experience- has a much better sound and connotation than -a more rusty experience-.
Yeah, throwing out the Wiring methods and implementing more idiomatic ones in Rust shouldn't be hard.
I wrote it during an after work hackathon, so I didn't really have time to make it both working and nice unfortunately.
Since this builds on zero.rs, there are some limitations.
https://github.com/pcwalton/zero.rs
Garbage collection, tasks, and failure will not work. All
the other language features, including unique pointers,
references, and closures do work, so programs such as
sprocketnes that do not use garbage collection should be
fine.
The Rust standard library cannot be used in this mode,
but splitting out the Rust standard library into a
portion that can be used in freestanding mode would be an
interesting and valuable project (IMO).Does anybody knows, would it be possible to use reference counting(and thus build hard real time systems), maybe by splitting the library?
You can use the `Rc` or `RcMut` types in the standard library. They're just smart pointers, like C++ `shared_ptr`.
Is it possible to use them in zero ? because ksr2's comments tells otherwise.
Nowadays you can just use libstd in no-runtime apps; you can choose whether to start the runtime and if you're running on bare metal, just don't start it.
But one can implement those, they are language items.
I was able to build and flash my Due with this, very cool. The possibilities are really exciting!
I'd assume the libarm thingy is at least partially generated instead of being handwritten?