Skip to main content
Associate III
June 15, 2026
Solved

STM32H723 GCC compiler Optimization problem

  • June 15, 2026
  • 5 replies
  • 118 views

STM32CubeIDE 2.1.1: My program works if I choose the GCC compiler “none” optimization and it doesn’w work if I select any other optimization; anyone may help me ?

 

Thank you

Best answer by Andrew Neil

This typically means that there is a flaw (or flaws) in your code - it’s relying on something which the C language does not guarantee.

 

Probably the commonest is omitting/forgetting volatile where it's needed.

Relying on timing of the C code is another.

 

The -Og level should give you good debuggability - see here.

You could try that …

 

Your could also try printf-style debugging to see where your code execution differs from what you intended

 

 

5 replies

Andrew Neil
Andrew NeilBest answer
Super User
June 15, 2026

This typically means that there is a flaw (or flaws) in your code - it’s relying on something which the C language does not guarantee.

 

Probably the commonest is omitting/forgetting volatile where it's needed.

Relying on timing of the C code is another.

 

The -Og level should give you good debuggability - see here.

You could try that …

 

Your could also try printf-style debugging to see where your code execution differs from what you intended

 

 

A complex system that works is invariably found to have evolved from a simple system that worked.A complex system designed from scratch never works and cannot be patched up to make it work.
carloVAuthor
Associate III
June 15, 2026

Thank you, I need the max speed...is there a fast way to identify where the problem comes ?

 

CarloV

Andrew Neil
Super User
June 15, 2026

No.

You’re just going to have to debug it to see what’s going wrong.

You could start with a code review to check volatile usage, timing dependencies, etc.

As well as the software debugger, use a scope or logic analyser to see what happens with/without the optimisation. 

A complex system that works is invariably found to have evolved from a simple system that worked.A complex system designed from scratch never works and cannot be patched up to make it work.