mirror of https://github.com/ARMmbed/mbed-os.git
Temporary: Loop in read
parent
b31e9754da
commit
34cbdb8fc8
|
@ -480,26 +480,38 @@ int SDBlockDevice::read(void *b, bd_addr_t addr, bd_size_t size)
|
||||||
addr = addr / _block_size;
|
addr = addr / _block_size;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Write command ro receive data
|
for (uint8_t i = 0; i < 3; i++) {
|
||||||
if (blockCnt > 1) {
|
// Write command ro receive data
|
||||||
status = _cmd(CMD18_READ_MULTIPLE_BLOCK, addr);
|
if (blockCnt > 1) {
|
||||||
} else {
|
status = _cmd(CMD18_READ_MULTIPLE_BLOCK, addr);
|
||||||
status = _cmd(CMD17_READ_SINGLE_BLOCK, addr);
|
} else {
|
||||||
}
|
status = _cmd(CMD17_READ_SINGLE_BLOCK, addr);
|
||||||
|
}
|
||||||
|
if (BD_ERROR_OK != status) {
|
||||||
|
_lock.unlock();
|
||||||
|
return status;
|
||||||
|
}
|
||||||
|
|
||||||
if (BD_ERROR_OK != status) {
|
// For the first time in read if start token is not received
|
||||||
_lock.unlock();
|
// means command is lost, retry sending read command once more
|
||||||
return status;
|
if (SD_BLOCK_DEVICE_ERROR_NO_RESPONSE == _read(buffer, _block_size)) {
|
||||||
|
continue;
|
||||||
|
} else {
|
||||||
|
buffer += _block_size;
|
||||||
|
--blockCnt;
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// receive the data : one block at a time
|
// receive the data : one block at a time
|
||||||
do {
|
while (blockCnt) {
|
||||||
if (0 != _read(buffer, _block_size)) {
|
if (0 != _read(buffer, _block_size)) {
|
||||||
status = SD_BLOCK_DEVICE_ERROR_NO_RESPONSE;
|
status = SD_BLOCK_DEVICE_ERROR_NO_RESPONSE;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
buffer += _block_size;
|
buffer += _block_size;
|
||||||
}while (--blockCnt); // Receive all blocks of data
|
--blockCnt;
|
||||||
|
}
|
||||||
|
|
||||||
// Send CMD12(0x00000000) to stop the transmission for multi-block transfer
|
// Send CMD12(0x00000000) to stop the transmission for multi-block transfer
|
||||||
if (size > _block_size) {
|
if (size > _block_size) {
|
||||||
|
@ -897,8 +909,9 @@ bool SDBlockDevice::_wait_token(uint8_t token) {
|
||||||
if (token == _spi.write(0xFF)) {
|
if (token == _spi.write(0xFF)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
} while (_spi_timer.read_ms() < SD_COMMAND_TIMEOUT);
|
} while (_spi_timer.read_ms() < 300); // Wait for 300 msec for start token
|
||||||
_spi_timer.stop();
|
_spi_timer.stop();
|
||||||
|
debug_if(SD_DBG, "_wait_token: timeout\n");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue