21ic问答首页 - GD32H759 搭载NANDFLASH(MT29F4G08ABADA)开发,跪求指导。
GD32H759 搭载NANDFLASH(MT29F4G08ABADA)开发,跪求指导。
23561740122024-03-14
nand flash 复位正常,但id读不对,读出来的错误ID有(0xffffffff\xe0e0e0e0\0x80808080)这几个,但总是读不出正确的ID。各种时序都设置过了,都读不对。代码和图纸如下:
NAND_Init(void)
{
exmc_nand_parameter_struct exmc_nand_init_struct;
exmc_nand_timing_parameter_struct nand_common_space_timing;
exmc_nand_timing_parameter_struct nand_attribute_space_timing;
exmc_nand_struct_para_init(&exmc_nand_init_struct);
// exmc_nand_deinit();
/* enable EXMC clock */
rcu_periph_clock_enable(RCU_EXMC);
rcu_periph_clock_enable(RCU_GPIOD);
rcu_periph_clock_enable(RCU_GPIOE);
/*NWAIT(PD6)输入*/
gpio_af_set(GPIOD, GPIO_AF_12, GPIO_PIN_6);
gpio_mode_set(GPIOD, GPIO_MODE_INPUT, GPIO_PUPD_NONE, GPIO_PIN_6);
// gpio_output_options_set(GPIOD, GPIO_OTYPE_PP, GPIO_OSPEED_60MHZ, GPIO_PIN_6 );
/* NCE(PD7) pin configuration */
gpio_af_set(GPIOD, GPIO_AF_12, GPIO_PIN_7);
gpio_mode_set(GPIOD, GPIO_MODE_AF, GPIO_PUPD_PULLUP, GPIO_PIN_7);
gpio_output_options_set(GPIOD, GPIO_OTYPE_PP, GPIO_OSPEED_60MHZ, GPIO_PIN_7);
/* D2(PD0),D3(PD1),NOE(PD4),NWE(PD5),CLE(PD11),ALE(PD12),D0(PD14),D1(PD15), pin configuration */
gpio_af_set(GPIOD, GPIO_AF_12, GPIO_PIN_0 | GPIO_PIN_1 | GPIO_PIN_4 |GPIO_PIN_5 |GPIO_PIN_11 |GPIO_PIN_12 |GPIO_PIN_14 | GPIO_PIN_15);
gpio_mode_set(GPIOD, GPIO_MODE_AF, GPIO_PUPD_NONE, GPIO_PIN_0 | GPIO_PIN_1 | GPIO_PIN_4 | GPIO_PIN_5 |GPIO_PIN_11 |GPIO_PIN_12| GPIO_PIN_14 | GPIO_PIN_15);
gpio_output_options_set(GPIOD, GPIO_OTYPE_PP, GPIO_OSPEED_60MHZ, GPIO_PIN_0 | GPIO_PIN_1 | GPIO_PIN_4 |GPIO_PIN_5 |GPIO_PIN_11 |GPIO_PIN_12| GPIO_PIN_14 | GPIO_PIN_15);
/* D4(PE7),D5(PE8),D6(PE9),D7(PE10)pin configuration */
gpio_af_set(GPIOE, GPIO_AF_12, GPIO_PIN_7 | GPIO_PIN_8 | GPIO_PIN_9 | GPIO_PIN_10 );
gpio_mode_set(GPIOE, GPIO_MODE_AF, GPIO_PUPD_NONE, GPIO_PIN_7 | GPIO_PIN_8 | GPIO_PIN_9 | GPIO_PIN_10 );
gpio_output_options_set(GPIOE, GPIO_OTYPE_PP, GPIO_OSPEED_60MHZ, GPIO_PIN_7 | GPIO_PIN_8 | GPIO_PIN_9 | GPIO_PIN_10 );
exmc_nand_init_struct.atr_latency = 4; //2,3,6 ,7
exmc_nand_init_struct.ctr_latency = 4;/*至少10ns. 设置 TCLR(tCLR=CLE 到 RE 的延时)=(TCLR+TSET+2)*THCLK,THCLK=1/300M=3.3ns */
exmc_nand_init_struct.databus_width = EXMC_NAND_DATABUS_WIDTH_8B;//8位数据宽度
exmc_nand_init_struct.ecc_size = EXMC_ECC_SIZE_512BYTES;
exmc_nand_init_struct.ecc_logic = DISABLE;//不使用ECC
exmc_nand_init_struct.wait_feature = DISABLE;//关闭等待特性
nand_common_space_timing.setuptime = 10;
nand_common_space_timing.waittime = 10;
nand_common_space_timing.holdtime = 10;
nand_common_space_timing.databus_hiztime = 10;
nand_attribute_space_timing.setuptime =10;
nand_attribute_space_timing.waittime = 10;
nand_attribute_space_timing.holdtime = 10;
nand_attribute_space_timing.databus_hiztime = 10;
exmc_nand_init_struct.common_space_timing = &nand_common_space_timing; // NAND 通用存储器空间时序
exmc_nand_init_struct.attribute_space_timing = &nand_attribute_space_timing;
exmc_nand_init(&exmc_nand_init_struct);
exmc_nand_enable();
if(NAND_Reset()== 0) //复位NAND
printf("复位成功.\r\n");
delay_1ms(100);
nand_dev.id = NAND_ReadID(); //读取ID
printf("NAND ID:%#x\r\n",nand_dev.id);
if(NAND_ModeSet(4)==0) //设置为MODE4,高速模式
printf("模式设置成功.\r\n");
if(nand_dev.id==MT29F4G08ABADA) //NAND为MT29F16G08ABABA
{
nand_dev.page_totalsize=2112;
nand_dev.page_mainsize=2048;//每个page =2k+64BYTE
nand_dev.page_sparesize=64;
nand_dev.block_pagenum=64;//每个block中page数
nand_dev.plane_blocknum=2048;//每个plane中block数
nand_dev.block_totalnum=4096; //总共的block数
}else return ERROR; //错误,返回
return SUCCESS;
}
NAND_Init(void)
{
exmc_nand_parameter_struct exmc_nand_init_struct;
exmc_nand_timing_parameter_struct nand_common_space_timing;
exmc_nand_timing_parameter_struct nand_attribute_space_timing;
exmc_nand_struct_para_init(&exmc_nand_init_struct);
// exmc_nand_deinit();
/* enable EXMC clock */
rcu_periph_clock_enable(RCU_EXMC);
rcu_periph_clock_enable(RCU_GPIOD);
rcu_periph_clock_enable(RCU_GPIOE);
/*NWAIT(PD6)输入*/
gpio_af_set(GPIOD, GPIO_AF_12, GPIO_PIN_6);
gpio_mode_set(GPIOD, GPIO_MODE_INPUT, GPIO_PUPD_NONE, GPIO_PIN_6);
// gpio_output_options_set(GPIOD, GPIO_OTYPE_PP, GPIO_OSPEED_60MHZ, GPIO_PIN_6 );
/* NCE(PD7) pin configuration */
gpio_af_set(GPIOD, GPIO_AF_12, GPIO_PIN_7);
gpio_mode_set(GPIOD, GPIO_MODE_AF, GPIO_PUPD_PULLUP, GPIO_PIN_7);
gpio_output_options_set(GPIOD, GPIO_OTYPE_PP, GPIO_OSPEED_60MHZ, GPIO_PIN_7);
/* D2(PD0),D3(PD1),NOE(PD4),NWE(PD5),CLE(PD11),ALE(PD12),D0(PD14),D1(PD15), pin configuration */
gpio_af_set(GPIOD, GPIO_AF_12, GPIO_PIN_0 | GPIO_PIN_1 | GPIO_PIN_4 |GPIO_PIN_5 |GPIO_PIN_11 |GPIO_PIN_12 |GPIO_PIN_14 | GPIO_PIN_15);
gpio_mode_set(GPIOD, GPIO_MODE_AF, GPIO_PUPD_NONE, GPIO_PIN_0 | GPIO_PIN_1 | GPIO_PIN_4 | GPIO_PIN_5 |GPIO_PIN_11 |GPIO_PIN_12| GPIO_PIN_14 | GPIO_PIN_15);
gpio_output_options_set(GPIOD, GPIO_OTYPE_PP, GPIO_OSPEED_60MHZ, GPIO_PIN_0 | GPIO_PIN_1 | GPIO_PIN_4 |GPIO_PIN_5 |GPIO_PIN_11 |GPIO_PIN_12| GPIO_PIN_14 | GPIO_PIN_15);
/* D4(PE7),D5(PE8),D6(PE9),D7(PE10)pin configuration */
gpio_af_set(GPIOE, GPIO_AF_12, GPIO_PIN_7 | GPIO_PIN_8 | GPIO_PIN_9 | GPIO_PIN_10 );
gpio_mode_set(GPIOE, GPIO_MODE_AF, GPIO_PUPD_NONE, GPIO_PIN_7 | GPIO_PIN_8 | GPIO_PIN_9 | GPIO_PIN_10 );
gpio_output_options_set(GPIOE, GPIO_OTYPE_PP, GPIO_OSPEED_60MHZ, GPIO_PIN_7 | GPIO_PIN_8 | GPIO_PIN_9 | GPIO_PIN_10 );
exmc_nand_init_struct.atr_latency = 4; //2,3,6 ,7
exmc_nand_init_struct.ctr_latency = 4;/*至少10ns. 设置 TCLR(tCLR=CLE 到 RE 的延时)=(TCLR+TSET+2)*THCLK,THCLK=1/300M=3.3ns */
exmc_nand_init_struct.databus_width = EXMC_NAND_DATABUS_WIDTH_8B;//8位数据宽度
exmc_nand_init_struct.ecc_size = EXMC_ECC_SIZE_512BYTES;
exmc_nand_init_struct.ecc_logic = DISABLE;//不使用ECC
exmc_nand_init_struct.wait_feature = DISABLE;//关闭等待特性
nand_common_space_timing.setuptime = 10;
nand_common_space_timing.waittime = 10;
nand_common_space_timing.holdtime = 10;
nand_common_space_timing.databus_hiztime = 10;
nand_attribute_space_timing.setuptime =10;
nand_attribute_space_timing.waittime = 10;
nand_attribute_space_timing.holdtime = 10;
nand_attribute_space_timing.databus_hiztime = 10;
exmc_nand_init_struct.common_space_timing = &nand_common_space_timing; // NAND 通用存储器空间时序
exmc_nand_init_struct.attribute_space_timing = &nand_attribute_space_timing;
exmc_nand_init(&exmc_nand_init_struct);
exmc_nand_enable();
if(NAND_Reset()== 0) //复位NAND
printf("复位成功.\r\n");
delay_1ms(100);
nand_dev.id = NAND_ReadID(); //读取ID
printf("NAND ID:%#x\r\n",nand_dev.id);
if(NAND_ModeSet(4)==0) //设置为MODE4,高速模式
printf("模式设置成功.\r\n");
if(nand_dev.id==MT29F4G08ABADA) //NAND为MT29F16G08ABABA
{
nand_dev.page_totalsize=2112;
nand_dev.page_mainsize=2048;//每个page =2k+64BYTE
nand_dev.page_sparesize=64;
nand_dev.block_pagenum=64;//每个block中page数
nand_dev.plane_blocknum=2048;//每个plane中block数
nand_dev.block_totalnum=4096; //总共的block数
}else return ERROR; //错误,返回
return SUCCESS;
}
您需要登录后才可以回复 登录 | 注册