These tools are provided for applications which reserve part of the Flash for data. This code uses the IAP routines in IAP210x.fth.
N.B. An erase causes the whole of the sector at that address to be erased.
N.B. All writes to Flash must be from RAM as the Flash is unavailable at the time any part is being written.
Although some of these routines are not the most efficient for the LPC2000 series, they are designed to be easily expanded for future LPC2xxx parts with as yet unknown sector sizes.
Sector tables contain the number of sectors and starting offset of each sector, plus a dummy start address which enables the size of the last sector to be calculated. The boot block sector is not included in the table. The sector table is given by SecTab which is defined in FlashTables.fth.
: SectorN \ n -- addr len
Convert sector number (zero based) to base address and length
: FindSecN \ addr -- n
Find the sector number containing address addr. If
addr is outside the internal Flash range, n is set to -1.
: .src/dest \ src dest -- src dest
Display the addresses and contents of the source
and destination.
cell buffer: FlDest \ -- addr
Holds next destination address
cell buffer: #PrgErrs \ -- addr
Holds error count
: Prog512 \ src dest --
Program 512 bytes at src to dest. Increment error
counter on error.
: (EraseFlash) \ dest dlen --
Erase the flash for the given range. Note that complete
sectors in the range will be erased. If you want to write
partial sectors, check that they contain $FF in all bytes
before programming in order avoid having to erase them first.
: (ProgFlash) \ src dest len --
Write len bytes from memory at src to Flash at dest.
Note that the Flash is assumed to be erased, and that
no verification is performed except when each byte is
programmed. DEST is forced to a 512 byte boundary and
LEN is rounded up to the next 512 byte unit. SRC must be
on a word boundary.
: (VerifyFlash) \ src dest len --
Verify len bytes from memory at src to Flash at dest.
: ProgramFlash \ src dest len --
Using the RAM memory buffer at src, program the Flash at dest
with len bytes. The relevant Flash sectors are erased, the
Flash is programmed, and the result verified.
: ProgFlashQuiet \ src dest len --
As ProgramFlash, but with no console output.