Flashing the BlackPill on Linux using dfu-util

If you read my previous post you know I was facing many issues to flash the firmware on BlackPill using the SWD programmer (STLinkV2, JLink, etc).

Finally I got it working! Let check it out!

These are the step to get NuttX running on BlackPill:

Clone NuttX and Apps:

$ git clone https://github.com/apache/incubator-nuttx nuttx
$ git clone https://github.com/apache/incubator-nuttx-apps apps

Configure and Compile the NuttX:

$ cd nuttx
$ ./tools/configure.sh stm32f411-minimum:nsh
$ make menuconfig  (### This Command is Optional ###)
$ make

It will create the nuttx.bin file!

Then I remembered that the STM32F4 family has DFU support, using it I was able to flash the board:

1) Remove the USB cable
2) Press and Hold the buttons NRST and BOOT0
3) Connect the cable
4) Release the NRST button
5) Wait 1 second
6) Release the BOOT0

$ dmesg

[ 8203.223506] usb 1-2: new full-speed USB device number 38 using xhci_hcd
[ 8203.372844] usb 1-2: New USB device found, idVendor=0483, idProduct=df11, bcdDevice=22.00
[ 8203.372849] usb 1-2: New USB device strings: Mfr=1, Product=2, SerialNumber=3
[ 8203.372852] usb 1-2: Product: STM32  BOOTLOADER
[ 8203.372855] usb 1-2: Manufacturer: STMicroelectronics
[ 8203.372857] usb 1-2: SerialNumber: 3870XXXXXXXX


$ sudo apt install dfu-util

$ sudo dfu-util -l
dfu-util 0.9

Copyright 2005-2009 Weston Schmidt, Harald Welte and OpenMoko Inc.
Copyright 2010-2016 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/

Found DFU: [0483:df11] ver=2200, devnum=38, cfg=1, intf=0, path="1-2", alt=3, name="@Device Feature/0xFFFF0000/01*004 e", serial="387035953339"
Found DFU: [0483:df11] ver=2200, devnum=38, cfg=1, intf=0, path="1-2", alt=2, name="@OTP Memory /0x1FFF7800/01*512 e,01*016 e", serial="387035953339"
Found DFU: [0483:df11] ver=2200, devnum=38, cfg=1, intf=0, path="1-2", alt=1, name="@Option Bytes  /0x1FFFC000/01*016 e", serial="387035953339"
Found DFU: [0483:df11] ver=2200, devnum=38, cfg=1, intf=0, path="1-2", alt=0, name="@Internal Flash  /0x08000000/04*016Kg,01*064Kg,03*128Kg", serial="387035953339"


$ sudo dfu-util -d 0483:df11 -a 0 -s 0x08000000:leave -D nuttx.bin
dfu-util 0.9

Copyright 2005-2009 Weston Schmidt, Harald Welte and OpenMoko Inc.
Copyright 2010-2016 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/

dfu-util: Invalid DFU suffix signature
dfu-util: A valid DFU suffix will be required in a future dfu-util release!!!
Opening DFU capable USB device...
ID 0483:df11
Run-time device DFU version 011a
Claiming USB DFU Interface...
Setting Alternate Setting #0 ...
Determining device status: state = dfuERROR, status = 10
dfuERROR, clearing status
Determining device status: state = dfuIDLE, status = 0
dfuIDLE, continuing
DFU mode device DFU version 011a
Device returned transfer size 2048
DfuSe interface name: "Internal Flash  "
Downloading to address = 0x08000000, size = 53664
Download	[=========================] 100%        53664 bytes
Download done.
File downloaded successfully
Transitioning to dfuMANIFEST state

After flashing, connect the USB/Serial RXD to pin label A9 and the TXD to pin label A10.

Use the minicom or other serial console tool configured to 115200, you should see:

NuttShell (NSH) NuttX-9.0.0
nsh> ?
help usage:  help [-v] [<cmd>]

  .         cd        echo      kill      mount     set       uname     
  [         cp        exec      ls        mv        sleep     umount    
  ?         cmp       exit      mb        mw        source    unset     
  basename  dirname   false     mkdir     pwd       test      usleep    
  break     date      help      mkrd      rm        time      xd        
  cat       dd        hexdump   mh        rmdir     true      

Builtin Apps:
  sh   nsh  
nsh> 

2 thoughts on “Flashing the BlackPill on Linux using dfu-util

  1. Hi Patrick, thank you for your correction. Probably I tested it on U(S)ART2 but submitted the support to mainline to use U(S)ART1. I’ll fix it now, I appreciated your report!

Leave a comment