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.

Enable GPIO pin, AM1808

Other Parts Discussed in Thread: AM1808

Hello,

I'm using Linux 03.20.00.14 on SBC8018 development board (AM1808) and I need to enable one GPIO (44th) pin.I would like to use "uP_SPI1_ENAN" pin (11th pin on J42 expasion board) as GPIO. I added this code for multiplexing, and I hope that this is OK:

MUX_CFG(DA850, GPIO2_12, 5, 12, 15, 8, false);    // This is 44th pin when I use it from userspace?

Also, I selected in menuconfig:

Device drivers --->

-*- GPIO support --->

[*] /sys/class/gpio/... (sysfs interface)

Is this enough?

I would like to read that GPIO pin from my application. How to do it?

Best regards,

Vladimir

  • Hi Vladimir 

    Go through below link:

    http://processors.wiki.ti.com/index.php/GPIO_Driver_Guide

    which helps you in read/write GPIO.

    Thanks 

    Manish Badarkhe

  • Manish thanks for answer.


    Yes, I have seen that guide and I have succeeded to execute the following lines:

    • Device Drivers ---> GPIO Support ---> /sys/class/gpio/... (sysfs interface)
    • echo 44 > /sys/class/gpio/export (I need to read/write 44th GPIO pin)
    • echo "out" > /sys/class/gpio/gpio44/direction

    But I can't change the value of the GPIO pin with this command:
    echo 1 > /sys/class/gpio/gpio30/value
    or
    echo 0 > /sys/class/gpio/gpio30/value

    The value remains on a high level, but I don't know why. Pin multiplexing is OK:
    MUX_CFG(DA850, GPIO2_12, 5, 12, 15, 8, false);

    Do you have any advice?


    Regards,
    Vladimir
  • Hi Vladimir,

    Have you referred the section "Note" from below link?

    http://processors.wiki.ti.com/index.php/GPIO_Driver_Guide#User_Space_-_Sysfs_control

    If any Linux driver uses the particular gpio pin then sysfs cant take the control of it from user space.

  • Rajasekaran thanks for the answer.


    Yes, I saw that note. I have enabled SPI1 port (SPI1_MISO, SPI1_MOSI, SPI1_CLK and SPI1_CS pins, but not SPI1_ENA) on my board. Since I didn't enable SPI1_ENA signal, I want to use GPIO2[12] on that pin (11th pin on my extension board). In my da850.c file I don't have muxed SPI1_ENA signal: MUX_CFG(DA850, SPI1_ENA, 5, 12, 15, 1, false).

    I need to mux my GPIO2[12]? I have done that like this: MUX_CFG(DA850, GPIO2_12, 5, 12, 15, 8, false), is this OK? I didn't add anything in board_da850_evm.c file. Is that wrong? When I use this GPIO pin from user space, do I need to export 44th pin (2nd bank * 16 pins per bank + 12th pin = 44th pin) - echo 44 > /sys/class/gpio/export?

    Regards,

    Vladimir

  • Guys,

    I have succeeded to enable and to toggle GPIO2[12] pin on my J42 extension borad. I have followed this link http://e2e.ti.com/support/embedded/linux/f/354/t/157994.aspx (Posted by Norman Wong on Feb 17 2012 22:02 PM). I didn't add "#define" in board_da850_evm.c file. Now I can change the value of the GPIO pin as well as direction. How can I read that GPIO pin from my application? Any example?

    Regards,

    Vladimir

  • Hi,

    The below code snippet may help you to solve your issue. 


    Export the GPIO:
    int fd;
    char buf[MAX_BUF];
    int gpio = XX;
    fd = open("/sys/class/gpio/export", O_WRONLY);
    sprintf(buf, "%d", gpio);
    write(fd, buf, strlen(buf));
    close(fd);

    Set the direction in the GPIO folder just created:
    sprintf(buf, "/sys/class/gpio/gpio%d/direction", gpio);
    fd = open(buf, O_WRONLY);
    // Set out direction
    write(fd, "out", 3);
    // Set in direction
    write(fd, "in", 2);
    close(fd);

    In case of out direction set the value of GPIO:
    sprintf(buf, "/sys/class/gpio/gpio%d/value", gpio);
    fd = open(buf, O_WRONLY);
    // Set GPIO high status
    write(fd, "1", 1);
    // Set GPIO low status
    write(fd, "0", 1);
    close(fd);

    In case of in direction get the current value of GPIO:
    char value;
    sprintf(buf, "/sys/class/gpio/gpio%d/value", gpio);
    fd = open(buf, O_RDONLY);
    read(fd, &value, 1);
    if(value == '0')
    {
    // Current GPIO status low
    }
    else
    {
    // Current GPIO status high
    }
    close(fd);

    Once finished free (unexport) the GPIO:
    fd = open("/sys/class/gpio/unexport", O_WRONLY);
    sprintf(buf, "%d", gpio);
    write(fd, buf, strlen(buf));
    close(fd);

  • Or

    Please try writing the shell script for the usage.

    Read:

    cat /sys/class/gpio/gpio0/value

    Write:

    echo 1 > /sys/class/gpio/gpio4/value

    Example Script:

    #!/bin/sh

    echo "4" > /sys/class/gpio/export
    echo "out" > /sys/class/gpio/gpio4/direction

    while true
    do
    echo 1 > /sys/class/gpio/gpio4/value
    echo 0 > /sys/class/gpio/gpio4/value
    done