我是将原子哥的f429的nandflash例程移植到f407上的,将要修改的部分都进行修改了,然后烧写程序,并将id打印出出来,结果如下图1:有两个不同的id,而且我觉得两个id都是错的。
下面的是我配置的程序,请各位看看是不是配置哪里错了:
//初始化NAND FLASH
u8 NAND_Init(void)
{
GPIO_InitTypeDef GPIO_Initure;
FSMC_NAND_PCCARDTimingInitTypeDef p;
/* 使能 GPIO 时钟 */
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOD | RCC_AHB1Periph_GPIOE, ENABLE);
/* 使能 FSMC 时钟 */
RCC_AHB3PeriphClockCmd(RCC_AHB3Periph_FSMC, ENABLE);
/* 配置GPIOD */
/*FSMC CLE, ALE, D0->D3, NOE, NWE and NCE2初始化,推挽复用输出*/
GPIO_PinAFConfig(GPIOD, GPIO_PinSource0, GPIO_AF_FSMC);
GPIO_PinAFConfig(GPIOD, GPIO_PinSource1, GPIO_AF_FSMC);
GPIO_PinAFConfig(GPIOD, GPIO_PinSource4, GPIO_AF_FSMC);
GPIO_PinAFConfig(GPIOD, GPIO_PinSource5, GPIO_AF_FSMC);
GPIO_PinAFConfig(GPIOD, GPIO_PinSource7, GPIO_AF_FSMC);
GPIO_PinAFConfig(GPIOD, GPIO_PinSource11, GPIO_AF_FSMC);
GPIO_PinAFConfig(GPIOD, GPIO_PinSource12, GPIO_AF_FSMC);
GPIO_PinAFConfig(GPIOD, GPIO_PinSource14, GPIO_AF_FSMC);
GPIO_PinAFConfig(GPIOD, GPIO_PinSource15, GPIO_AF_FSMC);
GPIO_Initure.GPIO_Pin = GPIO_Pin_0 | GPIO_Pin_1 | GPIO_Pin_4 | GPIO_Pin_5 |
GPIO_Pin_7 | GPIO_Pin_11 |GPIO_Pin_12 | GPIO_Pin_14 | GPIO_Pin_15;
GPIO_Initure.GPIO_Mode = GPIO_Mode_AF;
GPIO_Initure.GPIO_Speed = GPIO_Speed_100MHz;
GPIO_Initure.GPIO_OType = GPIO_OType_PP;
GPIO_Initure.GPIO_PuPd = GPIO_PuPd_UP;
GPIO_Init(GPIOD, &GPIO_Initure);
/* GPIOE configuration */
GPIO_PinAFConfig(GPIOE, GPIO_PinSource7 , GPIO_AF_FSMC);
GPIO_PinAFConfig(GPIOE, GPIO_PinSource8 , GPIO_AF_FSMC);
GPIO_PinAFConfig(GPIOE, GPIO_PinSource9 , GPIO_AF_FSMC);
GPIO_PinAFConfig(GPIOE, GPIO_PinSource10 , GPIO_AF_FSMC);
GPIO_Initure.GPIO_Pin = GPIO_Pin_7 |GPIO_Pin_8 | GPIO_Pin_9 | GPIO_Pin_10 ;
GPIO_Initure.GPIO_Mode = GPIO_Mode_AF;
GPIO_Initure.GPIO_Speed = GPIO_Speed_100MHz;
GPIO_Initure.GPIO_OType = GPIO_OType_PP;
GPIO_Initure.GPIO_PuPd = GPIO_PuPd_UP;
GPIO_Init(GPIOE, &GPIO_Initure);
/* 配置GPIOD, PD6作为忙信息,配置为输入 */
/* INT2 引脚配置为内部上来输入,用于忙信号 */
GPIO_Initure.GPIO_Pin = GPIO_Pin_6;
GPIO_Initure.GPIO_Mode = GPIO_Mode_IN;
GPIO_Initure.GPIO_Speed = GPIO_Speed_100MHz;
GPIO_Initure.GPIO_OType = GPIO_OType_OD;
GPIO_Initure.GPIO_PuPd = GPIO_PuPd_UP;
GPIO_Init(GPIOD, &GPIO_Initure);
/* 配置 FSMC 时序 */
p.FSMC_SetupTime = 2; //建立时间
p.FSMC_WaitSetupTime = 3; //等待时间
p.FSMC_HoldSetupTime = 2; //保持时间
p.FSMC_HiZSetupTime = 1; //高阻建立时间
FSMC_NANDInitStructure.FSMC_Bank=FSMC_Bank3_NAND; //NAND挂在BANK3上
FSMC_NANDInitStructure.FSMC_Waitfeature=FSMC_Waitfeature_Disable; //关闭等待特性
FSMC_NANDInitStructure.FSMC_MemoryDataWidth=FSMC_MemoryDataWidth_8b; //8位数据宽度
FSMC_NANDInitStructure.FSMC_ECC=FSMC_ECC_Disable; //不使用ECC
FSMC_NANDInitStructure.FSMC_ECCPageSize=FSMC_ECCPageSize_2048Bytes; //ECC页大小为2k
FSMC_NANDInitStructure.FSMC_TCLRSetupTime=0; //设置TCLR(tCLR=CLE到RE的延时)=(TCLR+TSET+2)*THCLK,THCLK=1/180M=5.5ns
FSMC_NANDInitStructure.FSMC_TARSetupTime=1; //设置TAR(tAR=ALE到RE的延时)=(TAR+TSET+2)*THCLK,THCLK=1/180M=5.5n。
FSMC_NANDInitStructure.FSMC_CommonSpaceTimingStruct = &p; /* FSMC Common Space Timing */
FSMC_NANDInitStructure.FSMC_AttributeSpaceTimingStruct = &p; /* FSMC Attribute Space Timing */
FSMC_NANDInit(&FSMC_NANDInitStructure);
/* FSMC NAND Bank 使能 */
FSMC_NANDCmd(FSMC_Bank3_NAND, ENABLE);
NAND_Reset(); //复位NAND
delay_ms(100);
nand_dev.id=NAND_ReadID(); //读取ID
NAND_ModeSet(4); //设置为MODE4,高速模式
if(nand_dev.id==MT29F16G08ABABA) //NAND为MT29F16G08ABABA
{
nand_dev.page_totalsize=4320; //nand一个page的总大小(包括spare区)
nand_dev.page_mainsize=4096; //nand一个page的有效数据区大小
nand_dev.page_sparesize=224; //nand一个page的spare区大小
nand_dev.block_pagenum=128; //nand一个block所包含的page数目
nand_dev.plane_blocknum=2048; //nand一个plane所包含的block数目
nand_dev.block_totalnum=4096; //nand的总block数目
}
else if(nand_dev.id==MT29F4G08ABADA)//NAND为MT29F4G08ABADA
{
nand_dev.page_totalsize=2112; //nand一个page的总大小(包括spare区)
nand_dev.page_mainsize=2048; //nand一个page的有效数据区大小
nand_dev.page_sparesize=64; //nand一个page的spare区大小
nand_dev.block_pagenum=64; //nand一个block所包含的page数目
nand_dev.plane_blocknum=2048; //nand一个plane所包含的block数目
nand_dev.block_totalnum=4096; //nand的总block数目
}
else if(nand_dev.id==MT29F8G08ABACAWP)//NAND为MT29F8G08ABACAWP
{
nand_dev.page_totalsize=4320;
nand_dev.page_mainsize=4096;
nand_dev.page_sparesize=224;
nand_dev.block_pagenum=64;
nand_dev.plane_blocknum=2048;
nand_dev.block_totalnum=4096;
}
else return 1; //错误,返回
return 0;
}
一周热门 更多>