On-Chip Routines Source Code
aix
dec
bne
#1
1,sp
ReadData
;update pointer into FLASH (H:X)
;decrement ByteCount [E]
;loop until ByteCount=0
pula
pula
;deallocate [E]
;# of bad [D] -> A, and deallocate
;if Verify OK, A = $00
coma
add
pula
ais
;$00 -> $FF if verify OK
#1
#2
;$FF -> $00; C=1 if verify was OK
;Checksum [C] -> A, and deallocate
;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
lda
;save LADDR(hi) to stack [A]
LADDR+1
psha
pshx
;save LADDR(lo) to stack [B]
;calculate total # of bytes
; to be programmed
pula
sub
nega
inca
psha
;SLADDR (lo) -> A
LADDR+1
;SADDR(lo) - LADDR(lo) -> A
;LADDR(lo) - SADDR(lo) -> A
;change to 1-oriented vs 0-oriented
;[C] total remaining bytes to prog
; will decrement by LoopCOP on each
; pass through LoopPROG
StartProg:
On-Chip FLASH Programming Routines, Rev. 4
30
Freescale Semiconductor