You copied the Doc URL to your clipboard.

Tailoring the C library to your target hardware

By default, the C library uses semihosting to provide device driver level functionality, enabling a host computer to act as an input and an output device. This is useful because development hardware often does not have all the input and output facilities of the final system.

You can provide your own implementation of C library functions that make use of target hardware, and that are automatically linked in to your image in favor of the C library implementations. This process, known as retargeting the C library, is shown in Figure 5.

Figure 5. Retargeting the C library

Figure 5. Retargeting the C library

For example, you might have a peripheral I/O device such as an LCD screen, and you might want to override the library implementation of fputc(), that writes to the debugger console, with one that outputs to the LCD. Because this implementation of fputc() is linked in to the final image, the entire printf() family of functions prints out to the LCD.

Example implementation of fputc()

In this example implementation of fputc(), the function redirects the input character parameter of fputc() to a serial output function sendchar() that is assumed to be implemented in a separate source file. In this way, fputc() acts as an abstraction layer between target dependent output and the C library standard output functions.

extern void sendchar(char *ch);
int fputc(int ch, FILE *f)
{   /* e.g. write a character to an LCD screen */
    char tempch = ch;
    return ch;

In a standalone application, you are unlikely to support semihosting operations. Therefore, you must remove all calls to semihosting functions or re-implement them with non semihosting functions.

See also


Using ARM C and C++ Libraries and Floating Point Support: