2024-04-02 12:44 AM
I'm using STM32 CubeIDE and trying out different compiler optimization levels. I've been using the Og(size) level, which has reduced my code size while still keeping it working normally in regular situations.
I've noticed a problem: my custom board gets really hot when running the optimized code. This makes me think there might be some unintended issues with this optimization level.
I want to understand more about how compiler optimization levels work in CubeIDE and how they can affect code and hardware. Can someone explain what compiler optimization levels are and how they impact code generation in CubeIDE?
2024-04-02 01:57 AM
Here is a good explanation about optimization levels
https://developer.arm.com/documentation/100748/0622/Using-Common-Compiler-Options/Selecting-optimization-options?lang=en
more detailed explanation of the GNU gcc (that is used in CubeIDE)
https://gcc.gnu.org/onlinedocs/gcc-12.3.0/gcc/Optimize-Options.html
If your board gets too hot, you should find the specific part that gets too hot. Than you can now how this is related to your MCU on schematic level. An infrared camera is a good tool to track thermal issues.
2024-04-02 03:04 AM
@Ethan_hunt04 wrote:my custom board gets really hot when running the optimized code.
And it doesn't get hot when running non-optimised code?
2024-04-02 04:32 AM
without optimization its working well
2024-04-02 07:36 AM
So back to @user7 's point - you need to determine what, exactly, is getting hot.
Maybe step through your code while watching the current consumption - both with & without the optimisation.
2024-04-02 10:00 AM
Not clear what MCU / board you're talking about.
Optimization shouldn't cause a dramatic increase in heat/current, not clear what you're observing or doing.
Optimization can surface a lot of issues with coding and style, especially when things need to be defined as volatile due to content changing outside normal code flow.
Look for warnings.
Optimize sections of the code, and try to bisect the issue to pin down the area that's problematic.
Are you driving pins into external circuits? Any potential to drive two pins in a way that could clash?