2023-10-27 09:19 PM
Here in the below image from the Cube MX it suggests that, SET all the free pins as analog (to optimize the power consumption). How does it help. Also is it applicable to all the controller families?
2023-10-27 10:57 PM
Digital inputs have circuits that look like NOT gates, where a P-channel MOSFET has its source connected to Vdd and an n-channel MOSFET has its source connected to Vss. The gates are connected to the input pin and the drains connected together as the output of the NOT gate.
When the pin is at Vss i.e. 0V, the p-channel mosfet is turned on but the n-channel one is turned off. So the output of the NOT gate is high, and no current flows between Vdd and Vss.
When the input pin is at Vdd the n-channel mosfet is on but the p-channel mosfet is off, so the output is low and no current flows between Vdd and Vss.
When the input pin is somewhere between Vdd and Vss, both p-channel and n-channel mosfets will be partially turned on so current will flow between Vdd and Vss - wasting power.
Ways to fix this are to disable this NOT gate (analog mode) or ensure that the pin isn’t just “floating” but is either Vdd or Vss (enabling pull-up or enabling pul-down or having the pin as a digital output, or having external circuitry that holds the pin high or low).
Analog is not the only way to do this.
2023-10-28 12:33 AM
...and yes, this is same for all (cmos) chips , if a pin after startup is just an open floating input.
2023-10-28 12:27 PM
In analogue mode, the GPIO is connected to the respective analogue function instead of the internal digital Schmitt trigger, because the GPIO in question is otherwise very sensitive to interference signals due to the high-impedance input.
With older STM32s such as F1, F2, F3, the GPIOs were still set to digital input by default and had to be explicitly set to analogue input. With newer families (if I remember correctly with L4) this was then changed to default = analogue input.