-
Notifications
You must be signed in to change notification settings - Fork 18
esp32: introduce ESP32 driver #613
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
23b19f5
3b147a0
4a20fe4
7873309
981c2f2
e204945
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,137 @@ | ||
| # ESP32 driver | ||
|
|
||
| `jumpstarter-driver-esp32` provides functionality for flashing, monitoring, and controlling ESP32 devices using esptool and serial communication. | ||
|
|
||
| ## Installation | ||
|
|
||
| ```{code-block} console | ||
| :substitutions: | ||
| $ pip3 install --extra-index-url {{index_url}} jumpstarter-driver-esp32 | ||
| ``` | ||
|
|
||
| ## Configuration | ||
|
|
||
| Example configuration: | ||
|
|
||
| ```yaml | ||
| export: | ||
| esp32: | ||
| type: jumpstarter_driver_esp32.driver.ESP32 | ||
| config: | ||
| port: "/dev/ttyUSB0" | ||
| baudrate: 115200 | ||
| chip: "esp32" | ||
| # Optional GPIO pins for hardware control | ||
| # reset_pin: 2 | ||
| # boot_pin: 0 | ||
| ``` | ||
|
|
||
| ### Config parameters | ||
|
|
||
| | Parameter | Description | Type | Required | Default | | ||
| | ------------- | --------------------------------------------------------------------- | ---- | -------- | ------- | | ||
| | port | The serial port to connect to the ESP32 | str | yes | | | ||
| | baudrate | The baudrate for serial communication | int | no | 115200 | | ||
| | chip | The ESP32 chip type (esp32, esp32s2, esp32s3, esp32c3, etc.) | str | no | esp32 | | ||
| | reset_pin | GPIO pin number for hardware reset (if connected) | int | no | null | | ||
| | boot_pin | GPIO pin number for boot mode control (if connected) | int | no | null | | ||
| | check_present | Check if the serial port exists during exporter initialization | bool | no | True | | ||
|
|
||
| ## API Reference | ||
|
|
||
| ```{eval-rst} | ||
| .. autoclass:: jumpstarter_driver_esp32.client.ESP32Client() | ||
| :members: chip_info, reset, erase_flash, flash_firmware, flash_firmware_file, read_flash, enter_bootloader | ||
| ``` | ||
|
|
||
| ### CLI | ||
|
|
||
| The ESP32 driver client comes with a CLI tool that can be used to interact with ESP32 devices: | ||
|
|
||
| ``` | ||
| jumpstarter ⚡ local ➤ j esp32 | ||
| Usage: j esp32 [OPTIONS] COMMAND [ARGS]... | ||
|
|
||
| ESP32 client | ||
|
|
||
| Options: | ||
| --help Show this message and exit. | ||
|
|
||
| Commands: | ||
| bootloader Enter bootloader mode | ||
| chip-id Get chip ID information | ||
| erase Erase the entire flash | ||
| flash Flash firmware to the device | ||
| info Get device information | ||
| read-flash Read flash contents | ||
| reset Reset the device | ||
| ``` | ||
|
|
||
| ## Examples | ||
|
|
||
| ### Getting device information | ||
|
|
||
| ```{testcode} | ||
| :skipif: True | ||
| info = esp32.chip_info() | ||
| print(f"Connected to {info['chip_revision']}") | ||
| print(f"MAC Address: {info['mac_address']}") | ||
| print(f"Chip ID: {info['chip_id']}") | ||
| ``` | ||
|
|
||
| ### Flashing firmware | ||
|
|
||
| ```{testcode} | ||
| :skipif: True | ||
| # Flash firmware from a local file | ||
| result = esp32.flash_firmware_file("firmware.bin", address=0x1000) | ||
| print(result) | ||
| ``` | ||
|
|
||
| ### Reading flash contents | ||
|
|
||
| ```{testcode} | ||
| :skipif: True | ||
| # Read 1024 bytes from address 0x0 | ||
| data = esp32.read_flash(address=0x0, size=1024) | ||
| print(f"Read {len(data)} bytes from flash") | ||
| ``` | ||
|
|
||
| ### Device control | ||
|
|
||
| ```{testcode} | ||
| :skipif: True | ||
| # Reset the device | ||
| result = esp32.reset() | ||
|
|
||
| # Enter bootloader mode | ||
| result = esp32.enter_bootloader() | ||
|
|
||
| # Erase entire flash | ||
| result = esp32.erase_flash() | ||
| ``` | ||
|
|
||
| ### CLI Examples | ||
|
|
||
| ```{code-block} console | ||
| # Get device information | ||
| $ j esp32 info | ||
|
|
||
| # Flash firmware to default app partition (0x10000) | ||
| $ j esp32 flash firmware.bin | ||
|
|
||
| # Flash firmware to specific address | ||
| $ j esp32 flash firmware.bin --address 0x1000 | ||
|
|
||
|
Comment on lines
+116
to
+125
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 💡 Verification agent 🧩 Analysis chainDouble-check the default flash address matches the driver constant This page states 0x10000 as the default (Line 125) and shows an explicit 0x1000 example (Line 129). Ensure the driver’s default matches what we document as “default”. 🏁 Script executed: #!/bin/bash
# Verify any hardcoded/default flash address in code and docs
rg -nI -C2 -S -e '0x1000\b|0x10000\b|default.*address' \
packages/jumpstarter-driver-esp32 jumpstarter docs packages | sed -n '1,200p'Length of output: 5104 Align default flash address between docs and driver (0x1000 vs 0x10000) Docs declare default 0x10000 (docs/source/reference/package-apis/drivers/esp32.md, ~lines 123–130) but the codebase contains conflicting defaults: an async implementation uses "async def flash_firmware(self, src: str, address: int = 0x1000)" while other functions/CLI/fallbacks use 0x10000 (e.g., "def flash_firmware(..., address: int = 0x10000)", "flash_firmware_file(..., address: int = 0x10000)", CLI --address default "0x10000", _parse_size fallback 0x10000). Decide the correct default, update the discrepant implementation or the docs to match, and centralize the value into a single constant used by code, CLI, and docs. 🤖 Prompt for AI Agents |
||
| # Read flash contents | ||
| $ j esp32 read-flash 0x0 1024 | ||
|
|
||
| # Save flash contents to file | ||
| $ j esp32 read-flash 0x0 1024 --output flash_dump.bin | ||
|
|
||
| # Reset the device | ||
| $ j esp32 reset | ||
|
|
||
| # Erase the entire flash | ||
| $ j esp32 erase | ||
| ``` | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,51 @@ | ||
| # ESP32 driver | ||
|
|
||
| `jumpstarter-driver-esp32` provides functionality for flashing, monitoring, and controlling ESP32 devices using esptool and serial communication. | ||
|
|
||
| ## Installation | ||
|
|
||
| ```{code-block} console | ||
| :substitutions: | ||
| $ pip3 install --extra-index-url {{index_url}} jumpstarter-driver-esp32 | ||
| ``` | ||
|
|
||
| ## Configuration | ||
|
|
||
| Example configuration: | ||
|
|
||
| ```yaml | ||
| export: | ||
| esp32: | ||
| type: jumpstarter_driver_esp32.driver.ESP32 | ||
| config: | ||
| port: "/dev/ttyUSB0" | ||
| baudrate: 115200 | ||
| chip: "esp32" | ||
| serial: | ||
| type: jumpstarter_driver_pyserial.driver.PySerial | ||
| config: | ||
| url: "/dev/ttyUSB0" | ||
| baudrate: 115200 | ||
| ``` | ||
|
|
||
| ### Config parameters | ||
|
|
||
| | Parameter | Description | Type | Required | Default | | ||
| | ------------ | --------------------------------------------------------------------- | ---- | -------- | ----------- | | ||
| | port | The serial port to connect to the ESP32 | str | yes | | | ||
| | baudrate | The baudrate for serial communication | int | no | 115200 | | ||
| | chip | The ESP32 chip type (esp32, esp32s2, esp32s3, esp32c3, etc.) | str | no | esp32 | | ||
| | reset_pin | GPIO pin number for hardware reset (if connected) | int | no | null | | ||
| | boot_pin | GPIO pin number for boot mode control (if connected) | int | no | null | | ||
|
|
||
| ## API Reference | ||
|
|
||
| ```{autoclass} jumpstarter_driver_esp32.driver.ESP32 | ||
| :members: | ||
| ``` | ||
|
|
||
| # Examples | ||
|
|
||
| ```shell | ||
| $ j esp32 flash ESP32_GENERIC-20250911-v1.26.1.bin -a 0x1000 | ||
| ``` | ||
bennyz marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| #!/usr/bin/env python3 | ||
| from jumpstarter.common.utils import env | ||
|
|
||
|
|
||
| def main(): | ||
| with env() as client: | ||
| esp32 = client.esp32 | ||
|
|
||
| info = esp32.chip_info() | ||
| print(f"Connected to {info['chip_revision']}") | ||
| print(f"MAC Address: {info['mac_address']}") | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| main() |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| apiVersion: jumpstarter.dev/v1alpha1 | ||
| kind: ExporterConfig | ||
| metadata: | ||
| name: esp32 | ||
| spec: | ||
| export: | ||
| esp32: | ||
| type: jumpstarter_driver_esp32.driver.ESP32 | ||
| config: | ||
| port: "/dev/ttyUSB0" | ||
| baudrate: 115200 | ||
| chip: "esp32" | ||
| # Optional GPIO pins for hardware control | ||
| # reset_pin: 2 | ||
| # boot_pin: 0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💯 awesome!