diff options
Diffstat (limited to 'os/io/mmc_spi.c')
-rw-r--r-- | os/io/mmc_spi.c | 24 |
1 files changed, 19 insertions, 5 deletions
diff --git a/os/io/mmc_spi.c b/os/io/mmc_spi.c index 4e9d6e3f5..517291814 100644 --- a/os/io/mmc_spi.c +++ b/os/io/mmc_spi.c @@ -240,6 +240,7 @@ void mmcStop(MMCDriver *mmcp) { */
bool_t mmcConnect(MMCDriver *mmcp) {
unsigned i;
+ bool_t result;
chDbgCheck(mmcp != NULL, "mmcConnect");
@@ -278,8 +279,21 @@ bool_t mmcConnect(MMCDriver *mmcp) { /* Initialization complete, full speed. */
spiStart(mmcp->mmc_spip, mmcp->mmc_hscfg);
- mmcp->mmc_state = MMC_READY;
- return FALSE;
+
+ /* Setting block size.*/
+ if (send_command(mmcp, MMC_CMDSETBLOCKLEN, MMC_BLOCK_SIZE) != 0x00)
+ return TRUE;
+
+ /* Transition to MMC_READY state (if not extracted).*/
+ chSysLock();
+ if (mmcp->mmc_state == MMC_INSERTED) {
+ mmcp->mmc_state = MMC_READY;
+ result = FALSE;
+ }
+ else
+ result = TRUE;
+ chSysUnlock();
+ return result;
}
if (mmcp->mmc_state == MMC_READY)
return FALSE;
@@ -310,7 +324,7 @@ bool_t mmcStartSequentialRead(MMCDriver *mmcp, uint32_t startblk) { chSysUnlock();
spiSelect(mmcp->mmc_spip);
- send_hdr(mmcp, MMC_CMDREADMULTIPLE, startblk << 9);
+ send_hdr(mmcp, MMC_CMDREADMULTIPLE, startblk * MMC_BLOCK_SIZE);
if (recvr1(mmcp) != 0x00) {
spiUnselect(mmcp->mmc_spip);
chSysLock();
@@ -347,7 +361,7 @@ bool_t mmcSequentialRead(MMCDriver *mmcp, uint8_t *buffer) { for (i = 0; i < MMC_WAIT_DATA; i++) {
spiReceive(mmcp->mmc_spip, 1, buffer);
if (buffer[0] == 0xFE) {
- spiReceive(mmcp->mmc_spip, 512, buffer);
+ spiReceive(mmcp->mmc_spip, MMC_BLOCK_SIZE, buffer);
/* CRC ignored. */
spiIgnore(mmcp->mmc_spip, 2);
return FALSE;
@@ -418,7 +432,7 @@ bool_t mmcStartSequentialWrite(MMCDriver *mmcp, uint32_t startblk) { chSysUnlock();
spiSelect(mmcp->mmc_spip);
- send_hdr(mmcp, MMC_CMDWRITEMULTIPLE, startblk << 9);
+ send_hdr(mmcp, MMC_CMDWRITEMULTIPLE, startblk * MMC_BLOCK_SIZE);
if (recvr1(mmcp) != 0x00) {
spiUnselect(mmcp->mmc_spip);
chSysLock();
|