AN3354
Application note
STM32F105/107 in-application programming using a USB host
An important requirement for most Flash-memory-based systems is the ability to update firmware installed in the end product. This ability is referred to as in-application programming (IAP). The purpose of this application note is to provide general guidelines for creating an IAP application.
The STM32F105/107 microcontroller can run user-specific firmware to perform IAP of the microcontroller-embedded Flash memory. This feature allows the use of any type of communication protocol for the reprogramming process (such as CAN, USART, USB). USB Host Mass storage is the example used in this application note.
This kind of IAP using USB Host is very interesting because it is a standalone IAP 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.
Table 1. |
Glossary |
|
|
Term |
Meaning |
|
|
|
CAN |
|
Controller area network |
|
|
|
IAP |
|
in-application programming |
|
|
|
ICP |
|
In-circuit programming |
|
|
|
JTAG |
|
Joint Test Action Group (JTAG) debugger |
|
|
|
SWD |
|
Serial wire debugging. |
|
|
|
USART |
|
Universal synchronous/asynchronous receiver/transmitter |
|
|
|
USB |
|
Universal serial bus |
|
|
|
March 2011 |
Doc ID 018530 Rev 1 |
1/10 |
www.st.com
IAP overview |
AN3354 |
|
|
To program the IAP driver to the Flash memory base address, use in-circuit programming (ICP) either with the JTAG/SWD interface using the development toolchain of your choice or the factory-embedded bootloader in the System memory area.
The IAP driver uses the USB Host to:
●Download a binary file (.bin) from a Flash disk (thumb drive) to the STM32F105/107's internal Flash memory.
●Upload all the STM32F105/107's internal Flash memory content into a binary file.
●Execute the user program.
Note: |
This application note is based on the STM32F105/107xx USB Host library. For more details |
|
about the USB Host stack and a mass storage demonstration, please refer to the |
|
STM32F105/107xx USB Host library user manual (UM1021). |
The IAP driver contains the following set of source files:
● main.c: contains the USB initialization data. The USB Host state machine is then executed if the user wants to enter IAP mode or the program will execute the user code.
● stm32f10x_it.c: contains the interrupt handlers for the application.
● command.c: contains the IAP commands (download, upload and jump commands).
● flash_layer.c: provides a medium layer access to the STM32 embedded Flash driver.
● usb_bsp.c: implements the board support package for the USB host library.
● usbh_usr.c: includes the USB host library user callbacks and LCD control data.
The user can choose to either go to the user application or execute the IAP for reprogramming purposes by pressing a Key-button connected to a pin:
●If the Key-button is not pressed at reset, the device switches to the user application.
●If the Key-button is pressed at reset, the device displays the IAP main menu.
Figure 1 illustrates the IAP flowchart.
2/10 |
Doc ID 018530 Rev 1 |
AN3354 |
IAP overview |
|
|
3TART
)S KEY PRESSED .O
9ES
%NTERT)!0RMODE
53"3(OST PROCESSCTO ENTER STATEAMACHINE
$ISPLAYYTHET)!0EMENUUUNDERN,#$
3ELECT COMMAND USINGIJOYSTICK
|
|
|
|
|
|
|
'O |
|
$OWNLOAD |
|
5PLOAD |
|
|||
|
|
|
|||||
3CAN THE &LASH |
|
4RANSMIT IMAGE OFIDEVICE |
|
'O TO 5SER !PPLICATION |
|||
$ISK CONTENTS |
|
INTERNALA&LASH&MEMORY |
|
CODE ATE X |
|||
|
|
|
|
|
|
|
|
"). IMAGE |
3UCCESS |
.O |
9ES |
9ES |
.O |
5SESJOYSTICKKTO SELECT |
$ISPLAYYERRORRMESSAGE |
IMAGEATO DOWNLOAD |
|
0ROGRAM THE |
|
&LASHAMEMORY |
|
,#$#ERROREMESSAGE |
|
|
%ND |
-3 6
Doc ID 018530 Rev 1 |
3/10 |