EmbeddedRelated.com
Forums
The 2024 Embedded Online Conference

Standard Lib function with FreeRTOS Increases code size

Started by prab...@yahoo.co.in July 1, 2009
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???

An Engineer's Guide to the LPC2100 Series

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

Cheers,
Bruce
-----Original Message-----
From: l... [mailto:l...] On Behalf
Of p...@yahoo.co.in
Sent: Wednesday, 1 July 2009 3:57 PM
To: l...
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???
>> 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.

> >> 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.
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???

------------ --------- --------- ------
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/



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/
>
>
>
>
--- 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

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/
>
>
>
>
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

The 2024 Embedded Online Conference