This is the mail archive of the newlib@sources.redhat.com mailing list for the newlib project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re:how to retarget newlib printf scanf to embedded systemUART ?


Hi Wayne,

You need to do following things to redirect stdout to UART.
1) Please include syscalls.c in your project from following path,
	../newlib/libc/sys/arm
2) Without changing any other functions from syscalls.c, change only _read and _write functions 
   like following.

	int _read (int file, char *ptr, int len)
	{
    	    /* GetChar : Your implementation to receive the character 
      	 from the serial port.*/
          //*ptr=GetChar();  
    	       return (1);
	}
	
	int _write(int file,char *ptr,int len)
	{
	    int i;
 	    /* PutChar : Your implementation to send the character to the 
          serial port.*/
	    for(i=0;i<len;i++)
	    {      
		  //PutChar(*ptr++);
	    } 
	    return len;
	}
This implementation of redirecting stdin and stdout to serial port will override default 
implementation of stdin and stdout. 
Do not forget to include directories with required header files in your project.

This implementation works for H8/300 and SH targets. It should also work for ARM target.
Please refer to following link for more details,
http://billgatliff.com/articles/newlib/newlib.pdf

Good Luck.

Regards,
Anil Paranjpe
KPIT Cummins InfoSystems Ltd.
Pune, India

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Free download of GNU based tool-chains for Renesas' SH and H8 Series.
The following site also offers free technical support to its users. 
Visit http://www.kpitgnutools.com for details. 
Latest versions of KPIT GNU tools were released on June 1, 2004.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 

>>From: "wayne lee" <wnlee at cad dot csie dot ncku dot edu dot tw> 
>>To: <newlib at sources dot redhat dot com> 
>>Date: Fri, 6 Aug 2004 11:20:10 +0800 
>>Subject: how to retarget newlib printf scanf to embedded systemUART ? 

--------------------------------------------------------------------------------
>>Hi folks, 
>>
>> I successfully use GNU arm-elf toolchain to build a ROM image.
>> My program is linked with newlib.
>>
>> Now, I am wonder how to retarget newlib stdin, stdout to UART
>> Does anyone who can give me hints?
>>
>>Wayne
>>
>>-- 
>> I have ever use ARM ADS1.2 to build ROM image.
>> ADS provides a retarget mechanism likes bellows:
>>
>>struct __FILE { int handle;   /* Add whatever you need here */};
>>FILE __stdout;
>>FILE __stdin;
>>
>>void _ttywrch(int ch)
>>{
>>    char tempch = ch;
>>    write_ch_to_uart( &tempch );
>>}
>>
>>int fputc(int ch, FILE *p_fd)
>>{
>>    /* Place your implementation of fputc here     */
>>    /* e.g. write a character to a UART, or to the */
>>    /* debugger console with SWI WriteC            */
>>    char tempch = ch;
>>    write_ch_to_uart(&tempch);
>>    return ch;
>>}
>>
>>int fgetc(FILE *p_fd)
>>{
>>    /* Place your implementation of fgetc here        */
>>    /* e.g. read a character from a UART, or from the */
>>    /* debugger console with SWI ReadC                */
>>    char ch;
>>    ch = get_ch_from_uart();
>>    return ch;
>>}


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]