68HC08AZ32 (68HC908AZ60) And 68HC08GP32 In-Application FLASH Programming Toolkit
 
 

Introduction

This tool kit allows in-application programming of the on-chip FLASH block on the Motorola 68HC908AZ32 single chip microcontrollers. In-application programming is required when field updates are necessary of programs contained in the on-chip FLASH. The version here is for the 68HC908AZ32 but to convert it to be used with the 68HC908GP32 is reasonably easy. The tricky bit is getting the C compiler and linker to accommodate the strange memory map required and that does not change!

The initial programming of the device is carried out using the special monitor mode and tools from Motorola, HiWARE and Cosmic permit this. However in the field, the monitor mode is not suitable and the application already programmed into the device needs to be able to receive a new version of itself and program it into FLASH.

This requires some special tricks as the FLASH programming code itself must be run from the 68HC908GP32's internal RAM area. To allow this, the application must store an image of the program high up in the FLASH ROM and then copy the relevant FLASH programming parts into the RAM.

There is no direct support in any HC08 compiler/linker for these kinds of techniques so Hitex has developed a simple example that shows how it can be done.



The example program is in two parts:

(i) A main application, beginning at 0x8000. This is the user's real HC08 application.
(ii) An image of the FLASH programming routines at 0xFB81

The FLASH programmer is stored as an array which is copied to it run time address of 0xC0 in the 68HC908GP32's on-chip RAM. When FLASH programming is required, the application calls this routine and receives the new program via the serial interface.

A trick is used to build the FLASH programming routines. A separate program is built which locates the routines at their eventual run time address of 0xC0. This program is completely self-contained and is represented by a HEX file (FPROG.H86).

#	LINK COMMAND FILE FOR FLASH ROUTINES
#	Copyright (c) 1999 by HITEX UK LTD
#
+seg .text -b 0xc0 -n .text	# program start address
+seg .flash_code -b 0xc0 -n .text
+seg .const -a .text		# constants follow code
+seg .bsct -b 0x50 -ib	-m 0x48	# zero page start address
+seg .data -b 0xA8 -ib		# data start address
+seg .uflashdata -b 0xB0 -ib
+seg .iflashdata -b 0xb0 -ib
flash.o
c:/cx32/lib/libi.h08		# C library (if needed)
c:/cx32/lib/libm.h08		# machine library
+def __memory=@.bss		# symbol used by library
+def __stack=0x250		# stack pointer value

A simple QBASIC program is then used to convert it into a valid C array of 319 bytes in length.

10 '
20 '
30 '
40 PRINT "Converting FLASH programmer to const array"
50 '
99 '
100 OPEN "fprog.h86" FOR INPUT AS #1: OPEN "fprog.c" FOR OUTPUT AS #2: OPEN "fprog.d" FOR OUTPUT AS #3
120 size = 0
199 '
200 IF EOF(1) THEN GOTO 310
205 LINE INPUT #1, l$
210 ' get first byte of record
220 num = LEN(l$) - 12: ' PRINT "Record length = "; num
230 FOR i = 0 TO num STEP 2
250 byte$ = " 0x" + MID$(l$, 10 + i, 2) + ",": ' PRINT "byte = "; byte$
260 PRINT #3, byte$
290 size = size + 1: NEXT i
300 GOTO 200
310 '
320 CLOSE #3: OPEN "fprog.d" FOR INPUT AS #3
340 PRINT #2, "unsigned char const flashimage["; size; "] = {"
350 IF EOF(3) THEN GOTO 400
360 LINE INPUT #3, l$
370 PRINT #2, l$
390 GOTO 350
400 PRINT #2, " } ;"
410 CLOSE #2: OPEN "fprog.h" FOR OUTPUT AS #2
420 PRINT #2, "extern unsigned char const flashimage["; size; "] ;"
999 CLOSE


This array it then used by the application and is eventually copied back to 0xC0 when FLASH programming is required. In the package, the program MAIN.H86 is a simple application that includes the FPROG FLASH programming routines so that it can program new versions of itself into the FLASH.

void copy_func_to_ram(unsigned short func_ptr, unsigned short length) {

unsigned short i ;
unsigned short ta ;

ta = (unsigned short)&program_FLASH_row ;
for(i = 0 ; i < length ; i++) {

((unsigned char *) ta)[i] = *(unsigned char *) func_ptr++ ;
}
}

Under normal circumstances, the FLASH programming routines will not need alteration so all the user needs to do is include the array and the copy_func_to_ram() function.

The application includes the array representing the FLASH routines at 0xFB81.

# LINK COMMAND FILE FOR In-Application FLASH Programmer
# Copyright (c) 1999 Hitex (UK) Ltd.
#
+seg .text -b 0xFB00 -n .text # application program start address
+seg .flash_code -b 0xC0 -n .text -c # Place real flash program behind RAM, no real code though
+seg .const -a .text # constants follow code
+seg .bsct -b 0x50 -ib -m 0x48 # zero page start address
+seg .data -b 0xA0 -ib # data start address
+seg .uflashdata -b 0xB0 -ib # Data required by flash program
+seg .iflashdata -b 0xb0 -ib
crts.o # startup routine
main.o # application program
flash.o
fprog.o
fixed.o
c:/cx32/lib/libi.h08 # C library (if needed)
c:/cx32/lib/libm.h08 # machine library
+seg .const -b 0xffe0 # vectors start address
vector.o # interrupt vectors
+def __memory=@.bss # symbol used by library
+def __stack=0x250 # stack pointer value

To transmit a program to the FLASH, a simple Visual Basic application is included. This will send your Intel Hexfile to the HC08's UART (SCI) and blow it into the FLASH.



The program is written for the Cosmic compiler but it would be reasonably simple to port it to the Hiware one.

Note: We regret that as this was originally written for our own internal use, it is not an official Hitex product, we cannot provide our usual level of technical support, although we will try to answer queries via email! Hitex cannot be held resposible for the consequences arising from the deployment of this tool.

 
   
 
 
  View The README file for the programmer that explains the installation procedure  
  Download The Programmer Utility