<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[D1哪吒Debian系统内核驱动模块编译和使用（以CP210x USB to Serial 为例）]]></title><description><![CDATA[<p dir="auto">最近在使用哪吒D1开发板时遇到了一些USB转串口驱动上的小问题。</p>
<p dir="auto">方案基于PerfXLab的Debian系统进行开发，最近在测试2D LIDAR时发现内核中没有带USB转串口驱动，无法加载/dev/ttyUSB0设备，故需自行编译对应内核模块，具体步骤如下：</p>
<h2>1. Kernel源代码准备</h2>
<p dir="auto">PerfXLab的内核源代码已经在GitHub上开源（开源地址：<a href="https://github.com/rvboards/linux_kernel_for_d1" target="_blank" rel="noopener noreferrer nofollow ugc">https://github.com/rvboards/linux_kernel_for_d1</a> ），将代码clone到本地后，依README.md要求准备.config文件和board.dts文件</p>
<h2>2. 编译内核所需工具链准备</h2>
<p dir="auto">编译内核需要使用到D1的SDK工具，该工具可与全志客户服务中心下载，在步骤1仓库的README文件中亦有上传到百度云的工具链压缩包文件。解压工具链包后可以得到以下二进制文件以及对应库文件。</p>
<p dir="auto"><img src="/assets/uploads/files/1662343272189-053e725183dbce1f7aba0e9a7fc27f1a.png" alt="053e725183dbce1f7aba0e9a7fc27f1a.png" class=" img-responsive img-markdown" width="1333" height="930" /></p>
<p dir="auto">使用--version参数运行对应gcc程序，可以看到gcc的版本是8.1.0。</p>
<p dir="auto"><img src="/assets/uploads/files/1662343287790-847544d3dd3ded8f79fb5bb1d0915271.png" alt="847544d3dd3ded8f79fb5bb1d0915271.png" class=" img-responsive img-markdown" width="1012" height="550" /></p>
<h2>3. 配置内核</h2>
<p dir="auto">在内核目录下运行如下命令：</p>
<pre><code>make ARCH=riscv CROSS_COMPILE={工具链的bin目录}/riscv64-unknown-linux-gnu- menuconfig
</code></pre>
<p dir="auto">进入内核配置界面。在主界面按下/键搜索cp210x。</p>
<p dir="auto"><img src="/assets/uploads/files/1662343308291-0b892ee699b413c9d82f0bf19d1f1b4d.png" alt="0b892ee699b413c9d82f0bf19d1f1b4d.png" class=" img-responsive img-markdown" width="1068" height="791" /></p>
<p dir="auto">得到以下搜索结果：</p>
<p dir="auto"><img src="/assets/uploads/files/1662343321626-5021a4f46161a8a967371b0233f82c64.png" alt="5021a4f46161a8a967371b0233f82c64.png" class=" img-responsive img-markdown" width="1068" height="791" /></p>
<p dir="auto">将对应选项勾选为&lt;M&gt;，表示编译为内核模块。</p>
<p dir="auto"><img src="/assets/uploads/files/1662343330609-d64c388d78f2ec17cea2c2a075f9b890.png" alt="d64c388d78f2ec17cea2c2a075f9b890.png" class=" img-responsive img-markdown" width="1068" height="791" /></p>
<p dir="auto">之后使用命令</p>
<pre><code>make ARCH=riscv CROSS_COMPILE={工具链的bin目录}/riscv64-unknown-linux-gnu- -j$(nproc)
</code></pre>
<p dir="auto">完成内核编译工作。</p>
<p dir="auto">内核编译完成后，在内核目录的drivers/usb/serial文件夹下将出现<code>usbserial.ko</code>和<code>cp210x.ko</code>文件，将其复制到开发板上。</p>
<p dir="auto"><img src="/assets/uploads/files/1662343654385-195f9137942541fb5ecf9f414569ee17.png" alt="195f9137942541fb5ecf9f414569ee17.png" class=" img-responsive img-markdown" width="1355" height="930" /></p>
<h2>4. 内核模块加载</h2>
<p dir="auto">SSH进入哪吒开发板，首先使用lsmod查看当前加载的内核模块。</p>
<p dir="auto"><img src="/assets/uploads/files/1662343404240-39d7fb42bc46bc25d17afdfa5cbe1e4b.png" alt="39d7fb42bc46bc25d17afdfa5cbe1e4b.png" class=" img-responsive img-markdown" width="1068" height="929" /></p>
<p dir="auto">使用insmod命令按顺序加载usbserial.ko和cp210x.ko模块，之后使用lsmod查看加载的内核模块列表。</p>
<p dir="auto"><img src="/assets/uploads/files/1662343413757-2bf2c2c73b54378da41e534e06ed57bb.png" alt="2bf2c2c73b54378da41e534e06ed57bb.png" class=" img-responsive img-markdown" width="1068" height="836" /></p>
<p dir="auto">可以使用dmesg命令查看内核日志，日志中将显示cp210x模块已经成功加载。</p>
<p dir="auto"><img src="/assets/uploads/files/1662343438589-f473445761bac2a8f50c4ec6b2363fe2.png" alt="f473445761bac2a8f50c4ec6b2363fe2.png" class=" img-responsive img-markdown" width="1027" height="81" /></p>
<h2>5. 设备使用</h2>
<p dir="auto">插入cp210x设备，在内核日志中可以看到设备加载完成并被分配到ttyUSB0。</p>
<p dir="auto"><img src="/assets/uploads/files/1662343446787-24c12b3802446761fdc3e252dab74fb1.png" alt="24c12b3802446761fdc3e252dab74fb1.png" class=" img-responsive img-markdown" width="1023" height="218" /></p>
<p dir="auto">使用lsusb命令检查设备状态。</p>
<p dir="auto"><img src="/assets/uploads/files/1662343517689-926a140c4b7c59b484c28ba83db40ac1.png" alt="926a140c4b7c59b484c28ba83db40ac1.png" class=" img-responsive img-markdown" width="1068" height="584" /></p>
<p dir="auto">同样地，我们的ROS2应用程序可以正常运行并读取激光传感器输入。ROS2到D1开发板的移植部分将在后续博文中详细介绍。</p>
<p dir="auto"><img src="/assets/uploads/files/1662343524833-d53f3e3d9a601fab0a919a2bd1504a8f.png" alt="d53f3e3d9a601fab0a919a2bd1504a8f.png" class=" img-responsive img-markdown" width="1008" height="213" /></p>
<p dir="auto">原文链接：<a href="https://occ.t-head.cn/community/post/detail?spm=a2cl5.14300636.0.0.429d2846YxH5Fg&amp;id=4080021079526019072" target="_blank" rel="noopener noreferrer nofollow ugc">https://occ.t-head.cn/community/post/detail?spm=a2cl5.14300636.0.0.429d2846YxH5Fg&amp;id=4080021079526019072</a></p>
]]></description><link>https://bbs.aw-ol.com/topic/2040/d1哪吒debian系统内核驱动模块编译和使用-以cp210x-usb-to-serial-为例</link><generator>RSS for Node</generator><lastBuildDate>Thu, 14 May 2026 08:11:28 GMT</lastBuildDate><atom:link href="https://bbs.aw-ol.com/topic/2040.rss" rel="self" type="application/rss+xml"/><pubDate>Mon, 05 Sep 2022 02:06:11 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to D1哪吒Debian系统内核驱动模块编译和使用（以CP210x USB to Serial 为例） on Fri, 02 Dec 2022 09:21:52 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="https://bbs.aw-ol.com/uid/1424">@bayche</a> 在 <a href="/post/10084">D1哪吒Debian系统内核驱动模块编译和使用（以CP210x USB to Serial 为例）</a> 中说：</p>
<blockquote>
<p dir="auto">云的工具链压缩包文件。解压工</p>
</blockquote>
<p dir="auto">您好，大佬，我想请问驱动有了，指导对应的pwn和rst引脚，如何在设备树中给设备节点使能上电呢？</p>
]]></description><link>https://bbs.aw-ol.com/post/12627</link><guid isPermaLink="true">https://bbs.aw-ol.com/post/12627</guid><dc:creator><![CDATA[wanglang]]></dc:creator><pubDate>Fri, 02 Dec 2022 09:21:52 GMT</pubDate></item></channel></rss>