Skip to main content
Visitor II
September 6, 2018
Question

Firmware Upgrade using USB Key - How to get started? (CubeMX / F4Discovery / DFU?)

  • September 6, 2018
  • 14 replies
  • 7614 views

Setup:

(custom hardware based on STM32f373 with a USB A female port)

STM32F407 Discovery Board with additional micro-B to A cable for the USB drive

Keil uVision 5 and STM32CubeMX

What I want to do:

Plug in a USB thumb drive into the USB port to upgrade the firmware on the STM32f373.

This way, the STM32 acts as a USB host and pulls the firmware from the USB drive. I don't want to use a computer to program the microcontroller (using DfuSe).

I am using the STM32F4 discovery with a micro-B to A cable to test this feature before moving to my custom hardware.

What I found out so far:

  • DFU mode is only accessible in device mode (not host mode) in STM32CubeMX
  • There is AN3990 "Upgrading STM32F4DISCOVERY board firmware using a USB key"

My questions:

  • Where are the source code files referenced in AN3990?
  • Is it true that DFU only works with the microcontroller as a slave?
  • Are there other examples that show how to do firmware upgrades from a USB drive?

    This topic has been closed for replies.

    14 replies

    Super User
    September 7, 2018

    Yes, a working example is a good way to start. But ST does not have such example ready. (however, the guy I wrote above, told me that adapting the AN3990 example was not too hard).

    If you don't find a suitable example on github and other free places.... someone can do it for you.

    Another option is to use Keil's USB drivers and examples. They are good, stable and well maintained. Not free.

    -- pa

    Visitor II
    November 14, 2018

    Hi I am also trying to upgrade the Firmware via USB Mass storage.

    I am using a STM32F407 DISCO to test .

    I have tried two Examples, one in the System Workbench example tree and the other from the Atollic Truestudio - Download. "STM32F4_Discovery_FW_Upgrade" I cannot get either to work.

    The Truestudio examples appears to connect to the USB device and starts the download (Blue LED ON)

    but I then get a Hard Fault. My image.BIN file runs fine if I Flash the device with it and I have also tried the supplied Re-Vectored example by ST. The Hard fault states .Attempt to execute an undefined instruction.

    However if I'm lucky enough to keep the debugger going I can see that the application appears to Open the file on the USB Drive but the Hardfault occurs as it Enters the FLASH_GetStatus() function.

    Just for information the USB FATFS on the same Drive works just fine .

    Anyone managed to try either of the two STM32F4_Discovery_FW_Upgrade examples successfully?

    Visitor II
    July 21, 2022

    @paulcatherall9​ @Mnemocron​ Did you managed to find the solution for this topic and get it to work?

    I will be appreciated for your helps. I am trying to firmware update for STM32F746 Custom board through USB stick for my final product (In the field programming for end users).

    MnemocronAuthor
    Visitor II
    July 23, 2022

    Sadly, no. The company I worked for abandoned the project.

    Visitor II
    August 8, 2022

    Hi, yes I use an USB drive to update the firmware on a board of mine with a STM32F407VGT device.

    I basically used the ST Cube examples found in :-STM324xG_EVAL\Applications\USB_Host\FWupgrade_Standalone

    It looks for a .bin file "DNLOAD.BIN" but this filename can be changed in "command.c"

    This was easily modified to change the Boot mode pin and LED's if you have any.

    e.g. in main.c HAL_GPIO_ReadPin(BOOTLOAD_GPIO_Port,BOOTLOAD_Pin)

    I relocated the button to a Jumper on my board.

    The Bootloader resides at :-

    FLASH (rx)   : ORIGIN = 0x8000000, LENGTH = 1024K

    The application firmware Linker .ld file is modified to :-

    FLASH (rx) : ORIGIN = 0x800C000, LENGTH = 1024K-64K

    It is advisable to Erase the device fully then Upload the bootloader via ST programming utility or IDE.

    Then you can test the bootloader using the USB drive or just program as per utility or IDE.

    There is no issue with Debugging the firmware.

    I also use an old DOS utility srec_cat.exe so you can merge both files (Bootloader & Firmware)

    into one file for easier programming, then later on if you need to upgrade the existing firmware it can be done with the USB stick.

    Some USB drives are not as reliable as others I have tried it with up to 32gb device.

    I have not had much look with the UPLOAD feature (copy existing image) but I don't require it.

    I hope that helps.