Redirecting runtime library I/O?

Rating:
 
Vote for this:
Good  -  Bad

Answer

The C runtime library include many functions, including some that typically handle I/O. The I/O related runtime functions include printf(), fopen(), fclose(), and many others.

It is common to redirect the I/O from these functions to the actual embedded platform, such as redirecting printf() output to an LCD display or a serial cable, or to redirect file operations like fopen() and fclose() to some Flash file system middleware.

The free Lite version of TrueSTUDIO ® do not support I/O redirection, and instead have do-nothing stubs compiled into the C runtime library.

The professional versions of TrueSTUDIO ® do support I/O redirection. To enable I/O redirection the file "syscalls.c" should be included and built into the project:

  • Open TrueSTUDIO ® professional and load your project.

  • In the Project explorer, Right click on the project and select New->Other...

  • Expand System calls.

  • Select "Minimal System Calls Implementation" and click next.

  • Click Browse... and select the src folder as new file container and click OK.

  • Click on Finish and verify that "syscalls.c" is added to your project.


Example: Redirect "printf()" to your target output by modifying the "_write()" function in "syscalls.c":

int _write(int file, char *ptr, int len)

{

int index;

for(index=0 ; index<len ; index++){

__io_putchar(*ptr++) /* Your target output function */

}

}