STM32F10xxx in-application programming using the USART.pdf

(275 KB) Pobierz
STM32F10xxx in-application programming using the USART
AN2557
Application note
STM32F10xxx in-application programming
using the USART
Introduction
An important requirement for most Flash-memory-based systems is the ability to update
firmware when 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 STM3210B-EVAL/STM3210E-EVAL board was used to
validate the IAP driver.
The STM32F10xxx 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).
USART is the example used in this application note.
June 2008
Rev 4
1/13
273858709.043.png
Contents
AN2557
Contents
1
IAP overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
1.1
Principle . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
1.2
IAP driver description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
2
Running the IAP driver . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
2.1
HyperTerminal configuration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
2.2
Executing the IAP driver . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
3
IAP driver menu . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
3.1
Download image to the internal Flash memory . . . . . . . . . . . . . . . . . . . . . 6
3.2
Execute the new program . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
3.3
Disabling the write protection . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
4
STM32F10xxx IAP implementation summary . . . . . . . . . . . . . . . . . . . . . 8
5
User program conditions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
6
IAP restrictions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
7
How to use the IAP driver . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
8
Revision history . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
2/13
273858709.044.png
AN2557
IAP overview
1
IAP overview
Medium-density devices are STM32F101xx and STM32F103xx microcontrollers where
the Flash memory density ranges between 32 and 128 Kbytes. Medium-density devices are
implemented in the STMicroelectronics STM3210B-EVAL evaluation board.
High-density devices are STM32F101xx and STM32F103xx microcontrollers where the
Flash memory density ranges between 256 and 512 Kbytes. High-density devices are
implemented in the STMicroelectronics STM3210E-EVAL evaluation board.
1.1
Principle
The IAP driver must be programmed from the Flash memory base address via the JTAG or
SWD interface using the development toolchain chosen by the user. This driver uses the
USART to load a binary file from the HyperTerminal to the STM32F10xxx’s internal Flash
memory, and then executes it.
1.2
IAP driver description
The IAP driver contains the following set of source files:
●
main.c : where the USART initialization and RCC configuration are set. A main menu is
then executed from the common.c file.
●
common.c : contains display functions and the main menu routine. The main menu
gives the options of loading a new binary file, executing the binary file already loaded
and disabling the write protection of the pages where the user loads his binary file (if
they are write-protected).
●
ymodem.c and download.c : they are used to receive the data from the HyperTerminal
application (using the YMODEM protocol (a) , and then to load them into the
STM32F10xxx’s internal RAM. In the event of a failure when receiving the data, the
“Failed to receive the file” error message is displayed. If the data is received
successfully, it is programmed into the internal Flash memory from the appropriate
address. A comparison between internal RAM contents and internal Flash memory
contents is performed to check the data integrity. If there is any data discrepancy, the
“Verification failed” error message is displayed. Other error messages are also
displayed when the image file size is greater than the allowed memory space and when
the user aborts the task.
●
STM32F10xxx firmware library
To specify the device (High-density or Medium-density) on which the software is to be run,
uncomment the relative definition line in the platform_config.h header file:
//#define USE_STM3210B_EVAL
//#define USE_STM3210E_EVAL
a. The Ymodem protocol sends data in 1024-byte blocks. An error check is performed in data blocks transmitted
to the STM32F10xxx’s internal RAM to compare the transmitted and received data. Blocks unsuccessfully
received are acknowledged with an NAK (Negative Acknowledgement). For more details about the Ymodem
protocol, refer to existing documentation.
3/13
273858709.045.png
 
IAP overview
AN2557
The user can choose to either go to the user application or execute the IAP for
reprogramming purposes by pressing a push-button connected to a pin.
●
Not pressing the push-button at reset switches to the user application
●
Pressing the push-button at reset displays the IAP main menu
Refer to Table 1.: STM32F10xxx IAP implementation for more details about the STM3210B-
EVAL/STM3210E-EVAL board push-button used to enter the IAP mode.
The IAP flowchart is represented in Figure 1 .
Figure 1. Flowchart of the IAP driver
Start
Push-button
is pressed?
No
Ye s
Initialize the STM32F10xxx USART
Display the IAP main menu
Download
Download or
switch or disable write-
protection?
Switch to user
program
Receive a binary file
No
Success
Disable the write-
protection
Ye s
Program the Flash
System reset
generation
Switch to user
program
No
All data programmed
successfully?
Ye s
User application
software
Display the name and size of
received file
Display the error message
"Verification failed"
Display the error
message "Failed to
receive the file"
ai14402b
4/13
273858709.001.png 273858709.002.png 273858709.003.png 273858709.004.png 273858709.005.png 273858709.006.png 273858709.007.png 273858709.008.png 273858709.009.png 273858709.010.png 273858709.011.png 273858709.012.png 273858709.013.png 273858709.014.png 273858709.015.png 273858709.016.png 273858709.017.png 273858709.018.png 273858709.019.png 273858709.020.png 273858709.021.png 273858709.022.png 273858709.023.png 273858709.024.png 273858709.025.png 273858709.026.png 273858709.027.png 273858709.028.png 273858709.029.png 273858709.030.png 273858709.031.png 273858709.032.png 273858709.033.png 273858709.034.png 273858709.035.png 273858709.036.png 273858709.037.png 273858709.038.png 273858709.039.png 273858709.040.png
AN2557
Running the IAP driver
2
Running the IAP driver
The IAP driver is programmed in Flash memory:
●
from page 0 to page 7 on Medium-density devices
●
from page 0 to page 3 on High-density devices
The user application occupies the remaining memory space.
2.1
HyperTerminal configuration
To use the IAP, the user must have a PC running HyperTerminal and configured as shown in
Figure 2 .
Figure 2. COM port properties
Note:
The baud rate value of 115200 bps is used as an example.
Care must be taken when selecting the system clock frequency. To guarantee successful
communication via the USART, the system clock frequency in the end application must be
such that a baud rate equal to 115200 bps can be generated.
2.2
Executing the IAP driver
As an example in this application note, pressing the pin connected to the push-button allows
the IAP driver to run.
By pressing the push-button at reset, the user can run the IAP driver to reprogram the
STM32F10xxx’s internal Flash memory. It is not mandatory to use the push-button; the user
can apply a signal to this pin with respect to its active level. Refer to Table 1: STM32F10xxx
IAP implementation on page 8 .
5/13
273858709.041.png 273858709.042.png
Zgłoś jeśli naruszono regulamin