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 GPIO toggle

Other Parts Discussed in Thread: DA8XX, AM3358

Hello Rajeev ,

As u have mention "" Now one should export gpio using series of kernel inbuilt functions like GPIO_TO_PIN, gpio_request, gpio_direction_output, gpio_export ""    

How One could Export GPIO from board.c file

I can able to control GPIO but want to export and set direction from board file . So it will be easy to handle file to Read and Write files from script.

I have gone through gpio.txt

where I found --> int gpio_export(unsigned gpio,bool direction_may_change);

and " gpio" might be (bank*32+pin)  .

 Regarding "direction_may_change"   is it ""   0 """ for input and """" 1""""  for output  ?? if I am going right then ;

how could i write in board.c file.

Regards

Praveen

  • Hi Praveen,

    Please read the AM335x GPIO Driver Guide about kernel level usage of the GPIO driver: http://processors.wiki.ti.com/index.php/GPIO_Driver_Guide

    Regarding your question about "bool direction_may_change", please read the function description for gpio_export(). The kernel gpio driver can be found inside <linux_dir>/drivers/gpio/gpiolib.c. Here is an excerpt:

    /**
     * gpio_export - export a GPIO through sysfs
     * @gpio: gpio to make available, already requested
     * @direction_may_change: true if userspace may change gpio direction
     * Context: arch_initcall or later
     *
     * When drivers want to make a GPIO accessible to userspace after they
     * have requested it -- perhaps while debugging, or as part of their
     * public interface -- they may use this routine.  If the GPIO can
     * change direction (some can't) and the caller allows it, userspace
     * will see "direction" sysfs attribute which may be used to change
     * the gpio's direction.  A "value" attribute will always be provided.
     *
     * Returns zero on success, else an error.
     */
    int gpio_export(unsigned gpio, bool direction_may_change)

    Best regards,
    Miroslav

  • Hi Miroslav,

         Thank for Quick Response.

           I am just going through  drivers/gpio/gpiolib.c, line 832     

    from that link :http://lxr.free-electrons.com/ident?i=gpio_export

    where I found same as u mentioned above; from that it clear for specific direction  ""direction_may_change"" should be Zero and GPIO

    ----> eg for gpio2_18 will be 82;

    the function value should be int gpio_export(82,0); 

    So I have to modify board-am335x.c file  like 

    static struct pinmux_config gpio_out_pin_mux[] = {


           {"uart1_cstn.gpio1_8",OMAP_MUX_MODE7 | AM33XX_PIN_OUTPUT},


            {"mii1_rxd3.gpio2_18",OMAP_MUX_MODE7 | AM33XX_PIN_OUTPUT},


            {NULL, 0},
    };

    void gpio_out_init(int evm_id, int profile)
    {
         setup_pin_mux(gpio_out_pin_mux);
         /* Instance Zero */
         int status_gpio = gpio_export(82,0);

         if(status_gpio<0){

         pr_err("Failed to request gpio   82 and 40 ");

         }
    }

    If it is fine pls let me know or provide some suggestion for modification

    Regards

    Praveen

  • Hi Miroslav,

             i have tried but it didn't work

    when I tried to access pin status from;

    root@am335x $ cat /sys/kernel/debug/gpio

    didn't see any changes on pin 40 and  82

    Pls do help

    Regards

    Praveen

  • Did you add your gpio_out_init() function to the static struct evm_dev_cfg gen_purp_evm_dev_cfg[] ? Please note that depending on your board you may be using one of the other evm_def_cfg structure arrays.

    Best regards,
    Miroslav

  • Yes Miroslav ,

          I have added it , and while booting it executing also I have place and pr_error if there is error it will show an error:

    void gpio_out_init(int evm_id, int profile)
    {
         int status_rtc;
         int status_bckl;
         setup_pin_mux(gpio_out_pin_mux);
         /* Instance Zero */
         status_rtc  = gpio_export(82,0);
         status_bckl = gpio_export(40,0);
         
        if(status_rtc<0)
           pr_err("Failed to initialize GPIO82\n");
        if(status_bckl<0)
           pr_err("Failed to initialize GPIO40\n");
    }

    While booting I found These error ;

    [    0.092315]  da8xx_lcdc.0: alias fck already exists
    [    0.092987] Failed to initialize GPIO82
    [    0.093017] Failed to initialize GPIO40
    [    0.093139]  omap_hsmmc.0: alias fck already exists
    [    0.093536]  davinci-mcasp.0: alias fck already exists
    [    0.095245]  omap2_mcspi.1: alias fck already exists
    [    0.095550]  omap2_mcspi.2: alias fck already exists
    [    0.095886]  edma.0: alias fck already exists
    [    0.095916]  edma.0: alias fck already exists

    there is no error regarding ""gpio_out_pin_mux""  

    There is error in gpio_export(82,0); and gpio_export(40,0); it is not able to export

    Regards

    Praveen

  • Hi Praveen,

    After you setup the pin mux for the pins you need, they are set as GPIOs. If you need to export them to the SYSFS in order to manipulate them from user space, then you have to use the API as shown in the GPIO Driver's Guide I posted earlier.

    First you need to allocate memory for the GPIO line you wish to use and I can't see this in your code. Most probably this is the reason why the GPIO pin exporting fails.

    This is done by:

    err = gpio_request(30, "sample_name");

    Best regards,
    Miroslav

  • Hi Miroslav ,

     As you said I have added gpio_request:

    void gpio_out_init(int evm_id, int profile)
    {
         int status_rtc;
         int status_bckl;
         int status_req_rtc;
         int status_req_bckl;
         
         status_req_rtc = gpio_request(82,"rtc cs");
         if(status_req_rtc<0)
           pr_err("Failed to request GPIO82\n");         

         status_req_bckl = gpio_request(40,"b light");
         if(status_req_rtc<0)
           pr_err("Failed to request GPIO40\n");         
            
         status_rtc  = gpio_export(82,0);
         status_bckl = gpio_export(40,0);
         
        if(status_rtc<0)
           pr_err("Failed to initialize GPIO82\n");
        if(status_bckl<0)
           pr_err("Failed to initialize GPIO40\n");
        
        setup_pin_mux(gpio_out_pin_mux);
    }

    and I can able to see the gpio40 and gpio82 directory created in sys/class/gpio     BUT

    in these directory "" direction"" file is not created and these pins default defined as  input and when

    I am trying to change value it shows error

    root@am335x-evm:/# echo 1 > /sys/class/gpio/gpio40/value

    -sh: echo: write error: Operation not permitted

    as i see the description of pins    through      ---> cat  /sys/kernel/debug/gpio      gpio40 and gpio82

    defined as    gpio-82(rtc                     ) in lo  same for gpio 40

    I want to control those GPIO from application?

    Thank for Support :)

    Regards

    Praveen

  • Hi Miroslav ,

             As in gpio_export(gpio, direction_may_change)   making 1 to direction_may_change  as follows--

              I have made changes  gpio_export(40,1);  and direction file created but it is default Input In direction file

             and default 0 in Value file I can able to access gpio but  after making change in direction files.  

             How to make default output for gpio from api; so that initial setting has been done;

            using pin_mux_there is no changes in GPIO pins;

            Waiting for Reply;

         

          Regards

          Praveen

            

  • Hi,

    Did you read this guide? If not, please read it! If you read it, you will notice the following function, which does exactly what you want:

    gpio_direction_output(unsigned gpio, int value)

    Best regards,
    Miroslav

  • Hi ,

    Thanks Alot it worked !!

    Regards

    Praveen

  • Hi Miroslav,


    Can you please help me with the header files required to compile the code. Also if possible sample program to fiddle with the GPIO pins. I tried but not able to compile the code.

  • Harsha, the AM335x linux uses the generic GPIO driver (gpiolib.c), so there isn't a special header file to be included, only <linux/gpio.h>.

    You have to enable the GPIO support in the kernel configuration as shown in the GPIO Driver Guide.

    Please paste the error log from the failed compilation.

    Best regards,
    Miroslav

  • Hi Miroslav,

     Is there any API to change the pullup/pulldown config?  

    tks,

    Joe

  • You can write to the /sys/kernel/debug/omap_mux/ entries to do this from linux user space. Example:

    echo 0x#### > uart1_txd

    If the debugfs isn't mounted on your system, do this:

    mount -t debugfs none /sys/kernel/debug/

    Best regards,
    Miroslav

  • Hi,

    I am very new to AM335x. I was trying LED blink on AM3358 with CCS.  I am getting error " GPIO1ModuleClkConfig(); undefined". Can anyone support with solution.

     

    Thanks...

     

  • Siva,
    Did anyone answer you?

    I am also trying to do the same thing, and there is no support, and nothing compiles.

    And every other post/answer I can find it years old and doesn't work. Because they are changing this on a weekly bases, breaking old examples, answers, support, etc...

    It's a nightmare! I've never experience a development eco system that is this much of a mess.

    -Scott