ST AN1796 Application note

AN1796
APPLICATION NOTE
FIELD UPDATES FOR FLASH BASED ST7 APPLICATIONS
USING A PC COMM PORT
by Dennis Nolan
INTRODUCTION
The software presented here is a s mall (less th an 500 bytes) boo t loader whi ch will allow for the operating soft ware in th e S T7 to be replaced sa fely a nd relia ble by use of a standar d 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 w ill be de­scribed using the HyperTerminal pr ogram which i s availab le to all Windows based P C us ers 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. Th e selection at program time is to decide what will be the size of sector0, with the balance of the available mem ory going to sector1. The boot loader program is less than 500 bytes in size so w hen 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 pr ogrammed either by a dedicated pr o­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 prog ram w as written for t he ST 72264 w hich has 8K of flash s o 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 c an 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 t he exa mple program thi s table occupies from $F DD 0 to $FDFF. Looking at the vector section at the end the program, the segment directive is used to place the program pointer at eac h of the ab solute mem ory l ocations for the va rious inte rrupt vectors (and the reset vector) as described in the data sheet for the MCU. At each of these l o­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 s oftware applica tion and send it “out into the wor ld” by pro­gramming it into the MC U with a standard programmer (sector0 and sector1), sector0 will probably (if all goes according to plan) never be change d again, although se ctor1 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 th e program if it were not for the us e 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 s paced 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 ex ample program, all of the jum ps are to th e sy mbolic (a nd re-locat­able) address “dummyisr” except for the one associated with the reset vector, which jumps to “start”. This is because t he ex ample program doe s not m ake 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 j ump instr uction it self is fixed so that it always agrees with sector0.
A careful examination of the rese t vector r eveals that it is tr eated specially. This vector d oes use a symbolic (an d re- locatable ) addres s refer ence, “BANK 0”. T his is pe rm issible be cause
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 ex ecute normal code in sector1. The exit to sector1 is done via a j ump 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 PR OG RAM WITH HYPERTER MI NAL
Configure HyperTerminal as follows:
1. Select FILES->PROPERTIES
2. Click the “CONNECT T O” tab
3. At “CONNECT USING” sel ect D IR ECT TO COM1, 2,3, or 4 as appropriate.
4. Click CONFIGURE and se lect
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. Clic k 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 HyperT erminal 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 dol lar s i gn ($) c haracter 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 obs erved, r eset 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
FIELD UPDATES FOR FLASH BASED ST7 APPLICATIONS USING A PC COMM PORT
3. Navigate to the location of your .S19 S-Records file and double click it.
At this point you should see the S-Records data scroll past on the screen since the ST7 echoes the data back to the terminal as it is received and stored. Once the entire file has been received the boot loader will force a cold reset on the pr ocessor in order to safely lock-up the flash against any further writes. After the five second wait interval another $ character will be transmitted. The program section which transmits the $ is at the label “start” and is actually the entire s ecto r1 pro gram in t his e xamp le. A fter send ing t he $ , ex ecut ion f all s int o an e nd less loop at label “loop1”. As a suggested exercise, go to the example program source file and change the character that is transmitted from $ to some other printable character and then re­build the application. Now start up HyperTerminal and reset the ST7. After five seconds the $ character will appear (remember, we haven’t transmitted the new file yet). Now reset the MCU and, within five seconds, press any printable character on the keyboard. The character will be echoed back to the screen indicating that the ST7 is waiting for a file. Do the TRANSFER­>SEND TEXT FILE procedure and send the .s19 file for the example (now slightly modified). The file will scroll by on the screen and, after five seconds, whatever character you have re­placed the $ with will appear on the screen. CONGRAD ULATION S: You’ve used HyperT er­minal to do a field update of your application program via RS232.
6/17
Loading...
+ 11 hidden pages