AN2400 Freescale Semiconductor / Motorola, AN2400 Datasheet - Page 21

no-image

AN2400

Manufacturer Part Number
AN2400
Description
HCS12 NVM Guidelines
Manufacturer
Freescale Semiconductor / Motorola
Datasheet
Start-up Code
Constant Data
Unused Flash
MOTOROLA
Start-up code that is executed in the event of a reset must be permanently
accessible and therefore must be located in non-paged memory.
For constant data to be accessible to a function, both the function and the data
must be present in the memory map simultaneously. This is most easily
achieved by locating the constant data in non-paged memory, either in Flash
or EEPROM. If there is a large amount of constant data then sometimes an
alternative must be sought. There are a number of possibilities, for example the
constant data could be located in paged memory, with the functions that access
it located either in the same page or in non-paged memory.
If the data and the functions that access it are located on different pages, then
the data must be accessed through an intermediate function which handles the
page switching. This is to be avoided if at all possible due the inefficiency of this
method.
Surplus Flash memory that is not used by the application is often left in the
erased state ($FF). However, the state of unused Flash does sometimes have
an effect on the microcontroller behaviour. For example, a severe occurrence
of Electromagnetic Interference (EMI) may cause the microcontroller to behave
erratically. One possible effect is that the Program Counter may become
corrupted and then the CPU may read any address, including unused Flash for
the next instruction. This is called code-runaway. The value in the unused Flash
will determine what happens next.
If the Flash is erased, the $FF values will be interpreted as a LDS $FFFF
instruction. The CPU will continue reading increasing Flash addresses until it
reaches some code, and will then behave unpredictably. This situation is
normally undesirable and it is preferable to force a microcontroller reset as
soon as possible.
A simple solution is to fill unused Flash with $3F, the op-code for the SWI
instruction. As this is a single byte instruction, it will always be executed
correctly. The microcontroller will fetch the Software Interrupt vector and
execute the code at this address, as this interrupt cannot be masked. The code
in the interrupt service routine could shut down the microcontroller in an orderly
manner before forcing a reset. A reset can be forced by enabling the COP
watchdog and then writing an illegal value to the ARMCOP register.
If the Software Interrupt is required by the application, an alternative solution is
to use the ‘Unimplemented Instruction’ interrupt. As all page 1 op-codes are
valid, it is necessary to choose a page 2 op-code. Filling unused Flash with
$18A7 will cause an ‘Unimplemented Instruction’ interrupt if the CPU attempts
to execute this op-code. $18 is the pre-byte to select page 2, and $A7 is
unimplemented on page 2. If the $A7 is read first, this will be interpreted as a
NOP instruction and the next $18A7 will be read.
Freescale Semiconductor, Inc.
For More Information On This Product,
Go to: www.freescale.com
HCS12 NVM Guidelines
Flash Memory
AN2400/D
21

Related parts for AN2400