1、CM3计算板的IO资源
CM3支持的I/O管脚数为54个,每个管脚包括一个或多个复用功能,分别位于ALT0~ALT5,如下表:
2、设备树启用IO外设的方式
通过在/boot/config.txt 文件中描述IO行为,可以在系统启动时,初始化IO外设的初始状态,例如,配置为输入输出、上下拉状态以及复选功能。
The gpio directive allows GPIO pins to be set to specific modes and values at boot time in a way that would previously have needed a custom dt-blob.bin file. Each line applies the same settings (or at least makes the same changes) to a set of pins, either a single pin (3), a range of pins (3-4), or a comma-separated list of either (3-4,6,8). The pin set is followed by an = and one or more comma-separated attributes from this list:
- ip - Input
- op - Output
- a0-a5 - Alt0-Alt5
- dh - Driving high (for outputs)
- dl - Driving low (for outputs)
- pu - Pull up
- pd - Pull down
- pn/np - No pull
例如:
# 选择 复用功能2 Alt2 GPIO0~GPIO27
gpio=0-27=a2# 设置GPIO12 输出拉高
gpio=12=op,dh# 设置GPIO18 20 为输入上拉
gpio=18,20=pu# 设置GPIO17~GPIO21 为输入
gpio=17-21=ip
3、使用wiringPi C库对IO编程
- 安装最新wiringPi,安装方法见:安装wiringPi
- 使用gpio readall 查看是否读取到CM3的所有IO。
- 编程示例:CM3 GPIO27交替拉高拉低。
- 编译: gcc -c testGPIO3.c -o run -l wiringPi
- 执行:./run
#include <wiringPi.h>#define TEST_PIN 27int main(void)
{wiringPiSetup();pinMode(TEST_PIN, OUTPUT);while(1){digitalWrite(TEST_PIN, HIGH);delay(1000);digitalWrite(TEST_PIN, LOW);delay(1000);}return 0;
}