cancel
Showing results for 
Search instead for 
Did you mean: 

FATFs with w25qxx problem

KWier.2
Associate II

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 */

7 REPLIES 7

Perhaps don't use functions that only read/write single sectors/blocks to the W25 ??

Pay attention to Count parameter.​

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
KWier.2
Associate II

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

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.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
KWier.2
Associate II

Okay I see what's a problem. The hspi1->Lock sets to HAL_Locked and never return to HAL_Unlocked.

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.

i am try and i have some errors

KWier.2
Associate II

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