Author Topic: Rust for embedded  (Read 10201 times)

0 Members and 1 Guest are viewing this topic.

Offline SreejitSTopic starter

  • Contributor
  • Posts: 25
  • Country: in
Rust for embedded
« on: September 26, 2016, 05:26:01 am »
Hello everyone!
I recently came across a programming language called rust which is fast but safe language. My immediate response was to use it for embedded dev. It seems people already have started that and a github repo named zinc can be used to for a handful of uCs (NXP lpc11xx, NXP lpc17xx, Freescale k20, ST STM32f4, ST STM32l1).
Only few peripherals are supported and as a beginner I would love people contributing to the project as I really feel it would help the community to write awesome embedded firmware.
I am so excited about the project!!
What is your view on this??
Github link : https://github.com/hackndev/zinc
My favorite place to hang out : FooBar
 

Offline nano

  • Contributor
  • Posts: 29
  • Country: de
Re: Rust for embedded
« Reply #1 on: September 26, 2016, 05:54:39 am »
I think rust is really interesting for embedded and I plan on using it in future.

There are more embedded rust projects besides zinc that may be interesting:
http://www.tockos.org/ - A secure operating system for MCUs with a nice blog.
https://japaric.github.io/copper/ - WIP Book on embedded development in Rust.
 

Offline ataradov

  • Super Contributor
  • ***
  • Posts: 11228
  • Country: us
    • Personal site
Re: Rust for embedded
« Reply #2 on: September 26, 2016, 05:56:53 am »
Rust is a decent language, but its safety comes at a really big price. Once you narrate the program with all those borrowing directives, it starts to look like total unreadable garbage.

Some features of the language would be too heavy for the embedded systems.

I don't think it is going to be really usable in embedded world.

Also, being more oriented towards desktop programming, it really lacks granularity of memory control and heavily relies on dynamic memory allocation.
Alex
 

Offline SreejitSTopic starter

  • Contributor
  • Posts: 25
  • Country: in
Re: Rust for embedded
« Reply #3 on: September 26, 2016, 06:03:05 am »
Cool!!I never knew there are rust+embedded libraries!!Thanks for pointing it out :D
My favorite place to hang out : FooBar
 

Offline SreejitSTopic starter

  • Contributor
  • Posts: 25
  • Country: in
Re: Rust for embedded
« Reply #4 on: September 26, 2016, 06:32:17 am »
@ ataradov
I was under the impression that compile time optimizations and lack of garbage collector would make it apt for embedded stuff.
May I know why do you think its still heavy for embedded use?
My favorite place to hang out : FooBar
 

Offline ataradov

  • Super Contributor
  • ***
  • Posts: 11228
  • Country: us
    • Personal site
Re: Rust for embedded
« Reply #5 on: September 26, 2016, 06:39:30 am »
May I know why do you think its still heavy for embedded use?
Unicode strings, heavy reliance on dynamic memory. Advanced language tools (like iterators) can hide some slow code behind really nice syntax.

In embedded systems, direct memory access is an important thing, so half of your code will end up looking like this:
Code: [Select]
ptr::write_volatile(&mut (*self.registers).scr, 0x0000001);

Also, if you look at that OS code, there are a lot of "unsafe" places.

And with following good programming practices, it is not that hard to write good programs in C. Rust still will not save you from making logical mistakes, which become prevalent once you can write safe code.
Alex
 

Offline SreejitSTopic starter

  • Contributor
  • Posts: 25
  • Country: in
Re: Rust for embedded
« Reply #6 on: September 26, 2016, 06:50:18 am »
Quote
Rust still will not save you from making logical mistakes

True that. No tool can defeat human dumbness ;).

What is the opinion on using rust as a quick prototyping language and then port it to C for production. I feel that way the developers will feel less frustrated.
My favorite place to hang out : FooBar
 

Offline alexanderbrevig

  • Frequent Contributor
  • **
  • Posts: 700
  • Country: no
  • Musician, developer and EE hobbyist
    • alexanderbrevig.com
Re: Rust for embedded
« Reply #7 on: September 26, 2016, 06:53:18 am »
I really like rust for systems programming and I've had fun making some simple web server stuff. If you need concurrency and like to think functional, I'd recommend Rust.

However, I must say I would not consider it for embedded because the intent of the language does not match our needs. The intent of C is much much closer.
 

Offline ataradov

  • Super Contributor
  • ***
  • Posts: 11228
  • Country: us
    • Personal site
Re: Rust for embedded
« Reply #8 on: September 26, 2016, 06:55:27 am »
What is the opinion on using rust as a quick prototyping language and then port it to C for production. I feel that way the developers will feel less frustrated.
Rust is nowhere ready for production on embedded. Why do you think it makes it easy to prototype? I see all the limitations really annoying, to the point where it will just make sense to wrap the whole thing into one big "unsafe { }" block.

Plus, if you write something in a truly Rust style, there is no way to port it to C, it is basically a full rewrite.

Also, there are no header files for MCUs, so all low level code right now is a bunch of magic numbers. Some of this is solvable, but I just don't see why anyone would bother. It is a pointless exercise, like MicroPython and embedded Java.


Alex
 

Offline SreejitSTopic starter

  • Contributor
  • Posts: 25
  • Country: in
Re: Rust for embedded
« Reply #9 on: September 26, 2016, 07:08:21 am »
I would agree that the current state of rust is pretty unusable but i am excited about the possibilities.
Quote
Why do you think it makes it easy to prototype?
To get a peripheral up and running using C code may take more time than using a functional language. So you can check whether or not the hardware is sending/receiving correct data or something like that fairly easily, just like it is done in arduino(Don't Hate ;D)
My favorite place to hang out : FooBar
 

Offline ataradov

  • Super Contributor
  • ***
  • Posts: 11228
  • Country: us
    • Personal site
Re: Rust for embedded
« Reply #10 on: September 26, 2016, 07:11:58 am »
I chose to master the tools I use daily and it does not take me a long time to implement things.

Also,  writing low level code in Rust is a nightmare. 

Or you were going to depend on drivers written by others? In that case you are going to wait for a long time until your part is supported.
Alex
 

Offline SreejitSTopic starter

  • Contributor
  • Posts: 25
  • Country: in
Re: Rust for embedded
« Reply #11 on: September 26, 2016, 07:16:10 am »
Cool...I see your point. :-+
I just wish to lower the entry barrier for embedded systems....
My favorite place to hang out : FooBar
 

Offline ataradov

  • Super Contributor
  • ***
  • Posts: 11228
  • Country: us
    • Personal site
Re: Rust for embedded
« Reply #12 on: September 26, 2016, 07:18:49 am »
Entry barrier must be high,  otherwise you end up with an industry full of unqualified people. Arduino is already doing this to a certain extent.
Alex
 
The following users thanked this post: newbrain

Offline SreejitSTopic starter

  • Contributor
  • Posts: 25
  • Country: in
Re: Rust for embedded
« Reply #13 on: September 26, 2016, 07:34:04 am »
Well, even with industry full of this "qualified" people, embedded developers have to work with primitive tools and debuggers that are not taking full advantage of developments in programming languages. That is something I find very annoying as a beginner. And that is why I took immediate interest when I found about rust.

Anyway, I can conclude that languages like rust is currently unusable but who knows what the future holds for us !!
My favorite place to hang out : FooBar
 

Offline SreejitSTopic starter

  • Contributor
  • Posts: 25
  • Country: in
Re: Rust for embedded
« Reply #14 on: September 26, 2016, 08:10:57 am »
Can anyone share there experience in embedded coding in language other than C/C++ ?
PS: I dont have any personal grudge against C/C++ , just want to know stuff, that's all!
My favorite place to hang out : FooBar
 

Offline farsi

  • Regular Contributor
  • *
  • Posts: 66
Re: Rust for embedded
« Reply #15 on: September 26, 2016, 10:57:59 am »
maybe you could look at:

embeddednodejs.com

while javascript is for sure not the same in code size and efficiency than C or C++, its syntax is popular and there is larger community of programmers around.
 

Offline legacy

  • Super Contributor
  • ***
  • !
  • Posts: 4415
  • Country: ch
Re: Rust for embedded
« Reply #16 on: September 26, 2016, 11:15:45 am »
I don't think Rust is good for the low-level :-//
 

Offline alexanderbrevig

  • Frequent Contributor
  • **
  • Posts: 700
  • Country: no
  • Musician, developer and EE hobbyist
    • alexanderbrevig.com
Re: Rust for embedded
« Reply #17 on: September 26, 2016, 01:38:51 pm »
I've tried JavaScript (based on Espruino), MicroPython and a homebrew LISP.
They're all fun and different, and feel good while initially prototyping. But sooner or later you hit a wall because you're not as low level as you need to be.

If you had asked me a year ago I would be a huge proponent for scripted languages for the embedded, but since then I've had to rewrite all my previous work to low level. I feel more confident in the result, and looking back I would never sell a product that's running a script.

Programming in C will mean the initial learning curve is larger, but you get an intimate knowledge of the chip which enables you to be quick down the line. Seemingly weird bugs may become obvious when you're not simply doing some version of digitalWrite(pin, state) but instead know which registers to check etc.

C (and C++ if the tool chain is good) are my hands down favorites. I've looked at ADA too, but I'll rather stay with my good old friend.
 

Offline SreejitSTopic starter

  • Contributor
  • Posts: 25
  • Country: in
Re: Rust for embedded
« Reply #18 on: September 26, 2016, 02:02:40 pm »
@ alexanderbrevig
I think i am at the stage where you have been an year ago :D
I feel all the scripting is fun to implement and i am guessing that's where the fun ends....
Can you share on how your experience was with Ada?
Thank You!
My favorite place to hang out : FooBar
 

Offline legacy

  • Super Contributor
  • ***
  • !
  • Posts: 4415
  • Country: ch
Re: Rust for embedded
« Reply #19 on: September 26, 2016, 02:45:33 pm »
I've looked at ADA too, but I'll rather stay with my good old friend.

GNAT? Green Hills? for PowerPC? AVR8? AVR32?
with/without exceptions enabled?

 

Offline alexanderbrevig

  • Frequent Contributor
  • **
  • Posts: 700
  • Country: no
  • Musician, developer and EE hobbyist
    • alexanderbrevig.com
Re: Rust for embedded
« Reply #20 on: September 26, 2016, 03:03:36 pm »
[...]
I feel all the scripting is fun to implement and i am guessing that's where the fun ends....
I still use an Espruino (javascript) from time to time if I want to just try something out very quickly.
They also make for good live demos, as you can program them with the REPL and have things happen instantly.

Can you share on how your experience was with Ada?
I tried http://libre.adacore.com/ and https://github.com/AdaCore/Ada_Drivers_Library using a tutorial I couldn't find just now...
There was some difficulties setting it all up, and I don't really like the language so I did not bother to spend much time on it. I got the LEDs blinking and stopped at that.

It seems to me there are some people on this forum who likes it, maybe try to google ada site:eevblog.com or start a thread on the topic? :)

I forgot to mention I also tried http://www.eluaproject.net/ which is also kind of cool, but I stopped after some simple tests with that as well.
 

Offline legacy

  • Super Contributor
  • ***
  • !
  • Posts: 4415
  • Country: ch
Re: Rust for embedded
« Reply #21 on: September 26, 2016, 03:35:14 pm »
There was some difficulties setting it all up, and I don't really like the language so I did not bother to spend much time on it. I got the LEDs blinking and stopped at that.

if you want to try ADA, you'd better use GNAT with host=PC, target=PC
it's more comfortable, this way
once you have mastered the language you can move to
host=PC, target=PowerPC (we also have emulators, e.g. Qemu)

I wouldn't suggest ADA (especially with exceptions enabled)
for small machines with restricted amount of resources and ram

I happen to use ADA in avionics, our targets are PowerPC fly-control boxes
usually developed around PowerPC460, e500, with 128Mbyte of ram at least

the low level (kernel, driver, etc) is still written in C (rarely in C++)
and ADA takes its seat on a BSP/iBSP for the high-level (Application)
« Last Edit: September 26, 2016, 03:52:15 pm by legacy »
 

Offline legacy

  • Super Contributor
  • ***
  • !
  • Posts: 4415
  • Country: ch
Re: Rust for embedded
« Reply #22 on: September 26, 2016, 03:47:59 pm »
elua

eLua is also supported in the new line of pocket calculators
made by Texas Instruments under the name of "Ti-nSpire"
if you are interested, here it is a good forum
(it points directly to the eLua section)

I have already bought mine, lucky second hand from ebay
paid 60 USD, and freely updated to the last OS version
in order to have the full eLua support available
along with the CAS (computer algerbra system) support

to make the story short: eLua rocks for those things
and it's also used inside a lot of game-engines :D
 

Offline ataradov

  • Super Contributor
  • ***
  • Posts: 11228
  • Country: us
    • Personal site
Re: Rust for embedded
« Reply #23 on: September 26, 2016, 03:51:39 pm »
to make the story short: eLua rocks for those things
Except if your MCU does not support double precision flaoting point. In that case eLua sucks very much. And again, it is not a low-level language, it is good for scripting, but no for system programming.
Alex
 

Offline legacy

  • Super Contributor
  • ***
  • !
  • Posts: 4415
  • Country: ch
Re: Rust for embedded
« Reply #24 on: September 26, 2016, 03:56:27 pm »
Except if your MCU does not support double precision flaoting point

of course, I meant for those things like pocket calculators (arm based) developed with double precision engines or with CAS engines, in those cases eLua interfaces the engine with its scripting capability, and it's damn useful

the alternative consists in downloading the C SDK, and develop your own calculator app in C

you can choose, therefore it makes sense  :-+
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf