Hi, there; I am using stm32u575zit6 to make a demo, I configured the threadx/filex/levelx for the system as I would like to have the filex on nand flash W25N01GVZEIG. Here I met a strange issues for the files opeations, I debugged for weeks, but I cannot figure it out. Here is the description
1: I can successfully open/write/read/close the files
2: I am sure that when I wrote into the file, it was written into the nand flash and made sure it was wirtting sucessfully as I read it back to confirm in nand flash driver level
3: But when I reopen the files to read out , I found the files are still old ones.
4: the nand driver is writted with reference to the examples of the Fx_Dual_Instance
Is it possible the stcubemx configuration issues or my driver's issues?
thank you Chengtao
The nand driver is as the following:
u8 NAND_ReadPage(u32 PageNum,u16 start,u8 *destination,ULONG words)
{
u8 ret = 0;
u16 load_len;
flashPageRead(&spi_flash, PageNum);
// Addr is column address
flashDataBuffer[0] = W25X_ReadData;
flashDataBuffer[1] = (start>>8) & 0xFF;
flashDataBuffer[2] = start & 0xFF;
flashDataBuffer[3] = 0x0;
load_len = words+4;
sendFlashCommand(&spi_flash,(void *)flashDataBuffer,load_len);
load_len = 4;
memcpy(destination,&flashDataBuffer[load_len],words);
return ret;
}
u8 NAND_WritePage(u32 PageNum,u16 start,u8* source,ULONG words)
{
u8 ret = 0;
u16 load_len;
flashDataBuffer[0] = W25X_WriteEnable;
sendFlashCommand(&spi_flash,(void *)flashDataBuffer,1);
//Load Data to column adress
flashDataBuffer[0] = W25X_LoadProgramData;
flashDataBuffer[1] = (start>>8) & 0xFF;
flashDataBuffer[2] = start & 0xFF;
load_len = 3;
memcpy(&flashDataBuffer[load_len],source,words);
load_len += words;
sendFlashCommand(&spi_flash,(void *)flashDataBuffer,load_len);
//Program the page address
flashDataBuffer[0] = W25X_ProgramExcute;
flashDataBuffer[1] = 0x0;
flashDataBuffer[2] = (PageNum>>8) & 0xFF;
flashDataBuffer[3] = PageNum & 0xFF;
sendFlashCommand(&spi_flash,(void *)flashDataBuffer,4);
flashWaitBusy(&spi_flash,100);
flashDataBuffer[0] = W25X_WriteDisable;
sendFlashCommand(&spi_flash,(void *)flashDataBuffer,1);
tx_thread_sleep(1);
ret = checkPageWrite(PageNum,start, source,words);
return ret;
}
u8 NAND_ReadSpare(u32 PageNum,u16 start,u8* destination,ULONG words)
{
u16 load_len;
flashPageRead(&spi_flash, PageNum);
flashDataBuffer[0] = W25X_ReadData;
flashDataBuffer[1] = (PAGE_SIZE+start)>>8 & 0xFF;
flashDataBuffer[2] = (PAGE_SIZE+start) & 0xFF;
flashDataBuffer[3] = 0x0;
load_len = 4+words;
sendFlashCommand(&spi_flash,(void *)flashDataBuffer,load_len);
load_len = 4;
memcpy(destination,&flashDataBuffer[load_len],words);
return 0;
}
u8 NAND_WriteSpare(u32 PageNum,u16 start,u8* source,ULONG words)
{
u8 ret = 0;
u16 load_len;
flashDataBuffer[0] = W25X_WriteEnable;
sendFlashCommand(&spi_flash,(void *)flashDataBuffer,1);
//Load Data to column adress
flashDataBuffer[0] = W25X_LoadProgramData;
flashDataBuffer[1] = (PAGE_SIZE+start)>>8 & 0xFF;
flashDataBuffer[2] = (PAGE_SIZE+start) & 0xFF;
load_len = 3;
memcpy(&flashDataBuffer[load_len],source,words);
load_len += words;
sendFlashCommand(&spi_flash,(void *)flashDataBuffer,load_len);
//Program the page address
flashDataBuffer[0] = W25X_ProgramExcute;
flashDataBuffer[1] = 0x0;
flashDataBuffer[2] = (PageNum>>8) & 0xFF;
flashDataBuffer[3] = PageNum & 0xFF;
sendFlashCommand(&spi_flash,(void *)flashDataBuffer,4);
flashWaitBusy(&spi_flash,100);
flashDataBuffer[0] = W25X_WriteDisable;
sendFlashCommand(&spi_flash,(void *)flashDataBuffer,1);
tx_thread_sleep(1);
ret = checkSpareWrite(PageNum,start, source,words);
return ret;
}
u8 NAND_EraseBlock(ULONG block)
{
int32_t ret = 0;
u16 pageStart = (u16)(block << 6);
ret = flashErase(&spi_flash,pageStart);
if(ret < 0)
return 2;
else
return 0;
}