micropython-stubber 1.17.6__py3-none-any.whl → 1.20.0__py3-none-any.whl
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.
- {micropython_stubber-1.17.6.dist-info → micropython_stubber-1.20.0.dist-info}/METADATA +7 -6
- micropython_stubber-1.20.0.dist-info/RECORD +147 -0
- mpflash/README.md +18 -2
- mpflash/libusb_flash.ipynb +203 -0
- mpflash/mpflash/ask_input.py +234 -0
- mpflash/mpflash/cli_download.py +107 -0
- mpflash/mpflash/cli_flash.py +170 -0
- mpflash/mpflash/cli_group.py +40 -7
- mpflash/mpflash/cli_list.py +41 -0
- mpflash/mpflash/cli_main.py +13 -8
- mpflash/mpflash/common.py +33 -121
- mpflash/mpflash/config.py +9 -0
- mpflash/mpflash/{downloader.py → download.py} +110 -96
- mpflash/mpflash/downloaded.py +108 -0
- mpflash/mpflash/errors.py +5 -0
- mpflash/mpflash/flash.py +69 -0
- mpflash/mpflash/flash_esp.py +17 -23
- mpflash/mpflash/flash_stm32.py +16 -113
- mpflash/mpflash/flash_stm32_cube.py +111 -0
- mpflash/mpflash/flash_stm32_dfu.py +101 -0
- mpflash/mpflash/flash_uf2.py +8 -8
- mpflash/mpflash/flash_uf2_linux.py +13 -6
- mpflash/mpflash/flash_uf2_windows.py +24 -12
- mpflash/mpflash/list.py +56 -39
- mpflash/mpflash/logger.py +12 -13
- mpflash/mpflash/mpboard_id/__init__.py +96 -0
- mpflash/mpflash/mpboard_id/board_id.py +63 -0
- mpflash/mpflash/mpboard_id/board_info.csv +2213 -0
- mpflash/mpflash/mpboard_id/board_info.json +19910 -0
- mpflash/mpflash/mpremoteboard/__init__.py +209 -0
- mpflash/mpflash/mpremoteboard/mpy_fw_info.py +141 -0
- {stubber/bulk → mpflash/mpflash/mpremoteboard}/runner.py +19 -4
- mpflash/mpflash/vendor/dfu.py +164 -0
- mpflash/mpflash/vendor/pydfu.py +605 -0
- mpflash/mpflash/vendor/readme.md +3 -0
- mpflash/mpflash/vendor/versions.py +113 -0
- mpflash/mpflash/worklist.py +147 -0
- mpflash/poetry.lock +427 -610
- mpflash/pyproject.toml +22 -6
- mpflash/stm32_udev_rules.md +63 -0
- stubber/__init__.py +1 -1
- stubber/basicgit.py +1 -0
- stubber/board/createstubs.py +11 -4
- stubber/board/createstubs_db.py +11 -5
- stubber/board/createstubs_db_min.py +61 -58
- stubber/board/createstubs_db_mpy.mpy +0 -0
- stubber/board/createstubs_mem.py +11 -5
- stubber/board/createstubs_mem_min.py +56 -53
- stubber/board/createstubs_mem_mpy.mpy +0 -0
- stubber/board/createstubs_min.py +54 -51
- stubber/board/createstubs_mpy.mpy +0 -0
- stubber/board/modulelist.txt +1 -0
- stubber/bulk/mcu_stubber.py +9 -5
- stubber/codemod/_partials/db_main.py +14 -25
- stubber/codemod/_partials/lvgl_main.py +2 -2
- stubber/codemod/board.py +10 -3
- stubber/commands/clone_cmd.py +7 -7
- stubber/commands/config_cmd.py +3 -0
- stubber/commands/{mcu_cmd.py → get_mcu_cmd.py} +20 -3
- stubber/freeze/get_frozen.py +0 -2
- stubber/publish/candidates.py +1 -1
- stubber/publish/package.py +1 -1
- stubber/publish/pathnames.py +1 -1
- stubber/publish/stubpackage.py +1 -0
- stubber/rst/lookup.py +1 -1
- stubber/stubber.py +1 -9
- stubber/tools/manifestfile.py +5 -3
- stubber/update_fallback.py +104 -104
- stubber/utils/config.py +32 -36
- stubber/utils/repos.py +2 -2
- stubber/utils/versions.py +1 -0
- micropython_stubber-1.17.6.dist-info/RECORD +0 -132
- mpflash/mpflash/flasher.py +0 -276
- stubber/bulk/board_id.py +0 -40
- stubber/bulk/mpremoteboard.py +0 -141
- stubber/commands/get_lobo_cmd.py +0 -58
- stubber/commands/minify_cmd.py +0 -60
- stubber/commands/upd_fallback_cmd.py +0 -36
- stubber/commands/upd_module_list_cmd.py +0 -18
- {micropython_stubber-1.17.6.dist-info → micropython_stubber-1.20.0.dist-info}/LICENSE +0 -0
- {micropython_stubber-1.17.6.dist-info → micropython_stubber-1.20.0.dist-info}/WHEEL +0 -0
- {micropython_stubber-1.17.6.dist-info → micropython_stubber-1.20.0.dist-info}/entry_points.txt +0 -0
- /mpflash/mpflash/{uf2_boardid.py → flash_uf2_boardid.py} +0 -0
@@ -0,0 +1,107 @@
|
|
1
|
+
"""CLI to Download MicroPython firmware for specific ports, boards and versions."""
|
2
|
+
|
3
|
+
from pathlib import Path
|
4
|
+
from typing import List, Tuple
|
5
|
+
|
6
|
+
import rich_click as click
|
7
|
+
from loguru import logger as log
|
8
|
+
|
9
|
+
from mpflash.mpboard_id import find_stored_board
|
10
|
+
from mpflash.vendor.versions import clean_version
|
11
|
+
|
12
|
+
from .ask_input import DownloadParams, ask_missing_params
|
13
|
+
from .cli_group import cli
|
14
|
+
from .cli_list import list_mcus
|
15
|
+
from .config import config
|
16
|
+
from .download import download
|
17
|
+
|
18
|
+
|
19
|
+
@cli.command(
|
20
|
+
"download",
|
21
|
+
help="Download MicroPython firmware for specific ports, boards and versions.",
|
22
|
+
)
|
23
|
+
@click.option(
|
24
|
+
"--destination",
|
25
|
+
"-d",
|
26
|
+
"fw_folder",
|
27
|
+
type=click.Path(file_okay=False, dir_okay=True, path_type=Path),
|
28
|
+
default=config.firmware_folder,
|
29
|
+
show_default=True,
|
30
|
+
help="The folder to download the firmware to.",
|
31
|
+
)
|
32
|
+
@click.option(
|
33
|
+
"--version",
|
34
|
+
"-v",
|
35
|
+
"versions",
|
36
|
+
default=["stable"],
|
37
|
+
multiple=True,
|
38
|
+
show_default=True,
|
39
|
+
help="The version of MicroPython to to download.",
|
40
|
+
metavar="SEMVER, 'stable', 'preview' or '?'",
|
41
|
+
)
|
42
|
+
@click.option(
|
43
|
+
"--board",
|
44
|
+
"-b",
|
45
|
+
"boards",
|
46
|
+
multiple=True,
|
47
|
+
default=[],
|
48
|
+
show_default=True,
|
49
|
+
help="The board(s) to download the firmware for.",
|
50
|
+
metavar="BOARD_ID or ?",
|
51
|
+
)
|
52
|
+
@click.option(
|
53
|
+
"--clean/--no-clean",
|
54
|
+
default=True,
|
55
|
+
show_default=True,
|
56
|
+
help="""Remove dates and hashes from the downloaded firmware filenames.""",
|
57
|
+
)
|
58
|
+
@click.option(
|
59
|
+
"--force",
|
60
|
+
default=False,
|
61
|
+
is_flag=True,
|
62
|
+
show_default=True,
|
63
|
+
help="""Force download of firmware even if it already exists.""",
|
64
|
+
)
|
65
|
+
def cli_download(
|
66
|
+
**kwargs,
|
67
|
+
):
|
68
|
+
params = DownloadParams(**kwargs)
|
69
|
+
params.versions = list(params.versions)
|
70
|
+
params.boards = list(params.boards)
|
71
|
+
if params.boards:
|
72
|
+
pass
|
73
|
+
# TODO Clean board - same as in cli_flash.py
|
74
|
+
else:
|
75
|
+
# no boards specified - detect connected boards
|
76
|
+
params.ports, params.boards = connected_ports_boards()
|
77
|
+
|
78
|
+
params = ask_missing_params(params, action="download")
|
79
|
+
if not params: # Cancelled by user
|
80
|
+
exit(1)
|
81
|
+
params.versions = [clean_version(v, drop_v=True) for v in params.versions]
|
82
|
+
assert isinstance(params, DownloadParams)
|
83
|
+
|
84
|
+
download(
|
85
|
+
params.fw_folder,
|
86
|
+
params.ports,
|
87
|
+
params.boards,
|
88
|
+
params.versions,
|
89
|
+
params.force,
|
90
|
+
params.clean,
|
91
|
+
)
|
92
|
+
|
93
|
+
|
94
|
+
def connected_ports_boards() -> Tuple[List[str], List[str]]:
|
95
|
+
"""
|
96
|
+
Returns a tuple containing lists of unique ports and boards from the connected MCUs.
|
97
|
+
Boards that are physically connected, but give no tangible response are ignored.
|
98
|
+
|
99
|
+
Returns:
|
100
|
+
A tuple containing two lists:
|
101
|
+
- A list of unique ports where MCUs are connected.
|
102
|
+
- A list of unique board names of the connected MCUs.
|
103
|
+
"""
|
104
|
+
mpr_boards = [b for b in list_mcus() if b.connected]
|
105
|
+
ports = list({b.port for b in mpr_boards})
|
106
|
+
boards = list({b.board for b in mpr_boards})
|
107
|
+
return ports, boards
|
@@ -0,0 +1,170 @@
|
|
1
|
+
from pathlib import Path
|
2
|
+
|
3
|
+
import rich_click as click
|
4
|
+
from loguru import logger as log
|
5
|
+
|
6
|
+
from mpflash.errors import MPFlashError
|
7
|
+
from mpflash.mpboard_id import find_stored_board
|
8
|
+
from mpflash.vendor.versions import clean_version
|
9
|
+
|
10
|
+
from .ask_input import FlashParams, ask_missing_params
|
11
|
+
from .cli_download import connected_ports_boards
|
12
|
+
from .cli_group import cli
|
13
|
+
from .cli_list import show_mcus
|
14
|
+
from .config import config
|
15
|
+
from .flash import flash_list
|
16
|
+
from .worklist import MPRemoteBoard, WorkList, full_auto_worklist, manual_worklist, single_auto_worklist
|
17
|
+
|
18
|
+
# #########################################################################################################
|
19
|
+
# CLI
|
20
|
+
# #########################################################################################################
|
21
|
+
|
22
|
+
|
23
|
+
@cli.command(
|
24
|
+
"flash",
|
25
|
+
short_help="Flash one or all connected MicroPython boards with a specific firmware and version.",
|
26
|
+
)
|
27
|
+
@click.option(
|
28
|
+
"--firmware",
|
29
|
+
"-f",
|
30
|
+
"fw_folder",
|
31
|
+
type=click.Path(exists=True, file_okay=False, dir_okay=True, path_type=Path),
|
32
|
+
default=config.firmware_folder,
|
33
|
+
show_default=True,
|
34
|
+
help="The folder to retrieve the firmware from.",
|
35
|
+
)
|
36
|
+
@click.option(
|
37
|
+
"--version",
|
38
|
+
"-v",
|
39
|
+
"version", # single version
|
40
|
+
default="stable",
|
41
|
+
multiple=False,
|
42
|
+
show_default=True,
|
43
|
+
help="The version of MicroPython to flash.",
|
44
|
+
metavar="SEMVER, 'stable', 'preview' or '?'",
|
45
|
+
)
|
46
|
+
@click.option(
|
47
|
+
"--serial",
|
48
|
+
"--serial-port",
|
49
|
+
"-s",
|
50
|
+
"serial",
|
51
|
+
default="auto",
|
52
|
+
show_default=True,
|
53
|
+
help="Which serial port(s) to flash",
|
54
|
+
metavar="SERIAL_PORT",
|
55
|
+
)
|
56
|
+
@click.option(
|
57
|
+
"--port",
|
58
|
+
"-p",
|
59
|
+
"ports",
|
60
|
+
help="The MicroPython port to flash",
|
61
|
+
metavar="PORT",
|
62
|
+
default=[],
|
63
|
+
multiple=True,
|
64
|
+
)
|
65
|
+
@click.option(
|
66
|
+
"--board",
|
67
|
+
"-b",
|
68
|
+
"board", # single board
|
69
|
+
multiple=False,
|
70
|
+
help="The MicroPython board ID to flash. If not specified will try to read the BOARD_ID from the connected MCU.",
|
71
|
+
metavar="BOARD_ID or ?",
|
72
|
+
)
|
73
|
+
@click.option(
|
74
|
+
"--cpu",
|
75
|
+
"--chip",
|
76
|
+
"-c",
|
77
|
+
"cpu",
|
78
|
+
help="The CPU type to flash. If not specified will try to read the CPU from the connected MCU.",
|
79
|
+
metavar="CPU",
|
80
|
+
)
|
81
|
+
@click.option(
|
82
|
+
"--erase/--no-erase",
|
83
|
+
default=True,
|
84
|
+
show_default=True,
|
85
|
+
help="""Erase flash before writing new firmware. (Not supported on UF2 boards)""",
|
86
|
+
)
|
87
|
+
@click.option(
|
88
|
+
"--bootloader/--no-bootloader",
|
89
|
+
default=True,
|
90
|
+
is_flag=True,
|
91
|
+
show_default=True,
|
92
|
+
help="""Enter micropython bootloader mode before flashing.""",
|
93
|
+
)
|
94
|
+
def cli_flash_board(**kwargs):
|
95
|
+
# version to versions, board to boards
|
96
|
+
kwargs["versions"] = [kwargs.pop("version")] if kwargs["version"] != None else []
|
97
|
+
if kwargs["board"] is None:
|
98
|
+
kwargs["boards"] = []
|
99
|
+
kwargs.pop("board")
|
100
|
+
else:
|
101
|
+
kwargs["boards"] = [kwargs.pop("board")]
|
102
|
+
|
103
|
+
params = FlashParams(**kwargs)
|
104
|
+
if not params.boards or params.boards == []:
|
105
|
+
# nothing specified - detect connected boards
|
106
|
+
params.ports, params.boards = connected_ports_boards()
|
107
|
+
if params.boards == []:
|
108
|
+
# No MicroPython boards detected, but it could be unflashed or not in bootloader mode
|
109
|
+
# Ask for serial port and board_id to flash
|
110
|
+
params.serial = "?"
|
111
|
+
params.boards = ["?"]
|
112
|
+
else:
|
113
|
+
for board_id in params.boards:
|
114
|
+
if board_id == "":
|
115
|
+
params.boards.remove(board_id)
|
116
|
+
continue
|
117
|
+
if " " in board_id:
|
118
|
+
try:
|
119
|
+
info = find_stored_board(board_id)
|
120
|
+
if info:
|
121
|
+
log.info(f"Resolved board description: {info['board']}")
|
122
|
+
params.boards.remove(board_id)
|
123
|
+
params.boards.append(info["board"])
|
124
|
+
except Exception as e:
|
125
|
+
log.warning(f"unable to resolve board description: {e}")
|
126
|
+
|
127
|
+
# Ask for missing input if needed
|
128
|
+
params = ask_missing_params(params, action="flash")
|
129
|
+
if not params: # Cancelled by user
|
130
|
+
exit(1)
|
131
|
+
# TODO: Just in time Download of firmware
|
132
|
+
|
133
|
+
assert isinstance(params, FlashParams)
|
134
|
+
|
135
|
+
if len(params.versions) > 1:
|
136
|
+
log.error(f"Only one version can be flashed at a time, not {params.versions}")
|
137
|
+
raise MPFlashError("Only one version can be flashed at a time")
|
138
|
+
# if len(params.boards) > 1:
|
139
|
+
# log.error(f"Only one board can be flashed at a time, not {params.boards}")
|
140
|
+
# raise MPFlashError("Only one board can be flashed at a time")
|
141
|
+
|
142
|
+
params.versions = [clean_version(v) for v in params.versions]
|
143
|
+
worklist: WorkList = []
|
144
|
+
# if serial port == auto and there are one or more specified/detected boards
|
145
|
+
if params.serial == "auto" and params.boards:
|
146
|
+
worklist = full_auto_worklist(version=params.versions[0], fw_folder=params.fw_folder)
|
147
|
+
elif params.versions[0] and params.boards[0] and params.serial:
|
148
|
+
# A single serial port including the board / variant
|
149
|
+
worklist = manual_worklist(
|
150
|
+
params.versions[0],
|
151
|
+
params.fw_folder,
|
152
|
+
params.serial,
|
153
|
+
params.boards[0],
|
154
|
+
)
|
155
|
+
else:
|
156
|
+
# just this serial port on auto
|
157
|
+
worklist = single_auto_worklist(
|
158
|
+
serial_port=params.serial,
|
159
|
+
version=params.versions[0],
|
160
|
+
fw_folder=params.fw_folder,
|
161
|
+
)
|
162
|
+
|
163
|
+
if flashed := flash_list(
|
164
|
+
worklist,
|
165
|
+
params.fw_folder,
|
166
|
+
params.erase,
|
167
|
+
params.bootloader,
|
168
|
+
):
|
169
|
+
log.info(f"Flashed {len(flashed)} boards")
|
170
|
+
show_mcus(flashed, title="Updated boards after flashing")
|
mpflash/mpflash/cli_group.py
CHANGED
@@ -3,37 +3,69 @@ Main entry point for the CLI group.
|
|
3
3
|
Additional comands are added in the submodules.
|
4
4
|
"""
|
5
5
|
|
6
|
-
from typing import List
|
7
|
-
|
8
6
|
import rich_click as click
|
9
7
|
|
10
8
|
from .config import config
|
11
|
-
from .logger import set_loglevel
|
9
|
+
from .logger import make_quiet, set_loglevel
|
12
10
|
|
13
11
|
|
14
12
|
def cb_verbose(ctx, param, value):
|
15
13
|
"""Callback to set the log level to DEBUG if verbose is set"""
|
16
|
-
if value:
|
14
|
+
if value and not config.quiet:
|
17
15
|
set_loglevel("DEBUG")
|
16
|
+
config.verbose = True
|
18
17
|
else:
|
19
18
|
set_loglevel("INFO")
|
19
|
+
config.verbose = False
|
20
20
|
return value
|
21
21
|
|
22
22
|
|
23
23
|
def cb_ignore(ctx, param, value):
|
24
24
|
if value:
|
25
25
|
config.ignore_ports = list(value)
|
26
|
-
|
26
|
+
return value
|
27
|
+
|
28
|
+
|
29
|
+
def cb_interactive(ctx, param, value):
|
30
|
+
if value:
|
31
|
+
config.interactive = value
|
32
|
+
return value
|
33
|
+
|
34
|
+
|
35
|
+
def cb_quiet(ctx, param, value):
|
36
|
+
if value:
|
37
|
+
make_quiet()
|
27
38
|
return value
|
28
39
|
|
29
40
|
|
30
41
|
@click.group()
|
42
|
+
@click.version_option(package_name="mpflash")
|
43
|
+
@click.option(
|
44
|
+
"--quiet",
|
45
|
+
"-q",
|
46
|
+
is_eager=True,
|
47
|
+
is_flag=True,
|
48
|
+
help="Suppresses all output.",
|
49
|
+
callback=cb_quiet,
|
50
|
+
envvar="MPFLASH_QUIET",
|
51
|
+
show_default=True,
|
52
|
+
)
|
53
|
+
@click.option(
|
54
|
+
"--interactive/--no-interactive",
|
55
|
+
"-i/-x",
|
56
|
+
is_eager=True,
|
57
|
+
help="Suppresses all request for Input.",
|
58
|
+
callback=cb_interactive,
|
59
|
+
# envvar="MPFLASH_QUIET",
|
60
|
+
default=True,
|
61
|
+
show_default=True,
|
62
|
+
)
|
31
63
|
@click.option(
|
32
64
|
"-V",
|
33
65
|
"--verbose",
|
66
|
+
is_eager=True,
|
34
67
|
is_flag=True,
|
35
68
|
help="Enables verbose mode.",
|
36
|
-
is_eager=True,
|
37
69
|
callback=cb_verbose,
|
38
70
|
)
|
39
71
|
@click.option(
|
@@ -48,9 +80,10 @@ def cb_ignore(ctx, param, value):
|
|
48
80
|
show_default=True,
|
49
81
|
metavar="SERIALPORT",
|
50
82
|
)
|
51
|
-
def cli(
|
83
|
+
def cli(**kwargs):
|
52
84
|
"""mpflash - MicroPython Tool.
|
53
85
|
|
54
86
|
A CLI to download and flash MicroPython firmware to different ports and boards.
|
55
87
|
"""
|
88
|
+
# all functionality is added in the submodules
|
56
89
|
pass
|
@@ -0,0 +1,41 @@
|
|
1
|
+
import json
|
2
|
+
|
3
|
+
import rich_click as click
|
4
|
+
from rich import print
|
5
|
+
|
6
|
+
from .cli_group import cli
|
7
|
+
from .list import list_mcus, show_mcus
|
8
|
+
from .logger import make_quiet
|
9
|
+
|
10
|
+
|
11
|
+
@cli.command("list", help="List the connected MCU boards.")
|
12
|
+
@click.option(
|
13
|
+
"--json",
|
14
|
+
"-j",
|
15
|
+
"as_json",
|
16
|
+
is_flag=True,
|
17
|
+
default=False,
|
18
|
+
show_default=True,
|
19
|
+
help="""Output in json format""",
|
20
|
+
)
|
21
|
+
@click.option(
|
22
|
+
"--progress/--no-progress",
|
23
|
+
"progress",
|
24
|
+
is_flag=True,
|
25
|
+
default=True,
|
26
|
+
show_default=True,
|
27
|
+
help="""Show progress""",
|
28
|
+
)
|
29
|
+
def cli_list_mcus(as_json: bool, progress: bool = True):
|
30
|
+
"""List the connected MCU boards, and output in a nice table or json."""
|
31
|
+
if as_json:
|
32
|
+
# avoid noise in json output
|
33
|
+
make_quiet()
|
34
|
+
|
35
|
+
conn_mcus = list_mcus()
|
36
|
+
if as_json:
|
37
|
+
print(json.dumps([mcu.__dict__ for mcu in conn_mcus], indent=4))
|
38
|
+
progress = False
|
39
|
+
if progress:
|
40
|
+
show_mcus(conn_mcus, refresh=False)
|
41
|
+
return conn_mcus
|
mpflash/mpflash/cli_main.py
CHANGED
@@ -1,20 +1,25 @@
|
|
1
1
|
"""mpflash is a CLI to download and flash MicroPython firmware to various boards."""
|
2
2
|
|
3
|
-
import rich_click as click
|
3
|
+
# import rich_click as click
|
4
4
|
|
5
|
+
from .cli_download import cli_download
|
6
|
+
from .cli_flash import cli_flash_board
|
5
7
|
from .cli_group import cli
|
6
|
-
from .
|
7
|
-
from .flasher import flash_board
|
8
|
-
from .list import list_boards
|
8
|
+
from .cli_list import cli_list_mcus
|
9
9
|
|
10
10
|
# from loguru import logger as log
|
11
11
|
|
12
12
|
|
13
13
|
def mpflash():
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
cli(auto_envvar_prefix="MPFLASH")
|
14
|
+
cli.add_command(cli_flash_board)
|
15
|
+
cli.add_command(cli_list_mcus)
|
16
|
+
cli.add_command(cli_download)
|
17
|
+
# cli(auto_envvar_prefix="MPFLASH")
|
18
|
+
try:
|
19
|
+
exit(cli())
|
20
|
+
except AttributeError as e:
|
21
|
+
print(f"Error: {e}")
|
22
|
+
exit(-1)
|
18
23
|
|
19
24
|
|
20
25
|
if __name__ == "__main__":
|
mpflash/mpflash/common.py
CHANGED
@@ -1,126 +1,38 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
import os
|
2
|
+
import time
|
3
|
+
from typing import TypedDict
|
3
4
|
|
4
|
-
import
|
5
|
-
from
|
6
|
-
|
7
|
-
from
|
5
|
+
from github import Auth, Github
|
6
|
+
from rich.progress import track
|
7
|
+
|
8
|
+
from mpflash.errors import MPFlashError
|
9
|
+
# from mpflash.mpremoteboard import MPRemoteBoard
|
8
10
|
|
9
11
|
PORT_FWTYPES = {
|
10
|
-
"stm32": ".
|
11
|
-
"esp32": ".bin",
|
12
|
-
"esp8266": ".bin",
|
13
|
-
"rp2": ".uf2",
|
14
|
-
"samd": ".uf2",
|
15
|
-
"mimxrt": ".hex",
|
16
|
-
"nrf": ".uf2",
|
17
|
-
"renesas-ra": ".hex",
|
12
|
+
"stm32": [".dfu"], # need .dfu for pydfu.py - .hex for cube cli/GUI
|
13
|
+
"esp32": [".bin"],
|
14
|
+
"esp8266": [".bin"],
|
15
|
+
"rp2": [".uf2"],
|
16
|
+
"samd": [".uf2"],
|
17
|
+
"mimxrt": [".hex"],
|
18
|
+
"nrf": [".uf2"],
|
19
|
+
"renesas-ra": [".hex"],
|
18
20
|
}
|
19
21
|
|
20
|
-
|
21
|
-
#
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
version: str
|
36
|
-
|
37
|
-
build: bool = False,
|
38
|
-
patch: bool = False,
|
39
|
-
commit: bool = False,
|
40
|
-
drop_v: bool = False,
|
41
|
-
flat: bool = False,
|
42
|
-
):
|
43
|
-
"Clean up and transform the many flavours of versions"
|
44
|
-
# 'v1.13.0-103-gb137d064e' --> 'v1.13-103'
|
45
|
-
if version in {"", "-"}:
|
46
|
-
return version
|
47
|
-
if version.lower() == "stable":
|
48
|
-
_v = get_stable_version()
|
49
|
-
if not _v:
|
50
|
-
log.warning("Could not determine the latest stable version")
|
51
|
-
return "stable"
|
52
|
-
version = _v
|
53
|
-
log.info(f"Using latest stable version: {version}")
|
54
|
-
is_preview = "-preview" in version
|
55
|
-
nibbles = version.split("-")
|
56
|
-
ver_ = nibbles[0].lower().lstrip("v")
|
57
|
-
if not patch and ver_ >= "1.10.0" and ver_ < "1.20.0" and ver_.endswith(".0"):
|
58
|
-
# remove the last ".0" - but only for versions between 1.10 and 1.20 (because)
|
59
|
-
nibbles[0] = nibbles[0][:-2]
|
60
|
-
if len(nibbles) == 1:
|
61
|
-
version = nibbles[0]
|
62
|
-
elif build and not is_preview:
|
63
|
-
version = "-".join(nibbles) if commit else "-".join(nibbles[:-1])
|
64
|
-
else:
|
65
|
-
# version = "-".join((nibbles[0], LATEST))
|
66
|
-
# HACK: this is not always right, but good enough most of the time
|
67
|
-
if is_preview:
|
68
|
-
version = "-".join((nibbles[0], V_PREVIEW))
|
69
|
-
else:
|
70
|
-
version = V_PREVIEW
|
71
|
-
if flat:
|
72
|
-
version = version.strip().replace(".", "_").replace("-", "_")
|
73
|
-
else:
|
74
|
-
version = version.strip().replace("_preview", "-preview").replace("_", ".")
|
75
|
-
|
76
|
-
if drop_v:
|
77
|
-
version = version.lstrip("v")
|
78
|
-
elif not version.startswith("v") and version.lower() not in SET_PREVIEW:
|
79
|
-
version = "v" + version
|
80
|
-
if version in SET_PREVIEW:
|
81
|
-
version = V_PREVIEW
|
82
|
-
return version
|
83
|
-
|
84
|
-
|
85
|
-
def micropython_versions(minver: str = "v1.9.2"):
|
86
|
-
"""Get the list of micropython versions from github tags"""
|
87
|
-
try:
|
88
|
-
g = Github()
|
89
|
-
_ = 1 / 0
|
90
|
-
repo = g.get_repo("micropython/micropython")
|
91
|
-
versions = [tag.name for tag in repo.get_tags() if parse(tag.name) >= parse(minver)]
|
92
|
-
except Exception:
|
93
|
-
versions = [
|
94
|
-
"v9.99.9-preview",
|
95
|
-
"v1.22.2",
|
96
|
-
"v1.22.1",
|
97
|
-
"v1.22.0",
|
98
|
-
"v1.21.1",
|
99
|
-
"v1.21.0",
|
100
|
-
"v1.20.0",
|
101
|
-
"v1.19.1",
|
102
|
-
"v1.19",
|
103
|
-
"v1.18",
|
104
|
-
"v1.17",
|
105
|
-
"v1.16",
|
106
|
-
"v1.15",
|
107
|
-
"v1.14",
|
108
|
-
"v1.13",
|
109
|
-
"v1.12",
|
110
|
-
"v1.11",
|
111
|
-
"v1.10",
|
112
|
-
"v1.9.4",
|
113
|
-
"v1.9.3",
|
114
|
-
]
|
115
|
-
versions = [v for v in versions if parse(v) >= parse(minver)]
|
116
|
-
return sorted(versions)
|
117
|
-
|
118
|
-
|
119
|
-
def get_stable_version() -> str:
|
120
|
-
# read the versions from the git tags
|
121
|
-
all_versions = micropython_versions(minver="v1.17")
|
122
|
-
stable_version = [v for v in all_versions if not v.endswith(V_PREVIEW)][-1]
|
123
|
-
return stable_version
|
124
|
-
|
125
|
-
|
126
|
-
#############################################################
|
22
|
+
# Token with no permissions to avoid throttling
|
23
|
+
# https://docs.github.com/en/rest/using-the-rest-api/rate-limits-for-the-rest-api?apiVersion=2022-11-28#getting-a-higher-rate-limit
|
24
|
+
PAT_NO_ACCESS = (
|
25
|
+
"github_pat" + "_11AAHPVFQ0qAkDnSUaMKSp" + "_ZkDl5NRRwBsUN6EYg9ahp1Dvj4FDDONnXVgimxC2EtpY7Q7BUKBoQ0Jq72X"
|
26
|
+
)
|
27
|
+
PAT = os.environ.get("GITHUB_TOKEN") or PAT_NO_ACCESS
|
28
|
+
GH_CLIENT = Github(auth=Auth.Token(PAT))
|
29
|
+
|
30
|
+
|
31
|
+
class FWInfo(TypedDict):
|
32
|
+
filename: str
|
33
|
+
port: str
|
34
|
+
board: str
|
35
|
+
variant: str
|
36
|
+
preview: bool
|
37
|
+
version: str
|
38
|
+
build: str
|
mpflash/mpflash/config.py
CHANGED
@@ -1,10 +1,19 @@
|
|
1
1
|
"""centralized configuration for mpflash"""
|
2
2
|
|
3
|
+
from pathlib import Path
|
3
4
|
from typing import List
|
4
5
|
|
6
|
+
import platformdirs
|
7
|
+
|
5
8
|
|
6
9
|
class MPtoolConfig:
|
10
|
+
"""Centralized configuration for mpflash"""
|
11
|
+
|
12
|
+
quiet: bool = False
|
13
|
+
verbose: bool = False
|
7
14
|
ignore_ports: List[str] = []
|
15
|
+
interactive: bool = True
|
16
|
+
firmware_folder: Path = platformdirs.user_downloads_path() / "firmware"
|
8
17
|
|
9
18
|
|
10
19
|
config = MPtoolConfig()
|