You are here

for use w/_write(), how to create new FILE object for use with fprintf | Cypress Semiconductor

for use w/_write(), how to create new FILE object for use with fprintf

Summary: 1 Reply, Latest post by KeerthiRocks on 15 Jun 2015 12:33 AM PDT
Verified Answers: 0
Last post
Log in to post new comments.
cbarnhart's picture
7 posts


I've over-ridden the _write() function so that printf output is directed to a device (one of several UARTs) of my choosing.  The _write() method takes a file descriptor int which is used to specific which device the output is bound for.  

However, I have several 'devices' that I'd like to send output to with fprintf, thus think I need to create a FILE object and set the file descriptor.  Unfortunately, calling fprintf with my own FILE objects is resulting in a call to _write().  I've even tried to copy stderr as follows without success.

Any ideas?



main() {

FILE fobj;

memcpy(&fobj, stderr, sizeof(FILE))

fobj._file = FD_UART_2;


 } // main


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

  LED_Y_Write(~LED_Y_Read()); // how I know its not getting called w/fprintf


switch(file) {

  case stdout: 

  case stderr :

  UART_1_PutArray(ptr, len); 


case FD_UART_2 : 

  UART_2_PutArray(ptr, len);


  } // switch

} // _write



KeerthiRocks's picture
Cypress Employee
77 posts

Can you please create a tech support case and attach the coplete project so that we can take it from there to debug the issue.




Log in to post new comments.