最近在做6416的FLASH调试,出现的问题和你的很像,就是写不进去,FLASH芯片为AM29LV160B,目前手头有两块板(都是自己做的PCB),一块是按16bit位宽连接的EMIFA的CE0,可以正常读写;一块是按8bit位宽连接的EMIFB的CE1,死活没法写,读出的数据全是FF!目前已经测试芯片管脚的CE,OE,WE,RESET,BYTE等信号,还没发现问题!跪求各位老师、专家给点建议和指导啊!谢谢!
Shine:
看一下是不是没有满足Flash写的时序要求?试试在flash write命令后多等些时间再写下一个数。
qinbiao yang:
回复 Shine:
我在执行完一个写操作之后是回读写入的数据,看读出的数据是否等于写入的数据,如果不等于的话就一直等待,然后读出的数据就一直是FF,过不去了!控制CE的寄存器的那些等待时间我基本都设置成最大了!我用几乎相同的代码读写16bit连接方式的FLASH是可以的,我也用示波器测试了FLASH相应管脚上的信号时序,感觉也看不出明显错!有没有一些检测硬件好坏的测试方法啊?确定是不是硬件有问题呢!谢谢啊
Tony Tang:
回复 qinbiao yang:
检查一下你的两个flash的命令是否有区别。
下面是我在C6416上测试过的nor flash相关代码:
typedef unsigned int FLASH_DATA_TYPE;
#define FlashBaseAddr 0x064000000 //EMIFB CE1, COPY TO ADDRESS 0.void Init_Emif(){ #define EMIFA_GCTL 0x01800000 #define EMIFA_CE1 0x01800004 #define EMIFA_CE0 0x01800008 #define EMIFA_CE2 0x01800010 #define EMIFA_CE3 0x01800014 #define EMIFA_SDRAMCTL 0x01800018 #define EMIFA_SDRAMTIM 0x0180001c #define EMIFA_SDRAMEXT 0x01800020 #define EMIFA_CE1SECCTL 0x01800044 #define EMIFA_CE0SECCTL 0x01800048 #define EMIFA_CE2SECCTL 0x01800050 #define EMIFA_CE3SECCTL 0x01800054
#define EMIFB_GCTL 0x01A80000 #define EMIFB_CE1 0x01A80004 #define EMIFB_CE0 0x01A80008 #define EMIFB_CE2 0x01A80010 #define EMIFB_CE3 0x01A80014 #define EMIFB_SDRAMCTL 0x01A80018 #define EMIFB_SDRAMTIM 0x01A8001c #define EMIFB_SDRAMEXT 0x01A80020 #define EMIFB_CE1SECCTL 0x01A80044 #define EMIFB_CE0SECCTL 0x01A80048 #define EMIFB_CE2SECCTL 0x01A80050 #define EMIFB_CE3SECCTL 0x01A80054
/* Setup EMIFB Version 2 (120 MHz EMIF) */
*(int*)EMIFB_GCTL = 0x00002060;
*(int*)EMIFB_CE1 = 0xffffff03; // CE1 Flash 8-bit—BOOTLOADER
/* EMIFA Version 2 (120MHz EMIF) */ *(int*)EMIFA_GCTL = 0x00012070; *(int*)EMIFA_CE0 = 0x23228c43; // CE0 SDRAM 1Mx32bitx4bank=16M byte *(int*)EMIFA_CE1 = 0x23228c43; // CE1 8-bit Async *(int*)EMIFA_CE2 = 0x23228c43; // CE2 Daughtercard 32-bit async *(int*)EMIFA_CE3 = 0x23228c43; // CE3 Daughtercard 32-bit async *(int*)EMIFA_SDRAMCTL = 0x56228000; // SDRAM control *(int*)EMIFA_SDRAMTIM = 0x00001E1D; // SDRAM timing refresh *(int*)EMIFA_CE2SECCTL = 0x0032; //Read space; *(int*)EMIFA_CE3SECCTL = 0x0030; // Write back Space;
*(int*)EMIFA_SDRAMCTL |= 0x01000000;}
void Chip_Erase(){ //Unlock command *(unsigned char *)(FlashBaseAddr + 0xAAA) = 0xAA; *(unsigned char *)(FlashBaseAddr + 0x555) = 0x55; *(unsigned char *)(FlashBaseAddr + 0xAAA) = 0x80;
*(unsigned char *)(FlashBaseAddr + 0xAAA) = 0xAA; *(unsigned char *)(FlashBaseAddr + 0x555) = 0x55; *(unsigned char *)(FlashBaseAddr + 0xAAA) = 0x10;
// Polling D2, D6, D7 to determine when completed. // Polling D7 change to "0" after erase complete. while ((*(unsigned char *)FlashBaseAddr) != 0xff);}
int Write_Byte(unsigned int Address, unsigned char data){ unsigned int timeout = 0;
//Unlock command *(unsigned char *)(FlashBaseAddr+0xAAA) = 0xAA; *(unsigned char *)(FlashBaseAddr+0x555) = 0x55; //Setup command *(unsigned char *)(FlashBaseAddr+0xAAA) = 0xA0;
//Write data to destination *(unsigned char *)Address = data; do timeout += 1; while((*(unsigned char *)Address) != data && timeout < 0xffff); if(timeout ==0xffff) return -1; else return 0; // flashnext++;
}
main(){ unsigned int i, Address;
Address = FlashBaseAddr; Init_Emif(); printf("C64x Flash Burn, 8-bit Flash Boot Mode, Write by CHAO\n"); printf("Erasing Flash, Please Waiting……\n"); Chip_Erase(); printf("Reset Flash to Normal Mode\n"); *(unsigned char *)FlashBaseAddr = 0xF0; // Reset Flash to Normal Mode;
printf("Programming Begin Start From 0x64000000, Length = 0x%x; Please Wait Again……\n", hex_CNT ); for(i=0; i<hex_CNT; i++) { if(Write_Byte(Address++, hex[i]) == -1) { printf("Write error at Address: 0x%x\n", Address-1); return; } }
printf("Write Complete Flag\n"); for (i= 0; i<4; i++) Write_Byte(Address++, 0); // Write complete flag;
printf("Flash Burn End, Reset Flash to Normal Mode.\n"); *(unsigned char *)FlashBaseAddr = 0xF0; // Reset Flash to Normal Mode;
printf("Re-Power On the Board.\n"); while(1);}
Tony Tang:
回复 qinbiao yang:
qinbiao yang还有就是感觉芯片的那个Byte引脚,控制8bit,16bit方式的引脚下拉的时候必须是直接接地或者0欧电阻接地啊,不能以太大电阻下拉到地啊!
对于这种情况,你可以量一下电阻上面那端(接地的另一端)的电平到底是多少,是不是没有低于VIL.
qinbiao yang:
回复 Tony Tang:
谢谢回复!我用示波器和万用表多次测量过,测出的电压都是低于VIL的哦!之前也没注意过这种直接接地和电阻下拉到地的区别,或许也不是这个原因导致的工作不正常吧!