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.

Linux/PROCESSOR-SDK-AM335X: UART custom baud rate

Part Number: PROCESSOR-SDK-AM335X

Tool/software: Linux

Hi ,

I m facing issue , while setting my custom baud rates

root@sfms:~# stty -F /dev/ttyS4 1200
root@sfms:~# stty -F /dev/ttyS4 10400
stty: invalid argument '10400'
root@sfms:~# stty -F /dev/ttyS4 10965
stty: invalid argument '10965'

I referred the below TI link

In that, you are requesting to set baud for particular UART port through system call as 38400 then it will set it to 10400.
Then what is the baud rate for 10965 ? How to calculate it ? Is it possible directly set the custom baud rate ?

https://e2e.ti.com/support/arm/sitara_arm/f/791/p/384844/1357293#pi316653filter=all&pi316653scroll=false


  • The software team have been notified. They will respond here.
  • Yeah , thanks for the reply Biser
  • Karthikeyan,

    I think the problem is that the uart driver do not allow to change to a custom baudrate. You can try to modify the driver.

    An other opportunity is to make your own application and define custom baudrate as it is described below:

    #include <stropts.h>
    #include <asm/termios.h>
    .....
    
    struct termios2 tio;
    
    ioctl(fd, TCGETS2, &tio);
    tio.c_cflag &= ~CBAUD;
    tio.c_cflag |= BOTHER;
    tio.c_ispeed = 12345;
    tio.c_ospeed = 12345;
    ioctl(fd, TCSETS2, &tio);

    BR

    Tsvetolin Shulev

  • Hi Cvetolin,

    Thanks for the reply. I proceed with application method

  • Hi Cvetolin,

    I configured the serial port using API.

    The output of the ospeed and ispeed got changed according to my configuration.

    But I m not getting the proper data for 10400 Baud Rate.
    Can able to receive proper data on 1200 Baud Rate.

    What might be the problem in the API method configuration?
  • Here my API,

    int8_t klineConfigPort(uint64_t baudrate)
    {
        struct termios2 options;
        int ret, fd;

        /* Open Kline uart connection */
        if((baudrate < 0) || (baudrate > MAX_BAUDRATE)) {
            FMS_LOG(LOG_ERR,"Wrong baudrate[0-460800]:%d\r\n", baudrate);
            return -1;
        }

        /* Open Kline uart connection */
        fd = open(KLINE_DEV, O_RDWR | O_NOCTTY);
        if(fd < 0) {
            FMS_LOG(LOG_ERR,"Error opening  %s \r\n", KLINE_DEV);
            return -1;
        }

        /* Get serial port parameters */
        ret = ioctl(fd, TCGETS2, &options);
        if(ret !=0) {
            FMS_LOG(LOG_ERR,"Error getting kline uart parameters\r\n");
            return -1;
        }

        FMS_LOG(LOG_DEBUG,"Current baudrate (i/o): %d/%d\n",
            options.c_ispeed, options.c_ospeed);

        /* Set the baud rate */
        options.c_cflag &= ~CBAUD;
        options.c_cflag |= BOTHER;
        options.c_ispeed = baudrate;
        options.c_ospeed = baudrate;

        /* Enable the receiver and set local mode */
        options.c_cflag |= (CLOCAL | CREAD);

        /* No parity (8N1) */
        options.c_cflag &= ~PARENB;
        options.c_cflag &= ~CSTOPB;
        options.c_cflag &= ~CSIZE;
        options.c_cflag |= CS8;

        /* Disbale hardware flow control (CNEW_RTCCTS) */
        /* N7 extension */
        options.c_cflag &= ~CRTSCTS;

        /* N7 fix, disable XON XOFF explicitely */
        options.c_iflag &= ~(INLCR | ICRNL | IGNCR | IXON | IXOFF);
         /* N7 ignore framing and parity errors */
        options.c_iflag |= IGNPAR;

        /* set raw output */
        options.c_oflag &= ~OPOST;
        options.c_oflag &= ~OLCUC;
        options.c_oflag &= ~ONLRET;
        options.c_oflag &= ~ONOCR;
        options.c_oflag &= ~OCRNL;

        /* Set the new options for the port */
        ret = ioctl(fd, TCSETS2, &options);
        if (ret != 0) {
            FMS_LOG(LOG_ERR,"Error setting kline uart parameters\r\n");
            return -1;
        }
        /* Get serial port parameters */
        ret = ioctl(fd, TCGETS2, &options);
        if(ret !=0) {
            FMS_LOG(LOG_ERR,"Error getting uart parameters\r\n");
            return -1;
        }

        FMS_LOG(LOG_DEBUG,"Updated baudrate (i/o): %d/%d\n",
            options.c_ispeed, options.c_ospeed);

        close(fd);
        return 0;
    }

    Can you tell me what went wrong ?