If you care about RAM consumption, you need to share the stack between tasks, forcing you to write event-driven code. Rust async makes this easy, and a bit of function coloring is no big deal compared to converting blocking code into event-driven code the traditional way...
The alternative mechanism is to use interrupts, DMA, multiple cores, distributed devices (eg a CAN network) a state machine, an RTOS, or, it sounds like in context of this thread, PIOs! You get the point. Do these provide a similar coding style? No, and that's the point. The coding style is the objection.
I find the "how else would you do it" style questions that come up frequently re Async rust (embedded or not) amusing. It's as if there is a new method of accomplishing a task, and asking a world that has been accomplishing this task for decades how it's possible to accomplish the task without the new thing!
Because of RAM constraints, all the bare-metal projects I've worked on have used manually-written state machines, and I'm comfortable enough with this approach. But sometimes these state machines can be hard to understand when the control flow is complicated, and I am seriously considering adding some compiler-generated state machines that will fit nicely into my existing model.
- the rest of your program doesn't have to be an explicit state machine; it can use structured control flow with nested loops and conditionals and subroutines
- the interaction between the interrupt handlers and the rest of the program is almost completely asynchronous, because as long as interrupts are enabled, the interrupt can fire between any two instructions of the rest of the program; if you look at it as multitasking, it's preemptive multitasking rather than cooperative multitasking. preemptive multitasking introduces a lot of hairy error cases, and this is only moderately simplified by the fact that the rest of the program can't preempt your interrupt handler, only vice versa. arguably that makes the problem worse rather than better because you can't solve the problem with locks (except by disabling interrupts as a sort of global lock)
This works well until the requirements change and you have to run two structured control flows simultaneously. If I find myself in such a situation and have no SRAM for a second thread, rust async may be the quickest way to accomplish the goal without a major rewrite into manual event driven code.
i feel like the same kind of thing can happen even if you start entirely async, because something that was previously synchronous may have to become asynchronous, which leads to having to revalidate all your concurrency assumptions all the way up its (static) call stack. wherever you were depending on not getting preempted, you need to change the code to not depend on that anymore. but if ram is so tight that you're concerned about the sram for a second stack, maybe that's a pretty small task rather than a major rewrite
that said, i don't recall having actually had that problem
The bare minimum would be one of the examples [1] compiled with a Rust compiler and then transformed into a .uf2 file with elf2uf2 [2]. You can then just drag and drop the .uf2 file into the "mass storage device" presented by the bootloader. To get the bootloader to mount, you press a button on a Raspberry Pico (or short two outputs if you're using bare RP2040) while plugging it in.
You'll probably want a debug probe [3] driven by probe-rs [4] at some point, it's just much more convenient to flash and debug with it.
[1]: https://github.com/embassy-rs/embassy/tree/main/examples/rp/...
[2]: https://github.com/JoNil/elf2uf2-rs
[3]: https://www.raspberrypi.com/documentation/microcontrollers/d...
[4]: https://probe.rs/
STM32 is horrible, if you don't want to use the HAL.. Everything I used (Atmel, ESP32, rp2040) was better than that - Tho I heard NXP is bad.
The same code will more or less run abstractly on an RP2040, as well (for common peripherals/traits.)
JLC will assemble a RP2040 board for you for <$3/pc at quantities of 5.
Yes, but AFAIK you don't have to use Arduino IDE for Arduino stuff? e.g. there is PlatformIO.
If you must use C, ESP-IDF/Arduino aren't terrible. But you still don't really have a package manager or means to abstract anything, especially across devices.
The cohesion present in Embassy between the HALs, probe-rs, etc. is really amazing.
With Embassy for example, I can run the same async/interrupt-driven I2C driver code on any number of different MCUs across various manufacturers. This holds true for many, many different types of peripherals in the ecosystem. For the unique peripherals, implementation style and interface are extremely consistent and high-quality.