当前位置:网站首页>2. GPIO control summary (kernel driver) of nanopi M1 (Quanzhi H3)

2. GPIO control summary (kernel driver) of nanopi M1 (Quanzhi H3)

2022-04-23 22:03:00 July meteor

development environment :VM+Ubuntu

Compile environment :linux3.4

Cross compiler tool :arm-linux-gcc 4.4.3

GPIO Kernel driver link :https://download.csdn.net/download/ddffyhg/11022291

User application links :https://download.csdn.net/download/ddffyhg/11022286

Be careful : Development board linux Version and pc End Ubuntu Versions of can be inconsistent , But it has to do with compiler driven linux The kernel version is consistent

Development board :linux 3.4

pc Client downloaded linux kernel :/home/linux/Documents/lichee/linux3.4

1. The physical connections are as follows :

The hardware platform uses nanopi-m1,GPIO The physical pin corresponding to the output pin is pin7

LED The positive pole of the lamp ---------->PIN7(linux 213 Pin )

LED Lamp negative pole ---------->GND

2. stay PC End lichee/linux3.4/drivers/char/ Place under directory gpio The driver file for gpio.c

3. modify Makefile file , Add at the end of the file

obj-m            += gpio.o

4. stay lichee Recompile the kernel under the directory

./build.sh -p sun8iw7p1 -b nanopi-h3 -m kernel

After successful compilation , stay lichee/linux3.4/drivers/char/ The directory will generate gpio.ko file

5. take gpio.ko Copy files to development board

gpio.ko The file is the compiled driver file ,app.c The file is the corresponding user application .

6. Mount the kernel module :

insmod gpio.ko

View the list of kernel modules :

lsmod

Check whether there is a device node :

ls /dev/gpio*

Compiling the application :

gcc -o app app.c

Execute the application :

./app

Running results :

Because I don't have LED The lamp , Use the power indicator of the sensor instead :

Uninstall the kernel module :

rmmod gpio

Realization GPIO Control function of kernel driver module .

版权声明
本文为[July meteor]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204200609125613.html