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 baud rate

Part Number: PROCESSOR-SDK-AM335X

Tool/software: Linux

Hello experts

Hardware: Beaglebone black

Software : latest TI SDK

I am trying to operate the UART in 3000000 baud rate

my Question:

Do i need to do any changes in software to achieve this baudrate ?

 Regards

  • Hello,
    baud rate you want to use is non standard for AM335X. You can choose between 1.843Mbps or the highest one 3.6884Mbps.
    There is nothing in between supported because no available divider value is present (values are 2 and 1 respectively @ 48MHz, 13x).

    BR,
    Michail
  •  hi Michail the baudrate of 3000000 is possible as per the datasheet please see the attached file of the AM335X on page 3970

  • I derived my information from table 19-25, on page 4344 where this baud rate is not in the list, will check again for this difference in the tables.

    Forgot to mention that I'm looking at

    https://www.ti.com/lit/ug/spruh73p/spruh73p.pdf

  • Hi Michail the one i sent you from is a complete technical reference manual which i think i took a long time from ti website but now it is in this link
    elinux.org/.../Spruh73c.pdf
  • Hi Nick,

    3000000 baud rate should be supported. Did you try to set the baud rate in your application and ran into any issue?
  • Thanks bin liu can you verify if the serial driver in the latest TI SDK support 3000000 bits per second speed because as soon as i set this speed i was unable to see any data

    Regards

  • Hi Nick,

    What do you mean you don't see any data? You don't see data on the uart bus analyzer or the receiving application?

    Do you see data in any lower baud rate?

  • yes i dont see any data and in the

    kernel config

    Device Drivers --->

    Character devices --->

    Serial drivers --->

    "8250/16550 and compatible serial support" i see this driver is enabled can you please confirm if this driver support 3Mbps

    and by the way we are using the TI SDK version : Processor SDK Linux for AM335x v04.00.00.04 Download i know this is 3 version old but still

  • Please describe your test setup, which uart port? any software change related to uart? which program and how to write and read? Does the test pass when using lower baud rate, for example 115200?
  • Please the attached C code it works fine for all baud rate less than 230400 and when i increase the baudrate to 3000000 it does not work

    5822.main.c
    #include <stdio.h>   /* Standard input/output definitions */
    #include <string.h>  /* String function definitions */
    #include <unistd.h>  /* UNIX standard function definitions */
    #include <fcntl.h>   /* File control definitions */
    #include <errno.h>   /* Error number definitions */
    #include <termios.h> /* POSIX terminal control definitions */
    
    #include <sys/types.h>
    #include <sys/time.h>
    #include <sys/select.h>
    #include <signal.h>
    #include <pthread.h>
    
    #define TIMEVAL struct timeval
    
    //globals:
    int bRunning=1;
    int bRun=1;
    //static const char *pHelloToken="hey laptop i just got: ";
    
    //FD:
    int ttyFD=-1; //global for this module
    pthread_t thrid;
    
    //open-tuning:
    int tty_open(const char *pDevName, unsigned int nBaud)
    {
    	int fd;
    	struct termios options;
    	
    	//open:
    	fd = open(pDevName, O_RDWR | O_NOCTTY | O_NDELAY);
    	if(-1 == fd)
    		return fd;
    		
    	//tune:
    	fcntl(fd, F_SETFL, 0);
    	
    	tcgetattr(fd, &options);
    	
    		options.c_cflag &= ~PARENB;
    		options.c_cflag &= ~CSTOPB;
    		options.c_cflag &= ~CSIZE;
    		options.c_cflag |= CS8;
    		
    		
    		if(cfsetispeed(&options, nBaud)<0) //B115200); //B3000000);
    		{
    			printf("failed to set input speed to %d\n", nBaud);
    		}
    		if(cfsetospeed(&options, nBaud)<0) //B115200); //B3000000);
    		{
    			printf("failed to set output speed to %d\n", nBaud);
    		}
    		
    		/*options.c_cflag &= ~CBAUD;    //Remove current BAUD rate
    		options.c_cflag |= BOTHER;    //Allow custom BAUD rate using int input
    		options.c_ispeed = 3000000;    //Set the input BAUD rate
    		options.c_ospeed = 3000000;    //Set the output BAUD rate*/
    
    
    		options.c_cflag |= (CLOCAL | CREAD);
    		
    		options.c_cflag     |= (CLOCAL | CREAD);
    //		options.c_cflag &= ~CNEW_RTSCTS;
    		
    		
    		options.c_lflag &= ~(ICANON | ECHO | ECHOE | ISIG); //raw mode!!!
    		options.c_iflag &= ~(IXON | IXOFF | IXANY); //no soft flow
    		options.c_oflag &= ~OPOST;	//raw output also
    	
    	tcsetattr(fd, TCSAFLUSH, &options);	
    	
    	return fd; //!!!!!!
    }
    
    int tty_blread(int nFD, char *pBuf, int nBufSize, int tmt_mS)
    {
    	fd_set fd;
        TIMEVAL tv;
        int bytes_read;
        
            
        //read all from port:
        bytes_read=0;
    		
    	FD_ZERO(&fd);
        tv.tv_sec = 0;
        tv.tv_usec =tmt_mS*1000; //mS
    
    	FD_SET(nFD, &fd);
    
    	if(0==select(nFD+1, &fd, NULL, NULL, &tv)) //wait for data
              return bytes_read;
            
        bytes_read+=read(nFD, pBuf+bytes_read, nBufSize-bytes_read);
    	return bytes_read;
    }
    
    void *upd_loop(void *parg)
    {
    	int nRead;
    	char in_buf[1024];
    	
    	if(ttyFD<0)
    	{
    		pthread_exit(0); 
    	}
    	
    	printf("entering listening thread...\n");
    	while(bRun){
    	
    		nRead=tty_blread(ttyFD, in_buf, sizeof(in_buf), 500);
    		if(nRead>0)
    		{
    #ifdef DIAG_MSG
    	in_buf[nRead-1]='\0';
        printf("->%s", in_buf); printf("\r\n");
    #endif	
    		}
    		usleep(100000); 
    	}
    	printf("exiting listening thread...\n");
    	pthread_exit(0);
    }
    
    int init_at_comm(void)
    {
    	return pthread_create(&thrid, NULL, upd_loop, NULL);
    }
    void destroy_at_comm(void)
    {
    	bRun=0;
    	pthread_join(thrid, NULL);
    }
    
    static void sigexit_handler(int signum) {
       bRunning=0;  
    }
    
    int main(void)
    {
    	struct termios tios;
    	speed_t ispeed;
    	speed_t ospeed;
    	
    	signal(SIGQUIT, sigexit_handler);
        signal(SIGINT, sigexit_handler);
        signal(SIGTERM, sigexit_handler);
    	
    	ttyFD=tty_open("/dev/ttyS1", 3000000); //B9600); 
    	if(ttyFD<0)
    	{
    		printf("failed to open ttyS1\n");
    		return 1;
    	}
    	
        
        tcgetattr(0, &tios);
    	ispeed = cfgetispeed(&tios);
    	ospeed = cfgetospeed(&tios);
    	printf("baud rate in: %d\n", tios.c_ispeed);
    	printf("baud rate out: %d\n", tios.c_ospeed);
        
        init_at_comm();
        
        while(bRunning)
        {
    		usleep(50000); 
    	}
    		
    	destroy_at_comm();
    	close(ttyFD);
    	
    	return 0;
    }
    

  • You don't use cfsetispeed()/cfsetospeed() correctly. Please see the document 'man cfsetospeed', the speed parameter passed into the functions has to be one of the constants - B<xxxx>, which only goes up to B230400.
  • even if i use this linux-serial-test -y 0x55 -z 0x0 -p /dev/ttyS1 -b 3000000 as mentioned in this link (https://github.com/cbrake/linux-serial-test/blob/master/linux-serial-test.c) still i do not see the baud of 3000000 i think it is issue with the kernel serial drivers can you please help check if this driver support 3000000 baud rate

  • Nick,

    What did you use to check the baud rate? I ran the same command 'linux-serial-test -y -x55 -z 0 -p /dev/ttyS1 -b 3000000', and I see the baud rate is correct on  uart bus analyzer. Please check the screenshot below.

  • Hi Nick,

    I haven’t heard back from you, I’m assuming you were able to resolve your issue. If not, just post a reply below (or create a new thread if the thread has locked due to time-out). thanks.