News for hackers. Stuff that matters.
Re:I like the RP2040 by dgroshev on Tuesday June 11, 2024 @10:58AM (#40646932)
I ended up cutting a section on Rust support from the post, but if you're open to Rust (iirc you were sceptical at some point?), async Rust is really pleasant to use in embedded. Dario Nieuwenhuis, one of the main people behind Embassy, gave a great overview talk at RustNL: https://www.youtube.com/watch?v=H7NtzyP9q8E
Re:I like the RP2040 by antirez on Tuesday June 11, 2024 @11:23AM (#40647303)
Thanks, I prefer using C :) But happy that there are options out there.
Re:I like the RP2040 by the__alchemist on Tuesday June 11, 2024 @11:23AM (#40647302)
I disagree. Rust on embedded is fantastic (I do STM32 programming on rust all the time, and have used the RISC-V ESP chips and nRF-52 as well), but Async Rust on embedded suffers from the same problems of contagion and coloring that non-embedded async rust has.
Re:I like the RP2040 by fleventynine on Tuesday June 11, 2024 @11:36AM (#40647513)
Everything had tradeoffs, but the composability of the state machines built by the compiler's async support allows you to easily build multi-tasking bare-metal systems with thousands of "tasks" and no RTOS (or SRAM-wasting threads). I highly recommend playing with Embassy for a week before discounting this approach for embedded software.

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...

Re:I like the RP2040 by the__alchemist on Tuesday June 11, 2024 @11:41AM (#40647603)
I have - it does not avoid the structural and compatibility problems of Async in other contexts.
Re:I like the RP2040 by fleventynine on Tuesday June 11, 2024 @11:49AM (#40647737)
Can you go into more details? Most of the criticism I've read tends to be more abstract ("I don't like how ALL my blocking-style calls need to be async"), and doesn't propose an alternative mechanism to async that can provide a similar coding style in the same tight RAM footprint.
Re:I like the RP2040 by the__alchemist on Tuesday June 11, 2024 @11:53AM (#40647793)
I think you'll find details regarding any discussion of async in rust and other languages - I don't mean to casually dismiss your question, but my objections are not unique.

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!

Re:I like the RP2040 by fleventynine on Tuesday June 11, 2024 @12:07PM (#40647976)
As I see it, if you need everything to run on a single cpu core, the alternatives are to either implement threads (wasting memory on redundant stacks) or to write the state machines manually. Whether the state machine is pumped by interrupts or not doesn't change anything IMHO.

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.

Re:I like the RP2040 by kragen on Tuesday June 11, 2024 @02:56PM (#40650065)
none of this will be news to you, but it's probably of interest to other people reading the discussion. you can do stuff inside the interrupt handler itself, and while what you do there does have to be an event-driven explicit state machine, interrupts introduce two key differences:

- 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)

Re:I like the RP2040 by fleventynine on Tuesday June 11, 2024 @05:52PM (#40652016)
> 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

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.

Re:I like the RP2040 by kragen on Tuesday June 11, 2024 @06:17PM (#40652277)
i don't have experience with rust async, although i used to maintain a csp protocol stack in python async, which is pretty similar, so tell me if this is wrong

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

Re:I like the RP2040 by galangalalgol on Wednesday June 12, 2024 @09:18AM (#40657810)
A bit late to the thread but it is still on the front page. I've got some esp32 risc-v eval boards I've meant to mess with, but I'm nervous about their availability due to political instability and also while the rust support seems pretty great, I don't really know what is going on down in the hal and whatnot. Is rust on the 2040 well supported? Is it too well supported? Is it well enough documented that I could start with no software of any sort and load a pure rust blob and have it do some uart or something? My motivation is to recapture the feel of the c64 or Amiga1k wherebthe only mmu is optional page protection at most and you know what everything in memory is doing.
Re:I like the RP2040 by dgroshev on Wednesday June 12, 2024 @01:01PM (#40660358)
If I get your question right, you still need some host software (like a rust compiler)! It's not exactly micropython experience.

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/