September 23, 2016

A DFU Bootloader

DFU is "Device Firmware Update" and is some kind of standard.

If you want a USB DFU bootloader, you should look at the work by Roger Clark, who has worked over the Maple loader so it now has an 8K footprint.

You use dfu-util to communicate with this bootloader. See the linux page in the STM32duino wiki Note that on my Fedora system, this is easy (maybe) -- dfu-util is available as a package, albeit version 0.8 (version 0.9 is available online).
dfu-programmer.x86_64                    0.6.2-5.fc24                   fedora  
dfu-util.x86_64                          0.8-3.fc24                     fedora  
libdfu.x86_64                            0.7.2-3.fc24                   updates 
libdfu-devel.x86_64                      0.7.2-3.fc24                   updates 
The package "dfu-programmer" is for Atmel chips and can be ignored.
dnf install dfu-util
This has a man page. I plug in my device and see entries in the /var/log/messages file:
Sep 23 21:28:21 trona kernel: usb 3-2.1: new full-speed USB device number 16 using xhci_hcd
Sep 23 21:28:22 trona kernel: usb 3-2.1: New USB device found, idVendor=1eaf, idProduct=0003
Sep 23 21:28:22 trona kernel: usb 3-2.1: New USB device strings: Mfr=1, Product=2, SerialNumber=3
Sep 23 21:28:22 trona kernel: usb 3-2.1: Product: Maple 003
Sep 23 21:28:22 trona kernel: usb 3-2.1: Manufacturer: LeafLabs
Sep 23 21:28:22 trona kernel: usb 3-2.1: SerialNumber: LLM 003
Then:
dfu-util -l
Found DFU: [1eaf:0003] ver=0201, devnum=16, cfg=1, intf=0, alt=2, name="STM32duino bootloader v1.0  Upload to Flash 0x8002000", serial="LLM 003"
Found DFU: [1eaf:0003] ver=0201, devnum=16, cfg=1, intf=0, alt=1, name="STM32duino bootloader v1.0  Upload to Flash 0x8005000", serial="LLM 003"
Found DFU: [1eaf:0003] ver=0201, devnum=16, cfg=1, intf=0, alt=0, name="STM32duino bootloader v1.0  ERROR. Upload to RAM not supported.", serial="LLM 003"
So, as an experiment to see if this works at all, I flash an image:
[root@trona STM32]# dfu-util -a 2 -D maple_mini_boot20.bin 
dfu-util 0.8

Copyright 2005-2009 Weston Schmidt, Harald Welte and OpenMoko Inc.
Copyright 2010-2014 Tormod Volden and Stefan Schmidt
This program is Free Software and has ABSOLUTELY NO WARRANTY
Please report bugs to [email protected]

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 1eaf:0003
Run-time device DFU version 0110
Claiming USB DFU Interface...
Setting Alternate Setting #2 ...
Determining device status: state = dfuIDLE, status = 0
dfuIDLE, continuing
DFU mode device DFU version 0110
Device returned transfer size 1024
Copying data from PC to DFU device
Download	[=========================] 100%         7036 bytes
Download done.
state(8) = dfuMANIFEST-WAIT-RESET, status(0) = No error condition is present
Done!
This certainly seemed to work. This is using "-a 2", which puts the image at 0x08002000, and it belongs at 0x08000000, so I don't expect any good out of this. At any rate the device when plugged and unplugged still runs the maple boot loader, but who knows if it is running the copy at 0 in flash or the one at offset 0x2000.

The big question to me now is how to know if the boot loader runs or my application.


Feedback? Questions? Drop me a line!

Tom's Computer Info / [email protected]