環(huán)境:Unbuntu20.4LTS
交叉編譯工具鏈:arm-linux-gnueabihf-gcc
軟件:VsCode
選擇下載交叉編譯工具鏈(我就按照其他教程下載配置的)
在開發(fā)板上配置sftp用于文件傳輸,將編譯完成的可執(zhí)行文件傳到開發(fā)板上運(yùn)行
通過其他教程學(xué)習(xí)了一下Makefile文件的構(gòu)成及簡單實(shí)現(xiàn),make編譯得到可執(zhí)行文件main
編寫gpio_test.c文件,這里參考了文章https://www.jianshu.com/p/e5ecd92c0787
#include 《stdio.h》 #include 《stdlib.h》 #include 《unistd.h》 #include 《sys/stat.h》 #include 《sys/types.h》 #include 《fcntl.h》 char *GPIO_PATH = “/sys/class/gpio/gpio43/value”; int main(int argc, char *argv[]) { int res = 0; int fd; char *path; printf(“Gpio test demo ”); if(argc 》= 2) { path = argv[1]; } else { path = GPIO_PATH; } fd = open(path, O_WRONLY); if(fd《0) { printf(“Failed to Open gpio %s/n”, path); exit(1); } while(1) { write(fd, “1”, 1); sleep(1); write(fd, “0”, 1); sleep(1); } close(fd); }
編寫Makefile文件進(jìn)行編譯
將生成的可執(zhí)行文件gpio_flash復(fù)制到開發(fā)板目錄中,不加任何參數(shù)運(yùn)行可以看到核心板上的LED閃爍
帶參數(shù)可以換一個(gè)gpio進(jìn)行控制
fqj
電子發(fā)燒友App




















































































評(píng)論