cancel
Showing results for 
Search instead for 
Did you mean: 

How to solve the problem that the data values ​​of float type variables appear differently when debugging?

bupark007
Visitor

스크린샷 2025-09-05 115915.png스크린샷 2025-09-05 120031.png

I'm trying to figure out why the value 4.2 is returned as -2 when passed as a function argument. Could you please also provide a solution? The MCU is an STM32F302VET.

3 REPLIES 3
TDK
Super User

Is optimization turned off?

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

Hello @bupark007 

As mentioned by @TDK  using high optimization levels can cause variables to be kept in CPU registers or even optimized away, making them difficult to inspect during debugging. To address this, try setting the optimization level to -O0 (no optimization) when debugging your code.

GhofraneGSOURI_0-1757081751846.png

 

THX

Ghofrane

To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.

I'd probably instrument, and call test cases with terminal output to confirm the functionality.

I think there are reported issues with the debugger's memory/expression view.

Check you have pulled libraries with sscanf / printf support of floating point.

Inspect code generated by the compiler for consistency, double check the casting of the math at each stage.

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