STM32 gotchas
219. Floating ADC input may have nonzero voltage - this is normal

The purpose of ADC is to measure analog voltages. Sometimes users, perhaps drawing from analogy with the common voltmeter, expect, that the ADC's input is a high impedance towards ground, and that unconnected (floating) ADC input will tend to be around 0V. They may be therefore be surprised by the fact, that floating input of ADC, on which conversions are continuously ongoing, may be at any arbitrary voltage.

During conversion, the sampling capacitor is charged to an unspecified but quite likely nonzero voltage. This charge is then during the sampling phase delivered from the sampling capacitor to the parasitic capacitance of unloaded pin. The exact voltage of sampling capacitor at the end of conversion is dependent on the previous input voltage, and the minute details of the ADC itself, which may differ from STM32 family to family.

Following is a waveform taken on from a pin on STM32F4 Disco (bottom waveform is a zoom-in). The pin was first switched to GPIO Output and set to 0 to completely discharge the parasitic capacitance; then it was switched to Analog and 100 ADC conversions were taken (source code here). The parasicit capacitance of the pin is given by the pin itself and tracks on the board, plus cca 18pF of the connected oscilloscope.

voltage on a floating ADC input

This effect is another demonstration for the need of low signal impedance for ADC to measure input voltage correctly - in fact, this is the extreme case of the highest possible input signal impedance.