2024-05-21 11:22 PM
Hi all,
I want to access a NandFlash(H27U1G8F2B) chip which is extended by STM32F429BI's FMC;
According the datasheet, seems the default value after erase is '1' for each bit.
But I read the value by program is '0':
My test code as below:
#define TEST_NUM 97
NAND_FLASH_STA_t NAND_FLASH_test(void)
{
HAL_StatusTypeDef hal_sta = HAL_OK;
NAND_IDTypeDef nand_id = {0};
uint8_t buf[PAGE_SIZE] = {0};
hal_sta = HAL_NAND_Reset(&hnand1);
if(hal_sta == HAL_OK) {
NAND_FLASH_DBG("nand flash reset OK\n");
} else {
NAND_FLASH_ERR("nand flash reset err[%d]\n", hal_sta);
return NAND_FLASH_RESET_ERR;
}
// read ID (0xADF1001D for H27U1G8F2BTR) // 0xADDC9095 for H27U4G8F2ETR
hal_sta = HAL_NAND_Read_ID(&hnand1, &nand_id);
if(hal_sta == HAL_OK) {
NAND_FLASH_DBG("nand flash id[0x%02x%02x%02x%02x]\n", nand_id.Maker_Id, nand_id.Device_Id, nand_id.Third_Id, nand_id.Fourth_Id);
} else {
NAND_FLASH_ERR("read nand flash id err[%d]\n", hal_sta);
return NAND_FLASH_READ_ID_ERR;
}
NAND_AddressTypeDef nandAddr = {.Page = 0, .Block = BLOCK_NUM-1, .Plane = 0}; // last block
hal_sta = HAL_NAND_Erase_Block(&hnand1, &nandAddr);
if(hal_sta == HAL_OK) {
NAND_FLASH_DBG("erase nand flash OK\n");
} else {
NAND_FLASH_ERR("erase nand flash err[%d]\n", hal_sta);
return NAND_FLASH_ERASE_BLOCK_ERR;
}
memset(buf, 0xff, PAGE_SIZE);
hal_sta = HAL_NAND_Read_Page_8b(&hnand1, &nandAddr, buf, 1);
if(hal_sta == HAL_OK) {
NAND_FLASH_DBG("read nand flash after erase OK\n");
} else {
NAND_FLASH_ERR("read nand flash after erase err[%d]\n", hal_sta);
return NAND_FLASH_READ_ERR;
}
#if 1 // print the data
NAND_FLASH_DBG("\nread data after erase:\n");
for(uint8_t i = 0; i < 100; i++) {
if((i != 0) && (i % 10 == 0)) {
NAND_FLASH_DBG("\n");
HAL_Delay(20);
}
NAND_FLASH_DBG(" %02x", buf[i]);
}
NAND_FLASH_DBG("\n\n");
#endif
for(uint16_t i = 0; i < PAGE_SIZE; i++) {
buf[i] = i % TEST_NUM;
}
hal_sta = HAL_NAND_Write_Page_8b(&hnand1, &nandAddr, buf, 1);
if(hal_sta == HAL_OK) {
NAND_FLASH_DBG("write nand flash OK\n");
} else {
NAND_FLASH_ERR("write nand flash err[%d]\n", hal_sta);
return NAND_FLASH_WRITE_ERR;
}
memset(buf, 0, PAGE_SIZE);
hal_sta = HAL_NAND_Read_Page_8b(&hnand1, &nandAddr, buf, 1);
if(hal_sta == HAL_OK) {
NAND_FLASH_DBG("read nand flash after write OK\n");
} else {
NAND_FLASH_ERR("read nand flash after write err[%d]\n", hal_sta);
return NAND_FLASH_READ_ERR;
}
for(uint16_t i = 0; i < PAGE_SIZE; i++) {
#if 1 // print the data
if(i % 16 == 0) {
NAND_FLASH_DBG("\n %03d:", i / 16 + 1);
HAL_Delay(50);
}
NAND_FLASH_DBG(" %02x(%02x)", buf[i], i % TEST_NUM);
#endif
if(buf[i] != (i % TEST_NUM)) {
NAND_FLASH_ERR("\nread buf[%d] err[0x%02x 0x%02x]\n", i, buf[i], i % TEST_NUM);
return NAND_FLASH_CHECK_ERR;
}
}
NAND_FLASH_DBG("\n");
return NAND_FLASH_STA_OK;
}
You can check the LOG that I can read/write the NandFlash normally.
Thanks for your help!
2024-05-22 12:24 AM
Typically bytes in the page will be 0xFF
Does it read the JEDEC ID properly?
You could also try interacting with the NAND directly on the FMC rather than with the library. Confirm it is wired correctly and responsive to queries and commands.
2024-05-22 02:22 AM
Thanks for your reply!
> Does it read the JEDEC ID properly?
Yes, the NandFlash's ID is 0xADF1001D from the datasheet.
> You could also try interacting with the NAND directly on the FMC rather than with the library. Confirm it is wired correctly and responsive to queries and commands.
I don't know how to interacting with the NAND directly with the FMC, is there some document or demo? (BTW, because I can write and read the NAND by HAL library successfully, that's mean the wire is connected correctly, yes?)
Thanks again for your help!