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
}