- Dec 18th. 2014
- By Thomas Shue
There are many ways to flash Sparky, but one of the easiest ways is via the USB connection. It requires no additional hardware, or soldering. All you need to do is short the Sparky board’s bootloader pins momentarily as you plug in the USB cable to your PC. This will run a Pre-installed routine that will place the Sparky Board in DFU mode, allowing you to push up a .DFU file the main processor directly.
First off, in order to load the CleanFlight to the Sparky Board, you need to start with a clean copy of the binary file (.hex file). I suggest you create your own .hex file directly from the Cleanflight Repository located at here. What you are looking for is a file called cleanflight_SPARKY.hex, it’s in the OBJ folder. Once you find the proper .hex file on git, just double click it to open it, and then click on the RAW button to open the binary in a new window stripped of all the HTML. Now, select all (ctrl+a) of the binary, then copy (ctrl+c) and paste it (ctrl+v) into a simple text editor such as new notepad on your PC. Then save this code as a .hex, it’s easy. Just choose, “Save As”, then type cleanflight_Sparky.hex and save it to a location on your PC that you can easily find. Now we are ready to convert the .hex to .dfu
For DFU conversion and uploading of the CleanFlight binary to the Sparky Boards processor, we will use a utility from STMicroelectronics (STM) called DfuSe Demonstrator. Located in the download package there are two separate programs, DfuFileMgr, and DfuSeDemo. DfuFileMgr converts the .hex to .dfu files, and DfuSeDemo loads the .dfu file to the main processor of the Sparky Board. In summary use DfuFileMgr.exe to convert the cleanflight_Sparky Binary file (.hex) file to a .dfu, and upload it directly to the STM32F303 processor on Sparky via USB cable with DfuSeDemo.
To insure you have a path for communication to your Sparky Board, you need to know where Sparky is actually installed. You can find this information via the Device Manager (Windows). However, there’s a problem, when the Sparky Board is when it’s plugged into a PC via the USB we won’t be able to talk to it. Sparky will most likely be seen as a standard USB device, or it will be placed in the system as a, “Other Devices” with no driver installed. Our goal is to load Sparky with CleanFlight and to control it via CleanFlight Configurator (the set up gui). To do that, we need Sparky to communicate via a COM port. In order for that to happen, we have to install a special STM driver that will create a, VCP for us to communicate with Sparky via the USB cable. VCP is a, Virtual Com Port, and in this case it’s the STM32 Virtual COM Port Driver that we will need to download from STMicroelectronic (STM).
STM happens to make not only the processor for Sparky (STM32F303), but the VCP drivers, the conversion as well as uploading software. Ahhh….but Houston we have a problem. The latest version of DfuSE 3.0.4 has a bug in the DfuFileMgr. It will not convert a .hex file, you will get an error “Unable to create image From this file…” (see image directly below). The latest version 3.0.4 had me scratching my head for a solid day. There seems to be a bug only in DfuFileMgr.exe (the .hex to .dfu converter) portion of the DfuSe Demonstrator package. The uploader, “DfuSeDemo.exe” works exactly as it should. I have a friend working on a Bug fix for 3.0.4, but for now you can grab an older version (3.0.2) from the link below, it’s safe, and it works. The reason I offer an alternative link vs an actual STM one is because they do not archive older versions of DfuSe Demonstrator for download . Have no fear. Again, the older version (3.0.2) works great.
Below are the links that you will need for for the Conversion & Uploading Software, as well as the VCP driver.
Link to DfuSE 3.0.4 http://www.st.com/web/en/catalog/tools/FM147/CL1794/SC961/SS1533/PF257916
Link to (safe older version) DfuSe 3.0.2 https://code.google.com/p/multipilot32/downloads/detail?name=DfuSe.rar&can=2&q=
Link to STM32 Virtual COM Port Driver http://www.st.com/web/catalog/tools/FM147/CL1794/SC961/SS1533/PF257938
Link to VCP driver here. http://www.st.com/web/en/catalog/tools/PF257938
To get started, download and install DfuSe, and the VCP driver. as I said before, inside of the DfuSe Demonstrator install package there are two utilities that are needed to convert and upload the CleanFlight_Sparky Binary. The first utility is the DfuFileMgr.exe on my machine it’s located in C:\Program Files (x86)\STMicroelectronics\Software\DfuSe v3.0.4\Bin. You can try the latest version of DfuFileMgr.exe, but if you get the error, remember to use 3.0.2 to avoid the error. Launch DfuFileMgr.exe, and a pop up window will appear with two options. Select the top option where it says, “I want to Generate a DFU file from s19, HEX or BIN files” and click ok. Now the main dialog box will appear. To the left it has the Device options, to the right on top, you will see a box called Images, and under that you have a box called, “Injection”. In the Injection box, click on the box that says, “S19 or Hex”. That is the browser button that allows you to navigate to the cleanflight_Sparky.hex that we made earlier, so we can convert it. Be sure to click the drop down menu (s19 Files(*.19) next to, or under the File name box. Now change s19 Files(*.19) it to hex Files (*.hex), or the cleanflight_SPARKY.hex file will not be visible to select. Now double click the .hex file to load it into DfuFileMgr. Now click on Generate at the bottom of the program window, this will pop up a, “Save As” window allowing you to save the cleanflight_SPARKY.hex as a cleanflight_SPARKY.dfu. Navigate where you want to save the .dfu file, and click save. This will convert the hex. to a .dfu file that can be directly pushed to the STM32F3 processor via the USB using DfuSeDemo.exe.
To upload the .dfu file we just created to the STM32F303 processor on the Sparky board, you need to run the DfuSeDemo.exe program. Mine is located at “C:\Program Files (x86)\STMicroelectronics\Software\DfuSe v3.0.4\Bin\DfuSeDemo.exe”. When you launch the program, it will automatically detect any device that is connected and in DFU mode. Most likely the Sparky will be the only device you have in DFU mode, but you can browse and select any DFU connected device via the, “Available DFU Devices” drop down menu.
In order for Sparky to be detected in DFU mode, you have to short the bootloader pads marked SBL located just behind the USB socket but before the STM32F3 processor (see top image). Use some tweezers to momentarily bridge (short) the bootloader pads (marked SBL) on the Sparky Board while you plug in the USB cable to the PC. I always watch my devices populate the system via the Device Manager. However as soon as Sparky connects in DFU mode, you will be able to find it in the DfuSeDemo’s “Available DFU Devices” drop down menu. Once you have the Sparky Board selected in the Connected DUF Devices drop down, next click, “Choose” and this will allow to browse and load the cleanflight_SPARKY.dfu file you created into DfuSeDemo for uploading. (see image directly above)
Now its time to upload the .dfu file to Sparky (see image directly above). You need to look for the button marked Upgrade, and click it. A warning box will pop up will pop up saying,”You are in DFU mode, and it’s impossible to to make sure the file is correct for this device”. Just click, “Yes” and cleanflight_Sparky.dfu will be pushed to the Sparky Board. You will see a green progress bar and it will tell you when the, “Upgrade is Successful”. Next you click. “Quit” and your new Sparky Board is loaded with Cleanflight. You will be able to talk to Cleanflight Configurator, and upload the latest firmware from there.
Below is a video showing the process. I hope you find this helpful, if you have any questions, you can post them here, but a better place is via IRC on the #cleanflight channel. Good luck and happy flying.