I/O Retargeting  Version 1.2.0
User Code Templates for I/O Retargeting using ARM Compiler
 All Files Macros Pages
Overview

Application code frequently uses standard I/O library functions, such as printf(), scanf(), or fgetc() to perform input/output operations. The structure of these functions in the standard ARM Compiler C run-time library is:

struct_comp_function.png
Function Structure

High-level and low-level functions are not target-dependent and use the system I/O functions to interface with hardware. However, the high-level library functions perform input/output by calling the low-level ones, which themselves call the system I/O functions, which are target-dependent.

To retarget input/output, you can:

  • Avoid the high-level library functions.
  • Redefine the low-level library functions.
  • Redefine the system I/O functions.

Whether redefining the low-level library functions or the system I/O functions is a better solution, depends on your use case. For example, UARTs write a single character at a time and the default fputc() uses buffering, so redefining this function without a buffer might suit a UART. However, where buffer operations are possible, redefining the system I/O functions would probably be more appropriate.

The MicroLib of the ARM Compiler C run-time library interfaces to the hardware via low-level functions. It implements a reduced set of high-level functions and therefore does not implement system I/O functions. Thus, in case of using the MicroLib, you cannot redefine the system I/O functions. Using any of the features of the ARM Compiler component provides the assert facility for MicroLib.

The page Retargeting Channels and Variants explains the details about how retargeting is done using the ARM Compiler component.

Semihosting

Semihosting is a mechanism that enables code running on an ARM target to communicate and use the Input/Output facilities on a host computer that is running a debugger.

Semihosting is not supported by µVision. Thus, you cannot use semihosting SWI operations. In case you have to write your own retarget code, ensure that no semihosting functions of the C library get linked into your application. This is done by importing the symbol __use_no_semihosting_swi. This can be done in any C or assembler source file in your project. In a C module, use the #pragma directive:

#pragma import(__use_no_semihosting_swi)

In an assembler module, use the IMPORT directive:

IMPORT __use_no_semihosting_swi