AN1796
APPLICATION NOTE
FIELD UPDATES FOR FLASH BASED ST7 APPLICATIONS
USING A PC COMM PORT
by Dennis Nolan
INTRODUCTION
Having the capability to update software in a microprocessor while the part remains in-circuit
has proven to be a very valuable feature of the new flash based micro controllers. Generally,
this has been accomplished via a special dedicated connector (something like a 10 pin
header) on the board which talks to a specialized programmer which, in turn, is controlled by
a PC. While the cost of these programmers has come down steadily, mostly due to increased
capabilities of the MCUs to virtually program themselves, they are still not very available to the
end user. The purpose of this note is to present practical software techniques which can be
built into virtually any application which includes an RS232 serial port to allow the flash based
ST7 MCU to be updated by any end user in the field.
The software presented here is a small (less than 500 bytes) boot loader which will allow for
the operating software in the ST7 to be replaced safely and reliable by use of a standard S-
Records format file which can either be emailed to an end user or made available for download
on a Web site. The PC side of the software update operation can easily be accomplished
using any of a number of terminal emulation programs. In this note the operation will be de-
scribed using the HyperTerminal program which is available to all Windows based PC users
since it comes bundled with the operating system.
Rev. 1.0
AN1796/1103
1/17
1
FIELD UPDATES FOR FLASH BASED ST7 APPLICATIONS USING A PC COMM PORT
1 FLASH MEMORY SECTORS
We will divide flash memory within the ST7 into two sectors by selection within the option byte
when the chip is programmed using a standard programmer. These sectors are referred to as
sector0 and sector1. The selection at program time is to decide what will be the size of
sector0, with the balance of the available memory going to sector1. The boot loader program
is less than 500 bytes in size so when programming the part select the smallest size for
sector0, which is 0.5K or 512 bytes. The only real distinction between sector0 and sector1 is
that sector0 is always write protected as it pertains to in application programming (under direct
ST7 program control). Sector0 can always be programmed by a dedicated programmer but it
cannot be written to by the MCU itself. Sector1 can be programmed either by a dedicated pro-
grammer or by software executing on the MCU itself. Sector0 is always the uppermost part of
memory so that it includes the reset and interrupt vectors (data that one always wants to be
write protected in order to make a self updateable system “bulletproof” in the face of catastro-
phes such as power failures in the middle of an update). Since the entire boot loader code and
the vectors reside in the write protected sector0 it is always possible to recover from a problem
during an update transfer by simply resetting the ST7, which will get us back to the boot
loader. The example program was written for the ST72264 which has 8K of flash so sector1
occupies from $E000 to $FDFF and sector0 from $FE00 to $FFFF.
2/17
2
FIELD UPDATES FOR FLASH BASED ST7 APPLICATIONS USING A PC COMM PORT
2 ABSOLUTE ADRESSES AND VECTORS
The example program was written for the ST72264 but, so long as the reset and interrupt
vector locations are the same, it can be executed without change on any ST7 regardless of the
size of its flash memory. This is because whatever the size of the flash, it will occupy the top
of the 0000 to $FFFF 64k possible addressing space of an ST7. We would thus always want
sector0 to occupy the top 0.5k, the space from $FE00 to $FFFF. We would also want the skip-
jump table (which is technically part of sector1) to always be located in the area just below
sector0 (also the top of sector1). In the example program this table occupies from $FDD0 to
$FDFF. Looking at the vector section at the end the program, the segment directive is used to
place the program pointer at each of the absolute memory locations for the various interrupt
vectors (and the reset vector) as described in the data sheet for the MCU. At each of these lo-
cations, a dc.w directive is used to place a 16 bit absolute address vector. In most micro con-
troller software we would be more accustomed to seeing a symbolic (and relocatable) address
reference used here and this points out an important concept that must be understood. After
we make our first version of the software application and send it “out into the world” by pro-
gramming it into the MCU with a standard programmer (sector0 and sector1), sector0 will
probably (if all goes according to plan) never be changed again, although sector1 can have
many revisions. When sector1 code is revised, the addresses of any or all of the interrupt
service routines associated with the interrupt vectors will move. Since sector0 and the vector
table will not change we need the address references in the vector table to be fixed. This lim-
itation would cause a severe loss of flexibility in the program if it were not for the use of the
skip-jump table located at $FDD0. This table has one entry for each interrupt vector. The table
consists of long jump (to cover the entire 64k space) instructions spaced every four bytes. Ac-
tually a long jump only takes up three bytes (one for the jp op code and two for the address)
but it’s easier to count by four.
Please note that, in the example program, all of the jumps are to the symbolic (and re-locat-
able) address “dummyisr” except for the one associated with the reset vector, which jumps to
“start”. This is because the example program does not make use of any interrupts. The pro-
gram must provide a mechanism to use any of the interrupts since we cannot “get at” the
vector table once we send our program out into the world. If we send out a version 1.0 of our
application which perhaps uses only the SCI interrupt and later decide to revise the program
and make use of the TIMERA interrupt we can do that by simply replacing the appropriate “jp
dummyisr” instruction in the skip-jump table with a jump to our TIMERA interrupt service rou-
tine. Since the skip-jump table resides in sector1 we are free to change the destination of the
jumps whenever we please although the absolute location of the jump instruction itself is fixed
so that it always agrees with sector0.
A careful examination of the reset vector reveals that it is treated specially. This vector does
use a symbolic (and re-locatable) address reference, “BANK0”. This is permissible because
3/17
FIELD UPDATES FOR FLASH BASED ST7 APPLICATIONS USING A PC COMM PORT
the destination is within sector0 and so the two will always stay “in sync”. At power-up reset we
always want to execute code in sector0 which is write protected and gives the decision point
to either read in an S-Records file to update sector1 or exit to execute normal code in sector1.
The exit to sector1 is done via a jump to absolute address $FDFC which is an entry in the skip-
jump table containing a re-directing jump to “start”.
Note:
Time delays within this program are implemented as simple countings loops. If the
main crystal clock is other than 8 Mhz then times will change accordingly.
4/17
FIELD UPDATES FOR FLASH BASED ST7 APPLICATIONS USING A PC COMM PORT
3 USING THE PROGRAM WITH HYPERTERMINAL
Configure HyperTerminal as follows:
1. Select FILES->PROPERTIES
2. Click the “CONNECT TO” tab
3. At “CONNECT USING” select DIRECT TO COM1, 2,3, or 4 as appropriate.
4. Click CONFIGURE and select
BITS PER SECOND: 9600
DATA BITS: 8
PARITY: none
STOP BITS: 1
FLOW CONTROL: none
5. Click the “SETTINGS” tab
6. Select EMULATION: ansi
7. Click ASCII SETUP and
– Uncheck all boxes except “Append Line Feeds to Incoming Line Ends”
– Set CHARACTER DELAY to 0 milliseconds
– Set LINE DELAY to 20 milliseconds
NOTE: A proper line delay setting is crucial to proper operation of the system. The ST7 needs
this time to store the data in an S-Records line before it is ready to receive the data from the
next line.
After HyperTerminal has been configured select FILE-> “SAVE AS” to save the program con-
figuration as a .HT file. Afterwards, just clicking the .HT file will open HyperTerminal with the
required settings.
Load the example program into the MCU, connect the target to the PC via RS232, and start up
HyperTerminal. After HyperTerminal has started, reset the MCU. After approximately five sec-
onds the MCU will transmit a single dollar sign ($) character which will appear on the PC mon-
itor. Be sure not to press any keys on the keyboard during the five second interval. If the $ is
not observed, double check the program configuration and the COMM port selection.
Once the $ character has been observed, reset the MCU and, within five seconds, press any
printable key on the keyboard. This Key will be echoed back to the monitor and will indicate
that the ST7 is now in a mode where it will wait indefinitely to receive an S-Records file update
for sector1. At this point, do the following with HyperTerminal:
1. Select TRANSFER->SEND TEXT FILE
2. Select FILES OF TYPE: all files (*.*)
5/17