Flashing Firmware with Python
v0.4.0
The
tweliter
module is currently in beta.Overview
The tweliter
module is a Python module for flashing firmware to TWELITE devices.
It can be installed from PyPI, used as a command-line tool, or controlled from Python scripts.
Installation
Please install from PyPI.
pip install tweliter
If you use Poetry:
poetry add tweliter
Additional Notes for Linux
Setting udev
rules
You may need to grant permission via udev
.
- Create
/etc/udev/rules.d/99-ftdi.rules
# TWELITE R / MONOSTICK (FT232R / 0403:6001)
SUBSYSTEM=="usb", ATTRS{idVendor}=="0403", ATTRS{idProduct}=="6001", MODE="0666"
# TWELITE R2 / R3 (FT230X / 0403:6015)
SUBSYSTEM=="usb", ATTRS{idVendor}=="0403", ATTRS{idProduct}=="6015", MODE="0666"
- Reload udev rules
sudo udevadm control --reload-rules
sudo udevadm trigger
Also, while the TWELITE STAGE app requires unloading the ftdi_sio
module, when using Python you need to load it:
modprobe usbserial
modprobe ftdi_sio
Additional Notes for Windows
Applying libusb
driver
If you get errors like No backend available
, applying the libusb-win32
driver may resolve the issue. Install Zadig, select TWELITE R or MONOSTICK, and apply the libusb-win32
driver (not WinUSB
).
Reference: Installation — PyFtdi documentation (using the
pyftdi
module)
Examples
As a Command-Line Tool
Specify the binary file (.bin
) after tweliter
.
tweliter dir/SomeApp_BLUE.bin
Be careful not to confuse BLUE series with RED series.
Command-Line Options
tweliter -h
usage: tweliter [-h] [-u URL] [-g] [-v] [-s] [-m STARTMSG] [-r RETRY] file
Write TWELITE series firmware
positional arguments:
file Firmware file to write
options:
-h, --help show this help message and exit
-u URL, --url URL Optional device URL starting with ftdi://
-g, --gold Select GOLD series
-v, --verify Verify firmware after writing
-s, --safe Safe mode (GOLD series only, write slowly)
-m STARTMSG, --startmsg STARTMSG
Prefix for startup message to check
-r RETRY, --retry RETRY
Retry count in case of firmware writing failure
-u
--url
: Specify the device URL starting with ftdi://- If not specified, automatically selects the connected FTDI device if only one is found; prompts selection if multiple devices are connected.
-g
--gold
: Select GOLD series-v
--verify
: Verify firmware after writing-s
--safe
: (GOLD series only) Apply safe mode to slow down transfer speed-m
--startmsg
: After completion, capture and display startup messages starting with the specified text- Default is
!INF
- Default is
-r
--retry
: Number of retries on firmware writing failure- Default is 2 retries
From a Python Script
Use an instance of the Tweliter
class.
from pathlib import Path
from tweliter import Tweliter
file = Path('dir/SomeApp_BLUE.bin')
try:
with Tweliter(url="ftdi://:ft-x:/1") as liter:
# Get serial interface
ser = liter.get_serial_instance()
# Write firmware
liter.write(ser, file, verify=True)
# Show startup message
print(liter.get_startup_message_after(ser, "!INF"))
except IOError as e:
print(f"Cannot connect {e}")
except RuntimeError as e:
print(f"Failed to write {e}")