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
Mnemocron
Associate III

Thanks JW I found the repository.

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

This example code does not compile with my MDK v5 because of missing files and an aborted migration from v4 to v5.

Followup question

How do I apply the code from the FatFs_USBDisk example into my own project?

From what I see, the file structure is different (CubeMX vs. FatFs_USBDisk example).

Simply copying the main code from the FatFs_USBDisk example

/*##-1- Link the USB Host disk I/O driver ##################################*/
if(FATFS_LinkDriver(&USBH_Driver, USBDISKPath) == 0)
  {
 
// code goes on till the empty endless loop

into the /* USER CODE BEGIN 2 */ section of my newly generated Project from the CubeMX yields 4 errors of the type:

../Src/main.c(116): error:  #20: identifier "USBDISKPath" is undefined
    if(FATFS_LinkDriver(&USBH_Driver, USBDISKPath) == 0)
../Src/main.c(119): error:  #20: identifier "hUsbHostFS" is undefined
      USBH_Init(&
USB_Host, USBH_UserProcess, 0);
../Src/main.c(119): error:  #20: identifier "USBH_UserProcess" is undefined
      USBH_Init(&
USB_Host, USBH_UserProcess, 0);
../Src/main.c(134): error:  #20: identifier "Appli_state" is undefined
        switch(Appli_state)

Clearly I have never worked with USB before. For the start I would just like to replicate what the example does while understanding how it does it. Simple operations like creating and writing a file.

What are the easiest and the recommended steps to learn how to correctly implement a simple file operation on an STM32 connected to a USB drive using CubeMX and MDK-ARM v5 ?

On one hand I don't feel like reading a ton of specifications and application notes without a (working/applicable*) practical example. On the other hand I want to understand the important parts and do a proper implementation.

(* the current example from the CubeMX repository does not look applicable to me because the projects file structure and code differs from the code generated by the CubeMX)

Pavel A.
Evangelist III

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

paulcatherall9
Associate II

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?

MiladChalipa
Senior

@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).

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

paulcatherall9
Associate II

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.