STM32 gotchas
56.Internal temperature sensor on ADC indicates surprisingly high temperature

One of the channels in most if not all STM32 families' ADC is connected to an internal temperature sensor. Users, when trying to measure the chip's temperature, often report unexpectedly high temperature readouts.

While there are many potential sources for error - including incorrect temperature calculation from the raw ADC readout - most of the time the measured temperature is correct. Users usually don't realize, that the sensor is part of the chip, thus it indicates temperature of the chip itself, which can significantly differ from the ambient temperature. Differences of 15°C and more in an 'F4/'F7 running at maximum clock with many peripherals enabled, are perfectly normal.

An approximate estimate of this difference follows from the supply voltage, supply current and the thermal resistance of given chip (a more precise calculation would need to include also other factors, such as impact of the method of mounting of given chip/thermal properties of the PCB, surrounding sources of heat, air circulation, fluctuations in the power consumption, considering the power dissipated by currents flowing in and out of IO pins, etc.)

As an example, let's take the datasheet value for typical current consumption of STM32F407 running at 168MHz with all peripherals enabled, that's 87mA; as this value is given at VDD=3.3V, the power dissipation is 287.1mW. Let's assume we use the LQFP100 package for which the junction-to-ambient thermal resistance is given by DS as 43°C/W, this results in the basic estimate of difference between junction (chip) and ambient temperature of 12.3°C.