全誌R58平臺的GPIO引腳控制
全誌R58平臺的GPIO引腳控制
2017/8/18 15:50
版本:V1.0
開發板:SC5806(全誌R58平臺)
SDK:android4.4.4
本文以GPIO引腳PD24為例,在開發板的背面。J18座子上,+5V旁邊(可以用這個引腳來定位!)。
rootroot@cm-System-Product-Name:/home/wwt/vxiaoyu_s5k5eya/lichee/linux-3.4$ make ARCH=arm menuconfig
Device Drivers --->
-*- GPIO Support --->
[ ] /sys/class/gpio/... (sysfs interface)
修改為:
[*] /sys/class/gpio/... (sysfs interface)
rootroot@cm-System-Product-Name:/home/wwt/vxiaoyu_s5k5eya/lichee$ find . -name gpio.h
./linux-3.4/arch/arm/mach-sunxi/include/mach/gpio.h
W:\xiaoyu_s5k5eya\lichee\linux-3.4\arch\arm\mach-sunxi\include\mach\gpio.h
得知GPIO號:
#define SUNXI_PINCTRL "sunxi-pinctrl"
#define SUNXI_BANK_SIZE 32
#define SUNXI_PA_BASE 0
#define SUNXI_PB_BASE 32
#define SUNXI_PC_BASE 64
#define SUNXI_PD_BASE 96
#define SUNXI_PE_BASE 128
#define SUNXI_PF_BASE 160
#define SUNXI_PG_BASE 192
#define SUNXI_PH_BASE 224
#define SUNXI_PI_BASE 256
#define SUNXI_PJ_BASE 288
#define SUNXI_PK_BASE 320
#define SUNXI_PL_BASE 352
#define SUNXI_PM_BASE 384
#define SUNXI_PN_BASE 416
#define SUNXI_PO_BASE 448
#define AXP_PIN_BASE 1024
PD24的GPIO引腳號為:
96+24=120
在串口終端中的調試方法:
shell@octopus-f1:/ $
shell@octopus-f1:/ $ cd /sys/class/gpio/
shell@octopus-f1:/sys/class/gpio $ ll
--w------- root root 4096 1970-01-01 09:01 export
lrwxrwxrwx root root 1970-01-01 09:01 gpiochip0 -> ../../devices/platform/sunxi-pinctrl/gpio/gpiochip0
lrwxrwxrwx root root 1970-01-01 09:01 gpiochip1024 -> ../../devices/platform/axp-pinctrl/gpio/gpiochip1024
--w------- root root 4096 1970-01-01 09:01 unexport
shell@octopus-f1:/sys/class/gpio $
shell@octopus-f1:/sys/class/gpio $
(必須su權限:)
shell@octopus-sc5806:/sys/class/gpio $
shell@octopus-sc5806:/sys/class/gpio $ echo 120 > export
/system/bin/sh: can‘t create export: Permission denied
1|shell@octopus-sc5806:/sys/class/gpio $
1|shell@octopus-sc5806:/sys/class/gpio $ su
shell@octopus-sc5806:/sys/class/gpio #
shell@octopus-sc5806:/sys/class/gpio #
shell@octopus-sc5806:/sys/class/gpio # echo 120 > export
shell@octopus-sc5806:/sys/class/gpio # ll
--w------- root root 4096 1970-01-02 09:13 export
lrwxrwxrwx root root 1970-01-02 09:13 gpio120 -> ../../devices/platform/sunxi-pinctrl/gpio/gpio120
lrwxrwxrwx root root 1970-01-02 09:11 gpiochip0 -> ../../devices/platform/sunxi-pinctrl/gpio/gpiochip0
lrwxrwxrwx root root 1970-01-02 09:11 gpiochip1024 -> ../../devices/platform/axp-pinctrl/gpio/gpiochip1024
--w------- root root 4096 1970-01-02 09:11 unexport
shell@octopus-sc5806:/sys/class/gpio #
切換到DP24的目錄:
shell@octopus-sc5806:/sys/class/gpio # cd gpio120/
shell@octopus-sc5806:/sys/class/gpio/gpio120 # ll
-rw-r--r-- root root 4096 1970-01-02 09:14 active_low
lrwxrwxrwx root root 1970-01-02 09:14 device -> ../../../sunxi-pinctrl
-rw-r--r-- root root 4096 1970-01-02 09:14 direction
drwxr-xr-x root root 1970-01-02 09:14 power
lrwxrwxrwx root root 1970-01-02 09:14 subsystem -> ../../../../../class/gpio
-rw-r--r-- root root 4096 1970-01-02 09:14 uevent
-rw-r--r-- root root 4096 1970-01-02 09:14 value
shell@octopus-sc5806:/sys/class/gpio/gpio120 #
shell@octopus-sc5806:/sys/class/gpio/gpio120 # cat direction
in
shell@octopus-sc5806:/sys/class/gpio/gpio120 # echo out > direction
shell@octopus-sc5806:/sys/class/gpio/gpio120 #
shell@octopus-sc5806:/sys/class/gpio/gpio120 #
shell@octopus-sc5806:/sys/class/gpio/gpio120 # cat direction
out
shell@octopus-sc5806:/sys/class/gpio/gpio120 #
shell@octopus-sc5806:/sys/class/gpio/gpio120 #
shell@octopus-sc5806:/sys/class/gpio/gpio120 # cat value
0
shell@octopus-sc5806:/sys/class/gpio/gpio120 #
shell@octopus-sc5806:/sys/class/gpio/gpio120 # echo 1 > value
shell@octopus-sc5806:/sys/class/gpio/gpio120 #
shell@octopus-sc5806:/sys/class/gpio/gpio120 # cat value
1
shell@octopus-sc5806:/sys/class/gpio/gpio120 #
萬用表測得DP24為2.974V(高)
shell@octopus-sc5806:/sys/class/gpio/gpio120 # cat value
1
shell@octopus-sc5806:/sys/class/gpio/gpio120 # echo 0 > value
shell@octopus-sc5806:/sys/class/gpio/gpio120 # cat value
0
shell@octopus-sc5806:/sys/class/gpio/gpio120 #
萬用表測得DP24為0.000V(低)
全誌R58平臺的GPIO引腳控制