AnsweredAssumed Answered

How to set UART up as a standard device

Question asked by Sam99 on Feb 27, 2014
Latest reply on Mar 19, 2014 by Jithul_Janardhanan

We are working on a project using the 21479 (specifically because of power considerations) with the CrossCore tools, and are having a problem creating I/O support for the UART such that it can be accessed as a stream.  We need to be able to read and write binary data and provide a higher-level interface for our customer (fprintf, etc). 

We have a simple UART_putchar() and UART_getchar() basically working, but the problem is adding the UART as a device.  We have been following EE-347 and adapting it to the SHARC, but we just get garbage out the UART (and occasionally the correct first character of the string) when anything comes out at all.

Can you point us to example code implementing this?  I’ve enclosed a .zip of example code, but I have reproduced the high-level setup here:

 

                int PrimDevId = get_default_io_device(); //Debugger console for printfs

                int SecDevId = add_devtab_entry(&UART_DevEntry);  //UART for fprintfs

                set_default_io_device(SecDevId);  //Temporarily set uart as primary device

                pUartIOFile = fopen("uart","r+w"); //open a dummy file on the now primary UART device

                if(setvbuf(pUartIOFile,buf,_IOLBF,sizeof(buf)) == -1)  //Setup a buffer on the UART device

                {

                                set_default_io_device(PrimDevId);

                                printf("Error setting UART buffer \n");

                }

 

                if(pUartIOFile == NULL)

                {

                                set_default_io_device(PrimDevId);

                                printf("Error setting opening UART\n");

                }

 

                set_default_io_device(PrimDevId);  //Set the primary device back to debugger console for printfs

                fprintf(pUartIOFile,"UART test print.\n");  // If anything, get garbage; occasionally “U” along with.

`               printf(“After UART fprintf”);

                fclose(pUartIOFile);

 

Both if statements pass (are not executed) and we get the correct SecDevid back from add_devtab_entry().

The program pointer seems to be unable to increment if you break at the fprintf or thereafter. 

Attachments

Outcomes