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.

How to configure GPIO for SW1, SW2, SW3 and SW4 on the AM335x



Hi,

I need to check the pin is high when i pressed the SW1. Therefore I'm reading the article to enable GPIO on my AM335x Starter kit http://processors.wiki.ti.com/index.php/Linux_PSP_GPIO_Driver_Guide#User_Space_-_Sysfs_control

root@am335x-evm:/sys/class/gpio# cat /sys/kernel/debug/gpio
GPIOs 0-31, gpio:
gpio-6 (mmc_cd ) in lo
gpio-30 (SW3 ) in lo

GPIOs 32-63, gpio:
gpio-36 (am335x:EVM_SK:usr0 ) out lo
gpio-37 (am335x:EVM_SK:usr1 ) out lo
gpio-38 (am335x:EVM_SK:heartb) out lo
gpio-39 (am335x:EVM_SK:mmc0 ) out lo
gpio-61 (wlan_en ) out lo

GPIOs 64-95, gpio:
gpio-66 (SW2 ) in lo
gpio-67 (SW1 ) in lo
gpio-69 (SW4 ) in lo

GPIOs 96-127, gpio:
gpio-117 (bt_en
) out lo
root@am335x-evm:/sys/class/gpio# echo 67 /sys/class/gpio/export
67 /sys/class/gpio/export
root@am335x-evm:/sys/class/gpio# ls -l /sys/class/gpio/
--w------- 1 root root 4096 Jun 27 22:13 export
lrwxrwxrwx 1 root root 0 Jun 27 22:13 gpiochip0 -> ../../devices/virtual/gpio/gpiochip0
lrwxrwxrwx 1 root root 0 Jun 27 22:13 gpiochip32 -> ../../devices/virtual/gpio/gpiochip32
lrwxrwxrwx 1 root root 0 Jun 27 22:13 gpiochip64 -> ../../devices/virtual/gpio/gpiochip64
lrwxrwxrwx 1 root root 0 Jun 27 22:13 gpiochip96 -> ../../devices/virtual/gpio/gpiochip96
--w------- 1 root root 4096 Jun 27 22:13 unexport
root@am335x-evm:/sys/class/gpio#

  • Hi Biser,

    Sorry, apparently my last sentences are not in there after I insert the link. My question is have I have done wrong or missed out?My understanding is when I run "echo 67 /sys/class/gpio/export", isn't suppose the Sysfs entries will create for the GPIO67 SW1? Try to run the change the GPIO pin direction to in/out, I couldn't.

    root@am335x-evm:/sys/class/gpio# cat "out" /sys/class/gpio/gpio67/direction
    cat: can't open 'out': No such file or directory
    cat: can't open '/sys/class/gpio/gpio67/direction': No such file or directory
    root@am335x-evm:/sys/class/gpio#
  • See this wiki for correct usage: http://processors.wiki.ti.com/index.php/Linux_PSP_GPIO_Driver_Guide#User_Space_-_Sysfs_control

    What Linux version are you using? Are you sure these pins are defined as GPIO and not taken by another driver?

  • Hi Biser,

    ah! you are right. When i run the commands
    root@am335x-evm:/sys/class/gpio# mount -t debugfs debugfs /sys/kernel/debug
    mount: mounting debugfs on /sys/kernel/debug failed: Device or resource busy
    root@am335x-evm:/sys/class/gpio#

    I'm using the starter kit, which it comes with the Linux Development Kit. Once I have insert the Linux SDK SD card and boot up the board, I have the Matrix App Launcher v2 p1 shows on the screen. I presume, the Matrix App Launcher has some process uses some driver on these pins as GPIO? Do you know which section to ask about the Matrix App Launcher v2 p1 ? Is there any idea how or what process should I kill/stop so that I can access these GPIO pin?


    Thanks.

    Regards,
    jenny
  • I have asked the SW experts to help on this.
  • Hi Biser,

    Thank you so much! Looking forward the SW experts's response.


    Thanks.

    Regards,
    jenny
  • Hi Jenny,

    You don't need to kill any process.

    Just note, inside am335x_evmsk.dts, that the GPIO you're trying to access is used within the gpio_buttons: gpio_buttons@0 dts node.
    In order to verify its functionality you should comment the corresponding switch@x child node, recompile your kernel & verify the funcitonality of the GPIO.

    Best Regards,
    Yordan
  • Hi Yordan,

    Sorry to ask the noob question. Is that mean I can't change anything from the userspace? Basically, I need to programming detect the the switch is pressed (voltage change from low to hight and vise versa) using the GPIO protocol. As I have googled, the way is export the GPIO pin and checked on the /sys/class/gpio/gpio<GPIO pin>/value. Therefore you means that I need to recompile the kernel in order to do that?

    Before I recompile the kernel, I need to comment out as following?
    gpio_buttons: gpio_buttons@0 {
    compatible = "gpio-keys";
    #address-cells = <1>;
    #size-cells = <0>;

    # switch@1 {
    # label = "button0";
    # linux,code = <0x100>;
    # gpios = <&gpio2 3 GPIO_ACTIVE_HIGH>;
    # };

    # switch@2 {
    # label = "button1";
    # linux,code = <0x101>;
    # gpios = <&gpio2 2 GPIO_ACTIVE_HIGH>;
    # };

    # switch@3 {
    # label = "button2";
    # linux,code = <0x102>;
    # gpios = <&gpio0 30 GPIO_ACTIVE_HIGH>;
    # gpio-key,wakeup;
    # };

    # switch@4 {
    # label = "button3";
    # linux,code = <0x103>;
    # gpios = <&gpio2 5 GPIO_ACTIVE_HIGH>;
    # };
    };


    By the way, can I ask where is the GPIO button?

    Thanks.

    Regards,
    jenny

  • Hi, 

    Sorry for the delayed response.

    Jenny Liew said:
    Is that mean I can't change anything from the userspace?

    You can toggle gpios from user space, just not the one you're using currently (gpio67), because this pin is used in another process (most likely within the matrix-gui).

    Yes you should comment the above listed switch dts nodes & rebuild only the dtb

    I verified this, and it works on AM335x Starter Kit: 
      export ARCH=arm

      export PATH=$PATH:<path to ti-processor-sdk-linux-am335x-evm-01.00.00.00>/linux-devkit/sysroots/i686-arago-linux/usr/bin/

      export CROSS_COMPILE=arm-linux-gnueabihf-

      make singlecore-omap2plus_defconfig

      make am335x-evmsk.dtb 

    Then copy the am335x-evmsk.dtb in the sd card, in /media/rootfs/boot and rename it to devicetree-zImage-am335x-evmsk.dtb and boot your board. 

    I tried it with gpio 30 used in switch@3. Before commenting the switch@3 device tree node I was getting the device or resource busy error. 

    After modifying the dts & rebuilding it, the result was:

    root@am335x-evm:/sys/class/gpio# echo 30 > export
    root@am335x-evm:/sys/class/gpio# cd gpio30
    root@am335x-evm:/sys/class/gpio/gpio30# ls
    active_low direction edge power subsystem uevent value
    root@am335x-evm:/sys/class/gpio/gpio30# echo in > direction

    without pressing SW3 on the Starter kit the gpio 30 value was: 

    root@am335x-evm:/sys/class/gpio/gpio30# cat value
    0

    While holding SW3 on the starterkit pressed, I execute cat value & result is: 

    root@am335x-evm:/sys/class/gpio/gpio30# cat value
    1

    I am able to toggle gpio30 value, by pressing SW3 on the AM335x Starter Kit. 

    Best Regards, 

    Yordan

  • awesome! thanks yordon!

    regards,
    jenny