Using float variable with mqx 3.5.1

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Using float variable with mqx 3.5.1

2,115 Views
elel
Contributor III

Hello

 

I'm using the mcf52259 with the mqx 3.5.1.

 

I'm developing a function that print numbers,and characters, on the display of my board.

 

I've create a function declared as: void MyPrint(char_ptr Format, ... );

 

The function works correctly with all type of data exept with the float variables.

 

When I write "MyPrint("%f",Float_Variable); the micro is blocking on this instruction.

If I try to debug this problem the debugger jumps into an assembler routine called
".debug_macinfo + 0x0000000A (0x00006D56) (0x00006D56)"; and will never return from that routine.

 

In way to use float variables I've set to 1 the "MQX_INCLUDE_FLOATING_POINT_IO" define, and then I've recompiled all libraries.

 

I've also tried to call the printf macro declared in the bsp, but the effect it's the same.

 

Someone has ideas on how to fix it?

am I missing something? or am I doing something wrong?

 

Thanks in advace.

Stefano

 

P.s. I was forgetting to say that I'm calling that function into a task declared as:

{MAIN_TASK,    main_task,    2000,  9,       "MAIN", (MQX_AUTO_START_TASK | MQX_FLOATING_POINT_TASK),0,0}

 

0 Kudos
9 Replies

694 Views
DavidS
NXP Employee
NXP Employee

Hi Elel,

Please be sure you have re-compiled the build_libs.mcp for the M52259EVB.

I've tested this in the past successfully.  I do not recall the "MQX_FLOATING_POINT_TASK" parameter though.

Hopefully I can re-verify tomorrow.

Regards,

David

0 Kudos

694 Views
elel
Contributor III

Hi David.

 

Yes, I've recompiled the "build_libs.mcp" of the M52259DEMO.

 

I've also tried to don't recall the "MQX_FLOATING_POINT_TASK" parameter, but the problem it's still the same.

 

I've seen that in there are other 2 #define called "MQX_FP_REGISTERS_EXIST" and "MQXCFG_ENABLE_FP",  they now are at 0, should I set them?

 

Thanks
Stefano

0 Kudos

694 Views
DavidS
NXP Employee
NXP Employee

Hi Stefano,

I've tested on my M52259EVB using CW7.2 and started with the mqx/examples/hello project.

I added some floating point stuff (file attached) and increase task stack size to 2000 from 1500, added following to user_config.h:

#define MQX_INCLUDE_FLOATING_POINT_IO 1  //DES normally 0
re-compiled the build_m52259evb_libs.mcp (the ALL LIBS to ensure all targets built).

re-compiled hello_m52259evb.mcp

Tested all targets and get following output on terminal:

 Hello World
a=4.440000
b=2.220000
c=0.000000

 

c=9.856800
a=21.882097
b=215.687454

 

The other FLOAT flags you were using are actually to support floating point hardware on the silicon. Most ColdFire's do not have floating point hardware.

Regards,

David

0 Kudos

694 Views
weidberg
Contributor I

Hi David.

I'm having a different problem from Stefano one.

I'm running mqx 3.7.0

I tried what that you said and when running hello.c, I get on screen 


a=268156222601565000000000000000000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000000000000000000000000000000.00
0000                                                                            
b=268156222539130050000000000000000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000000000000000000000000000000.00
0000                                                                            
c=0.000000                                                                      
c=0.000000                                                                      
a=0.000000                                                                      
b=0.000000 


 

same when using sprintf,

 

any ideas?

 

thanks!

0 Kudos

694 Views
elel
Contributor III

Hi David.

 

I've performed some test on the float variables.

 

I'm able to print it but the debugger can't step into the print function if the parameter it's a float variable.

 

If I let the software run without debugging the print it's correct, but if I put a breakpoint on the call of the print and then I press F11 (step into) the debugger jump at a wrong address(the address I've reported in the first post of this tread) and never comes back from there.

 

But I don't know why.

 

Thanks.

Stefano

 

0 Kudos

694 Views
DavidS
NXP Employee
NXP Employee

Hi Stefano,

Do you have the BSP and PSP CodeWarrior projects open while debugging?  I usually try to have all FSLMQX component projects open when debugging code.

Don't know if that will help you or not.  I'm not having that issue.  But glad to hear it works correctly when you run it.

Actually please try to debug in mixed mode so you can see the assembly instructions being executed.  Maybe that will provide additional insight.

Regards,

David

0 Kudos

694 Views
elel
Contributor III

Hi David.

 

I've tried to debug in both ways, with bsp and psp project opened and with theese project closed; but the effect it's the same the debugger can't step into the function if the parameter is a float value.

 

But if I put a breakpoint inside the function and the let the debugger run, the debugger will stop into the function at the breakpoint.

 

The problem is only on the "step into" command.

 

This problem it's not so heavy, but I've another problem that I can't understand and that it's more serious than this:

The number I print it's different respect the number I give to the function.

 

For example:

If I try to print a variable like "float a=25.4;", I print "8.72". If I debug the function I can see that the value printed it's the value that I find from this operation "FloatValue=va_arg(ArgPointer,float);".

 

And when I return from the print function the value of the variable it's the value I've setted in the declaration(25.4).

 

 

How can I fix this problem?

 

Thanks in advance.
Stefano

0 Kudos

694 Views
CompilerGuru
NXP Employee
NXP Employee

The line

> FloatValue=va_arg(ArgPointer,float);".

seems suspect. According to the ANSI C default argument promotion rules, float are promoted to double.

Therefore va_arg should be used with double, not float.

> FloatValue=va_arg(ArgPointer,double);".

I'm not using (or even knowing) MQX, so just wanted to give a hint to the issue.

 

Daniel

0 Kudos

694 Views
elel
Contributor III

Hi Daniel.

 

You are right. I've tried call "va_arg(ArgPointer,double);" and now my print it's working good.

 

Thanks for your help.

 

Stefano

0 Kudos