2016-04-14 11:43 AM
2016-04-14 11:55 AM
Additional info: I would like to communicate via USB with a computer also. However it currently only works for 4-bit and not 8-bit. When I connect in USB mode, it is unable to be read.
Below are my read/writes for fatFS diskio defines. Further down is my emmc write multiblock function (I get stuck in the last while loop). Right now I suspect I'm sending 2x as much data as I want to since I'm trying to write multiblock with 4 bit DMA. Really though I'm at a loss, and would appreciate any ideas/feedback. Thanks!DRESULT EMMC_msd_read (
BYTE *buff, /* Data buffer to store read data */
DWORD sector, /* Sector address in LBA */
UINT count /* Number of sectors to read */
) {
EmmcError Status;
// if (EmmcGetState() != SD_PRESENT)
// return(RES_NOTRDY);
/* DMA Alignment failure, do single up to aligned buffer */
if ((DWORD)buff & 3) {
/* Alignment assured, you'll need a sufficiently big stack */
DRESULT res = RES_OK;
DWORD scratch[EMMC_SECTOR_SIZE / 4];
while(count--) {
res = EMMC_msd_read((void *)scratch, sector++, 1);
if (res != RES_OK)
break;
memcpy(buff, scratch, EMMC_SECTOR_SIZE);
buff += EMMC_SECTOR_SIZE;
}
return(res);
}
/* 4GB Compliant? */
Status = EmmcReadMultiBlocks(buff, sector, EMMC_SECTOR_SIZE, count); /* Works for up to 4GB. */
//Status = EmmcReadMultiBlocksFIXED(buff, sector, EMMC_SECTOR_SIZE, count);
if (Status == EMMC_OK) {
EmmcCardState State;
/* Check if the Transfer is finished */
/* UPDATE: Implicitely performed in fcn above. */
//Status = EmmcWaitReadOperation();
/* BUSY, OK (DONE), ERROR (FAIL) */
while((State = EmmcGetState()) == EMMC_TRANSFER_BUSY);
if ((State == EMMC_TRANSFER_ERROR) || (Status != EMMC_OK))
return(RES_ERROR);
else
return(RES_OK);
} else
return(RES_ERROR);
/* Need to check DMA status? */
//Sdio_WaitUntilDmaRdComplete();
}
/*-----------------------------------------------------------------------*/
/* Write Sector(s) */
/*-----------------------------------------------------------------------*/
#if _USE_WRITE
DRESULT EMMC_msd_write (
const BYTE *buff, /* Data to be written */
DWORD sector, /* Sector address in LBA */
UINT count /* Number of sectors to write */
) {
/* Taken from Clive's code. */
EmmcError Status;
/* DMA Alignment failure, do single up to aligned buffer */
if ((DWORD)buff & 3) {
DRESULT res = RES_OK;
DWORD scratch[EMMC_SECTOR_SIZE / 4]; // Alignment assured, you'll need a sufficiently big stack
while(count--) {
memcpy(scratch, buff, EMMC_SECTOR_SIZE);
res = EMMC_msd_write((void *)scratch, sector++, 1);
if (res != RES_OK)
break;
buff += EMMC_SECTOR_SIZE;
}
return (res);
}
/* 4GB Compliant. */
Status = EmmcWriteMultiBlocks((uint8_t *)buff, sector, EMMC_SECTOR_SIZE, count); /* Works for up to 4GB. */
//Status = EmmcWriteMultiBlocksFIXED((uint8_t *)buff, sector, EMMC_SECTOR_SIZE, count);
if (Status == EMMC_OK) {
EmmcCardState State;
//Status = SD_WaitWriteOperation(); // Check if the Transfer is finished
while((State = EmmcGetState()) == EMMC_TRANSFER_BUSY); // BUSY, OK (DONE), ERROR (FAIL)
if ((State == EMMC_TRANSFER_ERROR) || (Status != EMMC_OK))
return(RES_ERROR);
else
return(RES_OK);
} else
return (RES_ERROR);
}
#endif
2016-04-22 08:56 AM
Hi all, I'm still stuck on this one. If anyone has an idea, I'd greatly appreciate it. Thanks!