This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

TMS320F28P650DK: Erasing Sector results in "Command failed due to verify error."

Part Number: TMS320F28P650DK

Chip: f28p650DK6
(F28P650DK6 PZP )Issue:


Sometimes, when sector is erased STATCMD.FAILVERIFY is set. As per Flash API datasheet it indicates: "Command failed due to verify error."
Every time STATCMD.FAILVERIFY it takes significant amount (from seconds to tens of seconds) of time for Flash API FSM to become ready (Fapi_checkFsmForReady()==Fapi_Status_FsmReady)
This behaviour may be noticed on some chips but on others it is not observed.

Below is the code that does the sector erase function. Can you let us know why this delay is happening and why this Bit is geting set only sometimes and not always.


// Flash API initialization
void fw_init(void) {
    memset_ram(&g_fw, 0, sizeof(g_fw));
    fw_switch_state(FW_STATE_INIT);    SysCtl_disableWatchdog();    EALLOW;
    IPC_init(IPC_CPU1_L_CPU2_R);
    IPC_claimFlashSemaphore(IPC_FLASHSEM_OWNER_CPU1);    // Allocate all flash banks to CPU1
    SysCtl_allocateFlashBank(SYSCTL_FLASH_BANK0, SYSCTL_CPUSEL_CPU1);
    SysCtl_allocateFlashBank(SYSCTL_FLASH_BANK1, SYSCTL_CPUSEL_CPU1);
    SysCtl_allocateFlashBank(SYSCTL_FLASH_BANK2, SYSCTL_CPUSEL_CPU1);
    SysCtl_allocateFlashBank(SYSCTL_FLASH_BANK3, SYSCTL_CPUSEL_CPU1);
    SysCtl_allocateFlashBank(SYSCTL_FLASH_BANK4, SYSCTL_CPUSEL_CPU1);    
Fapi_initializeAPI(FlashTech_CPU0_BASE_ADDRESS, DEVICE_SYSCLK_FREQ);
    Fapi_setActiveFlashBank(Fapi_FlashBank0);    EDIS;    Fapi_LibraryInfoType fapi_info = Fapi_getLibraryInfo();
}

// Clearing of the FAPI status
int fw_clear_status(void) {
    while (Fapi_checkFsmForReady()!=Fapi_Status_FsmReady) {}    if (Fapi_getFsmStatus() != 0) {
        int ret = Fapi_issueAsyncCommand(Fapi_ClearStatus);
        if (ret != Fapi_Status_Success) {
            return -1;
        }
        while (Fapi_checkFsmForReady()!=Fapi_Status_FsmReady) {}
    }
    return 0;
}

// Reading FAPI_status
int fw_status(void) {
    int stat_word;    if (Fapi_checkFsmForReady()!=Fapi_Status_FsmReady) {
        return FLASH_WRITER_BUSY;
    }    stat_word = Fapi_getFsmStatus();    if (stat_word & FAPI_STATCMD_FAILMISC) {
        return FLASH_WRITE_FAIL_MISC;
    } else if (stat_word & FAPI_STATCMD_FAILINVDATA) {
        return FLASH_WRITE_FAIL_INVDATA;
    } else if (stat_word & FAPI_STATCMD_FAILILLADDR) {
        return FLASH_WRITE_FAIL_ILLADDR;
    } else if (stat_word & FAPI_STATCMD_FAILVERIFY) {
        return FLASH_WRITE_FAIL_VERIFY;
    } else if (stat_word & FAPI_STATCMD_FAILWEPROT) {
        return FLASH_WRITE_FAIL_WEPROT;
    }    return FLASH_WRITER_OK;
}

// Initializing of the sector erase
int fw_erase_async(void) {
    Fapi_FlashStatusWordType flash_status_word;
    uint32_t* sec_to_erase;
    int ret;
    SECTOR_INDEX_TYPE bank_sector_offset = mc_relative_sector(g_fw.mi.sector);   

 

 // Calculate protection bits
    g_fw.protection_bits_a = fw_get_protection_bits_a(bank_sector_offset);
    g_fw.protection_bits_b = fw_get_protection_bits_b(bank_sector_offset);    ret = fw_clear_status();
    if (ret < 0) {
        goto done;
    }    

// Clear ptotection bits on required sectors
    Fapi_setupBankSectorEnable(FLASH_WRAPPER_PROGRAM_BASE+FLASH_O_CMDWEPROTA, g_fw.protection_bits_a);
    Fapi_setupBankSectorEnable(FLASH_WRAPPER_PROGRAM_BASE+FLASH_O_CMDWEPROTB, g_fw.protection_bits_b);    while (Fapi_checkFsmForReady()!=Fapi_Status_FsmReady) {}   

 sec_to_erase = (uint32_t*)mc_sector_to_ptr(g_fw.mi.sector);    

ret = Fapi_issueAsyncCommandWithAddress(Fapi_EraseSector, sec_to_erase);

done:    
if (ret == Fapi_Status_Success) {
        ret = 0;
    } else {
        fw_switch_state(FW_STATE_ERASE_ERR);
        ret = -1;
    }    return ret;
}