2022-06-22 02:30 AM
Hey,
I have a problem with reading files larger than size of one sector of FATFs (4096 bytes).
Reading seems to be done correctly until it reaches 4096th byte of file, then data is corrupted. The problem appears when one part of readen data is on one sector and the second part is on another sector. It reads just one part of data correctly but not the second part.
DRESULT USER_read (
BYTE pdrv, /* Physical drive nmuber to identify the drive */
BYTE *buff, /* Data buffer to store read data */
DWORD sector, /* Sector address in LBA */
UINT count /* Number of sectors to read */
)
{
/* USER CODE BEGIN READ */
DRESULT res = RES_OK;
W25qxx_ReadSector(buff, sector, 0, 0);
return res;
/* USER CODE END READ */
}
/**
* @brief Writes Sector(s)
* @param pdrv: Physical drive number (0..)
* @param *buff: Data to be written
* @param sector: Sector address (LBA)
* @param count: Number of sectors to write (1..128)
* @retval DRESULT: Operation result
*/
#if _USE_WRITE == 1
DRESULT USER_write (
BYTE pdrv, /* Physical drive nmuber to identify the drive */
const BYTE *buff, /* Data to be written */
DWORD sector, /* Sector address in LBA */
UINT count /* Number of sectors to write */
)
{
/* USER CODE BEGIN WRITE */
/* USER CODE HERE */
W25qxx_EraseSector(sector);
W25qxx_WriteSector(buff, sector, 0, 0);
return RES_OK;
/* USER CODE END WRITE */
}
#endif /* _USE_WRITE == 1 */
2022-06-22 04:11 AM
Perhaps don't use functions that only read/write single sectors/blocks to the W25 ??
Pay attention to Count parameter.
2022-06-22 05:49 AM
As far as I understand since min sector size is equal to max sector size count parameter is always 1. I've tried to read it by pages but same happens
2022-06-22 06:00 AM
So what happens when you f_read() 32KB ?
Perhaps instrument the code so you know what's happening.
And while you're doing that, validate that at a block level you return the same data that was previously written.
Check your stack/heap can accommodate the larger sector size, and intermediate holding buffers.
2022-06-22 08:58 AM
Okay I see what's a problem. The hspi1->Lock sets to HAL_Locked and never return to HAL_Unlocked.
2022-06-28 02:03 AM
hi,can u send me your source code plz and thanks
haykel.mhedhbi@gmail.com
i am use AT45DB with fatfs and i have many probleme.
2022-06-28 03:22 AM
i am try and i have some errors
2022-07-06 04:11 AM
Unfortunately I can't share my code, but the problem was related to the FatFS instance defined on the stack. Then if I left the function where it was declared, it was still pointing to the same part of memory. So I had two options: Define FatFS fs; somewhere upper in the stack or define FatFS fs; as a global variable