{\r
bool need_stop_command = rx_length > SDSPI_MAX_DATA_LEN;\r
spi_transaction_t* t_command = get_transaction(slot);\r
+ const int cmd_extra_bytes = 8;\r
*t_command = (spi_transaction_t) {\r
- .length = (SDSPI_CMD_R1_SIZE + 8) * 8,\r
+ .length = (SDSPI_CMD_R1_SIZE + cmd_extra_bytes) * 8,\r
.tx_buffer = cmd,\r
.rx_buffer = cmd,\r
};\r
release_transaction(slot);\r
\r
uint8_t* cmd_u8 = (uint8_t*) cmd;\r
- size_t pre_scan_data_size = 8;\r
+ size_t pre_scan_data_size = cmd_extra_bytes;\r
uint8_t* pre_scan_data_ptr = cmd_u8 + SDSPI_CMD_R1_SIZE;\r
\r
+ /* R1 response is delayed by 1-8 bytes from the request.\r
+ * This loop searches for the response and writes it to cmd->r1.\r
+ */\r
+ while ((cmd->r1 & SD_SPI_R1_NO_RESPONSE) != 0 && pre_scan_data_size > 0) {\r
+ cmd->r1 = *pre_scan_data_ptr;\r
+ ++pre_scan_data_ptr;\r
+ --pre_scan_data_size;\r
+ }\r
+ if (cmd->r1 & SD_SPI_R1_NO_RESPONSE) {\r
+ ESP_LOGD(TAG, "no response token found");\r
+ return ESP_ERR_TIMEOUT;\r
+ }\r
\r
while (rx_length > 0) {\r
size_t extra_data_size = 0;\r