系统:Linux beaglebone 4.4.9-ti-r25 #1 SMP Thu May 5 23:08:13 UTC 2016 armv7l GNU/Linux
硬件:beagleboneblack
首先要使能gpio,如何查看想要的gpio是否已经使能了,也就是查看他的工作模式mode。在目录/sys/kernel/debug/pinctrl/44e10800.pinmux/pins可以查看,结合文档AM335x and AMIC110 Sitara™ Processors Technical Reference Manual (Rev. P).pdf的gpio相关内容。
如果gpio已经工作在mode7了,可以直接看使用gpio,如果gpio没有使能呢,就需要编辑设备树,来使能。例如使能P8_10,我的dtbs为:MY-GPIO-Example-00A0.dts
/dts-v1/;
/plugin/;
/{
compatible = "ti,beaglebone", "ti,beaglebone-black";
part-number = "MY-GPIO-Example";
version = "00A0";
fragment@0 {
target = <&am33xx_pinmux>;
__overlay__ {
my_example: MY_GPIO_Example {
pinctrl-single,pins = <
0x098 0x07 // P8_10 PINS$38 TIMER6 Output Mode7 pulldown
/* OUTPUT GPIO(mode7) 0x07 pulldown, 0x17 pullup, 0x?f no pullup/down */
/* INPUT GPIO(mode7) 0x27 pulldown, 0x37 pullup, 0x?f no pullup/down */
>;
};
};
};
fragment@1 {
target = <&ocp>;
__overlay__ {
gpio_helper {
compatible = "gpio-of-helper";
status = "okay";
pinctrl-names = "default";
pinctrl-0 = <&my_example>;
};
};
};
};
然后编译,我用的是 git clone https://github.com/beagleboard/bb.org-overlays,该项目可自动编译和拷贝(直接make和make install即可)。
dtbo生成到/lib/firmware后,使用命令echo MY-GPIO-Example > /sys/devices/platform/bone_capemgr/slots
P8_10的GPIONO是68,
1. echo 68 > /sys/class/gpio/export
2. echo out > /sys/class/gpio/gpio68/direction
3. echo 1 > /sys/class/gpio/gpio68/value
完成
最后参考两个网址,国外的,很有参考价值,国内很多blog都是翻译老外的:
https://github.com/jadonk/validation-scripts/blob/master/test-capemgr/README.md
https://vadl.github.io/beagleboneblack/2016/07/29/setting-up-bbb-gpio