Newlib-Nano Support

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

Newlib-Nano Support

Senior Contributor I

LPCXpresso v7 introduced a new C library to complement the existing 'Redlib' and 'Newlib' libraries - Newlib-Nano (sometimes written as NewlibNano).

Newlib-Nano was produced as part of ARM's "GNU Tools for ARM Embedded Processors" initiative in order to provide a version of Newlib focused on code size. Using Newlib-Nano can help to dramatically reduce the size of your application compared to using the standard version of Newlib - for both C and C++ projects.

Enabling the use of Newlib-Nano

To use Newlib-Nano, you will need to change the selected library being used by your project, the easiest way to do this being to use:

Quickstart -> Quick Settings -> Set library type

and then select the required Newlib-Nano variant.

By default, Newlib-Nano uses non-floating point variants of the printf and scanf family of functions, which can help to dramatically reduce the size of your image if only integer values are used by such functions.

If your codebase does require floating point variants of printf/scanf, then these can be enabled by going to

Project -> Properties -> C/C++ Build -> Settings -> MCU Linker -> Managed Linker Script

and selecting the "Enable printf/scanf float" tick box.

Enabling Newlib-Nano when not using managed linker scripts

If you are not using the managed linker script mechanism, then to enable the use of Newlib-Nano, you will need to define which library files to use in your linker script, as described in the FAQ "Using your own linker scripts".

In addition, the tick box method of enabling printf/scanf floating point support described above will also not be available. In such cases, you can enabling floating point support manually by going to

Project -> Properties -> C/C++ Build -> Settings -> MCU Linker -> Miscellaneous

and entering  -u _printf_float and/or  -u _scanf_float into the "Linker flags" box.

A further alternative is to put an explicit reference to the required support function into your project codebase itself.  One way to do this is to add a statement such as:

asm (".global _printf_float");

to one (or more) of the C source files in your project.

Newlib vs Newlib-Nano

Differences between Newlib and Newlib-Nano include:

  • Newlib-Nano is optimized for size.

  • The printf and scanf family of routines have been re-implemented in Newlib-Nano to remove a direct dependency on the floating-point input/output handling code. Projects that need to handle floating-point values using these functions must now explicitly request the feature during linking, as described above.

  • The printf and scanf family of routines in Newlib-Nano support only conversion specifiers defined in C89 standard. This provides a good balance between small memory footprint and full feature formatted input/output.

  • Newlib-Nano removes the now redundant integer-only implementations of the printf/scanf family of routines (iprintf/iscanf, etc).  These functions now alias the standard routines.

  • In Newlib-Nano, only unwritten buffered data is flushed on exit.  Open streams are not closed.

  • In Newlib-Nano, the dynamic memory allocator has been re-implemented

Related FAQs

0 Replies