5.6.1 Flash Partition Swapping
The Boot Sequence Number is used for determining the Active Partition at start-up and is encoded within the FBTSEQ Configuration register bits. Unlike most Configuration registers, which only utilize the lower 16 bits of the program memory, FBTSEQ is a 24-bit Configuration Word. The Boot Sequence Number (BSEQ) is a 12-bit value and is stored in FBTSEQ twice. The true value is stored in bits, FBTSEQ[11:0], and its complement is stored in bits, FBTSEQ[23:12]. At device Reset, the sequence numbers are read and the partition with the lowest sequence number becomes the Active Partition. If one of the Boot Sequence Numbers is invalid, the device will select the partition with the valid Boot Sequence Number, or default to Partition 1 if both sequence numbers are invalid. See Special Features for more information.
The BOOTSWP
instruction provides an alternative means
of swapping the Active and Inactive Partitions (soft swap) without the need for a device
Reset. The BOOTSWP
must always be followed by a GOTO
instruction. The BOOTSWP
instruction swaps the Active and Inactive
Partitions, and the PC vectors to the location specified by the GOTO
instruction in the newly Active Partition.
It is important to note that interrupts should temporarily be disabled while performing the soft swap sequence and that after the partition swap, all peripherals and interrupts which were enabled remain enabled. Additionally, the RAM and stack will maintain state after the switch. As a result, it is recommended that applications using soft swaps jump to a routine that will reinitialize the device in order to ensure the firmware runs as expected. The Configuration registers will have no effect during a soft swap.
For robustness of operation, in order to execute the
BOOTSWP
instruction, it is necessary to execute the NVM unlocking
sequence as follows:
- Write 0x55 to NVMKEY.
- Write 0xAA to NVMKEY.
- Execute the
BOOTSWP
instruction.
If the unlocking sequence is not performed, the BOOTSWP
instruction will be executed as a forced NOP
and a
GOTO
instruction, following the BOOTSWP
instruction, will be executed, causing the PC to jump to that location in the current
operating partition.
The SFTSWP and P2ACTIV bits in the NVMCON register are used to determine
a successful swap of the Active and Inactive Partitions, as well as which partition is
active. After the BOOTSWP
and GOTO
instructions, the
SFTSWP bit should be polled to verify the partition swap has occurred and then cleared
for the next panel swap event.