Retargeting printf/scanf to use a UART
By default, the printf function in Redlib outputs text to the debug console using the "semihosting" mechanism, as detailed in the FAQ "Using printf in your applications (Semihosting)".
In some circumstances, this output mechanism may not be suitable for your application.
Instead, you may want printf to output via an alternative communication channel - a UART for example. In this case you can retarget the bottom level of the Redlib C library.
To do this, you need to provide your own implementations of the function __write() (Red Suite / LPCXpresso 3.6 and earlier) or __sys_write() (later versions).
Similarly if you want to retarget scanf, you need to provide your own implementations of the function __readc() or __sys_readc().
The RDB1768 example code provides an example of how this can be done.
To retarget printf, you will need to provide your own implementation of the Newlib system function _write().
To retarget scanf, you will need to provide your own implementation of the Newlib system function _read(). Note that this has an additional parameter compared to the Redlib __readc(), as it also takes len : (int fd, char * ptr, int len).
Depending on the version of the Red Suite IDE that you are building with, you may encounter a linker error of the form multiple definition of '_write' when providing your own versions of these Newlib system functions. In this case, add the option --allow-multiple-definition to:
Project -> Properties -> Settings -> Linker -> Miscellaneous -> Other options
More information on the Newlib system calls can be found at: