Using Braswell GPIO, i2c and Uart pins.

Discussion in 'UDOO X86' started by Quack, Aug 16, 2020.

  1. Quack

    Quack UDOOer

    Joined:
    Jun 27, 2020
    Messages:
    15
    Likes Received:
    4
    Searching for information on using the GPIO has been fairly daunting. The user docs refer the the https://github.com/torvalds/linux/blob/master/drivers/pinctrl/intel/pinctrl-cherryview.c Cherryview driver which refers to the code and the use of sysfs interface https://www.kernel.org/doc/Documentation/gpio/sysfs.txt, which has been depreciated in favor of libgpiod, https://git.kernel.org/pub/scm/libs/libgpiod/libgpiod.git/. I had trouble getting the sysfs commands to work until I found the forum thread which indicated that sudo doesn't work right and the commands should be in the format: echo xxx | sudo tee /sys/class/gpio/export.

    The libgpiod brings several commands for CLI manipulation:gpiodetect, gpiofind, gpioget, gpioinfo, gpiomon and gpioset. It requires sudo and a knowledge of the new structure. There are 4 "gpio" chips which control the gpio pins as well as the Uart, and i2c ports.
     

    Attached Files:

    Maximo likes this.
  2. Quack

    Quack UDOOer

    Joined:
    Jun 27, 2020
    Messages:
    15
    Likes Received:
    4
    Libgpiod is available from several distros. C++ and python bindings are available and I have submitted a pull request to the Adafruit_Blinka for Circuit Python support. It's based on the libgpiod library.

    A couple notes about the organization of the pin file. The pin # refers to the diagram and table in the docshttps://www.udoo.org/docs-x86II/Introduction/Introduction.html Hardware & Accessories / GPIOs / Braswell GPIOs / Kernel 4.15 or higher. It's cross-referenced to the libgpiod chip and line #s, connector #s/pin #s in the Hardware Manual and some of the labels/ names I identified. Also look at the voltages for the pins! As the Hardware Manual points out, pins 24-29 (LPC_xxxxx) are 3.3 V, but pin 30 (LPC_SERIQ, GPIO307) is 1.8 V. All of the rest are 1.8 V. You can verify this using a voltmeter. Use either the sysfs above or sudo gpioset chip# line#=1or0. E.g. sudo gpioset 3 79=0 turns off pin 30 sudo gpioset 3 79=1 turns it on. You will need to use level shifting to interface the 1.8 V pins to 3.3 or 5 V logic.

    I2C ports. You will need to use an i2c compatable level shifter (not all are!), import smbus under python3 or use the Adafruit_Blinka busio. Note that there are conflicting labels assigned to the ports. I2C1 is listed by ls /dev/i2c* as /dev/i2c-0 and I2C2 as /dev/ic2-1. Using sudo i2c detect -l will list all the i2c devices. I2C1 and 2 are listed as i2c-0 and -1 and are Synopsis DesignWare I2C adapters. If you attach an i2c device you can detect it using sudo i2cdetect -r <I2CBUS# > e.g. sudo i2cdetect -r 0 will give the i2c address of your devices attached to the I2C1 port.

    Uarts-- are supposed to be usable with pyserial. I haven't verified it yet.
     
  3. Quack

    Quack UDOOer

    Joined:
    Jun 27, 2020
    Messages:
    15
    Likes Received:
    4
    I have verified that pySerial does work. As the documentation states use ttyS4 for Uart1. Under linux (Mint) you have to disable the "Virtual Uart" in the Bios to have /dev/ttyS4 available.
     
  4. zach dwiel

    zach dwiel UDOOer

    Joined:
    Oct 24, 2020
    Messages:
    1
    Likes Received:
    0
    Thank you for this tip. I also had this same problem where UARTS seemed enabled in the bios yet, /dev/ttyS4 and /dev/ttyS5 were both still missing. The Udoo documentation page called Braswell Pinout mentions that HSUART needs to be enabled in BIOS and where to do that, but it doesn't tell you that the "Virtual Uart" needs to be disabled as you pointed out. Making this change got /dev/ttyS4 and /dev/ttyS5 working for me on Ubuntu 18.04.
     
  5. waltervl

    waltervl UDOOer

    Joined:
    Dec 12, 2015
    Messages:
    2,295
    Likes Received:
    565
    @evaloverde please update the documentation
     
  6. Quack

    Quack UDOOer

    Joined:
    Jun 27, 2020
    Messages:
    15
    Likes Received:
    4
    Updated/corrected table of gpio/uart/I2c ports
     

    Attached Files:

Share This Page