初级会员

- 积分
- 160
- 金钱
- 160
- 注册时间
- 2016-1-26
- 在线时间
- 58 小时
|
下面是按照我的理解移植的驱动
/*-----------------------------------------------------------------------*/
/* 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 "w25qxx.h"
#include "malloc.h"
#define SD_CARD 0 //SD¿¨,¾í±êÎa0
#define EX_FLASH 1 //ía2¿flash,¾í±êÎa1
#define FLASH_SECTOR_SIZE 1024*4
u16 FLASH_SECTOR_COUNT=16*256;
#define FLASH_BLOCK_SIZE 16
DSTATUS disk_status (
BYTE pdrv /* Physical drive nmuber to identify the drive */
)
{
return RES_OK;
}
//3õê¼»ˉ′ÅÅì
DSTATUS disk_initialize (
BYTE pdrv /* Physical drive nmuber to identify the drive */
)
{
u8 res=0;
switch(pdrv)
{
case EX_FLASH://ía2¿flash
W25QXX_Init();
break;
default:
res=1;
}
if(res)return STA_NOINIT;
else return 0; //3õê¼»ˉ3é1|
}
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 */
)
{
u8 res=0;
if (!count)return RES_PARERR;//count2»Äüμèóú0£¬·ñÔò·μ»Ø2Îêy′íÎó
switch(pdrv)
{
case EX_FLASH://ía2¿flash
res=0;
break;
default:
res=1;
}
if(res==0x00)return RES_OK;
else return RES_ERROR;
}
#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 */
)
{
u8 res=0;
if (!count)return RES_PARERR;//count2»Äüμèóú0£¬·ñÔò·μ»Ø2Îêy′íÎó
switch(pdrv)
{
case EX_FLASH://ía2¿flash
W25QXX_Write((u8*)buff,sector,count*FLASH_SECTOR_SIZE);
res=0;
break;
default:
res=1;
}
if(res == 0x00)return RES_OK;
else return RES_ERROR;
}
#endif
#if _USE_IOCTL
DRESULT disk_ioctl (
BYTE pdrv, /* Physical drive nmuber (0..) */
BYTE cmd, /* Control code */
void *buff /* Buffer to send/receive control data */
)
{
DRESULT res;
if(pdrv==EX_FLASH) //ía2¿FLASH
{
switch(cmd)
{
case CTRL_SYNC:
res = RES_OK;
break;
case GET_SECTOR_SIZE:
*(WORD*)buff = FLASH_SECTOR_SIZE;
res = RES_OK;
break;
case GET_BLOCK_SIZE:
*(WORD*)buff = FLASH_BLOCK_SIZE;
res = RES_OK;
break;
case GET_SECTOR_COUNT:
*(DWORD*)buff = FLASH_SECTOR_COUNT;
res = RES_OK;
break;
default:
res = RES_PARERR;
break;
}
}
else res=RES_ERROR;//ÆäËûμÄ2»Ö§3Ö
return res;
}
#endif
//User defined function to give a current time to fatfs module */
//31-25: Year(0-127 org.1980), 24-21: Month(1-12), 20-16: Day(1-31) */
//15-11: Hour(0-23), 10-5: Minute(0-59), 4-0: Second(0-29 *2) */
DWORD get_fattime (void)
{
return 0;
}
void *ff_memalloc (UINT size)
{
return (void*)mymalloc(SRAMIN,size);
}
void ff_memfree (void* mf)
{
myfree(SRAMIN,mf);
}
移植结果是:
1:能够进行 f_open(file,"1:/3.txt",FA_WRITE|FA_CREATE_ALWAYS);f_close(); 并且通过mf_scan_files("1:");看见了文件夹。因为sd卡还没动起来,所以没加。
2:调用f_write();时总是返回0x07 /* (7) Access denied due to prohibited access or directory full */ 所以f_Read()也就没测。
调了好久一直做不好,还请各位大神指点下。
|
|