Live data from Hacker News

Embassy: Modern embedded framework, using Rust and async

github.com

111–120 of 167 posts

Re: Embassy: Modern embedded framework, using Rust and async

#111
post #11

Earlier quoted context omitted.

I think it's interesting because they seem to have built some vaguely pretty decent interfaces and drivers. Before that there were some attempts to make a rust embedded HAL but I think they were a bit too basic and didn't seem to get much traction. Also async interfaces are probably the most generic, because you can hook them up to superloops, single-threaded applications, and threaded code relatively easily (at leas…

> superloops I’ve been doing async non-blocking code for decades, but this is the first time I e seen that word used? I’m assume you’re meaning something like one big ass select!() or is this something else? > IMO one of the big reasons Arduino stayed firmly hobbyist tier is because it was almost entirely stuck in a single-threaded blocking mindset and everything kind of fell apart as soon as you had to do two things…

I'm surprised nobody has put together a cooperative threading C framework using the -fstack-usage (https://gcc.gnu.org/onlinedocs/gcc/Developer-Options.html#in...) option supported by GCC and clang. With per-function stack usage info, you can statically allocate a stack for a thread according to the entry function, just like async Rust effectively does for determining the size of the future. Context switching can be implemented just like any other scheduling framework (including async Rust executors), where you call the framework's I/O functions, which could just be the normal API if implemented as a drop-in alternative runtime.

Googling I see people attempting to use -fstack-usage and -fcallgraph-info for FreeRTOS, but in an ad hoc manner. It seems there's nothing available that handles things end-to-end, such as generating C source type info to reflect back the computed size of a call graph based on the entry function.

In principle Rust might have a much tighter bound for maximum stack usage, but in an embedded context, especially embedded C, you don't normally stack-allocate large buffers or objects, so the variance between minimum and maximum stack usage of functions should be small. And given Rust's preference for stack allocation, I wouldn't be surprised if a C-based threading framework has similar or even better stack usage.

Re: Embassy: Modern embedded framework, using Rust and async

#112
post #54

Earlier quoted context omitted.

Here's a good technical writeup on latency and jitter (latency standard deviation) for interrupts when it comes to Embassy, FreeRTOS, and RTIC: https://tweedegolf.nl/en/blog/65/async-rust-vs-rtos-showdown Obviously if you're working on something truly hard real-time you probably wouldn't be reaching for these tools to begin with, but for the average embedded project it seems you will enjoy quite good latency and jitt…

I've read this, and frankly its comparing apples to oranges. These are not the same things though naively they may appear the same.

Maybe actually post a legitimate criticism instead of making people think hard about what you're saying?

If I had to complain, I'd say that usually an RTOS isn't really meant for something like button handling. You can use it and it will work, but the bread and butter workload of an RTOS is multiple simultaneous CPU/time intensive tasks that need to complete within a deadline.

The embassy scheduler here could run into a problem because long running tasks would block short lived interrupts.

Re: Embassy: Modern embedded framework, using Rust and async

#113

Earlier quoted context omitted.

I agree. the type safety that it brings to the HAL. it's a like cushion for people entering this space. never understood what a watchdog is tho...

A watchdog is a piece of hardware that will automatically restart the chip if it detects the code as being stuck. The way it detects this is that you have to poke a register of the watchdog every so often, and if the register hasn't been poked for a certain timeout (usually configurable), the chip is restarted. Watchdogs exist on MCUs but also on some "proper" computers. The Raspberry Pi has one for example.

You don't need to poke the watchdog! Petting or feeding is fine too.

Re: Embassy: Modern embedded framework, using Rust and async

#115
post #114

I was pretty stoked to find this a month ago. Sadly, I bought an nRF54L15 board to start my embedded journey, which isn't 100% supported yet :/ Now I have to wait. I'm not gonna go back to C :D

What parts are you missing? (I'm working on the nrf54l support so just curious to know what is blocking you).

Re: Embassy: Modern embedded framework, using Rust and async

#116

I never learned any C based languages, so it's been a challenge, but I've enjoyed learning the basics of bare-metal no_std rust on the esp32c3, with esp-rs and its support for embassy to help me get started! My learning project -- using mqtt for HomeAssistant integration: https://github.com/n8henrie/esp32c3-rust-mqtt >

I know bare metal programming is a learning exercise but i can say for 99% of use cases esphome is awesome. I just finished making a cat feeder a esphome smart device

Yes, I have several esphome devices. Very easy to use. Unfortunately the project is not written in a language that I know, and I strongly prefer projects in languages that are familiar to me.

Re: Embassy: Modern embedded framework, using Rust and async

#117
Embassy and async Rust are probably the best things that have happened to the embedded world in the past decade!

C RTOSes are conceptually nice, but such as pain to use in the real world, a lean framework like embassy is the natural evolution.

The best thing is that embassy can actually be considered as a real-time "OS" (you can read more here: https://kerkour.com/introduction-to-embedded-development-wit...).

Re: Embassy: Modern embedded framework, using Rust and async

#118

Earlier quoted context omitted.

I would recommend getting a ST nucleo board over raspberry PICO or ESP32. The nucleo boards have integrated SWD programmer which makes flashing easier. You can also use it to debug your code. Try to get one with onboard USB port (like https://www.st.com/en/evaluation-tools/nucleo-f767zi.html ) so that you can build USB projects.

Of note neither the debugger nor user USB port on that board work with ARM Macs (guess how I found that out). You can connect it to a hub as a workaround but that may lead to data corruption (per the errata). Also worth noting that the discrete STLink V3 dongles also use the F7 for USB stuff. Also also worth noting that not all of the Embassy examples are set up to work with Nucleo boards. It's an odd choice but it i…

...how the heck did Apple break a USB port of all the things?

Re: Embassy: Modern embedded framework, using Rust and async

#119

Earlier quoted context omitted.

>rushed to market, fix the bugs later I've yet to see a MCU vendor ship without bugs. At least with ST, the MCU is very cheap. >USB controllers straight up doesn't enumerate with ARM Macs I've seen USB devices struggling to enumerate on Mac/IOS devices before. This feels more like an Apple bug to me considering how they work very well on Linux, Windows and Android.

I've yet to see a MCU vendor ship without bugs. At least with ST, the MCU is very cheap. Moving the goalposts much? You went from "lengthy errata doesn't mean anything" to "at least it's cheap", which was my point entirely. The STM32 lineup is cheap with a bunch of features, has readily available documentation, and that appeals to a lot of people. This feels more like an Apple bug to me considering how they work very…

I sympathize to some extent but really if popular products work for everybody else but not Mac, that sure seems like Apple ought to make it work even if technically it's not their fault, and I note that you've offered no evidence either way on whose fault this is.

Apple's products being shit in some ways isn't even a weird outlier, the company knows its loyal fans have nowhere else to go.

Re: Embassy: Modern embedded framework, using Rust and async

#120

Earlier quoted context omitted.

A watchdog is a piece of hardware that will automatically restart the chip if it detects the code as being stuck. The way it detects this is that you have to poke a register of the watchdog every so often, and if the register hasn't been poked for a certain timeout (usually configurable), the chip is restarted. Watchdogs exist on MCUs but also on some "proper" computers. The Raspberry Pi has one for example.

You don't need to poke the watchdog! Petting or feeding is fine too.

lol
Post reply on HN