HACKER Q&A
📣 the__alchemist

Thoughts on Async in Embedded?


In the Rust OSS embedded community, Async is a popular approach, most notably with Embassy: https://github.com/embassy-rs/embassy

In embedded, it's common to use interrupts, DMA, and leverage multiple cores to handle concurrent events without blocking the main loop. These are traditionally handled with deliberate register writes. Eg send a command to a peripheral to start a task. Continue running the program. When the task is complete, an interrupt fires, and code to handle the completion is immediately run.

Async/Await functionality is used to abstract over these processes, using Futures. In my own programs, the abstraction doesn't provide enough value over natively handling interrupts, and DMA, to be worth the added complexity and cognitive overhead. Eg, framework code you need to account for, and coloring issues, which I'd argue still apply to Rust.

I'm deliberately asking here, to get an outside perspective from the Rust community (They love async and RTIC), and the more general embedded community (Rust is foreign, and new patterns are viewed with caution). Of note, RTOS is popular in C embedded, which perhaps handles some of the same abstraction issues handled by Async and RTIC in rust.


  👤 detaro Accepted Answer ✓
If you squint enough, an event loop and the smaller RTOSes look pretty damn similar. And embedded is a massive range of devices and approaches, and I don't think the Rust projects are claiming to cover all of it with one thing. So the approach doesn't seem obviously useless to me, and things will adjust as needed if there's problems.

👤 steveklabnik
I am in the Rust community, and am doing embedded, but no async. That brings its own set of issues, but they're more straightforward for what we care about, personally.