Blinky example with USB Device Firmware Upgrade (DFU) detach support for use with a no-offset bootloader
Dependencies: USBDevice_STM32F103 mbed-STM32F103C8T6 mbed
Fork of STM32F103C8T6_USBSerial by
Overview
This is an example application that runs on an STM32F103C8 "bluepill" board using a USB DFU bootloader. Once the bootloader and this application have been uploaded, it blinks just like any other blinky example. However, it also enumerates as a USB DFU runtime device, making it possible to re-enable the bootloader and upload new code over USB.
Installing the bootloader
A pre-built copy of the bootloader can be downloaded from GitHub.
Note that this bootloader primarily lives in the upper 8KiB of flash, so no application offset is needed (and the online compiler doesn't let you set an application offset, anyways).
See Zoltan Hudak's page for an example of using an Nucleo board to program a standalone board.
Uploading programs
Once the bootloader has been flashed, it will enumerate as a USB DFU device. dfu-util can be used to upload new programs to the board over USB. Note that on Windows, you may need to use a program such as Zadig to associate the WinUSB driver with the DFU interface.
You can check if the bootloader was uploaded successfully by seeing if dfu-util can find it using dfu-util -l
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 http://sourceforge.net/p/dfu-util/tickets/ dfu-util: Cannot open DFU device 0a5c:21e6 Found DFU: [1209:db42] ver=0100, devnum=25, cfg=1, intf=0, alt=0, name="DAPBoot DFU", serial="463112677267505055FF7206"
If you get something like "dfu-util: Cannot open DFU device 1209:db42", you may need to fix your permissions.
You can then upload your code over USB using:
dfu-util -d 1209:db42 -D STM32F103C8T6_USBDFU_NUCLEO_F103RB.bin
If all goes well, you should see something along the lines of
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 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 1209:db42 Run-time device DFU version 0110 Claiming USB DFU Interface... Setting Alternate Setting #0 ... 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% 29716 bytes Download done. state(7) = dfuMANIFEST, status(0) = No error condition is present dfu-util: unable to read DFU status after completion
The board should now blink once per second. If you run "dfu-util -l" again, it should now show the DFU runtime:
Found Runtime: [1234:0006] ver=0001, devnum=26, cfg=1, intf=0, alt=0, name="DFU", serial="0123456789"
Since it has a different USB VID/PID pair than the bootloader, if you ran into any permissions/drivers issues with the bootloader, you will need to solve them again for the application.
You can switch from the application to the back to bootloader by running
dfu-util -d 1234:0006 -e
dfu-util can also handle switching from the application to the bootloader and uploading code in one step:
dfu-util -d 1234:0006,1209:db42 -D your_firmware.bin