本帖最后由 小猫薄薄 于 2014-10-21 14:58 编辑
nandflash的型号是 HY27UF081G2A, 128MB
命令参数如下图
这个芯片的页大小是2k的,修改了固件库中fsmc那部分的代码
写函数如下
uint32_t NAND_WriteBigPage(uint8_t *pBuffer,NAND_ADDRESS Address,uint32_t NumPageToWrite){
uint32_t index = 0x00, numpagewritten = 0x00, addressstatus = NAND_VALID_ADDRESS;
uint32_t status = NAND_READY, size = 0x00;
while((addressstatus == NAND_VALID_ADDRESS) && (status == NAND_READY) && (NumPageToWrite != 0)){
*(__IO uint8_t *)(Bank_NAND_ADDR | CMD_AREA) = NAND_CMD_WRITE0;
*(__IO uint8_t *)(Bank_NAND_ADDR | ADDR_AREA) = 0x00;
*(__IO uint8_t *)(Bank_NAND_ADDR | ADDR_AREA) = 0X00;
*(__IO uint8_t *)(Bank_NAND_ADDR | ADDR_AREA) = ADDR_1st_CYCLE(ROW_ADDRESS);
*(__IO uint8_t *)(Bank_NAND_ADDR | ADDR_AREA) = ADDR_2nd_CYCLE(ROW_ADDRESS);
size = NAND_PAGE_SIZE + (NAND_PAGE_SIZE * numpagewritten); /*ͳ¼ÆдÈëµÄ¸öÊý*/
for(;index < size;index++){
*(__IO uint8_t *)(Bank_NAND_ADDR | DATA_AREA) = pBuffer[index];
}
*(__IO uint8_t *)(Bank_NAND_ADDR | CMD_AREA) = NAND_CMD_WRITE_TRUE1;
status = NAND_GetStatus();//µÃµ½flashµÄµ±Ç°×´Ì¬
if(status == NAND_READY){
numpagewritten++;
NumPageToWrite--;
addressstatus = NAND_AddressIncrement(&Address);
}
}
return (status | addressstatus);
}
读flash的函数如下
uint32_t NAND_ReadBigPage(uint8_t *pBuffer,NAND_ADDRESS Address,uint32_t NumPageToWrite){
uint32_t index = 0x00, numpagewritten = 0x00, addressstatus = NAND_VALID_ADDRESS;
uint32_t status = NAND_READY, size = 0x00;
while((addressstatus == NAND_VALID_ADDRESS) && (NumPageToWrite != 0)){
*(__IO uint8_t *)(Bank_NAND_ADDR | CMD_AREA) = NAND_CMD_AREA_A;
*(__IO uint8_t *)(Bank_NAND_ADDR | ADDR_AREA) = 0x00;
*(__IO uint8_t *)(Bank_NAND_ADDR | ADDR_AREA) = 0X00;
*(__IO uint8_t *)(Bank_NAND_ADDR | ADDR_AREA) = ADDR_1st_CYCLE(ROW_ADDRESS);
*(__IO uint8_t *)(Bank_NAND_ADDR | ADDR_AREA) = ADDR_2nd_CYCLE(ROW_ADDRESS);
*(__IO uint8_t *)(Bank_NAND_ADDR | CMD_AREA) = NAND_CMD_AREA_TRUE1;
while(GPIO_ReadInputDataBit(GPIOG, GPIO_Pin_6) == 0 ){};
size = NAND_PAGE_SIZE + (NAND_PAGE_SIZE * numpagewritten); /*ͳ¼Æ¶Á³öµÄ¸öÊý*/
for(;index < size;index++){
pBuffer[index] = *(__IO uint8_t *)(Bank_NAND_ADDR | DATA_AREA);
}
numpagewritten++;
NumPageToWrite--;
addressstatus = NAND_AddressIncrement(&Address);
}
status = NAND_GetStatus();
return (status | addressstatus);
}
主函数中将一组连续的数列101.102.103.104,........ 写入到第0页中,然后读出来校验,串口显示的结果却是一个固定值。结果如下图
单步调试的时候在单步到写的时候 地址0x70000000中的内容如下图
为什么都是一个数呀
搞了一天多了 实在不知是什么原因,请各位高手帮忙给看下
|