Possible issue with Floating Point Units

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

Possible issue with Floating Point Units

1,194 Views
ignisuti
Contributor IV

I'm transitioning a project form CW6.3 to CW10.1 Eclipse IDE. All seems to run well except for this line of code. It displays: "%4.1fV" instead of the appropriate value.

 

displayLen = (unsigned char)sprintf(newString,"%4.1fV", (float)battV/1000);

 

I have other sprintf commands in this same function that work fine. So, I believe this has something to do with the float values.

 

I tried changing the Processor settings for Floating Points from Software to Hardware, but the code stopped building and didn't give me any errors. What other settings should I check?

Labels (1)
0 Kudos
6 Replies

607 Views
ignisuti
Contributor IV

Kef, how come I don't see this Floating Point setting the 6.3 IDE. Do you know if it's set to Hardware or Software?

0 Kudos

607 Views
kef
Specialist I

What MCU are you using? One of Coldfire V1? As fas as I know no current CF V1 MCU has hardware floating point unit, so you should choose software. Floating point setting in CW6.3 is available in Standard Settings->Code Generation->ColdFire Processor. But it is set and blocked to Software only for all current CF V1 derivatives.

0 Kudos

607 Views
ignisuti
Contributor IV

Kef, your suggestion of adding printf.c to my project fixed the issue. However, I don't understand what this is needed. Can you please elaborate?

Also, I had to bring in stdio.h due to a  undefined function prototype and I now have 6 warnings in printf.c are are all illegal pragmas

 

#pragma MESSAGE DISABLE C5919 /* WARNING C5919: Conversion of floating to unsigned integral */#pragma MESSAGE DISABLE C4001 /* INFORMATION C4001: Condition always is FALSE */#pragma MESSAGE DISABLE C5703 /* INFORMATION C5703: This: parameter declared in function outc_callback but not referenced */#pragma MESSAGE DISABLE C2402 /* Variable pow10  allocated in ROM */#pragma MESSAGE DISABLE C2706#pragma warning "assume double is IEEE64"

BTW: I'm using mcf51cn128 MCU.

0 Kudos

607 Views
kef
Specialist I

I think that CW10.1 comes with CF libraries configured for and compiled with %f printf format disabled to save some kB of flash. You may either recompile library with enabled %f format, or just add printf source file and enable %f. I don't know how CF library should be configured for full printf. My previous suggestion was regarding S08 library. You probably added S08 printf, so now you get warnings about unkwnown for CF conpiler #pragmas from S08 compiler. If it all is working, then maybe just ignore those warnings or comment out bad pragmas.

0 Kudos

607 Views
ignisuti
Contributor IV

Looks like commenting them out is working.

 

I'm not 100% thrilled with this solution as it's not as clean as I'd like. When I port this project months from now I'll have to try and remember I have printf.c in my source files.

 

If you have any other recommendations, I'm all ears.

Thanks!

0 Kudos

607 Views
kef
Specialist I

It must be something wrong with library. Maybe CW10.1 libraries were compiled with LIBDEF_PRINTF_FLOATING not defined. If it's the case, then you may need to rebuild libs with LIBDEF_PRINTF_FLOATING defined. Or, you may just add required source file to your project. 1) try adding "\lib\hc08c\src\PRINTF.C" to your project, 2) change link order so that printf.c you added is linked first and not the printf.c from libraries, 3) define LIBDEF_PRINTF_FLOATING in compilers options. 4) make. I can't provide more detailed steps for CW10, I'm not familiar with it.

0 Kudos