AN2400 Freescale Semiconductor / Motorola, AN2400 Datasheet - Page 28

no-image

AN2400

Manufacturer Part Number
AN2400
Description
HCS12 NVM Guidelines
Manufacturer
Freescale Semiconductor / Motorola
Datasheet
AN2400/D
Flash Sector Erase
Command
28
FSTAT.byte = ACCERR|PVIOL;
while(wordsToDo != 0)
{
}
while(FSTAT.bit.ccif != 1)
{
}
}
if(FSTAT.bit.cbeif == 1)
{
}
return(PASS);
if((FSTAT.byte & (ACCERR|PVIOL))!= 0)
*progAddr++ = *dataAddr++;
FCMD.byte = PROG;
FSTAT.byte = CBEIF;
{
}
wordsToDo--;
return(FAIL);
written to select the desired block for programming. This code snippet will not
program over page boundaries.
Registers: X contains first word aligned Flash address to be programmed, Y
contains address of first word of data.
Stack Pointer
Stack Pointer + 2
C function local variables: UINT16* progAddr, UINT16* dataAddr,
UINT16 wordsToDo.
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 a sector (512 bytes,
or 1024 bytes on a 128k byte Flash block) of Flash.
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
Go to: www.freescale.com
HCS12 NVM Guidelines
MOVB
BRA
fepbt:
BRCLR $105,#$80,fepsc
LDD
STD
MOVB
MOVB
BRSET $105,#$30,fepf
DEC 0,SP
fepsc:
LDD 0,SP
BNE fepbt
BRCLR $105,#$40,*+0
CLRB
BRA
fepf:
LDAB
feprtn:
RTS
number of words to be programmed.
feprtn
return address.
#$30,$105
fepsc
2,Y+
2,X+
#$20,$106
#$80,$105
#1
Clear error flags on selected block
Check if any more words to be programmed
Check command buffer is empty
Write data word to Flash address,
increment addresses
Write program command
Write '1' to CBEIF to launch the command
Command failed if either error flag set
One word less to be programmed
Any more words to be programmed?
Wait for last command to finish: this is
optional, but the Flash block cannot be
accessed until CCIF is set.
Successful, return
Fail, return
Appendix A ‘C’
MOTOROLA

Related parts for AN2400