Live data from Hacker News

Ask HN: Has any Rust developer moved to embedded device programming?

news.ycombinator.com

1–10 of 64 posts

Ask HN: Has any Rust developer moved to embedded device programming?

#1
Hi! Was wondering if any Rust developer have moved to embedded land. Did you switch to C/C++ or stayed with Rust? What MCU did you work with? Any tips?

I have good understanding of Rust and soon will need to program ESP32 chip. Write a driver and and http/tcp api on it.

Currently I jave seen mixed messages about Rust in embedded. Ecosystem moves fast, but semms like old C/C++ devs stay with their lang. So I'm curious what Rust devs have to say abou it.

Re: Ask HN: Has any Rust developer moved to embedded device programming?

#3
Not exactly embedded but I'm writing an operating system kernel in Rust, having done so previously with C.

I love it so far. There are still some rough edges in the tooling, but overall I'm very happy. The resulting binaries are much larger than C projects, but I'm also opting into a lot of functionality you probably wouldn't always need in smaller environments.

Re: Ask HN: Has any Rust developer moved to embedded device programming?

#4
post #2

Our company builds a wearable device using an NRF5x chip, and our firmware is written in C. We are moving to Rust for our newest device, in order to run graphical output and RT operations. It is looking pretty sweet!

And why not Carbon? :-)

Re: Ask HN: Has any Rust developer moved to embedded device programming?

#5
post #2

Our company builds a wearable device using an NRF5x chip, and our firmware is written in C. We are moving to Rust for our newest device, in order to run graphical output and RT operations. It is looking pretty sweet!

And why not Carbon? :-)

Not OP, also I don't know if is sarcasm or not, but Carbon is just too new, I would understand somehow if you asked about Zig, but isn't also mature enough.

Re: Ask HN: Has any Rust developer moved to embedded device programming?

#6
Not a Rust dev but I like the language. I've learned embedded over the last few years. I used to hate C and avoid it like the plague. On a good day now I kind of enjoy it, in some sick perverse twisted way. I'd say in general the embedded space is more project-centric in general thus new stacks are not at as significant a disadvantage as in backend land at the lower end of the project complexity and regulatory ingress spectrum. You will see gaps in terms of device driver availability and maturity and integration level with silicon vendor toolkits. However, since most projects do not use too much exotic hardware writing one or two I2C or SPI drivers won't take forever, you're probably OK to go Rust. But realistically, for complex stuff, you're going to run in to wall after wall that will eat time and money. If you can meld C/C++ and Rust in one binary or reach godlike device driver implementation status then you'll be relatively free of issues but while I'm sure that's possible once you're at the point where you're writing the whole stack you might be best to look for a job with a silicon vendor overhauling their toolkit for Rust support, since base library and code generation will help shift more product than any one shop. Try writing to TI/NXP/Renesas/STM/Freescale/Microchip/NXP/Atmel's HR department and asking for scope: I'd be surprised if you received zero interest.

Re: Ask HN: Has any Rust developer moved to embedded device programming?

#7
post #3

Not exactly embedded but I'm writing an operating system kernel in Rust, having done so previously with C. I love it so far. There are still some rough edges in the tooling, but overall I'm very happy. The resulting binaries are much larger than C projects, but I'm also opting into a lot of functionality you probably wouldn't always need in smaller environments.

Can you name a few of those rough edges in the tooling? Thanks

Re: Ask HN: Has any Rust developer moved to embedded device programming?

#8
post #2

Our company builds a wearable device using an NRF5x chip, and our firmware is written in C. We are moving to Rust for our newest device, in order to run graphical output and RT operations. It is looking pretty sweet!

And why not Carbon? :-)

From Carbon's FAQ[1]:

> Why not Rust? If you can use Rust, ignore Carbon.

So that's probably one reason.

[1]: https://github.com/carbon-language/carbon-lang/blob/trunk/do...

Re: Ask HN: Has any Rust developer moved to embedded device programming?

#9
I've been working in embedded for 5 years and am curious how rust could solve my biggest headaches:

* Managing build configurations - I use CMake to build a single application for multiple hardware platforms. This is accomplished almost exclusively through linking, e.g., a single header file "ble-ncp-driver.h" with multiple "ble-ncp-driver.cpp" files for each target platform. I call this the "fat driver" approach which has proven to be easier to work with than creating a UART abstraction or ADC abstraction. Does rust's package system address this?

* Automated device testing - fluid leaks are similar to bugs in software. They are systemic in nature and cannot be easily understood through static analysis. We spent equal time maintaining a test bench as product development.

* Preemptive operating systems - more trouble than they are worth. Often, devs get bogged down writing messages queues to pass items between task contexts and timing analysis requires detailed event tracing.

Given I don't see teams struggle with memory ownership (easy to do if you never, ever malloc), what else can rust bring to embedded dev?

Re: Ask HN: Has any Rust developer moved to embedded device programming?

#10
I started to explore the area, mostly arm based (rp2040 and STM) and a little bit of ESP32.

Tool chain wise:

ESP32 support is very recent and still based on the C tool chain and this makes it very fragile (you can break your environment easily and it is never clear how to recover except recompiling the entire tooolchain from 0)

Arm is a little better because the support is native.

The community is trying to make a generic embedded Hal platform API and implement it for specific devices. And it is pretty bad: almost no documentation, very few examples, tons of autogenerated code where you need to come back to the C world to understand the actual concepts.

Once you start to get going Rust is a blast to program in and the generated code is pretty efficient.

A small project I shared to help people starting on a raspberry pi clone (lilygo): https://github.com/gbin/rp2040-mandel-pico

Post reply on HN