Skip to content

Error initiating sdhc disk #15444

@lucaspeixotot

Description

@lucaspeixotot

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,

2019-04-14-144849_910x463_scrot

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.

Metadata

Metadata

Assignees

Labels

area: Disk AccessbugThe issue is a bug, or the PR is fixing a bugpriority: lowLow impact/importance bug

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions