This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

DM648 printf to UART

Other Parts Discussed in Thread: TMS320DM648

Hello,


I am currently using a TMS320DM648, and CCS4. I read a couple of papers from TI which briefly touch on how to map printf to UART. One of the webpages is located here:

And mentions to do the following following:

ret_val = add_device("uart", _SSA, uart_open, uart_close, uart_read, uart_write, uart_lseek, uart_unlink, uart_rename);
fid = fopen("uart","w");
freopen("uart:", "w", stdout); // redirect stdout to uart
setvbuf(stdout, NULL, _IONBF, 0); // turn off buffering for stdout
printf("Hello world!\r\n");

My questions are
1. How do I define "uart"? Is it supposed to be the name of the library which I need to add in the .tcf file? Do I need to make changes in the .tcf file?
2. How are the uart_open, uart_close, etc defined? Do the they need to be functions in the uart library? I planned on using a uart library which came with dvsdk 1.10.00.26..
3. I do not understand how is the printf is calling the uart write function...
4. Are there documents which clearly define how to do this? I was only able to find vague documents.

Any help is welcome.

Thanks.
Alin



 

  • Alin,

    Please look at the example attached that remaps stdout to write to a buffer in memory. You can define functions in memdevice.c to use UART driver instead, and map stdout to UART. This example is tested on DM648 EVM. On building and running the program, you will see that, after the second printf() call in main.c (line 28), the string is copied to 'buffer' array instead of being printed on the console.

    1586.RemapSTDOUT.zip

    Thanks.

    Sudhakar

  • Thanks. I will give it a try.

    Is there any way that I can do both: print in the console, and print on UART by using just one printf statement?

    Alin

  • Hi Sudhakar,
    I was not able to import the project in CCS4... So, I tried your suggestion in my own project.
    Here's what's happening... Indeed after calling
    setvbuf(stdout, NULL, _IONBF, 0);
    I don't see anything printed in the console using the printf statement. However, variable buffer does not get the data either. I put a breakpoint in the device_write() function, and it never gets called, which tells me the function never gets called.
    I did a small experiment, and instead of
    setvbuf(stdout, NULL, _IONBF, 0);
    I used:
    setvbuf(stdout, buffer, _IOLBF, sizeof(buffer))
    Now, I see the printf statement writing data to buffer. But, of course, this is not a solution.
    Is there anything special that I need to do in the linker, project options, etc? I looked, but couldn't find anythings.

    Thanks.
    Alin
  • Alin,
    First I would like you to make sure that the freopen() call is exactly same as in the code I sent earlier (There is a colon after 'memdevice'):
    freopen("memdevice:","w",stdout);
    If it still does not work, please let us know what compiler version you are using.
    Thanks.

    Sudhakar

  • Hi Sudhakar,

    There is a colon after memdevice...

    I am using: CCS Version: 4.0.1.01001

    Alin

  • Alin,

    My settings are:

    CCS 6.0.1

    Compiler TI v7.4.8

    Can you please try with these? If you upgrade to CCS 5 or above, you should be able to import the project I sent earlier.

    Thanks.

    Sudhakar