Embedded Systems

Anyone who knows me very well could probably tell you that I’m a pretty big fan of Particle, a provider of hardware and software components for building internet-connected products (IoT). I love their product suite because they have abstracted the common functions of IoT products into easy-to-use components while still allowing access to all the nitty-gritty details for those of us who need to get down to that level. Read more on Adding an OLED to Your Particle Device…

Let’s face it, when you’re doing embedded development, you really don’t have a lot of great tools at your disposal. If you’re lucky, you might have a C99-compliant compiler and a microcontroller with floating-point hardware and DMA. If you’re unlucky you might have a microcontroller that doesn’t actually have a stack and a compiler that doesn’t support using structures as function arguments!

Rust now has usable support for Rust sysroots. This makes it must easier and useful to use cargo to build your embedded projects. You should be able to even use stable rust once 1.9 is out, but you will have to use a nightly for now.

A lot of things have changed since I wrote my last blog post on using Rust to build embedded firmware.

Since Rust 1.6 was released, libcore is now stable, and nostd is now a stable feature. This means we can now build Rust libraries for our embedded firmware using the official stable version of the compiler!

Computers are amazing machines. They can perform massive amounts of stuff every second, and they’re being put into everything around us to make the things we interact with on a day-to-day basis smarter and better.

This is made all the more remarkable by the fact that computers are astonishingly dumb. My favorite explanation of just how dumb computers are can be found in one of my favorite recorded talks, Richard Feynman’s lecture about computer heuristics. (Start around the 10-minute mark for the particularly relevant bit.)

I’ve been getting asked the question, “So how would I get started with embedded development?” more and more often lately.

This is actually a really tricky question. It’s not like, “How would I get started with Haskell?” or “How would I get started with Rust?” Embedded development is such a weird and diverse thing that it’s almost like asking, “How do I get started with programming?” except in an alternate universe where 128k is still a lot of RAM. I’m not sure where to even begin.

As I talked about in my last post, Embedded Rust Right Now!, you can call C functions directly from Rust without much difficulty. However, you normally still need to provide Rust types and prototypes for the corresponding C types and functions you want to use. This can be a time-consuming and error-prone process.

Fortunately there is a tool call rust-bindgen that can generate bindings automatically directly from C header files! It’s a little trickier when you’re cross compiling to target embedded systems, but you just need to pass some extra clang flags to bindgen. Read more on Generating Rust Bindings for Embedded Libraries…