* feat: add portable ESP32 development skill Add source-backed workflows, safe templates, native CLI routing, and a read-only preflight for ESP32 hardware and firmware work.\n\nAI assistance: research, drafting, implementation, and review used OpenAI Codex and delegated DeepSeek agents under human direction. * docs: harden ESP32 family and security guidance Add source-backed family traps, brownout, calibration, USB recovery, and security-mode boundaries found during independent review.\n\nAI assistance: independent audits and drafting used delegated DeepSeek agents and OpenAI Codex under human direction.
6.5 KiB
Debugging, recovery, and security
Diagnose from the lowest unproven layer. Do not rewrite application code while power, boot mode, port ownership, or bus electrical state remains unknown.
Failure ladder
- Host/tool: command exists, expected version/environment active, permissions correct.
- USB/serial: data-capable cable, stable USB identity, correct port, no competing process.
- Power/reset/boot: rails stable, EN/reset and BOOT/strapping levels correct, boot log captured.
- ROM loader/flash: targeted
chip-id, image target/layout, transfer, verification. - Bootloader/partition: valid image headers, selected slot, partition table, security state.
- Runtime: crash reason, watchdog, heap/stack, task state, exception/backtrace.
- Peripheral: pin routing, voltage, pulls, bus waveform, address/identity, driver sequence.
- Network/service: radio state, IP, DNS/time/TLS, endpoint, auth, application protocol.
- Physical behavior: calibration, load, thermal, EMI, mechanical/environmental constraints.
Flash and connection failures
Capture the complete native-tool error. Common categories:
No serial data received: wrong/non-ESP port, target not in download mode, reset wiring, cable, permissions, port owner, native-USB state, or power.- Invalid packet/header or intermittent transfer: marginal power, signal/cable, excessive baud, USB hub, competing access, or boot-mode instability.
- Wrong chip argument/image: stop and obtain the exact target artifact; do not force it.
- Write succeeds but no boot: capture boot log; inspect reset loop, image target, flash mode/frequency/size, offsets, partition table, boot slot, and security state.
Try a lower baud only after the basic target/port/power checks. Manual BOOT/RESET sequencing is board-specific. Use the board guide instead of random button timing.
Boot loops and crashes
Preserve the first complete boot log after power-on. Note reset reason, boot mode, image/partition choice, exception, program counter, and backtrace.
ESP-IDF Monitor can decode addresses against the matching ELF. A backtrace from another build is not evidence. Keep the ELF, map, sdkconfig, commit, and toolchain version for a released image.
Common classes:
- brownout: measure supply at the board during peaks;
- watchdog: find the blocked/starved task or interrupt path; do not merely extend the timeout;
- stack overflow: inspect task stack sizing and call depth;
- heap failure/fragmentation: capture free/largest-block metrics and allocation lifetime;
- illegal access/panic: decode against the exact ELF and inspect ownership/lifetime/concurrency;
- reset caused by serial DTR/RTS: reproduce with monitor
--no-resetor equivalent; - crash only with peripheral attached: isolate power, pin conflict, bus lock, interrupt storm, and driver sequence.
Bus diagnosis
I2C
Measure SDA/SCL idle high, effective pull-ups, and voltage. Scan at conservative speed, then inspect start/address/ACK with a logic analyzer. A device that ACKs but returns bad data points to register, timing, mode, endian, readiness, or signal-integrity issues.
SPI
Inspect CS, clock, MOSI, and MISO together. Verify mode and transaction boundaries. Floating MISO, wrong CS polarity, and a reset pin left asserted can resemble a software driver failure.
UART
Loop back the ESP32 UART, then loop back or independently test the peripheral. Verify voltage standard and framing. Capture bytes rather than relying on rendered text.
Recovery order
Use the least destructive rung that can restore observability:
- close port owners and capture logs with no-reset behavior;
- reset/power-cycle using the documented board path;
- enter documented ROM download or bootloader mode;
- query chip/flash identity;
- reflash the known-good build with generated/authoritative offsets;
- reflash bootloader/partition/application set when the framework requires it;
- erase only the specific corrupt data partition when supported and authorized;
- full-chip erase only after backup/impact review and explicit authorization;
- hardware debugger or board-level repair.
Before erase, preserve readable flash or at least record partition layout, MAC/identity, security state, calibration implications, credentials/data impact, and the known-good recovery artifact. Do not read or publish secret-bearing flash without authorization.
JTAG and debugger use
Use an ESP32-compatible OpenOCD configuration and voltage-compatible adapter. The exact JTAG pins and built-in USB JTAG support vary by family. Confirm pin conflicts and production security state. A debugger can change timing; reproduce without it before concluding the race is fixed.
Security provisioning
Secure boot, flash encryption, eFuses, JTAG/download-mode controls, signing keys, and anti-rollback are product lifecycle decisions. Some transitions are irreversible.
Before provisioning:
- identify exact SoC revision and supported security scheme;
- read the matching stable ESP-IDF security pages and eFuse documentation;
- define development, manufacturing, RMA, field-update, and decommission paths;
- protect signing/encryption keys outside source and build logs;
- verify image signing and encrypted-flash behavior on disposable hardware;
- verify OTA, rollback/anti-rollback, serial recovery restrictions, and RMA path;
- record non-secret provisioning evidence without publishing key material.
Secure Boot V1 and V2 are not interchangeable; choose the scheme supported by the exact chip revision and current ESP-IDF documentation. Flash Encryption development mode preserves reflashing paths for testing, while release mode applies production restrictions. Do not ship a development-mode security posture by accident: select the mode from the threat model only after OTA, recovery, manufacturing, and RMA behavior is proven.
Do not copy eFuse commands from a generic guide. Capture the chip-specific eFuse summary, coding scheme, and remaining writable fields before any burn. Do not enable flash encryption or secure boot merely to satisfy a checklist. The correct state depends on the threat model and a proven update/recovery lifecycle.
Bounded escalation
After two genuinely different approaches fail at the same layer, stop and report:
- exact board/SoC and evidence;
- wiring/power state;
- tool versions and commands;
- complete errors/logs;
- what each attempt proved or disproved;
- the next action and its risk.
A third blind reset, framework switch, erase, or guessed image adds risk faster than information.