Why ADC sampling time matters
The ADC input capacitor must charge through the source impedance. If sampling time is too short, readings become inaccurate.
Source impedance effect
Higher source resistance requires longer sampling time. Voltage dividers, sensors and filters can all increase source impedance.
How to improve ADC accuracy
Use lower source impedance, add a buffer op-amp, increase sampling cycles or add a suitable capacitor near the ADC input.
STM32 configuration
Choose the next higher sampling time in CubeMX or firmware after calculating the minimum required time.