Skip to content

Commit 837c137

Browse files
committed
Merge commit '3718058bfc5726165394febfd75e7bdf94d5ad07'
2 parents 77fe3f7 + 3718058 commit 837c137

File tree

4 files changed

+34
-5
lines changed

4 files changed

+34
-5
lines changed

mpflash/cli_flash.py

+8
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,13 @@
115115
show_default=True,
116116
help="""How to enter the (MicroPython) bootloader before flashing.""",
117117
)
118+
@click.option(
119+
"--flash_mode", "-fm",
120+
type=click.Choice(["keep", "qio", "qout", "dio", "dout"]),
121+
default="keep",
122+
show_default=True,
123+
help="""Flash mode for ESP boards. (default: keep)""",
124+
)
118125
def cli_flash_board(**kwargs) -> int:
119126
# version to versions, board to boards
120127
kwargs["versions"] = [kwargs.pop("version")] if kwargs["version"] is not None else []
@@ -201,6 +208,7 @@ def cli_flash_board(**kwargs) -> int:
201208
params.fw_folder,
202209
params.erase,
203210
params.bootloader,
211+
flash_mode = params.flash_mode,
204212
):
205213
log.info(f"Flashed {len(flashed)} boards")
206214
show_mcus(flashed, title="Updated boards after flashing")

mpflash/common.py

+2
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
from serial.tools.list_ports_common import ListPortInfo
1212

1313

14+
# from mpflash.flash.esp import FlashMode
1415
from .logger import log
1516

1617
PORT_FWTYPES = {
@@ -98,6 +99,7 @@ class FlashParams(Params):
9899
erase: bool = True
99100
bootloader: BootloaderMethod = BootloaderMethod.NONE
100101
cpu: str = ""
102+
flash_mode: str = "keep" # keep, qio, qout, dio, dout
101103

102104
def __post_init__(self):
103105
if isinstance(self.bootloader, str):

mpflash/flash/__init__.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ def flash_list(
1919
fw_folder: Path,
2020
erase: bool,
2121
bootloader: BootloaderMethod,
22+
**kwargs
2223
):
2324
"""Flash a list of boards with the specified firmware."""
2425
UF2_PORTS = [port for port, exts in PORT_FWTYPES.items() if ".uf2" in exts]
@@ -41,7 +42,7 @@ def flash_list(
4142
updated = flash_stm32(mcu, fw_file, erase=erase)
4243
elif mcu.port in ["esp32", "esp8266"]:
4344
# bootloader is handled by esptool for esp32/esp8266
44-
updated = flash_esp(mcu, fw_file=fw_file, erase=erase)
45+
updated = flash_esp(mcu, fw_file=fw_file, erase=erase, **kwargs)
4546
else:
4647
log.error(f"Don't (yet) know how to flash {mcu.port}-{mcu.board} on {mcu.serialport}")
4748
except Exception as e:

mpflash/flash/esp.py

+22-4
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,24 @@
55
"""
66

77
from pathlib import Path
8-
from typing import List, Optional
8+
from typing import List, Literal, Optional
99

1010
import esptool
1111
from loguru import logger as log
1212

1313
from mpflash.mpboard_id import find_known_board
1414
from mpflash.mpremoteboard import MPRemoteBoard
1515

16+
FlashMode = Literal["keep", "qio", "qout", "dio", "dout"]
1617

17-
def flash_esp(mcu: MPRemoteBoard, fw_file: Path, *, erase: bool = True) -> Optional[MPRemoteBoard]:
18+
def flash_esp(
19+
mcu: MPRemoteBoard,
20+
fw_file: Path,
21+
*,
22+
erase: bool = True,
23+
flash_mode: FlashMode = "keep", # keep, qio, qout, dio, dout
24+
flash_size: str = "detect",
25+
) -> Optional[MPRemoteBoard]:
1826
if mcu.port not in ["esp32", "esp8266"] or mcu.board.startswith("ARDUINO_"):
1927
log.error(f"esptool not supported for {mcu.port} {mcu.board} on {mcu.serialport}")
2028
return None
@@ -29,6 +37,8 @@ def flash_esp(mcu: MPRemoteBoard, fw_file: Path, *, erase: bool = True) -> Optio
2937
chip = "auto"
3038
start_addr = "0x0"
3139
if mcu.cpu.upper().startswith("ESP32"):
40+
start_addr = "0x0"
41+
3242
baud_rate = str(921_600)
3343
if mcu.cpu.upper() == "ESP32":
3444
start_addr = "0x1000"
@@ -39,21 +49,29 @@ def flash_esp(mcu: MPRemoteBoard, fw_file: Path, *, erase: bool = True) -> Optio
3949
elif "S2" in mcu.cpu.upper():
4050
start_addr = "0x1000"
4151
chip = "esp32s2"
52+
baud_rate = str(460_800)
4253
elif "S3" in mcu.cpu.upper():
4354
start_addr = "0x0"
4455
chip = "esp32s3"
4556
elif "C3" in mcu.cpu.upper():
4657
start_addr = "0x0"
4758
chip = "esp32c3"
59+
elif "C6" in mcu.cpu.upper():
60+
start_addr = "0x0"
61+
chip = "esp32c6"
62+
baud_rate = str(460_800)
63+
64+
4865
cmds.append(
49-
f"esptool --chip {chip} --port {mcu.serialport} -b {baud_rate} write_flash --compress {start_addr}".split() + [str(fw_file)]
66+
f"esptool --chip {mcu.cpu} --port {mcu.serialport} -b {baud_rate} write_flash --flash_mode {flash_mode} --flash_size {flash_size} --compress {start_addr}".split()
67+
+ [str(fw_file)]
5068
)
5169
elif mcu.cpu.upper() == "ESP8266":
5270
baud_rate = str(460_800)
5371
start_addr = "0x0"
5472
chip = "esp8266"
5573
cmds.append(
56-
f"esptool --chip {chip} --port {mcu.serialport} -b {baud_rate} write_flash --flash_size=detect {start_addr}".split()
74+
f"esptool --chip {chip} --port {mcu.serialport} -b {baud_rate} write_flash --flash_mode {flash_mode} --flash_size=detect {start_addr}".split()
5775
+ [str(fw_file)]
5876
)
5977
# now that we have the chip, we can do the erare properly

0 commit comments

Comments
 (0)