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

How to use sys to control GPIO

2025-02-27 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

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

This article introduces the knowledge of "how to use sys to control GPIO". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!

This document mainly explains, iMX6 development board, through the way of sys files to control GPIO.

To control GPIO through sys, you need to do the following steps:

1 turn on the "GPIO_SYSFS" driver configuration in the kernel

2 make sure that IO is configured as GPIO and that there are no driver calls

3 calculate the GPIO number and manipulate GPIO through commands or scripts.

1 GPIO_SYSFS configuration

As shown in the following figure, you can see that GPIO_SYSFS is configured by default in the kernel, which is basically included in all the original BSP of this driver, and is generally configured by default.

2 make sure that IO is configured as GPIO and that there are no driver calls

Here, take the GPIO of LED as an example to remove the driver of LED to ensure that there is no driver call.

Device Drivers->

Character devices->

Enable LEDS config-remove and recompile the kernel to write to the development board.

Configure menuconfig as shown in the following figure.

Burn it to the development board and make sure there is no led device node. There are led device nodes in the default kernel, as shown in the following figure.

The configuration of GPIO will not be repeated here, but is described in "iTOP-iMX6- device Tree Kernel-IO configuration Analysis document _ V1.0".

3 calculate GPIO number and test

The network label of LED is: KEY_ROW6

The name of the PIN foot of LED corresponding to GPIO is: GPIO_2

The macro corresponding to GPIO_2 is defined as # define MX6QDL_PAD_GPIO_2__GPIO1_IO02

Then the bank [n] of GPIO corresponding to GPIO_2 is GPIO1_IO02, that is, GPIO 02 of bank 1.

The numbering calculation method of GPIO is: nr= (P-1) * 32 + N

Nr is the number, P is the bank number, and N is the number in the specific bank.

Then nr=2 1 is calculated to be Numeric 2, which is calculated.

The test command is:

Echo nr > / sys/class/gpio/export

Echo out > / sys/class/gpio/gpionr/direction

Echo 1 > / sys/class/gpio/gpionr/value-- > write high level, small light on

Echo 0 > / sys/class/gpio/gpionr/value-- > write low level, small light off

If the above nr is replaced with the number of GPIO, the command is:

Echo 2 > / sys/class/gpio/export

Echo out > / sys/class/gpio/gpio2/direction

Echo 1 > / sys/class/gpio/gpio2/value-- > write high level, small light on

Echo 0 > / sys/class/gpio/gpio2/value-- > write low level, small light off

As shown in the following figure, the small light is on after executing three commands.

Then execute echo 0 > / sys/class/gpio/gpio2/value small light off.

This is the end of the content of "how to Control GPIO with sys". Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!

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