本帖最后由 740071911 于 2022-1-7 09:12 编辑
对FatFS移植,主要是将diskio.c接口和ffconf.h的配置
先来看看效果:
因为目录比较多,分两张截图
这里是目录的下半截图
接口文件diskio.c的移植
/* Includes ------------------------------------------------------------------*/
#include "diskio.h"
#include "ffconf.h"
#include "spi_sd.h"
/* Private typedef -----------------------------------------------------------*/
/* Private define ------------------------------------------------------------*/
#define BLOCK_SIZE 512 /* Block Size in Bytes */
/* Private variables ---------------------------------------------------------*/
/* Private function prototypes -----------------------------------------------*/
/* Private functions ---------------------------------------------------------*/
/**
* [url=home.php?mod=space&uid=247401]@brief[/url] Initializes a Disk
* @param pdrv: Physical drive number
* @retval DSTATUS: Operation status
*/
DSTATUS disk_initialize(BYTE pdrv)
{
SD_Error res = SD_RESPONSE_FAILURE;
res = SD_Init();
return ((DSTATUS)res);
}
/**
* [url=home.php?mod=space&uid=247401]@brief[/url] Gets Disk Status
* @param pdrv: Physical drive number
* @retval DSTATUS: Operation status
*/
DSTATUS disk_status (BYTE pdrv)
{
if (pdrv) return STA_NOINIT; /* Supports only single drive */
return 0;
}
/**
* @brief Reads Sector
* @param pdrv: Physical drive number
* @param *buff: Data buffer to store read data
* @param sector: Sector address (LBA)
* @param count: Number of sectors to read
* @retval DRESULT: Operation result
*/
DRESULT disk_read (BYTE pdrv, BYTE*buff, DWORD sector, UINT count)
{
SD_ReadBlock(buff, sector << 9, BLOCK_SIZE);
return RES_OK;
}
/**
* @brief Writes Sector
* @param pdrv: Physical drive number
* @param *buff: Data to be written
* @param sector: Sector address (LBA)
* @param count: Number of sectors to write
* @retval DRESULT: Operation result
* [url=home.php?mod=space&uid=536309]@NOTE[/url] The FatFs module will issue multiple sector transfer request
* (count > 1) to the disk I/O layer. The disk function should process
* the multiple sector transfer properly Do. not translate it into
* multiple single sector transfers to the media, or the data read/write
* performance may be drasticaly decreased.
*/
#if _USE_WRITE == 1
DRESULT disk_write (BYTE pdrv, const BYTE* buff, DWORD sector, UINT count)
{
SD_WriteBlock((BYTE *)buff, sector << 9, BLOCK_SIZE);
return RES_OK;
}
#endif /* _USE_WRITE == 1 */
/**
* @brief Get current time
* @param none
* @retval DWORD: Current time
*/
DWORD get_fattime ()
{
return ((2006UL-1980) << 25) /* Year = 2006 */
| (2UL << 21) /* Month = Feb */
| (9UL << 16) /* Day = 9 */
| (22U << 11) /* Hour = 22 */
| (30U << 5) /* Min = 30 */
| (0U >> 1) /* Sec = 0 */
;
}
/*-----------------------------------------------------------------------*/
/* Miscellaneous Functions */
/*-----------------------------------------------------------------------*/
/**
* @brief I/O control operation
* @param pdrv: Physical drive number
* @param cmd: Control code
* @param *buff: Buffer to send/receive control data
* @retval DRESULT: Operation result
*/
#if _USE_IOCTL != 0
DRESULT disk_ioctl(BYTE pdrv, BYTE cmd, void *buff)
{
DRESULT res = RES_OK;
switch (cmd)
{
/* Get number of sectors on the disk (DWORD) */
case GET_SECTOR_COUNT :
*(DWORD*)buff = 131072; /* 4*1024*32 = 131072 */
res = RES_OK;
break;
/* Get R/W sector size (WORD) */
case GET_SECTOR_SIZE :
*(WORD*)buff = BLOCK_SIZE;
res = RES_OK;
break;
/* Get erase block size in unit of sector (DWORD) */
case GET_BLOCK_SIZE :
*(DWORD*)buff = 32;
res = RES_OK;
}
return res;
}
#endif /* _USE_IOCTL == 1 */
main.c主函数的实现:
同样,最后附上demo
SD_FATFS_R0.10.rar
(714.47 KB)
|