Why Rust is a great fit for embedded software – 2023 update
tweedegolf.nl
tweedegolf.nl
I am using SPARK2014[0], a big subset of Ada, that has a 25-year track record in high-integrity, safety-critical applications in civil and military applications in many fields. It's also very easy to pick up with integrated tooling and a package manager called Alire.
I used to despise verbose syntax, and when I first tried learning Ada over 12 years ago, I now see SPARK2014's syntax and methods as much easier and to work with especially with the surrounding and supportive ecosystem.
I worked through the book, "Building High Integrity Applications with Spark"[1] that is a very nice summary and intro to SPARK based on its use in the CubeSAT program.
Here's a cute little article on how SPARK2014 was used to replace some low-level stabilization routine in a bigger C program for a specific consumer drone:
https://blog.adacore.com/how-to-prevent-drone-crashes-using-...
[1]: https://github.com/rust-lang/rust/pull/107606 [2]: https://cohost.org/oli-obk/post/165584-ranged-integers-via [3]: https://blog.yoshuawuyts.com/pattern-extensions/#pattern-typ...
type Temperature is range -100 .. 300; -- in Celsius, operating range for an aircraft or system perhaps
You cannot assign anything outside that range to variables of that type, if the value is known at compile time it won't compile otherwise you get a runtime error (unless you disable checks). You cannot assign an arbitrary integer variable's value (that holds a value in that range) into a variable of type Temperature, you have to cast it. T : Temperature := 500; -- won't compile
...
T : Temperature;
N : Integer := 50;
...
T := N; -- won't compile
T := T1 + T2; -- two other temperatures; runtime error if sum is outside -100 .. 300
If you want a subtype range you might do something like: type Days is (Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, Sunday); -- an enumeration
subtype Weekdays is Days range Monday .. Friday; -- ranges are inclusive in Ada
Now you can have a variable of type Days and try to put its value into a variable of type Weekdays and you'll get a runtime error if it's Saturday or Sunday. And you can use these for array indices. These are actual arrays, not dictionaries, so you don't get the performance penalty of a map/dictionary (though generic maps are also available): Schedule : array (Weekdays) of ...; -- fill in with some useful type; Weekdays is the index range
D : Days;
W : Weekdays;
...
W := D; -- will compile, may error at runtime
D := Saturday;
W := D; -- will error at runtime
W := Sunday; -- won't compile
W := Monday; -- will compile
Schedule(W) := ...;Out of curiosity, was the problem with the language itself, the embedded library/tooling ecosystem, or something else?
I seem to recall they were using Spark for some of the core libraries then exposing all the goodness to the Rust code.
Here with some examples using gcc and gnat: https://gcc.gnu.org/onlinedocs/gnat_ugn/Mixed-Language-Progr...
And finally here with the Adacore learning site: https://learn.adacore.com/courses/intro-to-ada/chapters/inte...
I have limited experience with FFI in Ada, but never had any issues. Cross compilation is about the same as you'd expect from any mature language ecosystem. Metaprogramming, it does not have macros but it has a very good generics systems.
Also for some reason your comment was dead (not flagged dead) so you may want to email the HN mods (see contact at the bottom of the page) about that.
So, each time I create a new project with alr, an Ada toolchain will be downloaded into its project directory?
I thought about switching to something more low level but as long as I can stomach my current job I don't really see a good reason why. I don't even earn that much money but I'd probably still take a pay cut going into embedded.