I want to find at runtime if a GPIO is floating (nothing connected to it).
I assumed I'd find tons of answers on Google, but maybe I'm searching wrong.
My approach has been to:
- enable the internal pullup resistor and read the IO
- disable the pullup, enable the pulldown and read the IO again
If it reads high first and low second, the input is floating.
Since I've not seen a lot f discussion on this online, I'm wondering if I'm doing something unusual, or if there's a better way, or if this approach doesn't work in the general case and I simply lucked out in my application.
If this does work in the general case, I'm curious what happens with GPIOs that don't exist in a package. Presumably, if a particular IO line doesn't come out to a pin, there are no pullup or pulldown resistors for this line either. I'm curious particularly about what STM32 does in this case.