Dual partition, upgrade and FBTSEQ and configuration bits change.
I’m working with PIC24FJ256GB410 in a PIM module for the EXPLORER16 development board. I’m using MPLAB X IDE 5.05 for code development and XC16 (v1.35) as compliler.
My goal is to make an upgrade of the firmware “on the fly” using the communication serial port (Standard RS232). For this purpose I decided to divide the memory in half, using the dual partition feature. So the active partition, running the old firmware, will receive data from serial port and write it into the inactive partition. At the end it will check the integrity of it. If everything goes fine it will switch to the other one by rebooting and hence running the new firmware. I’m using the .hex files generated by the XC16 (v1.35) compiler as source.
So far so good, to simplify things I first tried to not use the serial port and directly clone the active partition into the inactive partition, then use the BOOTSWAP command to switch between partitions. For this purpose I am using some write flash functions created directly from the MCC Code generator plugin (v3.95.0) and its example code. This code provides the basic handling to write or read one word at a time and I use them to do the job. I successfully could clone the partition into the inactive partition and after a software swap (bootswap command) the new partition was active. Good.
However when I tried to reboot it always run the old partition not the new one. I checked there is another parameter to get this, the FTBSEQ. This parameter is used to decide which partition would be active after a boot. However seems I’m unable to write it properly. I’m also unable to write the configuration bits properly.
I read many many papers and applications notes but none of them explains well how to do this properly. I also found a software, called EZLIB which seems to do the job. However, I cannot use EZLIB as a whole as it is a library which creates a booloader which is not the purpose of my project and also weights too much for my application. Anyway I managed to extracted just the function that changes the FBSEQ but when I use it my system bricks.
So my question is how to write configuration bits and FBSEQ properly in the inactive partition and how to swap to the inactive partition successfully.
Any help or ideas in how to solve this? Any code sample different from EZLIB I can use?