• AVR Freaks

Hot!Live Update on PIC32MZ works only the first time

Author
Johnny0099
Super Member
  • Total Posts : 156
  • Reward points : 0
  • Joined: 2015/06/20 00:33:20
  • Location: 0
  • Status: offline
2018/04/02 15:55:32 (permalink)
0

Live Update on PIC32MZ works only the first time

I've implemented an application that burns the HEX file to the opposite flash panel and finally writes the Flash ID according to the Microchip Examples. Here it is the function:
 
uint32_t flashId = APP_FWUPD_LowerFlashIdGet();
APP_FWUPD_UpdateFlashId(flashId + 1);

uint32_t APP_FWUPD_LowerFlashIdGet(void)
{
      APP_FWUPD_FLASH_ID_DATA *lowerFlashId = APP_FWUPD_LOWER_FLASH_ID_READ;
      return (lowerFlashId->flashId);
}

void APP_FWUPD_UpdateFlashId(uint32_t flashId)
{
    APP_FWUPD_FLASH_ID_DATA flashIdObj = { 0 };

    /* Increment opposite flash id by 1 to be ahead of the current running panels flash ID*/
    flashIdObj.flashId = flashId;
    flashIdObj.checksumStart = FLASH_ID_CHECKSUM_START;
    flashIdObj.checksumEnd = FLASH_ID_CHECKSUM_END;

    _APP_FWUPD_NVMQuadWordWrite((void *)(KVA0_TO_KVA1(LOWER_FLASH_ID_BASE_ADDRESS)), (uint32_t *)&flashIdObj);
}

 
I'm using the Live Update Bootloader Switcher, and the update only works the firts time. The second time using the Live Update from the application, the switcher is not able to switch the panel. The IDs are correct, the upper panel has an ID higher than the one in the lower panel.
 
This is the function that switches the panels:
 
void __longcall__ __attribute__ ((section (".cache_init"))) SwapFlashPanels()
{
    PLIB_NVM_MemoryModifyInhibit(NVM_ID_0);
    PLIB_NVM_FlashWriteKeySequence(NVM_ID_0, NVM_PROGRAM_UNLOCK_KEY1);
    PLIB_NVM_FlashWriteKeySequence(NVM_ID_0, NVM_PROGRAM_UNLOCK_KEY2);
    PLIB_NVM_ProgramFlashBank2LowerRegion(NVM_ID_0);
}

 
And the code that operates the switch is the following:
 
static void Enter_Application(void)
{
    void (*fptr)(void);

    /* Set default to APP_RESET_ADDRESS */
    fptr = (void (*)(void))APP_RESET_ADDRESS;

#if(BOOTLOADER_LIVE_UPDATE_SWITCHER == 1)
    T_FLASH_ID *lower_flash_id = LOWER_FLASH_ID_READ;
    T_FLASH_ID *upper_flash_id = UPPER_FLASH_ID_READ;

    SYS_DEVCON_InstructionCacheFlush();

    /* Application has been programmed first time into flash panel 1 by the bootloader */
    if( *(uint32_t *)LOWER_FLASH_ID_READ == FLASH_ID_CHECKSUM_CLR &&
        *(uint32_t *)UPPER_FLASH_ID_READ == FLASH_ID_CHECKSUM_CLR)
    {
        /* Program Checksum and initial ID's for both panels*/
        T_FLASH_ID low_flash_id = { 0 };
        T_FLASH_ID up_flash_id = { 0 };
 
        low_flash_id.flash_id = 1;
        low_flash_id.checksum_start = FLASH_ID_CHECKSUM_START;
        low_flash_id.checksum_end = FLASH_ID_CHECKSUM_END;

        up_flash_id.flash_id = 0;
        up_flash_id.checksum_start = FLASH_ID_CHECKSUM_START;
        up_flash_id.checksum_end = FLASH_ID_CHECKSUM_END;
        
        APP_NVMQuadWordWrite((void *)LOWER_FLASH_ID_BASE_ADDRESS, (uint32_t *)&low_flash_id);
        APP_NVMQuadWordWrite((void *)UPPER_FLASH_ID_BASE_ADDRESS, (uint32_t *)&up_flash_id);
    }
    /* If both the panels have proper checksum*/
    else if((lower_flash_id->checksum_start == FLASH_ID_CHECKSUM_START) &&
            (lower_flash_id->checksum_end == FLASH_ID_CHECKSUM_END) &&
            (upper_flash_id->checksum_start == FLASH_ID_CHECKSUM_START) &&
            (upper_flash_id->checksum_end == FLASH_ID_CHECKSUM_END))
    {
        if(upper_flash_id->flash_id > lower_flash_id->flash_id)
        {
            SwapFlashPanels();
        }
    }
    /* Fallback Cases when either of Panels checksum is corrupted*/
    else if((upper_flash_id->checksum_start == FLASH_ID_CHECKSUM_START) &&
            (upper_flash_id->checksum_end == FLASH_ID_CHECKSUM_END))
    {
        SwapFlashPanels();
    }
#endif // BOOTLOADER_LIVE_UPDATE_SWITCHER == 1
    /* Disable Global Interrupts and Jump to Application*/
    PLIB_INT_Disable(INT_ID_0);
    if (bootloaderData.StartAppFunc != NULL)
        bootloaderData.StartAppFunc();
    fptr();
}
#endif // BOOTLOADER_LIVE_UPDATE_STATE_SAVE != 1

 
Any idea of what can be the problem?
 
MCU: PIC32MZ2048EFM100
Harmony Version: 2.05
Compiler: XC32 v 1.44
 
Thanks,
CF
post edited by Johnny0099 - 2018/04/02 15:56:48
#1

11 Replies Related Threads

    Paul PortSol
    Super Member
    • Total Posts : 430
    • Reward points : 0
    • Joined: 2015/07/03 11:52:03
    • Location: Newfoundland, Canada
    • Status: offline
    Re: Live Update on PIC32MZ works only the first time 2018/04/03 08:15:58 (permalink)
    0
    If this uses Heap then make sure you have plenty assigned in MHC (try 10000).
    #2
    Johnny0099
    Super Member
    • Total Posts : 156
    • Reward points : 0
    • Joined: 2015/06/20 00:33:20
    • Location: 0
    • Status: offline
    Re: Live Update on PIC32MZ works only the first time 2018/04/07 09:13:09 (permalink)
    0
    I solved this issue. Harmony code for page swap was wrong. This function only allowe to swap from Page 1 to Page 2 one time.
     
    void __longcall__ __attribute__ ((section (".cache_init"))) SwapFlashPanels()
    {
        PLIB_NVM_MemoryModifyInhibit(NVM_ID_0);
        PLIB_NVM_FlashWriteKeySequence(NVM_ID_0, NVM_PROGRAM_UNLOCK_KEY1);
        PLIB_NVM_FlashWriteKeySequence(NVM_ID_0, NVM_PROGRAM_UNLOCK_KEY2);
        PLIB_NVM_ProgramFlashBank2LowerRegion(NVM_ID_0);
    }

    #3
    mwieckowski
    New Member
    • Total Posts : 2
    • Reward points : 0
    • Joined: 2018/04/09 10:11:10
    • Location: 0
    • Status: offline
    Re: Live Update on PIC32MZ works only the first time 2018/04/09 12:38:40 (permalink)
    0
    Johnny0099 - Can you give some more detail here?  Why is this wrong, and what did you do to fix it?
     
    I'm having an issue with the LiveUpdate demo.  I can program the Switcher, and it properly enters bootloader mode based on the detection of unprogrammed Flash (0xFFFF).  I then use the unified bootloader to load an app into program flash, and it runs fine.  Then I try to boatload a second image while the first one is still running, and the bootloader crashes.  (I'm using a UART implementation.  By looking at raw signal data, I can see that the version is properly read, the flash erase works fine, and the first couple of Hex writes work.  After the 3rd hex write, the uart stops responding.)  
     
    Any ideas?
     
    Johnny0099
    I solved this issue. Harmony code for page swap was wrong. This function only allowe to swap from Page 1 to Page 2 one time.
     
    void __longcall__ __attribute__ ((section (".cache_init"))) SwapFlashPanels()
    {
        PLIB_NVM_MemoryModifyInhibit(NVM_ID_0);
        PLIB_NVM_FlashWriteKeySequence(NVM_ID_0, NVM_PROGRAM_UNLOCK_KEY1);
        PLIB_NVM_FlashWriteKeySequence(NVM_ID_0, NVM_PROGRAM_UNLOCK_KEY2);
        PLIB_NVM_ProgramFlashBank2LowerRegion(NVM_ID_0);
    }





    #4
    Johnny0099
    Super Member
    • Total Posts : 156
    • Reward points : 0
    • Joined: 2015/06/20 00:33:20
    • Location: 0
    • Status: offline
    Re: Live Update on PIC32MZ works only the first time 2018/04/10 14:25:58 (permalink)
    0
    My post is generating an error..
     
    post edited by Johnny0099 - 2018/04/10 14:27:05
    #5
    Johnny0099
    Super Member
    • Total Posts : 156
    • Reward points : 0
    • Joined: 2015/06/20 00:33:20
    • Location: 0
    • Status: offline
    Re: Live Update on PIC32MZ works only the first time 2018/04/10 14:33:29 (permalink)
    0
    I think your problem is different. You are able to flash the app with the Switcher that is running from the bootloader area but your live update application is not working properly. I was one step ahead, since my custom live update application was working the first time but the second time the Switcher was not able to swap Bank 1 and Bank 2 according with the last update.
     
    You: switcher (works) -> live update (not working)
    Me: switcher (works) -> custom live update programming bank 2(works) -> custom live update programming bank 1(not swapping in Switcher).
    #6
    Johnny0099
    Super Member
    • Total Posts : 156
    • Reward points : 0
    • Joined: 2015/06/20 00:33:20
    • Location: 0
    • Status: offline
    Re: Live Update on PIC32MZ works only the first time 2018/04/10 14:36:23 (permalink)
    0
    Here some suggestions:
    1) Are you sure you are programming the opposite bank with the live update application? Are you using physical address? Double check the address in the function NVMQuadWordWrite, just print it to verify like this
     
    #7
    Johnny0099
    Super Member
    • Total Posts : 156
    • Reward points : 0
    • Joined: 2015/06/20 00:33:20
    • Location: 0
    • Status: offline
    Re: Live Update on PIC32MZ works only the first time 2018/04/10 14:39:39 (permalink)
    0
    What a hell!! It's 3rd time I'm writing this post and I'm getting an error!!! Cannot post code and a longer comment?? What is happening?
    #8
    indira
    New Member
    • Total Posts : 2
    • Reward points : 0
    • Joined: 2018/05/08 02:47:46
    • Location: 0
    • Status: offline
    Re: Live Update on PIC32MZ works only the first time 2018/05/09 04:15:04 (permalink)
    0
    Hi all,
     
    I too have the Live Update issue....
     
    I am new to PIC32MZ. I want to do live update. I did following things.
    1. I created application ver1.0 in MPLAB xIDE3.65 and loaded using ICD3 to PFM1, which works fine, verified.
    2. In that application, i integrated bootloader portion too. So, i could get the HEX code for next version and write into BANK2
    meanwhile, I have created the next version 2.0 application in the same way. (that mean the hex code is meant for bank1)
    3. Through the ver1.0, i could receive the hexcode of ver2.0 via USB, and add an offset of 0x40000 to make it for bank2 and written it to.( which i verified using ICD3, data is there at bank2)
    4. After writting into bank2, i swapped the Program Memory using
    void __longcall__ __attribute__ ((section (".cache_init"))) SwapFlashPanels(void)
    {
    void (*fptr)(void);
    PLIB_NVM_MemoryModifyInhibit(NVM_ID_0);
    PLIB_NVM_FlashWriteKeySequence(NVM_ID_0, NVM_PROGRAM_UNLOCK_KEY1);
    PLIB_NVM_FlashWriteKeySequence(NVM_ID_0, NVM_PROGRAM_UNLOCK_KEY2);
    PLIB_NVM_ProgramFlashBank2LowerRegion(NVM_ID_0);
    /* Disable Global Interrupts */
    PLIB_INT_Disable(INT_ID_0);
    fptr = (void (*)(void))BOOTLOADER_RESET_ADDRESS;
    fptr();
    }
    5. I did not update the boot flash memory yet, expecting atleast to work from bank1 to bank2.
     
     
     It is not happening in the expected way.
    Please help me out.
    whether i need to use different way to create application hex code for bank2.
     
    Thanks in advance,
    Indira
     
     
     
     
     
    #9
    Johnny0099
    Super Member
    • Total Posts : 156
    • Reward points : 0
    • Joined: 2015/06/20 00:33:20
    • Location: 0
    • Status: offline
    Re: Live Update on PIC32MZ works only the first time 2018/05/22 10:36:37 (permalink)
    0
    Hi Indira,
     
    page swap should be done by bootloader and is not parmanent (you should check whether bank1 or bank 2 contains the last firmware version at boot time).
     
    Hope this help.
    CF
     
     
    #10
    indira
    New Member
    • Total Posts : 2
    • Reward points : 0
    • Joined: 2018/05/08 02:47:46
    • Location: 0
    • Status: offline
    Re: Live Update on PIC32MZ works only the first time 2018/05/22 23:00:09 (permalink)
    0
    Thanks for the information.
    Now i did with "void __attribute__((section(".cache_init"))) _on_reset(void)". I understand this part of code is placed at boot flash, getting executed on run time.
     
    So, now swapping happens. But my application is not running.
     
    I am using ICD3. I dont know how to place boot portion into second bank. Through ICD3, i could not.
    Planning to change the address and Checksum of boot code of bank1 to bank2 and try. 
     
    1. Any idea how else bank2 could be written?
    2. Is it must to write into bootflash bank2?
    3. I understand the hex code of PFM bank1 could be written in Bank2 for live update. Am i right?
     
    Sorry to ask the basics.
     
    Thanks in advance.
     
    Regards,
    Indira
    #11
    AndreaC
    Starting Member
    • Total Posts : 40
    • Reward points : 0
    • Joined: 2017/01/27 12:49:40
    • Location: 0
    • Status: offline
    Re: Live Update on PIC32MZ works only the first time 2019/04/25 11:08:00 (permalink)
    0
    Johnny099, I have exactly the same problem you originally described when trying to run the LiveUpdate demonstrations from Harmony 2.06. I ported the two projects (Switcher and App) to a chipKIT WiFire and perform the LiveUpdate over USB. I can perform the update once, and it works (i.e., the new app runs). But if I try the update a second time, the update is completed but the new app is never executed. How did you fix the SwapFlashPanels function?
     
    Johnny0099
    I solved this issue. Harmony code for page swap was wrong. This function only allowe to swap from Page 1 to Page 2 one time.
     
    void __longcall__ __attribute__ ((section (".cache_init"))) SwapFlashPanels()
    {
        PLIB_NVM_MemoryModifyInhibit(NVM_ID_0);
        PLIB_NVM_FlashWriteKeySequence(NVM_ID_0, NVM_PROGRAM_UNLOCK_KEY1);
        PLIB_NVM_FlashWriteKeySequence(NVM_ID_0, NVM_PROGRAM_UNLOCK_KEY2);
        PLIB_NVM_ProgramFlashBank2LowerRegion(NVM_ID_0);
    }





    #12
    Jump to:
    © 2019 APG vNext Commercial Version 4.5