
Example: Case in which a sector erase is performed on 0xE000 through 0xEFFF in the data area, and then data at
0x0100 through 0x01FF is written to 0xE000 through 0xE0FF in the data area.
If nonmaskable interrupts (INTSWI, INTUNDEF or INTWDT) occur, system clock reset is generated.
.BTWrite
equ 0x1010
; Write data to the flash memory
.BTEraseSec
equ 0x1012
; Sector Erase
.BTEraseChip equ 0x1014
; Chip Erase
.BTGetRP
equ 0x1016
; Check the status of the security program
.BTSetRP
equ 0x1018
; Configure the security program
cRAMStartAdd equ 0x0200
; RAM start address
main section code abs = 0xF000
; #### Transfer the program to RAM ####
LD
HL,cRAMStartAdd
LD
IX,sRAMprogStart
sRAMLOOP:
LD
A,(IX)
; Transfer the program from sRAMprogStart to
LD
(HL),A
; sRAMprogEnd to cRAMStartAdd.
INC
HL
INC
IX
CMP
IX,sRAMprogEnd
J
NZ,sRAMLOOP
; #### Set a nonmaskable interrupt vector inside the RAM area ####
LD
HL,0x01FC
; Set INTUNDEF and INTSWI interrupt vectors
LDW
(HL),sINTSWI - sRAMprogStart + cRAMStartAdd
LD
HL,0x01F8
; Set INTWDT interrupt vector
LDW
(HL),sINTWDT - sRAMprogStart + cRAMStartAdd
; #### Allocate RAM to the code area. Switch the vector area to RAM ####
LD
(SYSCR3),0x06
; Set RAREA and RVCTR to "1"
LD
(SYSCR4),0xD4
; Enable Code
; #### Allocate BOOTROM to the data/code area ####
LD
(FLSCR1),0x50
; Set BAREA to "1" (note)
LD
(FLSCR2),0xD5
; Reflect the FLSCR1 setting
; #### Sector erase process (API) ####
LD
A,0x0E
; Specify the area to be erased (0xE000 through 0xEFFF)
LD
C,0xD5
; Enable Code
CALL
(.BTEraseSec)
; Execute sector erase
; #### Write process ####
LD
HL,0xE000
; Flash start address (address where data is written)
LD
IY,0x0100
; RAM start address
sLOOP1:
LD
C,0x00
; Address where data is written (bit 16)
LD
WA,HL
; Address where data is written (bits 15 to 0)
LD
E,(IY)
; Data to be written
LD
(SP-),0xD5
; Enable Code
CALL
(.BTWrite)
; Write data to the flash memory (1 byte)
INC
IY
; Increment flash address
INC
HL
; Increment RAM address
CMP
L,0x00
; Finish 256-byte write?
J
NZ,sLOOP1
; Return to sLOOP1 if the number of bytes is less than 256
; #### End process ####
LD
(FLSCR1),0x40
; Set BAREA to "0"
LD
(FLSCR2),0xD5
TMP89FH46L
Page 339
RA005