AN2078
Application note
STR7 In-Application Programming using UART
Introduction
An important requirement for most Flash-based systems is the ability to update firmware
while the system is installed in the end product. This is referred to as In-Application
Programming (IAP).
STR7xx MCUs have the capability of running user-specific firmware to perform In
Application Programming of the MCU embedded Flash memory. This feature allows the use
of any type of communication protocol for the reprogramming process (for example, CAN,
UART, USB). In this application note, UART is used as an example.
This application note outlines general guidelines for creating an IAP application. The
STR7xx Eval Boards were used to validate the IAP driver.
Software is provided and is available on
http://www.st.com/mcu
January 2007
Rev 3
www.st.com
1/13
Contents
AN2078
Contents
1
IAP overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
1.1
1.2
Principle . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
IAP driver description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
2
Running the IAP driver . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
2.1
2.2
HyperTerminal configuration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
Triggering execution of the IAP driver . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
3
IAP driver menu . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
3.1
3.2
Download image to internal Flash . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
Execute the new program . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
4
5
6
7
8
STR7xx IAP implementation Summary . . . . . . . . . . . . . . . . . . . . . . . . . . 7
User program conditions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
IAP restrictions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
How to use the IAP driver . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
Revision history . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
2/13
AN2078
IAP overview
1
1.1
IAP overview
Principle
The IAP driver must be programmed by the user in the Flash base address (0x00) via JTAG
using a flasher toolset.
Using the UART, the IAP driver loads a binary file from the HyperTerminal to the STR7xx
internal Flash, and then jumps to execute it.
1.2
IAP driver description
The following table shows the IAP driver code size for each STR7xx MCU.
STR71x
7.2 Kbytes
STR73x
8.3 Kbytes
STR75x
5.8 Kbytes
The IAP driver contains a set of source files:
●
●
main.c:
where the UART initialization and PLL configuration are set. Then, a main
menu is executed from the
common.c
file.
common.c:
contains display functions and the main menu routine. The main menu
gives the choice between loading a new binary file and executing the binary file already
loaded.
ymodem.c
and
download.c:
they allow all data to be received from the HyperTerminal
application (using the YMODEM protocol
1)
), then loaded into STR7 internal RAM. In
the event of a failure in data receival, the ‘Failed to receive the file’ error message is
displayed on the HyperTerminal window. However, if successful, the data is then
programmed into internal Flash at the appropriate address. A comparison between
internal RAM and internal Flash contents is performed to check the data intergrity. If
there is any discrepency, the ‘Verification failed’ error message is displayed on
HyperTerminal window. Other error messages are also displayed when the image size
is higher than the allowed space memory and when there is an abort by the user.
●
Note:
1
Ymodem protocol sends data in 1024-byte blocks. A check for errors in data blocks
transmitted to the STR7xx Internal RAM is applied: A comparison between the transmitted
and received data is achieved. Blocks received unsuccessfully are acknowledged with a
NAK (Negative Acknowledgement). For more details about the Ymodem protocol, refer to
existing documentation.
●
Some STR7xx Standard library and Flash library files.
A pin connected to a push button is used to select between jumping to the user application
and executing the IAP for reprogramming purpose:
●
●
Push button is not pressed at reset: jump to the user application
Push button is pressed at reset: the IAP main menu is displayed
Figure 1
shows the IAP flowchart.
3/13
IAP overview
Figure 1.
FlowChart of the IAP Driver
Start
AN2078
Push button is
pressed?
Yes
No
Initialize the STR7 UART & PLL
Display the IAP Main Menu
Download
Download or
Jump?
Jump to User Program
Receive a binary file
No
Success
Yes
Program the internal Flash
Jump to the User Program
No
All data
programmed
successfully?
Yes
Display the error
message ‘Failed
to receive the
file’
Display the name and the size of
the received file
User Application
Software
Display the error message
‘Verfification failed’
4/13
AN2078
Running the IAP driver
2
Running the IAP driver
To run the IAP driver, STR7xx internal Flash must be hardware remapped at address 0x0.
Thus the IAP driver is programmed in Flash bank0 sector0 and the user application in the
remaining memory space in bank0.
2.1
HyperTerminal configuration
The IAP requires a PC running HyperTerminal with the following settings:
Figure 2.
COM Port Properties
Note:
A baud rate value of 115200 bps is used as an example.
Care should be taken when selecting the system clock frequency. Ensure that with the
system clock frequency used in your application, you are able to generate a baud rate equal
to 115200 bps in order to guarantee successful communication via UART.
2.2
Triggering execution of the IAP driver
In this application note, depending on the micro eval board, pins connected to push buttons
are used as an example, allowing execution of the IAP driver. By keeping the push button
pressed at reset, the user is able to run the IAP driver to reprogram the STR7xx internal
Flash.
It is not mandatory to use push buttons and the user can simply enter signals on these pins
with respect to their corrsponding active levels. Refer to the table in
Section 4 on page 7
for
the correct pins and their active levels for each MCU.
5/13
评论