|
| 1 | +# ESP32 driver |
| 2 | + |
| 3 | +`jumpstarter-driver-esp32` provides functionality for flashing and managing |
| 4 | +ESP32 devices using [esptool](https://github.com/espressif/esptool) as a |
| 5 | +library. It implements the `FlasherInterface` from `jumpstarter-driver-opendal`. |
| 6 | + |
| 7 | +## Installation |
| 8 | + |
| 9 | +```{code-block} console |
| 10 | +:substitutions: |
| 11 | +$ pip3 install --extra-index-url {{index_url}} jumpstarter-driver-esp32 |
| 12 | +``` |
| 13 | + |
| 14 | +## Configuration |
| 15 | + |
| 16 | +Example configuration: |
| 17 | + |
| 18 | +```yaml |
| 19 | +export: |
| 20 | + storage: |
| 21 | + type: jumpstarter_driver_esp32.driver.Esp32Flasher |
| 22 | + config: |
| 23 | + baudrate: 115200 |
| 24 | + chip: "esp32" |
| 25 | + children: |
| 26 | + serial: |
| 27 | + ref: serial |
| 28 | + serial: |
| 29 | + type: jumpstarter_driver_pyserial.driver.PySerial |
| 30 | + config: |
| 31 | + url: "/dev/ttyUSB0" |
| 32 | + baudrate: 115200 |
| 33 | +``` |
| 34 | +
|
| 35 | +### Config parameters |
| 36 | +
|
| 37 | +| Parameter | Description | Type | Required | Default | |
| 38 | +| --------- | ------------------------------------ | ---- | -------- | ------------- | |
| 39 | +| baudrate | Baud rate for esptool communication | int | no | 115200 | |
| 40 | +| chip | Target chip type | str | no | esp32 | |
| 41 | +
|
| 42 | +The ESP32 driver requires a `serial` child driver (PySerial) for serial port |
| 43 | +access. DTR/RTS control signals and the serial port path are managed through |
| 44 | +the child driver. Use a `ref` proxy to share the serial driver with the |
| 45 | +top-level composite, enabling both `j serial start-console` and |
| 46 | +`j storage flash` to work. |
| 47 | + |
| 48 | +## API Reference |
| 49 | + |
| 50 | +```{eval-rst} |
| 51 | +.. autoclass:: jumpstarter_driver_esp32.client.Esp32FlasherClient() |
| 52 | + :members: flash, dump, get_chip_info, erase, hard_reset, enter_bootloader |
| 53 | +``` |
| 54 | + |
| 55 | +### CLI |
| 56 | + |
| 57 | +```text |
| 58 | +$ j storage |
| 59 | +Usage: j storage [OPTIONS] COMMAND [ARGS]... |
| 60 | +
|
| 61 | +Commands: |
| 62 | + bootloader Enter download mode |
| 63 | + chip-info Get chip info (name, features, MAC) |
| 64 | + dump Dump flash content to file |
| 65 | + erase Erase entire flash |
| 66 | + flash Flash firmware to ESP32 |
| 67 | + reset Hard reset the chip |
| 68 | +
|
| 69 | +$ j serial |
| 70 | +Usage: j serial [OPTIONS] COMMAND [ARGS]... |
| 71 | +
|
| 72 | +Commands: |
| 73 | + start-console Start serial port console |
| 74 | + pipe Pipe serial port data to stdout or file |
| 75 | +``` |
| 76 | + |
| 77 | +## Examples |
| 78 | + |
| 79 | +### CLI usage |
| 80 | + |
| 81 | +```bash |
| 82 | +# Flash MicroPython firmware |
| 83 | +j storage flash firmware.bin --address 0x1000 |
| 84 | +
|
| 85 | +# Get chip info |
| 86 | +j storage chip-info |
| 87 | +
|
| 88 | +# Enter download mode |
| 89 | +j storage bootloader |
| 90 | +
|
| 91 | +# Erase entire flash |
| 92 | +j storage erase |
| 93 | +
|
| 94 | +# Hard reset |
| 95 | +j storage reset |
| 96 | +
|
| 97 | +# Open serial console |
| 98 | +j serial start-console |
| 99 | +
|
| 100 | +# Read serial output |
| 101 | +j serial pipe |
| 102 | +``` |
| 103 | + |
| 104 | +### Python API |
| 105 | + |
| 106 | +```python |
| 107 | +# Get chip information |
| 108 | +info = client.storage.get_chip_info() |
| 109 | +print(info["chip"]) # e.g. "ESP32-D0WD-V3 (revision v3.1)" |
| 110 | +print(info["features"]) # e.g. "Wi-Fi, BT, Dual Core" |
| 111 | +print(info["mac"]) # e.g. "5c:01:3b:68:ab:0c" |
| 112 | +
|
| 113 | +# Flash firmware |
| 114 | +client.storage.flash("/path/to/firmware.bin", target="0x1000") |
| 115 | +
|
| 116 | +# Enter download mode |
| 117 | +client.storage.enter_bootloader() |
| 118 | +
|
| 119 | +# Erase flash |
| 120 | +client.storage.erase() |
| 121 | +
|
| 122 | +# Hard reset |
| 123 | +client.storage.hard_reset() |
| 124 | +
|
| 125 | +# Serial console via pexpect |
| 126 | +console = client.serial.open() |
| 127 | +console.sendline("import machine") |
| 128 | +console.expect(">>>") |
| 129 | +``` |
0 commit comments