SD Card Timeout on read - STM32F207VCT6
Posted: Mon Feb 10, 2014 3:03 pm
Hello, I am trying to read a SD card using the MMC over SPI driver.
I am having a sporadic timeout in the function mmcSequentialRead, which I copy below for convenience. The MCU doesn't receive the 0xFE. I tried waiting in an infinite loop, but the 0xFE never arrives. The problem is not very frequent (for example, it appears when I try to read files larger than 100kB).
Has someone seen a similar problem? What could be the cause?
Thank you very much for your help.
Diego.
I am having a sporadic timeout in the function mmcSequentialRead, which I copy below for convenience. The MCU doesn't receive the 0xFE. I tried waiting in an infinite loop, but the 0xFE never arrives. The problem is not very frequent (for example, it appears when I try to read files larger than 100kB).
Has someone seen a similar problem? What could be the cause?
Thank you very much for your help.
Diego.
Code: Select all
bool_t mmcSequentialRead(MMCDriver *mmcp, uint8_t *buffer) {
int i;
chDbgCheck((mmcp != NULL) && (buffer != NULL), "mmcSequentialRead");
if (mmcp->state != BLK_READING)
return CH_FAILED;
for (i = 0; i < MMC_WAIT_DATA; i++) {
spiReceive(mmcp->config->spip, 1, buffer);
if (buffer[0] == 0xFE) {
spiReceive(mmcp->config->spip, MMCSD_BLOCK_SIZE, buffer);
/* CRC ignored. */
spiIgnore(mmcp->config->spip, 2);
return CH_SUCCESS;
}
}
/* Timeout.*/
spiUnselect(mmcp->config->spip);
spiStop(mmcp->config->spip);
mmcp->state = BLK_READY;
return CH_FAILED;
}