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.

AM6546: Wakeup UART baud rate is getting double

Part Number: AM6546

Hi,

We are using wake up UART0 port for RS485 port. We are using application to write data.When data transmitted at 9600 baud rate we are receiving at 19200.I am not sure what is the issue, Please support in finding solution.

DTS:

&wkup_uart0 {
    /* Wakeup UART is used by System firmware */
    status = "okay";
    pinctrl-names = "default";
    pinctrl-0 = <&wkup_uart0_pins_default>;
};

 wkup_uart0: serial@42300000 {
        compatible = "ti,am654-uart";
        reg = <0x42300000 0x100>;
        reg-shift = <2>;
        reg-io-width = <4>;
        interrupts = <GIC_SPI 697 IRQ_TYPE_LEVEL_HIGH>;
        clock-frequency = <48000000>;
        current-speed = <115200>;
        power-domains = <&k3_pds 150 TI_SCI_PD_EXCLUSIVE>;
    };

application code:

    #include <stdio.h>
    #include <fcntl.h>       /* File Control Definitions           */
    #include <termios.h>     /* POSIX Terminal Control Definitions */
    #include <unistd.h>      /* UNIX Standard Definitions          */ 
    #include <errno.h>       /* ERROR Number Definitions           */
    #include <sys/ioctl.h>   /* ioctl()                            */

    void main(void)
    {
        int fd;/*File Descriptor*/

    printf("\n +----------------------------------+");
    printf("\n |      external rs485     |");
    printf("\n +----------------------------------+");

    /*------------------------------- Opening the Serial Port -------------------------------*/

    /* Change /dev/ttyUSB0 to the one corresponding to your system */

        fd = open("/dev/ttyS2",O_RDWR | O_NOCTTY);
                                /* O_RDWR Read/Write access to serial port           */
                                /* O_NOCTTY - No terminal will control the process   */

        if(fd == -1 )                        /* Error Checking */
               printf("\n  Error! in Opening ttyS2");
        else
               printf("\n  tty Opened Successfully ");


    /*---------- Setting the Attributes of the serial port using termios structure --------- */

    struct termios SerialPortSettings;  /* Create the structure                          */

    tcgetattr(fd, &SerialPortSettings); /* Get the current attributes of the Serial port */

    cfsetispeed(&SerialPortSettings,B9600); /* Set Read  Speed as 9600                       */
    cfsetospeed(&SerialPortSettings,B9600); /* Set Write Speed as 9600                       */

    SerialPortSettings.c_cflag &= ~PARENB;   /* Disables the Parity Enable bit(PARENB),So No Parity   */
    SerialPortSettings.c_cflag &= ~CSTOPB;   /* CSTOPB = 2 Stop bits,here it is cleared so 1 Stop bit */
    SerialPortSettings.c_cflag &= ~CSIZE;    /* Clears the mask for setting the data size             */
    SerialPortSettings.c_cflag |=  CS8;      /* Set the data bits = 8                                 */

    SerialPortSettings.c_cflag &= ~CRTSCTS;       /* No Hardware flow Control                         */
    SerialPortSettings.c_cflag |= CREAD | CLOCAL; /* Enable receiver,Ignore Modem Control lines       */ 


    SerialPortSettings.c_iflag &= ~(IXON | IXOFF | IXANY);          /* Disable XON/XOFF flow control both i/p and o/p */
    SerialPortSettings.c_iflag &= ~(ICANON | ECHO | ECHOE | ISIG);  /* Non Cannonical mode                            */

    SerialPortSettings.c_oflag &= ~OPOST;/*No Output Processing*/

    /* Setting Time outs */
    SerialPortSettings.c_cc[VMIN] =  1; /* Read at least 10 character */
    SerialPortSettings.c_cc[VTIME] = 0;  /* Wait indefinetly   */

    if((tcsetattr(fd,TCSANOW,&SerialPortSettings)) != 0) /* Set the attributes to the termios structure*/
        printf("\n  ERROR ! in Setting attributes tx");
    else
                printf("\n  BaudRate = 9600 \n  StopBits = 1 \n  Parity   = none");

    /*---------------------------------------- Controlling RTS and DTR Pins --------------------------------------*/
    /* ~RTS(USB2SERIAL) ---> ~RE(MAX485) */
    /* ~DTR(USB2SERIAL) --->  DE(MAX485) */

    /*------------------------- Putting MAX485 chip in USB2SERIAL in Transmit Mode ---------------------------*/
    //                                                                                                        //
    //  ----+           +-----------+              H  +-----------+                                           //
    //      |           |       ~RTS| --------------> |~RE        |                                           //
    //   PC |==========>| FT232     |                 |   MAX485  +(A,B)~~~~~~~~~~~~~~~>Data out(RS485)       //
    //      |    USB    |       ~DTR| --------------> | DE        |        Twisted Pair                       //
    //  ----+           +-----------+              H  +-----------+                                           //
    //                                                                                                        //
    //--------------------------------------------------------------------------------------------------------//
    //TxMode - DE->High,~RE -> High

    int RTS_flag,DTR_flag;

    RTS_flag = TIOCM_RTS;   
    DTR_flag = TIOCM_DTR;

    ioctl(fd,TIOCMBIC,&RTS_flag);/* ~RTS = 1,So ~RE pin of MAX485 is HIGH                       */
    ioctl(fd,TIOCMBIC,&DTR_flag);/* ~DTR = 1,So  DE pin of MAX485 is HIGH,Transmit Mode enabled */ 

        /*------------------------------- Write data to serial port -----------------------------*/

    tcflush(fd, TCIFLUSH);   /* Discards old data in the rx buffer            */     

    char write_buffer[] = "che$";    /* Buffer containing characters to write into port       */ 
    char write_buffer1[] = {'\r','\n'};
    char write_buffer2[] = "kumar";
    int  bytes_written  = 0;    /* Value for storing the number of bytes written to the port */ 

    bytes_written = write(fd,write_buffer,sizeof(write_buffer));/* use write() to send data to port                                            */
                                     /* "fd"                   - file descriptor pointing to the opened serial port */
                                     /* "write_buffer"         - address of the buffer containing data              */
                                     /* "sizeof(write_buffer)" - No of bytes to write                               */  
    printf("\n  %s written to ttyS2",write_buffer);
    sleep(2);
    printf("\n  %d Bytes written to ttyS2", bytes_written);
    bytes_written = write(fd,write_buffer1,2);
    printf("\n  %s written to ttyS2",write_buffer1);
    printf("\n  %d Bytes written to ttyS2", bytes_written);
    printf("\n +----------------------------------+\n\n");
    sleep(2);
    bytes_written = write(fd,write_buffer2,5);

    printf("\n +----------------------------------+\n\n\n");
    close(fd); /* Close the serial port */
}

Regards,

N Chetan Kumar

  • Hi Chetan,

    If i look at the "arch/arm64/boot/dts/ti/k3-am654-base-board.dts"


    &wkup_uart0 {
    /* Wakeup UART is used by System firmware */
    status = "disabled";
    };

    As the comment above mentions it is to be used my System firmware. May i know why you are particular about
    wkup_uart0 instance?

    If you still want to use wkup_uart0 the clock frequency is not set in the dts:

    diff --git a/arch/arm64/boot/dts/ti/k3-am65-wakeup.dtsi b/arch/arm64/boot/dts/ti/k3-am65-wakeup.dtsi
    index 0f602ae8d..1c485e574 100644
    --- a/arch/arm64/boot/dts/ti/k3-am65-wakeup.dtsi
    +++ b/arch/arm64/boot/dts/ti/k3-am65-wakeup.dtsi
    @@ -53,7 +53,7 @@
                    reg-shift = <2>;
                    reg-io-width = <4>;
                    interrupts = <GIC_SPI 697 IRQ_TYPE_LEVEL_HIGH>;
    -               clock-frequency = <48000000>;
    +               clock-frequency = <96000000>;
                    current-speed = <115200>;
                    power-domains = <&k3_pds 150 TI_SCI_PD_EXCLUSIVE>;
            };
    

    Best Regards,
    Keerthy

  • Hi Keerthy,

    Thanks for input.

    We are using Wakeup UART port in custom board for rs485 purpose.

    If we use this port for some other purpose, This may cause any issue?

    Regards,

    N Chetan Kumar

  • Hi Chetan,

    Typically all the DMSC firmware traces are routed to this UART instance. Hence i raised

    the concern.  None the less with the above frequency change are you able to get the BAUD
    corrected?

    Best Regards,
    Keerthy

  • Hi Keerthy,

    After changing the clock frequency. I was able to get proper baud rate.

    Regards,

    N Chetan Kumar