CW 6.3 for ColdFire and floating point functions

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

CW 6.3 for ColdFire and floating point functions

9,357 Views
Nouchi
Senior Contributor II
Hi,

I would build a simple stationery project for M5213EVB like this :

#include stdio.h
#include stdlib.h

int main()
{
char string[50];
float dummy;

printf("Hello World in C\n\r");
gets(string);
dummy= atof(string);
printf("%f",dummy);
fflush(stdout);
while(1); // Idle

}
and the Linker say :
Link Error : Undefined : "atof"
Referenced from "main" in main.c

Link failed.

C_TRK_4i_CF_SZ_MSL.a, C_4i_CF_SZ_MSL.a, fp_coldfire.a and C_4i_CF_Runtime.a are in the project.
What's wrong ?
This kind of project worked with CW 6.2.



Thanks,
Emmanuel

Message Edited by BugMan on 2006-08-2202:02 AM

Message Edited by BugMan on 2006-08-22 02:02 AM

Labels (1)
0 Kudos
17 Replies

767 Views
CrasyCat
Specialist III

Hello

I have used CodeWarrior for Coldfire V6.3, created a new project using a stationery for CF_M5213EVB and I plugged following source code in my main.c function:

Code:

#include <stdlib.h>#include <stdio.h>#include <math.h>int main(){double dummy;dummy = atof("12.35");dummy = floor(dummy);while(1); // Idle}

I have replaced the library file C_TRK_4i_CF_SZ_MSL.a by C_TRK_4i_CF_MSL.a.

I am then able to link the application. I have removed the printf from the application as this one generates a lot of code when floating point formatting is enabled. And the application would not fit the available memory.

CrasyCat

0 Kudos

767 Views
Nouchi
Senior Contributor II
Hello,

Did you try to enable "require function prototype" option?
I can't build any project with FP functions and this option enabled.
Can you send me your project?

Thanks,
Emmanuel.
0 Kudos

767 Views
CrasyCat
Specialist III
Hello
OK I was too quick last time and did not pay attention to the "require function prototype" option.

I made some additional check and tests here.
In order to be able to use floating point within a MCF5213 project you have to
- Edit the file ansi_prefix.CF.size.h in directory {Install}\E68K_Support\msl\MSL_C\MSL_E68k\Include.
- Set _MSL_FLOATING_POINT to 1, _MSL_NO_MATH_LIB to 0, _MSL_FLOATING_POINT_IO to 1
- Rebuild the reduced working set libraries (open project {Install}\E68K_Support\msl\MSL_C\MSL_E68k\Project\MSL_C.CF.SZ.mcp and rebuild the library
- Rebuild your application

You should be able to use floating point arithmetic now.
I have to re-install my V6.3 so I am not able to test that right now.
But that should be working.

CrasyCat
0 Kudos

767 Views
Nouchi
Senior Contributor II
Hello,

Is there datasheet speaking about "how to rebuild libraries", because when I set _MSL_FLOATING_POINT to 1,
_MSL_NO_MATH_LIB to 0
_MSL_FLOATING_POINT_IO to 1
the compiler generate a lot of errors.
I think there is others definitions switch to modify to compile without errors.
Is the C_4i_CF_MSL.a compiled with FP support or it has to be rebuild too?

Thanks,
Emmanuel
0 Kudos

767 Views
CrasyCat
Specialist III
Hello
OK I have re-installed my Coldfire V6.3 tools and I made some further tests.
Currently I get it working in following way:
  - I have created a project from a MCF5213 stationary
  - I have replaced the file C_TRK_4i_CF_SZ_MSL.a by C_TRK_4i_CF_MSL.a in build target M5213EVB Console Debug.
  - I have replaced the file C_4i_CF_SZ_MSL.a by C_4i_CF_MSL.a in the other build targets.
  - I have adjusted the file ansi_prefix.CF.size.h as follows:
Code:
#define _MSL_FLOATING_POINT     1//#define _MSL_NO_MATH_LIB                    0#undef _MSL_NO_MATH_LIB#endif#define _MSL_FLOATING_POINT_IO    1

 I am now able to link the application. I have attached the sample application to this email. 
CrasyCat
0 Kudos

767 Views
Nouchi
Senior Contributor II
Hi,

I successfully rebuilt libraries.
Did you try to enable "require function protype" ?
Because I always get the same error (function has no prototype) on atof and floor with your project.


Thanks,
Emmanuel
0 Kudos

767 Views
CrasyCat
Specialist III
Hello
 
  Works well for me if I used the modified prefix file (ansi_prefix_CF_size.h) for the project too.
 
CrasyCat
0 Kudos

767 Views
Nouchi
Senior Contributor II
Hello,

Shame on me, I forgot some definitions.
Now, it's working fine (just replace float by double).

What should I modify to use FP functions with IEEE32 format such as ceilf, floorf, powf, etc.....? (maybe a little bit faster than IEEE64 no?)

Thanks,
Emmanuel
0 Kudos

767 Views
CrasyCat
Specialist III
Hello
 
You will surely get faster and smaller code using 32-bit variant for floating point.
It all depends on the precision you need on your floating point arithmetic :smileyhappy:
 
CrasyCat
0 Kudos

767 Views
Nouchi
Senior Contributor II
Hello,

In fact floorf, ceilf etc... aren't defined in the current library, and what must I do to compile libraries with IEEE32 support?


Thanks,
Emmanuel
0 Kudos

767 Views
CrasyCat
Specialist III
Hello
 
Looks like there is a lot of fine tuning requested if you want to add floating point support to a MCF5213 application :smileymad:.
 
OK here is what I found out so far.
Single precision arithmetic functions are implemented in modules stored in
       {Install}\E68K_Support\msl\MSL_C\MSL_Common_Embedded\Math\Single_precision .
These source files are not part of the reduced working set libraries.
 
In order to be able to use floorf in your application you have to either add the file roundingf.c in your application or create a library containing single precision arithmetic functions and link that lib to your application.
 
I will report internally that some documentation on this subject is required.
 
CrasyCat
 
0 Kudos

767 Views
Nouchi
Senior Contributor II
Hello,

Thanks for all these tricks, but I didn't have to ask all these questions with CW V6.2, all functions were built in the libraries and the (smart?)linker picked up needed functions, it was easier to use (but less efficent?)


Emmanuel
0 Kudos

767 Views
CrasyCat
Specialist III
Hello
 
In fact V6.2 was not providing reduced working set libraries. We were always linking whole library with the project. This leads to a lot of issues where customer have not been able to link their application on MCU with limited amount of RAM available.
 
In order to avoid these issues we decided to come up with a reduced working set library. But then if you want to use floating point library you have to really fine tune everything and it gets complicated. 
 
As mentioned previously I will report that back to product management.
 
CrasyCat
0 Kudos

767 Views
CrasyCat
Specialist III

Hello

In fact C_TRK_4i_CF_SZ_MSL.a is the Reduced Working Set Library for Coldfire. It does not contain support for Floating point functions.

Please refer to {Install}\Help\PDF\ColdFire_Build_Tools_Reference.pdf, chapter "Coldfire Runtime Libraries" -> "MSL for Coldfire Development" -> "Reduces Working Set Libraries" for more information on that.

CrasyCat

0 Kudos

767 Views
Nouchi
Senior Contributor II
Hi,

Ok, if I want floting point support I have to use C_4i_CF_MSL.a library.
I have an other problem with this simple programm:
#include stdlib.h
#include stdio.h
#include math.h

int main()
{
char string[50];
double dummy;
int dummy1;

printf("Hello World in C\n\r");
gets(string) ;
dummy = atof(string);
dummy1 = floor(dummy);
fflush(stdout);

while(1); // Idle

}


But, when I use floating point function, compiler say:

Error : function has no prototype
main.c line 19 dummy = atof(string);

Error : function has no prototype
main.c line 20 dummy1 = floor(dummy);

Error : function has no prototype
mcf5xxx.c line 34 printf(EXCEPTFMT,"Illegal stack type", MCF5XXX_SF_PC(framep));
etc...


If I disable "Require Function Prototypes", compiler say nothing, but
atof doesn't works properly (always return 0.0), and I've got some Access Error (Attempted write to write-protected space) with floor function, and I don't know what happened. It's probably a passing parameter's problem, but I don't know why.

Thanks,
0 Kudos

767 Views
J2MEJediMaster
Specialist I
The compiler is fussing about a mismatch between the arguments types your code is passing to, or expecting from, the library functions.

1) I'm not sure what's awry with atof(). Try using a hard-coded floating-point value as the input argument rather than a variable character array and see what happens.

2) Although the documentation says floor() returns an integer, the return value is actually of type double. Change your declaration for dummy1 to double instead of int.

3) In your printf() statement, you're trying to print out a floating-point value, but supplying it with an integer variable. Changing the declaration of dummy1 to double should fix this.

Finally have you confirmed that the project is *not* using the minimum library and using exclusively the new library you've added?

HTH,

---Tom

Message Edited by J2MEJediMaster on 2006-08-23 11:57 AM

0 Kudos

767 Views
Nouchi
Senior Contributor II
Hello,

I did tests with this code:

#include stdlib.h
#include stdio.h
#include math.h

int main()
{
double dummy;


printf("Hello World in C\n\r");
dummy = atof("12.35");
dummy = floor(dummy);
fflush(stdout);

while(1); // Idle

}

>1) I'm not sure what's awry with atof(). Try using a hard-coded floating-point value as
>the input argument rather than a variable character array and see what happens.
atof still return 0.0

>2) Although the documentation says floor() returns an integer, the return value is
>actually of type double. Change your declaration for dummy1 to double instead of int.
floor return 1.0 which is correct, but still generate Access Error exeption.
Implicit cast double to integer doesn't work or passing parameters problem?

For the example, the library in the project are C_4i_CF_MSL.a, C_4i_CF_Runtime and fp_Coldfire.a, I remove from the project *_SZ* library.

My real problem, is that I can't convert a CW6.2 project into CW6.3, because I can't compile project with option require prototypes enabled, I've got errors (function has no prototype) on evry FP functions. I tryed to make a copy of math.h on the source directory without success.
I try to solve the problem with a simple original CW6.3 project stationery.


Thanks,
Emmanuel

Message Edited by BugMan on 2006-08-24 01:52 AM

Message Edited by BugMan on 2006-08-24 01:55 AM

0 Kudos