This is my twelfth week in AESTE, and also my last week here. Last week I manage to download file from localhost by TFTP. This week the task is PIC32 which is to swap the program flash memory after receive a valid new firmware.
From the Microchip Datasheet Section 52: Flash Memory, there are a Bit use to control the program flash — PFSWAP (Program Flash Swap Control Bit).
1 = Program Flash Bank 2 is mapped to the lower mapped region and program Flash Bank 1 is mapped to the upper mapped region
0 = Program Flash Bank 1 is mapped to the lower mapped region and program Flash Bank 2 is mapped to the upper mapped region
The PIC32 will set PFSWAP to ‘1’ after receive a valid new firmware. We will use the checksum to the new firmware after download from localhost. If the first byte of checksum is 0 (set by us before we upload the new firmware to localhost), it mean is a valid firmware. In order to set PFSWAP , the interrupt has to disable, unlock the sequence and set “WREN” to ‘0’. Remember the swap flash function should place at Section .cache_init according demo code from Microchip.
After testing this code, it has successfully swap the program flash immediately after download a valid firmware. Unfortunately, after I reset the PIC32 the program flash is swap back to initial (not running new firmware). This is because the PFSWAP will be ‘0’ after Power On Reset. Dr Shawn gave me a suggestion, which was to store two counter to PFM (Program Flash Memory) 1 and PFM 2. Every time a valid firmware is successfully downloaded, will increment PFM 1 counter by 1. At the startup, PIC32 will read from counter 1 and counter 2 and do a comparison. If the counter 1 is bigger than counter 2, it will perform the swap function. Yeah! Finally I have done this PIC32 live update by Ethernet.
“TELL ME, AND I WILL FORGET. SHOW ME, AND I MAY REMEMBER. INVOLVE ME, AND I WILL UNDERSTAND.” Confucius, circa 450BC
Along this 3 months internship, I really learn a LOT from here and I’m very appreciate Dr Shawn for giving me this chance to learn from him. The knowledge gain from here is very valuable and I will keep in mind every sentence that you had taught me. Thank You!
0 Comments