void delay(uint32_t delayCnt) { uint32_t i; for ( i = 0; i < delayCnt; i++ ); return; } void NORFLASHInit( void ) { TIM_TIMERCFG_Type TIM_ConfigStruct; EMC_Init(); TIM_ConfigStruct.PrescaleOption = TIM_PRESCALE_USVAL; TIM_ConfigStruct.PrescaleValue = 1; TIM_Init(LPC_TIM0, TIM_TIMER_MODE,&TIM_ConfigStruct); TIM_Waitms(100); EMC_StaMemConfigMW (0,EMC_StaticConfig_MW_16BITS); EMC_StaMemConfigPB(0,EMC_StaticConfig_PB); EMC_SetStaMemoryParameter(0, EMC_STA_MEM_WAITWEN, EMC_StaticWaitWen_WAITWEN(0x0F)); EMC_SetStaMemoryParameter(0, EMC_STA_MEM_WAITOEN, EMC_StaticWaitOen_WAITOEN(0x04)); EMC_SetStaMemoryParameter(0, EMC_STA_MEM_WAITRD, EMC_StaticWaitRd_WAITRD(0x0F)); EMC_SetStaMemoryParameter(0, EMC_STA_MEM_WAITPAGE, EMC_StaticwaitPage_WAITPAGE(0x1f)); EMC_SetStaMemoryParameter(0, EMC_STA_MEM_WAITWR, EMC_StaticWaitwr_WAITWR(0x1f)); EMC_SetStaMemoryParameter(0, EMC_STA_MEM_WAITTURN, EMC_StaticWaitTurn_WAITTURN(0x1f)); //delay time TIM_Waitms(10); return; } uint32_t ToggleBitCheck( uint32_t Addr, uint16_t Data ) { volatile uint16_t *ip; uint16_t temp1, temp2; uint32_t TimeOut = PROGRAM_TIMEOUT; while( TimeOut > 0 ) { ip = GET_ADDR(Addr); temp1 = *ip; ip = GET_ADDR(Addr); temp2 = *ip; if ( (temp1 == temp2) && (temp1 == Data) ) { return( TRUE ); } TimeOut--; } return ( FALSE ); } uint32_t NORFLASHCheckID( void ) { volatile uint16_t *ip; uint16_t SST_id1 = 0, SST_id2 = 0; ip = GET_ADDR(0x555); *ip = 0x00AA; ip = GET_ADDR(0x2AA); *ip = 0x0055; ip = GET_ADDR(0x555); *ip = 0x0090; delay(10); ip = GET_ADDR(0x0001); SST_id2 = *ip; delay(10); return SST_id2; } void NORFLASHErase( void ) { volatile uint16_t *ip; ip = GET_ADDR(0x555); *ip = 0x00AA; ip = GET_ADDR(0x2AA); *ip = 0x0055; ip = GET_ADDR(0x555); *ip = 0x0080; ip = GET_ADDR(0x555); *ip = 0x00AA; ip = GET_ADDR(0x2AA); *ip = 0x0055; ip = GET_ADDR(0x555); *ip = 0x0010; delay(10000000); /* Use timer 1 */ return; } uint32_t NORFLASHWriteWord( uint32_t Addr, uint16_t Data ) { volatile uint16_t *ip; ip = GET_ADDR(0x555); *ip = 0x00AA; ip = GET_ADDR(0x2AA); *ip = 0x0055; ip = GET_ADDR(0x555); *ip = 0x00A0; ip = GET_ADDR(Addr); /* Program 16-bit word */ *ip = Data; return ( ToggleBitCheck( Addr, Data ) ); } |