10 Replies Latest reply on Feb 3, 2015 4:17 PM by KurtE

    Uart's speeds available for Edison

    Víctor

      How can I know the different speed that I can set the UARTs?  In the tech document say that the uart baud rate go from 300 bps to 3.686 Mbps. But how to know the values allowed to be established?

       

       

      I need to set the uart 2 (ttyMFD2) to 1 Mbps, but I get an invalid argument error message.

       

       

      root@edison:~# stty -F /dev/ttyMFD2 1000000

      stty: invalid argument '1000000'

       

       

      (and the same for the UART 1)

       

       

      Any idea?

       

       

      Thanks a lot!

        • 1. Re: Uart's speeds available for Edison
          Intel_Peter

          Hello marblegravy,

           

          These are the baud rates that worked for me:

           

          50                75               110              134   

          150              200             300               600               1200

          1800            2400            4800             9600             19200

          38400          57600          115200          230400          460800

           

          Anything above these would show me the same error message.

           

          Peter.

          • 2. Re: Uart's speeds available for Edison
            KurtE

            It is interesting that the command does not support all of the baud rates you can set by the Arduino IDE... Or by tcsetattr....

             

            From the header files I see:

            define  B50    0000001
            #define  B75    0000002
            #define  B110    0000003
            #define  B134    0000004
            #define  B150    0000005
            #define  B200    0000006
            #define  B300    0000007
            #define  B600    0000010
            #define  B1200    0000011
            #define  B1800    0000012
            #define  B2400    0000013
            #define  B4800    0000014
            #define  B9600    0000015
            #define  B19200    0000016
            #define  B38400    0000017
            #define  B57600   0010001
            #define  B115200  0010002
            #define  B230400  0010003
            #define  B460800  0010004
            #define  B500000  0010005
            #define  B576000  0010006
            #define  B921600  0010007
            #define  B1000000 0010010
            #define  B1152000 0010011
            #define  B1500000 0010012
            #define  B2000000 0010013
            #define  B2500000 0010014
            #define  B3000000 0010015
            #define  B3500000 0010016
            #define  B4000000 0010017
            
            • 3. Re: Uart's speeds available for Edison
              Andre.M

              i miss 921600 even if that does not answer the main question "how to set higher rates or user defined rates..."

               

              root@edison:/boot# stty < /dev/ttyMFD1

              speed 921600 baud; line = 0;

              intr = ^C; quit = ^\; erase = ^?; kill = ^U; eof = ^D; eol = <undef>;

              eol2 = <undef>; swtch = <undef>; start = ^Q; stop = ^S; susp = ^Z; rprnt = ^R;

              werase = ^W; lnext = ^V; flush = ^O; min = 1; time = 0;

              -brkint -imaxbel

              • 4. Re: Uart's speeds available for Edison
                KurtE

                Have you tried something like: stty -F /dev/ttyMFD2 ospeed 1000000 ispeed 1000000

                The command does not give an error, don't know if it works or not...

                 

                Kurt

                • 5. Re: Uart's speeds available for Edison
                  Andre.M

                  @KurtE

                  root@edison:/boot# stty < /dev/ttyMFD1

                  speed 115200 baud; line = 0;

                  intr = ^C; quit = ^\; erase = ^?; kill = ^U; eof = ^D; eol = <undef>;

                  eol2 = <undef>; swtch = <undef>; start = ^Q; stop = ^S; susp = ^Z; rprnt = ^R;

                  werase = ^W; lnext = ^V; flush = ^O; min = 1; time = 0;

                  -brkint -imaxbel

                  root@edison:/boot# stty -F /dev/ttyMFD1 ospeed 1000000 ispeed 1000000

                  root@edison:/boot# stty < /dev/ttyMFD1

                  speed 115200 baud; line = 0;

                  intr = ^C; quit = ^\; erase = ^?; kill = ^U; eof = ^D; eol = <undef>;

                  eol2 = <undef>; swtch = <undef>; start = ^Q; stop = ^S; susp = ^Z; rprnt = ^R;

                  werase = ^W; lnext = ^V; flush = ^O; min = 1; time = 0;

                  -brkint -imaxbel

                   

                  as you can see nothing changed

                  • 6. Re: Uart's speeds available for Edison
                    KurtE

                    Yep sorry... If it were me, I would probably simply write my own command

                    • 7. Re: Uart's speeds available for Edison
                      Víctor

                      Yes, the highest baud rate I can set is 921600. But I don't know where's that limit set and how to change it.

                       

                       

                      Thanks for your answers.

                      • 8. Re: Uart's speeds available for Edison
                        Víctor

                        I'm going to try see the kernel code and detect where's these restrintions. I think (I suppose) it's only a software problem.

                        Any idea of where is the uarts definitions?

                         

                        Thanks

                        • 9. Re: Uart's speeds available for Edison
                          KurtE

                          Actually my guess is that the restriction is actually in the stty command.  That is I thought I read other threads, where someone used some higher speed settings, I believe they did it with the Arduino side, which they found only specific value were accepted.   My guess is this version of stty only accepts the baud rates that are in the non extended standard settings.

                           

                          So it should not be hard to write a simple program using termios that sets this to 1000000.  If I get a chance I could probably hack one up pretty quick, using my support code.  Example I have a WrapperSerial class, that I ported over the Arduino Serial class (plus print, plus..), such that I can create an instance of it with two IO pins, and then use standandard Arduino Serial.xxx calls to use it.  I did this to make it easier to port some of my Arduino programs over to linux.

                           

                          Could probably do with simple Arduino app to verify that you can get 1000000 with kernel.  Something like:

                          void setup() {
                            // put your setup code here, to run once:
                            delay(100);
                            Serial1.begin(1000000);
                            delay(100);
                            Serial1.end();
                          #ifdef ONLYONCE 
                            Serial.begin(1152000);
                            Serial.println("Kill the program");
                          //  system ("cp -f /tmp/log* /home/root/");
                            system ("mv -f /sketch/sketch.elf /sketch/sketch.elf.old");
                            delay(500);
                          //  system("reboot");
                          #endif
                          }
                          
                          void loop() {
                            // put your main code here, to run repeatedly:
                            delay(10000);  // long sleep
                          }
                          
                          • 10. Re: Uart's speeds available for Edison
                            KurtE

                            For the fun of it I did track down the sources for stty in my Edison build.  Note: I looked at the generated files not the actual source/patches

                            ~/edison-src/build/tmp/work/core2-32-poky-linux/busybox/1.22.1-r0/busybox-1.22.1/coreutils

                            is stty.c which calls out to: tty_value_to_baud

                            which is in the file:

                            ~/edison-src/build/tmp/work/core2-32-poky-linux/busybox/1.22.1-r0/busybox-1.22.1/libbb/speed_table.c

                            This file has the table:

                            static const struct speed_map speeds[] = {
                                {B0, 0},
                                {B50, 50},
                                {B75, 75},
                                {B110, 110},
                                {B134, 134},
                                {B150, 150},
                                {B200, 200},
                                {B300, 300},
                                {B600, 600},
                                {B1200, 1200},
                                {B1800, 1800},
                                {B2400, 2400},
                                {B4800, 4800},
                                {B9600, 9600},
                            #ifdef B19200
                                {B19200, 19200},
                            #elif defined(EXTA)
                                {EXTA, 19200},
                            #endif
                            #ifdef B38400
                                {B38400, 38400/256 + 0x8000U},
                            #elif defined(EXTB)
                                {EXTB, 38400/256 + 0x8000U},
                            #endif
                            #ifdef B57600
                                {B57600, 57600/256 + 0x8000U},
                            #endif
                            #ifdef B115200
                                {B115200, 115200/256 + 0x8000U},
                            #endif
                            #ifdef B230400
                                {B230400, 230400/256 + 0x8000U},
                            #endif
                            #ifdef B460800
                                {B460800, 460800/256 + 0x8000U},
                            #endif
                            #ifdef B921600
                                {B921600, 921600/256 + 0x8000U},
                            #endif
                            };
                            
                            
                            

                             

                            The code simply looks through this table

                            peed_t FAST_FUNC tty_value_to_baud(unsigned int value)
                            {
                                int i = 0;
                            
                                do {
                                    if (value == tty_baud_to_value(speeds[i].speed)) {
                                        return speeds[i].speed;
                                    }
                                } while (++i < NUM_SPEEDS);
                            
                                return (speed_t) - 1;
                            }
                            
                            

                             

                            So you could potentially figure out how to patch this table if you wish for some of the higher speed baud rates to work.