Re:Writing embedded firmware using Rust
by steveklabnik on Sunday December 19, 2021 @08:37PM
(#29620655)
Yes, the syntax doesn't have to be this way, it's just the way that the libraries in the ecosystem tend to do it. It works, but it does also have quite a few problems, imho. But since it's just a particular library, you can write your own or use a different one.
Re:Writing embedded firmware using Rust
by oxidizedcutrace on Sunday December 19, 2021 @08:44PM
(#29620690)
Good question! I'm also not a Rust expert, but maybe that syntax would be considered unsafe in some situations?
I think the 'peripheral access crates' try to auto-generate those sorts of struct objects from SVD files, but you still need to obey Rust's ownership rules to get the advantage of its built-in memory safety.
So if a function needs to modify a peripheral's memory, it needs to claim mutable ownership of the relevant peripheral registers. That's a feature of the language which makes it 'safer', but the cost/benefit calculation is a bit different on embedded platforms. They have less memory, and static allocation is usually preferred.
Still, microcontrollers are getting faster quickly. You can even run Linux on some cortex-M4/M7 chips. The verbose syntax might be worthwhile if you're collaborating on complicated firmware.
Still learning rust, so apologies if this syntax doesn't make sense.