AnsweredAssumed Answered

Activating the swap flag creates a reboot

Question asked by samuel boivineau on Oct 22, 2015
Latest reply on Oct 30, 2015 by Jorge_Gonzalez

Hello,

 

I am trying to implement a flash over the air, and most of it is ok. The issue is when initializing the flag of swap.

Here are my steps, based on the driver C90TFS in KSDK 1.2.0 over a K64F120M with 1MB flash :

- call the relocate function :

 

g_FlashLaunchCommand = (pFLASHCOMMANDSEQUENCE)RelocateFunction((uint32_t)ramFunc , LAUNCH_CMD_SIZE ,(uint32_t)FlashCommandSequence);

Then get the current swap status :

result = PFlashSwapCtl(&flashSSDConfig,FLASH_SWAP_INDICATOR_ADDR,FTFx_SWAP_REPORT_STATUS,&currentSwapMode, \
        &currentSwapBlockStatus, &nextSwapBlockStatus ,g_FlashLaunchCommand);

I can then see that the currentSwapMode is FTFx_SWAP_UNINIT.

Then I call the flash function :

result = PFlashSwap(&flashSSDConfig, FLASH_SWAP_INDICATOR_ADDR, SwapCallback, g_FlashLaunchCommand);

 

Unfortunately, this function creates a reboot (or more exactly, a jump to the startup...

 

The flash function is the one of the driver :

uint32_t SIZE_OPTIMIZATION PFlashSwap(PFLASH_SSD_CONFIG pSSDConfig, \
                  uint32_t addr, \
                  PFLASH_SWAP_CALLBACK pSwapCallback, \
                  pFLASHCOMMANDSEQUENCE pFlashCommandSequence)
{
    uint32_t ret = FTFx_OK;      /* Return code */
    uint8_t currentSwapMode , currentSwapBlockStatus , nextSwapBlockStatus;
    bool swapContinue;

    currentSwapMode = currentSwapBlockStatus = nextSwapBlockStatus = 0xFFU;
    swapContinue = FALSE;

    /* Report current swap state */
    ret = PFlashSwapCtl(pSSDConfig,addr,FTFx_SWAP_REPORT_STATUS,&currentSwapMode, \
    &currentSwapBlockStatus, &nextSwapBlockStatus ,pFlashCommandSequence);

    if (FTFx_OK == ret)
    {
        if ((FTFx_SWAP_UNINIT == currentSwapMode) || (FTFx_SWAP_READY == currentSwapMode) || \
            (FTFx_SWAP_UPDATE == currentSwapMode))
        {
            /* If current swap mode is Uninitialized */
            if (FTFx_SWAP_UNINIT == currentSwapMode)
            {
                /* Initialize Swap to Initialized/READY state */
                ret = PFlashSwapCtl(pSSDConfig, addr, FTFx_SWAP_SET_INDICATOR_ADDR,&currentSwapMode, \
                &currentSwapBlockStatus, &nextSwapBlockStatus , pFlashCommandSequence);
            }[...]

 

and what is really curious is, it calls PFlashSwapCtl() a first time (line 14) then a second time (line 26) but only the second time, there is a failure. And if I follow until it fails, it's in the call to pFlashCommandSequence here :

 

uint32_t SIZE_OPTIMIZATION PFlashSwapCtl(PFLASH_SSD_CONFIG pSSDConfig,uint32_t addr, uint8_t swapcmd,uint8_t* pCurrentSwapMode, \
                         uint8_t* pCurrentSwapBlockStatus, \
                         uint8_t* pNextSwapBlockStatus, \
                         pFLASHCOMMANDSEQUENCE pFlashCommandSequence)
 {
     uint32_t ret;      /* Return code variable */
     uint32_t temp;     /* temporary variable */

     addr = WORD2BYTE(addr - pSSDConfig->PFlashBase);
     /* clear RDCOLERR & ACCERR & FPVIOL flag in flash status register. Write 1 to clear*/
     temp = pSSDConfig->ftfxRegBase + FTFx_SSD_FSTAT_OFFSET;
     REG_WRITE(temp, FTFx_SSD_FSTAT_ERROR_BITS);

     /* passing parameter to the command */
     temp = pSSDConfig->ftfxRegBase + FTFx_SSD_FCCOB0_OFFSET;
     REG_WRITE(temp, FTFx_PFLASH_SWAP);
     temp = pSSDConfig->ftfxRegBase + FTFx_SSD_FCCOB1_OFFSET;
     REG_WRITE(temp, GET_BIT_16_23(addr));
     temp = pSSDConfig->ftfxRegBase + FTFx_SSD_FCCOB2_OFFSET;
     REG_WRITE(temp, GET_BIT_8_15(addr));
     temp = pSSDConfig->ftfxRegBase + FTFx_SSD_FCCOB3_OFFSET;
     REG_WRITE(temp, GET_BIT_0_7(addr));

     temp = pSSDConfig->ftfxRegBase + FTFx_SSD_FCCOB4_OFFSET;
     REG_WRITE(temp, swapcmd);
     temp = pSSDConfig->ftfxRegBase + FTFx_SSD_FCCOB5_OFFSET;
     REG_WRITE(temp, 0xFFU);
     temp = pSSDConfig->ftfxRegBase + FTFx_SSD_FCCOB6_OFFSET;
     REG_WRITE(temp, 0xFFU);
     temp = pSSDConfig->ftfxRegBase + FTFx_SSD_FCCOB7_OFFSET;
     REG_WRITE(temp, 0xFFU);

     /* calling flash command sequence function to execute the command */
     ret = pFlashCommandSequence(pSSDConfig);

     if (FTFx_OK == ret) [...]

 

By looking into it with the debugger, I can see that g_FlashLaunchCommand is still pointing to the same adress in ram. I am using a multilink, but should I supposed to be able to follow step by step the execution in the ram function ?

 

Does anyone has any idea about why this command FTFx_SWAP_INDICATOR_ADDR fails ?

 

Thanks

Outcomes