Project - Command line tool for STDFU Dll's (allows you to deploy DFU files to devices)

I just posted Command line tool for STDFU Dll’s (allows you to deploy DFU files to devices) on Codeshare. Feel free to discuss and make suggestions here.

6 Likes

Excellent contribution!

1 Like

Nice

@ untitled - That is a great contribution. I will be using that, thank you!

Excellent. I was just starting to embark on this exact same thing. From your Codeshare comment you mentioned integrating the NETMF runtime and your app. Could you elaborate on how you did it or publish the code?

I was looking at the following Codeshare Windows app and there’s a comment for a Hex to Dfu conversion routine which I thought would be useful to using STDFU for flashing the NETMF runtime and my app.

http://www.codeproject.com/Tips/540963/ST-Micro-electronics-Device-Firmware-Upgrade-DFU-D#_comments

In essence I need a one-stop app (command line or Windows) that will flash the Boot Loader, NETMF, and my app with minimal user involvement.

Update: I posted this before downloading your code. So it looks like you command lined the code from the Mark McLean’s Windows app referenced above. Did you figure out how to use the Hex to Dfu conversion to flash the NETMF and your app?

“I’ve developed a small tool that uploads the DFU, NETMF runtime…”

I could sure use that! Any chance you’ll be uploading it any time soon? I’m a one man operation about to attempt volume production. Ok, only 100 units, but still…

What can I do to help? Pound of coffee? Case of soda? Case of beer? ;D

Gregg, did you try out the codeshare entry? Link in the first post…

adding… you could possibly just wrap the codeshare with a winforms app to do everything… or wait for @ untitled’s next entry…

After many hours of experimenting and testing, I finally figured how to flash the Tiny Bootloader, NetMF, and my App all in one step. Here is how I did it. Note, this is for the Cerberus (STM32Fx).

From the DBU Tester, perform the following steps after setting your board in DFU flash mode.

  1. Click the Protocol Tab
  2. Check just Internal Flash 0 Mapping
    …Uncheck all other Area Mappings
  3. Click the Create from Map button
  4. Change Element 0 Length
    …Clear the Element 0 Length (it will go to 0)
    …Position Length cursor after the 0 (important)
    …Paste 1048576
  5. Select the Upload Operation
  6. Click the Go button
  7. Click the Save DFU File button

This will save the entire flash memory to your DFU file. Assuming you have deployed your app, everything will be there.

I then modified Mark McLean’s app to work with my DFU file by changing the following:

In the LoadDFU_File procedure comment out the following code:


                //if (FileData[10] != 1)
                //{
                //    throw new Exception("There should be exactly one target in the DFU file");
                //}

This is because there will actually be 4 files. The Alt Set 1, 2, 3 files will be included but will have no data.

In the DoFirmwareUpdate procedure, change the For loop to


                for (BlockNumber = 0; BlockNumber < NofBlocks; BlockNumber++)

The original code has a <= which is incorrect (but harmless).

I also added my own EraseSector procedure (note a Sector is the same as an Element)


        private const Int32 LastSector = 11;
        private void EraseSector(IntPtr hDevice, Int32 Sector)
        {
            if (Sector < LastSector) // don't show the last sector after flashing firmware
                UpdateProgress(((Sector + 1) * 100 / LastSector), "Initializing Sector " + Sector + " of " + (LastSector-1), false, false);

            EraseSector(hDevice, Sectors[Sector].dwStartAddress);
        }

Because I use the last sector for my app flash storage, I erase the first 11 sectors (0-10), do the firmware update, then erase the last sector (11). I do it this way because when I deploy I have data there and I want it cleared before the app starts for the first time. Note, you must erase the sectors containing the Bootloader, NetMF, and your App before flashing.

Hope this helps.

2 Likes

Sorry I wasn’t following this thread. I wrote my app for work. I need to pull our company name, etc. out of the tool. Currently it’s in a wizard format, with pictures and instructions for the few steps describing how to open our device, attach the USB cable, etc. It’s made for idiots.

Behind the scenes it simply uses MFDeploy.exe. I like BlueFire’s approach, but not the manual process to create the single-shot DFU file.

Currently my UI just executes these batch files to deplay the NETMF runtime and my app. I log their results to text files and read the response.

The first lists the devices on-screen and saves them to a file. The second uploads the runtime and app. I’m posting these until I get my full-blown UI polished and uploaded.

[ListDevices.bat]
@ echo off
del devices.txt
mfdeploy /list > devices.txt

[Deploy.bat]
@ echo off
Echo Starting… > deploy_log.txt
MFDeploy.exe ERASE /I:USB:"%1 %2 %3 %4 %5 %6" >> deploy_log.txt
MFDeploy.exe DEPLOY:ER_FLASH;ER_CONFIG /I:USB:"%1 %2 %3 %4 %5 %6" >> deploy_log.txt
MFDeploy.exe DEPLOY:YOURAPP.hex;ER_FLASH;ER_CONFIG /I:USB:"%1 %2 %3 %4 %5 %6" >> deploy_log.txt
Echo Done. >> deploy_log.txt

Current instructions…

  1. Change YOURAPP.hex in Deploy.bat to be the name of your app’s hex file.
  2. Copy these batch files int othe same folder you have your app hex, runtime flash and config files.
  3. Execute ListDevices.bat
  4. Execute Deploy.bat passing it the name of the device returned from ListDevices that you want to use.