Adding environment setup and instructions
This commit is contained in:
60
flash_tool/flash.py
Normal file
60
flash_tool/flash.py
Normal file
@@ -0,0 +1,60 @@
|
||||
import json
|
||||
import subprocess
|
||||
import sys
|
||||
from pathlib import Path
|
||||
|
||||
def main():
|
||||
root = Path(__file__).resolve().parent.parent
|
||||
config_file = root / "settings.json"
|
||||
|
||||
if not config_file.exists():
|
||||
print(f"[ERROR] settings.json not found at {config_file}")
|
||||
sys.exit(1)
|
||||
|
||||
with open(config_file) as f:
|
||||
cfg = json.load(f)
|
||||
|
||||
project = cfg["project_name"]
|
||||
chip = cfg.get("chip", "esp32")
|
||||
port = cfg.get("port", "COM3")
|
||||
baud = cfg.get("flash_baud", 460800)
|
||||
flash_mode = cfg.get("flash_mode", "dio")
|
||||
flash_freq = cfg.get("flash_freq", "40m")
|
||||
flash_size = cfg.get("flash_size", "4MB")
|
||||
before = cfg.get("before", "default_reset")
|
||||
after = cfg.get("after", "hard_reset")
|
||||
|
||||
# Define binaries and offsets
|
||||
bootloader = root / "build" / "bootloader" / "bootloader.bin"
|
||||
firmware = root / "build" / f"{project}.bin"
|
||||
partition = root / "build" / "partition_table" / "partition-table.bin"
|
||||
|
||||
# Verify binaries exist
|
||||
for f in [bootloader, firmware, partition]:
|
||||
if not f.exists():
|
||||
print(f"[ERROR] File not found: {f}")
|
||||
sys.exit(1)
|
||||
|
||||
# Build esptool command
|
||||
cmd = [
|
||||
sys.executable, "-m", "esptool",
|
||||
"--chip", chip,
|
||||
"--port", port,
|
||||
"--baud", str(baud),
|
||||
"--before", before,
|
||||
"--after", after,
|
||||
"write-flash", # ✅ hyphenated command
|
||||
"--flash-mode", flash_mode, # ✅ hyphenated flags
|
||||
"--flash-freq", flash_freq,
|
||||
"--flash-size", flash_size,
|
||||
"0x0", str(bootloader),
|
||||
"0x10000", str(firmware),
|
||||
"0x8000", str(partition)
|
||||
]
|
||||
|
||||
|
||||
print(f"[Flashing] Running: {' '.join(cmd)}")
|
||||
subprocess.run(cmd, check=True)
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
45
flash_tool/monitor.py
Normal file
45
flash_tool/monitor.py
Normal file
@@ -0,0 +1,45 @@
|
||||
import json
|
||||
import serial
|
||||
import sys
|
||||
import time
|
||||
from pathlib import Path
|
||||
# import colorama
|
||||
# colorama.just_fix_windows_console()
|
||||
|
||||
print("\x1b[0;32mThis should be green\x1b[0m")
|
||||
print("\x1b[0;31mThis should be red\x1b[0m")
|
||||
|
||||
def main():
|
||||
# Load config
|
||||
root = Path(__file__).resolve().parent.parent
|
||||
config_file = root / "settings.json"
|
||||
if not config_file.exists():
|
||||
print(f"Error: settings.json not found at {config_file}")
|
||||
sys.exit(1)
|
||||
|
||||
with open(config_file) as f:
|
||||
cfg = json.load(f)
|
||||
|
||||
port = cfg.get("port", "COM3")
|
||||
baud = cfg.get("monitor_baud", 115200)
|
||||
|
||||
print(f"[Serial Monitor] Connecting to {port} at {baud} baud...")
|
||||
|
||||
try:
|
||||
with serial.Serial(port, baud, timeout=0.5) as ser:
|
||||
print("[Serial Monitor] Press Ctrl+C to exit.\n")
|
||||
while True:
|
||||
if ser.in_waiting:
|
||||
line = ser.readline().decode(errors="replace")
|
||||
if line:
|
||||
print(line, end="")
|
||||
|
||||
time.sleep(0.01)
|
||||
except KeyboardInterrupt:
|
||||
print("\n[Serial Monitor] Disconnected.")
|
||||
except serial.SerialException as e:
|
||||
print(f"[Error] Could not open serial port {port}: {e}")
|
||||
sys.exit(1)
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
Reference in New Issue
Block a user