How to open "ttyd:" in TWR-K60N512 and TWR_SER?

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

How to open "ttyd:" in TWR-K60N512 and TWR_SER?

Jump to solution
2,791 Views
Xuejian
Contributor II

I want to print to hyperterminal instead of PEmicro. Unfortunately, I saw nothing on hyperterminal. What I have done was below:

1) enabled the "ttyd:" in \Freescale MQX 3.8\mqx\source\bsp\k60n512.h

2) recompiled the BSP

3) added the following codes in my program

        fh_ptr = (pointer)fopen("ttyd:", BSP_DEFAULT_IO_OPEN_MODE);    

        _io_set_handle(IO_STDOUT, fh_ptr);

4) compile my project

Then, when I ran the program, still nothing in hyperterminal.  I don't know how to figure out the problem.

1 Solution
1,517 Views
rjohnson
Contributor II

All I had to do was enable ttyd in user_config.h, and then do this:

 

serial_fd = fopen("ttyd:", 0);
ioctl(serial_fd, IO_IOCTL_SERIAL_SET_FLAGS, &flags);

fprintf(serial_fd,"HELLO!!!\r\n");

View solution in original post

0 Kudos
18 Replies
1,518 Views
rjohnson
Contributor II

All I had to do was enable ttyd in user_config.h, and then do this:

 

serial_fd = fopen("ttyd:", 0);
ioctl(serial_fd, IO_IOCTL_SERIAL_SET_FLAGS, &flags);

fprintf(serial_fd,"HELLO!!!\r\n");

0 Kudos
1,516 Views
DavidGao
Contributor I

what is the flag?

 

I think if I set it as the default uart port, printf will print things to hyperterminal.

0 Kudos
1,516 Views
lisa_tx
Contributor III

Hi David,

 

     I didn't check the flag.

 

     I believe that UART5 ("ittyf:") is connected to both RS-232/RS-485 and USB/OSJTAG. If you set UART5 as default uart port, printf will print things to both Hypertermianl and Terminal Window, assuming both connectors are connected to PC respectively. You can't read back from Hyperterminal, but you can read back from Terminal Window without removing R65 from processor board.

 

     I believe that there should be a mux connected to UART5 receiver, which allow user to select which incoming data to read. For some reason, nobody tells me how to do this. The only answer I have got is to remove R65 from processor board. Now I still can print to both Hyperterminal and Terminal Window by using printf or write, but I can read from Hyperterminal with fread.

 

Lisa

0 Kudos
1,517 Views
lisa_tx
Contributor III

Hi rjohnson,

 

      Thank you for answer!

 

       Are you sure that you are having TWR-K60F120M, instead of TWR-K60N512? I don't have TWR-K60N512, I have TWR-K60F120M. I have tried what you suggested on TWR-K60F120M. There is no output on my PC side (I use Clear Terminal). If I change serial_fd to "ttyf:", then I can see output on my PC without problem. So I believe that UART5 (instead of UART3) is connected to RS-232 on TWR-SER.

 

Lisa

0 Kudos
1,517 Views
J2MEJediMaster
Specialist I

This forum https://community.freescale.com/message/86418#86418 might provide some information. Also, you might try using the search function (the box at the upper right) and enter "TWR_SER". I recall that there were some problems with the serial connection on certain TWR_SER boards.

0 Kudos
1,517 Views
Xuejian
Contributor II

Yes, I found many same problems in forum, but I did not see how to solve it explicitly. Would you please help me with more directions? I doubt maybe I missed something in configuration, which I don't know where and how should do. Thanks!

0 Kudos
1,517 Views
Gewehr88
Contributor I

I have been working with both TWR-K60N512 and TWR-K60f120m, and have both UARTs working.

 

You need to modify user_config.h file (C:\Program Files\Freescale\Freescale MQX 3.8\lib\twrk60f120m.cw10, in my case)  to enable "ttyd".

 

#define BSPCFG_ENABLE_ITTYD      1

 

Then compile BSP.

 

Also, I am using the similar functions of device drivers

 

device = (pointer)fopen("ttyd:", NULL);

 _io_set_handle(IO_STDOUT, device);
 _io_set_handle(IO_STDIN,  device);

 

Only issue I have is that it cannot handles the arrow keys, "<" ">".  And I have been told that could be device drive issue, but have not dug into it yet.

0 Kudos
1,517 Views
lisa_tx
Contributor III

Gewehr88,

 

    Are you sure that you have got channel "ttyd:" work on TWR-K60F120M? In your description, you said to enable "ttyd", but in user_config.h, you actually enable "ittyd:" by the following definition:

 

#define BSPCFG_ENABLE_ITTYD      1

 

   I have tried to enable "ittyd:" in user_config.h, it doesn't work. The data won't be sent to PC's RS-232 port. I believe RS-232 is connected to UART5 ("ttyd:" or "ittyd:"), but OSJTAG also uses UART5. If I use "write("iddyf:", buf, strlen(buf));", I can see output data on PC through RS-232. My problem is that I can't use "fread("ittyf:", ...);" get data from PC's RS-232 port. 

 

Lisa

0 Kudos
1,517 Views
Gewehr88
Contributor I

Lisa,

 

#define BSPCFG_ENABLE_ITTYD 1

is for TWR-K60N512.

 

#define BSPCFG_ENABLE_ITTYF 1

is for TWR-k60f120m.

 

I do have both boards and have both UARTs work.

 

Please refer to the attached SCH of TWR-k60f120m.

 

Gewehr88

0 Kudos
1,516 Views
Xuejian
Contributor II

Thank you Gewehr88!

You do help me make it working. I am so excitied.

0 Kudos
1,516 Views
Xuejian
Contributor II

Thank you rjohnson. Your suggestion is also very important!

0 Kudos
1,516 Views
lisa_tx
Contributor III

Hi Gewehr88,

 

       Thank you fow answer me!

 

       Yes, believe RS-232/RS-485 connector on TWR-SER is connected to UART5 ("ittyf:"). I have no problem to write data to RS-232/RS-485. My problem is to read back through RS-232/RS-485.

 

       Since UART5 is connected to OSJTAG as well, whenever I write to UART5, I can see the output from both P&E Terminal Window which is connected to USB/OSJTAG and Clear Terminal (or you can use HyperTerminal) which is connected to RS-232/RS-485. When I type anything on P&E Terminal Window, my program can receive it, but when I type anything on Clear Terminal, my program can't receive anything. That is the problem I have. Have you tried to read from RS-232/RS-485?

 

        My question in above is that you didn't specify it should be "ittyf:" for TWR-K60F120M.

 

Lisa

0 Kudos
1,516 Views
Gewehr88
Contributor I

I had both enabled.  You can try one way or another, to see which one works

 

case 1: enable ITTYF

case 2: enable TTYF

case 3: enable both

 

I think one is Interrupt driven and another is pulling. But INT overwrites pulling.

 

I am using Tera Term and use it as shell application, and not P&E terminal window.  And I have no problem for either input and output.

 

0 Kudos
1,516 Views
lisa_tx
Contributor III

Gewehr88,

 

       Thank you for answer me again!

 

       I use Clear Terminal. I believe that Clear Terminal is similar to Tera Term.

 

       I still have problem with reading from RS-232/RS485.

 

       I have enable either "ttyf:" or "ittyf:". My program look like below:

 

       rs232_dev = fopen("ITTYF:", NULL);

 

       if(rs232_dev != NULL)

       {  

            fprintf(rs232_dev, "Please type something. \n");

            fflush(rs232_dev);

 

           

            while(1)

            {

                   fread(read_buf, 1, 18, rs232_dev);

                   write(rs232_dev, read_buf, 18);

                   fflush(rs232_dev);

            }

        }

 

        Note, this program can get data from OSJTAG (through P&E Terminal Window) which is connected to UART5 too, but can not get data from RS-232/RS-485 (through Clear Terminal). It can send data to both P&E Terminal Window and Clear Terminal. Do you see anyting wrong with my program? Or do you mind share your source code here to show how do you get fread() work?

 

Lisa

      

0 Kudos
1,516 Views
Gewehr88
Contributor I

I use getchar() for input with following combination

 

device = (pointer)fopen("ttyd:", NULL);

 _io_set_handle(IO_STDOUT, device);
 _io_set_handle(IO_STDIN,  device);

 

Not sure about fread()?

0 Kudos
1,516 Views
lisa_tx
Contributor III

Gewehr88,

 

      Thank you for answering me!

 

      I have got help from Freescale. The problem has been solved. Removing R65 on TWR-K60F120M board. I can write to and read back from UART 5 ("ittyf:") through RS-232/RS-485. I can't read back through USB/OSJTAG anymore. That is OK with me.

 

Lisa

0 Kudos
1,517 Views
lisa_tx
Contributor III

I am sorry that there is typo in this post. I mean "I believe RS-232 is connected to UART5 ("ttyf:" or "ittyf:"), but OSJTAG also uses UART5.".   "ttyd:" or "ittyd:" doesn't work.

 

Lisa

0 Kudos
1,517 Views
Xuejian
Contributor II

I did the same thing with you, but I cannot see any output on PC hyperterminal through RS232 on SER board, no matter I use "printf()" or "write()". I do not know why.

0 Kudos