AN2548 Freescale Semiconductor / Motorola, AN2548 Datasheet - Page 17

no-image

AN2548

Manufacturer Part Number
AN2548
Description
Serial Monitor Program for HCS12 MCUs
Manufacturer
Freescale Semiconductor / Motorola
Datasheet
Intelligent Writes
DoOnStack
Subroutine
MOTOROLA
I bit (or leave it set) such as during reset initialization routines and when the
user program is executing an interrupt service routine. Most such cases would
only block interrupts for a very short period of time so the user would not notice
that a command request was delayed. If a user program erroneously forgets to
clear the I bit or gets stuck in an interrupt service routine, commands through
the SCI0 serial link cannot be recognized. If this condition persisted, the user
would have to force a reset or cycle the power to the target system so it would
get a power-on reset and the monitor could regain control.
The intelligent write routine uses the address in IX register to decide what to
do. If the location is in nonvolatile memory, it checks to see if the location is
already correct (if so it skips the program operation and signals success). If the
nonvolatile memory location is different than desired, the routine checks to see
if it is erased (it is considered an error if you try to change a location in
nonvolatile memory that is not blank). If those checks pass, the routine does a
word program operation and finally checks FACCERR, FPVIOL, EACCERR
and EPVIOL to make sure there was no access or protection violation during
programming (it is considered an error if there was). If the location is not
nonvolatile memory, the routine simply writes the requested data to the
specified address. See
This unusual subroutine is used to program FLASH locations or perform erase
operations in the FLASH memory. You cannot execute a program out of the
FLASH array while a program or erase operation is being performed on the
same nonvolatile memory array. Because of this, the DoOnStack subroutine
(which is located in the FLASH), copies a small routine onto the stack (in RAM)
and then passes control to that subroutine on the stack. When the operation is
finished, an RTS returns control from the DoOnStack routine. This de-allocates
the space used by the small stack routine and then returns to the program
where DoOnStack was called.
Prior to calling DoOnStack, the main program started a FLASH operation by
writing data to a FLASH address and by writing an erase or word program
command code to the FCMD register. These steps can be performed by code
executing in the FLASH, but the final step of setting the CBEIF bit in FSTAT
must not be executed from within the FLASH. The FLASH is removed from the
memory map as soon as this write is executed.
The first line in DoOnStack saves the X index register on the stack. The
SpMoveLoop copies the SpSub routine onto the stack (with a series of PSHD
instructions) starting with the last word of SpSub and ending with the push of
the first word of SpSub onto the stack. At this point, the stack pointer points to
the location of the first word of the stacked SpSub routine. The TFR in the next
line copies the SP into the IX register so X points to the start of the copy of
Freescale Semiconductor, Inc.
For More Information On This Product,
Serial Monitor Program for HCS12 MCUs
Go to: www.freescale.com
WriteD2IX Subroutine
for details.
Software Detail
AN2548/D
17

Related parts for AN2548