hudson2009 wrote on Monday, February 23, 2009:
Using the internal flash of sam7x as to log data.
When running in debugging mode with Jtag connected, the code Run (alternately -> didn’t run 1st time and after reset it will run and redet again it will stop running and so on).
Also it will not run in release mode(no debugger attached).
following are my Flash command code and it is in .fast section.
Any one can give me some hint how to get the Internal flash working properly in FreeRTOS.
Many Thanks!
//----------------------------------------------------------------------------
e_FLASH_Result Flash_Command(e_FLASH_Cmd cmd, const int page)
{
e_FLASH_Result ret_val = FLASH_FAIL;
unsigned int fcr_val = 0x0; //Value to be placed in MC_FCR.
unsigned int fsr_val; //FSR reg content.
AT91S_MC *pEfc; //pointer to EFC.
pEfc = AT91C_BASE_MC; // Base address of EFC0 registers.
portDISABLE_INTERRUPTS();
switch(cmd)
{
case FLASH_LOCK_PAGE: // Lock a page.
fcr_val = (0x5A << 24) | (page << 8) | 0x2;
pEfc->MC_FMR = (48 << 16) | AT91C_MC_FWS_3FWS;
break;
case FLASH_UNLOCK_PAGE: // Unlock a page.
fcr_val = (0x5A << 24) | (page << 8) | 0x4;
pEfc->MC_FMR = (48 << 16) | AT91C_MC_FWS_3FWS;
break;
case FLASH_ERASE_PAGE: // Erase a page of data - write all zeroes (not 0xff)!
case FLASH_WRITE_PAGE: // Write data to a page (which should be unlocked already).
fcr_val = (0x5A << 24) | (page << 8) | 0x1;
pEfc->MC_FMR = (72 << 16) | AT91C_MC_FWS_3FWS;
break;
default:
return ret_val;
break;
}
// Wait for flash to be ready.
do
{
fsr_val = pEfc->MC_FSR;
}
while ((fsr_val & AT91C_MC_FRDY) == 0);
// Now send command.
pEfc->MC_FCR = fcr_val;
// Wait for flash to be ready.
do
{
fsr_val = pEfc->MC_FSR;
}
while ((fsr_val & AT91C_MC_FRDY) == 0);
//Check for errors and return.
if((fsr_val = pEfc->MC_FSR) & (AT91C_MC_PROGE | AT91C_MC_LOCKE))
{
return ret_val; // Error shown in PROGE or LOCKE bits.
}
portENABLE_INTERRUPTS();
return FLASH_OK;
}
//---------------------------------------------------------------------------