11 Replies Latest reply on Jan 20, 2015 7:15 PM by bermerlin

    how to activate uart2

    shb

      hi,

      i am trying to activate uart2 on the mini breakout board

      i used this for information than i used this to activate uart1. i only need rx thats why i only used

       

      echo 130 > /sys/class/gpio/export 2>&1

      echo mode1 > /sys/kernel/debug/gpio_debug/gpio130/current_pinmux

      echo in > /sys/class/gpio/gpio130/direction


      i ve wrote a python script, which reads tx and it works how it should.


      Now i tried to setup uart2

       

      echo 134 > /sys/class/gpio/export 2>&1

      echo mode1 > /sys/kernel/debug/gpio_debug/gpio134/current_pinmux

      echo in > /sys/class/gpio/gpio134/direction


      and changed my script from /dev/ttyMFD1 to /dev/ttyMFD2

      and now  my script is crashing

      Traceback (most recent call last):

        File "rfid2.py", line 37, in <module>

          c = rfid.read(rfid.inWaiting())

        File "/usr/lib/python3/dist-packages/serial/serialposix.py", line 449, in read

          buf = os.read(self.fd, size-len(read))

      OSError: [Errno 11] Resource temporarily unavailable

       

      i think i forgot something, but i dont know what.

      can someone give me advice?

       

      regardes stefan

        • 1. Re: how to activate uart2
          KurtE

          I have not tried it yet with the mini-board, but has used Serial2 on the Arduino breakout board.  I have done so through the Arduino IDE.  I believe by default the system console is using this Serial port...

           

          If you look at the Arduino sources for this.  On my machine it is at:

          C:\arduino-1.5.3-Intel.1.0.4\hardware\arduino\edison\cores\arduino\TTYUART.cpp,

           

          You will see how the Arduino system detaches the console from the serial port.  It also sets up stuff such that the console is reattached when you end using the Serial2 and/or reboot.

          • 2. Re: how to activate uart2
            shb

            hi

                 > I believe by default the system console is using this Serial port...


            yes you are right, but

            This is a very useful port to connect to for debugging, especially when trying to isolate boot problems.  The kernel generates its debug “spew” to this port at 115,200 baud.  I find it useful to always have a PuTTY terminal console connected to this.  When the Serial2 object is initialized with Serial2.begin(), the kernel's access to the port is removed, and the sketch is given control until it calls Serial2.end().

             

            there must be a solution to use uart2 but i dont know how.

             

            bye stefan

            • 3. Re: how to activate uart2
              mikalhart

              there must be a solution to use uart2 but i dont know how.

               

              stefan, I think KurtE's reply is the solution.  If you want to use uart2 outside of the Arduino IDE, the easiest way to do so is to examine the code for Serial2 in file he linked to.  You'll have to disable the kernel's access to uart2 if you want to use its resources for your application.

              • 4. Re: how to activate uart2
                shb

                yes you are right, i saw what you mean.

                i will try next weekend and reprot after succes of fail

                • 5. Re: how to activate uart2
                  shb

                  ok,

                  i ve tried with a litte success but i am not finished.

                  this ist the cpp source code

                   

                    system("/bin/cp -f /etc/inittab /etc/inittab.restore");

                    snprintf(cmd, sizeof(cmd),

                     "/bin/sed -i -e '/^\\(S.*getty.*%s$\\)/i\\\n"

                     "# Disabling getty to allow Arduino sketch to use %s and\n"

                     "# adding sysinit commands to restore normal behaviour on next boot\n"

                     "' /etc/inittab",

                    ttydev, ttydev);

                    system(cmd);

                    snprintf(cmd, sizeof(cmd),

                     "/bin/sed -i -e '/^\\(S.*getty.*%s$\\)/i\\\n"

                     "res1:2345:sysinit:/bin/mv -f /etc/inittab.restore /etc/inittab\n"

                     "' /etc/inittab",

                    ttydev);

                    system(cmd);

                    snprintf(cmd, sizeof(cmd),

                     "/bin/sed -i -e '/^\\(S.*getty.*%s$\\)/i\\\n"

                     "res2:2345:sysinit:/sbin/telinit q\n"

                     "' /etc/inittab",

                    ttydev);

                    system(cmd);

                   

                  // Modify inittab to stop use of this console device for user log-in

                    snprintf(cmd, sizeof(cmd),

                     "/bin/sed -i -e 's/^\\(S.*getty.*%s$\\)/#\\1/' /etc/inittab",

                    ttydev);

                    system(cmd);

                   

                  // Tell init to reload its configuration

                    system("/sbin/telinit q");

                   

                  // Forcibly kill any processes still using the tty device.

                    snprintf(cmd, sizeof(cmd),

                     "export PATH=/bin:/usr/bin; "

                     "lsof | grep '%s' | cut -f 1 | sort -u | xargs -r kill -9",

                    ttydev);

                    system(cmd);

                   

                  i search for getty in /etc/inttab and found

                   

                  1:2345:respawn:/sbin/getty 38400 tty1

                  2:23:respawn:/sbin/getty 38400 tty2

                  3:23:respawn:/sbin/getty 38400 tty3

                  4:23:respawn:/sbin/getty 38400 tty4

                  5:23:respawn:/sbin/getty 38400 tty5

                  6:23:respawn:/sbin/getty 38400 tty6

                   

                  # Example how to put a getty on a serial line (for a terminal)

                  #

                  #T0:23:respawn:/sbin/getty -L ttyS0 9600 vt100

                  #T1:23:respawn:/sbin/getty -L ttyS1 9600 vt100

                  T0:23:respawn:/sbin/getty -L ttyMFD2 115200 vt100

                  i uncommented the last line and reload with

                       telinit q

                   

                  after this i started my programm

                  and tried to read the serial rfid reader

                   

                  and... the resources was not busy, but  i dont get the data i want, i only get

                   

                  b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'

                  but i expect hex values, does someone has an idea?

                   

                  regardes stefan

                  • 6. Re: how to activate uart2
                    vivo133

                    It do not work for me to activate the uart2.


                    After I  detaches the console from the serial port. It starts again.I run the Serial.begin(115200)  in Edison ,the phenomenon  is that:

                     

                     

                    图片1.png

                    I want to sheild the uart2's  terminal function and use uart2 as simple data transfer.

                     

                    Thanks a lot

                     

                     

                    • 7. Re: how to activate uart2
                      bermerlin

                      After some research, I have been able to find a crude way to disable the console on UART2, thanks to this post:
                      https://communities.intel.com/message/269377

                      FIRST MAKE SURE THAT YOU HAVE ACCESS TO THE CONSOLE WIRELESSLY THROUGH SSH, as you will need this access to reattach the console to UART2 later on if you wish.

                      - Open an SSH session and disable the console:

                         fw_setenv bootargs_console

                      then reboot

                         shutdown -r now

                      To re-attach:
                      - Open an SSH session and enable the console

                      fw_setenv bootargs_console console=ttyMFD2 earlyprintk=ttyMFD2,keep  

                      and reboot

                      This could surely be automated the same way as in the Edison Arduino firmware.

                      • 8. Re: how to activate uart2
                        vivo133

                        Hi,@bermerlin, I did as you said ,but it  didn't work .

                         

                        I open an SSH session and disable the console:

                         

                        like this:

                        图片1.png

                         

                        I  can log on the terminal console still, the buad chang to 9600

                         

                        图片2.png

                        • 9. Re: how to activate uart2
                          bermerlin

                          It is normal that you can still log to UART2 (either through the USB port or directly at TTL level on an expansion board). The difference now is that the port is not used by the console, but available for your own usage.

                          • 10. Re: how to activate uart2
                            vivo133

                            Hi,bermerlin

                            If the terminal console  can receive  data from Uart2 ,it's unavailable for my own  usage.

                            • 11. Re: how to activate uart2
                              bermerlin

                              I will try to be more clear. After detaching the console from UART2 with fw_setenv bootargs_console and reboot, the console input/output is not directed anymore on UART2, but continue to be available through SSH. At this moment, UART2 is completely isolated from the console and is available for other uses. I should add that this method only applies to the Yocto distro.