-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Description
I tried to run samples/subsys/fs and I got error in disk_access_init() function. Tracking the problem, I noticed that the error was at the beginner of the communication between mcu and sdhc, when the mcu needs to send some CMD messages to initiate the communication. The error was, more specifically, in the sending of CMD9(SDHC_SEND_CSD) message.
(file disk_accesss_sdhc.c, sdhc_detect function, line 754)
/* Read the CSD */
err = sdhc_cmd_r1(data, SDHC_SEND_CSD, 0);
if (err != 0) {
return err;
}
err = sdhc_rx_block(data, buf, sizeof(buf));
if (err != 0) {
return err;
}
If we look sdhc_cmd_r1_raw() function, which is called inside sdhc_cmd_r1() function, we will see that we are discarding a byte with this code
(file disk_accesss_sdhc.c, sdhc_cmd_r1_raw function, line 457)
/* Ensure there's a idle byte between commands */
sdhc_rx_u8(data);
I think that this is the problem, because according to this table we can't discard every time,
there is some commands that have a data packet response after R1, R3/R7 response, so the existence of the code above is eating the message token of data packet response.
To solve this bug I just replace the code above with this if statement
if (cmd != SDHC_SEND_CSD && cmd != SDHC_SEND_CID &&
cmd != SDHC_READ_SINGLE_BLOCK && cmd != SDHC_READ_MULTIPLE_BLOCK &&
cmd != SDHC_WRITE_BLOCK && cmd != SDHC_WRITE_MULTIPLE_BLOCK) {
sdhc_rx_u8(data);
}
and the sdhc disk was initiated and mounted successfully. I do not know if this is the best solution, but is the solution that worked for me until now.
@edit: I'm sorry, I think that I was not clear, I forgot to mention that the error is in sdhc_rx_block, after send SDHC_SEND_CSD. In this portion of code
if (token != SDHC_TOKEN_SINGLE) {
/* No start token */
return -EIO;
}
The data packet response token was lost.
