GPIO use

2,002 views
Skip to first unread message

e3bble

unread,
Dec 1, 2011, 12:30:48 AM12/1/11
to pandaboard
Hi all,
I try to use GPIO from ubuntu(11.04), but only one I can use is
gpio_138.

I tray change OMAPxxxxxxx.c file to set some GPIO (set mode from M0 to
M2 or M3, M4 depend on pin) and create new MLO,
then change OMAPxxxxxxx.h file to set some GPIO (set mode from M0 to
M2 or M3, M4 depend on pin) too, and create new u-boot.bin.

then create boot SD from linux and change in boot partition MLO and u-
boot files with new one which I was created.

After it I boot my pandabord REV A1 and get same resultant, work only
one GPIO_138...

Where are may mistakes?

I need to read encoder signals ( 2 channels 360 imp. per rot. and 1500
rot per min.) and idea are to read accurate speed on each impulse.(by
calculating time between impulses)


Help someone :)

Bruno

unread,
Dec 1, 2011, 2:42:49 AM12/1/11
to panda...@googlegroups.com
hi e3bble,

how do you try to use the GPIOs?
Does the gpio-sysfs method word?
E.g for reading gpio 49 and writiting gpio50
$cd /sys/class/gpio
$echo 49 > export
$echo 50 > export
$echo in > gpio49/direction
$echo out > gpio50/direction
$echo 1 > gpio50/value [this sets gpio50 to high]
$cat gpio49/value [this reads gpio49]

you can open the gpio's as file in any normal c/c++ application. but if it needs to be fast
its better to write a kernel module then use the gpio-sysfs

Robis

unread,
Dec 5, 2011, 1:13:31 AM12/5/11
to panda...@googlegroups.com
I using C/C++ by using GPIO like files(how use like kernel model?)
My program set in export 134,135,136,137,138,139,140,155,156   GPIO'S,
then set all them direction to IN and then tray to find change in input and I connect all pins by 1,8 V,  but getting echo only from 138...



2011/12/1 Bruno <niklau...@gmail.com>

Bruno Niklaus

unread,
Dec 5, 2011, 1:36:56 AM12/5/11
to panda...@googlegroups.com
hi e3bble,

is it possible that another driver/module already uses this GPIO's ?
If you enabled debugfs in kernel you can try
cat /sys/kernel/debug/gpio
to see if they are allready in use.

For the kernel module you could start with the gpio_keys.c from kernel source,
it simulates keys by reading in the gpio ports.


or google for "gpio kernel module"

Robis

unread,
Dec 5, 2011, 3:56:05 AM12/5/11
to panda...@googlegroups.com
"Cat " command give me that:
"cat /sys/kernel/debug/gpio
GPIOs 0-31, gpio:
 gpio-0   (DVI PD              ) out lo
 gpio-1   (hub_power           ) out hi
 gpio-7   (pandaboard::status1 ) out lo
 gpio-8   (pandaboard::status2 ) out lo

GPIOs 32-63, gpio:
 gpio-41  (hdmi_gpio_ls_oe     ) out hi
 gpio-43  (vwl1271             ) out hi
 gpio-46  (kim                 ) out hi
 gpio-60  (hdmi_gpio_hpd       ) out hi
 gpio-62  (hub_nreset          ) out hi

GPIOs 64-95, gpio:

GPIOs 96-127, gpio:
 gpio-127 (audpwron            ) out hi

GPIOs 128-159, gpio:

GPIOs 160-191, gpio:
"

2011/12/5 Bruno Niklaus <niklau...@gmail.com>

Robis

unread,
Dec 5, 2011, 4:12:13 AM12/5/11
to panda...@googlegroups.com
after I use my program and connect 1.8 V to this pins I get "
GPIOs 128-159, gpio:
 gpio-128 (sysfs               ) in  lo
 gpio-129 (sysfs               ) in  lo
 gpio-134 (sysfs               ) in  lo
 gpio-136 (sysfs               ) in  lo
 gpio-137 (sysfs               ) in  lo
 gpio-138 (sysfs               ) in  hi
 gpio-139 (sysfs               ) in  lo
 gpio-156 (sysfs               ) in  lo
"

Way all other pins stay in LOW? ..

PS: code exactly same for all gpio's.



2011/12/5 Robis <e3b...@gmail.com>

Bruno Niklaus

unread,
Dec 5, 2011, 4:27:10 AM12/5/11
to panda...@googlegroups.com
dumb question, but where do you get your 1.8v from? external or
board-internal? gnd connected between external an pandaboard?

could you try to connect GPIO_128 to GPIO_129
then config GPIO_128 as output and set high, set gpio_129
to input and read the value?

Bruno Niklaus

unread,
Dec 5, 2011, 4:29:06 AM12/5/11
to panda...@googlegroups.com
sorry i mean connect GPIO_128 and GPIO_129 together,
like shorten pin expansion connector J1 pin 15 to expansion
connector J4 pin 14

or probably you find some gpio which are better to shorten :)

Robis

unread,
Dec 8, 2011, 12:13:56 AM12/8/11
to panda...@googlegroups.com
1.8 V I get from J3 connector pin 2 and connect same connector to pin 10(GPIO 138) and pins 4,6,12,14,16,20,22,24 , but it works only on pin 10 (Gpio 138)....
 

2011/12/5 Bruno Niklaus <niklau...@gmail.com>

e3bble

unread,
Dec 30, 2011, 2:13:27 AM12/30/11
to pandaboard
Find the solution my mux was bad(set mode 4 or2 but need m3), new
almost all work. I mis only UART4 and I
2C4 pins mux to GPIO, but it not so important :)

On 8 Gruo, 07:13, Robis <e3b...@gmail.com> wrote:
> 1.8 V I get from J3 connector pin 2 and connect same connector to pin
> 10(GPIO 138) and pins 4,6,12,14,16,20,22,24 , but it works only on pin 10
> (Gpio 138)....
>
> 2011/12/5 Bruno Niklaus <niklaus.br...@gmail.com>
>
>
>
> > sorry i mean connect GPIO_128 and GPIO_129 together,
> > like shorten pin expansion connector J1 pin 15 to expansion
> > connector J4 pin 14
>
> > or probably you find some gpio which are better to shorten :)
>
> >>>> 2011/12/5 Bruno Niklaus <niklaus.br...@gmail.com>
>
> >>>>> hi e3bble,
>
> >>>>> is it possible that another driver/module already uses this GPIO's ?
> >>>>> If you enabled debugfs in kernel you can try
>
> >>>>> cat /sys/kernel/debug/gpio
>
> >>>>> to see if they are allready in use.
>
> >>>>> For the kernel module you could start with the gpio_keys.c from kernel
> >>>>> source,
> >>>>> it simulates keys by reading in the gpio ports.
>
> >>>>>http://lxr.free-electrons.com/source/drivers/input/keyboard/gpio_keys.c
>
> >>>>> or google for "gpio kernel module"
>
> >>>>> Am 5. Dezember 2011 07:13 schrieb Robis <e3b...@gmail.com>:
>
> >>>>> I using C/C++ by using GPIO like files(how use like kernel model?)
> >>>>>> My program set in export 134,135,136,137,138,139,140,155,156   GPIO'S,
> >>>>>> then set all them direction to IN and then tray to find change in
> >>>>>> input and I connect all pins by 1,8 V,  but getting echo only from 138...
>
> >>>>>> 2011/12/1 Bruno <niklaus.br...@gmail.com>
>
> >>>>>>> hi e3bble,
>
> >>>>>>> how do you try to use the GPIOs?
> >>>>>>> Does the gpio-sysfs method word?
> >>>>>>> E.g for reading gpio 49 and writiting gpio50
> >>>>>>> $cd /sys/class/gpio
> >>>>>>> $echo 49 > export
> >>>>>>> $echo 50 > export
> >>>>>>> $echo in > gpio49/direction
> >>>>>>> $echo out > gpio50/direction
> >>>>>>> $echo 1 > gpio50/value [this sets gpio50 to high]
> >>>>>>> $cat gpio49/value [this reads gpio49]
> >>>>>>> have a look at
> >>>>>>>http://www.avrfreaks.net/wiki/index.php/Documentation:Linux/GPIO#gpio...

Goldensgui

unread,
Jan 4, 2012, 4:40:50 PM1/4/12
to pandaboard
Hello,

I'm starting using my pandaboard but can't use the gpio.
What did you do exactly when you say "my mux was bad"?

Thank you

qua...@gmail.com

unread,
Mar 14, 2012, 3:14:40 PM3/14/12
to panda...@googlegroups.com
Mux probably means "Pins Multiplexing"

see: http://elinux.org/BeagleBoardPinMux

Details of OMAP35x PinMux can be found in OMAP35x Applications Processor TRM (spruf98u.pdf) in section 7.4.4.3 Pad Multiplexing Register Fields (page 782)


I created initalization part for GPIO. When I tried to show GPIO status via "cat /sys/kernel/debug/gpio" I saw this:

GPIOs 32-63, gpio:

gpio-32 (pandaboard_exp_menu ) in hi

gpio-33 (pandaboard_exp_volup) in hi

gpio-36 (pandaboard_exp_power) in hi

gpio-37 (pandaboard_exp_voldw) in lo

gpio-38 (pandaboard_exp_back ) in lo


I was not able to control gpio-37 and gpio-38 (low state).

If you have some similar problem with addressing of GPIO you must add some snipped to board-omap4panda.c file.


find (board-omap4panda.c):

#ifdef CONFIG_OMAP_MUX

static struct omap_board_mux board_mux[] __initdata = {


and append code like this:


/** GPIO Expansion board */

// AD12 - GPIO 36 - HOME

OMAP4_MUX(GPMC_AD12, OMAP_PIN_INPUT | OMAP_MUX_MODE3),

// AD08 - GPIO 32 - MENU

OMAP4_MUX(GPMC_AD8, OMAP_PIN_INPUT | OMAP_MUX_MODE3),

// AD14 - GPIO 38 - BACK

OMAP4_MUX(GPMC_AD14, OMAP_PIN_INPUT | OMAP_MUX_MODE3),

// AD09 - GPIO 33 - VOLUME_UP

OMAP4_MUX(GPMC_AD9, OMAP_PIN_INPUT | OMAP_MUX_MODE3),

// AD13 - GPIO 37 - VOLUME_DOWN

OMAP4_MUX(GPMC_AD13, OMAP_PIN_INPUT | OMAP_MUX_MODE3),


Note: This snipped is from my configuration for chipsee expansion board.

samsou...@gmail.com

unread,
Mar 26, 2012, 11:14:37 PM3/26/12
to panda...@googlegroups.com
I am having the same problem. I changed the files as you mentioned but what do I do from here? How do I get the file compiled and installed?

David Anders

unread,
Mar 27, 2012, 12:11:10 AM3/27/12
to pandaboard
samsounda,

please review the docs on compile linux kernel for pandaboard.

Dave


On Mar 26, 10:14 pm, samsounda...@gmail.com wrote:
> I am having the same problem. I changed the files as you mentioned but what
> do I do from here? How do I get the file compiled and installed?
>
>
>
>
>
>
>
> On Wednesday, March 14, 2012 2:14:40 PM UTC-5, qua...@gmail.com wrote:
>
> > *Mux probably means "Pins Multiplexing"*
>
> > see:* *http://elinux.org/BeagleBoardPinMux
>
> > Details of OMAP35x PinMux can be found in OMAP35x Applications Processor
> > TRM <http://www.ti.com/lit/ug/spruf98u/spruf98u.pdf> (spruf98u.pdf) in
> > section *7.4.4.3 Pad Multiplexing Register Fields* (page 782)
>
> > I created initalization part for GPIO. When I tried to show GPIO status
> > via "cat /sys/kernel/debug/gpio" I saw this:
>
> > GPIOs 32-63, gpio:
>
> > gpio-32 (pandaboard_exp_menu ) in hi
>
> > gpio-33 (pandaboard_exp_volup) in hi
>
> > gpio-36 (pandaboard_exp_power) in hi
>
> > gpio-37 (pandaboard_exp_voldw) in lo
>
> > gpio-38 (pandaboard_exp_back ) in lo
>
> > I was not able to control gpio-37 and gpio-38 (low state).
>
> > If you have some similar problem with addressing of GPIO you must add some
> > snipped to board-omap4panda.c file.*
> > *
>
> >  find (board-omap4panda.c):
>
> > #ifdef CONFIG_OMAP_MUX
>
> > static struct omap_board_mux board_mux[] __initdata = {
>
> >  and append code like this:
>
> >  * */** GPIO Expansion board */

Prajwal Upadhya

unread,
Apr 20, 2012, 9:29:01 PM4/20/12
to pandaboard
Hi,
 We are trying to set the GPIO135 available on the (pin 18)J3
expansion
header. We have deployed the android ice cream sandwich on the panda
board.

For this we have added the line "OMAP4_MUX(MCSPI1_SOMI,
OMAP_MUX_MODE3 | OMAP_PIN_OUTPUT)" in the struct omap_board_mux
board_mux[] of board-omap4panda.c.

This struct contains all the pin mux configurations. This change does
not seem to let us control the status (High/Low) of the pin. We were
wondering if anybody could point out the extra changes (if any) that
need to be done in order to configure the pin as an output pin.

Also, when we do a cat /sys/kernel/debug/gpio we see this.

GPIOs 0-31, gpio:
gpio-0 (DVI PD ) out hi
gpio-1 (hub_power ) out hi

GPIOs 32-63, gpio:
gpio-39 (nfc_int ) in lo
gpio-41 (hdmi_gpio_ls_oe ) out hi
gpio-43 (vwl1271 ) out hi
gpio-46 (kim ) out hi
gpio-60 (hdmi_gpio_hpd ) out hi
gpio-62 (hub_nreset ) out hi
gpio-63 (? ) in lo

GPIOs 64-95, gpio:

GPIOs 96-127, gpio:
gpio-127 (audpwron ) out lo

GPIOs 128-159, gpio:
gpio-134 (nfc_firm ) in lo
gpio-135 (nfc_ven ) in lo

GPIOs 160-191, gpio:

The pin (GPIO135) is registered as an input pin instead as an output
pin as configured by the mux configuration mentioned earlier. We are
not sure y this is happening. It would be very helpful if anyone can
guide us.

On Mar 26, 9:11 pm, David Anders <danders....@gmail.com> wrote:
> samsounda,
>
> please review the docs on compile linux kernel for pandaboard.
>
> Dave
>
> On Mar 26, 10:14 pm, samsounda...@gmail.com wrote:
>
>
>
>
>
>
>
> > I am having the same problem. I changed the files as you mentioned but what
> > do I do from here? How do I get the file compiled and installed?
>
> > On Wednesday, March 14, 2012 2:14:40 PM UTC-5, qua...@gmail.com wrote:
>
> > > *Mux probably means "Pins Multiplexing"*
>
> > > see:* *http://elinux.org/BeagleBoardPinMux
>
> > > Details of OMAP35x PinMux can be found in OMAP35x Applications Processor
> > > TRM <http://www.ti.com/lit/ug/spruf98u/spruf98u.pdf> (spruf98u.pdf) in
> > > section *7.4.4.3 Pad Multiplexing Register Fields* (page 782)
>
> > > I created initalization part forGPIO. When I tried to showGPIOstatus
> > > via "cat /sys/kernel/debug/gpio" I saw this:
>
> > > GPIOs 32-63,gpio:
>
> > >gpio-32 (pandaboard_exp_menu ) in hi
>
> > >gpio-33 (pandaboard_exp_volup) in hi
>
> > >gpio-36 (pandaboard_exp_power) in hi
>
> > >gpio-37 (pandaboard_exp_voldw) in lo
>
> > >gpio-38 (pandaboard_exp_back ) in lo
>
> > > I was not able to controlgpio-37 andgpio-38 (low state).
>
> > > If you have some similar problem with addressing ofGPIOyou must add some
> > > snipped to board-omap4panda.c file.*
> > > *
>
> > >  find (board-omap4panda.c):
>
> > > #ifdef CONFIG_OMAP_MUX
>
> > > static struct omap_board_mux board_mux[] __initdata = {
>
> > >  and append code like this:
>
> > >  * */**GPIOExpansion board */
>
> > > // AD12 -GPIO36 - HOME
>
> > > OMAP4_MUX(GPMC_AD12, OMAP_PIN_INPUT | OMAP_MUX_MODE3),
>
> > > // AD08 -GPIO32 - MENU
>
> > > OMAP4_MUX(GPMC_AD8, OMAP_PIN_INPUT | OMAP_MUX_MODE3),
>
> > > // AD14 -GPIO38 - BACK
>
> > > OMAP4_MUX(GPMC_AD14, OMAP_PIN_INPUT | OMAP_MUX_MODE3),
>
> > > // AD09 -GPIO33 - VOLUME_UP
>
> > > OMAP4_MUX(GPMC_AD9, OMAP_PIN_INPUT | OMAP_MUX_MODE3),
>
> > > // AD13 -GPIO37 - VOLUME_DOWN
Message has been deleted

lon...@gmail.com

unread,
May 1, 2012, 11:26:31 PM5/1/12
to panda...@googlegroups.com
Hi 
There are 2 things you have to take care when using GPIO.
- The GPIO chip itself
- The mux which control the actual ball/pin will route to GPIO or other peripherals (SPI, I2C...)

Inside the OMAP4 there are 6 GPIO chips each has 32 GPIO (=> total 192 GPIOs). 
Linux only care about the GPIO NUMBER. 6 GPIO chips inside OMAP will register GPIO number from 1 to 192 (AFAIK).
(GPIO_135 belong to chip 5)
Each GPIO_n in Linux has a struct name: struct gpio_desc.
struct gpio_desc {
struct gpio_chip *chip;
unsigned long flags;
/* flag symbols are bit numbers */
#define FLAG_REQUESTED 0
#define FLAG_IS_OUT 1
#define FLAG_RESERVED 2
#define FLAG_EXPORT 3 /* protected by sysfs_lock */
#define FLAG_SYSFS 4 /* exported via /sys/class/gpio/control */
#define FLAG_TRIG_FALL 5 /* trigger on falling edge */
#define FLAG_TRIG_RISE 6 /* trigger on rising edge */
#define FLAG_ACTIVE_LOW 7 /* sysfs value has active low */

#define ID_SHIFT 16 /* add new flags before this one */

#define GPIO_FLAGS_MASK ((1 << ID_SHIFT) - 1)
#define GPIO_TRIGGER_MASK (BIT(FLAG_TRIG_FALL) | BIT(FLAG_TRIG_RISE))

#ifdef CONFIG_DEBUG_FS
const char *label;
#endif
};

/sys/kernel/debug/gpio is actually show you the current value the struct gpio_desc of GPIO_n
you see it's configured as input because the bit 1 the flag is not set. (FLAG_IS_OUT)
to set enable chip output you may do: 
ECHO 135 > /sys/class/gpio/export  /* this will call the function [int gpio_request(unsigned gpio, const char *label)] this function will call to the specific omap's chip function [ &gpio_desc[135]->chip->request(chip, gpio - chip->base) ] this will set the bit in the OMAP4_GPIO_CTRL register to enable the clock for GPIO chip 5 ---> clock for chip 5 will be enable (if it's initially disable) */

ECHO "out" > /sys/class/gpio/gpio135/direction  // this will call [ int gpio_direction_output(unsigned gpio, int value) ] --> set flag FLAG_IS_OUT --->  &gpio_desc[135]->chip->direction_output(chip, gpio, value) ---> set the corresponding bit in the register GPIO_EN of chip 5 to actually enable the pin for out put
 
the result of the 2 above command is you will enable the clock for GPIO chip 5 and set the both the FLAG_IS_OUT in the &gpio_desc[135] and the corresponding bit in GPIO_EN  

BUT, the mux is not configured to route GPIO chip to the actual pin/ball after the 2 command. So you also have to configure the mux mode 3 and output enable. (as already pointed out)
Reply all
Reply to author
Forward
0 new messages