Search

Technical Discussion Group Forum

This forum is provided for user discussion. While Beacon EmbeddedWorks support staff and engineers participate, Beacon EmbeddedWorks does not guarantee the accuracy of all information within in the Technical Discussion Group (TDG).

The "Articles" forums provide brief Articles written by Beacon EmbeddedWorks engineers that address the most frequently asked technical questions.

To receive email notifications when updates are posted for a Beacon EmbeddedWorks product download, please subscribe to the TDG Forum of interest.

TDG Forum

PrevPrev Go to previous topic
NextNext Go to next topic
Last Post 23 Apr 2014 03:35 PM by  bradb
Simple GPIO application for Linux
 6 Replies
Sort:
You are not authorized to post a reply.
Author Messages
jd1234
New Member
New Member
Posts:6


--
22 Apr 2014 04:28 PM

    Hi,

     I am looking for a very simple application code (C/C++) demostrating GPIO configuration and usage for Linux. It seems like all examples are for Linux command lines or WinCE. I have searched to LogicPD and TI e2e forums.

     Thanks.

     

    bradb
    Basic Member
    Basic Member
    Posts:203


    --
    23 Apr 2014 11:09 AM

    In addition to the information provided in the (AN 527 Selecting and Using GPIO Signals on DM3730 - AM3703 SOMs) application note Logic PD offers two options for accessing GPIO signals within a Linux application:

    1) AN 582 application note will describe how to set, clean, read the state of an IO pin as well as allow you to use an IO pin as an interrupt.   Note: You may need to log into the Logic PD support site before you can access the link provided.

    AN 582 Introduction to Direct Hardware Access with Linux Device Drivers

    2) An update to the helloworld application using system commands to set and clear a GPIO signals is now available for download  in the link below.

    helloworld-1.1_updated.zip

     

    jd1234
    New Member
    New Member
    Posts:6


    --
    23 Apr 2014 11:52 AM

    Thanks.

     Let me try it out and report back.

     

    jd1234
    New Member
    New Member
    Posts:6


    --
    23 Apr 2014 02:47 PM

    Followed the step, and getting

     

    DM-37x# hello    
    hello world
    Toggle LED2 on the DM37x T+W Development Kit (GPIO_179)
    [  563.317199] gpio_request: gpio-179 (sysfs) status -16
    [  563.322814] export_store: status -16
    sh: line 1: /sys/class/gpio/gpio179/direction: No such file or directory
    sh: line 1: /sys/class/gpio/gpio179/value: No such file or directory
    sh: line 1: /sys/class/gpio/gpio179/value: No such file or directory

     I am not sure if an "export" action is required prior to using this pin.


     

    bradb
    Basic Member
    Basic Member
    Posts:203


    --
    23 Apr 2014 03:08 PM
    Great, you are most of the way there. Could you have skipped step #4?

    Yes, you must execute this "export" command successfully for the system commands to work.

    The readme.txt file included with the updated helloworld application states in step #4 that you must update a kernel file.

    To get access to the kernel file you can do the following.

    Linux_3.0\REL-ltib-DM3730-2.4-2\$ ./ltib -p kernel -m prep
    Linux_3.0\REL-ltib-DM3730-2.4-2\$ cd rpm/BUILD/linux/arch/arm/mach-omap2
    Linux_3.0\REL-ltib-DM3730-2.4-2\$ vi Board-omap3logic.c

    Step #4. Update arch\arm\mach-omap2\Board-omap3logic.c, otherwise there will be a conflict with GPIO_179
    // #define GPIO_LED2_TORPEDO 179
    #define GPIO_LED2_TORPEDO 111

    Once you have updated Board-omap3logic.c, rebuild the kernel.

    Linux_3.0\REL-ltib-DM3730-2.4-2\$  ./ltib -p kernel -m scbuild && ./ltib -p kernel -m scdeploy

    You can then get the updated kernel from:
    REL-ltib-DM3730-2.4-2/rootfs/boot
    jd1234
    New Member
    New Member
    Posts:6


    --
    23 Apr 2014 03:26 PM
    Yes, that was it. Now it is working perferctly fine.

    I noticed in the source file that it is basically sysfs commands used with wrapper "system". I wonder if I can build upon this application and execute it in user-space without rebuilding the kernel.

    Thanks again.
    bradb
    Basic Member
    Basic Member
    Posts:203


    --
    23 Apr 2014 03:35 PM
    Great. I am glad to hear you got it working. If you chose a different GPIO that is not already reserved by the kernel, then yes.

    For example, if you had not updated the kernel you could have chosen GPIO_111 but that would have required a resistor removal and population on the baseboard. More on that is covered in the AN 527 Selecting and Using GPIO Signals on DM3730 - AM3703 SOMs Application Note. However, I am sure there are other GPIOs that would not require either moving a resistor or updating the kernel. I chose GPIO_179 (LED2) because it seemed to be mostly available and easy to see the change of state.

    You are not authorized to post a reply.