AN2400 Freescale Semiconductor / Motorola, AN2400 Datasheet - Page 30

no-image

AN2400

Manufacturer Part Number
AN2400
Description
HCS12 NVM Guidelines
Manufacturer
Freescale Semiconductor / Motorola
Datasheet
AN2400/D
Flash Erase-Verify
Command
30
FSTAT.byte = ACCERR|PVIOL;
if(FSTAT.bit.cbeif == 1)
{
}
else
{
}
if((FSTAT.byte & (ACCERR|PVIOL))!= 0)
*flashAddr = dummy;
FCMD.byte = MASS_ERASE;
FSTAT.byte = CBEIF;
{
}
while(FSTAT.bit.ccif != 1)
{
}
return(PASS);
return(FAIL);
return(FAIL);
The leftmost column contains C code (variable definitions in
Variable
assuming the register base address is $0000, and the rightmost column
contains comments.
Prerequisites: FCLKDIV must be configured correctly, the flash block 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 any page in the Flash block. 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 mass erase.
Registers: X contains word aligned Flash address within the Flash block to be
erased.
Stack Pointer
C function local variables: UINT16* flashAddr, 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 verify that a Flash block is
erased using the erase verify command.
The leftmost column contains C code (variable definitions in
Variable
Freescale Semiconductor, Inc.
For More Information On This Product,
Definitions), the centre column contains equivalent assembly code
Definitions), the centre column contains equivalent assembly code
Go to: www.freescale.com
MOVB
BRCLR $105,#$80,femef Check command buffer is empty
STD
MOVB
MOVB
BRSET $105,#$30,femef
BRCLR $105,#$40,*+0
CLRB
BRA
femef:
LDAB
femertn:
RTS
HCS12 NVM Guidelines
return address.
femertn
#$30,$105
0,X
#$41,$106
#$80,$105
#1
Clear error flags on selected block
Write any data to Flash block address
Write mass erase command
Write '1' to CBEIF to launch the command
Command failed if either error flag set
Wait for command to finish: this is
optional, but the Flash block cannot be
accessed until CCIF is set.
Successful, return
Fail, return
Appendix A ‘C’
Appendix A ‘C’
MOTOROLA

Related parts for AN2400