Update and test

Console factory CLI

The factory test port. Do not leave debug commands open for end users.

Update and test Factory CLI ESP32 family

Official path: examples/system/console

01 Overview

The Console is a UART-based command-line interface on the ESP32, commonly used for production testing and lab debugging. It allows executing hardware self-tests, reading parameters, and writing configuration via simple text commands.

On the production line, the Console works with a fixture to quickly verify each board's basic functions: LED operation, Wi-Fi RF performance, MAC address readability, and serial number writability. These tests catch early failures.

The Console is also handy during development, letting engineers directly access registers, view logs, and trigger specific behaviors without re-flashing firmware.

However, the Console is not a consumer-facing interface. If exposed, end users might misoperate or exploit it, causing device malfunction or security vulnerabilities. Therefore, production firmware must disable or protect the Console.

This page focuses on using the Console as a factory test tool, covering hardware design, firmware flow, and precautions.

02 Hardware

  • UART interface: The test UART typically uses the default UART0 (GPIO1/GPIO3), but can share the log port. For a separate port, use other UART pins, but specify in the schematic.
  • Test pads: Reserve test pads or headers on the PCB for fixture connection. Plan this on the first board to avoid later rework.
  • Level shifting: If the fixture uses 5V logic, add a level shifter (e.g., TXS0108) to avoid damaging GPIOs.
  • Power: During testing, the fixture supplies power; ensure the regulator (e.g., AMS1117) can handle the current draw.
  • Antenna connection: For Wi-Fi tests, ensure the antenna connector (e.g., IPEX) can be disconnected to connect conducted test equipment.
  • Other peripherals: Depending on the product, you may need to bring out test points for LEDs, buttons, sensors, but reuse existing interfaces where possible.
  • Layout notes: Test points should be near the board edge for easy probe access; avoid being covered by the enclosure.

03 Software flow

1. Initialize NVS and default pins, then call `console_cmd_init()` to register basic commands (e.g., help, free, heap).

2. Register factory-specific commands such as `test_led`, `test_wifi`, `read_mac`, `write_serial`. Each command maps to a handler function.

3. In factory mode, receive commands over UART, parse and execute. Add a simple handshake (e.g., send a specific character) to prevent accidental triggers.

4. After executing a test command, return results (e.g., OK/FAIL) over UART; the fixture decides pass/fail.

5. For operations like writing serial numbers, ensure they are written to NVS or OTP, and verify uniqueness.

6. In production firmware, disable factory commands via compile-time macros or runtime flags, or require a password to enter.

7. If remote updates are needed, combine with OTA, but the factory port is not for user upgrades.

04 Core points

  • The CLI is a factory asset, not a user feature. Exposing it to users can lead to security risks; disable or protect it in release firmware.
  • Custom work: fixture protocol, serialisation, release switch. Define the command set and flow based on the product.
  • UART sharing: If sharing with the log port, note that log output may interfere with command parsing; disable logs or use a different baud rate in factory mode.
  • Test coverage: Factory commands should cover key hardware (e.g., Flash, PSRAM, sensors), but avoid over-testing to keep production time low.
  • Security: Commands like serial write need permission control to prevent accidental misuse.
  • Do not copy console implementations from other chips: ESP32's console component is based on readline; command registration differs from Linux, so follow the ESP-IDF example.

中文

升级与产测

Console 产测指令

工厂测试口。不要把调试命令留给最终用户乱开。

升级与产测 产线命令 ESP32 family

官方路径: examples/system/console

01 项目概述

Console 是 ESP32 上基于 UART 的命令行交互环境,常用于产线测试和研发调试。它允许通过简单的文本命令执行硬件自检、参数读取和配置写入。

在产线上,Console 配合治具可以快速验证每块板子的基本功能:LED 是否点亮、Wi-Fi 射频是否正常、MAC 地址是否可读、序列号是否可写。这些测试能有效拦截早期不良品。

Console 也适合研发阶段使用,工程师可以通过命令行直接操作寄存器、查看日志、触发特定行为,比反复烧录固件更高效。

但 Console 不是面向消费者的界面。如果最终产品暴露了 UART 命令行,用户可能误操作或恶意利用,导致设备异常或安全漏洞。因此,量产固件必须关闭或保护 Console。

本页聚焦于如何将 Console 用作产测工具,包括硬件设计、固件流程和注意事项。

02 项目硬件描述

  • UART 接口: 产测 UART 通常使用默认的 UART0(GPIO1/GPIO3),但也可以复用日志输出口。若需独立,可选用其他 UART 引脚,但需在原理图中明确。
  • 测试垫: 在 PCB 上预留测试焊盘或排针,方便治具连接。建议在首次投板时就规划,避免后期飞线。
  • 电平匹配: 若治具使用 5V 电平,需加电平转换芯片(如 TXS0108),否则可能损坏 GPIO。
  • 电源: 产测时治具供电,注意电流需求,确保稳压器(如 AMS1117)能承受。
  • 天线连接: 若测试 Wi-Fi,需确保天线接口(如 IPEX)可断开,以便连接传导测试设备。
  • 其他外设: 根据产品功能,可能需引出 LED、按键、传感器等测试点,但尽量复用现有接口。
  • 布局注意: 测试点应靠近板边,方便治具探针接触;避免被外壳遮挡。

03 项目软件流程描述

1. 初始化 NVS 和默认引脚,然后调用 `console_cmd_init()` 注册基础命令(如 help、free、heap)。

2. 注册产测专用命令,例如 `test_led`、`test_wifi`、`read_mac`、`write_serial`。每个命令对应一个处理函数。

3. 在产测模式下,通过 UART 接收命令,解析并执行。可添加简单的握手协议(如发送特定字符)防止误触发。

4. 测试命令执行后,通过 UART 返回结果(如 OK/FAIL),治具根据结果判断是否通过。

5. 对于写序列号等操作,需确保写入 NVS 或 OTP,并校验唯一性。

6. 量产固件中,通过编译宏或运行时标志禁用产测命令,或要求输入密码才能进入。

7. 若需远程更新,可结合 OTA,但产测口本身不用于用户升级。

04 项目核心点

  • 产测口是工厂资产,不是用户功能。 暴露给用户可能导致安全风险,务必在发行固件中关闭或保护。
  • 可定制: 治具协议、序列号写入、发行开关。根据具体产品定义命令集和流程。
  • UART 复用: 若与日志口共用,注意日志输出可能干扰命令解析,建议在产测模式下关闭日志或使用不同波特率。
  • 测试覆盖: 产测命令应覆盖关键硬件(如 Flash、PSRAM、传感器),但不要过度,以免增加产线时间。
  • 安全: 写序列号等命令需有权限控制,防止误操作。
  • 不要照搬其他芯片的 console 实现: ESP32 的 console 组件基于 readline,命令注册方式与 Linux 不同,需参考 ESP-IDF 示例。