This is amazing. Register and peripheral config is so easy to fuck up and waste a whole day chasing down because of limited debugging capabilities on these platforms. I've hit just about every one of those scenarios these compile-time guards now catch on one project or another.<p>Kudos, can't wait to see where to goes from here.
This is super exciting, and it smacks a little bit of the C++11 variadic template based HW init scheme explored in the stm32plus library, eg:<p><a href="https://github.com/andysworkshop/stm32plus/blob/master/examples/timer_dual_pwm_gpio_out/timer_dual_pwm_gpio_out.cpp#L48-L57" rel="nofollow">https://github.com/andysworkshop/stm32plus/blob/master/examp...</a><p>Though obviously the Rust approach provides a lot more guarantees, especially at runtime.<p>The one thing that interests me is how flexible this approach would be at dealing with cases where you have to hack around a hardware bug. For example, I had a board on it with an I2C expander whose default I2C address was not one the STM32 was able to address, but could be changed at runtime with an I2C command. So this was dealt with in firmware by initializing those pins initially as GPIO and bit-banging in the message to change the address, then changing them over to the regular I2C peripheral and taking it from there.<p>How possible would something like that be with this much more tightly constrained Rust IO model?
These problems that embedded rust is trying to solve are not a big deal. In C you try to minimize what happens in any interrupt, usually just set a flag, save a result, and return. You generally use atomic instructions on gpio. To set or clear a bit mask is atomic so there is not much reason to read-modify-write gpio in an interrupt or anywhere. I think these solutions would create more work than they save.
This is, amusingly, a lot like Modula I, circa 1979. That had language support for device registers, cooperative multiprogramming, and interrupts. A very nice way to program a PDP-11 at the bare metal level.
OT but I’ve just got into microcontrollers for the first time in the last week via an Arduino Uno. I’m absolutely in love with it and I now need to go a bit deeper (I’m working on a synth). I get a lot of the concepts like the registers to control the timers / interrupts but I’ve found a good guide to be lacking. I haven’t seen a list anywhere of all the available registers and what the bits do. I get that it’s different for different chips but I thought the info for more common ones (like the ATMega328) would be easier to come by.<p>Any hints on where to look?