How To Modify GPIO Function Pins Of AM335x

1, How to configure GPIO function?

Modify the kernel board file kernel-3.2/arch/arm/mach-omap2/board-am335xevm-xd.c

For example, configure uart as gpio, mode7 is determined by chip manual or hardware manual, like follows


How to configure GPIO function

Modify

static struct pinmux_config uart1_pin_mux[] = {

{"uart1_rxd.uart1_rxd", OMAP_MUX_MODE0 | AM33XX_PIN_INPUT_PULLUP},

{"uart1_txd.uart1_txd", OMAP_MUX_MODE0 | AM33XX_PULL_ENBL},

{NULL, 0},

};


To:

static struct pinmux_config uart1_pin_mux[] = {

{"uart1_rxd.gpio0_14",OMAP_MUX_MODE7 | AM33XX_PIN_OUTPUT},

{"uart1_txd.gpio0_15", OMAP_MUX_MODE7 | AM33XX_PIN_OUTPUT},

{NULL, 0},

};


2, Set the configuration as above method. GPIO is not available. Why does the configuration not work?

Reason: The other functions of the pin are not commented out.

For example, GPIO function of uart1_rxd pin. This is a multiplexed pin. Check its functions in hardware manual. Then comment out all other multiplexing functions of this pin, except GPIO.

As follows:

GPIO function of uart1_rxd pin

Note: A pin can only be used for one function! ! ! Either uart_rxd or gpio

3, Set the correct configuration. Commented out the multiplexing functions.Why can't a GPIO be configured to pull a pin high or low?

If create/add xxx _pin_mux [] by yourself, you need setup_pin_mux (xxx _pin_mux ). This step is critical. If you configure it without setting pinmux, no matter how you configure it, it will not be able to pull high and low.

Then initialize and write the xxx_init{} function. Initialize pinmux, as follows:

static void xxx_init(int evm_id, int profile)

{

setup_pin_mux(xxx_mux);

}


Finally put xxx_init into ok335x_dev_cfg[]

All these done in the board-level configuration file. You can refer to the configuration and initialization process of LED, KEYS.

put xxx_init into ok335x_dev_cfg


4, Set the correct configuration. Commented out the multiplexing functions. Why can't GPIO be exported by echo in user space?

Let’s see a simple example of LED.

Set the correct configuration

To use echo to export gpio in user space, just need setup_pin_mux()

If use platform_device_register(), this function will register gpio through the kernel. Thus it can not be exported through user space.

In addition, use gpio_set_value() gpio_request() pio_direction_output() function will also cause echo export failed in user space.


5, How to use echo to export pins? what is the corresponding GPIO number?

Formula: number = 32 * gpio group + gpio number

For example, the number of gpio1_16 is 32 *1+16=48

Export: echo 48 > /sys/class/gpio/export


6, Added a new function, such as uart, pwm, etc., but it doesn't work? Why?

For example add pwm on OK335xD. We can check the hardware manual and there are four pins that can output pwm, gpmc_a2, gpmc_a3, gpmc_ad8, gpmc_ad9. But only gpmc_a2 can output signal. The reason is the pins of Texas Instruments are not fully defined. Thus the configuration does not work.

In hardware manual, the mode6 of gpmc_a2 and gpmc_a3 is the pwm function, as shown:

OK335xD hardware manual

OK335xD hardware manual


But the pins of Texas Instruments are defined as:

TI OK335xD SBC

This configuration means: configure the multiplexed functions of gpmc_a2 pins in sequence.

When use mode6 "ehrpwm1a" function of gpmc_a3, the configuration is NULL

Solution: modify in mux33xx.c, which is in the same directory of board-level configuration file. Just change NULL to ehrpwm1b. Same method for other pins.


7, Why does the level state of GPIO pins jump when I start up, and can only be stabilized after the kernel is fully started?

The reason is when chip is powered on, each pin will have a default state, which is uncontrollable. If the initialized state of pin is inconsistent with the default state, it will cause a jump instantly. If the requirement for power-on level is strict, you can refer the chip manual from Chip manufacturer. Check the default power-on state of the corresponding pin, and select the pin that meets your requirements.