123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140 |
- #include "diskio.h"
- #include <string.h> // memcpy
- #include "stm32f4xx.h"
- #include "../SD_Card/sdio_sd.h"
- #define BLOCK_SIZE 512
- #define ATA 0
- #define MMC 1
- #define USB 2
- DSTATUS disk_initialize (
- BYTE pdrv
- )
- {
- SD_Error Status;
-
- if (pdrv) return STA_NOINIT;
-
- Status = SD_Init();
- if (Status!=SD_OK ) return STA_NOINIT;
- else return RES_OK;
- }
- DSTATUS disk_status (
- BYTE pdrv
- )
- {
- DSTATUS stat = 0;
- if (SD_Detect() != SD_PRESENT)
- stat |= STA_NODISK;
-
-
- return(stat);
- }
- DRESULT disk_read (
- BYTE pdrv,
- BYTE *buff,
- DWORD sector,
- UINT count
- )
- {
- SDTransferState state;
- DRESULT res = RES_OK;
- if (SD_Detect() != SD_PRESENT) return RES_NOTRDY;
- if (count == 0) return RES_PARERR;
-
- 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;
- }
- #if _USE_WRITE
- DRESULT disk_write (
- BYTE pdrv,
- const BYTE *buff,
- DWORD sector,
- UINT count
- )
- {
-
-
- if (SD_Detect( ) != SD_PRESENT) return RES_NOTRDY;
- if (count == 0) return RES_PARERR;
-
- SD_WriteMultiBlocksFIXED ((uint8_t *)buff, sector, 512, count);
- SD_WaitWriteOperation();
- while (SD_GetStatus() != SD_TRANSFER_OK);
- return RES_OK;
- }
- #endif
- #if _USE_IOCTL
- DRESULT disk_ioctl (
- BYTE pdrv,
- BYTE cmd,
- void *buff
- )
- {
- return RES_OK;
- }
- #endif
|