AN2400 Freescale Semiconductor / Motorola, AN2400 Datasheet - Page 27

no-image

AN2400

Manufacturer Part Number
AN2400
Description
HCS12 NVM Guidelines
Manufacturer
Freescale Semiconductor / Motorola
Datasheet
Protected
Application Example
Flash Program and
Erase Routines
Flash Program
Command
MOTOROLA
The values loaded into each FPROT register during a reset sequence
determine the minimum level of protection: the application software can write
to the FPROT registers to increase (but not decrease) the amount of protected
Flash by clearing additional bits in the register. This feature is useful for
applications which are required to have the ability to reprogram the Flash. For
example, after each reset, start-up code would determine whether
reprogramming is required or not. If reprogramming is required, serial
communication software would download and run first a Flash erase routine
and then a Flash program routine followed by the new Flash code.
The reset vector, start-up code and communication software (bootloader)
should be protected so that reprogramming is always possible, even if the
reprogramming process is interrupted or corrupted in some way. The start-up
code and bootloader should be located in the higher protected area of Flash
Block 0 (page $3F) and address $FF0D is programmed to a suitable value to
permanently protect the required size. Note that this will protect the entire
vector table, so future code revisions will need to have interrupt service routines
located at constant, defined, addresses.
If reprogramming is not required, or when reprogramming has been completed,
the whole of the Flash could be protected by software clearing the FPOPEN bit
in each FPROT register. This will protect the main application from
unintentional corruption until the next reset.
On the other hand, if Flash reprogramming is never required, the FPOPEN bit
in each Flash protection byte should be programmed to ‘0’. This will give
permanent Flash protection.
The following code segment demonstrates how to program a number of words
of Flash using the pipelined programming command. For words that are on the
same Flash row, this will invoke Burst programming, reducing the programming
time by half.
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 words to be
programmed must be erased and not protected, the first Flash address must
be word aligned (bit 0 = 0). If the Flash program 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
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
Appendix A ‘C’
Flash Memory
AN2400/D
27

Related parts for AN2400