To use the standard output functions putchar, puts, and printf, you need to customize the way that characters are written to the standard output device. These output functions rely on a function __putchar that outputs a character and returns an indication of whether it was successfully written.
The prototype for __putchar is
int __putchar(int ch);
You can send all output to the CrossStudio virtual terminal by supplying the following implementation of the__putchar function in your code:
#include <__cross_studio_io.h>
int __putchar(int ch)
{
return debug_putchar(ch);
}
This hands off output of the character ch to the low-level debug output routine, debug_putchar.
Whilst this is an adequate implementation of __putchar, it does consume stack space for an unnecessary nested call and associated register saving. A better way of achieving the same result is to define the low-level symbol for __putchar to be equivalent to the low-level symbol for debug_putchar. To do this, we need to instruct the linker to make the symbols equivalent. To do this:
Note that there are three leading underscores in ___putchar and a single leading underscore in _debug_putchar because the C compiler automatically prepends an underscore to all global symbols.
If you need to output to a physical device, such as a UART, the following notes will help you: