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.

AM335x Starter Kit LED GPIO Trouble

Hello,

I'm trying to get my control in the user space over the LEDs of my AM335x starter kit. I'm running into trouble when it comes to using the command:

echo 39 > /sys/class/gpio/export

The terminal gives me the response

-sh: echo: write error: Device or resource busy

I'm not sure what I'm doing wrong. I'm using kernel version 3.2 and SDK 6. In my make menuconfig my GPIO support is enabled as is the sysfs interface. If I'm reading the starter kit schematic right, the LEDs are tied to GPIO #s 36-39. I just don't understand how to get to the root of why the "resource is busy".

Any suggestions are appreciated.

  • Tim,

    If you take a look at the board-am335xevm.c file in your kernel source tree (arch/arm/mach-omap2), around line 1940, you'll see that these GPIOs are being allocated. If you want to use one of them, you'll need to "unallocate" it in the board file. Or, you can simply use one of the "usr" leds directly with the sysfs interface.

  • Hi Ron,

    If I wanted to use the sysfs interface to control one of the usr LEDs, how would I go about doing that? If I need to use the export command, what are the arguments that need to be passed?

  • Hi Tim,

    As Ron said, if you don't want to usr LEDs then you have to remove all those code stuff from the board file to access this GPIO 39 from user space.

    That's why it saying "busy" since it is accessing "usr leds"

    Could you attach your board file here.

  • Hi Titus,

    As you probably guessed from what I'm trying to do I'm fairly new to this environment.

    I've commented out the 2 usr leds in the file (attached to this post) and rebuilt the kernel using the following commands:

    make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- uImage

    After it was done, I have a valid uImage. I copied it to my /tftpboot folder and re-named it uImage-am335x-evm.bin. The starter kit accepted the uImage file and booted from it. After trying the same commands as the beginning of this post, I got back the same write error. Any thoughts on what I've done wrong?

    0211.board-am335xevm.c

  • Hi Tim,

    Why do you want to access the GPIO39 from user space ?

    Do you know that what component had been connected to the GPIO39 ?

    I'm sure that GPIO39 is either GPIO1_7 or GPIO1_6 but not GPIO1_4 and GPIO1_5 as per GPIO no calculation.

    But you have commented out the GPIO1_4 and GPIO1_5 which is not accessed from user space.

    Attached board file, I've commented out the whole GPIO LED configuration except pinmuxing which is must.

    Try this and let me know.

    2313.board-am335xevm.c

  • Hi Titus,

    I feel really silly now. I completely misread the schematic. I'm still very new to this environment, so all I'm trying to do at this point is get control of LEDs (it doesn't really matter which ones). When I had initially looked at the schematic, I had thought GPIO 39 was tied to one of the USR LEDs. This was wrong. I see now that it is GPIO 36 and 37 that are tied to the user LEDs.

    Like I said earlier, my purpose at this point in the game is to just familiarize myself as much as possible with the starter kit. My plan is first to figure out how to get control of the LED in the user space and what that takes, then figure out how to write a C program that controls the LED, then write a driver to control an LED and insert it into the kernel and write a program to interface with it.

  • Hi Tim,

    Have you tried the attached board file from my previous reply ?

    Use that and do the following commands.

    arch/arm/mach-omap2/board-am335xevm.c

    #define GPIO_TO_PIN(bank, gpio) (32 * (bank) + (gpio))

     

    Green LED4 -> GPIO1_4 -> GPIO Number 36

    Green LED3 -> GPIO1_5 ->  GPIO 37

    Green LED2 -> GPIO1_6 ->  GPIO 38

    Green LED1 -> GPIO1_7 -> GPIO 39


    AM335x-root # echo 36 > /sys/class/gpio/export

    AM335x-root # echo out > /sys/class/gpio/gpio36/direction

    AM335x-root # echo 1 > /sys/class/gpio/gpio36/value

    AM335x-root # echo 0 > /sys/class/gpio/gpio36/value

    Do the same for the rest of the GPIOs.

    Please let me know the results.

  • Hi Titus,

    This worked for me. Thank you for your help.

  • Hi Tim,

    Sounds good.

    Thanks for your update.