Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What is the / sys/class/gpio operation method in linux

2025-03-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly explains "what is the operation method of/sys/class/gpio in linux", the explanation content in the article is simple and clear, easy to learn and understand, please follow the idea of Xiaobian slowly in-depth, together to study and learn "what is the operation method of/sys/class/gpio in linux"!

The following is an example of debugging on ZC702 development to illustrate the process:

First, see if there is a folder called "/sys/class/gpio" on your system.

If not, add Device Drivers -> GPIO Support -> /sys/class/gpio/… (sysfs interface) when compiling the kernel. Note: My kernel is selected by default and does not need to be reselected.

/sys/class/gpio instructions:

1. gpio_operation Operate IO port GPIO to file system mapping through/sys/file interface;

2. The directory controlling GPIO is located in/sys/class/gpio;

3. The/sys/class/gpio/export file is used to notify the system that it needs to export the GPIO pin number of the control;

The requested URL/sys/class/gpio/unexport was not found on this server.

5. The/sys/class/gpio/gpiochipX directory stores the information of GPIO registers in the system, including the starting number base of each register control pin, the register name, and the total number of pins.

6, first calculate the pin number, pin number = control pin register base + control pin register bits;

7. Write this number to/sys/class/gpio/export, such as pin 12, which can be implemented in the shell by the following command. After the command succeeds, the directory/sys/class/gpio/gpio12 is generated. If the corresponding directory does not appear, it means that this pin cannot be exported: echo 12 > /sys/class/gpio/export;

8. direction file, which defines the input direction and can be defined as output by the following command;

echo out > direction, direction Accepted parameters: in, out, high, low. high/low sets the direction to output at the same time, and sets the value to the corresponding 1/0;

10, value file is the port value, 1 or 0.echo 1 > value

Below is a test under the ZC702 development board

1. Get GPIO information and type the following command in the terminal:

1.1、$ cd /sys/class/gpio;

1.2、$ for i in gpiochip* ; do echo `cat $i/label`: `cat $i/base` ; done

The command I used was echo `cat gpichip 906/label`: `cat gpichip 906/base`

The terminal displays the following:

zynq_gpio: 906

2. Calculate GPIO Number

We use GPE10 to control LEDs.

GPIO header is 906, 10 is 906+10 = 916.

$ echo 916 > /sys/class/gpio/export

See if there is a GPIO916.

3. GPIO control test.

Control LED so it is output.

So we should execute:

$ echo out > /sys/class/gpio/gpio916/direction

Then you can set the output.

$ echo 1 > /sys/class/gpio/gpio916/value

$ echo 0 > /sys/class/gpio/gpio916/value

Thank you for reading, the above is "linux/sys/class/gpio operation method is what" the content, after the study of this article, I believe that everyone on linux/sys/class/gpio operation method is what this problem has a deeper understanding, the specific use of the situation also needs to be verified by practice. Here is, Xiaobian will push more articles related to knowledge points for everyone, welcome to pay attention!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report