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.

GPIO settings for AM335x

Hi friends,

   I am using SDKv7 for Starter Kit. I want to configure GPIOs Pins for various configurations, but I don't

  know how to do so.

  Eg:

     1) how to set direction of pins, using which function we can do this, at which location I am able to find

          respective File.c.

     2) using which functions Pin Toggle, High, low is done. at what location(.c file) I am able to see tho se

         function definitions.

   Regards,

   Vishal Rana,

  • Hi Vishal,

    SDK v7 uses device tree files instead of board files like SDK v6. Take a look at the <linux_dir>/arch/arm/boot/dts/am335x-evm.dts device tree file and check the am33xx_pinmux: pinmux@44e10800 section. There you will find how the pins are pinmuxed for the AM335x GP EVM. For example:

            matrix_keypad_default: matrix_keypad_default {
                pinctrl-single,pins = <
                    0x54 (PIN_OUTPUT_PULLDOWN | MUX_MODE7)    /* gpmc_a5.gpio1_21 */
                    0x58 (PIN_OUTPUT_PULLDOWN | MUX_MODE7)    /* gpmc_a6.gpio1_22 */
                    0x64 (PIN_INPUT_PULLDOWN | MUX_MODE7)    /* gpmc_a9.gpio1_25 */
                    0x68 (PIN_INPUT_PULLDOWN | MUX_MODE7)    /* gpmc_a10.gpio1_26 */
                    0x6c (PIN_INPUT_PULLDOWN | MUX_MODE7)    /* gpmc_a11.gpio1_27 */
                >;
            };

    The first entry is the pin's conf_<module>_<pin> register offset from the 44e10800 address, which can be extracted from the am335x TRM, section 9.3.1 CONTROL_MODULE Registers.

    The second entry is the value to store in the conf register, which affects how the pin will be pinmuxed. Check the TRM, section 9.3.1.51 for more details. The macros used there can be found in <linux_dir>/include/dt-bindings/pinctrl/am33xx.h.

    You can also use the sysfs interface to control the GPIO pin's direction or value. Actually this is the easiest way. For more details, please visit: http://processors.wiki.ti.com/index.php/GPIO_Driver_Guide#User_Space_-_Sysfs_control

    Best regards,
    Miroslav

  • Hi Miroslav,

             I want to use GPIO2_3 as interrupt GPIO, Presently that GPIO is configured as Input pin on starter kit.

             when I am checking cat sys/kernel/debug/gpio.

             I am getting this info.

             GPIOs 64-95, gpio:
             gpio-66  (button1             ) in  lo
             gpio-67  (button0             ) in  lo
             gpio-69  (button3             ) in  lo

          I am interested to make gpio-67  (button0             ) in  lo as interrupt gpio.

          I had writen ISR handler for this I am able to build.

         using function  irq_num = gpio_to_irq(Interrupt_key);   in ISR handler

         I am getting irq_num = 211.

        I am passing same infunction.

        request_irq(irq_num, (irq_handler_t) extn_irq_handler,IRQF_DISABLED, "EXTn_irq_handler", NULL);

       when I am inserting module .KO on board. I am getting

    root@am335x-evm:/# insmod ToggleLed2.ko
    [   52.648148] Inside toggle_init //this is debugging string.
    [   52.651394]  assingned interrupt num is = 211
    [   52.656322] genirq: Flags mismatch irq 211. 00000020 (EXTn_irq_handler) vs. 00000083 (button0)
    [   52.665483] Failed to get requested interrupt .


     Please Guide me where i am doing wrong, Where I have to make changes. I checked below link but not get

     solution for this.

    http://processors.wiki.ti.com/index.php/GPIO_Driver_Guide#User_Space_-_Sysfs_control.

    Thanks

    Vishal,

  • Vishal,

    Please report the error code that request_irq() returns.

    Best regards,
    Miroslav

  • hi miroslav,

      I am getting -16 from request_irq() function.

     root@am335x-evm:/# insmod ToggleLed.ko                                          
    [  221.912755] Inside toggle_init  // debugging line                                            
    [  221.915921]  assingned interrupt num is = 211      // debugging line getting this from gpiio_to irq()  func                           
    221.920821] genirq: Flags mismatch irq 211. 00000020 (EXTn_irq_handler) vs. )
    [  221.929950] Failed to get requested interrupt       // this is getting when inserting it on target                                                                                                       
    [  221.934732] Val return by request_irq() is = -16  // value return by request_irq().


    Regards,

    Vishal Rana

  • Vishal,

    Error -16 means /* Device or resource busy */.

    Looking further down the call chain of request_irq() you'll get to the __setup_irq() function inside <linux_dir>/kernel/irq/manage.c.

    My guess is that this has something to do with the IRQF_DISABLED flag you pass to the request_irq() function. As stated in the definition of this flag:

     * IRQF_DISABLED - keep irqs disabled when calling the action handler.
     *                 DEPRECATED. This flag is a NOOP and scheduled to be removed

    Try to request an irq with 0 flag as shown in the GPIO Driver Guide.

    Can you check if something else is using IRQ 211 before you insert the module? Most probably not, since I don't see any handler name printed, but still please check with:

    cat /proc/interrupts

    Best regards,
    Miroslav

  • Hi Miroslav,

      Thanks for your support, I am able to write and execute my external interrupt on GPIO.

      While doing so I find something which is new for me if you know the answers please share.

       1) Using SYSFS user space I am able to Export all free GPIOs also able to make them Input and output.

           but when I am writing 0 or 1 on few outputs pin( example: GPIO05 on J11 connector on starter board)

           using command given below 

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

           echo 1 > /sys/class/gpio/gpio5/value

           echo 0 > /sys/class/gpio/gpio5/value

           I am getting desired status of pin when checking on terminal using cat sys/kernel/debug/gpio (GPIO5 hi/lo).

           But when I am checking status of same pin with Digital Multimeter. it is showing NO change in voltage level.

           actually output PINs status is not changing. why this is happening??Please tell me.

     

       2)  On starter kit all 4 Pushbuttons are configured as GPIO interrupt I find it using cat /proc/interrupts,

             but for them I didn't able to find handler routine.  

        3) GPIOs which are configure in .dts file, I am not able to export them using sysfs, If I want to export and 

             use them for my application how could I do that?? should I delete  the given Pin configuration from .dts file

             or. Is there another way for doing this?? 

     

          THANKS IN ADVANCE.

     

           Regards,

           vishal

            

           

     

  • Vishal,

    Regarding your first question, the most probable reason for not having your signals coming out to the processor pin, is that the pin hasn't been multiplexed in GPIO mode. Please check and correct this. I just tested this on a BeagleBone White and setting the GPIO signals from the sysfs works flawlessly.

    2) I'm not sure there is any handler at all for the StarterKit. For the GP EVM, for example, there is the matrix keypad driver that gets registered and provides an ISR for the button interrupts. You can check the driver inside <linux>/drivers/input/keyboard/matrix_keypad.c.

    3) Please explain further and provide an example.

    Best regards,
    Miroslav