IMX 28 UART issue

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

IMX 28 UART issue

3,746 Views
ganeshh
Contributor III

hello,

Am IMX28 EVK and Linux BSP 2.6.35... I tried following this pdf and developing a UART test code

http://cache.freescale.com/files/dsp/doc/app_note/AN3870.pdf

But when i tried the command ./uart_appnote /dev/ttymxc2 i found that  /dev/ttymxc2 is missing there is no ttymxc0 or ttymxc1.

So How can i get the UART device files. Do i need to edit source files or is there any configuration missing in BSP building

Labels (2)
Tags (3)
0 Kudos
Reply
9 Replies

2,343 Views
gonfer
Contributor V

Hi Ganesh,

on iMX28EVK you should use /dev/ttySP0, /dev/ttySP1 and so on.

Hope this helps,

Gonzalo.

0 Kudos
Reply

2,343 Views
ganeshh
Contributor III

Thanks  gonfer

But when i tried that ttySP2

root@freescale /home/user$ ./uart_appnote /dev/ttySP2

Test: MXC UART With Eclipse !

Usage: mxc_uart_test <UART device name, opens UARmxs-auart mxs-auart.2: Unhandled status 52028d

T2 if no dev name is specified>

/dev/ttySP2 opened

Attributes set

Test: IOCTL Set

Data Written= Test

Data Read back=

I got this reply..there is no Data Read back??

0 Kudos
Reply

2,343 Views
gonfer
Contributor V

Can you paste your source code here?

0 Kudos
Reply

2,342 Views
ganeshh
Contributor III

Hi gonfer,

Source code

#include <stdio.h>

#include <stdlib.h>

#include <sys/types.h>

#include <sys/stat.h>

#include <fcntl.h>

#include <termios.h>

#include <sys/ioctl.h>

#include <unistd.h>

#define LOOPBACK        0x8000

int main(int argc, char **argv)

{

        int uart_file1;

        unsigned int line_val;

        char buf[5];

        struct termios mxc, old;

        int retval;

        printf("Test: MXC UART With Eclipse !\n");

        printf("Usage: mxc_uart_test <UART device name, opens UART2 if no dev name is specified>\n");

        if (argc == 1) {

                /* No Args, open UART 2 */

                if ((uart_file1 = open("/dev/ttymxc/1", O_RDWR)) == -1) {

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

                        exit(1);

                } else {

                        printf("Test: UART 2 opened\n");

                }

        } else {

                /* Open the specified UART device */

                if ((uart_file1 = open(*++argv, O_RDWR)) == -1) {

                        printf("Error opening %s\n", *argv);

                        exit(1);

                } else {

                        printf("%s opened\n", *argv);

                }

        }

        tcgetattr(uart_file1, &old);

        mxc = old;

        mxc.c_lflag &= ~(ICANON | ECHO | ISIG);

        retval = tcsetattr(uart_file1, TCSANOW, &mxc);

        printf("Attributes set\n");

        line_val = LOOPBACK;

        ioctl(uart_file1, TIOCMSET, &line_val);

        printf("Test: IOCTL Set\n");

        write(uart_file1, "Test\0", 5);

        printf("Data Written= Test\n");

        read(uart_file1, buf, 5);

        printf("Data Read back= %s\n", buf);

        sleep(2);

        ioctl(uart_file1, TIOCMBIC, &line_val);

        retval = tcsetattr(uart_file1, TCSAFLUSH, &old);

        close(uart_file1);

        return 0;

}

0 Kudos
Reply

2,343 Views
gonfer
Contributor V

Could you check if

retval = tcsetattr(uart_file1, TCSANOW, &mxc);

or

ioctl(uart_file1, TIOCMSET, &line_val);

are returning an error?

0 Kudos
Reply

2,343 Views
ganeshh
Contributor III

hello gonfer,

I got the return values as zero

root@freescale /home/user$ ./uart_appnote /dev/ttySP2

Test: MXC UART With Eclipse !

Usage: mxmxs-auart mxs-auart.2: Unhandled status 52028d

c_uart_test <UART device name, opens UART2 if no dev name is specified>

/dev/ttySP2 opened

The first retval is 0

Attributes set

Test: IOCTL Set

Data Written= Test

Data Read back=

The second retval is 0

0 Kudos
Reply

2,343 Views
gonfer
Contributor V

Hi Ganesh,

I think I've found 2 problems:

1st one:

#define LOOPBACK        0x8000

I think this value goes into HW_UARTAPP_CTRL2 register, and its purpose is to activate LBE bit. If this is so, then LOOPACK should be defined as 0x0080.

2nd one:

I've taken a quick look to the application uart driver and it looks that setting the LBE bit is not supported, so you should modify this driver to support this feature.

I've brute forced the driver setting always the LBE bit and the source code you have posted runs fine.

Regards,

Gonzalo.

0 Kudos
Reply

2,343 Views
ganeshh
Contributor III

Hi gonfer,

I didn't understand how you brute forced the driver ? Can you explain how you did that? are you using the same IMX28 EVK board?

0 Kudos
Reply

2,343 Views
gonfer
Contributor V

Hi Ganesh,

a deeper look shows I was wrong - the name LOOPBACK was misleading me, but the definition is OK. I think a more appropriate name could be use, like:

#define TIOCM_LOOP          0x8000

like in kernel headers.

To add support for the LOOPBACK feature in the driver (not brute forcing):

1.- In /arch/arm/mach-stmp378x/include/mach/regs-uartapp.h you should add:

#define BM_UARTAPP_CTRL2_LBE    0x00000080

2.- In /drivers/serial/mxs-auart.c look for static void mxs_auart_set_mctrl(struct uart_port *u, unsigned mctrl). This function should look something like this:

static void mxs_auart_set_mctrl(struct uart_port *u, unsigned mctrl)

{

    struct mxs_auart_port *s = to_auart_port(u);

    u32 ctrl = __raw_readl(u->membase + HW_UARTAPP_CTRL2);

    ctrl &= ~(BM_UARTAPP_CTRL2_RTS | BM_UARTAPP_CTRL2_LBE);

    if (mctrl & TIOCM_RTS)

        ctrl |= BM_UARTAPP_CTRL2_RTS;

    if (mctrl & TIOCM_LOOP)

        ctrl |= BM_UARTAPP_CTRL2_LBE;

    s->ctrl = mctrl;

    __raw_writel(ctrl, u->membase + HW_UARTAPP_CTRL2);

}

Then, recompile the kernel and you are done. I've ran your code in my iMX28evk and works fine !!

Regards,

Gonzalo.

0 Kudos
Reply