After I update my firmware, set swap state to Complete and reboot my K64F system runs fine showing swap state as Ready and running out of the appropriate block. When I then set swap state to Prepare 0x02 system crashes with SRS1 showing the LOCKUP bit set. This happens occasionally and am trying to understand why this is happening.
Reading the flash_demo_frdmk64f code, and comparing to AN4533 app note - I see one discrepancy right away.
AN4533 4.1.1 First Swap states that if swap state is uninitialized, you:
(1) initialize the system (assume - PFlashSwapCtl set FTFx_SWAP_SET_INDICATOR_ADDR)
(2) Erase the nonactive (upper block) - in my case the upper 4K (PSWAP_INDICATOR + PFLASH_SIZE/2). My PSWAP_INDICATOR is set to 0x7F000.
In flash_swap.c, the code does the following:
(1) Erases BOTH the active and non-active block:
ret = FlashEraseSector(&flashSSDConfig,PSWAP_INDICATOR_ADDR + P_FLASH_SIZE/2, P_SECTOR_SIZE,g_FlashLaunchCommand);
ret |= FlashEraseSector(&flashSSDConfig,PSWAP_INDICATOR_ADDR, P_SECTOR_SIZE,g_FlashLaunchCommand);
(2) Initializes the system
/* after this call, swap state = UPDATE_ERS */
ret = PFlashSwapCtl(&flashSSDConfig, PSWAP_INDICATOR_ADDR, FTFx_SWAP_SET_INDICATOR_ADDR, ¤tSwapMode, ¤tSwapBlock, &nextSwapBlock, g_FlashLaunchCommand);
if ((FTFx_OK != ret)||(currentSwapMode!= FTFx_SWAP_UPDATE_ERASED))
My questions -
(1) Why does sample code erase the active block where PSWAP_INDICATOR is set?
(2) Why does sample code erase first then initialize?