|
![](static/image/common/ico_lz.png)
楼主 |
发表于 2012-4-9 22:49:34
|
显示全部楼层
int c_entry(void)
{
uint32_t i;
volatile uint16_t *ip;
uint32_t NorFlashAdr;
/* Initialize debug via UART0
* ?115200bps
* ?8 data bit
* ?No parity
* ?1 stop bit
* ?No flow control
*/
debug_frmwrk_init();
// print welcome screen
print_menu();
_DBG_("Init NOR Flash...");
NORFLASHInit();
_DBG_("Read NOR Flash ID...");
if ( NORFLASHCheckID() == FALSE )
{
_DBG_("Error in reading NOR Flash ID, testing terminated!");
while ( 1 ); /* Fatal error */
}
_DBG_("Erase entire NOR Flash...");
NORFLASHErase(); /* Chip erase */
/* Write to flash with pattern 0xAA55 and 0xA55A */
NorFlashAdr = NOR_FLASH_BASE;
_DBG_("Write a block of 2K data to NOR Flash...");
for ( i = 0; i < NORFLASH_RW_PAGE_SIZE/2; i++ )
{
NORFLASHWriteWord( NorFlashAdr, 0xAA55 );
NorFlashAdr++;
NORFLASHWriteWord( NorFlashAdr, 0xA55A );
NorFlashAdr++;
}
/* Verify */
_DBG_("Verify data...");
NorFlashAdr = NOR_FLASH_BASE;
for ( i = 0; i < NORFLASH_RW_PAGE_SIZE/2; i+=2 )
{
ip = GET_ADDR(i);
if ( (*ip & 0xFFFF) != 0xAA55 )
{
_DBG_("Verifying fail, testing terminated!");
while ( 1 ); /* Fatal error */
}
ip = GET_ADDR(i+1);
if ( (*ip & 0xFFFF) != 0xA55A )
{
_DBG_("Verifying fail, testing terminated!");
while ( 1 ); /* Fatal error */
}
}
// terminated
_DBG_("Verifying complete! Testing terminated!");
while (1);
return 1;
}
void NORFLASHInit( void )
{
TIM_TIMERCFG_Type TIM_ConfigStruct;
/**************************************************************************
* Initialize EMC for NOR FLASH
**************************************************************************/
EMC_Init();
// init timer
TIM_ConfigStruct.PrescaleOption = TIM_PRESCALE_USVAL;
TIM_ConfigStruct.PrescaleValue = 1;
// Set configuration for Tim_config and Tim_MatchConfig
TIM_Init(LPC_TIM0, TIM_TIMER_MODE,&TIM_ConfigStruct);
TIM_Waitms(100);
EMC_StaMemConfigMW (2,EMC_StaticConfig_MW_16BITS); // WANG CS2的 16位数据
EMC_StaMemConfigPB(2,EMC_StaticConfig_PB);
EMC_SetStaMemoryParameter(2, EMC_STA_MEM_WAITWEN, EMC_StaticWaitWen_WAITWEN(2));
EMC_SetStaMemoryParameter(2, EMC_STA_MEM_WAITOEN, EMC_StaticWaitOen_WAITOEN(2));
EMC_SetStaMemoryParameter(2, EMC_STA_MEM_WAITRD, EMC_StaticWaitRd_WAITRD(0x1f));
EMC_SetStaMemoryParameter(2, EMC_STA_MEM_WAITPAGE, EMC_StaticwaitPage_WAITPAGE(0x1f));
EMC_SetStaMemoryParameter(2, EMC_STA_MEM_WAITWR, EMC_StaticWaitwr_WAITWR(0x1f));
EMC_SetStaMemoryParameter(2, EMC_STA_MEM_WAITTURN, EMC_StaticWaitTurn_WAITTURN(0x1f));
//delay time
TIM_Waitms(10);
return;
}
uint32_t NORFLASHCheckID( void )
{
volatile uint16_t *ip;
uint16_t SST_id1, SST_id2;
/* Issue the Software Product ID code to 39VF160 */
//这里定义 #define GET_ADDR(addr) (volatile uint16_t *)(NOR_FLASH_BASE | (addr<<1))
ip = GET_ADDR(0x0555);
*ip = 0x00AA;
ip = GET_ADDR(0x02AA);
*ip = 0x0055;
ip = GET_ADDR(0x0555);
*ip = 0x0090;
delayns(150);
/* Read the product ID from 39VF160 */
ip = GET_ADDR(0x0000);
SST_id1 = *ip & 0x00FF;
ip = GET_ADDR(0x0001);
SST_id2 = *ip;
/* Issue the Soffware Product ID Exit code thus returning the 39VF160 */
/* to the read operating mode */
ip = GET_ADDR(0x0555);
*ip = 0x00AA;
ip = GET_ADDR(0x02AA);
*ip = 0x0055;
ip = GET_ADDR(0x0555);
*ip = 0x00F0;
delayns(150);
/* Check ID */
if ((SST_id1 == SST_ID) && (SST_id2 ==SST_39VF160))
return( TRUE );
else
return( FALSE );
}
主要是这3个函数, |
|