Windows: Installing and Testing "dfu-util"

Contents

Getting Started

This article describes how to install and test the dfu-util tool on Windows. This utility provides an easy to use method for installing and updating MicroPython on compliant STM32 based microcontroller boards.

This article; Linux: Installing and Testing "dfu-util" Utility describes the Linux 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).

The first time the STM32 board is connected in DFU mode, Windows may show a device with a warning sign (yellow exclamation mark) in Device Manager until the correct DFU driver is installed. Installing the WinUSB driver will remedy this.

Installing the WinUSB driver

From the Zadig website (https://zadig.akeo.ie/) install the Zadig application. This program is used to install generic USB Windows drivers. Using the Zadig application install the WinUSB driver.

Installing the WinUSB driver
Fig 1 - Installing the WinUSB driver.[1]

Disconnect the Pyboard from the computer then reconnect it again in DFU mode. This time the error should have disappeared. In Device Manager the STM32 board should now appear as an entry under Universal Serial Bus devices.

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.

  1. Download the latest dfu-util binaries file (e.g. we used dfu-util-0.11-binaries.tar.xz) from the dfu-util  homepage on SourceForge (https://dfu-util.sourceforge.net/).
  2. From the downloaded file extract the contents of the win64 folder to a chosen directory (e.g., C:\Program Files\dfu-util)
  3. Add the directory containing the dfu-util executable files to your system's PATH[2]. This allows you to run dfu-util from any directory in the command prompt.
  4. Enter the following into a Command Prompt:
    •  dfu-util --version  

dfu-util --version
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 STM32G474CEU6 Long board in DSU mode to a USB port on the laptop. Then we ran the the following in a Command Prompt:

  •  dfu-util --list  

This was returned:


Found DFU: [0483:df11] ver=0200, devnum=33, cfg=1, intf=0, path="2-9", alt=2, name="@OTP Memory   /0x1FFF7000/01*1024 e", serial="207838995143"
Found DFU: [0483:df11] ver=0200, devnum=33, cfg=1, intf=0, path="2-9", alt=1, name="@Option Bytes   /0x1FFF7800/01*048 e/0x1FFFF800/01*048 e", serial="207838995143"
Found DFU: [0483:df11] ver=0200, devnum=33, cfg=1, intf=0, path="2-9", alt=0, name="@Internal Flash   /0x08000000/256*02Kg", serial="207838995143"
          

The output shows three alternate settings (alt=0, alt=1, alt=2), each corresponding to a different memory region on the STM32:

  • alt=0: Internal Flash (/0x08000000/...) — used for flashing firmware.
  • alt=1: Option Bytes — used for configuration settings.
  • alt=2: OTP (One-Time Programmable) Memory — used for unique, non-rewritable data.

This is normal behavior for STM32 DFU mode. The bootloader exposes these interfaces so that different memory areas can be programmed without additional tools.