ST AN3990 APPLICATION NOTE

AN3990
Application note
Upgrading STM32F4DISCOVERY board firmware using a USB key

Introduction

An important requirement for most Flash memory-based systems is the ability to update the firmware installed in the end product. This document provides general guidelines for creating a firmware upgrade application based on the STM32F4DISCOVERY board.
The firmware upgrade using a USB Host is very advantageous because it is a standalone executed code in which the user does not need to use a host computer to perform the firmware upgrade. The user only needs a Flash disk to upgrade the target STM32 device.
Document contents
Section 1: Firmware upgrade overview contains an overview of the firmware upgrade
process and demonstrates how to run the firmware upgrade.
Section 2: How to use the firmware upgrade application describes the user program
and system requirements for the software and hardware.
Reference documents
STM32F4DISCOVERY STM32F4 high-performance discovery board (UM1472)
STM32F405xx, STM32F407xx, STM32F415xx and STM32F417xx advanced ARM-
based 32-bit MCUs reference manual (RM0090)
STM32F405xx STM32F407xx datasheet
STM32F415xx STM32F417xx datasheet
The above documents are available at www.st.com/stm32f4-discovery.
October 2011 Doc ID 022318 Rev 1 1/14
www.st.com
Firmware upgrade overview AN3990

1 Firmware upgrade overview

To program the firmware upgrade application to the Flash memory, use the STM32F4xx's embedded Bootloader or any in-system programming tool to easily reprogram this application.
The firmware upgrade application uses the USB Host to:
Download a binary file (.bin) from a Flash disk (thumb drive) to the STM32F4xx's
internal flash memory.
Upload all the STM32F4xx's internal Flash memory content into a binary file.
Execute the user program.
Note: This application note is based on the STM32 USB On-The-Go (OTG) Host and device
library. For more details about the USB Host stack and a mass storage demonstration, please refer to user manual (UM1021).

1.1 Implementing the firmware upgrade application

The firmware upgrade application contains the source files in Tab l e 1 .

Table 1. Source files

File Contents
Contains the USB initialization data. The USB Host state machine is then
main.c
executed if the user wants to execute the firmware upgrade application or the program will execute the user code
stm32f4xx_it.c
command.c
flash_if.c
usb_bsp.c
usbh_usr.c
system_stm32f4xx.c Contains the system clock configuration for STM32 F4xx devices
Contains the interrupt handlers for the application
Contains the firmware upgrade commands (DOWNLOAD, UPLOAD and JUMP commands)
Provides a medium layer access to the STM32 embedded Flash driver
Implements the board support package for the USB Host library
Includes the USB Host library user callbacks
2/14 Doc ID 022318 Rev 1
AN3990 Firmware upgrade overview
After the board reset and depending on the user button state:
1. User button pressed: The firmware upgrade application is executed.
2. User button not pressed: A test on the user application start address will be performed and one of the below processes is executed.
User vector table available: User application is executed.
User vector table not available: firmware upgrade application is executed.
During the firmware upgrade application execution, there is a continuous check on the user button pressed state time. Depending on the state time of the user button, one of the following processes is executed.

Table 2. User button state time control

User button state Time Process executed
Pressed
> 3 seconds
< 3 seconds Only the DOWNLOAD command is executed.
UPLOAD command will be executed immediately after completed execution of the DOWNLOAD command.
Note: The UPLOAD command condition verification is signaled by the blinking state of the blue
LED.
Doc ID 022318 Rev 1 3/14
Firmware upgrade overview AN3990
Figure 1 illustrates the Firmware upgrade application flowchart.

Figure 1. Upgrade application flowchart

Note: To execute the UPLOAD command the user button should be kept pressed 3s just after a
board reset, at firmware startup.
4/14 Doc ID 022318 Rev 1
AN3990 Firmware upgrade overview

1.2 LEDs status

The following section describes the LEDs behaviors during the firmware upgrade application execution:
Red LED blinks in infinite loop
Error (USB key disconnected, binary file not available or FATFS file system error).
Red LED blinks in infinite loop and Blue LED ON
Error (No available Flash memory size to load the binary file).
Red LED blinks in infinite loop, Blue LED ON and Orange LED ON
Flash erase error.
Blue LED ON
DOWNLOAD ongoing.
Blue LED ON and Orange LED ON
DOWNLOAD done; UPLOAD ongoing.
Blue LED blinks
UPLOAD condition verified and the user should release the user button.
Orange LED ON
DOWNLOAD done.
Orange LED ON, Blue LED ON and Red LED blinks in infinite loop
USB key read out protection ON.
Green LED ON and Orange LED OFF
DOWNLOAD done with success; and the MCU waiting until you press the user
button to execute the JUMP command.
Green LED ON and Orange LED ON
DOWNLOAD and UPLOAD done with success; and the MCU waiting until you
press the user button before execute the JUMP command.

1.3 Commands description

The firmware upgrade application commands are listed in Tab le 3 .

Table 3. Supported commands

Command Description
DOWNLOAD
UPLOAD
JUMP
Note: The maximum length for the file names (DOWNLOAD_FILENAME, UPLOAD_FILENAME)
should be 11 characters as the LFN feature on the FAT file system is a patent of Microsoft® Corporation and when enabling it on commercial products, a license from Microsoft may be required depending on the final destination.
Reads the defined image file “DOWNLOAD_FILENAME” from the thumb drive and writes it to the embedded Flash memory.
Reads the entire embedded Flash memory and saves the contents to the defined file name “UPLOAD_FILENAME” in the thumb drive.
Executes the user code at the defined user application start address “APPLICATION_ADDRESS”.
Doc ID 022318 Rev 1 5/14
Loading...
+ 9 hidden pages