sdcard_sd: Decode commands always as command#127
sdcard_sd: Decode commands always as command#127harper23 wants to merge 1 commit intosigrokproject:masterfrom
Conversation
|
|
Am 08.12.2025 um 19:31 schrieb Dan Horák:
sharkcz left a comment (sigrokproject/libsigrokdecode#127)
- please add the description to the commit message, the project is not using MRs
- the commit subject should be "sdcard_sd: Decode commands always as command" to follow the style and fix a typo
Hi Dan,
many thanks for your mail. It helps me to provide a pull request
acceptable for the sigrok project. I am rather new to GitHub
contribution. So, please allow me to describe, how I want to proceed.
I will make a new commit using the --amend option to rewrite the commit
message like this
sdcard_sd: Decode commands always as command
The SD card decoder predicts always the next token type from the
current token type. This is working if the SD card is responding
as expected.
But if the card is not responding, the prediction is wrong. A second
command token is decoded as a response token.
To fix this behavior the decoder state is set to St.GET_COMMAND_TOKEN,
if the current token is a command token.
Then I push with the option --force-with-lease.
This fixes the commit message, the pull request is still at the HEAD of
my repository. I checked with another (private) repository how this
change can be done. But the pull request title has still the typo. I
hope this is okay.
How do you think?
Regards,
Helge
|
|
Hi Helge, |
The SD card decoder predicts always the next token type from the current token type. This is working if the SD card is responding as expected. But if the card is not responding, the prediction is wrong. A second command token is decoded as a response token. To fix this behavior the decoder state is set to St.GET_COMMAND_TOKEN, if the current token is a command token.
|
Push is done. I hope this contribution is helpful and can be integrated in the sigrok repo. |
|
Thanks, it looks good to me. Now we need someone familiar with the decoders who can do a review from a functional point of view. |
|
@harper23 I didn't do a whole lot of checking, but I don't like the approach taken. The issue is that However, even if I'm right I would suggest to change the implementation. This is a very unexpected sideeffect. My suggestion would be to read the first two bits in |
|
@Krakonos This works because the implementation of all
The number of expected bits are hard coded in the functions. The R2 response has 136 bits, the other 48. In that way the variable I agree that this could be implemented in a completely different way. First grab as many bits until a token is complete, then decode the token. This would also allow to identify aborted tokens. You can find in |
|
@Krakonos I have implemented a redesign of the state machine. Now the token is assembled first before any handler for command or response is called. If the token is complete, the handler for common fields is called. Thereafter the Transmission bit is used to make the decision for the command or response handler. I have started a branch I have also added some additional traces to the sigrok-dumps repository and test cases to the sigrok-test repository. |
|
Hi! Sorry it took me a bit to get back to you. I've read through the Move the block following
Edit: Originally posted this under a wrong account... |
|
I have created a factor The original state machine counts all bits at the rising CLK edge. If error happens, this will be stuck in the same way. The data transmission in the SD-card protocol is synchronous. But the frame has start and stop bit, i.e. is asynchronous. If there are gaps between tokens while the clock is still active, the decoder will find a stop bit and the next start bit gives you a new synchronization with the token. Hence, calling You can simulate this easily by using a file created with the "Save range as..." menu item. I attach incomplete.zip with an example, one file has an incomplete command. It would be possible to detect this with the new state machine, because it first takes the token and could check the CRC7. You could mark the token is invalid. This is not always simple, since the CRC field is calculated differently depending on the response type. See section "4.9 Responses" of the "Physical Layer Simplified Specification". |
The SD card decoder predicts always the next token type from the current token type. This is working if the SD card is responding as expected. But if the card is not responding, the prediction is wrong. A second command token is decoded as a response token.
See example trace file. SD-card-init-001.zip
To fix this behavior the decoder state is set to St.GET_COMMAND_TOKEN, if the current token is a command token.