stm32f4xx-hal
stm32f4xx-hal copied to clipboard
Pin state violation in public API.
Hi, i discovered several Pins trait allowing to violate the Pin type state system from outside the crate. It concern i2c, i2s, serial and spi module. The way to do this violation is actually simple.
Pseudo example
use stm32f4xx_hal::serial::Pins;
let pins = (gpioa.pa9, gpioa.pa10); // tuple of Input pins
pins.set_alt_mode(); // type state violation, set pin in alternate mode without changing the type.
A simple fix consist to put those trait in a private module to prevent using their methods outside the crate. The trait SetAlternate must also documented, since the dangerous pin state violation ability comes from here.
SetAlternate is in private alt mode
SetAlternateis in privatealtmode
In my example, the set_alt_mode() method comes from the Pins trait which is public
https://docs.rs/stm32f4xx-hal/0.13.1/stm32f4xx_hal/serial/trait.Pins.html
Yes, this is really not good.