PLEASE, PLEASE, PLEASE try not to pollute this thread with ad hominem, strawman, funky and flawed edge cases... we already have the other
thread for that.
It would be nice to collect here only constructive discussion and useful information.
FLASHING/RUNNING/LOGGING/DEBUGGINGTwo somewhat overlapping tool-sets competing for sponsors, the first one
probe-rs is the rusty implementation that replaces gdb (includes a gdb stub for seamless integration)
On windows if you want to use J-Link you need to replace its USB drivers with zadig thus preventing the regular Segger tools to connect to it (how can possibly those people think that you ever wanna do that???)beside the debugger itself, two command line tools and a vscode extension are provided:
cargo-flash: downloads the code to the MCU, starts it, and returns
cargo-embed: downloads the code to the MCU, starts it, open RTT terminal (s) and starts the debugger server (you need to connect to it manually)
can save logs -AFTER- you kill the communication, saving does not support defmt (see below)
probe-rs-debugger: a vscode extension that allows seamless debugging experience by configuring launch.json, logs are directed to a vscode terminal (I don't know if and how the can be automatically saved). This extension + probe-res functionally replace cortex-debug + openocd which is also a viable alternative, even if I perceive the older (and possibly going to be dismissed) one.
To my understanding these are the "original" tools on which the second toolset
knurling tools is built upon. They provide different resources:
probe-run: is a cargo-embed replacement which adds stack back-traces (albeit a false positive warning "(HOST) WARN call stack was corrupted; unwinding could not be completed still appears notwithstanding the fact that its
issue has been closed since long time) and integrates with vscode extension rust-analyzer by enabling the run|debug button (this doesn't work for me, initially I believed that it was due to the funky macros of RTIC (see below) but then I downloaded an official
template which doesn't use RTIC macros, here run|debug appears -only- over #[test] functions. Fun fact: if you delete the target directory and perform a developer-reload-window in vscode the run|debug button appears momentarily). Probe run sends the logs to stdout allowing redirection to an online, host side, application (e.g. for plotting, oh I'm gonna love this so much!). To facilitate writing such applications probe-run can format the defmt (see below) logs in json format.
defmt: logging framework optimized for efficiency through compile time encoding of the log format that are decoded host side. This, combined with RTT, allows for the highest logging speed. Inside a vscode defmt messages are clickable leading to the source log statement.
flip-link: zero-cost stack overflow protection. (nice and easy)
app-template: showcase for defmt logging, flip-link protection and run time panic.
defmt-test: didn't have time for this
REAL TIME AND CONCURRENCYUsing plain rust in a MCU where ISR are essential for most projects is kinda pain in the ass as the usual pattern (is there any alternative??) is to initialize ISR resources in the main thread and the borrow checker makes this simple thing difficult. Following this pattern there are no "security" issues as when initalizing interrupts are disabled. The
RTIC framework was devised to facilitate this process, it organizes the code in tasks of four kinds:
two running at the "main" level one after the otherinit: here you set up all the hardware resources and divides them in local (meant to be used by one and only one task) and shared with different strategies to prevent data races
idle: useful if you want to implement sleep between interrupts or if you are a superloop nostalgic
and two interrupt drivenhardware: old style ISR
software: these can be scheduled _at or _after some time or duration by exploiting unused interrupt vectors
All this "magic" takes care for you of the tedious chore of fighting the borrow checker when you don't need it and is based on macros that aggressively rewrite the source code before sending it to the compiler (nothing to do with the dumb cpp #define(s) )
Its API are under fast development so stability does not live here, but the major bummer is that (for the moment?) is cortex-m only, however this seems to fit quite well in the ISR driven MCU paradigm for REAL TIME applications.
Here is an application template using defmt.
Another option which seem to have a lot of hype (more than RTIC) is
Embassy which approaches concurrency through coroutines exploiting rust's async/await mechanism which is, you know, a form of multithreading not really REAL TIME. Yes you can spawn different executors each with its own priority (and its own stack!!) but these are no ISR. This and the fact that it comes with loads of communication resources (
USB,
Bluetooth,
LoRa,
Ethernet,...) seems to suggest that its major application is on the IoT side of embedded. (This is a very superficial glimpse on Embassy which I didn't have yet the time to investigate in some detail)
MISSING- levels of abstractions (many)
- useful crates (libraries, drivers,... )
- ...
INTERIM CONSIDERATIONS.Before convincing others of the superior safety of RUST based solely on its borrow checker, enthusiasts should take the time to guide those who are interested in approaching this language in the field of embedded systems. These individuals may wish to continue working with their hardware and using the paradigm for which it was designed, namely, responding to events through interrupts and creating drivers that take advantage of DMA. Furthermore, enthusiasts should provide information on the tools to use, some of which may not have undergone recent development, and they should strive to ensure that these tools are as bug-free as possible (meaning that at least the features advertised in one page websites should work! and, sadly no, some don't!).