Philips LPC2xxx Reflashing








Introduction

If you destroy the application in the internal Flash, you must use the Philips ISP loader to reload an Intel Hex file supplied on the ARM Stamp CD. A suitable baud rate is 38400 baud. To use this, ensure that port P0.14 is low. There is a link on the board that (when installed) enforces this. Then reset the board and use the Philips loader. Then close the Philips loader. Ensure that the P0.14 link is removed before resetting the board. Then connect using AIDE's PowerTerm or HyperTerm.

Once the Forth system is running again, you can use the word REFLASH ( -- ) to download a new binary image. Note that REFLASH only handles binary memory image files. These should transferred using the XModem 128 (checksum) protocol. If you are using AIDE with the file server enabled, a file selection dialog will appear automatically after you have executed REFLASH.

The LPC2xxx can only be reflashed from an application by a program running from RAM. A separate application built by a control file REPROG\REPROG*.CTL is used to do this. A binary image REPROG*.IMG is inserted into the application. When required, the code is copied into the internal RAM and executed from RAM.

Return is by rebooting the system. The contents of the internal RAM and Flash are destroyed, therefore any data that must be preserved should be saved externally to the chip. Alternatively, modify the reprogramming code to use the last sector to hold data to be preserved.




Code in main application

The layout of the RAM code is defined in the source file InitRp210x.fth. This defines the first cell as the Forth word to execute.

create reprog2xxx.img   \ -- addr
The start address of the reprogramming code

data-file %HwDir%/ReProg/REPROG210X.IMG equ /reprog     \ -- len
The length of the reprogramming code loaded into the dictionary.

data-file %HwDir%/ReProg/REPROG2134.IMG equ /reprog     \ -- len
The length of the reprogramming code loaded into the dictionary.

data-file %HwDir%/ReProg/REPROG213X.IMG equ /reprog     \ -- len
The length of the reprogramming code loaded into the dictionary.

$40000200 equ reprogrun \ -- addr
The run time address of the reprogramming code. This must match the start address of the CDATA section defined in REPROG210x.CTL, and that section must not overlap the run-time stacks and user area.

0 value ReflashDev      \ -- addr
Holds 0 or a UART base address. If set to 0, the reflash code will use the default device for the XModem transfer. Otherwise it will use the value here as the base address of the LPC2xxx UART to use. N.B. No effect on the MPE USB Stamp.

: callit        \ xt --
Load the reprogramming code and execute the xt.

: reflash       \ -- ; no exit
Copies the reprogramming code to the run-time address and executes it.

: CopyFlash     \ src dest len --
Copy the flash. The parameters are as for CMOVE. The process is repeated until there are no errors, and the system is then rebooted.