AN2400 Freescale Semiconductor / Motorola, AN2400 Datasheet - Page 29

no-image

AN2400

Manufacturer Part Number
AN2400
Description
HCS12 NVM Guidelines
Manufacturer
Freescale Semiconductor / Motorola
Datasheet
Flash Mass Erase
Command
MOTOROLA
FSTAT.byte = ACCERR|PVIOL;
if(FSTAT.bit.cbeif == 1)
{
}
else
{
}
if((FSTAT.byte & (ACCERR|PVIOL))!= 0)
*sectorAddr = dummy;
FCMD.byte = ERASE;
FSTAT.byte = CBEIF;
{
}
while(FSTAT.bit.ccif != 1)
{
}
return(PASS);
return(FAIL);
return(FAIL);
assuming the register base address is $0000, and the rightmost column
contains comments.
Prerequisites: FCLKDIV must be configured correctly, the sector to be erased
must not be protected, the Flash address must be word aligned (bit 0 = 0). If
the Flash address is in the range $8000 to $BFFF, the PPAGE register must
be written to select the desired page. If the microcontroller has multiple Flash
blocks, the ACCERR and PVIOL flags in all other blocks must be clear and the
BKSEL bits in the FCNFG register must be written to select the desired block
for sector erase.
Registers: X contains word aligned Flash address within the sector to be
erased.
Stack Pointer
C function local variables: UINT16* sectorAddr, UINT16 dummy.
On return, accumulator B contains 0 if the command executed correctly, or 1 if
the command failed.
The following code segment demonstrates how to erase an entire Flash block.
Note: A mass erase of the entire block is only possible when the FPLDIS,
FPHDIS and FOPEN bits are set, see section
Programming.
Freescale Semiconductor, Inc.
For More Information On This Product,
Go to: www.freescale.com
MOVB
BRCLR $105,#$80,fesef Check command buffer is empty
STD
MOVB
MOVB
BRSET $105,#$30,fesef Command failed if either error flag set
BRCLR $105,#$40,*+0
CLRB
BRA
fesef:
LDAB
fesertn:
RTS
HCS12 NVM Guidelines
return address.
fesertn
#$30,$105
0,X
#$40,$106
#$80,$105
#1
Clear error flags on selected block
Write any data to Flash sector address
Write sector erase command
Write '1' to CBEIF to launch the command
Wait for command to finish: this is
optional, but the Flash block cannot be
accessed until CCIF is set.
Successful, return
Fail, return
Parallel Flash Block
Flash Memory
AN2400/D
29

Related parts for AN2400