• Join
  • Sign In with my.TI Login
Texas Instruments
  • Products
  • Applications
  • Tools & Software
  • Support & Community
  • Sample & Buy
  • About TI
Sample & Purchase Cart Sample & Purchase Cart
  • Search
  • Advanced
TI E2E™ Community
  • Support Forums
  • Blogs
  • Groups
  • Videos
  • 简体中文
  • More ...
TI Home » TI E2E Community » Support Forums » Embedded Software » Linux » Linux forum » GPIO quarries on OMAPL138 and Linux-2.6.33
Share
Linux
  • Forum
Options
  • Subscribe via RSS

Forums

GPIO quarries on OMAPL138 and Linux-2.6.33

This question is not answered
Ram ap
Posted by Ram ap
on Jan 05 2012 01:35 AM
Prodigy90 points

Hi,

I have some quarries on GPIO for OMAPL138 LINUX-2.6.33.    

1.) Please provide the user usage information of GPIO driver, on  Linux-2.6.33.

2.) How to access GPIO pin on user side like gpio_request();  gpio_request_input(); etc

3.) what are the user API for accessing the gpio. for linx application.

4.) And i checked the /sys/class/gpio is present .

Thanks in adv

      Ram

GPIO_OMAPL138
Report Abuse
  • Reply
You have posted to a forum that requires a moderator to approve posts before they are publicly available.
All Replies
  • Anil
    Posted by Anil
    on Jan 05 2012 01:46 AM
    Expert6655 points

    Hi Ram,

    1.) Please provide the user usage information of GPIO driver, on  Linux-2.6.33.

    Go through kernel documentation "Documentation/gpio.txt" for more details

    2.) How to access GPIO pin on user side like gpio_request();  gpio_request_input(); etc

    http://processors.wiki.ti.com/index.php/Sitara_GPIO_Driver_User_Guide#Driver_Usage

    Regards

    AnilKumar

    GPIO PSP
    Report Abuse
    • Reply
    You have posted to a forum that requires a moderator to approve posts before they are publicly available.
  • Norman Wong
    Posted by Norman Wong
    on Jan 06 2012 09:43 AM
    Guru14870 points

    Noticed in your other forum threads that you have some confustion between the kernel and user space interfaces to GPIOS. User space access to the sysfs GPIO driver is all through files. Here's an example to toggling GPIO 11 in a Linux console or terminal:

    cd /sys/class/gpio/
    echo 11 > export
    cd gpio11
    echo out > direction
    echo 0 > value
    echo 1 > value
    echo 0 > value

    The equivalent code in C is:

    #include <fcntl.h>       /* For open() */

    #include <unistd.h>      /* For read(), close() */


    int main(int argc, char *argv[])
    {
     int fd;
     fd = open("/sys/class/gpio/export", O_WRONLY);
     write(fd, "11", 3); // Include null!
     close(fd);

     fd = open("/sys/class/gpio/gpio11/direction", O_WRONLY);
     write(fd, "out", 4);
     close(fd);

     fd = open("/sys/class/gpio/gpio11/value", O_WRONLY);
     write(fd, "0", 2);
     write(fd, "1", 2);
     write(fd, "0", 2);
     close(fd);

     return(0);
    }

    Please take note that you must check that the GPIO line you want to use is pinmux'ed to an external pin. That involves looking at the kernel code and possibly modifiying the kernel.

    Report Abuse
    • Reply
    You have posted to a forum that requires a moderator to approve posts before they are publicly available.
  • Ram ap
    Posted by Ram ap
    on Jan 16 2012 05:52 AM
    Prodigy90 points

    Hi,

    Thanks for your above example to toggle gpio....

    GPIO_OMAPL138
    Report Abuse
    • Reply
    You have posted to a forum that requires a moderator to approve posts before they are publicly available.
  • he he1
    Posted by he he1
    on May 08 2012 02:38 AM
    Prodigy200 points

    Hi, if I want set  GP2[3] to out direction .And set it to 1 or 0, how can I use the function write and open?\

     fd = open("/sys/class/gpio/export", O_WRONLY);
     write(fd, "??", ??); // Include null!
     close(fd);

     fd = open("/sys/class/gpio/gpio11/direction", O_WRONLY);
     write(fd, "??", ??);
     close(fd);

    fd = open("/sys/class/gpio/gpio11/value", O_WRONLY);
     write(fd, "0", ??);

    Report Abuse
    • Reply
    You have posted to a forum that requires a moderator to approve posts before they are publicly available.
  • Anil
    Posted by Anil
    on May 08 2012 03:21 AM
    Expert6655 points

    Hi,

    write(fd, buf, len);

    fd - file pointer

    buf - contains characters ex: "1" or "0" or "in" or "out"

    len - length of the buffer ex: 2 or 2 or 3 or 4.

    Regards

    AnilKumar

    Please mark this Forum post as answered via the Verify Answer button below if it helps answer your question.  Thanks!

    GPIO PSP
    Report Abuse
    • Reply
    You have posted to a forum that requires a moderator to approve posts before they are publicly available.
  • he he1
    Posted by he he1
    on May 08 2012 04:04 AM
    Prodigy200 points

    Hi,  

    cd /sys/class/gpio/
    echo 11 > export
    cd gpio11
    echo out > direction
    echo 0 > value
    echo 1 > value
    echo 0 > value

    The equivalent code in C is:

    #include <fcntl.h>       /* For open() */

    #include <unistd.h>      /* For read(), close() */


    int main(int argc, char *argv[])
    {
     int fd;
     fd = open("/sys/class/gpio/export", O_WRONLY);
     write(fd, "11", 3); // Include null!

    what's the meaning of  write(fd, "11", 3); // Include null!

    Regards

    He

    Report Abuse
    • Reply
    You have posted to a forum that requires a moderator to approve posts before they are publicly available.
  • Anil
    Posted by Anil
    on May 08 2012 04:48 AM
    Expert6655 points

    Hi,

    what's the meaning of  write(fd, "11", 3); // Include null!

    This means writing 11 into export file.

    Regards

    AnilKumar

    Please mark this Forum post as answered via the Verify Answer button below if it helps answer your question.  Thanks!

    GPIO PSP
    Report Abuse
    • Reply
    You have posted to a forum that requires a moderator to approve posts before they are publicly available.
  • he he1
    Posted by he he1
    on May 08 2012 07:01 AM
    Prodigy200 points

    Hi AnilKumar

    I don't know what the "11" mean.  if i want control GP1[1],  in the OMAPL138 datasheet:

                                         GPIO Register Bits and Banks  Associated With GPIO  Signals

    GPIO Pin Number      GPIO Signal Name        Bank Number    Control Registers     Register Bit     Register Field

                   1                              GP0[0]                                    0                register_name01              Bit 0              GP0P0

                   2                              GP0[1]                                    0                register_name01              Bit 1              GP0P1

                   ……                   ……                   ……

                   18                            GP1[1]                                    1                register_name01              Bit 17              GP1P1

     Can  I use it like this  write(fd,“18",3) ?    right?  

    int fd;
    fd = open("/sys/class/gpio/export", O_WRONLY);
    write(fd, "18", 3); // Include null!
    close(fd);

    fd = open("/sys/class/gpio/gpio18/direction", O_WRONLY);
    write(fd, "out", 4);
    close(fd);

    fd = open("/sys/class/gpio/gpio18/value", O_WRONLY);
    while(1){
    write(fd, "0", 2);
    sleep(3);
    write(fd, "1", 2);
    sleep(3);
    }
    close(fd);

    When  I detect the pin GP1[1],  I can't get the value I set to it .  Why?

    Regards

    He

    Report Abuse
    • Reply
    You have posted to a forum that requires a moderator to approve posts before they are publicly available.
  • Anil
    Posted by Anil
    on May 08 2012 07:52 AM
    Expert6655 points

    Hi He,

    The way you are using are correct,

    Make sure that pinmux settings are proper, refer OMAPL138 GPIO user guide for more details

    Below post will help you on GPIO functionality.

    http://e2e.ti.com/support/dsp/davinci_digital_media_processors/f/716/p/182160/657204.aspx#657204

    Regards

    AnilKumar

    Please mark this Forum post as answered via the Verify Answer button below if it helps answer your question.  Thanks!

    GPIO PSP
    Report Abuse
    • Reply
    You have posted to a forum that requires a moderator to approve posts before they are publicly available.
  • he he1
    Posted by he he1
    on May 08 2012 22:52 PM
    Prodigy200 points

    Hi,AnilKuma

    Thank you for your quick reply. But I still have problem to find the pinmux setting fuction.

    My PSP is: OMAP_L138_arm_1_00_00_08\DaVinci-PSP-SDK-03.20.00.08\ 

    I tried to add below in /arch/arm/mach-davinci/include/mach/mux.h

    /* GPIO function */

    DA850_GPIO2_6,
    DA850_GPIO2_8,

    DA850_GPIO1_1,//my add

    and add in /arch/arm/mach-davinci/da850.c  in static const struct mux_config da850_pins[] = {}   fuction

    /* GPIO function */
    MUX_CFG(DA850, GPIO2_6, 6, 4, 15, 8, false)
    MUX_CFG(DA850, GPIO2_8, 5, 28, 15, 8, false)

    MUX_CFG(DA850, GPIO1_1, 4, 24, 15, 8, false)  //my add

    after rebuilt the kernel When  I detect the pin GP1[1],  I still can't get the value I set to it .  Is I wrong?   Is there any other place I must modify?

    Regards

    He

    Report Abuse
    • Reply
    You have posted to a forum that requires a moderator to approve posts before they are publicly available.
  • he he1
    Posted by he he1
    on May 09 2012 01:52 AM
    Prodigy200 points

    Hi Ram

    Do you solve you problem? I have the same problems with you ?  

    Are you success setting pinmux?  How to do it.

    Below is my problems.

    Hi Norman
    I have some trobles in pinmux settings.
    My PSP is: OMAP_L138_arm_1_00_00_08\DaVinci-PSP-SDK-03.20.00.08\
    I tried to add below in /arch/arm/mach-davinci/include/mach/mux.h
    /* GPIO function */
    DA850_GPIO2_6,
    DA850_GPIO2_8,
    DA850_GPIO1_1,//my add

    and add in /arch/arm/mach-davinci/da850.c in static const struct mux_config da850_pins[] = {} fuction
    /* GPIO function */
    MUX_CFG(DA850, GPIO2_6, 6, 4, 15, 8, false)
    MUX_CFG(DA850, GPIO2_8, 5, 28, 15, 8, false)
    MUX_CFG(DA850, GPIO1_1, 4, 24, 15, 8, false) //my add
    after rebuilt the kernel When I detect the pin GP1[1], I still can't get the value I set to it . Is I wrong? Is there any other place I must modify?

    Regards
    He

    Report Abuse
    • Reply
    You have posted to a forum that requires a moderator to approve posts before they are publicly available.
  • Anil
    Posted by Anil
    on May 09 2012 04:12 AM
    Expert6655 points

    Hi He,

    Make sure that you have written the correct value to corresponding register

    http://e2e.ti.com/support/embedded/linux/f/354/p/167148/609581.aspx#609581

    Regards

    AnilKumar

    Please mark this Forum post as answered via the Verify Answer button below if it helps answer your question.  Thanks!

    GPIO PSP
    Report Abuse
    • Reply
    You have posted to a forum that requires a moderator to approve posts before they are publicly available.
  • he he1
    Posted by he he1
    on May 09 2012 05:34 AM
    Prodigy200 points

    Hi Anil

    I do it like this:

    # echo 18 > /sys/class/gpio/export
    ~# ls  /sys/class/gpio/gpio18
    active_low  edge        subsystem   value
    direction   power       uevent
    :~# echo out > /sys/class/gpio/gpio18/direction
    ~# echo 0 > /sys/class/gpio/gpio18/value
    ~# cat /sys/class/gpio/gpio18/value
    1
    ~# echo 1 > /sys/class/gpio/gpio18/value
    ~# cat /sys/class/gpio/gpio18/value
    1

    ~# echo 0 > /sys/class/gpio/gpio18/value
    ~# cat /sys/class/gpio/gpio18/value
    1

    why the value can not be change?  when I use "echo 29 > /sys/class/gpio/export "  , the export29   value can changed as I set.

    The  file 'value' is R/W.

    Report Abuse
    • Reply
    You have posted to a forum that requires a moderator to approve posts before they are publicly available.
  • yaliu_2000
    Posted by yaliu_2000
    on May 09 2012 08:24 AM
    Intellectual805 points

    Did you call "davinci_cfg_reg(gpio_pin)" to set pinmux for gpio18 besides adding entries in mux.h and da850.c?

    BTW, gpio1[1] is gpio17 instead of gpio18.

    Regards,

    Yan

    Report Abuse
    • Reply
    You have posted to a forum that requires a moderator to approve posts before they are publicly available.
  • Anil
    Posted by Anil
    on May 09 2012 08:26 AM
    Expert6655 points

    Hi He,

    Make sure that you are configuring the same GPIO pin.

    You are trying to add pinmux for GPIO1_1 (18th gpio pin) means gpio 17 in your previous post.

    Here you are changing the value of gpio 18 (19th pin), use the same GPIO at both the places

    Can you check these

    echo 17 > /sys/class/gpio/export

    echo "out" > /sys/class/gpio/gpio17/direction

    echo 0 > /sys/class/gpio/gpio17/value

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

    Note: Can you check the status of pinmux register after kernel boots-up

    Regards

    AnilKumar

    Please mark this Forum post as answered via the Verify Answer button below if it helps answer your question.  Thanks!

    GPIO PSP
    Report Abuse
    • Reply
    You have posted to a forum that requires a moderator to approve posts before they are publicly available.
12
TI E2E™ Community
  • Support Forums
  • Blogs
  • Videos
  • Groups
  • Site Support & Feedback
  • Settings
TI E2E™ Community Groups
  • TI University Program
  • Make the Switch
  • Microcontroller Projects
  • Motor Drive & Control
Other Communities
  • Deyisupport
  • Designsomething.org
  • beagleboard.org
  • TI on Element 14
  • TI on TechXchangeSM
Other Technical & Support Resources
  • WEBENCH® Design Center
  • Product Information Centers
  • Technical Documents
  • TI Design Network
  • TI Technical Articles
  • TI Training

All content and materials on this site are provided "as is". TI and its respective suppliers and providers of content make no representations about the suitability of these materials for any purpose and disclaim all warranties and conditions with regard to these materials, including but not limited to all implied warranties and conditions of merchantability, fitness for a particular purpose, title and non-infringement of any third party intellectual property right. TI and its respective suppliers and providers of content make no representations about the suitability of these materials for any purpose and disclaim all warranties and conditions with respect to these materials. No license, either express or implied, by estoppel or otherwise, is granted by TI. Use of the information on this site may require a license from a third party, or a license from TI.

Content on this site may contain or be subject to specific guidelines or limitations on use. All postings and use of the content on this site are subject to the Terms of Use of the site; third parties using this content agree to abide by any limitations or guidelines and to comply with the Terms of Use of this site. TI, its suppliers and providers of content reserve the right to make corrections, deletions, modifications, enhancements, improvements and other changes to the content and materials, its products, programs and services at any time or to move or discontinue any content, products, programs, or services without notice.

Follow Us Texas Instruments on Facebook Texas Instruments on Twitter Texas Instruments on LinkedIn Texas Instruments on Google+
TI Worldwide | Contact Us | my.TI Login | Site Map | Corporate Citizenship | mobile m.ti.com (Mobile Version)

TI is a global semiconductor design and manufacturing company. Innovate with 100,000+ analog ICs and
embedded processors, along with software, tools and the industry’s largest sales/support staff.

© Copyright 1995-2013 Texas Instruments Incorporated. All rights reserved.
Trademarks | Privacy Policy | Terms of Use