-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathflash_firmware.py
More file actions
64 lines (54 loc) · 1.48 KB
/
flash_firmware.py
File metadata and controls
64 lines (54 loc) · 1.48 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
from pathlib import Path
import sys
ROOT = Path(__file__).resolve().parent
BIN = ROOT.parent / "firmware"
USAGE = """Usage:
py scripts/flash_firmware.py COM3
Flashes the published ESP32-C3 board-proof firmware from the local `firmware/`
directory. 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)
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()