6.4.2.2.2 BOOTSWP Instruction
The BOOTSWP instruction supports the LiveUpdate feature, by allowing code segments to be swapped between the active and inactive partitions without the need for a device Reset. A partition swap using the BOOTSWP instruction is referred to as a “soft swap”. To execute a BOOTSWP instruction, the Configuration bit FICD.NOBTSWP must be enabled. If a BOOTSWP instruction is attempted with NOBTSWP set, it will result in a two-cycle NOP instruction.
The BOOTSWP instruction must always be followed by a single-word instruction that writes the PC (e.g., GOTO W, CALL W or BRA W); the target of the instruction must be at an address within 32 Kbytes of the current address. Upon execution, the active and inactive partitions trade places, and the PC vectors to the location specified by the GOTO instruction in the newly active partition.
After the execution of the BOOTSWP instruction, the SFTSWP bit (NVMCON [11]) is set. This bit indicates to the firmware that the BOOTSWP instruction has been executed correctly and that the current active partition was entered via BOOTSWP rather than via a device Reset. Status bit P2ACTIV (NVMCON [10]) can also be read to verify which partition is active. It is important to note that after the partition swap, all peripherals and interrupts which were previously enabled remain enabled. Additionally, the RAM and stack maintain their states after the swap. It is highly recommended that applications using soft swaps jump to a routine that re-initializes the device to ensure the application continues to run as expected.
Different from the previous dsPIC33C core devices, the BOOTSWP operation no longer needs a software lock for it to work. An enabled BOOTSWP instruction must perform a validation operation on the inactive panel. This is achieved using the inactive panel BTSEQ value and is intended to prevent an inadvertent swap into an unprogrammed or corrupted panel because of erroneous code execution.