cancel
Showing results for 
Search instead for 
Did you mean: 

Difficulties with Compiler Optimization Levels in STM32 CubeIDE

Ethan_hunt04
Associate II

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?

5 REPLIES 5
user7
Associate II

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. 

 

Andrew Neil
Evangelist III

@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?

without optimization its working well 

 

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.

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?

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..