-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' of https://github.com/Josverl/micropython-stubber
- Loading branch information
Showing
11 changed files
with
483 additions
and
170 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,174 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 1, | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"data": { | ||
"text/plain": [ | ||
"[<DEVICE ID 2109:2812 on Bus 002 Address 004>,\n", | ||
" <DEVICE ID f055:9800 on Bus 002 Address 040>,\n", | ||
" <DEVICE ID 045e:0c1e on Bus 002 Address 002>,\n", | ||
" <DEVICE ID 043e:9a39 on Bus 002 Address 035>,\n", | ||
" <DEVICE ID 0b0e:245e on Bus 002 Address 032>,\n", | ||
" <DEVICE ID 045e:0927 on Bus 002 Address 010>,\n", | ||
" <DEVICE ID 2109:2812 on Bus 002 Address 007>,\n", | ||
" <DEVICE ID 045e:07b2 on Bus 002 Address 033>,\n", | ||
" <DEVICE ID 1000:2000 on Bus 002 Address 031>,\n", | ||
" <DEVICE ID 046d:085e on Bus 002 Address 011>,\n", | ||
" <DEVICE ID 0bda:5401 on Bus 002 Address 006>,\n", | ||
" <DEVICE ID 0bda:5411 on Bus 002 Address 003>,\n", | ||
" <DEVICE ID 0a05:7211 on Bus 002 Address 013>,\n", | ||
" <DEVICE ID 0a05:7211 on Bus 002 Address 012>,\n", | ||
" <DEVICE ID 8086:a0ed on Bus 002 Address 000>,\n", | ||
" <DEVICE ID 8087:0029 on Bus 002 Address 018>,\n", | ||
" <DEVICE ID 8086:9a13 on Bus 001 Address 000>]" | ||
] | ||
}, | ||
"execution_count": 1, | ||
"metadata": {}, | ||
"output_type": "execute_result" | ||
} | ||
], | ||
"source": [ | ||
"import usb.core\n", | ||
"import usb.util\n", | ||
"import usb.backend.libusb1 as libusb1\n", | ||
"from pathlib import Path\n", | ||
"import platform\n", | ||
"\n", | ||
"if platform.system() == \"Windows\":\n", | ||
" # on windows you need to use the libusb1 backend\n", | ||
" import libusb\n", | ||
"\n", | ||
" arch = \"x64\" if platform.architecture()[0] == \"64bit\" else \"x86\"\n", | ||
" libusb1_dll = Path(libusb.__file__).parent / f\"_platform\\\\_windows\\\\{arch}\\\\libusb-1.0.dll\"\n", | ||
"\n", | ||
" backend = libusb1.get_backend(find_library=lambda x: libusb1_dll.as_posix())\n", | ||
"usb_devices = usb.core.find(backend=backend, find_all=True)\n", | ||
"\n", | ||
"list(usb_devices)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 8, | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"name": "stdout", | ||
"output_type": "stream", | ||
"text": [ | ||
"No DFU devices found\n" | ||
] | ||
} | ||
], | ||
"source": [ | ||
"from mpflash.vendored import pydfu as pydfu\n", | ||
"\n", | ||
"try:\n", | ||
" pydfu.list_dfu_devices()\n", | ||
"except SystemExit:\n", | ||
" print(\"No DFU devices found\")" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 5, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"pydfu.init()" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 6, | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"name": "stdout", | ||
"output_type": "stream", | ||
"text": [ | ||
"Read DFU file...\n", | ||
"File: C:\\Users\\josverl\\Downloads\\firmware\\stm32\\PYBV11-THREAD-v1.23.0-preview.203.dfu\n", | ||
" b'DfuSe' v1, image size: 365621, targets: 1\n", | ||
" b'Target' 0, alt setting: 0, name: \"ST...\", size: 365336, elements: 2\n", | ||
" 0, address: 0x08000000, size: 14712\n", | ||
" 1, address: 0x08020000, size: 350608\n", | ||
" usb: 0483:df11, device: 0x0000, dfu: 0x011a, b'UFD', 16, 0xd114e190\n" | ||
] | ||
} | ||
], | ||
"source": [ | ||
"dfu_file = Path(\"C:\\\\Users\\\\josverl\\\\Downloads\\\\firmware\\\\stm32\\\\PYBV11-THREAD-v1.23.0-preview.203.dfu\")\n", | ||
"\n", | ||
"print(\"Read DFU file...\")\n", | ||
"elements = pydfu.read_dfu_file(dfu_file)\n", | ||
"if not elements:\n", | ||
" print(\"No data in dfu file\")" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 8, | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"name": "stdout", | ||
"output_type": "stream", | ||
"text": [ | ||
"Writing memory...\n", | ||
"0x08000000 14712 [=========================] 100% \n", | ||
"0x08020000 350608 [=========================] 100% \n" | ||
] | ||
} | ||
], | ||
"source": [ | ||
"print(\"Writing memory...\")\n", | ||
"pydfu.write_elements(elements, False, progress=pydfu.cli_progress)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 9, | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"name": "stdout", | ||
"output_type": "stream", | ||
"text": [ | ||
"Exiting DFU...\n" | ||
] | ||
} | ||
], | ||
"source": [ | ||
"print(\"Exiting DFU...\")\n", | ||
"pydfu.exit_dfu()" | ||
] | ||
} | ||
], | ||
"metadata": { | ||
"kernelspec": { | ||
"display_name": ".venv", | ||
"language": "python", | ||
"name": "python3" | ||
}, | ||
"language_info": { | ||
"codemirror_mode": { | ||
"name": "ipython", | ||
"version": 3 | ||
}, | ||
"file_extension": ".py", | ||
"mimetype": "text/x-python", | ||
"name": "python", | ||
"nbconvert_exporter": "python", | ||
"pygments_lexer": "ipython3", | ||
"version": "3.11.7" | ||
} | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 2 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,26 @@ | ||
"""Flash STM32 boards using either STM32CubeProgrammer CLI or dfu-util""" | ||
|
||
from pathlib import Path | ||
from .flash_stm32_dfu import flash_stm32_dfu | ||
from .flash_stm32_cube import flash_stm32_cubecli | ||
|
||
from loguru import logger as log | ||
|
||
from mpflash.common import wait_for_restart | ||
|
||
# from .flash_stm32_cube import flash_stm32_cubecli | ||
from .flash_stm32_dfu import dfu_init, flash_stm32_dfu | ||
from .mpremoteboard.mpremoteboard import MPRemoteBoard | ||
|
||
|
||
def flash_stm32(mcu: MPRemoteBoard, fw_file: Path, *, erase: bool, stm32_hex: bool): | ||
"""Flash STM32 boards using either STM32CubeProgrammer CLI or dfu-util""" | ||
# TODO: Check installed utilities / Lazy import | ||
if stm32_hex: | ||
updated = flash_stm32_cubecli(mcu, fw_file=fw_file, erase=erase) | ||
else: | ||
updated = flash_stm32_dfu(mcu, fw_file=fw_file, erase=erase) | ||
def flash_stm32(mcu: MPRemoteBoard, fw_file: Path, *, erase: bool, stm32_dfu: bool = True): | ||
# sourcery skip: lift-return-into-if | ||
log.info("Using dfu-util") | ||
dfu_init() | ||
updated = flash_stm32_dfu(mcu, fw_file=fw_file, erase=erase) | ||
# if stm32_dfu: | ||
# else: | ||
# log.info("Using STM32CubeProgrammer CLI") | ||
# updated = flash_stm32_cubecli(mcu, fw_file=fw_file, erase=erase) | ||
|
||
wait_for_restart(mcu) | ||
log.success(f"Flashed {mcu.version} to {mcu.board}") | ||
return updated |
Oops, something went wrong.