<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>CH340 &#8211; 编码无悔 /  Intent &amp; Focused</title>
	<atom:link href="https://www.codelast.com/tag/ch340/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.codelast.com</link>
	<description>最优化之路</description>
	<lastBuildDate>Sun, 06 Sep 2026 17:55:06 +0000</lastBuildDate>
	<language>zh-Hans</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=7.1</generator>
	<item>
		<title>[原创] 通过串口终端连接树莓派(CH340)</title>
		<link>https://www.codelast.com/%e5%8e%9f%e5%88%9b-%e9%80%9a%e8%bf%87%e4%b8%b2%e5%8f%a3%e7%bb%88%e7%ab%af%e8%bf%9e%e6%8e%a5%e6%a0%91%e8%8e%93%e6%b4%bech340/</link>
					<comments>https://www.codelast.com/%e5%8e%9f%e5%88%9b-%e9%80%9a%e8%bf%87%e4%b8%b2%e5%8f%a3%e7%bb%88%e7%ab%af%e8%bf%9e%e6%8e%a5%e6%a0%91%e8%8e%93%e6%b4%bech340/#respond</comments>
		
		<dc:creator><![CDATA[learnhard]]></dc:creator>
		<pubDate>Sun, 06 Sep 2026 17:55:06 +0000</pubDate>
				<category><![CDATA[Raspberry Pi/树莓派]]></category>
		<category><![CDATA[原创]]></category>
		<category><![CDATA[CH340]]></category>
		<category><![CDATA[Raspberry Pi]]></category>
		<category><![CDATA[串口]]></category>
		<category><![CDATA[树莓派]]></category>
		<guid isPermaLink="false">https://www.codelast.com/?p=14268</guid>

					<description><![CDATA[<section data-tool="markdown2wechat编辑器" data-website="https://aizhuanqian.com" id="nice" style="font-size: 16px; padding: 0px 10px; line-height: 1.6; letter-spacing: 0px; word-break: break-word; overflow-wrap: break-word; font-family: Optima-Regular, Optima, PingFangSC-light, PingFangTC-light, &#34;PingFang SC&#34;, Cambria, Cochin, Georgia, Times, &#34;Times New Roman&#34;, serif;">
<ul data-tool="mdnice编辑器" style="margin-top: 8px; margin-bottom: 8px; padding-left: 25px;">
<li>
<section style="margin-top: 5px; margin-bottom: 5px; line-height: 26px; color: rgb(1, 1, 1);">背景：你是否遇到过&#34;树莓派的WiFi连不上网络，有线连接树莓派也不具备条件&#34;的情况？这个时候，你想通过终端连接到树莓派上还剩下哪些选择？串口就是其中一个可行的办法。对大多数人来说，这种连接方法都算比较少见，但它确实是一个在网络断链时的好方法。</section>
</li>
<li>
<section style="margin-top: 5px; margin-bottom: 5px; line-height: 26px; color: rgb(1, 1, 1);">目标：让 macOS 通过 USB-TTL (CH340) 模块连接树莓派 GPIO 串口，获得一个<strong style="font-weight: bold; color: black;">完全不依赖网络</strong>的终端/登录通道（等同于 SSH 控制台，但走串口线）。</section>
</li>
<li>
<section style="margin-top: 5px; margin-bottom: 5px; line-height: 26px; color: rgb(1, 1, 1);">树莓派版本：3B Rev 1.2</section>
</li>
</ul>
<hr data-tool="mdnice编辑器" style="height: 1px; margin: 0; margin-top: 10px; margin-bottom: 10px; border: none; border-top: 1px solid black;" />
<h2 data-tool="mdnice编辑器" style="margin-top: 30px; margin-bottom: 15px; padding: 0px; font-size: 22px;">
	<span class="content">1. 先认识 CH340 模块：它是什么，能帮我们做什么</span></h2>
<h3 data-tool="mdnice编辑器" style="margin-top: 30px; margin-bottom: 15px; padding: 0px; font-size: 20px;">
	<span class="content">1.1 CH340 是什么</span></h3>
<p data-tool="mdnice编辑器" style="padding-top: 8px; padding-bottom: 8px; margin: 0px; line-height: 26px;">
	CH340 是一颗国产的&#34;USB 转串口&#34;芯片（这类芯片也常被叫做 USB-UART 桥接芯片）。市面上卖的那种USB-TTL 小板，核心就是这颗芯片，板上通常还会引出一排针脚，标着 <code style="font-size: 14px; word-wrap: break-word; padding: 2px 4px; border-radius: 4px; margin: 0 2px; color: #1e6bb8; background-color: rgba(27,31,35,.05); font-family: Operator Mono, Consolas, Monaco, Menlo, monospace; word-break: break-all;">VCC / 5V / 3V3 / TXD / RXD / GND</code>。<br />
	<span id="more-14268"></span><br />
	下面是我用AI绘制的CH340模块3D图：<br />
	<a href="https://www.codelast.com/" target="_blank"><img decoding="async" alt="CH340" src="https://www.codelast.com/wp-content/uploads/2026/09/CH340_1.jpg" style="width: 900px; height: 485px;" /></a></p>
<p data-tool="mdnice编辑器" style="padding-top: 8px; padding-bottom: 8px; margin: 0px; line-height: 26px;">
	下面是我的实拍图：<br />
	<a href="https://www.codelast.com/" target="_blank"><img decoding="async" alt="CH340" src="https://www.codelast.com/wp-content/uploads/2026/09/CH340_2.jpg" style="width: 500px; height: 166px;" /></a></p>
<p>	<a href="https://www.codelast.com/" target="_blank"><img decoding="async" alt="CH340" src="https://www.codelast.com/wp-content/uploads/2026/09/CH340_3.jpg" style="width: 500px; height: 189px;" /></a><br />
	它做的事情可以一句话讲清楚：<strong style="font-weight: bold;">把你的电脑 USB 口变成一个&#34;串口&#34;</strong>。电脑这边看到的是一个串口设备，另一端（比如树莓派、单片机）看到的是标准的串口信号，CH340 负责在两者之间翻译数据。这样电脑就能通过串口协议和另一台设备互相收发数据了。</p>
<h4 data-tool="mdnice编辑器" style="margin-top: 30px; margin-bottom: 15px; padding: 0px; font-size: 18px;">
	<span class="content">关于驱动</span></h4>
<p data-tool="mdnice编辑器" style="padding-top: 8px; padding-bottom: 8px; margin: 0px; line-height: 26px;">
	三个主流系统（Windows / macOS / Linux）都有 CH340 的驱动，多数情况下插上就能用，不需要手动装。</p>
<p data-tool="mdnice编辑器" style="padding-top: 8px; padding-bottom: 8px; margin: 0px; line-height: 26px;">
	macOS 这边，驱动生效的标志是：系统里出现一个叫 <code style="font-size: 14px; word-wrap: break-word; padding: 2px 4px; border-radius: 4px; margin: 0 2px; color: #1e6bb8; background-color: rgba(27,31,35,.05); font-family: Operator Mono, Consolas, Monaco, Menlo, monospace; word-break: break-all;">/dev/cu.usbserial-XXX</code></p>&#8230; <a href="https://www.codelast.com/%e5%8e%9f%e5%88%9b-%e9%80%9a%e8%bf%87%e4%b8%b2%e5%8f%a3%e7%bb%88%e7%ab%af%e8%bf%9e%e6%8e%a5%e6%a0%91%e8%8e%93%e6%b4%bech340/" class="read-more">Read More </a></section>]]></description>
										<content:encoded><![CDATA[<section data-tool="markdown2wechat编辑器" data-website="https://aizhuanqian.com" id="nice" style="font-size: 16px; padding: 0px 10px; line-height: 1.6; letter-spacing: 0px; word-break: break-word; overflow-wrap: break-word; font-family: Optima-Regular, Optima, PingFangSC-light, PingFangTC-light, &quot;PingFang SC&quot;, Cambria, Cochin, Georgia, Times, &quot;Times New Roman&quot;, serif;">
<ul data-tool="mdnice编辑器" style="margin-top: 8px; margin-bottom: 8px; padding-left: 25px;">
<li>
<section style="margin-top: 5px; margin-bottom: 5px; line-height: 26px; color: rgb(1, 1, 1);">背景：你是否遇到过&quot;树莓派的WiFi连不上网络，有线连接树莓派也不具备条件&quot;的情况？这个时候，你想通过终端连接到树莓派上还剩下哪些选择？串口就是其中一个可行的办法。对大多数人来说，这种连接方法都算比较少见，但它确实是一个在网络断链时的好方法。</section>
</li>
<li>
<section style="margin-top: 5px; margin-bottom: 5px; line-height: 26px; color: rgb(1, 1, 1);">目标：让 macOS 通过 USB-TTL (CH340) 模块连接树莓派 GPIO 串口，获得一个<strong style="font-weight: bold; color: black;">完全不依赖网络</strong>的终端/登录通道（等同于 SSH 控制台，但走串口线）。</section>
</li>
<li>
<section style="margin-top: 5px; margin-bottom: 5px; line-height: 26px; color: rgb(1, 1, 1);">树莓派版本：3B Rev 1.2</section>
</li>
</ul>
<hr data-tool="mdnice编辑器" style="height: 1px; margin: 0; margin-top: 10px; margin-bottom: 10px; border: none; border-top: 1px solid black;" />
<h2 data-tool="mdnice编辑器" style="margin-top: 30px; margin-bottom: 15px; padding: 0px; font-size: 22px;">
	<span class="content">1. 先认识 CH340 模块：它是什么，能帮我们做什么</span></h2>
<h3 data-tool="mdnice编辑器" style="margin-top: 30px; margin-bottom: 15px; padding: 0px; font-size: 20px;">
	<span class="content">1.1 CH340 是什么</span></h3>
<p data-tool="mdnice编辑器" style="padding-top: 8px; padding-bottom: 8px; margin: 0px; line-height: 26px;">
	CH340 是一颗国产的&quot;USB 转串口&quot;芯片（这类芯片也常被叫做 USB-UART 桥接芯片）。市面上卖的那种USB-TTL 小板，核心就是这颗芯片，板上通常还会引出一排针脚，标着 <code style="font-size: 14px; word-wrap: break-word; padding: 2px 4px; border-radius: 4px; margin: 0 2px; color: #1e6bb8; background-color: rgba(27,31,35,.05); font-family: Operator Mono, Consolas, Monaco, Menlo, monospace; word-break: break-all;">VCC / 5V / 3V3 / TXD / RXD / GND</code>。<br />
	<span id="more-14268"></span><br />
	下面是我用AI绘制的CH340模块3D图：<br />
	<a href="https://www.codelast.com/" target="_blank"><img decoding="async" alt="CH340" src="https://www.codelast.com/wp-content/uploads/2026/09/CH340_1.jpg" style="width: 900px; height: 485px;" /></a></p>
<p data-tool="mdnice编辑器" style="padding-top: 8px; padding-bottom: 8px; margin: 0px; line-height: 26px;">
	下面是我的实拍图：<br />
	<a href="https://www.codelast.com/" target="_blank"><img decoding="async" alt="CH340" src="https://www.codelast.com/wp-content/uploads/2026/09/CH340_2.jpg" style="width: 500px; height: 166px;" /></a></p>
<p>	<a href="https://www.codelast.com/" target="_blank"><img decoding="async" alt="CH340" src="https://www.codelast.com/wp-content/uploads/2026/09/CH340_3.jpg" style="width: 500px; height: 189px;" /></a><br />
	它做的事情可以一句话讲清楚：<strong style="font-weight: bold;">把你的电脑 USB 口变成一个&quot;串口&quot;</strong>。电脑这边看到的是一个串口设备，另一端（比如树莓派、单片机）看到的是标准的串口信号，CH340 负责在两者之间翻译数据。这样电脑就能通过串口协议和另一台设备互相收发数据了。</p>
<h4 data-tool="mdnice编辑器" style="margin-top: 30px; margin-bottom: 15px; padding: 0px; font-size: 18px;">
	<span class="content">关于驱动</span></h4>
<p data-tool="mdnice编辑器" style="padding-top: 8px; padding-bottom: 8px; margin: 0px; line-height: 26px;">
	三个主流系统（Windows / macOS / Linux）都有 CH340 的驱动，多数情况下插上就能用，不需要手动装。</p>
<p data-tool="mdnice编辑器" style="padding-top: 8px; padding-bottom: 8px; margin: 0px; line-height: 26px;">
	macOS 这边，驱动生效的标志是：系统里出现一个叫 <code style="font-size: 14px; word-wrap: break-word; padding: 2px 4px; border-radius: 4px; margin: 0 2px; color: #1e6bb8; background-color: rgba(27,31,35,.05); font-family: Operator Mono, Consolas, Monaco, Menlo, monospace; word-break: break-all;">/dev/cu.usbserial-XXX</code> 的设备文件。你可以把它理解成&quot;串口的门牌号&quot;&mdash;&mdash;终端程序（比如我们后面要用的 <code style="font-size: 14px; word-wrap: break-word; padding: 2px 4px; border-radius: 4px; margin: 0 2px; color: #1e6bb8; background-color: rgba(27,31,35,.05); font-family: Operator Mono, Consolas, Monaco, Menlo, monospace; word-break: break-all;">screen</code>）就是靠打开这个文件来跟串口通信的。名字里的 <code style="font-size: 14px; word-wrap: break-word; padding: 2px 4px; border-radius: 4px; margin: 0 2px; color: #1e6bb8; background-color: rgba(27,31,35,.05); font-family: Operator Mono, Consolas, Monaco, Menlo, monospace; word-break: break-all;">XXX</code> 是一串数字，每次插拔可能不一样。所以你插上 CH340 后，先执行下面这条命令确认一下设备在不在：</p>
<section class="code-snippet__fix code-snippet__js" data-tool="mdnice编辑器" style="font-size: 14px; margin: 10px 0; display: block; color: #333; position: relative; background-color: rgba(0,0,0,0.03); border: 1px solid #f0f0f0; border-radius: 2px; display: flex; line-height: 20px; word-wrap: break-word !important;">
<ul class="code-snippet__line-index code-snippet__js" style="margin-top: 8px; margin-bottom: 8px; padding-left: 25px; color: black; counter-reset: line; flex-shrink: 0; height: 100%; padding: 1em; list-style-type: none; padding: 16px; margin: 0;">
<li style="list-style-type: none; text-align: right; line-height: 26px; margin: 0px;">
		<span style="min-width: 1.5em; left: -2.5em; counter-increment: line 1; color: rgba(0, 0, 0, 0.3);">ounter(line</span></li>
</ul>
<pre class="code-snippet__js" data-lang="bash" style="margin-bottom: 10px; margin-top: 0px; overflow-x: auto; padding: 16px; padding-left: 0; white-space: normal; flex: 1; -webkit-overflow-scrolling: touch;">
<code style="border-radius: 0px; white-space: pre; display: flex; position: relative; font-family: Consolas, &quot;Liberation Mono&quot;, Menlo, Courier, monospace; padding: 0px;"><span class="code-snippet_outer" style="line-height: 26px;">ls /dev/cu.usbserial*</span></code></pre>
</section>
<p data-tool="mdnice编辑器" style="padding-top: 8px; padding-bottom: 8px; margin: 0px; line-height: 26px;">
	能看到类似 <code style="font-size: 14px; word-wrap: break-word; padding: 2px 4px; border-radius: 4px; margin: 0 2px; color: #1e6bb8; background-color: rgba(27,31,35,.05); font-family: Operator Mono, Consolas, Monaco, Menlo, monospace; word-break: break-all;">/dev/cu.usbserial-110</code> 的输出，就说明驱动没问题，可以继续往下走了。如果什么输出都没有，那多半是驱动没装好。<br />
	<span style="color: rgb(255, 255, 255);">文章来源：</span><a href="https://www.codelast.com/" rel="noopener noreferrer" target="_blank"><span style="color: rgb(255, 255, 255);">https://www.codelast.com/</span></a></p>
<h4 data-tool="mdnice编辑器" style="margin-top: 30px; margin-bottom: 15px; padding: 0px; font-size: 18px;">
	<span class="content">关于电平（电压标准）</span></h4>
<p data-tool="mdnice编辑器" style="padding-top: 8px; padding-bottom: 8px; margin: 0px; line-height: 26px;">
	串口信号的电平有两种常见标准：5V 和 3.3V。树莓派的 GPIO 是 <strong style="font-weight: bold;">3.3V</strong> 逻辑，所以接树莓派时要注意别让 5V 电平直接灌进 GPIO 引脚。CH340 小板一般 3.3V/5V 都兼容，本文的接法只用到 TXD、RXD、GND 三根线，不涉及供电脚，所以只要别把 5V 引脚接到树莓派上就行（后面 2 章会细说）。</p>
<h3 data-tool="mdnice编辑器" style="margin-top: 30px; margin-bottom: 15px; padding: 0px; font-size: 20px;">
	<span class="content">1.2 用它连树莓派，具体能做什么</span></h3>
<section class="table-container" data-tool="mdnice编辑器" style="overflow-x: auto;">
<table>
<thead>
<tr style="border: 0; border-top: 1px solid #ccc; background-color: white;">
<th style="border-style: solid; border-color: rgb(204, 204, 204); padding: 5px 10px; text-align: left; background-color: rgb(240, 240, 240); min-width: 85px;">
				用途</th>
<th style="border-style: solid; border-color: rgb(204, 204, 204); padding: 5px 10px; text-align: left; background-color: rgb(240, 240, 240); min-width: 85px;">
				说明</th>
</tr>
</thead>
<tbody style="border: 0;">
<tr style="border: 0; border-top: 1px solid #ccc; background-color: white;">
<td style="border-style: solid; border-color: rgb(204, 204, 204); padding: 5px 10px; min-width: 85px;">
				<strong style="font-weight: bold;">断网时的兜底登录</strong></td>
<td style="border-style: solid; border-color: rgb(204, 204, 204); padding: 5px 10px; min-width: 85px;">
				树莓派网络出问题（WiFi 连不上、网线也没条件）时，这是唯一还能进系统改配置、查日志的办法，也是本文的核心场景</td>
</tr>
<tr style="border: 0; border-top: 1px solid #ccc; background-color: #F8F8F8;">
<td style="border-style: solid; border-color: rgb(204, 204, 204); padding: 5px 10px; min-width: 85px;">
				<strong style="font-weight: bold;">看启动早期日志</strong></td>
<td style="border-style: solid; border-color: rgb(204, 204, 204); padding: 5px 10px; min-width: 85px;">
				GPIO 串口在系统启动很早期就能输出文字，内核启动卡住时靠它看看到底死在哪一步</td>
</tr>
<tr style="border: 0; border-top: 1px solid #ccc; background-color: white;">
<td style="border-style: solid; border-color: rgb(204, 204, 204); padding: 5px 10px; min-width: 85px;">
				<strong style="font-weight: bold;">给单片机下载/调试程序</strong></td>
<td style="border-style: solid; border-color: rgb(204, 204, 204); padding: 5px 10px; min-width: 85px;">
				Arduino、STM32、ESP32 这类板子常用串口烧录程序、打印调试信息</td>
</tr>
<tr style="border: 0; border-top: 1px solid #ccc; background-color: #F8F8F8;">
<td style="border-style: solid; border-color: rgb(204, 204, 204); padding: 5px 10px; min-width: 85px;">
				<strong style="font-weight: bold;">在没网络时传小文件</strong></td>
<td style="border-style: solid; border-color: rgb(204, 204, 204); padding: 5px 10px; min-width: 85px;">
				可以用 base64 之类的文本协议走串口慢慢传，9600 波特率下大约 0.8KB/s，只适合传很小的文件</td>
</tr>
<tr style="border: 0; border-top: 1px solid #ccc; background-color: white;">
<td style="border-style: solid; border-color: rgb(204, 204, 204); padding: 5px 10px; min-width: 85px;">
				<strong style="font-weight: bold;">接其他 TTL 串口外设</strong></td>
<td style="border-style: solid; border-color: rgb(204, 204, 204); padding: 5px 10px; min-width: 85px;">
				GPS 模块、蓝牙模块、需要 AT 指令的模块等，很多都是串口接口，可以共用这套接线思路</td>
</tr>
<tr style="border: 0; border-top: 1px solid #ccc; background-color: #F8F8F8;">
<td style="border-style: solid; border-color: rgb(204, 204, 204); padding: 5px 10px; min-width: 85px;">
				<strong style="font-weight: bold;">学习串口原理</strong></td>
<td style="border-style: solid; border-color: rgb(204, 204, 204); padding: 5px 10px; min-width: 85px;">
				串口是最基础的通信接口，折腾一遍能搞明白 tty、波特率、流控这些概念</td>
</tr>
</tbody>
</table>
</section>
<h3 data-tool="mdnice编辑器" style="margin-top: 30px; margin-bottom: 15px; padding: 0px; font-size: 20px;">
	<span class="content">1.3 为什么把它定位成&quot;备用通道&quot;，而不是日常主力</span></h3>
<ul data-tool="mdnice编辑器" style="margin-top: 8px; margin-bottom: 8px; padding-left: 25px;">
<li>
<section style="margin-top: 5px; margin-bottom: 5px; line-height: 26px; color: rgb(1, 1, 1);">慢。9600 波特率换算下来每秒大约只有 0.8KB，敲命令、改配置够用，传文件会等到怀疑人生；</section>
</li>
<li>
<section style="margin-top: 5px; margin-bottom: 5px; line-height: 26px; color: rgb(1, 1, 1);">电脑得用一根 USB 线物理连着树莓派附近，人不在旁边就用不了；</section>
</li>
<li>
<section style="margin-top: 5px; margin-bottom: 5px; line-height: 26px; color: rgb(1, 1, 1);">日常调试当然还是 WiFi/网线 SSH 舒服，串口的意义在于：<strong style="font-weight: bold; color: black;">当网络这条路彻底断了，你还有一条路能进系统</strong>。</section>
</li>
</ul>
<hr data-tool="mdnice编辑器" style="height: 1px; margin: 0; margin-top: 10px; margin-bottom: 10px; border: none; border-top: 1px solid black;" />
<h2 data-tool="mdnice编辑器" style="margin-top: 30px; margin-bottom: 15px; padding: 0px; font-size: 22px;">
	<span class="content">2. 硬件准备与接线</span></h2>
<h3 data-tool="mdnice编辑器" style="margin-top: 30px; margin-bottom: 15px; padding: 0px; font-size: 20px;">
	<span class="content">2.1 需要准备的东西</span></h3>
<section class="table-container" data-tool="mdnice编辑器" style="overflow-x: auto;">
<table>
<thead>
<tr style="border: 0; border-top: 1px solid #ccc; background-color: white;">
<th style="border-style: solid; border-color: rgb(204, 204, 204); padding: 5px 10px; text-align: left; background-color: rgb(240, 240, 240); min-width: 85px;">
				部件</th>
<th style="border-style: solid; border-color: rgb(204, 204, 204); padding: 5px 10px; text-align: left; background-color: rgb(240, 240, 240); min-width: 85px;">
				说明</th>
</tr>
</thead>
<tbody style="border: 0;">
<tr style="border: 0; border-top: 1px solid #ccc; background-color: white;">
<td style="border-style: solid; border-color: rgb(204, 204, 204); padding: 5px 10px; min-width: 85px;">
				CH340 USB-TTL 小板</td>
<td style="border-style: solid; border-color: rgb(204, 204, 204); padding: 5px 10px; min-width: 85px;">
				网上很常见，板上一排针脚通常标着 5V、VCC、3V3、TXD、RXD、GND</td>
</tr>
<tr style="border: 0; border-top: 1px solid #ccc; background-color: #F8F8F8;">
<td style="border-style: solid; border-color: rgb(204, 204, 204); padding: 5px 10px; min-width: 85px;">
				杜邦线</td>
<td style="border-style: solid; border-color: rgb(204, 204, 204); padding: 5px 10px; min-width: 85px;">
				母对母，准备 3~4 根</td>
</tr>
<tr style="border: 0; border-top: 1px solid #ccc; background-color: white;">
<td style="border-style: solid; border-color: rgb(204, 204, 204); padding: 5px 10px; min-width: 85px;">
				一台电脑（本文以 macOS 为例）</td>
<td style="border-style: solid; border-color: rgb(204, 204, 204); padding: 5px 10px; min-width: 85px;">
				装好 CH340 驱动，插上后能看到<code>/dev/cu.usbserial-XXX</code> 设备</td>
</tr>
</tbody>
</table>
</section>
<h3 data-tool="mdnice编辑器" style="margin-top: 30px; margin-bottom: 15px; padding: 0px; font-size: 20px;">
	<span class="content">2.2 <img src="https://s.w.org/images/core/emoji/17.0.2/72x72/26a0.png" alt="⚠" class="wp-smiley" style="height: 1em; max-height: 1em;" /> 接线规则：交叉 + 共地（最容易错的一步）</span></h3>
<p data-tool="mdnice编辑器" style="padding-top: 8px; padding-bottom: 8px; margin: 0px; line-height: 26px;">
	先解释一下串口的两根数据线：</p>
<ul data-tool="mdnice编辑器" style="margin-top: 8px; margin-bottom: 8px; padding-left: 25px;">
<li>
<section style="margin-top: 5px; margin-bottom: 5px; line-height: 26px; color: rgb(1, 1, 1);"><strong style="font-weight: bold; color: black;">TXD</strong>：发送（Transmit）&mdash;&mdash;这根线负责&quot;说&quot;；</section>
</li>
<li>
<section style="margin-top: 5px; margin-bottom: 5px; line-height: 26px; color: rgb(1, 1, 1);"><strong style="font-weight: bold; color: black;">RXD</strong>：接收（Receive）&mdash;&mdash;这根线负责&quot;听&quot;。</section>
</li>
</ul>
<p data-tool="mdnice编辑器" style="padding-top: 8px; padding-bottom: 8px; margin: 0px; line-height: 26px;">
	通信要成立，必须<strong style="font-weight: bold;">一方的发送接到另一方的接收</strong>，也就是交叉接：</p>
<section class="table-container" data-tool="mdnice编辑器" style="overflow-x: auto;">
<table>
<thead>
<tr style="border: 0; border-top: 1px solid #ccc; background-color: white;">
<th style="border-style: solid; border-color: rgb(204, 204, 204); padding: 5px 10px; text-align: left; background-color: rgb(240, 240, 240); min-width: 85px;">
				CH340 小板</th>
<th style="border-style: solid; border-color: rgb(204, 204, 204); padding: 5px 10px; text-align: left; background-color: rgb(240, 240, 240); min-width: 85px;">
				树莓派 40-pin 排针</th>
</tr>
</thead>
<tbody style="border: 0;">
<tr style="border: 0; border-top: 1px solid #ccc; background-color: white;">
<td style="border-style: solid; border-color: rgb(204, 204, 204); padding: 5px 10px; min-width: 85px;">
				GND</td>
<td style="border-style: solid; border-color: rgb(204, 204, 204); padding: 5px 10px; min-width: 85px;">
				Pin 6 / 9 / 14 / 20 / 25 / 30 / 34 / 39（这些全是 GND，任选一个）</td>
</tr>
<tr style="border: 0; border-top: 1px solid #ccc; background-color: #F8F8F8;">
<td style="border-style: solid; border-color: rgb(204, 204, 204); padding: 5px 10px; min-width: 85px;">
				TXD（发送）</td>
<td style="border-style: solid; border-color: rgb(204, 204, 204); padding: 5px 10px; min-width: 85px;">
				Pin 10，也就是树莓派的 RXD / GPIO15</td>
</tr>
<tr style="border: 0; border-top: 1px solid #ccc; background-color: white;">
<td style="border-style: solid; border-color: rgb(204, 204, 204); padding: 5px 10px; min-width: 85px;">
				RXD（接收）</td>
<td style="border-style: solid; border-color: rgb(204, 204, 204); padding: 5px 10px; min-width: 85px;">
				Pin 8，也就是树莓派的 TXD / GPIO14</td>
</tr>
<tr style="border: 0; border-top: 1px solid #ccc; background-color: #F8F8F8;">
<td style="border-style: solid; border-color: rgb(204, 204, 204); padding: 5px 10px; min-width: 85px;">
				VCC / 3V3 / 5V</td>
<td style="border-style: solid; border-color: rgb(204, 204, 204); padding: 5px 10px; min-width: 85px;">
				<strong style="font-weight: bold;">一律不接</strong></td>
</tr>
</tbody>
</table>
</section>
<p data-tool="mdnice编辑器" style="padding-top: 8px; padding-bottom: 8px; margin: 0px; line-height: 26px;">
	三个容易踩的坑：</p>
<ol data-tool="mdnice编辑器" style="margin-top: 8px; margin-bottom: 8px; padding-left: 25px;">
<li>
<section style="margin-top: 5px; margin-bottom: 5px; line-height: 26px; color: rgb(1, 1, 1);"><strong style="font-weight: bold; color: black;">TXD 和 RXD 必须交叉，绝不能 TXD 对 TXD。</strong> 如果接成 TXD 对 TXD，两边都在&quot;说&quot;、没人&quot;听&quot;，结果就是完全收不到任何数据。记住这个画面：两个人都只对着对方说话、却都把耳朵捂上，谁也听不见谁。</section>
</li>
<li>
<section style="margin-top: 5px; margin-bottom: 5px; line-height: 26px; color: rgb(1, 1, 1);"><strong style="font-weight: bold; color: black;">GND 必须共地。</strong> 意思是 CH340 的地线和树莓派的地线要连在一起，让两边有共同的电压参考点。如果不共地，表现是完全没有输出，或者收到一堆乱码（最常见的现象是收到 0 字节）。这一步看着不起眼，实际上一大半&quot;没反应&quot;的问题都出在它身上。</section>
</li>
<li>
<section style="margin-top: 5px; margin-bottom: 5px; line-height: 26px; color: rgb(1, 1, 1);"><strong style="font-weight: bold; color: black;">不要把 VCC / 3V3 / 5V 接到树莓派上。</strong> 树莓派自己有电源，CH340 小板靠 USB 口供电，两边电源脚对接会造成双电源冲突，严重时可能烧东西。</section>
</li>
</ol>
<p data-tool="mdnice编辑器" style="padding-top: 8px; padding-bottom: 8px; margin: 0px; line-height: 26px;">
	另外，杜邦线插拔多了容易接触不良。如果怀疑接触问题，换一根线、或者重新插紧往往就好了。<br />
	<span style="color: rgb(255, 255, 255);">文章来源：</span><a href="https://www.codelast.com/" rel="noopener noreferrer" target="_blank"><span style="color: rgb(255, 255, 255);">https://www.codelast.com/</span></a></p>
<h3 data-tool="mdnice编辑器" style="margin-top: 30px; margin-bottom: 15px; padding: 0px; font-size: 20px;">
	<span class="content">2.3 接线示意图</span></h3>
<p data-tool="mdnice编辑器" style="padding-top: 8px; padding-bottom: 8px; margin: 0px; line-height: 26px;">
	下面这张图把树莓派 40-pin 排针全部画出来了。排针是竖着排列的：左边一列是奇数号 1、3、5&hellip;，右边一列是偶数号 2、4、6&hellip;，从上往下递增。蓝色高亮的是我们真正用到的三个脚。<br />
	<a href="https://www.codelast.com/" target="_blank"><img decoding="async" alt="" src="https://www.codelast.com/wp-content/uploads/2026/09/CH340_and_rpi.jpg" style="width: 835px; height: 1354px;" /></a></p>
<p>	<span style="letter-spacing: 0px;">图中三个高亮触点分别是：</span></p>
<ul data-tool="mdnice编辑器" style="margin-top: 8px; margin-bottom: 8px; padding-left: 25px;">
<li>
<section style="margin-top: 5px; margin-bottom: 5px; line-height: 26px; color: rgb(1, 1, 1);"><strong style="font-weight: bold; color: black;">Pin 8</strong>：树莓派的 TXD（GPIO14）&mdash;&mdash;接 CH340 的 RXD；</section>
</li>
<li>
<section style="margin-top: 5px; margin-bottom: 5px; line-height: 26px; color: rgb(1, 1, 1);"><strong style="font-weight: bold; color: black;">Pin 10</strong>：树莓派的 RXD（GPIO15）&mdash;&mdash;接 CH340 的 TXD；</section>
</li>
<li>
<section style="margin-top: 5px; margin-bottom: 5px; line-height: 26px; color: rgb(1, 1, 1);"><strong style="font-weight: bold; color: black;">Pin 20</strong>：GND&mdash;&mdash;图里选它只作示例，实际上树莓派上一堆 GND 脚（Pin 6/9/14/20/25/30/34/39）任选一个接都行。</section>
</li>
</ul>
<p data-tool="mdnice编辑器" style="padding-top: 8px; padding-bottom: 8px; margin: 0px; line-height: 26px;">
	再次强调：<strong style="font-weight: bold;">CH340 的 TXD 必须接树莓派的 RXD，CH340 的 RXD 必须接树莓派的 TXD</strong>，其他引脚一律不接。</p>
<hr data-tool="mdnice编辑器" style="height: 1px; margin: 0; margin-top: 10px; margin-bottom: 10px; border: none; border-top: 1px solid black;" />
<h2 data-tool="mdnice编辑器" style="margin-top: 30px; margin-bottom: 15px; padding: 0px; font-size: 22px;">
	<span class="content">3. 树莓派端要改的配置</span></h2>
<p data-tool="mdnice编辑器" style="padding-top: 8px; padding-bottom: 8px; margin: 0px; line-height: 26px;">
	要让树莓派通过 GPIO 串口提供登录服务，需要改三个系统文件。因为本文假设的场景是&quot;树莓派已经没有任何网络连接&quot;，所以先讲怎么在没有网络的情况下修改这些文件，再逐个讲每个文件改什么。<br />
	<span style="color: rgb(255, 255, 255);">文章来源：</span><a href="https://www.codelast.com/" rel="noopener noreferrer" target="_blank"><span style="color: rgb(255, 255, 255);">https://www.codelast.com/</span></a></p>
<h3 data-tool="mdnice编辑器" style="margin-top: 30px; margin-bottom: 15px; padding: 0px; font-size: 20px;">
	<span class="content">3.1 没有网络时怎么改系统文件（拔卡方式）</span></h3>
<p data-tool="mdnice编辑器" style="padding-top: 8px; padding-bottom: 8px; margin: 0px; line-height: 26px;">
	先认识要改的三个文件：</p>
<section class="table-container" data-tool="mdnice编辑器" style="overflow-x: auto;">
<table>
<thead>
<tr style="border: 0; border-top: 1px solid #ccc; background-color: white;">
<th style="border-style: solid; border-color: rgb(204, 204, 204); padding: 5px 10px; text-align: left; background-color: rgb(240, 240, 240); min-width: 85px;">
				文件</th>
<th style="border-style: solid; border-color: rgb(204, 204, 204); padding: 5px 10px; text-align: left; background-color: rgb(240, 240, 240); min-width: 85px;">
				所在分区</th>
<th style="border-style: solid; border-color: rgb(204, 204, 204); padding: 5px 10px; text-align: left; background-color: rgb(240, 240, 240); min-width: 85px;">
				作用</th>
</tr>
</thead>
<tbody style="border: 0;">
<tr style="border: 0; border-top: 1px solid #ccc; background-color: white;">
<td style="border-style: solid; border-color: rgb(204, 204, 204); padding: 5px 10px; min-width: 85px;">
				<code>/boot/firmware/config.txt</code></td>
<td style="border-style: solid; border-color: rgb(204, 204, 204); padding: 5px 10px; min-width: 85px;">
				boot 分区（FAT32）</td>
<td style="border-style: solid; border-color: rgb(204, 204, 204); padding: 5px 10px; min-width: 85px;">
				启用 GPIO 串口、决定用哪个 UART（3.2 节）</td>
</tr>
<tr style="border: 0; border-top: 1px solid #ccc; background-color: #F8F8F8;">
<td style="border-style: solid; border-color: rgb(204, 204, 204); padding: 5px 10px; min-width: 85px;">
				<code>/boot/firmware/cmdline.txt</code></td>
<td style="border-style: solid; border-color: rgb(204, 204, 204); padding: 5px 10px; min-width: 85px;">
				boot 分区（FAT32）</td>
<td style="border-style: solid; border-color: rgb(204, 204, 204); padding: 5px 10px; min-width: 85px;">
				让内核把启动日志输出到串口，并定好波特率（3.3 节）</td>
</tr>
<tr style="border: 0; border-top: 1px solid #ccc; background-color: white;">
<td style="border-style: solid; border-color: rgb(204, 204, 204); padding: 5px 10px; min-width: 85px;">
				<code>/etc/systemd/system/serial-getty@*.service.d/override.conf</code></td>
<td style="border-style: solid; border-color: rgb(204, 204, 204); padding: 5px 10px; min-width: 85px;">
				系统分区（ext4）</td>
<td style="border-style: solid; border-color: rgb(204, 204, 204); padding: 5px 10px; min-width: 85px;">
				让系统在串口上启动登录程序（3.4 节）</td>
</tr>
</tbody>
</table>
</section>
<p data-tool="mdnice编辑器" style="padding-top: 8px; padding-bottom: 8px; margin: 0px; line-height: 26px;">
	这里有个背景知识需要先说明：树莓派的 SD 卡（TF 卡）其实分成两个分区。一个是 <strong style="font-weight: bold;">boot 分区</strong>，格式是 FAT32，里面放的是开机要用的配置文件（<code style="font-size: 14px; word-wrap: break-word; padding: 2px 4px; border-radius: 4px; margin: 0 2px; color: #1e6bb8; background-color: rgba(27,31,35,.05); font-family: Operator Mono, Consolas, Monaco, Menlo, monospace; word-break: break-all;">config.txt</code>、<code style="font-size: 14px; word-wrap: break-word; padding: 2px 4px; border-radius: 4px; margin: 0 2px; color: #1e6bb8; background-color: rgba(27,31,35,.05); font-family: Operator Mono, Consolas, Monaco, Menlo, monospace; word-break: break-all;">cmdline.txt</code> 都在这里）；另一个是 <strong style="font-weight: bold;">系统分区</strong>，格式是 ext4，装着整个操作系统。FAT32 分区在任何电脑上都能直接读写，而 ext4 分区普通电脑默认是看不到的。</p>
<p data-tool="mdnice编辑器" style="padding-top: 8px; padding-bottom: 8px; margin: 0px; line-height: 26px;">
	拔卡修改的具体步骤：</p>
<ol data-tool="mdnice编辑器" style="margin-top: 8px; margin-bottom: 8px; padding-left: 25px;">
<li>
<section style="margin-top: 5px; margin-bottom: 5px; line-height: 26px; color: rgb(1, 1, 1);"><strong style="font-weight: bold; color: black;">关机断电</strong>：先在树莓派上正常关机，然后断开电源。切记不能带电拔卡，容易损坏文件系统；</section>
</li>
<li>
<section style="margin-top: 5px; margin-bottom: 5px; line-height: 26px; color: rgb(1, 1, 1);"><strong style="font-weight: bold; color: black;">取出 TF 卡</strong>，用读卡器插到电脑上；</section>
</li>
<li>
<section style="margin-top: 5px; margin-bottom: 5px; line-height: 26px; color: rgb(1, 1, 1);"><strong style="font-weight: bold; color: black;">改 boot 分区的文件</strong>：boot 分区是 FAT32，插上后电脑会直接识别。macOS 下它会自动挂载成一个盘，一般叫 <code style="font-size: 14px; word-wrap: break-word; padding: 2px 4px; border-radius: 4px; margin: 0 2px; color: #1e6bb8; background-color: rgba(27,31,35,.05); font-family: Operator Mono, Consolas, Monaco, Menlo, monospace; word-break: break-all;">/Volumes/bootfs</code>，直接用文本编辑器打开里面的 <code style="font-size: 14px; word-wrap: break-word; padding: 2px 4px; border-radius: 4px; margin: 0 2px; color: #1e6bb8; background-color: rgba(27,31,35,.05); font-family: Operator Mono, Consolas, Monaco, Menlo, monospace; word-break: break-all;">config.txt</code>、<code style="font-size: 14px; word-wrap: break-word; padding: 2px 4px; border-radius: 4px; margin: 0 2px; color: #1e6bb8; background-color: rgba(27,31,35,.05); font-family: Operator Mono, Consolas, Monaco, Menlo, monospace; word-break: break-all;">cmdline.txt</code> 修改保存就行；Windows、Linux 同理，打开 TF 卡对应的盘符/挂载点就能看到这两个文件；</section>
</li>
<li>
<section style="margin-top: 5px; margin-bottom: 5px; line-height: 26px; color: rgb(1, 1, 1);"><strong style="font-weight: bold; color: black;">系统分区里的文件</strong>：如果你需要改第三个文件（<code style="font-size: 14px; word-wrap: break-word; padding: 2px 4px; border-radius: 4px; margin: 0 2px; color: #1e6bb8; background-color: rgba(27,31,35,.05); font-family: Operator Mono, Consolas, Monaco, Menlo, monospace; word-break: break-all;">serial-getty</code> 的 override），它在 ext4 系统分区里，普通电脑默认看不到。macOS 要用 <code style="font-size: 14px; word-wrap: break-word; padding: 2px 4px; border-radius: 4px; margin: 0 2px; color: #1e6bb8; background-color: rgba(27,31,35,.05); font-family: Operator Mono, Consolas, Monaco, Menlo, monospace; word-break: break-all;">debugfs</code> 之类的 ext4 工具（需要 root 权限），Windows 可以用 ext2fsd 之类的软件。<strong style="font-weight: bold; color: black;">如果觉得这一步麻烦，可以先跳过它</strong>&mdash;&mdash;先只改 boot 分区里的两个文件，等接上串口发现确实登录不了，再回头处理 3.4 节的问题；</section>
</li>
<li>
<section style="margin-top: 5px; margin-bottom: 5px; line-height: 26px; color: rgb(1, 1, 1);"><strong style="font-weight: bold; color: black;">安全弹出 TF 卡</strong>（macOS 里右键推出），插回树莓派，重新上电。</section>
</li>
</ol>
<p data-tool="mdnice编辑器" style="padding-top: 8px; padding-bottom: 8px; margin: 0px; line-height: 26px;">
	两个容易困惑的点，提前说明：</p>
<ul data-tool="mdnice编辑器" style="margin-top: 8px; margin-bottom: 8px; padding-left: 25px;">
<li>
<section style="margin-top: 5px; margin-bottom: 5px; line-height: 26px; color: rgb(1, 1, 1);"><strong style="font-weight: bold; color: black;">路径差异</strong>：新版 Raspberry Pi OS（Debian 12/13）里，boot 分区在系统内挂在 <code style="font-size: 14px; word-wrap: break-word; padding: 2px 4px; border-radius: 4px; margin: 0 2px; color: #1e6bb8; background-color: rgba(27,31,35,.05); font-family: Operator Mono, Consolas, Monaco, Menlo, monospace; word-break: break-all;">/boot/firmware/</code>；老版本是挂在 <code style="font-size: 14px; word-wrap: break-word; padding: 2px 4px; border-radius: 4px; margin: 0 2px; color: #1e6bb8; background-color: rgba(27,31,35,.05); font-family: Operator Mono, Consolas, Monaco, Menlo, monospace; word-break: break-all;">/boot/</code>。但不管系统内路径怎么写，<strong style="font-weight: bold; color: black;">文件本身就在 boot 分区根目录里</strong>&mdash;&mdash;你拔卡插电脑后，直接看盘符根目录下有没有 <code style="font-size: 14px; word-wrap: break-word; padding: 2px 4px; border-radius: 4px; margin: 0 2px; color: #1e6bb8; background-color: rgba(27,31,35,.05); font-family: Operator Mono, Consolas, Monaco, Menlo, monospace; word-break: break-all;">config.txt</code> 就行，不用管 <code style="font-size: 14px; word-wrap: break-word; padding: 2px 4px; border-radius: 4px; margin: 0 2px; color: #1e6bb8; background-color: rgba(27,31,35,.05); font-family: Operator Mono, Consolas, Monaco, Menlo, monospace; word-break: break-all;">/boot/firmware</code> 这种路径。</section>
</li>
<li>
<section style="margin-top: 5px; margin-bottom: 5px; line-height: 26px; color: rgb(1, 1, 1);"><strong style="font-weight: bold; color: black;">全新卡 vs 用过的卡</strong>：如果你是刚烧录好系统、还没第一次开机的卡，也可以插电脑直接改 boot 分区，效果和改 <code style="font-size: 14px; word-wrap: break-word; padding: 2px 4px; border-radius: 4px; margin: 0 2px; color: #1e6bb8; background-color: rgba(27,31,35,.05); font-family: Operator Mono, Consolas, Monaco, Menlo, monospace; word-break: break-all;">/boot/firmware/</code> 一样；如果是已经用过的卡，改之前一定要先正常关机再拔。</section>
</li>
</ul>
<h3 data-tool="mdnice编辑器" style="margin-top: 30px; margin-bottom: 15px; padding: 0px; font-size: 20px;">
	<span class="content">3.2 启用 GPIO 串口，并决定用哪个 UART</span></h3>
<p data-tool="mdnice编辑器" style="padding-top: 8px; padding-bottom: 8px; margin: 0px; line-height: 26px;">
	树莓派 GPIO 上引出的串口默认是关闭的，需要在 <code style="font-size: 14px; word-wrap: break-word; padding: 2px 4px; border-radius: 4px; margin: 0 2px; color: #1e6bb8; background-color: rgba(27,31,35,.05); font-family: Operator Mono, Consolas, Monaco, Menlo, monospace; word-break: break-all;">/boot/firmware/config.txt</code> 里打开它。用文本编辑器打开这个文件，在文件末尾追加：</p>
<section class="code-snippet__fix code-snippet__js" data-tool="mdnice编辑器" style="font-size: 14px; margin: 10px 0; display: block; color: #333; position: relative; background-color: rgba(0,0,0,0.03); border: 1px solid #f0f0f0; border-radius: 2px; display: flex; line-height: 20px; word-wrap: break-word !important;">
<ul class="code-snippet__line-index code-snippet__js" style="margin-top: 8px; margin-bottom: 8px; padding-left: 25px; color: black; counter-reset: line; flex-shrink: 0; height: 100%; padding: 1em; list-style-type: none; padding: 16px; margin: 0;">
<li style="list-style-type: none; text-align: right; line-height: 26px; margin: 0px;">
		<span style="min-width: 1.5em; left: -2.5em; counter-increment: line 1; color: rgba(0, 0, 0, 0.3);">ounter(line</span></li>
</ul>
<pre class="code-snippet__js" data-lang="ini" style="margin-bottom: 10px; margin-top: 0px; overflow-x: auto; padding: 16px; padding-left: 0; white-space: normal; flex: 1; -webkit-overflow-scrolling: touch;">
<code style="border-radius: 0px; white-space: pre; display: flex; position: relative; font-family: Consolas, &quot;Liberation Mono&quot;, Menlo, Courier, monospace; padding: 0px;"><span class="code-snippet_outer" style="line-height: 26px;">enable_uart=1</span></code></pre>
</section>
<p data-tool="mdnice编辑器" style="padding-top: 8px; padding-bottom: 8px; margin: 0px; line-height: 26px;">
	光打开还不够，树莓派 3 上有个特殊情况需要决定：这颗芯片其实有<strong style="font-weight: bold;">两个串口硬件</strong>&mdash;&mdash;一个叫 <strong style="font-weight: bold;">PL011</strong>（质量好、波特率准，但默认分配给蓝牙用），一个叫 <strong style="font-weight: bold;">mini-UART</strong>（功能弱一些、波特率会随 CPU 频率漂移）。GPIO 引出的串口到底用哪个，由要不要给蓝牙让路决定。有三个方案：</p>
<section class="table-container" data-tool="mdnice编辑器" style="overflow-x: auto;">
<table>
<thead>
<tr style="border: 0; border-top: 1px solid #ccc; background-color: white;">
<th style="border-style: solid; border-color: rgb(204, 204, 204); padding: 5px 10px; text-align: left; background-color: rgb(240, 240, 240); min-width: 85px;">
				方案</th>
<th style="border-style: solid; border-color: rgb(204, 204, 204); padding: 5px 10px; text-align: left; background-color: rgb(240, 240, 240); min-width: 85px;">
				config.txt 里的写法</th>
<th style="border-style: solid; border-color: rgb(204, 204, 204); padding: 5px 10px; text-align: left; background-color: rgb(240, 240, 240); min-width: 85px;">
				结果</th>
</tr>
</thead>
<tbody style="border: 0;">
<tr style="border: 0; border-top: 1px solid #ccc; background-color: white;">
<td style="border-style: solid; border-color: rgb(204, 204, 204); padding: 5px 10px; min-width: 85px;">
				1. 关闭蓝牙，串口用最好的 PL011</td>
<td style="border-style: solid; border-color: rgb(204, 204, 204); padding: 5px 10px; min-width: 85px;">
				<code>dtoverlay=disable-bt</code></td>
<td style="border-style: solid; border-color: rgb(204, 204, 204); padding: 5px 10px; min-width: 85px;">
				GPIO 串口是<code>/dev/ttyAMA0</code>（PL011，波特率最准），但蓝牙彻底没了</td>
</tr>
<tr style="border: 0; border-top: 1px solid #ccc; background-color: #F8F8F8;">
<td style="border-style: solid; border-color: rgb(204, 204, 204); padding: 5px 10px; min-width: 85px;">
				2. 串口用 PL011、蓝牙挤到 mini-UART</td>
<td style="border-style: solid; border-color: rgb(204, 204, 204); padding: 5px 10px; min-width: 85px;">
				<code>dtoverlay=miniuart-bt</code></td>
<td style="border-style: solid; border-color: rgb(204, 204, 204); padding: 5px 10px; min-width: 85px;">
				理论可行，但在部分树莓派 3 上会导致蓝牙固件加载失败，<strong style="font-weight: bold;">不推荐</strong></td>
</tr>
<tr style="border: 0; border-top: 1px solid #ccc; background-color: white;">
<td style="border-style: solid; border-color: rgb(204, 204, 204); padding: 5px 10px; min-width: 85px;">
				3. 什么都不加，维持默认</td>
<td style="border-style: solid; border-color: rgb(204, 204, 204); padding: 5px 10px; min-width: 85px;">
				（不加 dtoverlay）</td>
<td style="border-style: solid; border-color: rgb(204, 204, 204); padding: 5px 10px; min-width: 85px;">
				蓝牙正常用 PL011；GPIO 串口退而求其次用 mini-UART，即<code>/dev/ttyS0</code></td>
</tr>
</tbody>
</table>
</section>
<p data-tool="mdnice编辑器" style="padding-top: 8px; padding-bottom: 8px; margin: 0px; line-height: 26px;">
	怎么选，取决于你要不要蓝牙：</p>
<ul data-tool="mdnice编辑器" style="margin-top: 8px; margin-bottom: 8px; padding-left: 25px;">
<li>
<section style="margin-top: 5px; margin-bottom: 5px; line-height: 26px; color: rgb(1, 1, 1);"><strong style="font-weight: bold; color: black;">还要用蓝牙</strong>：选方案 3。GPIO 串口会是 <code style="font-size: 14px; word-wrap: break-word; padding: 2px 4px; border-radius: 4px; margin: 0 2px; color: #1e6bb8; background-color: rgba(27,31,35,.05); font-family: Operator Mono, Consolas, Monaco, Menlo, monospace; word-break: break-all;">/dev/serial0 -&gt; ttyS0</code>（mini-UART）。因为 mini-UART 的波特率会随 CPU 频率漂移，建议把波特率定在 9600 这种低速档，或者去固定 CPU 频率，否则可能出现乱码；</section>
</li>
<li>
<section style="margin-top: 5px; margin-bottom: 5px; line-height: 26px; color: rgb(1, 1, 1);"><strong style="font-weight: bold; color: black;">不需要蓝牙，只想要最稳定的串口</strong>：选方案 1。GPIO 串口是 <code style="font-size: 14px; word-wrap: break-word; padding: 2px 4px; border-radius: 4px; margin: 0 2px; color: #1e6bb8; background-color: rgba(27,31,35,.05); font-family: Operator Mono, Consolas, Monaco, Menlo, monospace; word-break: break-all;">/dev/serial0 -&gt; ttyAMA0</code>（PL011），波特率精确，省心。</section>
</li>
</ul>
<blockquote data-tool="mdnice编辑器" style="font-size: 0.9em; overflow: auto; border-left: 3px solid rgba(0, 0, 0, 0.4); background: rgba(0, 0, 0, 0.05); color: rgb(106, 115, 125); padding: 10px 10px 10px 20px; margin-bottom: 20px; margin-top: 20px;">
<p style="font-size: 16px; padding-top: 8px; padding-bottom: 8px; margin: 0px; color: black; line-height: 26px;">
		后面各小节的命令都以 <strong style="font-weight: bold;">方案 3（设备名 <code style="font-size: 14px; word-wrap: break-word; padding: 2px 4px; border-radius: 4px; margin: 0 2px; color: #1e6bb8; background-color: rgba(27,31,35,.05); font-family: Operator Mono, Consolas, Monaco, Menlo, monospace; word-break: break-all;">ttyS0</code>）</strong> 为例。如果你选了方案 1，把命令里出现的 <code style="font-size: 14px; word-wrap: break-word; padding: 2px 4px; border-radius: 4px; margin: 0 2px; color: #1e6bb8; background-color: rgba(27,31,35,.05); font-family: Operator Mono, Consolas, Monaco, Menlo, monospace; word-break: break-all;">ttyS0</code> 全部换成 <code style="font-size: 14px; word-wrap: break-word; padding: 2px 4px; border-radius: 4px; margin: 0 2px; color: #1e6bb8; background-color: rgba(27,31,35,.05); font-family: Operator Mono, Consolas, Monaco, Menlo, monospace; word-break: break-all;">ttyAMA0</code> 即可。</p>
</blockquote>
<p data-tool="mdnice编辑器" style="padding-top: 8px; padding-bottom: 8px; margin: 0px; line-height: 26px;">
	顺带一提：<code style="font-size: 14px; word-wrap: break-word; padding: 2px 4px; border-radius: 4px; margin: 0 2px; color: #1e6bb8; background-color: rgba(27,31,35,.05); font-family: Operator Mono, Consolas, Monaco, Menlo, monospace; word-break: break-all;">/dev/serial0</code> 是一个软链接，它总是指向&quot;当前 GPIO 串口实际对应的那个设备&quot;（<code style="font-size: 14px; word-wrap: break-word; padding: 2px 4px; border-radius: 4px; margin: 0 2px; color: #1e6bb8; background-color: rgba(27,31,35,.05); font-family: Operator Mono, Consolas, Monaco, Menlo, monospace; word-break: break-all;">ttyS0</code> 或 <code style="font-size: 14px; word-wrap: break-word; padding: 2px 4px; border-radius: 4px; margin: 0 2px; color: #1e6bb8; background-color: rgba(27,31,35,.05); font-family: Operator Mono, Consolas, Monaco, Menlo, monospace; word-break: break-all;">ttyAMA0</code>），所以不确定时先执行 <code style="font-size: 14px; word-wrap: break-word; padding: 2px 4px; border-radius: 4px; margin: 0 2px; color: #1e6bb8; background-color: rgba(27,31,35,.05); font-family: Operator Mono, Consolas, Monaco, Menlo, monospace; word-break: break-all;">ls -l /dev/serial0</code> 看一眼它指向谁，心里就有数了。</p>
<h3 data-tool="mdnice编辑器" style="margin-top: 30px; margin-bottom: 15px; padding: 0px; font-size: 20px;">
	<span class="content">3.3 让内核把启动信息输出到串口（顺便定波特率）</span></h3>
<p data-tool="mdnice编辑器" style="padding-top: 8px; padding-bottom: 8px; margin: 0px; line-height: 26px;">
	Linux 内核启动时的日志默认是输出到屏幕的。我们希望它同时也输出到 GPIO 串口，这样就算树莓派没接屏幕，也能从串口看到启动过程。</p>
<p data-tool="mdnice编辑器" style="padding-top: 8px; padding-bottom: 8px; margin: 0px; line-height: 26px;">
	这个行为由 <code style="font-size: 14px; word-wrap: break-word; padding: 2px 4px; border-radius: 4px; margin: 0 2px; color: #1e6bb8; background-color: rgba(27,31,35,.05); font-family: Operator Mono, Consolas, Monaco, Menlo, monospace; word-break: break-all;">/boot/firmware/cmdline.txt</code> 控制。用文本编辑器打开它，确认里面有这样一段（注意是 <code style="font-size: 14px; word-wrap: break-word; padding: 2px 4px; border-radius: 4px; margin: 0 2px; color: #1e6bb8; background-color: rgba(27,31,35,.05); font-family: Operator Mono, Consolas, Monaco, Menlo, monospace; word-break: break-all;">serial0</code>，不是别的）：</p>
<section class="code-snippet__fix code-snippet__js" data-tool="mdnice编辑器" style="font-size: 14px; margin: 10px 0; display: block; color: #333; position: relative; background-color: rgba(0,0,0,0.03); border: 1px solid #f0f0f0; border-radius: 2px; display: flex; line-height: 20px; word-wrap: break-word !important;">
<ul class="code-snippet__line-index code-snippet__js" style="margin-top: 8px; margin-bottom: 8px; padding-left: 25px; color: black; counter-reset: line; flex-shrink: 0; height: 100%; padding: 1em; list-style-type: none; padding: 16px; margin: 0;">
<li style="list-style-type: none; text-align: right; line-height: 26px; margin: 0px;">
		<span style="min-width: 1.5em; left: -2.5em; counter-increment: line 1; color: rgba(0, 0, 0, 0.3);">ounter(line</span></li>
</ul>
<pre class="code-snippet__js" data-lang="" style="margin-bottom: 10px; margin-top: 0px; overflow-x: auto; padding: 16px; padding-left: 0; white-space: normal; flex: 1; -webkit-overflow-scrolling: touch;">
<code style="border-radius: 0px; white-space: pre; display: flex; position: relative; font-family: Consolas, &quot;Liberation Mono&quot;, Menlo, Courier, monospace; padding: 0px;"><span class="code-snippet_outer" style="line-height: 26px;">console=serial0,9600</span></code></pre>
</section>
<p data-tool="mdnice编辑器" style="padding-top: 8px; padding-bottom: 8px; margin: 0px; line-height: 26px;">
	<code style="font-size: 14px; word-wrap: break-word; padding: 2px 4px; border-radius: 4px; margin: 0 2px; color: #1e6bb8; background-color: rgba(27,31,35,.05); font-family: Operator Mono, Consolas, Monaco, Menlo, monospace; word-break: break-all;">serial0</code> 就是 GPIO 串口的软链接名，<code style="font-size: 14px; word-wrap: break-word; padding: 2px 4px; border-radius: 4px; margin: 0 2px; color: #1e6bb8; background-color: rgba(27,31,35,.05); font-family: Operator Mono, Consolas, Monaco, Menlo, monospace; word-break: break-all;">9600</code> 是波特率。如果文件里同时有 <code style="font-size: 14px; word-wrap: break-word; padding: 2px 4px; border-radius: 4px; margin: 0 2px; color: #1e6bb8; background-color: rgba(27,31,35,.05); font-family: Operator Mono, Consolas, Monaco, Menlo, monospace; word-break: break-all;">console=tty1</code> 之类的（那是输出到本地屏幕的），不要删掉它们，只把 <code style="font-size: 14px; word-wrap: break-word; padding: 2px 4px; border-radius: 4px; margin: 0 2px; color: #1e6bb8; background-color: rgba(27,31,35,.05); font-family: Operator Mono, Consolas, Monaco, Menlo, monospace; word-break: break-all;">serial0</code> 这一段波特率定为 9600 就好。</p>
<blockquote data-tool="mdnice编辑器" style="font-size: 0.9em; overflow: auto; border-left: 3px solid rgba(0, 0, 0, 0.4); background: rgba(0, 0, 0, 0.05); color: rgb(106, 115, 125); padding: 10px 10px 10px 20px; margin-bottom: 20px; margin-top: 20px;">
<p style="font-size: 16px; padding-top: 8px; padding-bottom: 8px; margin: 0px; color: black; line-height: 26px;">
		波特率这个东西，后面会反复强调：<strong style="font-weight: bold;">发送端和接收端必须用同一个波特率</strong>，否则收到的就是乱码。</p>
</blockquote>
<h3 data-tool="mdnice编辑器" style="margin-top: 30px; margin-bottom: 15px; padding: 0px; font-size: 20px;">
	<span class="content">3.4 让系统在串口上启动登录程序（serial-getty）</span></h3>
<p data-tool="mdnice编辑器" style="padding-top: 8px; padding-bottom: 8px; margin: 0px; line-height: 26px;">
	前面两步只是让内核往串口输出日志，但光有日志还不能登录。要登录，系统里得有一个程序在串口上等着，显示 <code style="font-size: 14px; word-wrap: break-word; padding: 2px 4px; border-radius: 4px; margin: 0 2px; color: #1e6bb8; background-color: rgba(27,31,35,.05); font-family: Operator Mono, Consolas, Monaco, Menlo, monospace; word-break: break-all;">login:</code> 提示符、接受你输入用户名密码&mdash;&mdash;这个程序叫 <strong style="font-weight: bold;">getty</strong>，对应的系统服务是 <code style="font-size: 14px; word-wrap: break-word; padding: 2px 4px; border-radius: 4px; margin: 0 2px; color: #1e6bb8; background-color: rgba(27,31,35,.05); font-family: Operator Mono, Consolas, Monaco, Menlo, monospace; word-break: break-all;">serial-getty@&lt;串口设备&gt;.service</code>。</p>
<p data-tool="mdnice编辑器" style="padding-top: 8px; padding-bottom: 8px; margin: 0px; line-height: 26px;">
	树莓派系统在检测到 GPIO 串口启用后，一般会自动启动对应的 <code style="font-size: 14px; word-wrap: break-word; padding: 2px 4px; border-radius: 4px; margin: 0 2px; color: #1e6bb8; background-color: rgba(27,31,35,.05); font-family: Operator Mono, Consolas, Monaco, Menlo, monospace; word-break: break-all;">serial-getty</code> 服务。但有一个很常见的坑：<strong style="font-weight: bold;">getty 的波特率必须和内核 console 的波特率一致</strong>（都是 9600）。如果登录提示符不出现，多半就是 getty 没启动，或者波特率不对。</p>
<p data-tool="mdnice编辑器" style="padding-top: 8px; padding-bottom: 8px; margin: 0px; line-height: 26px;">
	手动确认/修正的方法是给 getty 写一个配置文件，强制指定设备和波特率。在树莓派上创建 <code style="font-size: 14px; word-wrap: break-word; padding: 2px 4px; border-radius: 4px; margin: 0 2px; color: #1e6bb8; background-color: rgba(27,31,35,.05); font-family: Operator Mono, Consolas, Monaco, Menlo, monospace; word-break: break-all;">/etc/systemd/system/serial-getty@ttyS0.service.d/override.conf</code>（目录可能要自己建）：</p>
<section class="code-snippet__fix code-snippet__js" data-tool="mdnice编辑器" style="font-size: 14px; margin: 10px 0; display: block; color: #333; position: relative; background-color: rgba(0,0,0,0.03); border: 1px solid #f0f0f0; border-radius: 2px; display: flex; line-height: 20px; word-wrap: break-word !important;">
<ul class="code-snippet__line-index code-snippet__js" style="margin-top: 8px; margin-bottom: 8px; padding-left: 25px; color: black; counter-reset: line; flex-shrink: 0; height: 100%; padding: 1em; list-style-type: none; padding: 16px; margin: 0;">
<li style="list-style-type: none; text-align: right; line-height: 26px; margin: 0px;">
		<span style="min-width: 1.5em; left: -2.5em; counter-increment: line 1; color: rgba(0, 0, 0, 0.3);">ounter(line</span></li>
<li style="list-style-type: none; text-align: right; line-height: 26px; margin: 0px;">
		<span style="min-width: 1.5em; left: -2.5em; counter-increment: line 1; color: rgba(0, 0, 0, 0.3);">ounter(line</span></li>
<li style="list-style-type: none; text-align: right; line-height: 26px; margin: 0px;">
		<span style="min-width: 1.5em; left: -2.5em; counter-increment: line 1; color: rgba(0, 0, 0, 0.3);">ounter(line</span></li>
</ul>
<pre class="code-snippet__js" data-lang="ini" style="margin-bottom: 10px; margin-top: 0px; overflow-x: auto; padding: 16px; padding-left: 0; white-space: normal; flex: 1; -webkit-overflow-scrolling: touch;">
<code style="border-radius: 0px; white-space: pre; display: flex; position: relative; font-family: Consolas, &quot;Liberation Mono&quot;, Menlo, Courier, monospace; padding: 0px;"><span class="code-snippet_outer" style="line-height: 26px;">[Service]</span></code><code style="border-radius: 0px; white-space: pre; display: flex; position: relative; font-family: Consolas, &quot;Liberation Mono&quot;, Menlo, Courier, monospace; padding: 0px;"><span class="code-snippet_outer" style="line-height: 26px;">ExecStart=</span></code><code style="border-radius: 0px; white-space: pre; display: flex; position: relative; font-family: Consolas, &quot;Liberation Mono&quot;, Menlo, Courier, monospace; padding: 0px;"><span class="code-snippet_outer" style="line-height: 26px;">ExecStart=-/sbin/agetty --noclear --keep-baud ttyS0 9600 vt100</span></code></pre>
</section>
<blockquote data-tool="mdnice编辑器" style="font-size: 0.9em; overflow: auto; border-left: 3px solid rgba(0, 0, 0, 0.4); background: rgba(0, 0, 0, 0.05); color: rgb(106, 115, 125); padding: 10px 10px 10px 20px; margin-bottom: 20px; margin-top: 20px;">
<p style="font-size: 16px; padding-top: 8px; padding-bottom: 8px; margin: 0px; color: black; line-height: 26px;">
		如果你的 GPIO 串口实际是 <code style="font-size: 14px; word-wrap: break-word; padding: 2px 4px; border-radius: 4px; margin: 0 2px; color: #1e6bb8; background-color: rgba(27,31,35,.05); font-family: Operator Mono, Consolas, Monaco, Menlo, monospace; word-break: break-all;">ttyAMA0</code>（方案 1），就把上面两处 <code style="font-size: 14px; word-wrap: break-word; padding: 2px 4px; border-radius: 4px; margin: 0 2px; color: #1e6bb8; background-color: rgba(27,31,35,.05); font-family: Operator Mono, Consolas, Monaco, Menlo, monospace; word-break: break-all;">ttyS0</code> 换成 <code style="font-size: 14px; word-wrap: break-word; padding: 2px 4px; border-radius: 4px; margin: 0 2px; color: #1e6bb8; background-color: rgba(27,31,35,.05); font-family: Operator Mono, Consolas, Monaco, Menlo, monospace; word-break: break-all;">ttyAMA0</code>，文件名也跟着改成 <code style="font-size: 14px; word-wrap: break-word; padding: 2px 4px; border-radius: 4px; margin: 0 2px; color: #1e6bb8; background-color: rgba(27,31,35,.05); font-family: Operator Mono, Consolas, Monaco, Menlo, monospace; word-break: break-all;">serial-getty@ttyAMA0.service.d/override.conf</code>。</p>
</blockquote>
<p data-tool="mdnice编辑器" style="padding-top: 8px; padding-bottom: 8px; margin: 0px; line-height: 26px;">
	然后重新加载 systemd 并启用服务：</p>
<section class="code-snippet__fix code-snippet__js" data-tool="mdnice编辑器" style="font-size: 14px; margin: 10px 0; display: block; color: #333; position: relative; background-color: rgba(0,0,0,0.03); border: 1px solid #f0f0f0; border-radius: 2px; display: flex; line-height: 20px; word-wrap: break-word !important;">
<ul class="code-snippet__line-index code-snippet__js" style="margin-top: 8px; margin-bottom: 8px; padding-left: 25px; color: black; counter-reset: line; flex-shrink: 0; height: 100%; padding: 1em; list-style-type: none; padding: 16px; margin: 0;">
<li style="list-style-type: none; text-align: right; line-height: 26px; margin: 0px;">
		<span style="min-width: 1.5em; left: -2.5em; counter-increment: line 1; color: rgba(0, 0, 0, 0.3);">ounter(line</span></li>
<li style="list-style-type: none; text-align: right; line-height: 26px; margin: 0px;">
		<span style="min-width: 1.5em; left: -2.5em; counter-increment: line 1; color: rgba(0, 0, 0, 0.3);">ounter(line</span></li>
</ul>
<pre class="code-snippet__js" data-lang="bash" style="margin-bottom: 10px; margin-top: 0px; overflow-x: auto; padding: 16px; padding-left: 0; white-space: normal; flex: 1; -webkit-overflow-scrolling: touch;">
<code style="border-radius: 0px; white-space: pre; display: flex; position: relative; font-family: Consolas, &quot;Liberation Mono&quot;, Menlo, Courier, monospace; padding: 0px;"><span class="code-snippet_outer" style="line-height: 26px;">sudo systemctl daemon-reload</span></code><code style="border-radius: 0px; white-space: pre; display: flex; position: relative; font-family: Consolas, &quot;Liberation Mono&quot;, Menlo, Courier, monospace; padding: 0px;"><span class="code-snippet_outer" style="line-height: 26px;">sudo systemctl enable --now serial-getty@ttyS0.service</span></code></pre>
</section>
<p data-tool="mdnice编辑器" style="padding-top: 8px; padding-bottom: 8px; margin: 0px; line-height: 26px;">
	验证服务确实在跑：</p>
<section class="code-snippet__fix code-snippet__js" data-tool="mdnice编辑器" style="font-size: 14px; margin: 10px 0; display: block; color: #333; position: relative; background-color: rgba(0,0,0,0.03); border: 1px solid #f0f0f0; border-radius: 2px; display: flex; line-height: 20px; word-wrap: break-word !important;">
<ul class="code-snippet__line-index code-snippet__js" style="margin-top: 8px; margin-bottom: 8px; padding-left: 25px; color: black; counter-reset: line; flex-shrink: 0; height: 100%; padding: 1em; list-style-type: none; padding: 16px; margin: 0;">
<li style="list-style-type: none; text-align: right; line-height: 26px; margin: 0px;">
		<span style="min-width: 1.5em; left: -2.5em; counter-increment: line 1; color: rgba(0, 0, 0, 0.3);">ounter(line</span></li>
<li style="list-style-type: none; text-align: right; line-height: 26px; margin: 0px;">
		<span style="min-width: 1.5em; left: -2.5em; counter-increment: line 1; color: rgba(0, 0, 0, 0.3);">ounter(line</span></li>
</ul>
<pre class="code-snippet__js" data-lang="bash" style="margin-bottom: 10px; margin-top: 0px; overflow-x: auto; padding: 16px; padding-left: 0; white-space: normal; flex: 1; -webkit-overflow-scrolling: touch;">
<code style="border-radius: 0px; white-space: pre; display: flex; position: relative; font-family: Consolas, &quot;Liberation Mono&quot;, Menlo, Courier, monospace; padding: 0px;"><span class="code-snippet_outer" style="line-height: 26px;">systemctl is-active serial-getty@ttyS0   # 应该输出 active</span></code><code style="border-radius: 0px; white-space: pre; display: flex; position: relative; font-family: Consolas, &quot;Liberation Mono&quot;, Menlo, Courier, monospace; padding: 0px;"><span class="code-snippet_outer" style="line-height: 26px;">systemctl list-units | grep ttyS0        # 能看到 serial-getty 在运行</span></code></pre>
</section>
<p data-tool="mdnice编辑器" style="padding-top: 8px; padding-bottom: 8px; margin: 0px; line-height: 26px;">
	到这里，树莓派端的配置就齐了：GPIO 串口已启用、内核往串口输出日志、getty 在串口上等你登录。</p>
<hr data-tool="mdnice编辑器" style="height: 1px; margin: 0; margin-top: 10px; margin-bottom: 10px; border: none; border-top: 1px solid black;" />
<h2 data-tool="mdnice编辑器" style="margin-top: 30px; margin-bottom: 15px; padding: 0px; font-size: 22px;">
	<span class="content">4. macOS 这一端怎么连</span></h2>
<h3 data-tool="mdnice编辑器" style="margin-top: 30px; margin-bottom: 15px; padding: 0px; font-size: 20px;">
	<span class="content">4.1 先确认设备名</span></h3>
<p data-tool="mdnice编辑器" style="padding-top: 8px; padding-bottom: 8px; margin: 0px; line-height: 26px;">
	CH340 插上后 macOS 会自动给它分配一个设备文件，名字是 <code style="font-size: 14px; word-wrap: break-word; padding: 2px 4px; border-radius: 4px; margin: 0 2px; color: #1e6bb8; background-color: rgba(27,31,35,.05); font-family: Operator Mono, Consolas, Monaco, Menlo, monospace; word-break: break-all;">/dev/cu.usbserial-XXXX</code>（也可能是 <code style="font-size: 14px; word-wrap: break-word; padding: 2px 4px; border-radius: 4px; margin: 0 2px; color: #1e6bb8; background-color: rgba(27,31,35,.05); font-family: Operator Mono, Consolas, Monaco, Menlo, monospace; word-break: break-all;">/dev/tty.usbserial-XXXX</code>）。注意末尾那串数字<strong style="font-weight: bold;">每次重新插拔都可能变</strong>（比如这次是 11310，下次变成 11320，再下次是 110），所以别死记一个名字，每次用之前先查一下：</p>
<section class="code-snippet__fix code-snippet__js" data-tool="mdnice编辑器" style="font-size: 14px; margin: 10px 0; display: block; color: #333; position: relative; background-color: rgba(0,0,0,0.03); border: 1px solid #f0f0f0; border-radius: 2px; display: flex; line-height: 20px; word-wrap: break-word !important;">
<ul class="code-snippet__line-index code-snippet__js" style="margin-top: 8px; margin-bottom: 8px; padding-left: 25px; color: black; counter-reset: line; flex-shrink: 0; height: 100%; padding: 1em; list-style-type: none; padding: 16px; margin: 0;">
<li style="list-style-type: none; text-align: right; line-height: 26px; margin: 0px;">
		<span style="min-width: 1.5em; left: -2.5em; counter-increment: line 1; color: rgba(0, 0, 0, 0.3);">ounter(line</span></li>
</ul>
<pre class="code-snippet__js" data-lang="bash" style="margin-bottom: 10px; margin-top: 0px; overflow-x: auto; padding: 16px; padding-left: 0; white-space: normal; flex: 1; -webkit-overflow-scrolling: touch;">
<code style="border-radius: 0px; white-space: pre; display: flex; position: relative; font-family: Consolas, &quot;Liberation Mono&quot;, Menlo, Courier, monospace; padding: 0px;"><span class="code-snippet_outer" style="line-height: 26px;">ls /dev/cu.usbserial*</span></code></pre>
</section>
<p data-tool="mdnice编辑器" style="padding-top: 8px; padding-bottom: 8px; margin: 0px; line-height: 26px;">
	如果这条命令什么都查不到，说明驱动没装好，去 WCH 官网装 macOS 驱动。</p>
<h3 data-tool="mdnice编辑器" style="margin-top: 30px; margin-bottom: 15px; padding: 0px; font-size: 20px;">
	<span class="content">4.2 用 screen 连上去</span></h3>
<p data-tool="mdnice编辑器" style="padding-top: 8px; padding-bottom: 8px; margin: 0px; line-height: 26px;">
	macOS 自带的 <code style="font-size: 14px; word-wrap: break-word; padding: 2px 4px; border-radius: 4px; margin: 0 2px; color: #1e6bb8; background-color: rgba(27,31,35,.05); font-family: Operator Mono, Consolas, Monaco, Menlo, monospace; word-break: break-all;">screen</code> 命令就能当串口终端用：</p>
<section class="code-snippet__fix code-snippet__js" data-tool="mdnice编辑器" style="font-size: 14px; margin: 10px 0; display: block; color: #333; position: relative; background-color: rgba(0,0,0,0.03); border: 1px solid #f0f0f0; border-radius: 2px; display: flex; line-height: 20px; word-wrap: break-word !important;">
<ul class="code-snippet__line-index code-snippet__js" style="margin-top: 8px; margin-bottom: 8px; padding-left: 25px; color: black; counter-reset: line; flex-shrink: 0; height: 100%; padding: 1em; list-style-type: none; padding: 16px; margin: 0;">
<li style="list-style-type: none; text-align: right; line-height: 26px; margin: 0px;">
		<span style="min-width: 1.5em; left: -2.5em; counter-increment: line 1; color: rgba(0, 0, 0, 0.3);">ounter(line</span></li>
</ul>
<pre class="code-snippet__js" data-lang="bash" style="margin-bottom: 10px; margin-top: 0px; overflow-x: auto; padding: 16px; padding-left: 0; white-space: normal; flex: 1; -webkit-overflow-scrolling: touch;">
<code style="border-radius: 0px; white-space: pre; display: flex; position: relative; font-family: Consolas, &quot;Liberation Mono&quot;, Menlo, Courier, monospace; padding: 0px;"><span class="code-snippet_outer" style="line-height: 26px;">screen /dev/cu.usbserial-110 9600</span></code></pre>
</section>
<p data-tool="mdnice编辑器" style="padding-top: 8px; padding-bottom: 8px; margin: 0px; line-height: 26px;">
	格式是 <code style="font-size: 14px; word-wrap: break-word; padding: 2px 4px; border-radius: 4px; margin: 0 2px; color: #1e6bb8; background-color: rgba(27,31,35,.05); font-family: Operator Mono, Consolas, Monaco, Menlo, monospace; word-break: break-all;">screen 设备文件 波特率</code>，把设备名换成你上一步查到的实际名字。连接成功后，按一下回车，应该能看到：</p>
<section class="code-snippet__fix code-snippet__js" data-tool="mdnice编辑器" style="font-size: 14px; margin: 10px 0; display: block; color: #333; position: relative; background-color: rgba(0,0,0,0.03); border: 1px solid #f0f0f0; border-radius: 2px; display: flex; line-height: 20px; word-wrap: break-word !important;">
<ul class="code-snippet__line-index code-snippet__js" style="margin-top: 8px; margin-bottom: 8px; padding-left: 25px; color: black; counter-reset: line; flex-shrink: 0; height: 100%; padding: 1em; list-style-type: none; padding: 16px; margin: 0;">
<li style="list-style-type: none; text-align: right; line-height: 26px; margin: 0px;">
		<span style="min-width: 1.5em; left: -2.5em; counter-increment: line 1; color: rgba(0, 0, 0, 0.3);">ounter(line</span></li>
</ul>
<pre class="code-snippet__js" data-lang="" style="margin-bottom: 10px; margin-top: 0px; overflow-x: auto; padding: 16px; padding-left: 0; white-space: normal; flex: 1; -webkit-overflow-scrolling: touch;">
<code style="border-radius: 0px; white-space: pre; display: flex; position: relative; font-family: Consolas, &quot;Liberation Mono&quot;, Menlo, Courier, monospace; padding: 0px;"><span class="code-snippet_outer" style="line-height: 26px;">rpi login:</span></code></pre>
</section>
<p data-tool="mdnice编辑器" style="padding-top: 8px; padding-bottom: 8px; margin: 0px; line-height: 26px;">
	输入树莓派的用户名和密码，就进入 shell 了，用法和 SSH 完全一样。</p>
<p data-tool="mdnice编辑器" style="padding-top: 8px; padding-bottom: 8px; margin: 0px; line-height: 26px;">
	退出 screen 的方法：先按 <code style="font-size: 14px; word-wrap: break-word; padding: 2px 4px; border-radius: 4px; margin: 0 2px; color: #1e6bb8; background-color: rgba(27,31,35,.05); font-family: Operator Mono, Consolas, Monaco, Menlo, monospace; word-break: break-all;">Ctrl+A</code>，松开后再按 <code style="font-size: 14px; word-wrap: break-word; padding: 2px 4px; border-radius: 4px; margin: 0 2px; color: #1e6bb8; background-color: rgba(27,31,35,.05); font-family: Operator Mono, Consolas, Monaco, Menlo, monospace; word-break: break-all;">K</code>，最后按 <code style="font-size: 14px; word-wrap: break-word; padding: 2px 4px; border-radius: 4px; margin: 0 2px; color: #1e6bb8; background-color: rgba(27,31,35,.05); font-family: Operator Mono, Consolas, Monaco, Menlo, monospace; word-break: break-all;">y</code> 确认退出。</p>
<h3 data-tool="mdnice编辑器" style="margin-top: 30px; margin-bottom: 15px; padding: 0px; font-size: 20px;">
	<span class="content">4.3 不想开终端？也可以用命令直接收发</span></h3>
<p data-tool="mdnice编辑器" style="padding-top: 8px; padding-bottom: 8px; margin: 0px; line-height: 26px;">
	如果你是脚本/程序要自动化测试串口，不需要交互式终端，可以用下面的方式非交互地验证：</p>
<section class="code-snippet__fix code-snippet__js" data-tool="mdnice编辑器" style="font-size: 14px; margin: 10px 0; display: block; color: #333; position: relative; background-color: rgba(0,0,0,0.03); border: 1px solid #f0f0f0; border-radius: 2px; display: flex; line-height: 20px; word-wrap: break-word !important;">
<ul class="code-snippet__line-index code-snippet__js" style="margin-top: 8px; margin-bottom: 8px; padding-left: 25px; color: black; counter-reset: line; flex-shrink: 0; height: 100%; padding: 1em; list-style-type: none; padding: 16px; margin: 0;">
<li style="list-style-type: none; text-align: right; line-height: 26px; margin: 0px;">
		<span style="min-width: 1.5em; left: -2.5em; counter-increment: line 1; color: rgba(0, 0, 0, 0.3);">ounter(line</span></li>
<li style="list-style-type: none; text-align: right; line-height: 26px; margin: 0px;">
		<span style="min-width: 1.5em; left: -2.5em; counter-increment: line 1; color: rgba(0, 0, 0, 0.3);">ounter(line</span></li>
<li style="list-style-type: none; text-align: right; line-height: 26px; margin: 0px;">
		<span style="min-width: 1.5em; left: -2.5em; counter-increment: line 1; color: rgba(0, 0, 0, 0.3);">ounter(line</span></li>
<li style="list-style-type: none; text-align: right; line-height: 26px; margin: 0px;">
		<span style="min-width: 1.5em; left: -2.5em; counter-increment: line 1; color: rgba(0, 0, 0, 0.3);">ounter(line</span></li>
<li style="list-style-type: none; text-align: right; line-height: 26px; margin: 0px;">
		<span style="min-width: 1.5em; left: -2.5em; counter-increment: line 1; color: rgba(0, 0, 0, 0.3);">ounter(line</span></li>
</ul>
<pre class="code-snippet__js" data-lang="bash" style="margin-bottom: 10px; margin-top: 0px; overflow-x: auto; padding: 16px; padding-left: 0; white-space: normal; flex: 1; -webkit-overflow-scrolling: touch;">
<code style="border-radius: 0px; white-space: pre; display: flex; position: relative; font-family: Consolas, &quot;Liberation Mono&quot;, Menlo, Courier, monospace; padding: 0px;"><span class="code-snippet_outer" style="line-height: 26px;">DEV=/dev/cu.usbserial-110                       # 换成你实际的设备名</span></code><code style="border-radius: 0px; white-space: pre; display: flex; position: relative; font-family: Consolas, &quot;Liberation Mono&quot;, Menlo, Courier, monospace; padding: 0px;"><span class="code-snippet_outer" style="line-height: 26px;">stty -f &quot;$DEV&quot; 9600 raw -echo                   # 设置波特率 9600，关闭回显</span></code><code style="border-radius: 0px; white-space: pre; display: flex; position: relative; font-family: Consolas, &quot;Liberation Mono&quot;, Menlo, Courier, monospace; padding: 0px;"><span class="code-snippet_outer" style="line-height: 26px;">(timeout 4 cat &quot;$DEV&quot; &gt; /tmp/rx.txt &amp;)          # 后台启动一个读取，读 4 秒</span></code><code style="border-radius: 0px; white-space: pre; display: flex; position: relative; font-family: Consolas, &quot;Liberation Mono&quot;, Menlo, Courier, monospace; padding: 0px;"><span class="code-snippet_outer" style="line-height: 26px;">printf &#39;\r&#39; &gt; &quot;$DEV&quot;                            # 往串口写一个回车，触发登录提示</span></code><code style="border-radius: 0px; white-space: pre; display: flex; position: relative; font-family: Consolas, &quot;Liberation Mono&quot;, Menlo, Courier, monospace; padding: 0px;"><span class="code-snippet_outer" style="line-height: 26px;">cat /tmp/rx.txt                                 # 查看收到的内容，应该能看到 &quot;rpi login:&quot;</span></code></pre>
</section>
<p data-tool="mdnice编辑器" style="padding-top: 8px; padding-bottom: 8px; margin: 0px; line-height: 26px;">
	<code style="font-size: 14px; word-wrap: break-word; padding: 2px 4px; border-radius: 4px; margin: 0 2px; color: #1e6bb8; background-color: rgba(27,31,35,.05); font-family: Operator Mono, Consolas, Monaco, Menlo, monospace; word-break: break-all;">stty</code> 负责配置串口参数，<code style="font-size: 14px; word-wrap: break-word; padding: 2px 4px; border-radius: 4px; margin: 0 2px; color: #1e6bb8; background-color: rgba(27,31,35,.05); font-family: Operator Mono, Consolas, Monaco, Menlo, monospace; word-break: break-all;">cat</code> 负责读，<code style="font-size: 14px; word-wrap: break-word; padding: 2px 4px; border-radius: 4px; margin: 0 2px; color: #1e6bb8; background-color: rgba(27,31,35,.05); font-family: Operator Mono, Consolas, Monaco, Menlo, monospace; word-break: break-all;">printf</code> 负责写&mdash;&mdash;把串口当成一个文件来读写就行。</p>
<hr data-tool="mdnice编辑器" style="height: 1px; margin: 0; margin-top: 10px; margin-bottom: 10px; border: none; border-top: 1px solid black;" />
<h2 data-tool="mdnice编辑器" style="margin-top: 30px; margin-bottom: 15px; padding: 0px; font-size: 22px;">
	<span class="content">5. 调试记录：踩过的坑</span></h2>
<p data-tool="mdnice编辑器" style="padding-top: 8px; padding-bottom: 8px; margin: 0px; line-height: 26px;">
	下面这些是实际接线、调通过程中遇到的问题。如果你一次就成功了，可以跳过本章；如果哪里不对，按顺序排查通常能解决。<br />
	<span style="color: rgb(255, 255, 255);">文章来源：</span><a href="https://www.codelast.com/" rel="noopener noreferrer" target="_blank"><span style="color: rgb(255, 255, 255);">https://www.codelast.com/</span></a></p>
<h3 data-tool="mdnice编辑器" style="margin-top: 30px; margin-bottom: 15px; padding: 0px; font-size: 20px;">
	<span class="content">5.1 第一次接上：完全没有输出，或者全是乱码</span></h3>
<p data-tool="mdnice编辑器" style="padding-top: 8px; padding-bottom: 8px; margin: 0px; line-height: 26px;">
	刚接上时最常见的两个现象：读串口读到 0 字节（什么都没有），或者读到 40~70 字节的乱码。</p>
<p data-tool="mdnice编辑器" style="padding-top: 8px; padding-bottom: 8px; margin: 0px; line-height: 26px;">
	按下面的顺序排查：</p>
<p data-tool="mdnice编辑器" style="padding-top: 8px; padding-bottom: 8px; margin: 0px; line-height: 26px;">
	<strong style="font-weight: bold;">第 1 步：先确认 CH340 小板本身是好的（环回测试）</strong></p>
<p data-tool="mdnice编辑器" style="padding-top: 8px; padding-bottom: 8px; margin: 0px; line-height: 26px;">
	把 CH340 和树莓派的接线全部断开，然后用一根杜邦线把 CH340 板上的 <strong style="font-weight: bold;">TXD 和 RXD 短接</strong>（直接连在一起）。这样一来，CH340 自己发出去的数据会原路回到自己。然后用 <code style="font-size: 14px; word-wrap: break-word; padding: 2px 4px; border-radius: 4px; margin: 0 2px; color: #1e6bb8; background-color: rgba(27,31,35,.05); font-family: Operator Mono, Consolas, Monaco, Menlo, monospace; word-break: break-all;">screen</code> 连上串口随便敲几个字：如果敲什么回显什么，说明 CH340 小板、USB 线、驱动这一整条链路都是好的，问题出在树莓派那一侧。</p>
<p data-tool="mdnice编辑器" style="padding-top: 8px; padding-bottom: 8px; margin: 0px; line-height: 26px;">
	不想开终端的话，也可以用命令自动验证：</p>
<section class="code-snippet__fix code-snippet__js" data-tool="mdnice编辑器" style="font-size: 14px; margin: 10px 0; display: block; color: #333; position: relative; background-color: rgba(0,0,0,0.03); border: 1px solid #f0f0f0; border-radius: 2px; display: flex; line-height: 20px; word-wrap: break-word !important;">
<ul class="code-snippet__line-index code-snippet__js" style="margin-top: 8px; margin-bottom: 8px; padding-left: 25px; color: black; counter-reset: line; flex-shrink: 0; height: 100%; padding: 1em; list-style-type: none; padding: 16px; margin: 0;">
<li style="list-style-type: none; text-align: right; line-height: 26px; margin: 0px;">
		<span style="min-width: 1.5em; left: -2.5em; counter-increment: line 1; color: rgba(0, 0, 0, 0.3);">ounter(line</span></li>
<li style="list-style-type: none; text-align: right; line-height: 26px; margin: 0px;">
		<span style="min-width: 1.5em; left: -2.5em; counter-increment: line 1; color: rgba(0, 0, 0, 0.3);">ounter(line</span></li>
<li style="list-style-type: none; text-align: right; line-height: 26px; margin: 0px;">
		<span style="min-width: 1.5em; left: -2.5em; counter-increment: line 1; color: rgba(0, 0, 0, 0.3);">ounter(line</span></li>
<li style="list-style-type: none; text-align: right; line-height: 26px; margin: 0px;">
		<span style="min-width: 1.5em; left: -2.5em; counter-increment: line 1; color: rgba(0, 0, 0, 0.3);">ounter(line</span></li>
</ul>
<pre class="code-snippet__js" data-lang="bash" style="margin-bottom: 10px; margin-top: 0px; overflow-x: auto; padding: 16px; padding-left: 0; white-space: normal; flex: 1; -webkit-overflow-scrolling: touch;">
<code style="border-radius: 0px; white-space: pre; display: flex; position: relative; font-family: Consolas, &quot;Liberation Mono&quot;, Menlo, Courier, monospace; padding: 0px;"><span class="code-snippet_outer" style="line-height: 26px;">stty -f $DEV 115200 raw -echo</span></code><code style="border-radius: 0px; white-space: pre; display: flex; position: relative; font-family: Consolas, &quot;Liberation Mono&quot;, Menlo, Courier, monospace; padding: 0px;"><span class="code-snippet_outer" style="line-height: 26px;">(timeout 8 cat $DEV &gt; /tmp/loop.txt &amp;)   # 后台读</span></code><code style="border-radius: 0px; white-space: pre; display: flex; position: relative; font-family: Consolas, &quot;Liberation Mono&quot;, Menlo, Courier, monospace; padding: 0px;"><span class="code-snippet_outer" style="line-height: 26px;">printf &#39;HELLO_LOOP&#39; &gt; $DEV                # 写入一串测试文字</span></code><code style="border-radius: 0px; white-space: pre; display: flex; position: relative; font-family: Consolas, &quot;Liberation Mono&quot;, Menlo, Courier, monospace; padding: 0px;"><span class="code-snippet_outer" style="line-height: 26px;">grep HELLO_LOOP /tmp/loop.txt &amp;&amp; echo OK   # 能在读到的内容里找到它 =&gt; 模块正常</span></code></pre>
</section>
<p data-tool="mdnice编辑器" style="padding-top: 8px; padding-bottom: 8px; margin: 0px; line-height: 26px;">
	如果这步通过，说明小板没问题，继续看第 2 步。</p>
<p data-tool="mdnice编辑器" style="padding-top: 8px; padding-bottom: 8px; margin: 0px; line-height: 26px;">
	<strong style="font-weight: bold;">第 2 步：检查 GND 是否共地、TXD/RXD 是否交叉</strong></p>
<p data-tool="mdnice编辑器" style="padding-top: 8px; padding-bottom: 8px; margin: 0px; line-height: 26px;">
	读到的字节数是 0 时，优先怀疑两件事：GND 没接（换一个 GND 引脚试试），或者 TXD/RXD 没交叉。我实际遇到过：把 GND 从 Pin 30 换到 Pin 20 之后，读到的数据从 0 字节一下子变成 182 字节&mdash;&mdash;共地的影响就是这么明显。</p>
<p data-tool="mdnice编辑器" style="padding-top: 8px; padding-bottom: 8px; margin: 0px; line-height: 26px;">
	<strong style="font-weight: bold;">第 3 步：把 TXD 和 RXD 两根线对调</strong></p>
<p data-tool="mdnice编辑器" style="padding-top: 8px; padding-bottom: 8px; margin: 0px; line-height: 26px;">
	如果前面都查过还是没数据，把 TXD、RXD 两根线互换位置再试。很多时候数据从无到有，就差这一下。</p>
<h3 data-tool="mdnice编辑器" style="margin-top: 30px; margin-bottom: 15px; padding: 0px; font-size: 20px;">
	<span class="content">5.2 有数据了，但是全是乱码 &rarr; 波特率不对</span></h3>
<p data-tool="mdnice编辑器" style="padding-top: 8px; padding-bottom: 8px; margin: 0px; line-height: 26px;">
	现象：能收到数据了，但内容完全没法看，全是乱码；而且换了好几档波特率读出来的都是&quot;长度差不多的乱码&quot;。</p>
<p data-tool="mdnice编辑器" style="padding-top: 8px; padding-bottom: 8px; margin: 0px; line-height: 26px;">
	这是因为<strong style="font-weight: bold;">两边的波特率不一致</strong>。串口通信里，发送方和接收方必须用同样的波特率（相当于约定同样的说话语速），否则对方听到的就是无意义的声音。</p>
<p data-tool="mdnice编辑器" style="padding-top: 8px; padding-bottom: 8px; margin: 0px; line-height: 26px;">
	推荐用&quot;矩阵测试&quot;来找到正确的波特率：树莓派和 macOS 两边同步切到同一个波特率，树莓派持续发一段特征文字，macOS 在另一边读，看哪一档能读出可读的文本。</p>
<p data-tool="mdnice编辑器" style="padding-top: 8px; padding-bottom: 8px; margin: 0px; line-height: 26px;">
	树莓派侧（示例用 9600）：</p>
<section class="code-snippet__fix code-snippet__js" data-tool="mdnice编辑器" style="font-size: 14px; margin: 10px 0; display: block; color: #333; position: relative; background-color: rgba(0,0,0,0.03); border: 1px solid #f0f0f0; border-radius: 2px; display: flex; line-height: 20px; word-wrap: break-word !important;">
<ul class="code-snippet__line-index code-snippet__js" style="margin-top: 8px; margin-bottom: 8px; padding-left: 25px; color: black; counter-reset: line; flex-shrink: 0; height: 100%; padding: 1em; list-style-type: none; padding: 16px; margin: 0;">
<li style="list-style-type: none; text-align: right; line-height: 26px; margin: 0px;">
		<span style="min-width: 1.5em; left: -2.5em; counter-increment: line 1; color: rgba(0, 0, 0, 0.3);">ounter(line</span></li>
<li style="list-style-type: none; text-align: right; line-height: 26px; margin: 0px;">
		<span style="min-width: 1.5em; left: -2.5em; counter-increment: line 1; color: rgba(0, 0, 0, 0.3);">ounter(line</span></li>
</ul>
<pre class="code-snippet__js" data-lang="bash" style="margin-bottom: 10px; margin-top: 0px; overflow-x: auto; padding: 16px; padding-left: 0; white-space: normal; flex: 1; -webkit-overflow-scrolling: touch;">
<code style="border-radius: 0px; white-space: pre; display: flex; position: relative; font-family: Consolas, &quot;Liberation Mono&quot;, Menlo, Courier, monospace; padding: 0px;"><span class="code-snippet_outer" style="line-height: 26px;">sudo stty -F /dev/ttyS0 9600 raw -echo        # ttyS0 或 ttyAMA0，按你实际设备名</span></code><code style="border-radius: 0px; white-space: pre; display: flex; position: relative; font-family: Consolas, &quot;Liberation Mono&quot;, Menlo, Courier, monospace; padding: 0px;"><span class="code-snippet_outer" style="line-height: 26px;">for i in 1 2 3 4; do echo -n &quot;MATRIX_BAUD_9600_$i&quot; &gt; /dev/ttyS0; sleep 0.2; done</span></code></pre>
</section>
<p data-tool="mdnice编辑器" style="padding-top: 8px; padding-bottom: 8px; margin: 0px; line-height: 26px;">
	macOS 侧：</p>
<section class="code-snippet__fix code-snippet__js" data-tool="mdnice编辑器" style="font-size: 14px; margin: 10px 0; display: block; color: #333; position: relative; background-color: rgba(0,0,0,0.03); border: 1px solid #f0f0f0; border-radius: 2px; display: flex; line-height: 20px; word-wrap: break-word !important;">
<ul class="code-snippet__line-index code-snippet__js" style="margin-top: 8px; margin-bottom: 8px; padding-left: 25px; color: black; counter-reset: line; flex-shrink: 0; height: 100%; padding: 1em; list-style-type: none; padding: 16px; margin: 0;">
<li style="list-style-type: none; text-align: right; line-height: 26px; margin: 0px;">
		<span style="min-width: 1.5em; left: -2.5em; counter-increment: line 1; color: rgba(0, 0, 0, 0.3);">ounter(line</span></li>
<li style="list-style-type: none; text-align: right; line-height: 26px; margin: 0px;">
		<span style="min-width: 1.5em; left: -2.5em; counter-increment: line 1; color: rgba(0, 0, 0, 0.3);">ounter(line</span></li>
<li style="list-style-type: none; text-align: right; line-height: 26px; margin: 0px;">
		<span style="min-width: 1.5em; left: -2.5em; counter-increment: line 1; color: rgba(0, 0, 0, 0.3);">ounter(line</span></li>
</ul>
<pre class="code-snippet__js" data-lang="bash" style="margin-bottom: 10px; margin-top: 0px; overflow-x: auto; padding: 16px; padding-left: 0; white-space: normal; flex: 1; -webkit-overflow-scrolling: touch;">
<code style="border-radius: 0px; white-space: pre; display: flex; position: relative; font-family: Consolas, &quot;Liberation Mono&quot;, Menlo, Courier, monospace; padding: 0px;"><span class="code-snippet_outer" style="line-height: 26px;">stty -f $DEV 9600 raw -echo</span></code><code style="border-radius: 0px; white-space: pre; display: flex; position: relative; font-family: Consolas, &quot;Liberation Mono&quot;, Menlo, Courier, monospace; padding: 0px;"><span class="code-snippet_outer" style="line-height: 26px;">(timeout 4 cat $DEV &gt; /tmp/mx.txt &amp;)</span></code><code style="border-radius: 0px; white-space: pre; display: flex; position: relative; font-family: Consolas, &quot;Liberation Mono&quot;, Menlo, Courier, monospace; padding: 0px;"><span class="code-snippet_outer" style="line-height: 26px;">grep MATRIX_BAUD /tmp/mx.txt &amp;&amp; echo 通过</span></code></pre>
</section>
<p data-tool="mdnice编辑器" style="padding-top: 8px; padding-bottom: 8px; margin: 0px; line-height: 26px;">
	我实际测试的结果是：<strong style="font-weight: bold;">9600 波特率下两边完全互通，反而 115200 读出来是乱的</strong>&mdash;&mdash;这块 CH340 小板在 115200 这个高速档上精度不稳。所以最后统一把波特率定在 9600（8 数据位、无校验、1 停止位，也就是常说的 8N1），内核 console、getty、macOS 端全部用 9600。</p>
<h3 data-tool="mdnice编辑器" style="margin-top: 30px; margin-bottom: 15px; padding: 0px; font-size: 20px;">
	<span class="content">5.3 能看到内核日志，但没有 login 提示 &rarr; getty 没起来</span></h3>
<p data-tool="mdnice编辑器" style="padding-top: 8px; padding-bottom: 8px; margin: 0px; line-height: 26px;">
	现象：串口上能看到内核启动的日志，但日志播完就没了，一直没有 <code style="font-size: 14px; word-wrap: break-word; padding: 2px 4px; border-radius: 4px; margin: 0 2px; color: #1e6bb8; background-color: rgba(27,31,35,.05); font-family: Operator Mono, Consolas, Monaco, Menlo, monospace; word-break: break-all;">login:</code> 提示符。</p>
<p data-tool="mdnice编辑器" style="padding-top: 8px; padding-bottom: 8px; margin: 0px; line-height: 26px;">
	这说明问题不在硬件，而在系统这边&mdash;&mdash;<strong style="font-weight: bold;">没有程序在串口上等你登录</strong>，也就是 3.4 节说的 getty 没有正确启动，或者它的波特率和 console 不一致。解决办法就是按 3.4 节写好 override 文件、启用对应的 <code style="font-size: 14px; word-wrap: break-word; padding: 2px 4px; border-radius: 4px; margin: 0 2px; color: #1e6bb8; background-color: rgba(27,31,35,.05); font-family: Operator Mono, Consolas, Monaco, Menlo, monospace; word-break: break-all;">serial-getty@&lt;设备&gt;.service</code>。</p>
<h3 data-tool="mdnice编辑器" style="margin-top: 30px; margin-bottom: 15px; padding: 0px; font-size: 20px;">
	<span class="content">5.4 换了个 USB 口，就连不上了 &rarr; 设备名变了</span></h3>
<p data-tool="mdnice编辑器" style="padding-top: 8px; padding-bottom: 8px; margin: 0px; line-height: 26px;">
	现象：之前明明连得好好的，换了个 USB 口再插，<code style="font-size: 14px; word-wrap: break-word; padding: 2px 4px; border-radius: 4px; margin: 0 2px; color: #1e6bb8; background-color: rgba(27,31,35,.05); font-family: Operator Mono, Consolas, Monaco, Menlo, monospace; word-break: break-all;">screen</code> 报错 <code style="font-size: 14px; word-wrap: break-word; padding: 2px 4px; border-radius: 4px; margin: 0 2px; color: #1e6bb8; background-color: rgba(27,31,35,.05); font-family: Operator Mono, Consolas, Monaco, Menlo, monospace; word-break: break-all;">[screen is terminating]</code>。</p>
<p data-tool="mdnice编辑器" style="padding-top: 8px; padding-bottom: 8px; margin: 0px; line-height: 26px;">
	原因在 4.1 节说过：<strong style="font-weight: bold;">设备名末尾的数字每次插拔都可能变</strong>。换了 USB 口，旧名字就失效了。解决办法很简单：重新执行 <code style="font-size: 14px; word-wrap: break-word; padding: 2px 4px; border-radius: 4px; margin: 0 2px; color: #1e6bb8; background-color: rgba(27,31,35,.05); font-family: Operator Mono, Consolas, Monaco, Menlo, monospace; word-break: break-all;">ls /dev/cu.usbserial*</code> 查出新的设备名，用新名字重新连接。</p>
<hr data-tool="mdnice编辑器" style="height: 1px; margin: 0; margin-top: 10px; margin-bottom: 10px; border: none; border-top: 1px solid black;" />
<h2 data-tool="mdnice编辑器" style="margin-top: 30px; margin-bottom: 15px; padding: 0px; font-size: 22px;">
	<span class="content">6. 最终验证（确认可用）</span></h2>
<p data-tool="mdnice编辑器" style="padding-top: 8px; padding-bottom: 8px; margin: 0px; line-height: 26px;">
	配置全部完成后，用下面两条验证整个链路是通的。<br />
	<span style="color: rgb(255, 255, 255);">文章来源：</span><a href="https://www.codelast.com/" rel="noopener noreferrer" target="_blank"><span style="color: rgb(255, 255, 255);">https://www.codelast.com/</span></a></p>
<p data-tool="mdnice编辑器" style="padding-top: 8px; padding-bottom: 8px; margin: 0px; line-height: 26px;">
	交互式验证（macOS 终端里）：</p>
<section class="code-snippet__fix code-snippet__js" data-tool="mdnice编辑器" style="font-size: 14px; margin: 10px 0; display: block; color: #333; position: relative; background-color: rgba(0,0,0,0.03); border: 1px solid #f0f0f0; border-radius: 2px; display: flex; line-height: 20px; word-wrap: break-word !important;">
<ul class="code-snippet__line-index code-snippet__js" style="margin-top: 8px; margin-bottom: 8px; padding-left: 25px; color: black; counter-reset: line; flex-shrink: 0; height: 100%; padding: 1em; list-style-type: none; padding: 16px; margin: 0;">
<li style="list-style-type: none; text-align: right; line-height: 26px; margin: 0px;">
		<span style="min-width: 1.5em; left: -2.5em; counter-increment: line 1; color: rgba(0, 0, 0, 0.3);">ounter(line</span></li>
<li style="list-style-type: none; text-align: right; line-height: 26px; margin: 0px;">
		<span style="min-width: 1.5em; left: -2.5em; counter-increment: line 1; color: rgba(0, 0, 0, 0.3);">ounter(line</span></li>
</ul>
<pre class="code-snippet__js" data-lang="bash" style="margin-bottom: 10px; margin-top: 0px; overflow-x: auto; padding: 16px; padding-left: 0; white-space: normal; flex: 1; -webkit-overflow-scrolling: touch;">
<code style="border-radius: 0px; white-space: pre; display: flex; position: relative; font-family: Consolas, &quot;Liberation Mono&quot;, Menlo, Courier, monospace; padding: 0px;"><span class="code-snippet_outer" style="line-height: 26px;">screen /dev/cu.usbserial-110 9600</span></code><code style="border-radius: 0px; white-space: pre; display: flex; position: relative; font-family: Consolas, &quot;Liberation Mono&quot;, Menlo, Courier, monospace; padding: 0px;"><span class="code-snippet_outer" style="line-height: 26px;"># 应该看到 rpi login:，输入用户名密码进入 shell</span></code></pre>
</section>
<p data-tool="mdnice编辑器" style="padding-top: 8px; padding-bottom: 8px; margin: 0px; line-height: 26px;">
	非交互式验证（脚本里用）：</p>
<section class="code-snippet__fix code-snippet__js" data-tool="mdnice编辑器" style="font-size: 14px; margin: 10px 0; display: block; color: #333; position: relative; background-color: rgba(0,0,0,0.03); border: 1px solid #f0f0f0; border-radius: 2px; display: flex; line-height: 20px; word-wrap: break-word !important;">
<ul class="code-snippet__line-index code-snippet__js" style="margin-top: 8px; margin-bottom: 8px; padding-left: 25px; color: black; counter-reset: line; flex-shrink: 0; height: 100%; padding: 1em; list-style-type: none; padding: 16px; margin: 0;">
<li style="list-style-type: none; text-align: right; line-height: 26px; margin: 0px;">
		<span style="min-width: 1.5em; left: -2.5em; counter-increment: line 1; color: rgba(0, 0, 0, 0.3);">ounter(line</span></li>
<li style="list-style-type: none; text-align: right; line-height: 26px; margin: 0px;">
		<span style="min-width: 1.5em; left: -2.5em; counter-increment: line 1; color: rgba(0, 0, 0, 0.3);">ounter(line</span></li>
</ul>
<pre class="code-snippet__js" data-lang="bash" style="margin-bottom: 10px; margin-top: 0px; overflow-x: auto; padding: 16px; padding-left: 0; white-space: normal; flex: 1; -webkit-overflow-scrolling: touch;">
<code style="border-radius: 0px; white-space: pre; display: flex; position: relative; font-family: Consolas, &quot;Liberation Mono&quot;, Menlo, Courier, monospace; padding: 0px;"><span class="code-snippet_outer" style="line-height: 26px;">printf &#39;\r&#39; &gt; $DEV</span></code><code style="border-radius: 0px; white-space: pre; display: flex; position: relative; font-family: Consolas, &quot;Liberation Mono&quot;, Menlo, Courier, monospace; padding: 0px;"><span class="code-snippet_outer" style="line-height: 26px;">timeout 5 cat $DEV        # 应该能看到 &quot;rpi login:&quot;</span></code></pre>
</section>
</section>
<p></p>
<p>
	<span style="color: rgb(255, 255, 255);">文章来源：</span><a href="https://www.codelast.com/" rel="noopener noreferrer" target="_blank"><span style="color: rgb(255, 255, 255);">https://www.codelast.com/</span></a><br />
	<span style="color: rgb(255, 0, 0);">➤➤</span> 版权声明 <span style="color: rgb(255, 0, 0);">➤➤</span>&nbsp;<br />
	转载需注明出处：<u><a href="https://www.codelast.com/" rel="noopener noreferrer" target="_blank"><em><span style="color: rgb(0, 0, 255);"><strong style="font-size: 16px;"><span style="font-family: arial, helvetica, sans-serif;">codelast.com</span></strong></span></em></a></u>&nbsp;<br />
	感谢关注我的微信公众号（微信扫一扫）：<br />
	<img decoding="async" alt="wechat qrcode of codelast" src="https://www.codelast.com/codelast_wechat_qr_code.jpg" style="color: rgb(77, 77, 77); font-size: 13px; width: 200px; height: 200px;" /><br />
	以及我的微信视频号：</p>
<p style="border: 0px; font-size: 13px; margin: 0px 0px 9px; outline: 0px; padding: 0px; color: rgb(77, 77, 77);">
	<img decoding="async" alt="" src="https://www.codelast.com/wechat_shipinhao_qr_code.jpg" style="text-align: center; width: 200px; height: 199px;" /></p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.codelast.com/%e5%8e%9f%e5%88%9b-%e9%80%9a%e8%bf%87%e4%b8%b2%e5%8f%a3%e7%bb%88%e7%ab%af%e8%bf%9e%e6%8e%a5%e6%a0%91%e8%8e%93%e6%b4%bech340/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
