1 2 Previous Next 19 Replies Latest reply on Mar 6, 2016 6:51 PM by vaishali1

    How to program UART serial from Linux on Galileo Gen 2?

    tevin_wang

      Dear All,

       

      I use Intel Galileo Gen2 and I need 2 UART serials to link to 2 RS232 devices.
      Before this, I write a simple Arduino program and utilize UART #0 in an Arduino sketch, it is connected to shield pins IO0/IO1, it works fine and correctly.
      The UART #1 is connected to shield pins IO2/IO3 works fine as well.
      But I try the same setting in Linux environment, and refer Sergey's Blog: Configuring the Serial Port in Linux
      It doesn't work. Even I google all related information, and try everything I can do. I still have no idea to let it work.
      I know Sergey's is Galileo Gen1 so I refer the Gen2's I/O pin configuration from EmutexLab Getting Started with Intel Galileo Gen 2
      I change the IO0/IO1 as gpio11/gpio12 and setup the /dev/ttyS0, and it still doesn't work (actually, it can receive data but has problem on sending data via /dev/ttyS0)
      Does anyone have any ideas about how to program UART#0 and UART#1 serials on Galileo Gen 2 in Linux?
      Thank you.

       

      Regards,
      Tevin

        • 1. Re: How to program UART serial from Linux on Galileo Gen 2?
          Intel_Alvarado

          Hi tevin_wang,

          I will run some tests to try to give you a more accurate response. I will let you know my results.

          Regards

          Sergio

          • 2. Re: How to program UART serial from Linux on Galileo Gen 2?
            Intel_Peter

            Hello tevin_wang,

                      

            The information you posted on the link above only works on the Galilelo Gen1, because on the Gen2 they changed some of its hardware, so i will post the correct code to write on serial from linux bellow:              

            cd /sys/class/gpio                                                                         

            echo -n "28" > export

            echo -n "32" > export

            echo -n "45" > export

            cd gpio28

            echo -n "out" > direction

            echo -n "0" > value

            cd gpio32

            echo -n "out" > direction

            echo -n "1" > value

            cd gpio45

            echo -n "out" > direction

            echo -n "1" > value

            stty -F /dev/ttyS0 9600                    //change to the baud rate you want to use

            echo -n "value" > dev/ttyS0             //change value for what you want to write

            cat /dev/ttyS0                                //read from UART

             

            There is just one detail, whatever you write using echo -n "value" > dev/ttyS0 will be written in ASCII code so make sure you are using the correct ASCII characters.

             

            Regards,

                           Peter.

            1 of 1 people found this helpful
            • 3. Re: How to program UART serial from Linux on Galileo Gen 2?
              tevin_wang

              Hello, Peter,

               

              It works! I'm glad you solved my problem. Your help is much appreciated.

               

              Regards,

              Tevin

              • 4. Re: How to program UART serial from Linux on Galileo Gen 2?
                Intel_Peter

                Hello tevin_wang,

                 

                I'm glad you were able to solve your issue and that I could be of help. If you have any more doubts, don't hesitate to ask.

                 

                Regards,

                            Peter

                • 5. Re: How to program UART serial from Linux on Galileo Gen 2?
                  xthunderheartx

                  If you are attempting to access UART0 from C/C++ a better solution is libmraa.so->mraa_uart_init(int).  This routine sets up the GPIO to expose the UART for you programajikly.  No need for any file operations or calls to external bash scripts etc.  It was broken on GEN2 boards until yesterday but has been fixed in the repository by Tom.  See https://communities.intel.com/thread/57056 for more detail.

                   

                  Dallas

                  1 of 1 people found this helpful
                  • 6. Re: How to program UART serial from Linux on Galileo Gen 2?
                    tsvetan.filev

                    Hi all.

                     

                    I have Galileo Gen 1. I tried the example above:

                     

                    cd /sys/class/gpio

                    echo -n "28" > export

                    echo -n "32" > export

                    echo -n "45" > export

                    cd gpio28

                    echo -n "out" > direction

                    echo -n "0" > value

                    cd gpio32

                    echo -n "out" > direction

                    echo -n "1" > value

                    cd gpio45

                    echo -n "out" > direction

                    echo -n "1" > value

                    stty -F /dev/ttyS0 9600

                    echo -n "value" > /dev/ttyS0

                    cat /dev/ttyS0

                     

                    but I got:

                     

                    root@clanton:~# cd /sys/class/gpio

                    root@clanton:/sys/class/gpio# echo -n "28" > export

                    cd gpio28

                    -sh: echo: write error: Device or resource busyecho -n "out" > direction

                    echo -n "0" > value

                     

                    root@clanton:/sys/class/gpio# echo -n "32" > export

                    -sh: echo: write error: Device or resource busy

                    echo -n "1" > value

                    stty -F /dev/ttyS0 9600

                    root@clanton:/sys/class/gpio# echo -n "45" > export

                    -sh: echo: write error: Device or resource busy

                    root@clanton:/sys/class/gpio# cd gpio28

                    root@clanton:/sys/class/gpio/gpio28# echo -n "out" > direction

                    root@clanton:/sys/class/gpio/gpio28# echo -n "0" > value

                    root@clanton:/sys/class/gpio/gpio28# cd gpio32

                    -sh: cd: gpio32: No such file or directory

                    root@clanton:/sys/class/gpio/gpio28# echo -n "out" > direction

                    root@clanton:/sys/class/gpio/gpio28# echo -n "1" > value

                    root@clanton:/sys/class/gpio/gpio28# cd gpio45

                    -sh: cd: gpio45: No such file or directory

                    root@clanton:/sys/class/gpio/gpio28# echo -n "out" > direction

                    root@clanton:/sys/class/gpio/gpio28# echo -n "1" > value

                    root@clanton:/sys/class/gpio/gpio28# stty -F /dev/ttyS0 9600

                    stty: /dev/ttyS0: Input/output error

                    root@clanton:/sys/class/gpio/gpio28# echo -n "value" > /dev/ttyS0

                    -sh: echo: write error: Input/output error

                    root@clanton:/sys/class/gpio/gpio28# cat /dev/ttyS0

                    cat: /dev/ttyS0: Input/output error

                     

                     

                    Do you have any idea ?

                    • 7. Re: How to program UART serial from Linux on Galileo Gen 2?
                      Intel_Peter

                      Hello tsvetan.filev,

                       

                      The thing is that those instructions will only work on the Galileo Gen 2, these are the instructions for the Gen 1:

                       

                      echo -n "4" > /sys/class/gpio/export

                      echo -n "40" > /sys/class/gpio/export

                      echo -n "41" > /sys/class/gpio/export

                      echo -n "out" > /sys/class/gpio/gpio4/direction

                      echo -n "out" > /sys/class/gpio/gpio40/direction

                      echo -n "out" > /sys/class/gpio/gpio41/direction

                      echo -n "strong" > /sys/class/gpio/gpio40/drive

                      echo -n "strong" > /sys/class/gpio/gpio41/drive

                      echo -n "1" > /sys/class/gpio/gpio4/value

                      echo -n "0" > /sys/class/gpio/gpio40/value

                      echo -n "0" > /sys/class/gpio/gpio41/value

                      stty -F /dev/ttyS0 9600                      //change to the baud rate you want to use

                      echo -n "value" > dev/ttyS0             //change value for what you want to write

                      cat /dev/ttyS0                                      //read from UART

                       

                      Peter.

                      • 8. Re: How to program UART serial from Linux on Galileo Gen 2?
                        tsvetan.filev

                        Hi Peter.

                         

                        I gave it a try.

                        It works when I boot from the board's image.

                        But when I boot from the image on my SD card (I downloaded the BSP Intel® Download Center, added few packages and build my own image) it doesn't.

                         

                        I got:

                         

                        root@clanton:~# echo -n "4" > /sys/class/gpio/export

                        -sh: echo: write error: Device or resource busy

                        root@clanton:~# echo -n "40" > /sys/class/gpio/export

                        -sh: echo: write error: Device or resource busy

                        root@clanton:~# echo -n "41" > /sys/class/gpio/export

                        -sh: echo: write error: Device or resource busy

                        root@clanton:~# echo -n "out" > /sys/class/gpio/gpio4/direction

                        root@clanton:~# echo -n "out" > /sys/class/gpio/gpio40/direction

                        root@clanton:~# echo -n "out" > /sys/class/gpio/gpio41/direction

                        root@clanton:~# echo -n "strong" > /sys/class/gpio/gpio40/drive

                        root@clanton:~# echo -n "strong" > /sys/class/gpio/gpio41/drive

                        root@clanton:~# echo -n "1" > /sys/class/gpio/gpio4/value

                        root@clanton:~# echo -n "0" > /sys/class/gpio/gpio40/value

                        root@clanton:~# echo -n "0" > /sys/class/gpio/gpio41/value

                        root@clanton:~# stty -F /dev/ttyS0 9600

                        stty: /dev/ttyS0: Input/output error

                        root@clanton:~# echo -n "value" > dev/ttyS0

                        -sh: dev/ttyS0: No such file or directory

                        root@clanton:~# cat /dev/ttyS0

                        cat: /dev/ttyS0: Input/output error

                        root@clanton:~#

                         

                        Are there any special actions I should take in order to use this UART port.

                        I tried to kill all galileo (sketch) processes but this didn't help.

                        I also gave full permissions to /dev/ttyS0 even though I'm already loogged in as root which didn't help as well.

                        I looked in /var/log/messages but didn't find any error message,

                         

                        Regards.

                        Tsvetan.

                        • 9. Re: How to program UART serial from Linux on Galileo Gen 2?
                          Intel_Peter

                          Hello tsvetan.filev,

                           

                          Can you show me what's under /sys/class/gpio and /dev?

                           

                          Peter.

                          • 10. Re: How to program UART serial from Linux on Galileo Gen 2?
                            tsvetan.filev

                            Peter,

                             

                            this is the list:

                             

                            root@clanton:~# ls /sys/class/gpio

                            export  gpio17  gpio23  gpio29  gpio37  gpio42  gpio48  gpio54      unexport

                            gpio0   gpio18  gpio24  gpio3   gpio38  gpio43  gpio49  gpio55

                            gpio1   gpio19  gpio25  gpio30  gpio39  gpio44  gpio50  gpiochip0

                            gpio14  gpio20  gpio26  gpio31  gpio4   gpio45  gpio51  gpiochip16

                            gpio15  gpio21  gpio27  gpio32  gpio40  gpio46  gpio52  gpiochip2

                            gpio16  gpio22  gpio28  gpio36  gpio41  gpio47  gpio53  gpiochip8

                             

                            root@clanton:~# ls /dev/

                            block               ptyp0   snd        tty39    ttyp3

                            bus                 ptyp1   spidev1.0  tty4     ttyp4

                            char                ptyp2   stderr     tty40    ttyp5

                            console             ptyp3   stdin      tty41    ttyp6

                            core                ptyp4   stdout     tty42    ttyp7

                            cpu                 ptyp5   tty        tty43    ttyp8

                            cpu0                ptyp6   tty0       tty44    ttyp9

                            cpu_dma_latency     ptyp7   tty1       tty45    ttypa

                            disk                ptyp8   tty10      tty46    ttypb

                            esramtest0          ptyp9   tty11      tty47    ttypc

                            event0              ptypa   tty12      tty48    ttypd

                            event1              ptypb   tty13      tty49    ttype

                            fd                  ptypc   tty14      tty5     ttypf

                            full                ptypd   tty15      tty50    ttyq0

                            hpet                ptype   tty16      tty51    ttyq1

                            i2c-0               ptypf   tty17      tty52    ttyq2

                            iio:device0         ptyq0   tty18      tty53    ttyq3

                            imrtest0            ptyq1   tty19      tty54    ttyq4

                            initctl             ptyq2   tty2       tty55    ttyq5

                            input               ptyq3   tty20      tty56    ttyq6

                            kmem                ptyq4   tty21      tty57    ttyq7

                            kmsg                ptyq5   tty22      tty58    ttyq8

                            log                 ptyq6   tty23      tty59    ttyq9

                            loop-control        ptyq7   tty24      tty6     ttyqa

                            loop0               ptyq8   tty25      tty60    ttyqb

                            loop1               ptyq9   tty26      tty61    ttyqc

                            mem                 ptyqa   tty27      tty62    ttyqd

                            mmcblk0             ptyqb   tty28      tty63    ttyqe

                            mmcblk0p1           ptyqc   tty29      tty7     ttyqf

                            mqueue              ptyqd   tty3       tty8     udev_network_queue

                            msr0                ptyqe   tty30      tty9     uio0

                            mtab                ptyqf   tty31      ttyGS0   uio1

                            network_latency     ram0    tty32      ttyQRK0  urandom

                            network_throughput  random  tty33      ttyQRK1  vcs

                            null                rfkill  tty34      ttyS0    vcs1

                            port                root    tty35      ttyS1    vcsa

                            ppp                 rtc     tty36      ttyp0    vcsa1

                            ptmx                rtc0    tty37      ttyp1    zero

                            pts                 shm     tty38      ttyp2

                            • 11. Re: How to program UART serial from Linux on Galileo Gen 2?
                              Intel_Peter

                              This looks weird, everything seems to be as it should, could your run "cat /sys/kernel/debug/gpio" and show me what it outputs?

                              You said that it works fine when you use the onboard image but it starts to fail when you use your own image, right? So it looks like it is an issue on that side, when you built your image, did you use "image full" or "image full galileo"?

                              Also the "-sh: echo: write error: Device or resource busy" messages means they are already exported, you can see then in your last post.

                               

                              Peter.

                              • 12. Re: How to program UART serial from Linux on Galileo Gen 2?
                                tsvetan.filev

                                root@clanton:~# cat /sys/kernel/debug/gpio

                                GPIOs 0-1, platform/sch_gpio.2398, sch_gpio_core:

                                gpio-0   (sysfs               ) out lo

                                gpio-1   (sysfs               ) out lo

                                 

                                GPIOs 2-7, platform/sch_gpio.2398, sch_gpio_resume:

                                gpio-2   (cy8c9540a-int-s3    ) in  hi

                                gpio-3   (sysfs               ) out hi

                                gpio-4   (sysfs               ) out hi

                                gpio-7   (cy8c9540a-a0        ) in  hi

                                 

                                GPIOs 8-15, intel_qrk_gip_gpio:

                                gpio-8   (SPI_CS              ) out hi

                                gpio-10  (SPI_CS              ) out hi

                                gpio-13  (cy8c9540a-int-s0    ) in  hi

                                gpio-14  (sysfs               ) in  hi

                                gpio-15  (sysfs               ) in  hi

                                 

                                GPIOs 16-55, cy8c9540a, can sleep:

                                gpio-16  (sysfs               ) in  hi

                                gpio-17  (sysfs               ) in  lo

                                gpio-18  (sysfs               ) in  hi

                                gpio-19  (sysfs               ) in  lo

                                gpio-20  (sysfs               ) out hi

                                gpio-21  (sysfs               ) out hi

                                gpio-22  (sysfs               ) out hi

                                gpio-23  (sysfs               ) out hi

                                gpio-24  (sysfs               ) in  lo

                                gpio-25  (sysfs               ) in  hi

                                gpio-26  (sysfs               ) in  hi

                                gpio-27  (sysfs               ) in  lo

                                gpio-28  (sysfs               ) in  lo

                                gpio-29  (sysfs               ) out hi

                                gpio-30  (sysfs               ) out hi

                                gpio-31  (sysfs               ) out hi

                                gpio-32  (sysfs               ) in  hi

                                gpio-36  (sysfs               ) out hi

                                gpio-37  (sysfs               ) out hi

                                gpio-38  (sysfs               ) in  hi

                                gpio-39  (sysfs               ) out hi

                                gpio-40  (sysfs               ) out lo

                                gpio-41  (sysfs               ) out lo

                                gpio-42  (sysfs               ) out hi

                                gpio-43  (sysfs               ) out hi

                                gpio-44  (sysfs               ) in  hi

                                gpio-45  (sysfs               ) in  hi

                                gpio-46  (sysfs               ) in  hi

                                gpio-47  (sysfs               ) in  hi

                                gpio-48  (sysfs               ) in  hi

                                gpio-49  (sysfs               ) in  hi

                                gpio-50  (sysfs               ) in  hi

                                gpio-51  (sysfs               ) in  hi

                                gpio-52  (sysfs               ) in  hi

                                gpio-53  (sysfs               ) out hi

                                gpio-54  (sysfs               ) out hi

                                gpio-55  (sysfs               ) out hi

                                 

                                Here is what I did:

                                 

                                - Download Board_Support_Package_Sources_for_Intel_Quark_v0.7.5 (from https://downloadcenter.intel.com/Detail_Desc.aspx?DwnldID=23197)

                                - untar meta-clanton

                                - git config --global user.name "my_name"

                                - git config --global user.email "my_email"

                                - ./setup.sh

                                - source poky/oe-init-build-env yocto_build

                                - modify some files

                                vi meta-clanton_v1.0.1/meta-clanton-distro/recipes-core/images/image-full.bb

                                add:

                                IMAGE_FEATURES += "package-management dev-pkgs"

                                IMAGE_INSTALL += "apache2 modphp"

                                IMAGE_INSTALL += "libmpc autoconf automake binutils binutils-symlinks cpp cpp-symlinks gcc gcc-symlinks g++ g++-symlinks gettext make libstdc++ libstdc++-dev file coreutils"

                                vi meta-clanton_v1.0.1/yocto_build/conf/bblayers.conf

                                add:

                                  /home/ceco/Documents/galileo/meta-clanton_v1.0.1/meta-oe/meta-webserver \

                                 

                                - bitbake image-full-galileo

                                - Copy all files from ./tmp/deploy/images/ on SD card

                                - Boot the image (it boots and works fine) and all file changes are preserved after reboot.

                                 

                                Tsvetan.

                                • 13. Re: How to program UART serial from Linux on Galileo Gen 2?
                                  Intel_Peter

                                  Everything seems OK, I can see that you added some packages and added a few lines in some files, is that all modified? Did you modify any recipe?

                                   

                                  Peter.

                                  • 14. Re: How to program UART serial from Linux on Galileo Gen 2?
                                    tsvetan.filev

                                    Here is my full howto build:

                                     

                                    - Download Board_Support_Package_Sources_for_Intel_Quark_v0.7.5 (from https://downloadcenter.intel.com/Detail_Desc.aspx?DwnldID=23197)

                                    - untar meta-clanton

                                    - git config --global user.name "name"

                                    - git config --global user.email "email"

                                    - ./setup.sh

                                    - source poky/oe-init-build-env yocto_build

                                     

                                    ////////////// Chenge x264_git.bb //////////////

                                     

                                    vi meta-clanton_v1.0.1/meta-oe/meta-oe/recipes-multimedia/x264/x264_git.bb

                                     

                                    #SRCREV = "1cffe9f406cc54f4759fc9eeb85598fb8cae66c7"

                                    SRCREV = "bfed708c5358a2b4ef65923fb0683cefa9184e6f"

                                     

                                    ////////////// Change opencv_2.4.3.bb //////////

                                     

                                    Source code can be found here: http://www.filewatcher.com/_/?q=OpenCV-2.4.3%2Ctar.bz2

                                     

                                    vi meta-clanton_v1.0.1/meta-oe/meta-oe/recipes-support/opencv/opencv_2.4.3.bb

                                     

                                    SRC_URI = "ftp://ftp.igh.cnrs.fr/pub/os/linux/0linux/archives_sources/opencv/OpenCV-2.4.3.tar.bz2 \

                                               file://opencv-fix-pkgconfig-generation.patch \

                                    "

                                     

                                    #SRC_URI = "${SOURCEFORGE_MIRROR}/opencvlibrary/opencv-unix/${PV_VER}/OpenCV-${PV}.tar.bz2 \

                                    #           file://opencv-fix-pkgconfig-generation.patch \

                                    #"

                                     

                                    ///////////// Change dmidecode Makefile ///////////

                                     

                                    vi meta-clanton_v1.0.1/yocto_build/tmp/work/i586-poky-linux-uclibc/dmidecode/2.10-r2/dmidecode-2.10/Makefile

                                     

                                    RM              := rm -f

                                     

                                    # BSD make provides $MACHINE, but GNU make doesn't

                                    MACHINE ?= $(shell uname -m 2>/dev/null)

                                     

                                    # These programs are only useful on x86

                                    PROGRAMS-i386 := biosdecode ownership vpddecode

                                    PROGRAMS-i486 := $(PROGRAMS-i386)

                                    PROGRAMS-i586 := $(PROGRAMS-i386)

                                    PROGRAMS-i686 := $(PROGRAMS-i386)

                                    PROGRAMS-x86_64 := biosdecode ownership vpddecode

                                    PROGRAMS-amd64 := $(PROGRAMS-x86_64)

                                     

                                    PROGRAMS := dmidecode $(PROGRAMS-$(MACHINE))

                                     

                                    all : $(PROGRAMS)

                                     

                                    /////////////// Enable apache2 and modphp ////////////////

                                     

                                    vi meta-clanton_v1.0.1/meta-clanton-distro/recipes-core/images/image-full.bb

                                     

                                    and add

                                     

                                    IMAGE_INSTALL += "apache2 modphp"

                                     

                                     

                                    vi meta-clanton_v1.0.1/yocto_build/conf/bblayers.conf

                                     

                                    and add

                                     

                                      /home/ceco/Documents/galileo/meta-clanton_v1.0.1/meta-oe/meta-webserver \

                                     

                                     

                                    vi meta-clanton_v1.0.1/meta-oe/meta-webserver/recipes-php/modphp/modphp5.inc

                                     

                                    SRC_URI = "http://pkgs.fedoraproject.org/repo/pkgs/php/php-5.4.14.tar.bz2/cfdc044be2c582991a1fe0967898fa38/php-${PV}.tar.bz2 \

                                     

                                    ##### Add gcc support ############

                                     

                                    -  Add packages:

                                     

                                    vi meta-clanton-distro/recipes-core/images/image-full.bb

                                     

                                    IMAGE_ROOTFS_SIZE = "921600"

                                     

                                    IMAGE_FEATURES += "package-management dev-pkgs"

                                     

                                    IMAGE_INSTALL += "libmpc autoconf automake binutils binutils-symlinks cpp cpp-symlinks gcc gcc-symlinks g++ g++-symlinks gettext make libstdc++ libstdc++-dev file coreutils"

                                     

                                    - Change -ps to -p in tar commands in the following files:

                                     

                                    vi poky/meta/classes/staging.bbclass

                                     

                                    # not needed !!! vi poky/meta/classes/kernel.bbclass

                                     

                                    vi poky/meta/classes/package.bbclass

                                     

                                    vi poky/meta/lib/oe/path.py

                                     

                                    - bitbake image-full-galileo (I fixed here and there few things)

                                    - Copy all files from ./tmp/deploy/images/ on SD card

                                    - Boot the image (it boots and works fine) and all file changes are preserved after reboot.

                                     

                                     

                                    NOTE: I did the changes in order to be able to build otherwise I get errors.

                                    1 2 Previous Next