STM32 gotchas
149. Incorrect ADC readout - due to missing calibration

ADC is perhaps the most varying peripheral from STM32 family to STM32 family, so migration usually requires to compare ADC chapters in RM and modify software as appropriate.

In some STM32 (namely 'L1/'F2/'F4/'F7), ADC are relatively simple as far as single conversions go: after enabling ADC clock in RCC and selecting appropriate clock prescaler, selecting one channel in input multiplexer and setting its sampling time, a single conversion is started by writing appropriate register bit. After the expected time ADC signals conversion complete, and the appropriate result can be read out from the data register, provided that correct voltages are present at VREF+/VDDA pins. That's all. Of course, these ADCs are much more complex and have a various degree of autonomous operation on multiple channels, mutually synchronized multiple ADCs, etc., but the basic single conversion has no special prerequisites.

However, in all other STM32 families, the ADCs require to perform an extra step - calibration - in software, before the first conversion is started. This step removes offset present in the ADC due to manufacturing variations and imperfections. Calibration may be required also when temperatures and/or supply voltages change significantly.

The ADC chapter in relevant RMs always contains a subchapter dedicated to ADC calibration, which describes the required procedure in detail.

Users, who forget to perform ADC calibration before the first conversion, are usually surprised by the readouts being offset quite significantly, usually a few tens of bins.