News for hackers. Stuff that matters.
Re:I like the RP2040 by antirez on Tuesday June 11, 2024 @10:29AM (#40646580)
I switched from ESP32 to the RP2040 because it's a much more reliable and documented device. My only concern right now with the RP2040 is that there are many ESP32 models with SPIRAM but it's not so simple to find a SPIRAM equipped RP2040 board. To be honest, given that the C development environment of the RP2040 is so good, you can make good use of the memory, but when one wants to develop a large MicroPython project, the SPIRAM is really a great asset. Other than that, everything about the RP2040 is just great.
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/

Re:I like the RP2040 by j-krieger on Tuesday June 11, 2024 @04:17PM (#40650985)
I heavily disagree. I‘ve been working with the Espressif ecosystem for a couple of months now and it‘s the best documented microcontroller platform out there.
Re:I like the RP2040 by throwaway15968 on Tuesday June 11, 2024 @05:16PM (#40651594)
Completely agreed. ESP-IDF is incredible and the dev experience is miles beyond STM32 (my opinion).
Re:I like the RP2040 by dailykoder on Wednesday June 12, 2024 @04:54AM (#40655980)
> STM32 (my opinion).

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.

Re:I like the RP2040 by 15155 on Thursday June 13, 2024 @05:29AM (#40667589)
STM32 is great if you choose to use the community-maintained Embassy HAL for these chips. Zero vendor code, async/await - it's a dream.

The same code will more or less run abstractly on an RP2040, as well (for common peripherals/traits.)

Re:I like the RP2040 by 15155 on Tuesday June 11, 2024 @07:29PM (#40652863)
Meanwhile NXP is producing 3000+ page PDFs with behavioral examples.
Re:I like the RP2040 by casept on Wednesday June 12, 2024 @04:58AM (#40656009)
Only if you use their SDK. Quite a few parts of the chip lack actual register-level documentation, not so on the 2040.
Re:I like the RP2040 by mardifoufs on Tuesday June 11, 2024 @04:29PM (#40651100)
Did you use esp-idf? Or the Arduino libs?
Re:I like the RP2040 by antirez on Tuesday June 11, 2024 @05:19PM (#40651625)
ESP-IDF, Arduino IDE is untouchable for serious stuff IMHO.
Re:I like the RP2040 by mardifoufs on Tuesday June 11, 2024 @08:25PM (#40653192)
Yeah agreed, that's why I was wondering! But esp-idf has been great recently. It used to be very patchy and undocumented but I prefer it over everything else now. I'll check the rp2040 docs and try out the dev board I've had for a while, because now I'm wondering if I'm missing something haha
Re:I like the RP2040 by orphea on Wednesday June 12, 2024 @06:41AM (#40656566)
> Arduino IDE is untouchable for serious stuff

Yes, but AFAIK you don't have to use Arduino IDE for Arduino stuff? e.g. there is PlatformIO.

Re:I like the RP2040 by 15155 on Thursday June 13, 2024 @05:34AM (#40667608)
Embassy is next-level in terms of developer experience.

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.

Re:I like the RP2040 by reassembled on Tuesday June 11, 2024 @10:33PM (#40653896)
You can use Arduino libs via ESP-IDF. The IDF environment comes with a lot of libraries on its own but it is a development environment first and foremost. The design of IDF is very open and easy to understand throughout the stack. It is very easy to integrate external libraries via CMake as well.
Re:I like the RP2040 by 15155 on Tuesday June 11, 2024 @07:12PM (#40652740)
The RP2040 only has one QSPI port.

JLC will assemble a RP2040 board for you for <$3/pc at quantities of 5.

Re:I like the RP2040 by shadowpho on Tuesday June 11, 2024 @08:57PM (#40653376)
I think it’ll be more expensive. When I was looking at jlc it seemed to be $100/10 was starting point if you want assembly
Re:I like the RP2040 by 15155 on Tuesday June 11, 2024 @09:26PM (#40653552)
You need to carefully select JLC basic parts. QSPI, XOSC, etc. can all be had without paying fees. I've ordered 5+ boards with RP2040s that have come out to "cheaper than Pico" prices.
Re:I like the RP2040 by MartijnBraam on Tuesday June 11, 2024 @09:19PM (#40653507)
It all depends on how you select the parts. I've ordered a set of 5 boards for $12 total including shipping and assembly.