micropython-stubber 1.20.5__py3-none-any.whl → 1.20.6__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.
Files changed (152) hide show
  1. {micropython_stubber-1.20.5.dist-info → micropython_stubber-1.20.6.dist-info}/LICENSE +30 -30
  2. {micropython_stubber-1.20.5.dist-info → micropython_stubber-1.20.6.dist-info}/METADATA +1 -1
  3. micropython_stubber-1.20.6.dist-info/RECORD +159 -0
  4. mpflash/README.md +184 -184
  5. mpflash/libusb_flash.ipynb +203 -203
  6. mpflash/mpflash/add_firmware.py +98 -98
  7. mpflash/mpflash/ask_input.py +236 -236
  8. mpflash/mpflash/bootloader/__init__.py +37 -36
  9. mpflash/mpflash/bootloader/manual.py +102 -102
  10. mpflash/mpflash/bootloader/micropython.py +10 -10
  11. mpflash/mpflash/bootloader/touch1200.py +45 -45
  12. mpflash/mpflash/cli_download.py +129 -129
  13. mpflash/mpflash/cli_flash.py +219 -219
  14. mpflash/mpflash/cli_group.py +98 -98
  15. mpflash/mpflash/cli_list.py +81 -81
  16. mpflash/mpflash/cli_main.py +41 -41
  17. mpflash/mpflash/common.py +164 -164
  18. mpflash/mpflash/config.py +47 -47
  19. mpflash/mpflash/connected.py +74 -74
  20. mpflash/mpflash/download.py +360 -360
  21. mpflash/mpflash/downloaded.py +129 -129
  22. mpflash/mpflash/errors.py +9 -9
  23. mpflash/mpflash/flash.py +52 -52
  24. mpflash/mpflash/flash_esp.py +59 -59
  25. mpflash/mpflash/flash_stm32.py +24 -24
  26. mpflash/mpflash/flash_stm32_cube.py +111 -111
  27. mpflash/mpflash/flash_stm32_dfu.py +101 -101
  28. mpflash/mpflash/flash_uf2.py +67 -67
  29. mpflash/mpflash/flash_uf2_boardid.py +15 -15
  30. mpflash/mpflash/flash_uf2_linux.py +123 -123
  31. mpflash/mpflash/flash_uf2_macos.py +34 -34
  32. mpflash/mpflash/flash_uf2_windows.py +34 -34
  33. mpflash/mpflash/list.py +89 -89
  34. mpflash/mpflash/logger.py +41 -41
  35. mpflash/mpflash/mpboard_id/__init__.py +93 -93
  36. mpflash/mpflash/mpboard_id/add_boards.py +255 -255
  37. mpflash/mpflash/mpboard_id/board.py +37 -37
  38. mpflash/mpflash/mpboard_id/board_id.py +86 -86
  39. mpflash/mpflash/mpboard_id/store.py +43 -43
  40. mpflash/mpflash/mpremoteboard/__init__.py +221 -221
  41. mpflash/mpflash/mpremoteboard/mpy_fw_info.py +141 -141
  42. mpflash/mpflash/mpremoteboard/runner.py +140 -140
  43. mpflash/mpflash/uf2disk.py +12 -12
  44. mpflash/mpflash/vendor/basicgit.py +288 -288
  45. mpflash/mpflash/vendor/click_aliases.py +91 -91
  46. mpflash/mpflash/vendor/dfu.py +165 -165
  47. mpflash/mpflash/vendor/pydfu.py +605 -605
  48. mpflash/mpflash/vendor/readme.md +2 -2
  49. mpflash/mpflash/vendor/versions.py +119 -117
  50. mpflash/mpflash/worklist.py +170 -170
  51. mpflash/poetry.lock +1588 -1588
  52. mpflash/pyproject.toml +60 -60
  53. mpflash/stm32_udev_rules.md +62 -62
  54. stubber/__init__.py +3 -3
  55. stubber/basicgit.py +294 -288
  56. stubber/board/board_info.csv +193 -193
  57. stubber/board/boot.py +34 -34
  58. stubber/board/createstubs.py +986 -986
  59. stubber/board/createstubs_db.py +825 -825
  60. stubber/board/createstubs_db_min.py +331 -331
  61. stubber/board/createstubs_db_mpy.mpy +0 -0
  62. stubber/board/createstubs_lvgl.py +741 -741
  63. stubber/board/createstubs_lvgl_min.py +741 -741
  64. stubber/board/createstubs_mem.py +766 -766
  65. stubber/board/createstubs_mem_min.py +306 -306
  66. stubber/board/createstubs_mem_mpy.mpy +0 -0
  67. stubber/board/createstubs_min.py +294 -294
  68. stubber/board/createstubs_mpy.mpy +0 -0
  69. stubber/board/fw_info.py +141 -141
  70. stubber/board/info.py +183 -183
  71. stubber/board/main.py +19 -19
  72. stubber/board/modulelist.txt +247 -247
  73. stubber/board/pyrightconfig.json +34 -34
  74. stubber/bulk/mcu_stubber.py +454 -454
  75. stubber/codemod/_partials/__init__.py +48 -48
  76. stubber/codemod/_partials/db_main.py +147 -147
  77. stubber/codemod/_partials/lvgl_main.py +77 -77
  78. stubber/codemod/_partials/modules_reader.py +80 -80
  79. stubber/codemod/add_comment.py +53 -53
  80. stubber/codemod/add_method.py +65 -65
  81. stubber/codemod/board.py +317 -317
  82. stubber/codemod/enrich.py +145 -145
  83. stubber/codemod/merge_docstub.py +284 -284
  84. stubber/codemod/modify_list.py +54 -54
  85. stubber/codemod/utils.py +57 -57
  86. stubber/commands/build_cmd.py +94 -94
  87. stubber/commands/cli.py +51 -51
  88. stubber/commands/clone_cmd.py +66 -66
  89. stubber/commands/config_cmd.py +29 -29
  90. stubber/commands/enrich_folder_cmd.py +70 -70
  91. stubber/commands/get_core_cmd.py +69 -69
  92. stubber/commands/get_docstubs_cmd.py +87 -87
  93. stubber/commands/get_frozen_cmd.py +112 -112
  94. stubber/commands/get_mcu_cmd.py +56 -56
  95. stubber/commands/merge_cmd.py +66 -66
  96. stubber/commands/publish_cmd.py +119 -119
  97. stubber/commands/stub_cmd.py +30 -30
  98. stubber/commands/switch_cmd.py +54 -54
  99. stubber/commands/variants_cmd.py +48 -48
  100. stubber/cst_transformer.py +178 -178
  101. stubber/data/board_info.csv +193 -193
  102. stubber/data/board_info.json +1729 -1729
  103. stubber/data/micropython_tags.csv +15 -15
  104. stubber/data/requirements-core-micropython.txt +38 -38
  105. stubber/data/requirements-core-pycopy.txt +39 -39
  106. stubber/downloader.py +36 -36
  107. stubber/freeze/common.py +68 -68
  108. stubber/freeze/freeze_folder.py +69 -69
  109. stubber/freeze/freeze_manifest_2.py +113 -113
  110. stubber/freeze/get_frozen.py +127 -127
  111. stubber/get_cpython.py +101 -101
  112. stubber/get_lobo.py +59 -59
  113. stubber/minify.py +418 -418
  114. stubber/publish/bump.py +86 -86
  115. stubber/publish/candidates.py +262 -262
  116. stubber/publish/database.py +18 -18
  117. stubber/publish/defaults.py +45 -45
  118. stubber/publish/enums.py +24 -24
  119. stubber/publish/helpers.py +29 -29
  120. stubber/publish/merge_docstubs.py +130 -130
  121. stubber/publish/missing_class_methods.py +49 -49
  122. stubber/publish/package.py +146 -146
  123. stubber/publish/pathnames.py +51 -51
  124. stubber/publish/publish.py +120 -120
  125. stubber/publish/pypi.py +38 -38
  126. stubber/publish/stubpackage.py +1029 -1029
  127. stubber/rst/__init__.py +9 -9
  128. stubber/rst/classsort.py +77 -77
  129. stubber/rst/lookup.py +530 -530
  130. stubber/rst/output_dict.py +401 -401
  131. stubber/rst/reader.py +822 -822
  132. stubber/rst/report_return.py +69 -69
  133. stubber/rst/rst_utils.py +540 -540
  134. stubber/stubber.py +38 -38
  135. stubber/stubs_from_docs.py +90 -90
  136. stubber/tools/manifestfile.py +610 -610
  137. stubber/tools/readme.md +5 -5
  138. stubber/update_fallback.py +117 -117
  139. stubber/update_module_list.py +123 -123
  140. stubber/utils/__init__.py +5 -5
  141. stubber/utils/config.py +127 -127
  142. stubber/utils/makeversionhdr.py +54 -54
  143. stubber/utils/manifest.py +92 -92
  144. stubber/utils/post.py +79 -79
  145. stubber/utils/repos.py +157 -154
  146. stubber/utils/stubmaker.py +139 -139
  147. stubber/utils/typed_config_toml.py +77 -77
  148. stubber/utils/versions.py +128 -120
  149. stubber/variants.py +106 -106
  150. micropython_stubber-1.20.5.dist-info/RECORD +0 -159
  151. {micropython_stubber-1.20.5.dist-info → micropython_stubber-1.20.6.dist-info}/WHEEL +0 -0
  152. {micropython_stubber-1.20.5.dist-info → micropython_stubber-1.20.6.dist-info}/entry_points.txt +0 -0
@@ -1,111 +1,111 @@
1
- # """
2
- # Flash STM32 using STM32CubeProgrammer
3
- # needs to be installed independenty from https://www.st.com/en/development-tools/stm32cubeprog.html
4
-
5
- # On Linux needs to be run with sudo - unless udev rules are set to allow access to the device as a regular user
6
- # """
7
-
8
- # import subprocess
9
- # import sys
10
- # import time
11
- # from pathlib import Path
12
- # from typing import Optional
13
-
14
- # import bincopy
15
- # from loguru import logger as log
16
- # from rich.progress import track
17
- # from strip_ansi import strip_ansi
18
-
19
- # from .mpremoteboard.mpremoteboard import MPRemoteBoard
20
-
21
- # STM32_CLI_WIN = "C:\\Program Files\\STMicroelectronics\\STM32Cube\\STM32CubeProgrammer\\bin\\STM32_Programmer_CLI.exe"
22
- # STM32_CLI_LINUX = "~/STMicroelectronics/STM32Cube/STM32CubeProgrammer/bin/STM32_Programmer_CLI"
23
-
24
-
25
- # def get_stm32_start_address(fw_file: Path):
26
- # """
27
- # Get the start address of the firmware file, to allow automatic restart from that address after flashing
28
- # """
29
- # try:
30
- # fw_hex = bincopy.BinFile(str(fw_file))
31
- # return f"0x{fw_hex.execution_start_address:08X}"
32
- # except Exception:
33
-
34
- # return ""
35
-
36
-
37
- # def flash_stm32_cubecli(mcu: MPRemoteBoard, fw_file: Path, *, erase: bool = True) -> Optional[MPRemoteBoard]:
38
- # """
39
- # Flash STM32 devices using STM32CubeProgrammer CLI
40
- # - Enter bootloader mode
41
- # - wait 2s for the device to be detected
42
- # - list the connected DFU devices
43
-
44
- # On Linux: requires udev rules to allow access to the device as a regular user
45
- # """
46
- # if sys.platform == "linux":
47
- # STM32_CLI = Path(STM32_CLI_LINUX).expanduser().as_posix()
48
- # elif sys.platform == "win32":
49
- # STM32_CLI = str(Path(STM32_CLI_WIN).expanduser())
50
- # else:
51
- # log.error(f"OS {sys.platform} not supported")
52
- # return None
53
-
54
- # if not Path(STM32_CLI).exists():
55
- # log.error(
56
- # f"STM32CubeProgrammer not found at {STM32_CLI}\nPlease install it from https://www.st.com/en/development-tools/stm32cubeprog.html"
57
- # )
58
- # return None
59
-
60
- # # run STM32_Programmer_CLI.exe --list
61
- # cmd = [
62
- # STM32_CLI,
63
- # "--list",
64
- # ]
65
- # results = subprocess.run(cmd, capture_output=True, text=True).stdout.splitlines()
66
- # results = [strip_ansi(line) for line in results]
67
- # if not any(["Product ID : STM32 BOOTLOADER" in l for l in results]):
68
- # log.error("No STM32 BOOTLOADER detected")
69
- # return None
70
- # echo = False
71
- # for line in results:
72
- # if line.startswith("===== DFU Interface"):
73
- # echo = True
74
- # if line.startswith("===== STLink"):
75
- # echo = False
76
- # if echo:
77
- # print(line)
78
- # # Try to connect - no action
79
- # cmd = [
80
- # STM32_CLI,
81
- # "--connect",
82
- # "port=USB1",
83
- # ]
84
- # results = subprocess.run(cmd, capture_output=True, text=True).stdout.splitlines()
85
- # if erase:
86
- # log.info("Erasing flash")
87
- # cmd = [
88
- # STM32_CLI,
89
- # "--connect",
90
- # "port=USB1",
91
- # "--erase",
92
- # "all",
93
- # ]
94
- # results = subprocess.run(cmd, capture_output=True, text=True).stdout.splitlines()
95
- # results = [strip_ansi(line) for line in results]
96
- # log.info(f"Flashing {fw_file.name} using STM32CubeProgrammer CLI")
97
- # start_address = get_stm32_start_address(fw_file)
98
-
99
- # log.trace(f"STM32_Programmer_CLI --connect port=USB1 --write {str(fw_file)} --go {start_address}")
100
- # cmd = [
101
- # STM32_CLI,
102
- # "--connect",
103
- # "port=USB1",
104
- # "--write",
105
- # str(fw_file),
106
- # "--go",
107
- # start_address,
108
- # ]
109
- # results = subprocess.run(cmd, capture_output=True, text=True).stdout.splitlines()
110
- # log.success("Done flashing, resetting the board and wait for it to restart")
111
- # return mcu
1
+ # """
2
+ # Flash STM32 using STM32CubeProgrammer
3
+ # needs to be installed independenty from https://www.st.com/en/development-tools/stm32cubeprog.html
4
+
5
+ # On Linux needs to be run with sudo - unless udev rules are set to allow access to the device as a regular user
6
+ # """
7
+
8
+ # import subprocess
9
+ # import sys
10
+ # import time
11
+ # from pathlib import Path
12
+ # from typing import Optional
13
+
14
+ # import bincopy
15
+ # from loguru import logger as log
16
+ # from rich.progress import track
17
+ # from strip_ansi import strip_ansi
18
+
19
+ # from .mpremoteboard.mpremoteboard import MPRemoteBoard
20
+
21
+ # STM32_CLI_WIN = "C:\\Program Files\\STMicroelectronics\\STM32Cube\\STM32CubeProgrammer\\bin\\STM32_Programmer_CLI.exe"
22
+ # STM32_CLI_LINUX = "~/STMicroelectronics/STM32Cube/STM32CubeProgrammer/bin/STM32_Programmer_CLI"
23
+
24
+
25
+ # def get_stm32_start_address(fw_file: Path):
26
+ # """
27
+ # Get the start address of the firmware file, to allow automatic restart from that address after flashing
28
+ # """
29
+ # try:
30
+ # fw_hex = bincopy.BinFile(str(fw_file))
31
+ # return f"0x{fw_hex.execution_start_address:08X}"
32
+ # except Exception:
33
+
34
+ # return ""
35
+
36
+
37
+ # def flash_stm32_cubecli(mcu: MPRemoteBoard, fw_file: Path, *, erase: bool = True) -> Optional[MPRemoteBoard]:
38
+ # """
39
+ # Flash STM32 devices using STM32CubeProgrammer CLI
40
+ # - Enter bootloader mode
41
+ # - wait 2s for the device to be detected
42
+ # - list the connected DFU devices
43
+
44
+ # On Linux: requires udev rules to allow access to the device as a regular user
45
+ # """
46
+ # if sys.platform == "linux":
47
+ # STM32_CLI = Path(STM32_CLI_LINUX).expanduser().as_posix()
48
+ # elif sys.platform == "win32":
49
+ # STM32_CLI = str(Path(STM32_CLI_WIN).expanduser())
50
+ # else:
51
+ # log.error(f"OS {sys.platform} not supported")
52
+ # return None
53
+
54
+ # if not Path(STM32_CLI).exists():
55
+ # log.error(
56
+ # f"STM32CubeProgrammer not found at {STM32_CLI}\nPlease install it from https://www.st.com/en/development-tools/stm32cubeprog.html"
57
+ # )
58
+ # return None
59
+
60
+ # # run STM32_Programmer_CLI.exe --list
61
+ # cmd = [
62
+ # STM32_CLI,
63
+ # "--list",
64
+ # ]
65
+ # results = subprocess.run(cmd, capture_output=True, text=True).stdout.splitlines()
66
+ # results = [strip_ansi(line) for line in results]
67
+ # if not any(["Product ID : STM32 BOOTLOADER" in l for l in results]):
68
+ # log.error("No STM32 BOOTLOADER detected")
69
+ # return None
70
+ # echo = False
71
+ # for line in results:
72
+ # if line.startswith("===== DFU Interface"):
73
+ # echo = True
74
+ # if line.startswith("===== STLink"):
75
+ # echo = False
76
+ # if echo:
77
+ # print(line)
78
+ # # Try to connect - no action
79
+ # cmd = [
80
+ # STM32_CLI,
81
+ # "--connect",
82
+ # "port=USB1",
83
+ # ]
84
+ # results = subprocess.run(cmd, capture_output=True, text=True).stdout.splitlines()
85
+ # if erase:
86
+ # log.info("Erasing flash")
87
+ # cmd = [
88
+ # STM32_CLI,
89
+ # "--connect",
90
+ # "port=USB1",
91
+ # "--erase",
92
+ # "all",
93
+ # ]
94
+ # results = subprocess.run(cmd, capture_output=True, text=True).stdout.splitlines()
95
+ # results = [strip_ansi(line) for line in results]
96
+ # log.info(f"Flashing {fw_file.name} using STM32CubeProgrammer CLI")
97
+ # start_address = get_stm32_start_address(fw_file)
98
+
99
+ # log.trace(f"STM32_Programmer_CLI --connect port=USB1 --write {str(fw_file)} --go {start_address}")
100
+ # cmd = [
101
+ # STM32_CLI,
102
+ # "--connect",
103
+ # "port=USB1",
104
+ # "--write",
105
+ # str(fw_file),
106
+ # "--go",
107
+ # start_address,
108
+ # ]
109
+ # results = subprocess.run(cmd, capture_output=True, text=True).stdout.splitlines()
110
+ # log.success("Done flashing, resetting the board and wait for it to restart")
111
+ # return mcu
@@ -1,101 +1,101 @@
1
- import platform
2
- from pathlib import Path
3
- from typing import Optional
4
-
5
- from loguru import logger as log
6
-
7
- from mpflash.mpremoteboard import MPRemoteBoard
8
-
9
-
10
- def init_libusb_windows() -> bool:
11
- """
12
- Initializes the libusb backend on Windows.
13
-
14
- Returns:
15
- bool: True if the initialization is successful, False otherwise.
16
- """
17
- import libusb # type: ignore
18
- import usb.backend.libusb1 as libusb1
19
-
20
- arch = "x64" if platform.architecture()[0] == "64bit" else "x86"
21
- libusb1_dll = Path(libusb.__file__).parent / f"_platform\\_windows\\{arch}\\libusb-1.0.dll"
22
- if not libusb1_dll.exists():
23
- raise FileNotFoundError(f"libusb1.dll not found at {libusb1_dll}")
24
- backend = libusb1.get_backend(find_library=lambda x: libusb1_dll.as_posix())
25
- return backend is not None
26
-
27
-
28
- try:
29
- from .vendor import pydfu as pydfu
30
- except ImportError:
31
- pydfu = None
32
-
33
-
34
- def dfu_init():
35
- """
36
- Initializes the DFU (Device Firmware Upgrade) process.
37
- """
38
- if not pydfu:
39
- log.error("pydfu not found")
40
- return None
41
- if platform.system() == "Windows":
42
- init_libusb_windows()
43
-
44
-
45
- def flash_stm32_dfu(
46
- mcu: MPRemoteBoard,
47
- fw_file: Path,
48
- *,
49
- erase: bool = True,
50
- ) -> Optional[MPRemoteBoard]:
51
- """
52
- Flashes the STM32 microcontroller using DFU (Device Firmware Upgrade).
53
-
54
- Args:
55
- mcu (MPRemoteBoard): The remote board to flash.
56
- fw_file (Path): The path to the firmware file (.dfu).
57
- erase (bool, optional): Whether to erase the memory before flashing. Defaults to True.
58
-
59
- Returns:
60
- Optional[MPRemoteBoard]: The flashed remote board if successful, None otherwise.
61
- """
62
- if not pydfu:
63
- log.error("pydfu not found, please install it with 'pip install pydfu' if supported")
64
- return None
65
-
66
- if not fw_file.exists():
67
- log.error(f"File {fw_file} not found")
68
- return None
69
-
70
- if fw_file.suffix != ".dfu":
71
- log.error(f"File {fw_file} is not a .dfu file")
72
- return None
73
-
74
- kwargs = {"idVendor": 0x0483, "idProduct": 0xDF11}
75
- log.debug("List SPECIFIED DFU devices...")
76
- try:
77
- pydfu.list_dfu_devices(**kwargs)
78
- except ValueError as e:
79
- log.error(f"Insuffient permissions to access usb DFU devices: {e}")
80
- return None
81
-
82
- # Needs to be a list of serial ports
83
- log.debug("Inititialize pydfu...")
84
- pydfu.init(**kwargs)
85
-
86
- if erase:
87
- log.info("Mass erase...")
88
- pydfu.mass_erase()
89
-
90
- log.debug("Read DFU file...")
91
- elements = pydfu.read_dfu_file(fw_file)
92
- if not elements:
93
- print("No data in dfu file")
94
- return
95
- log.info("Writing memory...")
96
- pydfu.write_elements(elements, False, progress=pydfu.cli_progress)
97
-
98
- log.debug("Exiting DFU...")
99
- pydfu.exit_dfu()
100
- log.success("Done flashing, resetting the board and wait for it to restart")
101
- return mcu
1
+ import platform
2
+ from pathlib import Path
3
+ from typing import Optional
4
+
5
+ from loguru import logger as log
6
+
7
+ from mpflash.mpremoteboard import MPRemoteBoard
8
+
9
+
10
+ def init_libusb_windows() -> bool:
11
+ """
12
+ Initializes the libusb backend on Windows.
13
+
14
+ Returns:
15
+ bool: True if the initialization is successful, False otherwise.
16
+ """
17
+ import libusb # type: ignore
18
+ import usb.backend.libusb1 as libusb1
19
+
20
+ arch = "x64" if platform.architecture()[0] == "64bit" else "x86"
21
+ libusb1_dll = Path(libusb.__file__).parent / f"_platform\\_windows\\{arch}\\libusb-1.0.dll"
22
+ if not libusb1_dll.exists():
23
+ raise FileNotFoundError(f"libusb1.dll not found at {libusb1_dll}")
24
+ backend = libusb1.get_backend(find_library=lambda x: libusb1_dll.as_posix())
25
+ return backend is not None
26
+
27
+
28
+ try:
29
+ from .vendor import pydfu as pydfu
30
+ except ImportError:
31
+ pydfu = None
32
+
33
+
34
+ def dfu_init():
35
+ """
36
+ Initializes the DFU (Device Firmware Upgrade) process.
37
+ """
38
+ if not pydfu:
39
+ log.error("pydfu not found")
40
+ return None
41
+ if platform.system() == "Windows":
42
+ init_libusb_windows()
43
+
44
+
45
+ def flash_stm32_dfu(
46
+ mcu: MPRemoteBoard,
47
+ fw_file: Path,
48
+ *,
49
+ erase: bool = True,
50
+ ) -> Optional[MPRemoteBoard]:
51
+ """
52
+ Flashes the STM32 microcontroller using DFU (Device Firmware Upgrade).
53
+
54
+ Args:
55
+ mcu (MPRemoteBoard): The remote board to flash.
56
+ fw_file (Path): The path to the firmware file (.dfu).
57
+ erase (bool, optional): Whether to erase the memory before flashing. Defaults to True.
58
+
59
+ Returns:
60
+ Optional[MPRemoteBoard]: The flashed remote board if successful, None otherwise.
61
+ """
62
+ if not pydfu:
63
+ log.error("pydfu not found, please install it with 'pip install pydfu' if supported")
64
+ return None
65
+
66
+ if not fw_file.exists():
67
+ log.error(f"File {fw_file} not found")
68
+ return None
69
+
70
+ if fw_file.suffix != ".dfu":
71
+ log.error(f"File {fw_file} is not a .dfu file")
72
+ return None
73
+
74
+ kwargs = {"idVendor": 0x0483, "idProduct": 0xDF11}
75
+ log.debug("List SPECIFIED DFU devices...")
76
+ try:
77
+ pydfu.list_dfu_devices(**kwargs)
78
+ except ValueError as e:
79
+ log.error(f"Insuffient permissions to access usb DFU devices: {e}")
80
+ return None
81
+
82
+ # Needs to be a list of serial ports
83
+ log.debug("Inititialize pydfu...")
84
+ pydfu.init(**kwargs)
85
+
86
+ if erase:
87
+ log.info("Mass erase...")
88
+ pydfu.mass_erase()
89
+
90
+ log.debug("Read DFU file...")
91
+ elements = pydfu.read_dfu_file(fw_file)
92
+ if not elements:
93
+ print("No data in dfu file")
94
+ return
95
+ log.info("Writing memory...")
96
+ pydfu.write_elements(elements, False, progress=pydfu.cli_progress)
97
+
98
+ log.debug("Exiting DFU...")
99
+ pydfu.exit_dfu()
100
+ log.success("Done flashing, resetting the board and wait for it to restart")
101
+ return mcu
@@ -1,67 +1,67 @@
1
- """
2
- Flash SAMD and RP2 via UF2
3
- """
4
-
5
- import shutil
6
- import sys
7
- import time
8
- from pathlib import Path
9
- from typing import Optional
10
-
11
- from loguru import logger as log
12
- from rich.progress import track
13
-
14
- from mpflash.mpremoteboard import MPRemoteBoard
15
-
16
- from .common import PORT_FWTYPES
17
- from .flash_uf2_boardid import get_board_id
18
- from .flash_uf2_linux import dismount_uf2_linux, wait_for_UF2_linux
19
- from .flash_uf2_macos import wait_for_UF2_macos
20
- from .flash_uf2_windows import wait_for_UF2_windows
21
-
22
-
23
- def flash_uf2(mcu: MPRemoteBoard, fw_file: Path, erase: bool) -> Optional[MPRemoteBoard]:
24
- """
25
- Flash .UF2 devices via bootloader and filecopy
26
- - mpremote bootloader
27
- - Wait for the device to mount as a drive (up to 5s)
28
- - detect new drive with INFO_UF2.TXT
29
- - copy the firmware file to the drive
30
- - wait for the device to restart (5s)
31
-
32
- for Linux - to support headless operation ( GH Actions ) :
33
- pmount and pumount are used to mount and unmount the drive
34
- as this is not done automatically by the OS in headless mode.
35
- """
36
- if ".uf2" not in PORT_FWTYPES[mcu.port]:
37
- log.error(f"UF2 not supported on {mcu.board} on {mcu.serialport}")
38
- return None
39
- if erase:
40
- log.info("Erasing not yet implemented for UF2 flashing.")
41
-
42
- if sys.platform == "linux":
43
- destination = wait_for_UF2_linux()
44
- elif sys.platform == "win32":
45
- destination = wait_for_UF2_windows()
46
- elif sys.platform == "darwin":
47
- log.warning(f"OS {sys.platform} not tested/supported")
48
- destination = wait_for_UF2_macos()
49
- else:
50
- log.warning(f"OS {sys.platform} not tested/supported")
51
- return None
52
-
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
-
57
- log.info("Board is in bootloader mode")
58
- board_id = get_board_id(destination) # type: ignore
59
- log.info(f"Board ID: {board_id}")
60
- log.info(f"Copying {fw_file} to {destination}.")
61
- 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
1
+ """
2
+ Flash SAMD and RP2 via UF2
3
+ """
4
+
5
+ import shutil
6
+ import sys
7
+ import time
8
+ from pathlib import Path
9
+ from typing import Optional
10
+
11
+ from loguru import logger as log
12
+ from rich.progress import track
13
+
14
+ from mpflash.mpremoteboard import MPRemoteBoard
15
+
16
+ from .common import PORT_FWTYPES
17
+ from .flash_uf2_boardid import get_board_id
18
+ from .flash_uf2_linux import dismount_uf2_linux, wait_for_UF2_linux
19
+ from .flash_uf2_macos import wait_for_UF2_macos
20
+ from .flash_uf2_windows import wait_for_UF2_windows
21
+
22
+
23
+ def flash_uf2(mcu: MPRemoteBoard, fw_file: Path, erase: bool) -> Optional[MPRemoteBoard]:
24
+ """
25
+ Flash .UF2 devices via bootloader and filecopy
26
+ - mpremote bootloader
27
+ - Wait for the device to mount as a drive (up to 5s)
28
+ - detect new drive with INFO_UF2.TXT
29
+ - copy the firmware file to the drive
30
+ - wait for the device to restart (5s)
31
+
32
+ for Linux - to support headless operation ( GH Actions ) :
33
+ pmount and pumount are used to mount and unmount the drive
34
+ as this is not done automatically by the OS in headless mode.
35
+ """
36
+ if ".uf2" not in PORT_FWTYPES[mcu.port]:
37
+ log.error(f"UF2 not supported on {mcu.board} on {mcu.serialport}")
38
+ return None
39
+ if erase:
40
+ log.info("Erasing not yet implemented for UF2 flashing.")
41
+
42
+ if sys.platform == "linux":
43
+ destination = wait_for_UF2_linux()
44
+ elif sys.platform == "win32":
45
+ destination = wait_for_UF2_windows()
46
+ elif sys.platform == "darwin":
47
+ log.warning(f"OS {sys.platform} not tested/supported")
48
+ destination = wait_for_UF2_macos()
49
+ else:
50
+ log.warning(f"OS {sys.platform} not tested/supported")
51
+ return None
52
+
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
+
57
+ log.info("Board is in bootloader mode")
58
+ board_id = get_board_id(destination) # type: ignore
59
+ log.info(f"Board ID: {board_id}")
60
+ log.info(f"Copying {fw_file} to {destination}.")
61
+ 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
@@ -1,15 +1,15 @@
1
- from pathlib import Path
2
-
3
- from loguru import logger as log
4
-
5
-
6
- def get_board_id(path: Path):
7
- # Option : read Board-ID from INFO_UF2.TXT
8
- board_id = "Unknown"
9
- with open(path / "INFO_UF2.TXT") as f:
10
- data = f.readlines()
11
- for line in data:
12
- if line.startswith("Board-ID"):
13
- board_id = line[9:].strip()
14
- log.debug(f"INFO_UF2.TXT Board-ID={board_id}")
15
- return board_id
1
+ from pathlib import Path
2
+
3
+ from loguru import logger as log
4
+
5
+
6
+ def get_board_id(path: Path):
7
+ # Option : read Board-ID from INFO_UF2.TXT
8
+ board_id = "Unknown"
9
+ with open(path / "INFO_UF2.TXT") as f:
10
+ data = f.readlines()
11
+ for line in data:
12
+ if line.startswith("Board-ID"):
13
+ board_id = line[9:].strip()
14
+ log.debug(f"INFO_UF2.TXT Board-ID={board_id}")
15
+ return board_id