本帖最后由 wjc3k 于 2009-9-6 01:51 编辑
here is function for FATFS. ( ST SDCARD.C ,Sandisk 1GB DMA:24M)
/*-----------------------------------------------------------------------*/
/* Read Sector(s) */
#define MULTI_BLOCK
#define MAX_BLOCK_SIZE 512
DRESULT disk_read (
BYTE drv, /* Physical drive nmuber (0..) */
BYTE *buff, /* Data buffer to store read data */
DWORD sector, /* Sector address (LBA) */
BYTE count /* Number of sectors to read (1..255) */
)
{
u32 *pbuf=(u32 *)(buff);
SD_Error err;
// u8 c;
#ifdef MULTI_BLOCK
if( count == 1 )
err = SD_ReadBlock(sector*S_MAX_SIZ,(u32 *)pbuf,MAX_BLOCK_SIZE);
else
{
err = SD_ReadMultiBlocks(sector*S_MAX_SIZ, (u32 *)pbuf, MAX_BLOCK_SIZE, count);
}
if( err != SD_OK ) return( RES_ERROR);
#else
while(count--)
{
err = SD_ReadBlock(sector*S_MAX_SIZ,(u32 *)pbuf,MAX_BLOCK_SIZE);
if( err != SD_OK ) return( RES_ERROR);
pbuf+=(MAX_BLOCK_SIZE>>2);
sector++;
}
#endif
return(RES_OK);
}
/*-----------------------------------------------------------------------*/
/* Write Sector(s) */
#if _READONLY == 0
DRESULT disk_write (
BYTE drv, /* Physical drive nmuber (0..) */
const BYTE *buff, /* Data to be written */
DWORD sector, /* Sector address (LBA) */
BYTE count /* Number of sectors to write (1..255) */
)
{
u32 *pbuf=(u32 *)(buff);
SD_Error err;
#ifdef MULTI_BLOCK
if( count == 1 )
err = SD_WriteBlock(sector*S_MAX_SIZ,(u32 *)pbuf,MAX_BLOCK_SIZE);
else
err = SD_WriteMultiBlocks(sector*S_MAX_SIZ, (u32 *)pbuf, MAX_BLOCK_SIZE, count);
if( err != SD_OK )
{
printf("Write Blocks:%d %d Failed!\r\n",sector,count);
return( RES_ERROR);
}
#else
while(count--)
{
err = SD_WriteBlock(sector*S_MAX_SIZ, (u32 *)pbuf, MAX_BLOCK_SIZE);
if( err != SD_OK ) return( RES_ERROR);
pbuf+=(MAX_BLOCK_SIZE>>2);
sector++;
}
#endif
return(RES_OK);
}
#endif /* _READONLY */ |