tweliter
module is a Python module for flashing firmware to TWELITE devices. It can be installed via PyPI and used as a command-line tool or controlled from Python scripts.This is the multi-page printable view of this section. Click here to print...
Flashing Firmware with Python
1 - Flashing Firmware with Python
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
Install it from PyPI:
pip install tweliter
With Poetry:
poetry add tweliter
Additional Notes for Linux
Setting udev
rules
You may need to grant permissions 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, the TWELITE STAGE app requires unloading the ftdi_sio
module, but 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 might resolve it. Install Zadig, select TWELITE R or MONOSTICK, and apply the libusb-win32
driver (not WinUSB
).
Reference: Installation — PyFtdi documentation (used by the
pyftdi
module)
Examples
As a Command-Line Tool
Specify a .bin
binary file after tweliter
.
tweliter dir/SomeApp_BLUE.bin
Command-Line Options
tweliter -h
usage: tweliter [-h] [-u URL] [-t TYPE] [-g] [-v] [-s] [-m STARTMSG] [-r RETRY] [--clear] [file]
Write TWELITE series firmware
positional arguments:
file Firmware file to write (not required with --clear)
options:
-h, --help show this help message and exit
-u URL, --url URL Optional device URL starting with ftdi://
-t TYPE, --type TYPE Device type(s), comma-separated. e.g., TWELITE_R3,MONOSTICK
-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
--clear Clear application NVM memory (GOLD only)
u
url
: You can specify the URL for identifying FTDI device- If not specified, automatically selected if one device is found; otherwise, a prompt is shown.
t
type
: Specify the type(s) to narrow the target device(s)- Comma-separated. e.g.,
TWELITE_R3,MONOSTICK
.
- Comma-separated. e.g.,
g
gold
: Selects the GOLD series.v
verify
: Verifies after flashing.s
safe
: Applies Safe Mode (slower transfer) for GOLD series only.m
startmsg
: Captures and shows startup messages following the specified text after flashing.- Default is
!INF
- Default is
r
retry
: Number of retries upon flashing failure.- Defaults to 2 retries.
clear
: (GOLD only) Clears non-volatile memory (such as settings).
From a Script
Use an instance of the Tweliter
class.
from pathlib import Path
from tweliter import Tweliter
file = Path("firmware/SomeApp_BLUE.bin")
try:
with Tweliter(
type_filter=Tweliter.Type.TWELITE_R2 | Tweliter.Type.TWELITE_R3
) 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"Couldn't connect {e}")
except RuntimeError as e:
print(f"Failed to write {e}")
2 - Flashing Firmware with Python
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
Install it from PyPI:
pip install tweliter
With Poetry:
poetry add tweliter
Additional Notes for Linux
udev
Rule Configuration
You may need to grant permissions using 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 the udev rules:
sudo udevadm control --reload-rules
sudo udevadm trigger
While the TWELITE STAGE App requires unloading the ftdi_sio
module, it needs to be loaded when using Python:
modprobe usbserial
modprobe ftdi_sio
Additional Notes for Windows
Applying the libusb
Driver
If you get an error like No backend available
, try applying the libusb-win32
driver using Zadig. Select the TWELITE R or MONOSTICK device and apply libusb-win32
(not WinUSB
).
Reference: Installation — PyFtdi documentation (uses the
pyftdi
module)
Examples
As a Command-Line Tool
Specify a .bin
binary file after tweliter
:
tweliter dir/SomeApp_BLUE.bin
tweliter
Command-Line Options
tweliter -h
usage: tweliter [-h] [--url URL] [--verify] [--startmsg STARTMSG]
[--retry RETRY]
file
Write TWELITE BLUE/RED firmware
positional arguments:
file Firmware file to write
options:
-h, --help show this help message and exit
--url URL Device URL starting with ftdi://
--verify Verify firmware after writing
--startmsg STARTMSG Prefix for startup message to check
--retry RETRY Retry count in case of firmware writing failure
url
: Specify the URL scheme for FTDI device- If omitted, it auto-selects if one device is found, or prompts selection if multiple
verify
: Verifies firmware after flashing if specifiedstartmsg
: Displays the startup message after the specified prefix- Default is
!INF MONO WIRELESS
- Default is
retry
: Retries the write process if it fails- Defaults to 2 retries
From a Python Script
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 MONO WIRELESS"))
except IOError as e:
print(f"Cannot connect {e}")
except RuntimeError as e:
print(f"Failed to write {e}")
3 - Flashing Firmware with Python
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
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}")