
On-Chip FLASH Programming Routines, Rev. 4
30
Freescale Semiconductor
On-Chip Routines Source Code
aix #1 ;update pointer into FLASH (H:X)
dec 1,sp ;decrement ByteCount [E]
bne ReadData ;loop until ByteCount=0
pula ;deallocate [E]
pula ;# of bad [D] -> A, and deallocate
;if Verify OK, A = $00
coma ;$00 -> $FF if verify OK
add #1 ;$FF -> $00; C=1 if verify was OK
pula ;Checksum [C] -> A, and deallocate
ais #2 ;deallocate [A] and [B]
rts
;* RDVRRNG DONE ******************
;*********************************************************************
;* NAME: PRGRNGE
;* PURPOSE:
;* Program a FLASH address range which is maximum 32 bytes in the
;* same row. Bus frequency must be between 1.0MHz and 8.4MHz.
;* ENTRY CONDITIONS:
;* H:X contains a start address of the FLASH address range
;* LADDR:LADDR+1 contains a last address of the FLASH address range
;* DATA array contains the data to be programmed to the FLASH
;* (maximum 32 bytes)
;* CPUSPD contains a nearest integer of 4 x bus frequency (MHz)
;* EXIT CONDITIONS:
;* H:X contains a next FLASH address; I-bit set
;* SUBROUTINES CALLED:
;* VARIABLES READ: CPUSPD, LADDR:LADDR+1, DATA array
;* VARIABLES MODIFIED: LADDR(ByteCntr):LADDR+1(RamPntrLo)
;* The values are modified, but they are restored with original
;* values before exiting from this routine.
;* STACK SIZE: 9 bytes (including the call to this routine)
;* SIZE: 132 bytes
;* DESCRIPTION: EXECUTED OUT OF ROM
;* This routine can program the FLASH only in the same row.
;* Therefore, the total programing byte No. is maximum 32 bytes.
;* The COP is serviced in this routine. The first COP is serviced on
;* 59 bus cycles after this routine is called in the user software.
;* However, there could still be a COP time out if the COP is not
;* serviced within a proper period in user software.
;*********************************************************************
PRGRNGE:
sei ;set I bit to mask interrupts
lda LADDR
psha ;save LADDR(hi) to stack [A]
lda LADDR+1
psha ;save LADDR(lo) to stack [B]
pshx ;calculate total # of bytes
; to be programmed
pula ;SLADDR (lo) -> A
sub LADDR+1 ;SADDR(lo) - LADDR(lo) -> A
nega ;LADDR(lo) - SADDR(lo) -> A
inca ;change to 1-oriented vs 0-oriented
psha ;[C] total remaining bytes to prog
; will decrement by LoopCOP on each
; pass through LoopPROG
StartProg: