How To Access GPIO Pins From Linux User Space On LS1021A

キャンセル
次の結果を表示 
表示  限定  | 次の代わりに検索 
もしかして: 

How To Access GPIO Pins From Linux User Space On LS1021A

6,026件の閲覧回数
patrickmorrow
Contributor III

We've managed to get a yocto Linux build up and running on a custom board populated with a LS1021A utilizing the 1.7 sdk.  We've also managed to run some simple programs on our board that we've built using Codewarrior, mostly baby steps like hello world type stuff that will print out to the terminal, just to make sure that we can.  Now we're ready to try something a little more in depth, namely wiggling GPIO pins, but we can't seem to find any information that would tell us the absolute addresses of the pins we wish to drive.

We've found documentation, both within these forums and elsewhere on the internet, telling us that in order to drive a GPIO pin from Linux user space we need to navigate to /sys/class/gpio, which we do, and then: echo XX > export, where XX would be the address of the pin that we want to establish a connection to (we're aware that what was just written is terminal based, but for the sake of removing all possible things that can cause an issue, we've decided to attempt a terminal solution before translating it into something that can be run from a C program).  Our goal is to drive pins GPIO3[3], GPIO3[4] and GPIO3[5], but we get stuck trying to find some kind of conversion that will give us absolute values for those 3 pins.

When we list the contents of the /sys/class/gpio directory we notice that there are sub directories labeled gpiochip128, gpiochip160, gpiochip192, and gpiochip224.  Do those correspond to the different GPIO ports and associated pins?

Patrick

ラベル(1)
0 件の賞賛
返信
2 返答(返信)

2,389件の閲覧回数
Pavel
NXP Employee
NXP Employee

Check please that the following kernel configuration options are set. These options are necessary

for sysfs GPIO support:

CONFIG_MPC8XXX_GPIO (Platform Support / MPC8xxx GPIO support)

CONFIG_OF_GPIO

CONFIG_GPIOLIB (-*- GPIO Support --->  )

CONFIG_GPIO_SYSFS (/sys/class/gpio/... (sysfs interface))

This option can be checked using the .config file in the kernel source folder.

GPIO controllers should be declared in the Device Tree file.

More information on the device tree GPIO declaration can be found in the kernel source.

See please the following files:

/Documentation/powerpc/dts-bindings/gpio.txt and /Documentation/powerpc/dts-bindings/fsl/8xxx_gpio.txt

This possibility is available using sysfs from user space.

See the following pages

(http://elinux.org/GPIO)

and

(https://www.kernel.org/doc/Documentation/gpio/sysfs.txt).

and

(http://www.lindusembedded.com/blog/2011/12/29/gpio-general-purpose-inputoutput-interfaces-in-linux-2...)

and

(https://www.kernel.org/doc/Documentation/gpio/sysfs.txt).

The second method consist of using mmap command.

It is a POSIX-compliant Linux/Unix system call that maps files or devices into memory.

It is a method of memory-mapped file I/O.

For example, look at the following links (http://en.wikipedia.org/wiki/Mmap) and

(http://beej.us/guide/bgipc/output/html/multipage/mmap.html).

2,389件の閲覧回数
patrickmorrow
Contributor III

Thanks for pointing out all that documentation, Pavel.  That seems to have lead us down the correct path.

We were able to determine which port each gpiochip was associated with by reading the "label" of each (for our purposes, gpio3 translates to gpiochip160).  From there we were able to index the corresponding base and export the pin we want to manipulate (for us it was 163).  With gpio163 created we were able to write 1's and 0's to the "value" and see the levels change on an oscilloscope.

Thanks,

Patrick

0 件の賞賛
返信