Once IRT is configured as described in Enabling IRT, IRT firmware
execution starts immediately after device startup. IRT firmware execution ends when the
IRT firmware sets the DONE (IRTCTRL[2]) bit and there is a subsequent instruction fetch
from program memory that is NOT within an IRT region. Note that this includes an
attempted instruction fetch that has an error, such as an access privilege violation or
an uncorrectable bit error.
The IRT firmware may set the DONE bit and transfer control to the application code
(non-secure) while executing from an IRT region. Once the IRT code sets the DONE bit and
vectors to non-IRT space, PLCK will be set, and the regions will become
inaccessible.
Note: The IRT firmware must ensure that the application code is
not prefetched before the DONE bit is set. This requirement can be met by having at
least 32 bytes of separation between the end of the IRT firmware and the start of
the application firmware. This ensures that the start of the application code is
fetched after the DONE bit is set, disabling the IRT partition before the
application code can execute. The IRT firmware must ensure that the application
start address is in user program Flash and not within an IRT region.
Note: It is recommended to develop the IRT firmware separately
from the non-IRT firmware. To do this, create separate MPLAB projects for the IRT
and non-IRT firmware. The IRT project can then be added as a loadable in the non-IRT
project. The non-IRT project may also use a custom linker script to exclude the IRT
region as available Flash memory to avoid overlapping with IRT code.