Add chip type detection to device detection script

- Add --probe flag to detect exact chip type using esptool
- Show USB-based chip guess by default (faster)
- Support ESP32, ESP32-S2, ESP32-S3, ESP32-C3, ESP32-C6, ESP32-H2
- Useful for identifying mixed chip types in large deployments
This commit is contained in:
Bob 2025-11-10 03:43:58 +00:00
parent 1654753bbb
commit 33fb7fead1
1 changed files with 75 additions and 0 deletions

View File

@ -5,6 +5,57 @@ Detects and lists ESP32 devices connected via USB
"""
import serial.tools.list_ports
import subprocess
import sys
def detect_chip_type(port):
"""
Try to detect the ESP32 chip type using esptool.py
Returns chip type string or 'Unknown'
"""
try:
result = subprocess.run(
['esptool.py', '--port', port, 'chip_id'],
capture_output=True,
text=True,
timeout=10
)
output = result.stdout + result.stderr
if 'ESP32-S3' in output:
return 'ESP32-S3'
elif 'ESP32-S2' in output:
return 'ESP32-S2'
elif 'ESP32-C3' in output:
return 'ESP32-C3'
elif 'ESP32-C6' in output:
return 'ESP32-C6'
elif 'ESP32-H2' in output:
return 'ESP32-H2'
elif 'ESP32' in output:
return 'ESP32'
except Exception:
pass
return 'Unknown'
def guess_chip_type_from_usb(vid, pid):
"""
Make an educated guess about chip type based on USB VID:PID
Returns chip type string or None
"""
if vid == 0x303A: # Espressif USB
if pid == 0x1001:
return 'ESP32-S3/C3' # Built-in USB, could be either
elif pid == 0x1002:
return 'ESP32-S3/C3'
# For CP210x, CH340, etc., we can't tell from USB alone
return None
def detect_esp32_devices():
@ -59,6 +110,13 @@ def detect_esp32_devices():
def main():
import argparse
parser = argparse.ArgumentParser(description='ESP32 USB Device Detection')
parser.add_argument('--probe', action='store_true',
help='Probe each device to detect exact chip type (slower)')
args = parser.parse_args()
print("=" * 60)
print("ESP32 USB Device Detection")
print("=" * 60)
@ -79,6 +137,21 @@ def main():
if device.vid is not None and device.pid is not None:
print(f" VID:PID: {device.vid:04X}:{device.pid:04X}")
# Chip type detection
chip_type = None
if args.probe:
print(f" Probing chip type...", end='', flush=True)
chip_type = detect_chip_type(device.device)
print(f"\r Chip Type: {chip_type}")
else:
# Try to guess from USB VID:PID
if device.vid is not None and device.pid is not None:
chip_type = guess_chip_type_from_usb(device.vid, device.pid)
if chip_type:
print(f" Chip Guess: {chip_type} (use --probe for exact type)")
else:
print(f" Chip Type: Unknown (use --probe to detect)")
if device.manufacturer:
print(f" Manufacturer: {device.manufacturer}")
@ -89,6 +162,8 @@ def main():
print("=" * 60)
print(f"Total ESP32 devices detected: {len(esp32_devices)}")
if not args.probe:
print("Tip: Use --probe flag to detect exact chip types")
print("=" * 60)
else:
print("No ESP32 devices detected.")