qinyunti 发表于 2022-7-24 00:19

米尔MYC-YT507开发板测评:开发环境篇之一:Linux C按键控制LED

<h1><b>前言</b></h1>

<p style="">对于核心板或者开发板的选型我们一样会考虑二次开发的便捷性,开发环境,手册等的易用性和完整性。下面我们就从开发者的角度体验,从linux c开发,Qt开发,python开发等常见开发入手进行体验。</p>

<p style="">现在开始第一部分linux c开发环境的简单体验。</p>

<p style="">我这里使用WIN11+WSL2+Ubuntu 20.04进行开发。Ubuntu单独安装在E盘,而不是直接从应用商店下载安装(具体安装方法可以网络搜索,这里不再赘述),因为开发环境需要的空间较大,直接应用商店安装默认位于C盘会导致C盘空间不够,所以独立安装在空间较大的盘。</p>

<h1 style=""><b>准备</b></h1>

<h2 style=""><b>串口登录</b></h2>

<p style="">丝印Debug对应的TYPE-C USB口为调试串口,接到电脑。</p>

<p style="">&nbsp;</p>

<p style="">设置串口终端,我这里使用crt. 参数为115200-8-N-1.如果找不到COM则先网上搜索下载FTD21XX的驱动安装。登录到开发板。</p>

<p style="">&nbsp;</p>

<p style=""> &nbsp;</p>

<p style="">用户名为root无需密码</p>

<p style="">#</p>

<p style="">&nbsp;</p>

<h2 style=""><b>SSH登录</b></h2>

<p style="">网口接到丝印ENET2的网口</p>

<p style="">&nbsp;</p>

<p style="">串口终端中ifconfig查看IP</p>

<p style="">&nbsp;</p>

<p style=""> &nbsp;</p>

<p style="">开发板IP地址为169.254.127.228</p>

<p style="">我们将电脑的IP设置为同一网段169.254.127.227</p>

<p style="">&nbsp;</p>

<p style=""> &nbsp;</p>

<p style="">&nbsp;</p>

<p style="">开发板中ping电脑</p>

<p style=""> &nbsp;</p>

<p style="">&nbsp;</p>

<p style="">电脑中ping开发板</p>

<p style=""> &nbsp;</p>

<p style="">&nbsp;</p>

<p style=""><b>如果ping不通可以关闭电脑的防火墙</b></p>

<p style="">&nbsp;</p>

<p style=""><b>修改root用户密码</b></p>

<p style="">串口终端中输入passwd回车</p>

<p style="">输入123回车</p>

<p style="">继续输入123回车</p>

<p style="">将密码设置为了123</p>

<p style=""> &nbsp;</p>

<p style="">&nbsp;</p>

<p style="">使用CRT SSH登录</p>

<p style="">&nbsp;</p>

<p style=""> &nbsp;</p>

<p style=""> &nbsp;</p>

<p style=""> &nbsp;</p>

<p style="">密码为刚才设置的123</p>

<p style=""> &nbsp;</p>

<p style="">&nbsp;</p>

<h1 style=""><b>安装必备包</b></h1>

<p style="">进入WSL打开终端</p>

<p style="">sudo apt-get update</p>

<p style="">sudo apt-get install build-essential gcc libncurses5-dev bison flex texinfo</p>

<p style="">sudo apt-get install zlib1g-dev gettext libssl-dev autoconf</p>

<p style="">sudo apt-get install autoconf</p>

<p style="">sudo apt-get install automake</p>

<p style="">sudo apt-get install libtool</p>

<p style="">sudo apt-get install linux-libc-dev:i386</p>

<p style="">sudo apt-get install git</p>

<p style="">sudo apt-get install gnupg</p>

<p style="">sudo apt-get install flex</p>

<p style="">sudo apt-get install bison</p>

<p style="">sudo apt-get install gperf</p>

<p style="">sudo apt-get install build-essential</p>

<p style="">sudo apt-get install zip</p>

<p style="">sudo apt-get install curl</p>

<p style="">sudo apt-get install libc6-dev</p>

<p style="">sudo apt-get install libncurses5-dev:i386</p>

<p style="">sudo apt-get install x11proto-core-dev</p>

<p style="">sudo apt-get install libx11-dev:i386</p>

<p style="">sudo apt-get install libreadline6-dev:i386</p>

<p style="">sudo apt-get install libgl1-mesa-glx:i386</p>

<p style="">sudo apt-get install libgl1-mesa-dev</p>

<p style="">sudo apt-get install g++-multilib</p>

<p style="">sudo apt-get install mingw32</p>

<p style="">sudo apt-get install tofrodos</p>

<p style="">sudo apt-get install python-markdown</p>

<p style="">sudo apt-get install libxml2-utils</p>

<p style="">sudo apt-get install xsltproc</p>

<p style="">sudo apt-get install zlib1g-dev:i386</p>

<p style="">sudo apt-get install gawk</p>

<p style="">sudo apt-get install texinfo</p>

<p style="">sudo apt-get install gettext</p>

<p style="">&nbsp;</p>

<p style="">sudo dpkg-reconfigure dash #选择 no</p>

<p style="">sudo ln -s /usr/lib/i386-linux-gnu/mesa/libGL.so.1 /usr/lib/i386-linux-gnu/libGL.so</p>

<p style="">sudo apt-get install zlib1g-dev # 缺失 libz.so 时安装</p>

<p style="">sudo apt-get install uboot-mkimage # 缺失 mkimge 时安装或者安装 u-boot-tools</p>

<p style="">&nbsp;</p>

<h1 style=""><b>交叉编译环境安装</b></h1>

<p style="">windows下从http://down.myir-tech.com/MYD-YT507H/下载资料,其中03_Tools.zip解压</p>

<p style="">我这里解压后为E:\BOARD\MYC-YT507\03_Tools</p>

<p style="">将文件夹Complie Toolchain名字改为Complie_Toolchain因为linux中命令行文件名不能有空格。</p>

<p style="">&nbsp;</p>

<p style="">wsl中</p>

<p style="">cd ~</p>

<p style="">mkdir MYD-YT507H</p>

<p style="">cd MYD-YT507H/</p>

<p style="">&nbsp;</p>

<p style="">直接将windows下的文件解压到WSL中</p>

<p style="">tar -xvf /mnt/e/BOARD/MYC-YT507/03_Tools/Complie_Toolchain/gcc-linaro-7.4.1-2019.02-x86_64_aarch64-linux-gnu.tar.xz -C .</p>

<p style="">&nbsp;</p>

<p style="">export PATH=$PATH:~/MYD-YT507H/gcc-linaro-7.4.1-2019.02-x86_64_aarch64-linux-gnu/bin</p>

<p style="">&nbsp;</p>

<p style="">aarch64-linux-gnu-gcc -v</p>

<p style="">能看到打印信息说明安装成功。</p>

<h1 style=""><b>测试</b></h1>

<h2 style=""><b>编写代码</b></h2>

<p style="">以下代码实现按键控制LED的亮灭。</p>

<p style="">&nbsp;</p>

<p style="">led.c</p>

<p style="">#include&nbsp;&lt;linux/input.h&gt;&nbsp;</p>

<p style="">#include&nbsp;&lt;sys/types.h&gt;&nbsp;</p>

<p style="">#include&nbsp;&lt;sys/stat.h&gt;&nbsp;</p>

<p style="">#include&nbsp;&lt;fcntl.h&gt;&nbsp;</p>

<p style="">#include&nbsp;&lt;sys/ioctl.h&gt;&nbsp;</p>

<p style="">#include&nbsp;&lt;stdio.h&gt;&nbsp;</p>

<p style="">#include&nbsp;&lt;stdlib.h&gt;&nbsp;</p>

<p style="">#include&nbsp;&lt;string.h&gt;&nbsp;</p>

<p style="">#include&nbsp;&lt;unistd.h&gt;&nbsp;</p>

<p style="">/* ./key_led /dev/input/event0 noblock */&nbsp;</p>

<p style="">int&nbsp;main(int&nbsp;argc, char&nbsp;**argv)</p>

<p style="">{</p>

<p style="">&nbsp; &nbsp; int&nbsp;fd,bg_fd; int&nbsp;err, len, i;</p>

<p style="">&nbsp; &nbsp; unsigned&nbsp;char&nbsp;flag;</p>

<p style="">&nbsp; &nbsp; unsigned&nbsp;int&nbsp;data;</p>

<p style="">&nbsp; &nbsp; char&nbsp;*bg&nbsp;= &quot;/sys/class/leds/blue/brightness&quot;;</p>

<p style="">&nbsp; &nbsp; struct&nbsp;input_event&nbsp;event;</p>

<p style="">&nbsp; &nbsp; if&nbsp;(argc&nbsp;&lt; 2)</p>

<p style="">&nbsp; &nbsp; {</p>

<p style="">&nbsp; &nbsp; &nbsp; &nbsp; printf(&quot;Usage: %s&nbsp;&lt;dev&gt; \n&quot;, argv);</p>

<p style="">&nbsp; &nbsp; &nbsp; &nbsp; return&nbsp;-1;</p>

<p style="">&nbsp; &nbsp; }</p>

<p style="">&nbsp; &nbsp; if&nbsp;(argc&nbsp;== 3&nbsp;&amp;&amp; !strcmp(argv, &quot;noblock&quot;))</p>

<p style="">&nbsp; &nbsp; {</p>

<p style="">&nbsp; &nbsp; &nbsp; &nbsp; fd&nbsp;= open(argv, O_RDWR&nbsp;| O_NONBLOCK);</p>

<p style="">&nbsp; &nbsp; }</p>

<p style="">&nbsp; &nbsp; else&nbsp;</p>

<p style="">&nbsp; &nbsp; {</p>

<p style="">&nbsp; &nbsp; &nbsp; &nbsp; fd&nbsp;= open(argv, O_RDWR);</p>

<p style="">&nbsp; &nbsp; }</p>

<p style="">&nbsp; &nbsp; if&nbsp;(fd&nbsp;&lt; 0)</p>

<p style="">&nbsp; &nbsp; {</p>

<p style="">&nbsp; &nbsp; &nbsp; &nbsp; printf(&quot;open %s&nbsp;err\n&quot;, argv);</p>

<p style="">&nbsp; &nbsp; &nbsp; &nbsp; return&nbsp;-1;</p>

<p style="">&nbsp; &nbsp; }</p>

<p style="">&nbsp; &nbsp; while&nbsp;(1)</p>

<p style="">&nbsp; &nbsp; {</p>

<p style="">&nbsp; &nbsp; &nbsp; &nbsp; len&nbsp;= read(fd, &amp;event, sizeof(event));</p>

<p style="">&nbsp; &nbsp; &nbsp; &nbsp; if&nbsp;(event.type&nbsp;== EV_KEY)</p>

<p style="">&nbsp; &nbsp; &nbsp; &nbsp; {</p>

<p style="">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if&nbsp;(event.value&nbsp;== 1)//key down and up</p>

<p style="">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {</p>

<p style="">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; printf(&quot;key test \n&quot;);</p>

<p style="">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; bg_fd&nbsp;= open(bg, O_RDWR);</p>

<p style="">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if&nbsp;(bg_fd&nbsp;&lt; 0)</p>

<p style="">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {</p>

<p style="">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; printf(&quot;open %d&nbsp;err\n&quot;, bg_fd);</p>

<p style="">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return&nbsp;-1;</p>

<p style="">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }</p>

<p style="">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; read(bg_fd,&amp;flag,1);</p>

<p style="">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if(flag&nbsp;== &#39;0&#39;)</p>

<p style="">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; system(&quot;echo 1 &gt; /sys/class/leds/blue/brightness&quot;);&nbsp;//l ed off - 62 -</p>

<p style="">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; else&nbsp;system(&quot;echo 0 &gt; /sys/class/leds/blue/brightness &quot;);//led on</p>

<p style="">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }</p>

<p style="">&nbsp; &nbsp; &nbsp; &nbsp; }</p>

<p style="">&nbsp; &nbsp; }</p>

<p style="">&nbsp; &nbsp; return&nbsp;0;</p>

<p style="">}</p>

<p style="">&nbsp;</p>

<h2 style=""><b>编译</b></h2>

<p style="">aarch64-linux-gnu-gcc led.c -o led</p>

<h2 style=""><b>导入到开发板</b></h2>

<p style="">将编译后的程序led拷贝到windows下,再拷贝到开发板中</p>

<p style="">cp led /mnt/e</p>

<p style="">&nbsp;</p>

<p style="">&nbsp;</p>

<p style="">SSH登陆后</p>

<p style="">输入rz回车</p>

<p style="">选择程序文件led</p>

<p style="">点击Add</p>

<p style="">点击确定</p>

<p style=""> &nbsp;</p>

<p style="">&nbsp;</p>

<p style="">&nbsp;</p>

<p style="">&nbsp;</p>

<p style="">&nbsp;</p>

<h2 style=""><b>运行</b></h2>

<p style="">chmod +x led</p>

<p style="">./led /dev/input/event1&nbsp;noblock</p>

<p style="">&nbsp;</p>

<p style="">按下开发板上丝印ON/OFF的按键</p>

<p style="">则对应的蓝色的LED亮和灭。</p>

<p style="">&nbsp;</p>

<p style="">&nbsp;</p>

<h1 style=""><b>总结</b></h1>

<p style="">米尔的资料是比较友好和全面的,手册,开发环境等都比较详尽,能方便用户快速熟悉开发环境进行二次开发。</p>

<p style="">另外参考文档中《MYD-YT507H_Linux软件开发指南V1.1.pdf》中相关信息有误,比如</p>

<p style="">&nbsp;/dev/input/event0应该为&nbsp;/dev/input/event1</p>

<p style="">代码中/sys/class/leds/blue/brightness应该为</p>

<p style="">/sys/class/leds/heartbeat/brightness等,也没明确按键对应关系。</p>

<p style="">文档中也没有用户名密码等描述,所以需要手动修改root的密码等等,文档整体比较详细,但是一些细节还是需要尽可能描述清楚,并且保持更新。</p>

<h1 style=""><b>参考</b></h1>

<p style="">http://down.myir-tech.com/MYD-YT507H/</p>

<p style="">MYD-YT507H_Linux软件开发指南V1.1.pdf</p>

lugl4313820 发表于 2022-7-24 10:51

学习了,感米尔有好几款开发板,对应学习起来,还是需要很多时间。感谢分享!
页: [1]
查看完整版本: 米尔MYC-YT507开发板测评:开发环境篇之一:Linux C按键控制LED