| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140 | /*-----------------------------------------------------------------------*//* Low level disk I/O module skeleton for FatFs     (C)ChaN, 2013        *//*-----------------------------------------------------------------------*//* 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 module to the FatFs module with a defined API.        *//*-----------------------------------------------------------------------*/#include "diskio.h"		/* FatFs lower layer API */#include <string.h> // memcpy#include "stm32f4xx.h"#include "../SD_Card/sdio_sd.h"#define BLOCK_SIZE            512 /* Block Size in Bytes *//* Definitions of physical drive number for each media */#define ATA		0#define MMC		1#define USB		2/*-----------------------------------------------------------------------*//* Inidialize a Drive                                                    *//*-----------------------------------------------------------------------*/DSTATUS disk_initialize (	BYTE pdrv				/* Physical drive nmuber (0..) */){	SD_Error  Status;	/* Supports only single drive */	if (pdrv) return STA_NOINIT;	/*-------------------------- SD Init ----------------------------- */	Status = SD_Init();	if (Status!=SD_OK ) return STA_NOINIT;	else return RES_OK;}/*-----------------------------------------------------------------------*//* Get Disk Status                                                       *//*-----------------------------------------------------------------------*/DSTATUS disk_status (	BYTE pdrv		/* Physical drive nmuber (0..) */){	DSTATUS stat = 0;	if (SD_Detect() != SD_PRESENT)		stat |= STA_NODISK;	// STA_NOTINIT - Subsystem not initailized	// STA_PROTECTED - Write protected, MMC/SD switch if available	return(stat);}/*-----------------------------------------------------------------------*//* Read Sector(s)                                                        *//*-----------------------------------------------------------------------*/DRESULT disk_read (	BYTE pdrv,		/* Physical drive nmuber (0..) */	BYTE *buff,		/* Data buffer to store read data */	DWORD sector,	/* Sector address (LBA) */	UINT count		/* Number of sectors to read (1..128) */){	SDTransferState state;	DRESULT res = RES_OK;	if (SD_Detect() != SD_PRESENT) return RES_NOTRDY;	if (count == 0) return RES_PARERR;	//SD_ReadMultiBlocks ( buff, sector, 512, 1 );	SD_ReadMultiBlocksFIXED (buff, sector, 512, count);	SD_WaitReadOperation();    do {      state = SD_GetStatus();      if(state == SD_TRANSFER_ERROR) {        res = RES_ERROR;        break;      }	} while (state != SD_TRANSFER_OK);	return res;}/*-----------------------------------------------------------------------*//* Write Sector(s)                                                       *//*-----------------------------------------------------------------------*/#if _USE_WRITEDRESULT disk_write (	BYTE pdrv,			/* Physical drive nmuber (0..) */	const BYTE *buff,	/* Data to be written */	DWORD sector,		/* Sector address (LBA) */	UINT count			/* Number of sectors to write (1..128) */){	//SDTransferState state;	//  DRESULT res = RES_OK;	if (SD_Detect( ) != SD_PRESENT) return RES_NOTRDY;	if (count == 0) return RES_PARERR;	//SD_WriteMultiBlocks ( (uint8_t *)buff, sector, 512, count );	SD_WriteMultiBlocksFIXED ((uint8_t *)buff, sector, 512, count);	SD_WaitWriteOperation();	while (SD_GetStatus() != SD_TRANSFER_OK);	return RES_OK;}#endif/*-----------------------------------------------------------------------*//* Miscellaneous Functions                                               *//*-----------------------------------------------------------------------*/#if _USE_IOCTLDRESULT disk_ioctl (	BYTE pdrv,		/* Physical drive nmuber (0..) */	BYTE cmd,		/* Control code */	void *buff		/* Buffer to send/receive control data */){	return RES_OK;}#endif
 |