Author Topic: Floating point library  (Read 8354 times)

Offline johnr

  • Jr. Member
  • **
  • Posts: 91
    • View Profile
Floating point library
« on: October 09, 2007, 07:37:13 PM »
Hi , we may need to use floating point to do some ADC conversions.
The CW 6.3 lite help mentions that the M52233 lacks an FPU and in order
to enable software FP you must "include the appropriate FP_Coldfilre library"
into your project. I looked in the CW help and can't see how to do this.
Anyone ever include FP in their projects and if so how much memory would this
require.

 Thanks,
 John
« Last Edit: October 09, 2007, 07:40:23 PM by johnr »

Offline mark

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3188
    • View Profile
    • uTasker
Re: Floating point library
« Reply #1 on: October 10, 2007, 01:20:21 AM »
Hi John

Check out the reference guide: "Code Warrior Build Tools Reference Coldfire(TM) Architectures Edition":
http://www.freescale.com/files/soft_dev_tools/doc/ref_manual/ColdFire_Build_Tools_Reference.pdf
since it also discusses the Coldfire run-time libraries.

However I just took a look and saw that it includes a hardware floating piont library but not specifically a software floating point library, so I don't know exactly the best thing to link.

If you serach the Freescale CW forum there are a number of threads about this subject so possibly the exact answer will be there. Just briefly looking at a couple it looks as though there is FP support in the C_4i_CF_MSL.a which is possibly suitable. (C_4i_CF_SZ_MSL.a is for example a size reduced version of the library where FP stuff has been left out to avoid library bloat).

Another tip I saw was to look also at the following document (presumably in the CW directory) for a quide to chosing the best library set up: Help\PDF\Targeting_ColdFire.pdf

Good luck

Regards

Mark



Offline johnr

  • Jr. Member
  • **
  • Posts: 91
    • View Profile
Re: Floating point library
« Reply #2 on: October 11, 2007, 02:22:14 PM »
Hi , I read the threads in the FreeScale forum pertaining to runtime libraries
and have read the sections in the CF tools manual regarding them, but I still don't
see how to add/deleate librarys from a project. I posted this question up in
the FreeScale forum yesterday, but haven't gotten a response yet.

In the project menu the floating point option is set to software, being there is no FPU in the chip, but is greyed out. The manual say to include the appropriate libary to enable this option. I read in a thread to set the following in ansi-prefix.cf.size.h located in the FreeScale
CW dir tree
 
#if !(__COLDFIRE__ == 0x4080 && !__option(fp_library))
////#define _MSL_FLOATING_POINT     0
////#define _MSL_NO_MATH_LIB                    1
#define _MSL_FLOATING_POINT     1
#undef _MSL_NO_MATH_LIB
#endif
////#define _MSL_FLOATING_POINT_IO    0
#define _MSL_FLOATING_POINT_IO    1
 
 and rebuilt the project, but still get the link errors when I try to work with a float var . I assume the default project is using the * SZ.a libs, which don't support FP. How do I
specify using the regular libary in a project ? Is there a way to see what MSL libs are
included in a project so as to remove unnessesary ones ? Just taking a stab in the dark, I tried
adding various CF_4I*MSL*.a files to the Support Files folder in the project with no luck
 
 Thanks,
 John

« Last Edit: October 11, 2007, 03:40:35 PM by johnr »

Offline mark

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3188
    • View Profile
    • uTasker
Re: Floating point library
« Reply #3 on: October 11, 2007, 04:06:19 PM »
Hi John

Quote
Just taking a stab in the dark, I tried
adding various CF_4I*MSL*.a files to the Support Files folder in the project with no luck

I think that this is the correct way to do it. The uTasker project is set up without any library support since there are non needed for the basic project to work.

If I need malloc()/free() I add C_4i_CF_SZ_MSL.a to the support file directory as you have done.

Since you are still getting linker errors it means that the library you are adding doesn't contain what is needed for the Floating Point work.

I suggest noting the routines (and/or const data) which are missing. Then do a serach in all files in the CW directory until you find them. They may be in C files but may also be in assembler files so best search with wild card (*.*) so that you don't miss anything. The missing routines must be there somewhere and once you have located the files you can probably work out which library they are actually used in. You may also find that the library sources also use defines and  the routine you need is not actually being compiled into the library - in other words the actually library configuration is not available in the CW directory. In the worst case this may require settin the define in a header controlling the library build and rebuilding a library yourself. However it doesn't look as though the library support is quite rich and most flavours are already available precompiled.

I will also take a look later.

Regards

Mark


A little later...

I had a go at adding some floats and the linker complained about the routine f_add() being missing.
Now I couldn't find this anywhere at all!!
This makes me wonder whether the lite/special edition versions of CW perhaps really do not have any FP support at all.
If all else fails, it may be possible to add the GCC FP support (gcc/config/m68k/lb1sf68.asm in the GCC project) - see the following:
http://osdir.com/ml/hardware.motorola.microcontrollers.coldfire/2004-05/msg00063.html

I haven't tried this (yet) so I don't know whether it really is as simple as that. Hopefully there will be a reply from one of the Freescale experts soon to clear up this case.

« Last Edit: October 11, 2007, 04:36:27 PM by mark »

Offline johnr

  • Jr. Member
  • **
  • Posts: 91
    • View Profile
Re: Floating point library
« Reply #4 on: October 11, 2007, 06:23:22 PM »
Mark,
 just adding this line in my code causes link errors,
 "undefined _f_itof and undefined _f_imul".
p->AlarmHi is a float var. I don't call any math.h
functions.

   p->AlarmHi=(float)(i+1)*100;


 I'll try the GCC approach and let you know.

I tried using libgcc.a and libm.a from my CodeSourcery 4.11
install. They were under the M5213 dir, which seemed to be closest
to the M52233 chip. I added them under the SupportFile dir and got
the same link errors as before, just doing a simple mult operation
on 2 ints and storing them in a float.

 I read through the CF targeting PDF, and they don't mention
any floating point restrictions with the 6.3 Special Edition. It says
it lacks V2 and V4e simulatiohn, whatever that means.

 A closer look at the FreeScale site does not mention any floating point
limitations with the CW Special Edition  but I see they sell 2 versions of the Standard
Edition, one with an E and one with a FLOA suffix, which costs $300 more.


 When I tried to add C_4i_CF_SZ_MSL.a and added
#include <stdlib.h> at the start of one of my source files to test
out malloc(), I got "size_t redeclared errors". This is defined in the
MSL lib and in the project's types.h

 Thanks for the help,
 John
« Last Edit: October 11, 2007, 08:17:45 PM by johnr »