mpflash 0.8.8__tar.gz → 0.9.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {mpflash-0.8.8 → mpflash-0.9.0}/PKG-INFO +1 -1
- {mpflash-0.8.8 → mpflash-0.9.0}/mpflash/config.py +5 -9
- {mpflash-0.8.8 → mpflash-0.9.0}/mpflash/flash.py +17 -14
- {mpflash-0.8.8 → mpflash-0.9.0}/mpflash/flash_stm32.py +4 -9
- {mpflash-0.8.8 → mpflash-0.9.0}/mpflash/flash_uf2.py +38 -16
- {mpflash-0.8.8 → mpflash-0.9.0}/mpflash/flash_uf2_linux.py +10 -4
- {mpflash-0.8.8 → mpflash-0.9.0}/mpflash/flash_uf2_macos.py +5 -2
- {mpflash-0.8.8 → mpflash-0.9.0}/mpflash/flash_uf2_windows.py +7 -3
- {mpflash-0.8.8 → mpflash-0.9.0}/mpflash/mpremoteboard/__init__.py +8 -3
- {mpflash-0.8.8 → mpflash-0.9.0}/pyproject.toml +5 -1
- {mpflash-0.8.8 → mpflash-0.9.0}/LICENSE +0 -0
- {mpflash-0.8.8 → mpflash-0.9.0}/README.md +0 -0
- {mpflash-0.8.8 → mpflash-0.9.0}/mpflash/__init__.py +0 -0
- {mpflash-0.8.8 → mpflash-0.9.0}/mpflash/add_firmware.py +0 -0
- {mpflash-0.8.8 → mpflash-0.9.0}/mpflash/ask_input.py +0 -0
- {mpflash-0.8.8 → mpflash-0.9.0}/mpflash/bootloader/__init__.py +0 -0
- {mpflash-0.8.8 → mpflash-0.9.0}/mpflash/bootloader/manual.py +0 -0
- {mpflash-0.8.8 → mpflash-0.9.0}/mpflash/bootloader/micropython.py +0 -0
- {mpflash-0.8.8 → mpflash-0.9.0}/mpflash/bootloader/touch1200.py +0 -0
- {mpflash-0.8.8 → mpflash-0.9.0}/mpflash/cli_download.py +0 -0
- {mpflash-0.8.8 → mpflash-0.9.0}/mpflash/cli_flash.py +0 -0
- {mpflash-0.8.8 → mpflash-0.9.0}/mpflash/cli_group.py +0 -0
- {mpflash-0.8.8 → mpflash-0.9.0}/mpflash/cli_list.py +0 -0
- {mpflash-0.8.8 → mpflash-0.9.0}/mpflash/cli_main.py +0 -0
- {mpflash-0.8.8 → mpflash-0.9.0}/mpflash/common.py +0 -0
- {mpflash-0.8.8 → mpflash-0.9.0}/mpflash/connected.py +0 -0
- {mpflash-0.8.8 → mpflash-0.9.0}/mpflash/download.py +0 -0
- {mpflash-0.8.8 → mpflash-0.9.0}/mpflash/downloaded.py +0 -0
- {mpflash-0.8.8 → mpflash-0.9.0}/mpflash/errors.py +0 -0
- {mpflash-0.8.8 → mpflash-0.9.0}/mpflash/flash_esp.py +0 -0
- {mpflash-0.8.8 → mpflash-0.9.0}/mpflash/flash_stm32_cube.py +0 -0
- {mpflash-0.8.8 → mpflash-0.9.0}/mpflash/flash_stm32_dfu.py +0 -0
- {mpflash-0.8.8 → mpflash-0.9.0}/mpflash/flash_uf2_boardid.py +0 -0
- {mpflash-0.8.8 → mpflash-0.9.0}/mpflash/list.py +0 -0
- {mpflash-0.8.8 → mpflash-0.9.0}/mpflash/logger.py +0 -0
- {mpflash-0.8.8 → mpflash-0.9.0}/mpflash/mpboard_id/__init__.py +0 -0
- {mpflash-0.8.8 → mpflash-0.9.0}/mpflash/mpboard_id/add_boards.py +0 -0
- {mpflash-0.8.8 → mpflash-0.9.0}/mpflash/mpboard_id/board.py +0 -0
- {mpflash-0.8.8 → mpflash-0.9.0}/mpflash/mpboard_id/board_id.py +0 -0
- {mpflash-0.8.8 → mpflash-0.9.0}/mpflash/mpboard_id/board_info.zip +0 -0
- {mpflash-0.8.8 → mpflash-0.9.0}/mpflash/mpboard_id/store.py +0 -0
- {mpflash-0.8.8 → mpflash-0.9.0}/mpflash/mpremoteboard/mpy_fw_info.py +0 -0
- {mpflash-0.8.8 → mpflash-0.9.0}/mpflash/mpremoteboard/runner.py +0 -0
- {mpflash-0.8.8 → mpflash-0.9.0}/mpflash/uf2disk.py +0 -0
- {mpflash-0.8.8 → mpflash-0.9.0}/mpflash/vendor/basicgit.py +0 -0
- {mpflash-0.8.8 → mpflash-0.9.0}/mpflash/vendor/click_aliases.py +0 -0
- {mpflash-0.8.8 → mpflash-0.9.0}/mpflash/vendor/dfu.py +0 -0
- {mpflash-0.8.8 → mpflash-0.9.0}/mpflash/vendor/pydfu.py +0 -0
- {mpflash-0.8.8 → mpflash-0.9.0}/mpflash/vendor/readme.md +0 -0
- {mpflash-0.8.8 → mpflash-0.9.0}/mpflash/vendor/versions.py +0 -0
- {mpflash-0.8.8 → mpflash-0.9.0}/mpflash/worklist.py +0 -0
@@ -4,18 +4,15 @@ import os
|
|
4
4
|
from pathlib import Path
|
5
5
|
from typing import List
|
6
6
|
|
7
|
-
import pkg_resources
|
8
7
|
import platformdirs
|
8
|
+
from importlib.metadata import version
|
9
9
|
|
10
10
|
from mpflash.logger import log
|
11
11
|
|
12
12
|
|
13
13
|
def get_version():
|
14
14
|
name = __package__ or "mpflash"
|
15
|
-
|
16
|
-
return pkg_resources.get_distribution(name).version
|
17
|
-
except pkg_resources.DistributionNotFound:
|
18
|
-
return "Package not found"
|
15
|
+
return version(name)
|
19
16
|
|
20
17
|
|
21
18
|
class MPtoolConfig:
|
@@ -32,16 +29,15 @@ class MPtoolConfig:
|
|
32
29
|
@property
|
33
30
|
def interactive(self):
|
34
31
|
# No interactions in CI
|
35
|
-
if os.getenv(
|
32
|
+
if os.getenv("GITHUB_ACTIONS") == "true":
|
36
33
|
log.warning("Disabling interactive mode in CI")
|
37
34
|
return False
|
38
35
|
return self._interactive
|
39
|
-
|
36
|
+
|
40
37
|
@interactive.setter
|
41
|
-
def interactive(self, value:bool):
|
38
|
+
def interactive(self, value: bool):
|
42
39
|
self._interactive = value
|
43
40
|
|
44
41
|
|
45
|
-
|
46
42
|
config = MPtoolConfig()
|
47
43
|
__version__ = get_version()
|
@@ -30,20 +30,23 @@ def flash_list(
|
|
30
30
|
continue
|
31
31
|
log.info(f"Updating {mcu.board} on {mcu.serialport} to {fw_info.version}")
|
32
32
|
updated = None
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
33
|
+
try:
|
34
|
+
if mcu.port in UF2_PORTS and fw_file.suffix == ".uf2":
|
35
|
+
if not enter_bootloader(mcu, bootloader):
|
36
|
+
continue
|
37
|
+
updated = flash_uf2(mcu, fw_file=fw_file, erase=erase)
|
38
|
+
elif mcu.port in ["stm32"]:
|
39
|
+
if not enter_bootloader(mcu, bootloader):
|
40
|
+
continue
|
41
|
+
updated = flash_stm32(mcu, fw_file, erase=erase)
|
42
|
+
elif mcu.port in ["esp32", "esp8266"]:
|
43
|
+
# bootloader is handled by esptool for esp32/esp8266
|
44
|
+
updated = flash_esp(mcu, fw_file=fw_file, erase=erase)
|
45
|
+
else:
|
46
|
+
log.error(f"Don't (yet) know how to flash {mcu.port}-{mcu.board} on {mcu.serialport}")
|
47
|
+
except Exception as e:
|
48
|
+
log.error(f"Failed to flash {mcu.board} on {mcu.serialport}")
|
49
|
+
log.exception(e)
|
47
50
|
|
48
51
|
if updated:
|
49
52
|
flashed.append(updated)
|
@@ -1,4 +1,4 @@
|
|
1
|
-
"""Flash STM32 boards using
|
1
|
+
"""Flash STM32 boards using pydfu"""
|
2
2
|
|
3
3
|
from pathlib import Path
|
4
4
|
|
@@ -12,12 +12,7 @@ from mpflash.mpremoteboard import MPRemoteBoard
|
|
12
12
|
def flash_stm32(mcu: MPRemoteBoard, fw_file: Path, *, erase: bool, stm32_dfu: bool = True):
|
13
13
|
# sourcery skip: lift-return-into-if
|
14
14
|
dfu_init()
|
15
|
-
updated
|
16
|
-
|
17
|
-
|
18
|
-
# log.info("Using STM32CubeProgrammer CLI")
|
19
|
-
# updated = flash_stm32_cubecli(mcu, fw_file=fw_file, erase=erase)
|
20
|
-
|
21
|
-
mcu.wait_for_restart()
|
22
|
-
log.success(f"Flashed {mcu.version} to {mcu.board}")
|
15
|
+
if updated := flash_stm32_dfu(mcu, fw_file=fw_file, erase=erase):
|
16
|
+
mcu.wait_for_restart()
|
17
|
+
log.success(f"Flashed {mcu.version} to {mcu.board}")
|
23
18
|
return updated
|
@@ -12,6 +12,8 @@ from loguru import logger as log
|
|
12
12
|
from rich.progress import track
|
13
13
|
|
14
14
|
from mpflash.mpremoteboard import MPRemoteBoard
|
15
|
+
import tenacity
|
16
|
+
from tenacity import stop_after_attempt, wait_fixed
|
15
17
|
|
16
18
|
from .common import PORT_FWTYPES
|
17
19
|
from .flash_uf2_boardid import get_board_id
|
@@ -37,31 +39,51 @@ def flash_uf2(mcu: MPRemoteBoard, fw_file: Path, erase: bool) -> Optional[MPRemo
|
|
37
39
|
log.error(f"UF2 not supported on {mcu.board} on {mcu.serialport}")
|
38
40
|
return None
|
39
41
|
if erase:
|
40
|
-
|
42
|
+
destination = waitfor_uf2()
|
41
43
|
|
44
|
+
if not destination or not destination.exists() or not (destination / "INFO_UF2.TXT").exists():
|
45
|
+
log.error("Board is not in bootloader mode")
|
46
|
+
return None
|
47
|
+
|
48
|
+
log.info("Board is in bootloader mode")
|
49
|
+
board_id = get_board_id(destination) # type: ignore
|
50
|
+
log.info(f"Board ID: {board_id}")
|
51
|
+
try:
|
52
|
+
cp_firmware_to_uf2(fw_file, destination)
|
53
|
+
log.success("Done copying, resetting the board and wait for it to restart")
|
54
|
+
except tenacity.RetryError:
|
55
|
+
log.error("Failed to copy the firmware file to the board.")
|
56
|
+
return None
|
57
|
+
|
58
|
+
if sys.platform in ["linux"]:
|
59
|
+
dismount_uf2_linux()
|
60
|
+
|
61
|
+
mcu.wait_for_restart()
|
62
|
+
# time.sleep(1) # 5 secs to short on linux
|
63
|
+
return mcu
|
64
|
+
|
65
|
+
|
66
|
+
def waitfor_uf2():
|
67
|
+
"""
|
68
|
+
Wait for the UF2 drive to mount
|
69
|
+
"""
|
42
70
|
if sys.platform == "linux":
|
43
|
-
|
71
|
+
return wait_for_UF2_linux()
|
44
72
|
elif sys.platform == "win32":
|
45
|
-
|
73
|
+
return wait_for_UF2_windows()
|
46
74
|
elif sys.platform == "darwin":
|
47
75
|
log.warning(f"OS {sys.platform} not tested/supported")
|
48
|
-
|
76
|
+
return wait_for_UF2_macos()
|
49
77
|
else:
|
50
78
|
log.warning(f"OS {sys.platform} not tested/supported")
|
51
79
|
return None
|
52
80
|
|
53
|
-
if not destination or not destination.exists() or not (destination / "INFO_UF2.TXT").exists():
|
54
|
-
log.error("Board is not in bootloader mode")
|
55
|
-
return None
|
56
81
|
|
57
|
-
|
58
|
-
|
59
|
-
|
82
|
+
@tenacity.retry(stop=stop_after_attempt(3), wait=wait_fixed(1), reraise=False)
|
83
|
+
def cp_firmware_to_uf2(fw_file, destination):
|
84
|
+
"""
|
85
|
+
Copy the firmware file to the destination,
|
86
|
+
Retry 3 times with 1s delay
|
87
|
+
"""
|
60
88
|
log.info(f"Copying {fw_file} to {destination}.")
|
61
89
|
shutil.copy(fw_file, destination)
|
62
|
-
log.success("Done copying, resetting the board and wait for it to restart")
|
63
|
-
if sys.platform in ["linux"]:
|
64
|
-
dismount_uf2_linux()
|
65
|
-
for _ in track(range(5 + 2), description="Waiting for the board to restart", transient=True, refresh_per_second=2):
|
66
|
-
time.sleep(1) # 5 secs to short on linux
|
67
|
-
return mcu
|
@@ -42,7 +42,10 @@ def get_uf2_drives():
|
|
42
42
|
uf2.mountpoint = uf2_part["mountpoint"]
|
43
43
|
yield uf2
|
44
44
|
elif disk["type"] == "disk" and disk.get("children") and len(disk.get("children")) > 0:
|
45
|
-
if
|
45
|
+
if (
|
46
|
+
disk.get("children")[0]["type"] == "part"
|
47
|
+
and disk.get("children")[0]["fstype"] == "vfat"
|
48
|
+
):
|
46
49
|
uf2_part = disk.get("children")[0]
|
47
50
|
# print( json.dumps(uf2_part, indent=4))
|
48
51
|
uf2 = UF2Disk()
|
@@ -70,7 +73,7 @@ def pmount(disk: UF2Disk):
|
|
70
73
|
log.debug(f"Mounted {disk.label} at {disk.mountpoint}")
|
71
74
|
glb_dismount_me.append(disk)
|
72
75
|
else:
|
73
|
-
log.
|
76
|
+
log.trace(f"\n{disk.label} already mounted at {disk.mountpoint}")
|
74
77
|
|
75
78
|
|
76
79
|
def pumount(disk: UF2Disk):
|
@@ -101,9 +104,12 @@ def wait_for_UF2_linux(s_max: int = 10):
|
|
101
104
|
uf2_drives = []
|
102
105
|
# while not destination and wait > 0:
|
103
106
|
for _ in track(
|
104
|
-
range(s_max),
|
107
|
+
range(s_max),
|
108
|
+
description="Waiting for mcu to mount as a drive",
|
109
|
+
transient=True,
|
110
|
+
refresh_per_second=2,
|
111
|
+
total=s_max,
|
105
112
|
):
|
106
|
-
# log.info(f"Waiting for mcu to mount as a drive : {wait} seconds left")
|
107
113
|
uf2_drives += list(get_uf2_drives())
|
108
114
|
for drive in get_uf2_drives():
|
109
115
|
pmount(drive)
|
@@ -10,14 +10,17 @@ from typing import Optional
|
|
10
10
|
from rich.progress import track
|
11
11
|
|
12
12
|
|
13
|
-
|
14
13
|
def wait_for_UF2_macos(s_max: int = 10) -> Optional[Path]:
|
15
14
|
"""Wait for the MCU to mount as a drive"""
|
16
15
|
if s_max < 1:
|
17
16
|
s_max = 10
|
18
17
|
destination = None
|
19
18
|
for _ in track(
|
20
|
-
range(s_max),
|
19
|
+
range(s_max),
|
20
|
+
description="Waiting for mcu to mount as a drive",
|
21
|
+
transient=True,
|
22
|
+
refresh_per_second=2,
|
23
|
+
total=s_max,
|
21
24
|
):
|
22
25
|
# log.info(f"Waiting for mcu to mount as a drive : {n} seconds left")
|
23
26
|
vol_mounts = Path("/Volumes").iterdir()
|
@@ -11,14 +11,18 @@ import psutil
|
|
11
11
|
from rich.progress import track
|
12
12
|
|
13
13
|
|
14
|
-
|
15
|
-
|
16
14
|
def wait_for_UF2_windows(s_max: int = 10) -> Optional[Path]:
|
17
15
|
"""Wait for the MCU to mount as a drive"""
|
18
16
|
if s_max < 1:
|
19
17
|
s_max = 10
|
20
18
|
destination = None
|
21
|
-
for _ in track(
|
19
|
+
for _ in track(
|
20
|
+
range(s_max),
|
21
|
+
description="Waiting for mcu to mount as a drive",
|
22
|
+
transient=True,
|
23
|
+
refresh_per_second=2,
|
24
|
+
total=s_max,
|
25
|
+
):
|
22
26
|
# log.info(f"Waiting for mcu to mount as a drive : {n} seconds left")
|
23
27
|
drives = [drive.device for drive in psutil.disk_partitions()]
|
24
28
|
for drive in drives:
|
@@ -91,7 +91,9 @@ class MPRemoteBoard:
|
|
91
91
|
|
92
92
|
if sys.platform == "win32":
|
93
93
|
# Windows sort of comports by number - but fallback to device name
|
94
|
-
return sorted(
|
94
|
+
return sorted(
|
95
|
+
output, key=lambda x: int(x.split()[0][3:]) if x.split()[0][3:].isdigit() else x
|
96
|
+
)
|
95
97
|
# sort by device name
|
96
98
|
return sorted(output)
|
97
99
|
|
@@ -127,7 +129,9 @@ class MPRemoteBoard:
|
|
127
129
|
self.description = descr = info["board"]
|
128
130
|
pos = descr.rfind(" with")
|
129
131
|
short_descr = descr[:pos].strip() if pos != -1 else ""
|
130
|
-
if board_name := find_board_id_by_description(
|
132
|
+
if board_name := find_board_id_by_description(
|
133
|
+
descr, short_descr, version=self.version
|
134
|
+
):
|
131
135
|
self.board = board_name
|
132
136
|
else:
|
133
137
|
self.board = "UNKNOWN_BOARD"
|
@@ -211,7 +215,8 @@ class MPRemoteBoard:
|
|
211
215
|
transient=True,
|
212
216
|
get_time=lambda: time.time(),
|
213
217
|
show_speed=False,
|
214
|
-
refresh_per_second=
|
218
|
+
refresh_per_second=2,
|
219
|
+
total=timeout,
|
215
220
|
):
|
216
221
|
time.sleep(1)
|
217
222
|
try:
|
@@ -1,6 +1,6 @@
|
|
1
1
|
[tool.poetry]
|
2
2
|
name = "mpflash"
|
3
|
-
version = "0.
|
3
|
+
version = "0.9.0"
|
4
4
|
description = "Flash and download tool for MicroPython firmwares"
|
5
5
|
authors = ["Jos Verlinde <jos_verlinde@hotmail.com>"]
|
6
6
|
license = "MIT"
|
@@ -40,6 +40,10 @@ rich-click = "^1.8.1"
|
|
40
40
|
tenacity = "8.2.3"
|
41
41
|
|
42
42
|
|
43
|
+
[tool.poetry.group.dev]
|
44
|
+
optional = true
|
45
|
+
[tool.poetry.group.dev.dependencies]
|
46
|
+
|
43
47
|
[tool.poetry.group.test]
|
44
48
|
optional = true
|
45
49
|
[tool.poetry.group.test.dependencies]
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|