CFV1 with CW6.1 floating point support for printf

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

CFV1 with CW6.1 floating point support for printf

Jump to solution
4,010 Views
KAR
Contributor I
Hello,

I've looked at several posts talking about shrinking the footprint of printf-like functions by setting #define switches in header files.  There is also a "Tips & Tricks" segment about this discussed here.  I wish to do the opposite.  I want full floating point support for printf and scanf, but I'm running into problems making it happen.

First of all, here is what I have:
CodeWarrior 6.1 Special Eddition (Under "Help->About" it states the version is 5.9.0, Build 2404)
MCF51QE64 for my target MPU

Some other related threads that I have found useful are:
CW 6.3 for ColdFire and floating point
Simple Printf on CF question

As it stands by default, I can compile printf functions with the "%f" term, but nothing will be displayed.  (I'm actually using sprintf and whatever putchar function I choose.)  Also, printf works fine for printing integer values (%d, etc.).

I have tried adding print.c from "C:\Program Files\Freescale\CodeWarrior for Microcontrollers V6.1\lib\hc08c\src" and modifying libdefs.h from "C:\Program Files\Freescale\CodeWarrior for Microcontrollers V6.1\lib\hc08c\include", but I getting a lot of errors.  Specifically in libdefs.h I include the switch "#define LIBDEF_PRINTF_FLOATING   1".

I think others have had success with this process before, but maybe there is a quirk for the Coldfire V1 that I am not aware of.  I also wonder if I should be grabing printf.c from the HC08 source directory.

Thank you in advance for any guidance you can provide.

Kevin



Labels (1)
Tags (1)
0 Kudos
1 Solution
737 Views
kef
Specialist I
Did you see these files:
 
{install|}\ColdFire_Support\msl\MSL_C\MSL_Common\Src\printf.c
{install|}\ColdFire_Support\msl\MSL_C\MSL_Common\Src\printf_tiny_IO.c
 
 
I don't know what's the right way. I added printf_tiny_IO.c to the project and defined
#define LIBDEF_PRINTF_FLOATING 1
 
also I had to unsuppress code for Ten() routine, there's a #if 0 at line 197.
 

View solution in original post

0 Kudos
5 Replies
737 Views
CompilerGuru
NXP Employee
NXP Employee
Be sure not to mix the tips for HC08 and for CF. The way to go for the CF V1 is to use another library,
I think the second thread you mentions tells you which one (sorry, I don't now thouse lib names out of my memory).

Using the printf.c for the HC08 (the out of of lib/hc08c/src) or libdefs.h (out of lib/hc08c/include) is not applicable for the CF V1, instead use the provided MSL library for ColdFire.

Daniel


BTW: I still think that not using printf for small the devices is the right thing to do, so maybe a specialized float printing routing and a simple string to UART output is the way to go.
0 Kudos
737 Views
KAR
Contributor I
Thank you for your reply CompilerGuru.  I thought the HC08 sources might not be completely compatible with the V1, but that was the only place I could find printf.c.  There isn't a subdirectory for that source for the V1 that I could find.

The default libs that were added to my project are:
fp_coldfire_nodiv.a
C_4i_CF_RegABI_MSL.a
C_4i_CF_RegABI_Runtime.a

I found information about the MSL from here:
{install}\Help\PDF\ColdFireV1_Build_Tools_Reference.pdf
Then under "ColdFire V1 Tools --> Using MSL Libraries".  I replaced the C_4i_CF_RegABI_MSL.a with the C_4i_CF_RegABI_MATH_MSL.a choice because it contained floating point manipulation.  This didn't change anything.  I then tried replacing the other two libraries with the various other available libraries without any luck.  Is there a specific one I need to choose?  Is there anything special I need to do besides changing the libraries in the project and recompiling?

I understand that printf functions are bloated and I am not concerned in this application.  I just wanted to save a little time instead of writing any specialized functions.

Thanks,

Kevin

0 Kudos
738 Views
kef
Specialist I
Did you see these files:
 
{install|}\ColdFire_Support\msl\MSL_C\MSL_Common\Src\printf.c
{install|}\ColdFire_Support\msl\MSL_C\MSL_Common\Src\printf_tiny_IO.c
 
 
I don't know what's the right way. I added printf_tiny_IO.c to the project and defined
#define LIBDEF_PRINTF_FLOATING 1
 
also I had to unsuppress code for Ten() routine, there's a #if 0 at line 197.
 
0 Kudos
737 Views
KAR
Contributor I
Thanks a lot kef!  That did the trick.

I had to also "#define LIBDEF_PRINTF_PREC 1" as well in order for it to compile.  That was fine as I needed the precision feature anyway.

I also found that I did need the C_4i_CF_RegABI_MATH_MSL.a library instead of the default or I would get a link error for "frexp".

Thanks again.  I hope this may be of use to others.  For a heads up though, adding the floating point support added about 8 kB to my code.  Ouch :smileyhappy:
0 Kudos
737 Views
kef
Specialist I
You are right, LIBDEF_PRINTF_PREC 1 is necessary to make it compileable.
 
0 Kudos