-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathflash_open_input_firmware.py
More file actions
69 lines (59 loc) · 1.84 KB
/
flash_open_input_firmware.py
File metadata and controls
69 lines (59 loc) · 1.84 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
from pathlib import Path
import sys
ROOT = Path(__file__).resolve().parent
BIN = ROOT.parent / "firmware" / "open_input_demo"
USAGE = """Usage:
py scripts/flash_open_input_firmware.py COM3
Flashes the published ESP32-C3 open-input demo firmware from `firmware/open_input_demo/`.
This script expects `esptool` to be installed in the invoking Python environment.
"""
def parse_args(argv: list[str]) -> str:
for arg in argv[1:]:
if arg in {"-h", "--help"}:
print(USAGE.strip())
raise SystemExit(0)
port = "COM3"
for arg in argv[1:]:
if not arg.startswith("--"):
port = arg
return port
def main() -> None:
port = parse_args(sys.argv)
if not BIN.exists():
raise SystemExit(f"firmware directory not found: {BIN}")
required = ["bootloader.bin", "partitions.bin", "boot_app0.bin", "firmware.bin"]
missing = [name for name in required if not (BIN / name).exists()]
if missing:
raise SystemExit(f"missing firmware files in {BIN}: {', '.join(missing)}")
try:
import esptool
except ModuleNotFoundError as exc:
raise SystemExit(
"esptool is not installed in this Python environment. Run "
"`py -m pip install esptool` and retry."
) from exc
esptool.main(
[
"--chip",
"esp32c3",
"--port",
port,
"--baud",
"460800",
"--before",
"default-reset",
"--after",
"hard-reset",
"write-flash",
"0x0",
str(BIN / "bootloader.bin"),
"0x8000",
str(BIN / "partitions.bin"),
"0xe000",
str(BIN / "boot_app0.bin"),
"0x10000",
str(BIN / "firmware.bin"),
]
)
if __name__ == "__main__":
main()