cancel
Showing results for 
Search instead for 
Did you mean: 

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

Mnemocron
Associate III

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?

15 REPLIES 15

> Where are the source code files referenced in AN3990?

[en.stsw-stm32068.zip]\STM32F4-Discovery_FW_V1.1.0\Project\FW_upgrade\

https://www.st.com/content/st_com/en/products/embedded-software/mcus-embedded-software/stm32-embedded-software/stm32-standard-peripheral-library-expansion/stsw-stm32068.html

Note that it's based on the older SPL "library", not on Cube.

> Is it true that DFU only works with the microcontroller as a slave?

Yes.

JW

MSC != DFU

The MSC Host would permit you to read a DFU file off the media, and act on it. Read the docs on the .DFU format. Done it with DFU files on MicroSD cards here.

HAL Example of reading from USB Flash Stick

STM32Cube_FW_F4_V1.21.0\Projects\STM32F4-Discovery\Applications\FatFs\FatFs_USBDisk\readme.txt

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..

All examples I see for F3 are Device, not Host. Check if it supports Host/OTG operation at all.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..

> The MSC Host would permit you to read a DFU file off the media, and act on it.

What's the point, why would be the DFU file format more appropriate than e.g. intelhex?

JW

That I don't have to provide something in multiple formats? DFU also has a longitudinal CRC check, integrity can check before starting, and the binary data is easy to manage, addressed, no requirement to parse thousands of lines, with memory that my be sparse and out-of-order.

I could use a ZIP file if I wanted too, got code for that.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..

> That I don't have to provide something in multiple formats?

Yes that might be a point in certain cases. The rest is mostly fulfilled by the more common hex or sfile.

JW

Pavel A.
Evangelist III

With Keil, you can easily get a .bin file.

Enter the following in the project settings, post-make command:

$K\ARM\ARMCC\bin\fromelf.exe --bin --output=$L@L.bin !L

The output file is a plain binary image that begins from the starting flash address in project settings.

A good smart student in our lab did this sort of updater for F4 recently, based on that AN3990 example.

He also produced a python script that appends a header to that binary, with a CRC, version and so on (the updater discards this header after checking the update file).

Then it took me some time to convert it to a normal CubeMX project & USB host & fatfs from the Cube repo.

-- pa

Mnemocron
Associate III

> HAL Example of reading from USB Flash Stick

> STM32Cube_FW_F4_V1.21.0\Projects\STM32F4-Discovery\Applications\FatFs\FatFs_USBDisk\readme.txt

Where is this file? I am only able to find cloned stuff on some people's Github accounts.

In your CubeMX repository.

JW