NXP LPC17xx IAP routines

The IAP is accessed by calling a Thumb routine at the IAPentry address with the address of a command block in R0 and the address of a status/result block (RAM) in R1. All the IAPxxx words return a 0 result on success. Note also that all interrupts are disabled for the duration of an IAP call, and therefore that ticker interrupts will not be serviced. In particular, the sector erase command may take 400ms, and a write of a 512 byte line may take 1ms.

0 equ FullIAP?          \ -- n
If this EQUate is set non-zero, additional IAP routines are compiled, e.g. to get the bootloader version number and the device part number. The definition here is only used if it has not been previously defined.

5 cells buffer: IAPcmd  \ -- addr ; max 5 cells
Command input buffer for IAP routines.

4 cells buffer: IAPres  \ -- addr ; max 4 cells
Result output buffer from IAP routines.

code IAP        \ *cmd *res --
The primitive to call the IAP routines. Interrupts are disabled for the duration of the IAP call.

: IAPprep       \ start end -- res
Prepare sectors for erase/write.

: IAPcopy       \ Rsrc Fdest len -- res
Copy/program len bytes from Rsrc in RAM to Fdest in Flash.

: IAPerase      \ start end -- res
Erase the inclusive range of sectors.

: IAPcheck      \ start end -- res
Blank check the inclusive range of sectors.

: IAPcompare    \ Rsrc Fdest len -- res
Compare len bytes from Rsrc in RAM to Fdest in Flash.

: IAPbootver    \ -- bootver
Return the 16 bit boot code version. The high byte is the major version and the low byte is the minor version.

: IAPpartno     \ -- part#
Return the NXP part number.

: IAPserialno   \ -- addr
Return a pointer to the 128 bit (4 cells) NXP LPC17xx serial number.