Problem Implementing Fatfs on spi flash 1MB . hi i am trying to port Fatfs generated from cube mx on to my spi flash on stm32 board.
when creating and opening a file i get error and it exits what could be the problem below i have shared the code .
////////////////////////////////////main.c///////////////////////////////////////////
if( FATFS_LinkDriver(&USER_Driver, USERPath)== 0)
res = f_mkfs(USERPath, FM_ANY, 0, workBuffer, 4096);
if(f_mount(&USERFatFS, (TCHAR const*)USERPath, 0) == FR_OK)
if(f_open(&USERFile, "STM32.TXT", FA_CREATE_ALWAYS | FA_WRITE) == FR_OK)
///////////////////////////////////////user_diskio.c/////////////////////////////
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 */
//int i =0;
SST80B_ReadSector(buff,0,sector*4096,count*4096);
return RES_OK;
/* USER CODE END READ */
}
#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 */
uint32_t sector_address = sector;
uint8_t count_func = count;
int eras_add = 0;
int loc = 0;
for(int no=0;no<=count;no++)
{
chipsector_erase_call(sector*no*4096);
}
for(int i =1;i<=count_func;i++)
{
for(int j =0;j<4096;j++)
{
int bb =0;
bb = *(buff+j);
sector_address += j;
SST80B_WriteByte((uint8_t)(*(buff+j)),sector_address);
}
sector_address += 4096;
/* USER CODE END WRITE */
}
return RES_OK;
}
#if _USE_IOCTL == 1
DRESULT USER_ioctl (
BYTE pdrv, /* Physical drive nmuber (0..) */
BYTE cmd, /* Control code */
void *buff /* Buffer to send/receive control data */
)
{
/* USER CODE BEGIN IOCTL */
DRESULT res = RES_ERROR;
if (Stat & STA_NOINIT) return RES_NOTRDY;
switch (cmd)
{
/* Make sure that no pending write process */
case CTRL_SYNC :
res = RES_OK;
break;
/* Get number of sectors on the disk (DWORD) */
case GET_SECTOR_COUNT :
*(DWORD*)buff = 256;
res = RES_OK;
break;
/* Get R/W sector size (WORD) */
case GET_SECTOR_SIZE :
*(WORD*)buff = 4096;
res = RES_OK;
break;
/* Get erase block size in unit of sector (DWORD) */
case GET_BLOCK_SIZE :
*(DWORD*)buff = 1;
res = RES_OK;
break;
default:
res = RES_PARERR;
}
The spi flash driver for write operation is byte transmit, however the read is sector read .
The low level spi flash driver is working .
kindly let me know what could be the problem.Thanks in advance.
