前言
拿到一个板子后,点灯可以作为熟悉板子开发环境以及开发方式的一个过程。拿到板子中间阳了一段时间,现在继续开始测评。
环境搭建
安装官方资料包给的编译工具,但是装不上,在windows下载的,将文件直接拖到虚拟机导致文件损坏,可以通过其他方式传到虚拟机。
我这里安装的是gcc-aarch64-linux-gnu,直接使用sudo apt-get install命令安装即可。
硬件设计
在设计板子时,LED连接的是RZ_ET0_LINKSTA,并没有直接注明。
继续查看手册,发现是和核心板连接,没有说明连接的I/O口。
在核心板引脚列表中查到,LED连接的是P4_5引脚
软件设计
GPIO的使用,根据下图即可得到P4_5的引脚号为397
虚拟机下新建Helloworld.c文件,编写点灯程序
#include <fcntl.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <termio.h>
#include <sys/time.h>
#include <unistd.h>
#include <assert.h>
#include <errno.h>
#include <sys/mman.h>
#include <math.h>
int main(void)
{
__uint16_t i=0;
printf("Hello World\r\n");
system("echo 397 > /sys/class/gpio/export");
system("echo out > /sys/class/gpio/P4_5/direction");
for(;i<1000;i++)
{
system("echo 1 > /sys/class/gpio/P4_5/value");
sleep(1);
system("echo 0 > /sys/class/gpio/P4_5/value");
sleep(1);
}
}
编译
生成可执行文件
SSH连接开发板
通过串口终端查看板子的IP
使用MobaXterm终端建立SSH连接。
将刚才编译的可执行文件直接拖过来,将文件赋权限,chmod u+x helloworld
结果
LED
|