serial-monitor
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
Chinese串口监视
Serial Port Monitoring
适用场景
Applicable Scenarios
- 用户需要查看目标板的启动日志、断言输出或交互式 UART 输出。
- 烧录或复位刚完成,下一步需要观察运行期行为。
- 需要避免错过早期启动日志,或希望在监听后立即复位目标板。
- 工作区或 profile 中已经有明确的 UART 端口或波特率。
- Users need to view the startup logs, assertion outputs, or interactive UART outputs of the target board.
- Flashing or resetting has just been completed, and the next step is to observe runtime behavior.
- Need to avoid missing early startup logs, or want to reset the target board immediately after monitoring starts.
- There is a clear UART port or baud rate defined in the workspace or Project Profile.
必要输入
Required Inputs
- 一个串口,或一份足以完成串口探测的 。
Project Profile - 可选的波特率、监视模式、关键字符串、日志保存路径。
- 若要自动复位,还需要 OpenOCD 配置,来自显式输入或已有工程画像。
- A serial port, or a Project Profile sufficient for serial port detection.
- Optional baud rate, monitoring mode, key strings, and log save path.
- For automatic reset, an OpenOCD configuration is also required, which can come from explicit input or an existing project profile.
自动探测
Automatic Detection
- 串口优先级为:显式用户输入、、脚本自动检测结果,否则阻塞。
Project Profile - 波特率优先级为:显式用户输入、、工作区文档或代码常量,最后回落到
Project Profile。115200 - 自动检测时,优先选择 CH340、CP210x、CMSIS-DAP、ST-Link 等常见串口或调试器虚拟串口。
- 若存在多个同样合理的串口候选,先列出候选,再按需要阻塞而不是静默猜测。
- Serial port priority: explicit user input > Project Profile > script automatic detection result; otherwise, the process will block.
- Baud rate priority: explicit user input > Project Profile > workspace documents or code constants; finally falls back to .
115200 - During automatic detection, priority is given to common serial ports or debugger virtual serial ports such as CH340, CP210x, CMSIS-DAP, ST-Link.
- If there are multiple equally reasonable serial port candidates, list the candidates first, then block as needed instead of making silent guesses.
执行步骤
Execution Steps
- 先阅读 references/usage.md,确认本次是列表、抓取、等待字符串、持续监视,还是“先监听后复位”。
- 运行自带脚本 scripts/serial_monitor.py。列出串口时使用 ,自动选择端口时使用
--list。--auto - 普通抓取使用 ,等待特定输出使用
--duration,持续监视使用--wait。--monitor --timestamp - 若担心错过早期启动日志,使用 ;只有在 OpenOCD 配置已经明确时,才启用
--wait-reset。--auto-reset - 读取脚本输出的分析结果,而不是只转述原始串口文本;重点关注错误、警告、启动标记和关键外设关键词。
- 将选中的串口、波特率、命令和日志结论写回 ,并在需要时交给下游 skill。
Project Profile
- First read references/usage.md to confirm whether this operation is for listing ports, capturing logs, waiting for specific strings, continuous monitoring, or "monitor first then reset".
- Run the built-in script scripts/serial_monitor.py. Use to list serial ports, and
--listto automatically select a port.--auto - Use for regular log capture,
--durationto wait for specific output, and--waitfor continuous monitoring.--monitor --timestamp - Use if you are worried about missing early startup logs; enable
--wait-resetonly when the OpenOCD configuration is clearly defined.--auto-reset - Read the analysis results output by the script instead of just relaying the original serial port text; focus on errors, warnings, startup markers, and key peripheral keywords.
- Write the selected serial port, baud rate, command, and log conclusion back to the Project Profile, and pass them to downstream skills if needed.
失败分流
Failure Diversion
- 当缺少 或
pyserial等依赖时,返回openocd。environment-missing - 当选中的串口无法打开或在监视过程中消失时,返回 。
connection-failure - 当宿主机没有权限访问串口设备时,返回 。
permission-problem - 当存在多个合理串口候选,或工作区中隐含互相冲突的波特率时,返回 。
ambiguous-context - 当串口可访问,但日志明显表现为启动失败、重复复位、断言或 Fault 时,返回 。
target-response-abnormal
- Return when dependencies such as
environment-missingorpyserialare missing.openocd - Return when the selected serial port cannot be opened or disappears during monitoring.
connection-failure - Return when the host does not have permission to access the serial port device.
permission-problem - Return when there are multiple reasonable serial port candidates, or there are conflicting baud rates implied in the workspace.
ambiguous-context - Return when the serial port is accessible but the logs clearly show startup failure, repeated reset, assertion, or Fault.
target-response-abnormal
平台说明
Platform Notes
- Linux、macOS、Windows 的串口命名规则复用 platform-compatibility.md。
- 自带脚本使用 ,因此串口抓取路径本身是跨平台的。
pyserial - Windows 输出中要保留准确的 端口名,以及 shell 需要的命令行引号形式。
COM
- The serial port naming rules for Linux, macOS, and Windows reuse platform-compatibility.md.
- The built-in script uses , so the serial port capture path itself is cross-platform.
pyserial - In Windows output, retain the exact port name and the command line quote format required by the shell.
COM
输出约定
Output Conventions
- 输出选中的串口、波特率、实际执行命令,以及对日志分析结果的简洁总结。
- 当串口和波特率被明确后,用 和
serial_port更新baud_rate。Project Profile - 若使用了 ,同时记录 OpenOCD 配置来源和复位命令。
--auto-reset - 当日志表明程序崩溃、卡死或启动异常时,推荐 。
debug-gdb-openocd
- Output the selected serial port, baud rate, actual execution command, and a concise summary of the log analysis results.
- Update the Project Profile with and
serial_portonce the serial port and baud rate are confirmed.baud_rate - If is used, record the source of the OpenOCD configuration and the reset command at the same time.
--auto-reset - When logs indicate program crash, freeze, or abnormal startup, recommend .
debug-gdb-openocd
交接关系
Handover Relationship
- 当日志显示需要断点、寄存器或回溯时,将结果交给 。
debug-gdb-openocd
- When logs indicate the need for breakpoints, registers, or backtracking, pass the results to .
debug-gdb-openocd