linux笔记(4):东山哪吒开发板(D1-H)测试gpio点亮LED
文章目录
参考文档:
1.作者:eydwyz,文章:《 用Rust探索RISC-V主板D1之GPIO》
2.全志官方文档: https://open.allwinnertech.com/#/doc?menuID=2&projectId=264
1.控制gpio电平高低的流程
1.1 选PB2控制LED,对应的编号是GPIO34
1.2 进入目录 /sys/class/gpio
cd /sys/class/gpio
查看目录内容:
> ls -l
total 0
--w------- 1 root root 4096 Jan 1 00:00 export
lrwxrwxrwx 1 root root 0 Jan 1 00:00 gpiochip0 -> ../../devi ces/platform/soc@3000000/2000000.pinctrl/gpio/gpiochip0
--w------- 1 root root 4096 Jan 1 00:00 unexport
1.3 生成gpio34目录
> echo 34 > export
> ls
export gpio34 gpiochip0 unexport
1.4 进入gpio34目录
> cd gpio34
> ls
active_low edge uevent
device power value
direction subsystem waiting_for_supplier
1.5 设置IO方向为输出
> echo "out" > direction //控制gpio变为输出功能
1.6 控制gpio34(PB2)电平高低
> echo 1 > value //在output模式下,输出低电平
> echo 0 > value //在output模式下,输出高电平
附录:linux的GPIO编号和D1-H的IO对应关系
首先要挂载调试工具debugfs:
mount -t debugfs none /sys/kernel/debug
然后就可以通过下面的命令获取这个表格:
cat /sys/kernel/debug/pinctrl/2000000.pinctrl/pins
pin 32 (PB0)
pin 33 (PB1)
pin 34 (PB2)
pin 35 (PB3)
pin 36 (PB4)
pin 37 (PB5)
pin 38 (PB6)
pin 39 (PB7)
pin 40 (PB8)
pin 41 (PB9)
pin 42 (PB10)
pin 43 (PB11)
pin 44 (PB12)
pin 64 (PC0)
pin 65 (PC1)
pin 66 (PC2)
pin 67 (PC3)
pin 68 (PC4)
pin 69 (PC5)
pin 70 (PC6)
pin 71 (PC7)
pin 96 (PD0)
pin 97 (PD1)
pin 98 (PD2)
pin 99 (PD3)
pin 100 (PD4)
pin 101 (PD5)
pin 102 (PD6)
pin 103 (PD7)
pin 104 (PD8)
pin 105 (PD9)
pin 106 (PD10)
pin 107 (PD11)
pin 108 (PD12)
pin 109 (PD13)
pin 110 (PD14)
pin 111 (PD15)
pin 112 (PD16)
pin 113 (PD17)
pin 114 (PD18)
pin 115 (PD19)
pin 116 (PD20)
pin 117 (PD21)
pin 118 (PD22)
pin 128 (PE0)
pin 129 (PE1)
pin 130 (PE2)
pin 131 (PE3)
pin 132 (PE4)
pin 133 (PE5)
pin 134 (PE6)
pin 135 (PE7)
pin 136 (PE8)
pin 137 (PE9)
pin 138 (PE10)
pin 139 (PE11)
pin 140 (PE12)
pin 141 (PE13)
pin 142 (PE14)
pin 143 (PE15)
pin 144 (PE16)
pin 145 (PE17)
pin 160 (PF0)
pin 161 (PF1)
pin 162 (PF2)
pin 163 (PF3)
pin 164 (PF4)
pin 165 (PF5)
pin 166 (PF6)
pin 192 (PG0)
pin 193 (PG1)
pin 194 (PG2)
pin 195 (PG3)
pin 196 (PG4)
pin 197 (PG5)
pin 198 (PG6)
pin 199 (PG7)
pin 200 (PG8)
pin 201 (PG9)
pin 202 (PG10)
pin 203 (PG11)
pin 204 (PG12)
pin 205 (PG13)
pin 206 (PG14)
pin 207 (PG15)
pin 208 (PG16)
pin 209 (PG17)
pin 210 (PG18)