按照您给的链接看了,第一个帮助比较大 片外Flash为k9f1208,8位io的,64M; RE WE ALE CLE 分别接到CPU的OE WE P0.11(GPIO) P0.12(GPIO)上; CE通过CPLD接过来,CPLD的另一端也接的是CPU的NCS0;
/**********************************************************/ 总线的配置 ;/* Define the Bus Speed */ BCFG0 EQU 0xFFE00000 ;// Control Word of BANK0 / CS0 BCFG1 EQU 0xFFE00004 ;// Control Word of BANK1 / CS1 BCFG2 EQU 0xFFE00008 ;// Control Word of BANK2 / CS2 BCFG3 EQU 0xFFE0000C ;// Control Word of BANK3 / CS3
BCFG_08DEF EQU 0x00000400 ;// 8Bit Bus BCFG_16DEF EQU 0x10000400 ;// 16Bit Bus BCFG_32DEF EQU 0x20000400 ;// 32Bit Bus
;// | IDCY | WST1 | WST2 ;// | Idle width | Read width | Write width ;// | 0x00 ~ 0x0f| 0x00 ~ 0x1f| 0x00~0x1f BCFG_FLASH EQU (BCFG_08DEF | (0x1f<<00) | (0x1f<<05) | (0x0f<<11)) ;// For 90ns Flash BCFG_PSRAM EQU (BCFG_16DEF | (0x0f<<00) | (0x0f<<05) | (0x0f<<11)) ;// For 70ns PSRAM BCFG_CS2 EQU (BCFG_16DEF | (0x0f<<00) | (0x1f<<05) | (0x1f<<11)) ;// Blank BCFG_CS3 EQU (BCFG_16DEF | (0x01<<00) | (0x03<<05) | (0x03<<11)) ;// For Peripheral Equipment
这里的RBLE为1; ncs0接的是最慢的总线,为0x1f; /**********************************************************/ PINSEL2的设置没有改过;用的是lpc2100模板
;初始化外部总线控制器,根据目标板决定配置
LDR R0, =PINSEL2 IF :DEF: EN_CRP LDR R1, =0x0f814910 ELSE LDR R1, =0x0f814914 ENDIF STR R1, [R0] LDR R0, =BCFG0 LDR R1, =BCFG_FLASH STR R1, [R0]
LDR R0, =BCFG1 LDR R1, =BCFG_PSRAM STR R1, [R0]
LDR R0, =BCFG2 LDR R1, =BCFG_CS2 STR R1, [R0]
LDR R0, =BCFG3 LDR R1, =BCFG_CS3 STR R1, [R0] BL InitStack ;初始化堆栈 Initialize the stack BL TargetResetInit ;目标板基本初始化 Initialize the target board ;跳转到c语言入口 Jump to the entry point of C program B __main
/***************************************************/ 源程序,只写到了读芯片id,擦出和写入 #include "config.h" //#define LED_ADDR 0x82000000; #define CA_LE 0x00001800
void DelayNS(uint32 dly) { uint32 i;
for(; dly>0; dly--) { for(i=0; i<5000; i++); } }
int main (void) {// add user source code volatile uint8 *data; //unsigned short int id; volatile unsigned int *adder1; //unsigned int id1,id2; data=(uint8 *)0x80000000; adder1 =(uint32 *)0x81000000; //adder2 =(uint32 *)0x81000008; //PINSEL2=((PINSEL2&0xf07fffff)|(0x38<<20)); PINSEL0 = 0x00000000; // 设置管脚连接GPIO IO0DIR = CA_LE; IO0SET = (IO0SET|0x1000); IO0CLR = (IO0CLR|0x0800); //for(;;) *data =0x90; IO0SET = (IO0SET|0x0800); IO0CLR = (IO0CLR|0x1000); for(;;) *data = 0x0; IO0CLR = (IO0CLR|0x1800); //for(;;) *adder1 = *data<<8; *adder1 |= *data; for(;;); // _ *adder2 = *data;
/*****************************************************************************************************************/ int i; unsigned int block = 0x02; unsigned int blockpage = (block<<5); volatile uint8 *data; data=(uint8 *)0x80000000; PINSEL0 = 0x00000000; // 设置管脚连接GPIO IO0DIR = CA_LE; IO0SET = (IO0SET|0x1000); IO0CLR = (IO0CLR|0x0800); //for(;;) *data = 0x60; //设置擦写模式 IO0SET = (IO0SET|0x0800); IO0CLR = (IO0CLR|0x1000); *data = (blockpage&0xff); // A9_A16,(Page Address) , 是基于块擦 *data = ((blockpage>>8)&0xff); // A17_A24,(Page Address) *data = ((blockpage>>16)&0xff); // A25, (Page Address) IO0SET = (IO0SET|0x1000); IO0CLR = (IO0CLR|0x0800); *data = 0xd0; for(i=0;i<10;i++); /*****************************************************************************************************************/
int i; unsigned int block =0x00; unsigned int page =0x00; unsigned char a[528]; unsigned int blockpage = (block<<5)+page; volatile uint16 *data; data=(uint16 *)0x80000000; PINSEL0 = 0x00000000; // 设置管脚连接GPIO IO0DIR = CA_LE; for(i=0;i<528;i++) a=0x55; IO0SET = (IO0SET|0x1000); IO0CLR = (IO0CLR|0x0800); *data = 0x0; // 从A区开始写 *data = 0x80; // 写第一条命令 IO0SET = (IO0SET|0x0800); IO0CLR = (IO0CLR|0x1000); *data = 0; // A0_A7 位(Column Address) *data = blockpage&0xff; // A9_A16,(Page Address) *data = (blockpage>>8)&0xff; // A17_A24,(Page Address) *data = (blockpage>>16)&0xff;// A25 (Page Address) for(i=0;i<528;i++) { *data = a; } IO0SET = (IO0SET|0x1000); IO0CLR = (IO0CLR|0x0800); *data = 0x10; // 结束写命令
}
这个程序我是分为三部分(读id,擦出,写入)调试的,所以看上去有些重复定义;
还有我想向zlgARM请教,我向0X0000处擦出或写入,会不会影响芯片的ID,他不是就在0X0000处吗 |