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.

pin toggle am335x

Hi,

I'm using a custom board loosely based on the am335x evm.

I'm trying to get the backlight to work. First I have to hardcode a few pins to low ( or high) in the u-boot code ( just to test if it works), later we hope to implement a complete pwm driver.

I tried to hardcode these pins to a value in the pinmux ( mux.c and mux.h) but I'm doubting if this is the right place to do this.

I came across this function for u-boot on the internet:

gpio_set_value( <pin> , <value>);

But it doesn't seem to be working.

I tried pin toggling in the u-boot prompt ( with md and wd <adress> <value> ) but I don't know if this was the proper to do it because it didn't work either.

Or do I have to do hardcode pin values in linux?

Thanks in advance


  • Hi Laurens,
     
    Pinmux is definitely not the place to set GPIO pin state. Pinmux only configures the pin functional mode, direction and internal pullup/pulldown. For the GPIO driver guide see this link: http://processors.wiki.ti.com/index.php/GPIO_Driver_Guide.
  • Hi Laurens,

    What version of U-boot are you using? Is it from TI SDK or other source?

    The function 

    int gpio_set_value(unsigned gpio, int value)

    is available in U-Boot in omap_gpio.c file in /drivers/gpio/ folder together with other gpio API functions.

    You may use this to initialize the gpio in board.c file in /board/ti/am335x/ folder.

    Please note how you enter the GPIO number in the function call. it has to be 

    unsigned gpio = (32 * (bank) + (gpio_in the bank))
    You can use also macro #define GPIO_TO_PIN(bank, gpio) (32 * (bank) + (gpio)) 

    But first you have to set pinmux in mux.c file /board/ti/am335x/ and note that after you enter the pinmux structure, you have to call it at the end of the same file (check how it is done for other pinmuxes).

    Hope this helps,

    BR,

    Vidin

  • Hi Laurens,

           For any pin to work as GPIO, first  we should define it as GPIO in MODE7 in board file, for

    example if you want to gpmc_a1 as GPIO then define in a function

    static struct pinmux_config gpio_pins[] = {

    {"gpmc_a1.gpio1_17", OMAP_MUX_MODE7 | AM33XX_PIN_OUTPUT},

    }

    Above gpio_pins[]  function should be called in other user defined function like gpio_init(evm,profile),

      Now one should export gpio using series of kernel inbuilt functions like

    GPIO_TO_PIN, gpio_request, gpio_direction_output, gpio_export

    i sequential order to get gpio exported to sysfs

    Regards,

    Rajeev


      

  • In my case I have to set pin 54 ( well actually it's pin GPMC_A6 , but I think it's pinnumber is 54 ? ) high. I tried the following command from the guide:

    root@am335x-evm:/sys/class/gpio# echo 54 > export                              
    root@am335x-evm:/sys/class/gpio# ls                                            
    export      gpio54      gpiochip0   gpiochip32  gpiochip64  gpiochip96  unexport

    /* so I can export pins */

    root@am335x-evm:/sys/class/gpio# echo 1 > gpio54/value                         
    -sh: echo: write error: Operation not permitted

    But i'm logged in as root so I don't understand the error. And I enabled gpio support as stated in the guide.

  • Hi,

    Probably the GPIO is still input. You have to make it output before setting it to "1" or "0".

    You can check the gpio direction by doing this:

    cat /sys/class/gpio/gpio54/direction

    If it is input, that explains why the operation fails. Make it output and it should work:

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

    Best regards,
    Miroslav

  • Thanks Miroslav,

    I completely forgot about that :). I managed to toggle the pin with the command line by making it output like you said. I succeeded in getting the u-boot/linux gpio code to work too by first requesting the pin and then declaring it output as described in the Documentation/gpio.txt file in the linux source code, I should have read it better :).

    Thank you all for the great help and patience!