#include #include #include #include #include #include #include #include "flash.h" void gpio_init(); static GPIO_Handle hGpio4; static EMIFB_Config MyEmifbConfig = { EMIFB_GBLCTL_RMK ( EMIFB_GBLCTL_EK2RATE_FULLCLK, //1 X EMIF input clock EMIFB_GBLCTL_EK2HZ_CLK, //eclkout2 continue output during hold EMIFB_GBLCTL_EK2EN_ENABLE, //eclkout2 enable output EMIFB_GBLCTL_BRMODE_MRSTATUS, //bus request is memory access or refresh pending/in progress EMIFB_GBLCTL_NOHOLD_ENABLE, EMIFB_GBLCTL_EK1HZ_CLK, //eclkout1 continue output during hold EMIFB_GBLCTL_EK1EN_ENABLE //eclkout1 enable output ), 0xffffff0f, 0xffffff0f, // 0x20a0c412, 0x22a28a22, 0x22a28a22, EMIFB_SDCTL_DEFAULT, EMIFB_SDTIM_DEFAULT, EMIFB_SDEXT_DEFAULT, 0x00000002, 0x00000002, 0x00000002, 0x00000002 }; unsigned char data[0x400]; unsigned char redata[0x400]; Uint32 k; extern far void vectors(); void main(){ int pass = TRUE; char * flash_ptr = (char *)FLASH_ADDRS; int flash_ptr_if = FLASH_ADDRS; //unsigned char * src_ptr = (unsigned char *)SRC_ADDRS; /* initialize the CSL library */ CSL_init(); //配置EMIFA EMIFB_config(&MyEmifbConfig); //GPIO gpio_init(); //设置中断矢量表地址 IRQ_setVecs(vectors); //NMI使能 IRQ_nmiEnable(); //开总中断 IRQ_globalEnable(); for(k = 0; k < 0x400; k++) { data[k] = 0x00+k; } pass = erase_flash(flash_ptr); if (pass) { pass = program_flash(&data[0], flash_ptr, LENGTH); if (!pass) printf("Failed in program operation"); else printf("Successful erase and program!!!"); } else printf("Failed in erase operation"); //程序运行后,显示的是成功擦除和写,但是至少写没有成功 flash_readm(flash_ptr_if, &redata[0],LENGTH); //读出来的数据全是0xff } void gpio_init()//开始连线有错,信号线接到GPIO,目前是飞线过去的 { hGpio4 = GPIO_open(GPIO_DEV0,GPIO_OPEN_RESET); GPIO_reset(hGpio4); GPIO_pinEnable(hGpio4,GPIO_PIN12); // DEC6416_wait(1000); GPIO_pinDisable(hGpio4,GPIO_PIN12); //GPIO上面的OE信号Disable // DEC6416_wait(1000); GPIO_pinEnable(hGpio4,GPIO_PIN11); // DEC6416_wait(1000); GPIO_pinDisable(hGpio4,GPIO_PIN11); //GPIO上面的WE信号Disable // DEC6416_wait(1000); GPIO_pinEnable(hGpio4,GPIO_PIN10); // DEC6416_wait(1000); GPIO_pinDisable(hGpio4,GPIO_PIN10); //GPIO上面的WE信号Disable GPIO_pinEnable(hGpio4,GPIO_PIN1); GPIO_pinDirection(hGpio4,GPIO_PIN4,GPIO_OUTPUT); GPIO_pinWrite(hGpio4,GPIO_PIN1,1);//测试信号低有效 GPIO_pinEnable(hGpio4,GPIO_PIN13); GPIO_pinDirection(hGpio4,GPIO_PIN13,GPIO_OUTPUT); GPIO_pinWrite(hGpio4,GPIO_PIN13,1);//reset置高(Disable) int erase_flash(char * flash_ptr) { Uint32 i; char * ctrl_addr2 = (char *) ((int)flash_ptr + (0x555)); char * ctrl_addr1 = (char *) ((int)flash_ptr + (0xaaa)); int pass = TRUE; * ctrl_addr1 = 0xaa; /* Erase sequence writes to addr1 and addr2 */ * ctrl_addr2 = 0x55; /* with this data */ * ctrl_addr1 = 0x80; * ctrl_addr1 = 0xaa; * ctrl_addr2 = 0x55; * ctrl_addr1 = 0x10; for(i=0;i