Linux: Installing and Testing "dfu-util"
Contents
Getting Started
This article describes how to install and test the dfu-util tool on Linux. This utility provides an easy to use method for installing and updating MicroPython on compliant STM32 based microcontroller boards.
This article; Windows: Installing and Testing "dfu-util" Utility describes the Windows install.
DFU stands for Device Firmware Upgrade. It is a standardized USB protocol that allows firmware to be updated on a device without requiring special programming hardware. Key points:
- DFU enables flashing firmware over USB by putting the microcontroller into a special bootloader mode.
- The host computer uses tools like dfu-util to communicate with the device in DFU mode and transfer firmware.
- During DFU mode, the device halts normal operation and exposes memory programming interfaces over USB.
The dfu-util utility is the easy to use goto tool for flashing MicroPython firmware onto capable STM32 microcontrollers.
DFU Mode
All STM32 microcontrollers have a factory-programmed ROM-based bootloader that includes DFU support over USB, provided the chip has USB capabilities.
Placing the STM32 board into DFU mode
Ensure the board is unplugged from the computer. Hold down the BOOT0 button. If there is no BOOT0 button on the board then place a jumper wire across the 3V3 and BOOT0 pins. Plug the board into the computer's USB port. Release the BOOT0 button (or remove the jumper).
Linux doesn't require any drivers to be installed.
Installing the dfu-util Utility
In order to flash the MicroPython upgrade to the STM32 board we need a DFU file upload tool. There are a few available. Probably the easiest to use is the command line utility dfu-util.
Installing dfu-util on Linux is straightforward, as it is available in the standard repositories of all major distributions. These are the installation commands for the most popular Linux distributions. Enter into a Terminal:
- Ubuntu / Debian / Mint / Kali: Use the apt package manager:
- sudo apt-get install dfu-util
- Fedora / RHEL / CentOS / AlmaLinux: Use the dnf or yum package manager:
- sudo dnf install dfu-util
- Arch Linux / Manjaro: Use the pacman package manager:
- sudo pacman -S dfu-util
- OpenSUSE: Use the zypper package manager:
- sudo zypper install dfu-util
In a Terminal enter the following:
dfu-util --version
Returned:
dfu-util 0.11
Copyright 2005-2009 Weston Schmidt, Harald Welte and OpenMoko Inc.
Copyright 2010-2021 Tormod Volden and Stefan Schmidt
This program is Free Software and has ABSOLUTELY NO WARRANTY
Please report bugs to http://sourceforge.net/p/dfu-util/tickets/
Testing the dfu-util Installation
We attached a WeAct Studio STM32H743VIT6 board in DSU mode to a USB port on the laptop. Then we ran the the following in a Terminal:
- sudo dfu-util --list
This was returned:
Found DFU: [0483:df11] ver=0200, devnum=7, cfg=1, intf=0, path="3-9", alt=1, name="@Option Bytes /0x5200201C/01*128 e", serial="200364500000"
Found DFU: [0483:df11] ver=0200, devnum=7, cfg=1, intf=0, path="3-9", alt=0, name="@Internal Flash /0x08000000/16*128Kg", serial="200364500000"
The output shows two alternate settings (alt=0, alt=1), each corresponding to a different memory region on the STM32:
- alt=0: The Internal Flash. This is where the firmware/code usually goes (starting at memory address 0x08000000).
- alt=1: Option Bytes — used for configuration settings.
This is normal behavior for STM32 DFU mode. The bootloader exposes these interfaces so that different memory areas can be programmed without additional tools.
This board has external SPI flash memory that dfu-util didn't report on. That's not a problem because MicroPython firmware does find this additional flash and makes it available.
Microcontroller Bits and Pieces
Tools for Microcontrollers
dfu-util Utility
esptool Utility