In addition to the dfuh-tool GUI executable, there is also the dfuh-cli executable. The CLI allows programming, verifying, and erasing devices from a command-line prompt or from within batch files or shell scripts. The exit code for the dfuh-cli executable is zero if the operation is successful, or non-zero if the operation encounters an error.
To use the dfuh-cli executable, provide one of the following flags:
| Flag | Description |
|---|---|
|
|
Programs the device with the specified file and exits. |
|
|
Verifies the programming of the device with the specified file and exits. |
|
|
Erases the specified program from the device and exits. |
|
|
Executes commands defined in the specified *.mtbdfu file (JSON format). |
|
|
Generates an *.mtbdfu file from the provided input arguments. |
Use the following flag to specify which device to use:
| Flag | Description |
|---|---|
|
|
Specifies the hardware ID. |
Host mode flags
When the DFU host communicates with a companion device through a bridge MCU, use the following flags to enable and configure Bridging mode.
| Flag | Description |
|---|---|
|
|
Enables DFU Host Bridging mode on the target main MCU (sends 0x20 command with mode byte 0x00 for-bridging before starting the normal DFU flow and sends 0x23 on exit). |
|
|
Sets the companion interface byte for the 0x20 command using the string values ("I2C", "UART") or a corresponding byte value. Default: 0x00. |
|
|
Sets the companion device address. For I2C, this is the slave address. Valid values: from 8 (0x08) to 120 (0x78. Required when the companion interface is I2C (0x01). Default: 0x00. |
.mtbdfu generation (--generate mtbdfu) flags
| Flag | Description |
|---|---|
|
|
(Optional) Sets the product ID as a parameter for the generated *.mtbdfu file. Default value – 01020304. |
|
|
(Optional) Sets the file version as a parameter for the generated *.mtbdfu file. Default value – 0x1. |
|
|
Sets the packet checksum type as a parameter for the generated *.mtbdfu file. Default value – 0x0. |
|
|
(Optional) Sets the application ID as a parameter for the generated *.mtbdfu file. Required only for legacy devices or devices with the DFU-MW-based bootloader. |
|
|
(Optional) Sets the application start address as a parameter for the generated *.mtbdfu file. Required only for legacy devices or devices with the DFU-MW-based bootloader. |
|
|
(Optional) Sets the application size as a parameter for the generated *.mtbdfu file. Required only for legacy devices or devices with the DFU MW based bootloader. |
--data-length <hex> |
(Optional) Sets the data packet length (in bytes) for Send Data
commands during |
|
|
(Optional) Sets the flash row length on the device. Default value – 0x200. |
|
|
(Optional) Sets the timeout for the response packet (milliseconds). Default value – 0x12c. |
|
|
Sets the start address for the *.bin file as a parameter for the generated *.mtbdfu file. |
|
|
Sets the firmware image file(s) for the generated *.mtbdfu file. |
In addition, you must provide the appropriate configuration values for one of the following protocols:
I2C flags
| Flag | Description |
|---|---|
|
|
Sets the address for I2C protocol. Valid values: from 8 (0x08) to 120 (0x78). |
|
|
Sets the speed for I2C protocol in kHz. Valid values: 50, 100, 400, 1000. |
|
|
(Optional) Enables PMBus mode for I2C communication. Requires: --i2c-address and --i2c-speed. Allowed --i2c-speed values: 100, 400, 1000 kHz. |
--i2c-use-pec |
(Optional) Uses PMBus PEC byte. Requires: --i2c-use-pmbus. |
--i2c-cmd-code <int> |
(Optional) Sets PMBus user-defined command code byte. Requires: --i2c-use-pmbus. Valid values: from 0 (0x0) to 255 (0xFF). Default value – 0xE0. |
--i2c-cmd-size <int> |
(Optional) Sets the number of data bytes for the PMBus command. Requires: --i2c-use-pmbus. Valid values: from 0 to 255. |
SPI flags
| Flag | Description |
|---|---|
|
|
Sets the clock speed for SPI protocol in MHz. |
|
|
Sets the mode for SPI protocol in binary. Valid values: 00, 01, 10, 11. The first byte defines CPHA, the second defines CPOL. |
|
|
Sets the SPI bit order to LSB-first. When not specified, MSB-first is used (default). |
UART flags
| Flag | Description |
|---|---|
|
|
Sets the baud rate for UART protocol. |
|
|
Sets the number of data bits for UART protocol. |
|
|
Sets the parity type for UART protocol. Valid strings are “None”, “Odd”, “Even”. |
|
|
Sets the stop bits for UART protocol. Valid values are 1, 1.5, 2. |
CAN-FD flags
| Flag | Description |
|---|---|
--canfd-bitrate-switch |
Enables the switching between default and data bitrates. |
--canfd-bitrate <int> |
Sets the nominal communication bitrate. Supported nominal bitrates: 125000, 250000, 500000, 1000000. |
--canfd-data-bitrate <int> |
Sets the data communication bitrate for CAN-FD protocol. Supported data bitrates: 2000000, 4000000, 8000000, 10000000. |
--canfd-output-frame-id <string> |
Sets the output frame ID for CAN-FD protocol. Valid values: from 0x0 to 0x1FFFFFFF. |
--canfd-input-frame-id <string> |
(Optional) Sets input frame ID for CAN-FD protocol. Valid values: from 0x0 to 0x1FFFFFFF. |
--canfd-ext-frame |
Enables the extended frame support for CAN-FD protocol. |
Command-line flags
The following flags change the overall functioning of the tool:
| Flag | Description |
|---|---|
|
|
Displays information about all valid command-line arguments and exits. |
|
|
Displays the version information and exits. |
|
|
Outputs debug messages during a DFU process. |
|
|
Outputs compatible hardware attached to the computer and exits. |
|
|
(Optional) Sets the timeout for the response packet (milliseconds). Default value – 0x12c. |
|
|
Sets the max transfer size (in bytes) for a packet. Supports hexadecimal values from 0x0 to 0x1007. Default value – 0x80 (128 bytes). |
CLI example
The following shows simple examples for using the dfuh-cli executable
Programming image via *.cyacd2 file
dfuh-cli.exe --program-device test_app.cyacd2 --i2c-address 8 --i2c-speed 100Generating and programming image via *.mtbdfu file and *.hex file
To generate an *.mtbdfu file (without metadata):
dfuh-cli.exe --generate-mtbdfu test_gen.mtbdfu --mtbdfu-data-file blinky_cm4_crc.hex --file-version 0x1 --product-id 01020304 --checksum-type 0x0
To generate an *.mtbdfu file for legacy devices (with metadata):
dfuh-cli.exe --generate-mtbdfu test_gen.mtbdfu --mtbdfu-data-file blinky_cm4_crc.hex --file-version 0x1 --product-id 01020304 --checksum-type 0x0 --application-id 0x1 --application-start 1005 --application-length fffc
To program a *.hex file through the *.mtbdfu file under UART (without metadata):
dfuh-cli --program-device test_app.hex --hwid COM5 --uart-baudrate 115200 --uart-databits 8 --uart-paritytype None --uart-stopbits 1 --file-version 0x1 --product-id 01020304 --checksum-type 0x0
To program a *.bin file through the *.mtbdfu file under I2C:
dfuh-cli --program-device test_app.bin --hwid <device> --i2c-address 0x12 --i2c-speed 400 --start-address 0x10000
To program a *.hex file through the *.mtbdfu file under I2C with PMBus mode:
dfuh-cli --program-device test_app.hex --hwid <device> --i2c-speed 100 --i2c-address 0x8 --i2c-use-pmbus --i2c-use-pec --i2c-cmd-code 0xAA
To execute or send commands through the *.mtbdfu file under SPI:
dfuh-cli --custom-command test.mtbdfu --hwid MiniProg4-0C0806F801071400 --spi-clockspeed 1.0 --spi-mode 0
To execute or send commands through the *.mtbdfu file under USB-HID:
dfuh-cli --custom-command test.mtbdfu --hwid PSoC_DFU_HID_De
To execute or send commands through the *.mtbdfu file under CAN-FD:
dfuh-cli --custom-command test.mtbdfu --hwid usb0 --canfd-bitrate 1000000 --canfd-data-bitrate 2000000 --canfd-output-frame-id 0x013 --canfd-bitrate-switch
To program a companion device through Bridging mode under I2C:
dfuh-cli --hwid KitProg3-14100A5A012D2400 --i2c-address 51 --i2c-speed 100 --program-device test-app.cyacd2 --bridging --companion-interface i2c --companion-address 52