cancel
Showing results for 
Search instead for 
Did you mean: 

Release Firmware vs. Debug Firmware Behaving Differently

Jaboop
Associate II

I have noticed lately that when switching between my release and debug build configurations that the code behaves differently. Looking at the Project Build Settings the only difference I see between the two is the Release GCC and G++ compilers are optimized for speed as opposed to optimized for Debug, and that the release Debug Level is None.

Does anyone know of resources of code to watch out for that would cause different behavior depending on the Compiler optimization. Are there methods of debugging in the release configuration that would help figure out what could be causing these differences?

Edit:

I have gone ahead and matched my release optimization settings to the debug optimization settings and I am now seeing the same behavior between the two. So I guess any insight/resources into what these optimization settings are changing in the code base so I can still optimize for speed or size without changing functionality would be greatly appreciated!

1 ACCEPTED SOLUTION

Accepted Solutions
TDK
Guru

Optimizations can bring out bugs in code that otherwise go unnoticed. Track the bug down by looking at what behaves differently. Be aware of variables that should be declared volatile, be aware of software-based loops that can be optimized out. Race conditions can also change based on code speed.

Debugging in release is similar to debug except some things are optimized out. The "Debug" mode still works the same regardless of configuration.

If you feel a post has answered your question, please click "Accept as Solution".

View solution in original post

3 REPLIES 3
TDK
Guru

Optimizations can bring out bugs in code that otherwise go unnoticed. Track the bug down by looking at what behaves differently. Be aware of variables that should be declared volatile, be aware of software-based loops that can be optimized out. Race conditions can also change based on code speed.

Debugging in release is similar to debug except some things are optimized out. The "Debug" mode still works the same regardless of configuration.

If you feel a post has answered your question, please click "Accept as Solution".
Nikita91
Lead II

With different compilation options it is normal that the generated code is different, and therefore its behavior is different. As @TDK​  said, the timing of operations is modified.

This is why in some industries (aeronautics) the standard is to "fly what you have debugged": no release. If we spend a lot of time validating software, we are not going to do it a second time with different compilation options.

On the other hand, robustness tests often call for this: different compilation options, memory constraints, etc.

So if your application has a different but normal behavior everything is fine, but if aberrant behavior appears there is a bug somewhere (sometimes difficult to find and concerning timing, race conditions...).

FEber.1
Associate II

Hello Jaboob, I have currently a similar problem. The code is developed in STM32CubeIDE Version: 1.5.1.
If you used also STM32Cube I like to ask you, where did you matched the release optimization settings to the debug optimization settings.