2019-11-08 03:55 AM
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.
2019-11-08 04:54 AM
Several of the computations in the USER_write() are broken, and sending bytes will be very slow. Check if you can at least do a page at a time.
Test the USER_write(), and read, thoroughly BEFORE integrating into FatFs.
2019-11-11 03:45 AM
hi ,thanks for the reply , i have implemented a multi byte write (sector write ) which is working and tested.
Below is the code :
#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 add = sector *4096;
uint32_t ea1 = 0;
for(int no=1;no<=count;no++)
{
ea1 = sector*no*4096;
chipsector_erase_call(ea1);
}
for(int i =0;i<count;i++)
{
SST25Write(add,(uint8_t *)buff,4096);
buff= buff+4096;
add += 4096;
}
/* USER CODE END WRITE */
}
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 */
uint32_t add = sector *4096;
int c = 0;
for(int i =0;i<count;i++)
{
SST80B_ReadSector(buff,0,add,4096);
buff = buff+4096;
add += 4096;
}
return RES_OK;
/* USER CODE END READ */
}
I am able to open the file using if(f_open(&USERFile, "STM32.TXT", FA_CREATE_ALWAYS | FA_WRITE) == FR_OK)
{
res = f_write(&USERFile, wtext, sizeof(wtext), (void *)&byteswritten);
Not able to write into it, get disk error 0xffffffff, kindly let me know ,what could be creating problems,
thanks in advance.
2019-11-11 03:50 AM
Erase math is broken
2019-11-12 03:56 AM
hi, thanks for the reply it is working solved the issues:my next step would be trying to integrate this fatfs on spi flash along my usb code (configured as memory stick).I already have an working tested code for the usb were, if plugged in the pc detects it as a memory storage device and tries to format it.
Now that the fatfs is up , i will be integrating it along with my usb code,
any pointers on how to do this will be helpful ,i have come across two files user_diskio.c, usbd_storage_if.c ,should i have to add the flash driver
support to both these files.thanks in advance.