Heat problems for STM32F103C8T6 in enclosure
Well your main goal is to keep the MCU (generally all parts) within its operating region.

For that you have to have to guesstimate the current needed for operation, the thermal resistance (which is hard) and the ambient temperature the device will operate in.

The power dissipation figures you find in the datasheet are numbers which will prevent the junction temperature to go out of spec at the given ambient temperature.



So worst case, everything on, 3.6 V running full speed, they give 109 mA. This is 392 mW.

You are limited to 240 mA max through Vdd or Vss. 109 mA end up in the core, leaves 131 mA for the rest.

With modern LEDs I would not drive them with more than 5 mA as indicators, except they are used outside in sunlight.

Driving 10 LEDs with 5 mA and 0.4 V internal drop (table 49) adds another 20 mW to the internal dissipation.

Not sure about the other I/O ports. But lets assume a 450 mW power dissipation.

Table 98 has the thermal resistance for the packages listed. With the worst one you have 46 K/W.

With 450 mW you get a rise of 20 K of the junction temperature over the ambient (ambient of the MCU not the enclosure). That means you basically can have 85 °C inside your enclosure and the MCU would be fine. (84,3 °C to be precise)



Modeling what temperature will result in your enclosure is much harder. You need to know how the heat will transfer from the air to the enclosure and then from enclosure to ambient again - maybe your enclosure gives a number but most don't.

What I usually do is estimate the total power dissipation (add some extra), place a PCB inside the enclosure and solder a part on it which is able to handle the dissipation.

Then measure the ambient temperature, the temperature of the enclosure and the temperature inside the enclosure while powering the device. After some hours the temperatures will have stabilized and you can see what rise above ambient you get. If it's something like 40 K rise of the inside temperature, you can't use your device in temperatures above 45 °C. Because then, the ambient temperature of the MCU would be above 85 °C.



If you want to have some safeguards, you can use the internal temperature sensor of the MCU to shutdown in case of overtemperature.

There are some ICs around which will do the same and probably more accurate if you don't trust the internal sensor.