Reply by Pete Vidler July 2, 20092009-07-02
pra bu wrote:
> I am checking that .map file for whether the " standard libs are
> still included"?.

How exactly are you measuring your code size? Hopefully not just by
looking at the size of the elf file...

Have you tried other methods to reduce code size -- such as the options
I mentioned previously and optimising for space over speed (-Os)?

> How to stop compiler to use stdlib instead of user
> defined printf function(printf-stdarg.c)?.

If you're #include-ing the header for this library and not stdio.h, then
it should work. It's possible that GCC is hardwired to use printf from
the standard library, but changing the name should have avoided that
possibility.

(Provided you changed the name *everywhere*).

> 2. In printf-stdarg.c %f is not supported .for my app i need %f
> also.Is any other lib supported this also?Is latest printf-stdarg.c
> supported this?.

You can fake it using %d. Check out the answer here:

http://stackoverflow.com/questions/905928/using-floats-with-sprintf-in-embedded-c

Here's a cut-down version of the code presented there:

float value = 678.0123;
int intVal = value;
float decVal = value - intVal;
int intDecVal = (int)(decVal * 10000);
printf("value = %d.%04d\n", intVal, intDecVal);

> 3.My last project i used keil.that supported full printf
> functionality(.including %f). code memory also not incresed
> much.

Maybe that's why people pay for it...?

Pete

An Engineer's Guide to the LPC2100 Series

Reply by pra bu July 2, 20092009-07-02
Hi all,
Thanks for all shared with ur knowledge,and suggestionsregrding this issue.

1. I have used printf-stdarg.c.Code memory didnt decrease.then I have tried " #define printfkprintf " in Global header fileand change thedefinition of this printf function name to kprintf in printf-stdarg.c.But still code size didnt decrease.I am checking that .map file for whether the " standard libs are still included"?.How to stop compiler to use stdlib instead of user defined printf function(printf-stdarg.c)?.

2. In printf-stdarg.c %f is not supported .for my app i need%f also.Is any other
lib supported this also?Is latest printf-stdarg.c supported this?.

3.My last project i used keil.that supported full printf functionality(.including %f).
code memory also not incresed much.Anyone explain how keil lib used less memory??
I am looking similar lib in GCC.

Thanks,
Prabu


--- On Thu, 2/7/09, Pete Vidler wrote:
From: Pete Vidler
Subject: Re: [lpc2000] Standard Lib function with FreeRTOS Increases code size
To: l...
Date: Thursday, 2 July, 2009, 1:52 PM

Bruce Paterson wrote:
> Agree with Foltos here. There must be a printf (or variant) left behind
> in your code. Ensure all files that include the global #define have
> re-compiled (check your dependencies) . The map file shows you what is
> going on.

Depending on his library, printf may still be included in the final
output. He may also need the -ffunction-sections and -fdata-sections
compiler options (preferably on the libraries themselves as well) and
link with the --gc-sections option (often passed as '-Wl,--gc-sections'
if GCC is used to start the linker).

Those are only valid for GCC.

Also, I would recommend against the '#define printf' as anything other
than a test to see what difference it makes... I certainly wouldn't use
that in production code. In fact, I think I'd prefer a global search
and replace in either situation.

Pete

Love Cricket? Check out live scores, photos, video highlights and more. Click here http://cricket.yahoo.com



Reply by Pete Vidler July 2, 20092009-07-02
Bruce Paterson wrote:
> Agree with Foltos here. There must be a printf (or variant) left behind
> in your code. Ensure all files that include the global #define have
> re-compiled (check your dependencies). The map file shows you what is
> going on.

Depending on his library, printf may still be included in the final
output. He may also need the -ffunction-sections and -fdata-sections
compiler options (preferably on the libraries themselves as well) and
link with the --gc-sections option (often passed as '-Wl,--gc-sections'
if GCC is used to start the linker).

Those are only valid for GCC.

Also, I would recommend against the '#define printf' as anything other
than a test to see what difference it makes... I certainly wouldn't use
that in production code. In fact, I think I'd prefer a global search
and replace in either situation.

Pete
Reply by Bruce Paterson July 1, 20092009-07-01
Agree with Foltos here. There must be a printf (or variant) left behind in your code. Ensure all files that include the global #define have re-compiled (check your dependencies). The map file shows you what is going on.

iprintf (and siprintf etc etc) get rid of the floating point overhead in printf. Of course if you need "%f" then this won't work for you :)

Note also that scanf (sscanf fscanf etc) brings all the floating point overhead back in again, and unfortunately last time I checked there was no iscanf.

It really depends on the size of your system. If you have a lot of user code (like I do), then the 12k or whatever overhead starts to pale into insignificance. On the other hand, if you are trying to fit it all into a 32k Flash then using a small printf is important.

As a side note, most comparisons between compilers I've seen tend to dwell on the small project where the size of the library dominate and overshadow differences of the compilers on actual user code. However, you have to bear in mind the library overhead is mostly fixed and doesn't really increase proportionally to the size of the code base (assuming you use mostly the same library functions).

Cheers,
Bruce

-----Original Message-----
From: l... [mailto:l...] On Behalf Of Foltos
Sent: Wednesday, 1 July 2009 7:43 PM
To: l...
Subject: Re: [lpc2000] Standard Lib function with FreeRTOS Increases code size

Hi,

check your .map file if printf() from the standard library is still in
the executable. If so, then you did something wrong. You have to replace
all your printf calls with

1. iprintf(). This was the intention of the "#define printf iprintf"
solution. But you must have this macro alive in all your source
files where you use printf()
2. the printf() replacement in "printf-stdarg.c". You must replace
all printf() calls with the one defined in this file.

Additional note: you will have the same trouble if you use any printf()
functions in your code (sprintf(), snpritf(), etc...). So you have to
get rid of these too.

Foltos

pra bu wrote:
> I have used printf-stdarg. c...cod memory didnt decrease.
>
> --- On Wed, 1/7/09, FreeRTOS info wrote:
> From: FreeRTOS info
> Subject: RE: [lpc2000] Standard Lib function with FreeRTOS Increases code size
> To: l...
> Date: Wednesday, 1 July, 2009, 1:59 PM
>
>>>> 2.or Is this is limitation of GNUARM GCC lib?
>>>>
>
> Do a search in the FreeRTOS download for a file called printf-stdarg. c.
> That implements a teeny tiny printf() that you can direct anywhere you like.
> Note the file is not part of FreeRTOS but is open source (the license terms
> are in the file) and it has also been pointed out that there is a bug in one
> of the string functions it contains (string copy or string compare, can't
> remember which).
>
> Regards,
> Richard.
>
> + http://www.FreeRTOS .org
> Designed for Microcontrollers. More than 7000 downloads per month.
>
> + http://www.SafeRTOS .com
> Certified by T as meeting the requirements for safety related systems.
> Looking for local information? Find it on Yahoo! Local http://in.local.yahoo.com/
>
>
>
>
Reply by rtstofer July 1, 20092009-07-01
--- In l..., "HM2" wrote:

> I have my own "console.c" module that I have built up through the years
> which handles all of theses printf functions, str functions etc. It is less
> than 1K of compiled code. You generally have to do this if you want a small
> set of functions to handle the str formatting and I/O if you want small code
> for embedded.
>
> Just do some searching on the web. There is lots of code around for small
> embedded replacements of these common library I/O functions.
>
> Chris.
>

I have done the same thing. Nothing as sophisticated as printf() but just a set of functions for printing chars, strings. hex bytes, hex shorts, hex ints, an itoa() and a few other things.

I got most of the code from "The C Programming Language" book that every C programmer has within immediate reach.

Richard

Reply by Foltos July 1, 20092009-07-01
Hi,

check your .map file if printf() from the standard library is still in
the executable. If so, then you did something wrong. You have to replace
all your printf calls with

1. iprintf(). This was the intention of the "#define printf iprintf"
solution. But you must have this macro alive in all your source
files where you use printf()
2. the printf() replacement in "printf-stdarg.c". You must replace
all printf() calls with the one defined in this file.

Additional note: you will have the same trouble if you use any printf()
functions in your code (sprintf(), snpritf(), etc...). So you have to
get rid of these too.

Foltos

pra bu wrote:
> I have used printf-stdarg. c...cod memory didnt decrease.
>
> --- On Wed, 1/7/09, FreeRTOS info wrote:
> From: FreeRTOS info
> Subject: RE: [lpc2000] Standard Lib function with FreeRTOS Increases code size
> To: l...
> Date: Wednesday, 1 July, 2009, 1:59 PM
>
>>>> 2.or Is this is limitation of GNUARM GCC lib?
>>>>
>
> Do a search in the FreeRTOS download for a file called printf-stdarg. c.
> That implements a teeny tiny printf() that you can direct anywhere you like.
> Note the file is not part of FreeRTOS but is open source (the license terms
> are in the file) and it has also been pointed out that there is a bug in one
> of the string functions it contains (string copy or string compare, can't
> remember which).
>
> Regards,
> Richard.
>
> + http://www.FreeRTOS .org
> Designed for Microcontrollers. More than 7000 downloads per month.
>
> + http://www.SafeRTOS .com
> Certified by T as meeting the requirements for safety related systems.
> Looking for local information? Find it on Yahoo! Local http://in.local.yahoo.com/
>
>
>
>
Reply by pra bu July 1, 20092009-07-01
I have used printf-stdarg. c...cod memory didnt decrease.

--- On Wed, 1/7/09, FreeRTOS info wrote:
From: FreeRTOS info
Subject: RE: [lpc2000] Standard Lib function with FreeRTOS Increases code size
To: l...
Date: Wednesday, 1 July, 2009, 1:59 PM

> >> 2.or Is this is limitation of GNUARM GCC lib?

Do a search in the FreeRTOS download for a file called printf-stdarg. c.
That implements a teeny tiny printf() that you can direct anywhere you like.
Note the file is not part of FreeRTOS but is open source (the license terms
are in the file) and it has also been pointed out that there is a bug in one
of the string functions it contains (string copy or string compare, can't
remember which).

Regards,
Richard.

+ http://www.FreeRTOS .org
Designed for Microcontrollers. More than 7000 downloads per month.

+ http://www.SafeRTOS .com
Certified by T as meeting the requirements for safety related systems.

Looking for local information? Find it on Yahoo! Local http://in.local.yahoo.com/



Reply by pra bu July 1, 20092009-07-01
Bruce,
When i use #define printf iprintf ,It tookadditional 6k memory.Which menas 18k..

--- On Wed, 1/7/09, Bruce Paterson wrote:
From: Bruce Paterson
Subject: RE: [lpc2000] Standard Lib function with FreeRTOS Increases code size
To: l...
Date: Wednesday, 1 July, 2009, 1:28 PM

Try #define printf iprintf in a global include file and see how you go.

Cheers,
Bruce
-----Original Message-----
From: lpc2000@yahoogroups .com [mailto:lpc2000@yahoogroups .com] On Behalf
Of prabuisin@yahoo. co.in
Sent: Wednesday, 1 July 2009 3:57 PM
To: lpc2000@yahoogroups .com
Subject: [lpc2000] Standard Lib function with FreeRTOS Increases code
size

Hi all,
I am using printf() functions with FreeRTOS,GNUARM. When i use
printf() function, code size increased to 12k.Which means printf()
related lib functions used this much memory.But in keil lib, this much
code is not used when i used printf() function.

Questions:

1.Is there anyway to reduce this much code memory by setting compiler
option
in Makefile?
2.or Is this is limitation of GNUARM GCC lib?
3.Is GNU supported any libs for reduce code memory for standard lib
functions?Because 12k code memory is to much for my application?

4.Is GNUARM supported retarget.c file printf() like keil?

Please share your knowledge in this Issue???

------------ --------- --------- ------
Reply by FreeRTOS info July 1, 20092009-07-01
> >> 2.or Is this is limitation of GNUARM GCC lib?

Do a search in the FreeRTOS download for a file called printf-stdarg.c.
That implements a teeny tiny printf() that you can direct anywhere you like.
Note the file is not part of FreeRTOS but is open source (the license terms
are in the file) and it has also been pointed out that there is a bug in one
of the string functions it contains (string copy or string compare, can't
remember which).

Regards,
Richard.

+ http://www.FreeRTOS.org
Designed for Microcontrollers. More than 7000 downloads per month.

+ http://www.SafeRTOS.com
Certified by T as meeting the requirements for safety related systems.
Reply by HM2 July 1, 20092009-07-01
>> 1.Is there anyway to reduce this much code memory by setting compiler
option in Makefile?

Not really.

>> 2.or Is this is limitation of GNUARM GCC lib?

It is the full blown complete support for the printf, sprintf, etc.
functions. It is not designed to be small. It was designed to be robust
and full featured.

>> 3.Is GNU supported any libs for reduce code memory for standard lib
functions?

Yes of course, it is not a matter of 'support', you just define printf etc
in a different C file and compile it in. GCC will use those functions
instead of the default liba, libg, etc. functions.

>> 4.Is GNUARM supported retarget.c file printf() like keil?

Of course, same answer as above. I have used retarget.c with GCC. It's
just another C file.

>> Please share your knowledge in this Issue???

I have my own "console.c" module that I have built up through the years
which handles all of theses printf functions, str functions etc. It is less
than 1K of compiled code. You generally have to do this if you want a small
set of functions to handle the str formatting and I/O if you want small code
for embedded.

Just do some searching on the web. There is lots of code around for small
embedded replacements of these common library I/O functions.

Chris.