English
Language : 

TMP89FM42 Datasheet, PDF (335/408 Pages) Toshiba Semiconductor – 8 Bit Microcontroller
TMP89FM42
21.5.2.2 How to write to the flash memory by using a support program (API) of BOOTROM
This section describes how to perform an erase and a write on the flash memory by using a support pro-
gram (API) of BOOTROM in MCU mode.
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.
.BTWrite
equ 0x1010
.BTEraseSec equ 0x1012
.BTEraseChip equ 0x1014
.BTGetRP equ 0x1016
.BTSetRP
equ 0x1018
main section code abs = 0xF000
; Initial setting
LD
(FLSCR1),0x50
LD
(FLSCR2),0xD5
; Sector erase process (API)
LD
A,0x0E
LD
C,0xD5
CALL
(.BTEraseSec)
; Write process
LD
HL,0xE000
LD
IY,0x0100
sLOOP1:
LD
C,0x00
LD
WA,HL
LD
E,(IY)
LD
(SP-),0xD5
CALL
(.BTWrite)
INC
IY
INC
HL
CMP
L,0x00
J
NZ,sLOOP1
; End process
LD
(FLSCR1),0x40
LD
(FLSCR2),0xD5
; Write data to the flash memory
; Sector Erase
; Chip Erase
; Check the status of the security program
; Configure the security program
; Set BAREA to "1" (note)
; Reflect the FLSCR1 setting
; Specify the area to be erased (0xE000 through 0xEFFF)
; Enable Code
; Execute sector erase
; Flash start address (address where data is written)
; RAM start address
; Address where data is written (bit 16)
; Address where data is written (bits 15 to 0)
; Data to be written
; Enable Code
; Write data to the flash memory (1 byte)
; Increment flash address
; Increment RAM address
; Finish 256-byte write?
; Return to sLOOP1 if the number of bytes is less than 256
; Set BAREA to "0"
Example: Whether the security program is enabled or disabled is checked. If it is disabled, it is enabled.
RA003
.BTWrite
equ 0x1010
.BTEraseSec equ 0x1012
.BTEraseChip equ 0x1014
.BTGetRP equ 0x1016
.BTSetRP
equ 0x1018
main section code abs = 0xF000
; Initial setting
LD
(FLSCR1),0x50
LD
(FLSCR2),0xD5
; Check the status of the security program
LD
A,0xD5
LD
C,0x00
CALL
(.BTGetRP)
CMP
A,0xFF
J
NZ,sSKIP
; Security program enable process (API)
LD
A,0xD5
LD
C,0x00
CALL
(.BTSetRP)
sSKIP
LD
(FLSCR1),0x40
; Write data to the flash memory
; Sector Erase
; Chip Erase
; Check the status of the security program
; Enable the security program
; Set BAREA to "1"
; Reflect the FLSCR1 setting
; Enable Code
; Set 0x00 (note 1)
; Check the status of the security program
; Go to sSKIP if the security program is enabled
; Enable Code
; Set 0x00 (note 1)
; Enable the security program
; Set BAREA to "0"
Page 321