新手上路
- 积分
- 36
- 金钱
- 36
- 注册时间
- 2022-4-29
- 在线时间
- 8 小时
|
按照正点原子的例程修改引脚配置,如图是硬件连接原理图。 与例程唯一不同的是NCE3引脚和NWAIT引脚,我将案例中这两个引脚(NCE3:PG9 NWAITD6)都改成实际使用中的引脚(NCE3:PC8 NWAITC6),代码下到板子上就识别不到芯片,读出的ID是NAND ID:0xffffffff。 找了好久都没找到原因,大家帮忙看看,不胜感激!
配置的代码如下:
在nand.c中
//初始化NAND FLASH
u8 NAND_Init(void)
{
FMC_NAND_PCC_TimingTypeDef ComSpaceTiming,AttSpaceTiming;
NAND_MPU_Config();
NAND_Handler.Instance=FMC_Bank3;
NAND_Handler.Init.NandBank=FMC_NAND_BANK3; //NAND挂在BANK3上
NAND_Handler.Init.Waitfeature=FMC_NAND_PCC_WAIT_FEATURE_DISABLE; //关闭等待特性
NAND_Handler.Init.MemoryDataWidth=FMC_NAND_PCC_MEM_BUS_WIDTH_8; //8位数据宽度
NAND_Handler.Init.EccComputation=FMC_NAND_ECC_DISABLE; //禁止ECC
NAND_Handler.Init.ECCPageSize=FMC_NAND_ECC_PAGE_SIZE_512BYTE; //ECC页大小为512字节
NAND_Handler.Init.TCLRSetupTime=10; //设置TCLR(tCLR=CLE到RE的延时)=(TCLR+TSET+2)*THCLK,THCLK=1/200M=5ns
NAND_Handler.Init.TARSetupTime=10; //设置TAR(tAR=ALE到RE的延时)=(TAR+TSET+1)*THCLK,THCLK=1/200M=5n。
ComSpaceTiming.SetupTime=10; //建立时间
ComSpaceTiming.WaitSetupTime=10; //等待时间
ComSpaceTiming.HoldSetupTime=10; //保持时间
ComSpaceTiming.HiZSetupTime=10; //高阻态时间
AttSpaceTiming.SetupTime=10; //建立时间
AttSpaceTiming.WaitSetupTime=10; //等待时间
AttSpaceTiming.HoldSetupTime=10; //保持时间
AttSpaceTiming.HiZSetupTime=10; //高阻态时间
HAL_NAND_Init(&NAND_Handler,&ComSpaceTiming,&AttSpaceTiming);
NAND_Reset(); //复位NAND
delay_ms(100);
nand_dev.id=NAND_ReadID(); //读取ID
printf("NAND ID:%#x\r\n",nand_dev.id);
NAND_ModeSet(4); //设置为MODE4,高速模式
if(nand_dev.id==MT29F4G08ABADA)//NAND为MT29F4G08ABADA
{
nand_dev.page_totalsize=2112;
nand_dev.page_mainsize=2048;
nand_dev.page_sparesize=64;
nand_dev.block_pagenum=64;
nand_dev.plane_blocknum=2048;
nand_dev.block_totalnum=4096;
}else return 1; //错误,返回
return 0;
}
//NAND FALSH底层驱动,引脚配置,时钟使能
//此函数会被HAL_NAND_Init()调用
void HAL_NAND_MspInit(NAND_HandleTypeDef *hnand)
{
GPIO_InitTypeDef GPIO_Initure;
__HAL_RCC_FMC_CLK_ENABLE(); //使能FMC时钟
__HAL_RCC_GPIOC_CLK_ENABLE(); //使能GPIOG时钟
__HAL_RCC_GPIOD_CLK_ENABLE(); //使能GPIOD时钟
__HAL_RCC_GPIOE_CLK_ENABLE(); //使能GPIOE时钟
//初始化PC6 R/B引脚
/* GPIO_InitStruct */
GPIO_Initure.Pin = GPIO_PIN_6;
GPIO_Initure.Mode = GPIO_MODE_INPUT;
GPIO_Initure.Pull = GPIO_PULLUP;
GPIO_Initure.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
HAL_GPIO_Init(GPIOC, &GPIO_Initure);
//初始化PC8 NCE3引脚
GPIO_Initure.Pin = GPIO_PIN_8;
GPIO_Initure.Mode = GPIO_MODE_AF_PP;
GPIO_Initure.Pull = GPIO_NOPULL;
GPIO_Initure.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
GPIO_Initure.Alternate = GPIO_AF12_FMC;
HAL_GPIO_Init(GPIOC, &GPIO_Initure);
/* GPIO_InitStruct */
GPIO_Initure.Pin = GPIO_PIN_11|GPIO_PIN_12;
GPIO_Initure.Mode = GPIO_MODE_AF_PP;
GPIO_Initure.Pull = GPIO_NOPULL;
GPIO_Initure.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
HAL_GPIO_Init(GPIOD, &GPIO_Initure);
/* GPIO_InitStruct */
GPIO_Initure.Pin = GPIO_PIN_14|GPIO_PIN_15|GPIO_PIN_0|GPIO_PIN_1
|GPIO_PIN_4|GPIO_PIN_5;
GPIO_Initure.Mode = GPIO_MODE_AF_PP;
GPIO_Initure.Pull = GPIO_NOPULL;
GPIO_Initure.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
GPIO_Initure.Alternate = GPIO_AF12_FMC;
HAL_GPIO_Init(GPIOD, &GPIO_Initure);
//初始化PE7,8,9,10
GPIO_Initure.Pin = GPIO_PIN_7|GPIO_PIN_8|GPIO_PIN_9|GPIO_PIN_10;
GPIO_Initure.Mode = GPIO_MODE_AF_PP;
GPIO_Initure.Pull = GPIO_NOPULL;
GPIO_Initure.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
GPIO_Initure.Alternate = GPIO_AF12_FMC;
HAL_GPIO_Init(GPIOE, &GPIO_Initure);
}
在nand.h中也修改了#define NAND_RB HAL_GPIO_ReadPin(GPIOC,GPIO_PIN_6)//NAND Flash的闲/忙引脚
|
|