This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

What does retarget.c work?

Dear All,

Now I'm trying to use Hello example  of cortex-m3 for study on KEIL (uVision)

I came across "retarget.c" when I was opening the project file.

Does anyone know what does regret.c work? Why do I need or use this file what for?

#include <stdio.h>
extern unsigned char UartPutc(unsigned char my_ch);
FILE __stdout;
FILE __stdin;
int fputc(int ch, FILE *f) {
  return (UartPutc(ch));
}
int fgetc(FILE *f) {
  return (UartPutc(UartGetc()));
}
int ferror(FILE *f) {
  /* Your implementation of ferror */
  return EOF;
}
void _ttywrch(int ch) {
  UartPutc (ch);
}
...
 
/******************************************************************************/
/* Retarget functions for GNU Tools for ARM Embedded Processors               */
/******************************************************************************/
#include <stdio.h>
__attribute__ ((used))  int _write (int fd, char *ptr, int len)
{
  for (i=0; i<len;i++) {
    UartPutc(ptr[i]); // call character output function
    }
}