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.

F28M36P63C2: Fapi_getFsmStatus returned 2064 (0x810)

Part Number: F28M36P63C2

I am modifying my bootloader code so that it can read/write the flash memory.  The logic was working fine on application code already.  But when I port over to the boot loader.  In the log_clear runction, Fapi_getFsmStatus returns 0x810.  The SECTION definition looks fine to me.  Here comes the flash access code segment.

/* Private Variables ------------------------------------------------------------------- */
#pragma DATA_SECTION(log_entries, "LOG_ENTRIES"):

Log_Entry log_entries[LOG_NUM_ENTRIES];
unsigned log_next_free;

#pragma CODE_SECTION(log_init, "ramfuncs");
void log_init(void)
{
// /* Enable writes to protected registers */
// HWREG(SYSCTL_MWRALLOW) = 0xA5A5A5A5;

/* Gain control of the flash pump */
FlashGainPump();

FlashInit();

/* Initialize FLASH API based on system frequency of 75 MHz before any other Flash API
* calls can be made. */
Fapi_StatusType fapiStatus = Fapi_initializeAPI(F021_CPU0_BASE_ADDRESS, 75);
if(fapiStatus != Fapi_Status_Success)
{
printf("Flash API Initialization Error: %d\n", fapiStatus);
}

/* Set the Flash bank and FMC for further Flash operations to be performed on the
* bank */
fapiStatus = Fapi_setActiveFlashBank(Fapi_FlashBank0);
if(fapiStatus != Fapi_Status_Success)
{
printf("FAPI set active flash bank failed: %d\n", fapiStatus);
}

/* Yield control of the flash pump */
FlashLeavePump();

// /* Disable writes to protected registers */
// HWREG(SYSCTL_MWRALLOW) = 0;

/* Find the next free log entry */
Log_Entry* entry;
for(log_next_free = 0; (entry = log_entry(log_next_free)); log_next_free++)
{
if(log_empty(entry))
{
System_printf("log_init: No log entry\r\n");
break;
}
}
}

#pragma CODE_SECTION(log_clear, "ramfuncs");
int log_clear(void)
{
static uint32_t* FLASH_SECTOR_A = (uint32_t*)(0x002F8000);
Fapi_FlashStatusType fStatus;
Fapi_FlashStatusWordType oFlashStatusWord;
Fapi_FlashBankSectorsType oFlashBankSectors;
int nRet = 0xff;


/* Gain control of the flash pump */
EnterFlashProg();

fStatus = Fapi_getBankSectors(Fapi_FlashBank0,&oFlashBankSectors);
if(fStatus != Fapi_Status_Success)
{
nRet = 1;
return nRet;
}

while(Fapi_checkFsmForReady() != Fapi_Status_FsmReady) { }

Fapi_issueAsyncCommandWithAddress(Fapi_EraseSector, (uint32*)FLASH_SECTOR_A);

/* Wait until FSM is done with erase sector operation */
while(Fapi_checkFsmForReady() != Fapi_Status_FsmReady) { }

fStatus = Fapi_doBlankCheck((uint32*)FLASH_SECTOR_A, 0x2000, &oFlashStatusWord);

if(fStatus != Fapi_Status_Success)
{
//Check Flash API documentation for possible errors
//If Erase command fails, use Fapi_getFsmStatus() function to get
// the FMSTAT register contents
//to see if any of the EV bit, ESUSP bit, CSTAT bit or VOLTSTAT
//bit is set (Refer to API documentation for more details)
nRet = 2;
return nRet;
}

// Get the Flash state machine status which will indicate the results of the last write
fStatus = Fapi_getFsmStatus();
if (fStatus != Fapi_Status_Success)
{
nRet = fStatus;   /* return 0x810
return nRet;
}

/* Yield control of the flash pump */
LeaveFlashProg();
log_next_free = 0;

nRet = 4;
return nRet;
}

unsigned log_count(void)
{
return log_next_free;
}

Following is the cmd file:

#define FLASH_BOOTLOADER_VEC FLASH_BOOT

// FLASH (the rest of the code) goes into FLASH_BOOTLOADER
#define FLASH_BOOTLOADER FLASH


#include "F28M36_M3_MEMORY.lds"

SECTIONS
{
/* Allocate program areas: */
.text : > FLASH
.cinit : > FLASH
.pinit : > FLASH
.binit : > FLASH
.init_array : > FLASH

/* Initialized sections go in Flash_B */
.const : > FLASH

/* Allocate uninitalized data sections: */
.bss : > C03SRAM | RAM2 // place the largest block first
.data : > C03SRAM | RAM2
.sysmem : > C03SRAM | RAM2
.stack : > C03SRAM | RAM2
.cio : > C03SRAM | RAM2
.neardata : > C03SRAM | RAM2
.rodata : > C03SRAM | RAM2
.args : > C03SRAM | RAM2
.exch_mem : START(TFSystemGlobalData_address) > EXCHANGE_RAM
.smem_m3_tx : START(SmemTransportM3TxStart) > SMEM_TRANSPORT_M3_TX
.smem_c28_tx: START(SmemTransportC28TxStart) > SMEM_TRANSPORT_C28_TX
.app_storage: START(AppFlashStartAddress) > FLASH_APPLICATION_VEC
.flash_log : START(FlashLogAddress) > FLASH_LOG
.end_flash : START(AppFlashEndAddress) > FLASH_LOG

LOG_ENTRIES : > FLASH_LOG, ALIGN(4)

GROUP
{
ramfuncs
{
-l F021_API_CortexM3_LE.lib
}
} LOAD = FLASH,
RUN = C03SRAM,
LOAD_START(RamfuncsLoadStart),
LOAD_SIZE(RamfuncsLoadSize),
LOAD_END(RamfuncsLoadEnd),
RUN_START(RamfuncsRunStart),
RUN_SIZE(RamfuncsRunSize),
RUN_END(RamfuncsRunEnd),
PAGE = 0
}

  • Sorry for the typo. It returns 0x810. See the following:

    if (fStatus != Fapi_Status_Success)
    {
    nRet = fStatus; /* return 0x810 */
    return nRet;
    }
  • Hi,

    Here are a few debug tips:

    1) I see that you allocated Flash API library and the ramfuncs to Flash for load and run for RAM in the linker command file snapshot.  What is the origin and length for the memory entry "FLASH" in your linker command file?  Hope it does not consist one of those sectors that you are erasing in the application.  Just want to make sure you are not erasing the sectors that have Flash API stored in it.

    2) In the code I see that you gained pump and then released it after the API initialization.  Can you confirm whether the application gained it back before doing the erase operation or not? 

    3) Also, it is not clear whether MWRALLOW is configured to allow writes before using Flash API functions. Please confirm.

    Thanks and regards,
    Vamsi
      

  • Hi Vamsi,

    Very appreciate for your reply.  It turned out my old boot code was not involved in flash access.  As the new flash access was added in. the write protection has to be disabled before flash access logic.  That is what caused my boot code failed at Fapi_getFsmStatus().  My application code runs fine because it runs after flash write protection has been removed.

    Thanks,

    Jew-Dong

  • Jew-Dong,

    Glad that it helped.
    I am closing this thread.

    Thanks and regards,
    Vamsi