Reprog17xx.ctl is the control file for the serial loader which reprograms the on-chip Flash memory. Because the on-chip Flash cannot be accessed during programming, and because the initial loader code may itself be replaced, the Flash programming code is copied into RAM for execution. The only exit from the code is a reset of the CPU to execute the newly Flashed program. All interrupts are disabled during reprogramming, and so polled serial drivers are used.
Access to the reprogramming software is defined in ReFlash.fth for the main system code and in this control file. The two files must match.
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.
#1700 equ LPCtype \ -- 1700
Define the LPC type, using 1700 as the generic type
#512 kb equ /LPCflash \ -- u
Max size of LPC17xx internal Flash
#96000000 equ system-speed \ -- Hz
System operating speed in HZ.
0 equ FullIAP? \ -- n
Set this equate non-zero to compile additional IAP routines.
See IAP17xxx.FTH for more details.
The stacks have already been set up by the calling program.
include %CpuDir%\CortexDef \ Cortex CPU equates include %CpuDir%\sfrLPC17xx \ Special function registers
l: CLD1 \ -- addr
Filled in later with the xt of ReprogFlash
. This
label marks the start of the RAM code area.
l: CLD_CopyFlash \ -- addr
Filled in later with the xt of CopyFlash
l: CLD_UART \ -- addr
Filled in later with 0 or UART base address to use.
If set to 0, the default is UART0. This allows the calling
application to select which UART to use.
l: CLD_clockspeed \ -- addr
Contains the clock speed to use. Filled in by the calling
application. Default is 96 MHz.
l: CLD_#FlSectors \ -- addr
Number of sectors in the flash. Default is 30 for 512k
devices.
: prog-speed \ -- hz
A macro to fetch the system clock speed from the entry table.
include %AppDir%\primitives \ Forth primitives from CODEARM.FTH include %AppDir%\MinSerLPC17xxp \ polled serial line driver include %AppDir%\delays \ software delays include %CpuDir%\Drivers\rebootLPC17xx \ reboot using watchdog
synonym ser-emit emit
A synonym required by the Xmodem code.
synonym ser-key? key?
A synonym required by the Xmodem code.
synonym ser-key key
A synonym required by the Xmodem code.
include %AppDir%\MinXmodemRx \ Xmodem receiver include %HwDir%\IAP17xx \ IAP access include %HwDir%\FlashTables \ Flash sector tables include %AppDir%\ReprogApp \ Application
make-turnkey ReprogFlash \ start up action
Define the action of the reprogramming code.
' CopyFlash CLD_CopyFlash !
Define the action of the Flash copy code.