|ARM Technical Support Knowledge Articles|
The C++ libraries depend on the C library for target-specific support. There are no target dependencies in the C++ libraries.
To retarget your C++ streamed I/O, we recommend that you retarget the
_sys_xxxx driver level functions. These are the functions used by the C and C++ library and are responsible for target specific I/O. The default implementation uses Semihosting to handle I/O on the host machine.
The ARM Compiler toolchain's C and C++ libraries documentation discusses which functions have to be re-implemented. A summary is shown below:
_sys_open() _sys_close() _sys_read() _sys_write() _sys_ensure() _sys_flen() _sys_seek() _sys_istty() _sys_tmpnam() _sys_exit() _ttywrch()For an example file (
retarget.c), used for redirecting C++ streamed I/O to an UART (connected to e.g. a Terminal Emulator), click here.
To retarget standard input/output functionality, low level library functions such as
fputc()can be re-implemented instead.
In ADS 1.2, RVDS 3.x, RVDS 4.x and DS-5, only functions such as
fputc() need to be reimplemented. With RVDS 2.x an additional library function (used by
__fread_bytes_avail() must also be reimplemented.
The default version of
__fread_bytes_avail() fills a buffer by calling
fgetc() until either the buffer is filled or
EOF is encountered. Since the retargeted version of
fgetc() in the example code simply returns characters from a UART (and never returns
__fread_bytes_avail() must be re-implemented to read a single character by calling
size_t __fread_bytes_avail(void *buf, size_t nbytes, FILE *stream)
/* Read a single character into buf using fgetc() */
*(char *)buf = (char)fgetc(stream);
This function should be added to
retarget.c in the Application Note 107 code
For ADS users, general retargeting of I/O functions is described in Application Note 107, "Embedded Software Development". For RVDS users, general retargeting of I/O functions can be found in the RealView Compilation Tools documentation. For DS-5 users, see ARM Compiler toolchain documentation.
Article last edited on: 2011-09-20 16:35:49
Did you find this article helpful? Yes No
How can we improve this article?