Python USB firmware update library.
Project description
pyfu-usb: Python USB Firmware Updater
A small library for firmware updates over USB with devices that support the DFU and DfuSe protocols. Specifically, pyfu-usb
supports listing DFU capable devices and downloading binary files to them.
Compared to dfu-util
dfu-util
is the popular host side tool for interacting with DFU/DfuSe devices. pyfu-usb
has only a small sliver the functionality contained in dfu-util
: Listing and downloading binary files. The reason you would use pyfu-usb
over dfu-util
is if you have a Python project that needs firmware update capabilities and don't want an external (non-Python) dependency.
Compared to pydfu.py
pydfu.py
is a tool in the OpenMV project that solves the exact problem described above, but it is only for DfuSe devices (e.g. STM32) and also hard codes a number of parameters including device address and max transfer size. It also appears to only work with .dfu
files, which require an extra conversion step. Since binary files can be directly generated by many embedded toolchains using them is simpler, although less portable.
The code in this package originates from pydfu.py
and the OpenMV license agreement has been copied into the repository. Along with refactoring the code and adding support for "classic" DFU devices, several modernizations were added:
- Colored logs and progress bar with
rich
- Using
logging
instead ofprint
for output messages - Consistent style with
black
and linting withpylint
Dependencies
Even though this package may appear pure Python, by relying on pyusb
we rely on libusb
being installed. See the pyusb
docs for more details on platform support.
User Guide
Install with pip
:
pip install pyfu-usb
List connected DFU devices:
pyfu-usb --list
Download a file to a DfuSe capable device, specifying a start address in hex:
pyfu-usb --download <filename> -a <start_address>
Download a file to a DFU capable device:
pyfu-usb --download <filename>
Use the --device
argument to specify the vid:pid
of the device in hex if multiple are connected. See the examples directory for more detailed examples.
Developer Guide
The Makefile
contains workflow helpers for the development environment.
To setup the virtual environment:
make setup
To activate the virtual environment:
source .venv/bin/activate
To run pre-commit hooks (style, linting):
make pre_commit
To run unit tests:
make test
To build the wheel:
make wheel
To view code coverage metrics:
make coverage
To delete generated files:
make clean
Contributing
Please see the documentation prior to contributing.
License
Licensed under the MIT license.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
Built Distribution
File details
Details for the file pyfu_usb-2.0.0-py3-none-any.whl
.
File metadata
- Download URL: pyfu_usb-2.0.0-py3-none-any.whl
- Upload date:
- Size: 15.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.9.20
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | fe6185234fc58cb5c4b7981ae4b88e65d019b7af5dade9f4b20ebb71d8a73917 |
|
MD5 | 0959b08e465e0db54aef355533dd0262 |
|
BLAKE2b-256 | 4cb42fa9d074aaa29541032d52c5e3015c71a1e1dd243de7289c13028c34ba79 |