|
|
|
|
|
by correct_horse
1797 days ago
|
|
I like rust, but don't use it for embedded. Here's a blog I read on how to make GPIO access safe https://www.ecorax.net/macro-bunker-2/. In that article, they have three goals:
verify that the pin is correctly configured,
use atomic reads and writes,
make sure only one thread (including interrupts) can write to a pin at a time. Spoiler alert, the way they avoid interrupts screwing everything up is with `cortex_m::interrupt::free(|_| {/*read/write pin*/})`, which executes the passed closure in an interrupt-free context. The author's solution isn't atomic, but the borrow checker and the fact that they target single threaded MCU means no one else can be writing to the port at the same time. |
|