2016-02-22 11:32 PM
Hi everybody,
I develop file system on spi flash with FAtfs library.But i have a bit problem.My problem is f_getfree() function return 0 free cluster but all flash is free.The other fatfs function working properly.I am using SST26VF16B spi flash. This is my diskio config,/*-----------------------------------------------------------------------*/
/* Low level disk I/O module skeleton for FatFs (C)ChaN, 2014 */
/*-----------------------------------------------------------------------*/
/* If a working storage control module is available, it should be */
/* attached to the FatFs via a glue function rather than modifying it. */
/* This is an example of glue functions to attach various exsisting */
/* storage control modules to the FatFs module with a defined API. */
/*-----------------------------------------------------------------------*/
#include ''diskio.h'' /* FatFs lower layer API */
#include ''SST26VF016B.h''
/*-----------------------------------------------------------------------*/
/* Get Drive Status */
/*-----------------------------------------------------------------------*/
DSTATUS disk_status (
BYTE pdrv /* Physical drive nmuber to identify the drive */
)
{
return RES_OK;
}
/*-----------------------------------------------------------------------*/
/* Initialize a Drive */
/*-----------------------------------------------------------------------*/
DSTATUS disk_initialize (
BYTE pdrv /* Physical drive nmuber to identify the drive */
)
{
SST_Init();
return RES_OK;
}
/*-----------------------------------------------------------------------*/
/* Read Sector(s) */
/*-----------------------------------------------------------------------*/
DRESULT disk_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 */
)
{
int i=0;
if( count > 255 )
{
return RES_PARERR;
}
printf(''Disk_Read sector=%lu -->'',sector);
sector *= 512; // convert LBA to physical address
for(i=0;i<(count*2);i++)
{
SST_Read(sector,buff,256);
sector=sector+256;
buff=buff+256;
}
return RES_OK;
}
/*-----------------------------------------------------------------------*/
/* Write Sector(s) */
/*-----------------------------------------------------------------------*/
#if _USE_WRITE
DRESULT disk_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 */
)
{
uint32_t address;
uint32_t i=0;
if( count > 255 )
{
return RES_PARERR;
}
address=sector*512;
if((sector%8)==0)
{
SST_EraseBlock(address);
}
for(i=0;i<(count*2);i++)
{
SST_Write(address,buff,256);
address=address+256;
buff=buff+256;
}
return RES_OK;
}
#endif
/*-----------------------------------------------------------------------*/
/* Miscellaneous Functions */
/*-----------------------------------------------------------------------*/
#if _USE_IOCTL
DRESULT disk_ioctl (
BYTE pdrv, /* Physical drive number (0..) */
BYTE cmd, /* Control code */
void *buff /* Buffer to send/receive control data */
)
{
DRESULT res;
// uint8_t status;
// status=SST_Status();
switch(cmd)
{
case CTRL_SYNC:
// if(status & 0x01)
// res=RES_ERROR;
// else
res=RES_OK;
break;
case GET_SECTOR_COUNT:
*(DWORD*)buff=4096;
res = RES_OK;
break;
case GET_SECTOR_SIZE:
*(WORD*)buff=512;
res = RES_OK;
break;
case GET_BLOCK_SIZE:
*(DWORD*)buff=8;
res = RES_OK;
break;
default:
printf(''diskio error\n'');
break;
};
return res;
}
#endif
DWORD get_fattime (void)
{
return 0;
}
In addition i create filesystem with f_mkfs('''',0,512) function.
I m create file but i m not write anything on the file.Because i have disk full error.My SST low level driver working well.
Help me please
Best Regards
#fatfs #stm32l0 #spi-flash