项目中用到了 STM32F429+NAND FLASH (A5U4GA31ATS) 配置FMC接口以及GPIO后,无法正确读出 NAND 的ID,程序如下,请高人指点迷津。
[mw_shl_code=c,true]/* NAND FLASH area definition */
#define CMD_AREA (uint32_t) (1<<17) /*A17 CLE =hige*/
#define ADDR_AREA (uint32_t) (1<<16) /*A16 ALE = hige*/
#define DATA_AREA ((uint32_t)0x00000000)
/* NAND FLASH 的物理地址 定义*/
#define Bank2_NAND_ADDR ((uint32_t)0x70000000)
#define Bank_NAND_ADDR Bank2_NAND_ADDR
/* NAND FLASH 操作的3个宏*/
#define NAND_CMD_AREA *(__IO uint8_t *) (Bank_NAND_ADDR |CMD_AREA)
#define NAND_ADDR_AREA *(__IO uint8_t *) (Bank_NAND_ADDR |ADDR_AREA)
#define NAND_DATA_AREA *(__IO uint8_t *) (Bank_NAND_ADDR |DATA_AREA)
#define ADDR_1st_CYCLE(ADDR) (uint8_t)((ADDR)& 0xFF) /* 1st addressing cycle */
#define ADDR_2nd_CYCLE(ADDR) (uint8_t)(((ADDR)& 0xFF00) >> 8) /* 2nd addressing cycle */
#define ADDR_3rd_CYCLE(ADDR) (uint8_t)(((ADDR)& 0xFF0000) >> 16) /* 3rd addressing cycle */
#define ADDR_4th_CYCLE(ADDR) (uint8_t)(((ADDR)& 0xFF000000) >> 24) /* 4th addressing cycle */
/**********************************************************************************************/
NAND_IDTypeDef NAND_ID;
/**********************************************************************************************/
/*
** NAND FLASH 的 FMC 和GPIO 的初始化
**
*/
void FMC_NAND_Init(void)
{
/*
FMC_D0 PD14
FMC_D1 PD15
FMC_D2 PD0
FMC_D3 PD1
FMC_D4 PE7
FMC_D5 PE8
FMC_D6 PE9
FMC_D7 PE10
FMC_NOE PD4
FMC_NCE2 PD7
FMC_NWE PD5
FMC_WAIT PD6
WP PD3
CLE PD12(A17)
ALE PD11(A16)
*/
GPIO_InitTypeDef GPIO_InitStruct;
FMC_NANDInitTypeDef FMC_NANDInitStruct;
FMC_NAND_PCCARDTimingInitTypeDef p;
/* 使能 GPIO 时钟 */
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOD | RCC_AHB1Periph_GPIOE, ENABLE);
/* 使能 FMC 时钟 */
RCC_AHB3PeriphClockCmd(RCC_AHB3Periph_FMC, ENABLE);
/* 配置GPIOD */
GPIO_PinAFConfig(GPIOD, GPIO_PinSource0, GPIO_AF_FMC);
GPIO_PinAFConfig(GPIOD, GPIO_PinSource1, GPIO_AF_FMC);
GPIO_PinAFConfig(GPIOD, GPIO_PinSource4, GPIO_AF_FMC);
GPIO_PinAFConfig(GPIOD, GPIO_PinSource5, GPIO_AF_FMC);
GPIO_PinAFConfig(GPIOD, GPIO_PinSource7, GPIO_AF_FMC);
GPIO_PinAFConfig(GPIOD, GPIO_PinSource11, GPIO_AF_FMC);
GPIO_PinAFConfig(GPIOD, GPIO_PinSource12, GPIO_AF_FMC);
GPIO_PinAFConfig(GPIOD, GPIO_PinSource14, GPIO_AF_FMC);
GPIO_PinAFConfig(GPIOD, GPIO_PinSource15, GPIO_AF_FMC);
GPIO_InitStruct.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_InitStruct.GPIO_Mode = GPIO_Mode_AF;
GPIO_InitStruct.GPIO_Speed = GPIO_Speed_100MHz;
GPIO_InitStruct.GPIO_OType = GPIO_OType_PP;
GPIO_InitStruct.GPIO_PuPd = GPIO_PuPd_NOPULL;
GPIO_Init(GPIOD, &GPIO_InitStruct);
/* 配置GPIOE */
GPIO_PinAFConfig(GPIOE, GPIO_PinSource7, GPIO_AF_FMC);
GPIO_PinAFConfig(GPIOE, GPIO_PinSource8, GPIO_AF_FMC);
GPIO_PinAFConfig(GPIOE, GPIO_PinSource9, GPIO_AF_FMC);
GPIO_PinAFConfig(GPIOE, GPIO_PinSource10, GPIO_AF_FMC);
GPIO_InitStruct.GPIO_Pin = GPIO_Pin_7 | GPIO_Pin_8 | GPIO_Pin_9 | GPIO_Pin_10;
GPIO_InitStruct.GPIO_Mode = GPIO_Mode_AF;
GPIO_InitStruct.GPIO_Speed = GPIO_Speed_100MHz;
GPIO_InitStruct.GPIO_OType = GPIO_OType_PP;
GPIO_InitStruct.GPIO_PuPd = GPIO_PuPd_NOPULL;
GPIO_Init(GPIOE, &GPIO_InitStruct);
/* 配置GPIOD, PD6作为忙信息,配置为输入 */
/* INT2 引脚配置为内部上来输入,用于忙信号 */
GPIO_InitStruct.GPIO_Pin = GPIO_Pin_6;
GPIO_InitStruct.GPIO_Mode = GPIO_Mode_IN;
GPIO_InitStruct.GPIO_Speed = GPIO_Speed_100MHz;
GPIO_InitStruct.GPIO_OType = GPIO_OType_OD;
GPIO_InitStruct.GPIO_PuPd = GPIO_PuPd_UP;
GPIO_Init(GPIOD, &GPIO_InitStruct);
/* 配置GPIOD, PD3作为写保护,配置为输出 */
GPIO_InitStruct.GPIO_Pin = GPIO_Pin_3;
GPIO_InitStruct.GPIO_Mode = GPIO_Mode_OUT;
GPIO_InitStruct.GPIO_Speed = GPIO_Speed_100MHz;
GPIO_InitStruct.GPIO_OType = GPIO_OType_PP;
GPIO_InitStruct.GPIO_PuPd = GPIO_PuPd_UP;
GPIO_Init(GPIOD, &GPIO_InitStruct);
GPIO_SetBits(GPIOD,GPIO_Pin_3); //禁止写保护
/* 配置 FSMC 时序 */
p.FMC_SetupTime = 1;
p.FMC_WaitSetupTime = 3;
p.FMC_HoldSetupTime = 2;
p.FMC_HiZSetupTime = 1;
FMC_NANDInitStruct.FMC_Bank = FMC_Bank2_NAND;
FMC_NANDInitStruct.FMC_Waitfeature =FMC_Waitfeature_Disable;
FMC_NANDInitStruct.FMC_MemoryDataWidth =FMC_NAND_MemoryDataWidth_8b;
FMC_NANDInitStruct.FMC_ECC = FMC_ECC_Enable;
FMC_NANDInitStruct.FMC_ECCPageSize = FMC_ECCPageSize_2048Bytes;
FMC_NANDInitStruct.FMC_TCLRSetupTime = 0;
FMC_NANDInitStruct.FMC_TARSetupTime = 0;
FMC_NANDInitStruct.FMC_CommonSpaceTimingStruct = &p;
FMC_NANDInitStruct.FMC_AttributeSpaceTimingStruct = &p;
FMC_NANDInit(&FMC_NANDInitStruct);
FMC_NANDCmd(FMC_Bank2_NAND,ENABLE);
}
/*
*********************************************************************************************************
* 函 数 名: NAND_ReadID
* 功能说明: 读NAND Flash的ID。ID存储到形参指定的结构体变量中。
* 形 参: 无
* 返 回 值: 32bit的NAND Flash ID
*********************************************************************************************************
*/
uint32_t NAND_ReadID(void)
{
/* 发送命令 Command to the command area */
NAND_CMD_AREA = 0x90;
NAND_ADDR_AREA = 0x00;
/* 顺序读取NAND Flash的ID */
data = *(__IO uint32_t *)(Bank_NAND_ADDR | DATA_AREA);
NAND_ID.Maker_ID = ADDR_1st_CYCLE (data);//四个周期读取四个ID
NAND_ID.Device_ID = ADDR_2nd_CYCLE (data);
NAND_ID.Third_ID = ADDR_3rd_CYCLE (data);
NAND_ID.Fourth_ID = ADDR_4th_CYCLE (data);
return data;
}[/mw_shl_code]
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
原因很让人纠结~~~~~~~
一周热门 更多>