On-Chip FLASH Programming Routines, Rev. 4
32
Freescale Semiconductor
On-Chip Routines Source Code
;*********************************************************************
;* Step 7 and Step 8 are repeated until a value in location LADDR+1
;* reaches to zero.
;*********************************************************************
PRGstep7: pshx ;[2] temp flash pointer (lo) [F]
pshh ;[2] temp flash pointer (hi) [G]
;* Current stack frame
;* SP+1 [G] flash pointer (hi) temp store so H:X available
;* SP+2 [F] flash pointer (lo) temp store so H:X available
;* SP+3 [E] PCH (return addr hi)
;* SP+4 [D] PCL (return addr lo)
;* SP+5 [C] bytes remaining to prog..not counting this block
;* SP+6 [B] LADDR+1
;* SP+7 [A] LADDR
clrh ;[1] clear upper half of H:X
ldx RamPntrLo ;[3] get DATA array pointer (lo)
lda DATA,x ;[3] read data from a DATA array
pulh ;[2] restore flash pointer (hi) [G]
pulx ;[2] restore flash pointer (lo) [F]
sta ,x ;[.w] write data to Flash addr
; (Prog Algo Step 7)
;*********************************************************************
;* Compute Tprog based on bus speed
;* For slowest bus speeds (CPUSPD=4), Tprog = 38 bus cycles. For
;* other speeds, Tprog = 8 * CPUSPD + 5 bus cycles.
PRGstep8: ;delay for Tprog (Prog Algo Step 8)
lda CPUSPD ;[3]
cmp #4 ;[2] if CPUSPD=4 (bus = 1MHz),
beq PRGstep9 ;[3] Tprog=38 cycles
asla ;[1] for other cases
sub #9 ;[2] A = 2 x CPUSPD - 9
DelayPRG: nop ;[1] 1~ delay
dbnza DelayPRG ;[3] Tprog = 8 * CPUSPD + 5 cycles
PRGstep9: ; (Prog Algo Step 9)
aix #1 ;[2] point to next FLASH address
inc RamPntrLo ;[4] increment DATA array pointer
dec ByteCntr ;[4] decrement byte counter
bne PRGstep7 ;[3] loop until byte counter is = 0
rol 1,sp ;[5] ROL/ROR/SEI makes 12~ delay
ror 1,sp ;[5] to match delay to PRGstep10
sei ;[2]
PRGstep10: lda #mHVEN ;[2] clear PGM, leave HVEN=1
sta
FLCR
;[..w.]
(Prog Algo Step 10)
PRGstep11: lda CPUSPD ;[3] delay for time Tnvh
dbnza * ;[3*CPUSPD] (Prog Algo Step 11)
PRGstep12: clra ;[1] pattern to clear HVEN
sta FLCR ;[..w.] clear HVEN bit in FLCR