Skip to content

Improve CSD parsing#222

Merged
thejpster merged 3 commits into
rust-embedded-community:developfrom
robamu:improve-csd-parsing
Feb 23, 2026
Merged

Improve CSD parsing#222
thejpster merged 3 commits into
rust-embedded-community:developfrom
robamu:improve-csd-parsing

Conversation

@robamu

@robamu robamu commented Feb 19, 2026

Copy link
Copy Markdown
Contributor

Use bitbybit which is a good fit here. Also Add V3

@robamu robamu force-pushed the improve-csd-parsing branch 3 times, most recently from 9ea263f to 99810cb Compare February 19, 2026 18:21
@robamu

robamu commented Feb 19, 2026

Copy link
Copy Markdown
Contributor Author

Oh, this repo uses separate develop and main branches. that confused me a bit.. Any thoughts on moving to one main branch?

@thejpster

Copy link
Copy Markdown
Member

develop holds the working branch, main holds the releases. A release involves a merge from develop to main.

Comment thread src/sdcard/proto.rs
Comment thread src/sdcard/mod.rs Outdated

@thejpster thejpster left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks OK - just some nits to tidy up.

What is CsdV3 for? I don't see it used?

@robamu

robamu commented Feb 19, 2026

Copy link
Copy Markdown
Contributor Author

I think I had a UC card in my zynq7000 card slot. right now I am working with the ARM9 system, but ill probably just put the SD card from the zynq7000 into that one. Did not come much farther than parsing the CDS so far.

@robamu

robamu commented Feb 19, 2026

Copy link
Copy Markdown
Contributor Author

just want to test this again on the new system, then I will undraft :)

@robamu

robamu commented Feb 23, 2026

Copy link
Copy Markdown
Contributor Author

Finally managed to read a CSDv2 from an SD card. I updated/tweaked the CRC7 checksum handling.

@robamu robamu marked this pull request as ready for review February 23, 2026 15:12
@robamu robamu requested a review from thejpster February 23, 2026 15:12
@robamu

robamu commented Feb 23, 2026

Copy link
Copy Markdown
Contributor Author

Oh, one more thing I want to do: I'll add the CSDv2 block retrieved as a new test :)

@robamu robamu force-pushed the improve-csd-parsing branch from 47217c5 to 89f2ad6 Compare February 23, 2026 16:15
@robamu

robamu commented Feb 23, 2026

Copy link
Copy Markdown
Contributor Author

Okay, just another last thing to make the feature creep stop: I added a CSD constructor, which determines the CSD structure type, constructs it, and also verifies the checksum.

Comment thread src/sdcard/proto.rs Outdated
@thejpster thejpster added this pull request to the merge queue Feb 23, 2026
Merged via the queue into rust-embedded-community:develop with commit 4d842eb Feb 23, 2026
7 checks passed
@shilga

shilga commented Mar 21, 2026

Copy link
Copy Markdown
Contributor

@robamu Since this PR sdmmc has troubles finding any sd card. If I go back to one commit before this PR was merged everything works fine. Did this work for you on real hardware?

0.151351 TRACE Reading partition table
0.151696 DEBUG Read 1 blocks @ 0
0.152738 DEBUG acquiring card with opts: AcquireOpts { use_crc: true, acquire_retries: 50 }
0.153693 TRACE Reset card..
0.154300 TRACE Enter SPI mode, attempt: 1..
0.155214 WARN  Got response: 67, trying again..
0.155950 TRACE Enter SPI mode, attempt: 2..
0.156825 WARN  Got response: 19, trying again..
0.157599 TRACE Enter SPI mode, attempt: 3..
0.158469 WARN  Got response: 19, trying again..
0.159248 TRACE Enter SPI mode, attempt: 4..
0.160117 WARN  Got response: 19, trying again..
0.160897 TRACE Enter SPI mode, attempt: 5..
0.161765 WARN  Got response: 19, trying again..
0.162547 TRACE Enter SPI mode, attempt: 6..
0.163415 WARN  Got response: 19, trying again..
0.164196 TRACE Enter SPI mode, attempt: 7..
0.165064 WARN  Got response: 19, trying again..
0.165845 TRACE Enter SPI mode, attempt: 8..
0.166713 WARN  Got response: 19, trying again..
0.167495 TRACE Enter SPI mode, attempt: 9..
0.168363 WARN  Got response: 19, trying again..
0.169144 TRACE Enter SPI mode, attempt: 10..
0.170012 WARN  Got response: 19, trying again..
0.170793 TRACE Enter SPI mode, attempt: 11..
0.171661 WARN  Got response: 19, trying again..
0.172442 TRACE Enter SPI mode, attempt: 12..
0.173311 WARN  Got response: 19, trying again..
0.174092 TRACE Enter SPI mode, attempt: 13..
0.174960 WARN  Got response: 19, trying again..
0.175741 TRACE Enter SPI mode, attempt: 14..
0.176609 WARN  Got response: 19, trying again..
0.177390 TRACE Enter SPI mode, attempt: 15..
0.178258 WARN  Got response: 19, trying again..
0.179040 TRACE Enter SPI mode, attempt: 16..
0.179908 WARN  Got response: 19, trying again..
0.180689 TRACE Enter SPI mode, attempt: 17..
0.181557 WARN  Got response: 19, trying again..
0.182338 TRACE Enter SPI mode, attempt: 18..
0.183206 WARN  Got response: 19, trying again..
0.183987 TRACE Enter SPI mode, attempt: 19..
0.184856 WARN  Got response: 19, trying again..
0.185637 TRACE Enter SPI mode, attempt: 20..
0.186505 WARN  Got response: 19, trying again..
0.187286 TRACE Enter SPI mode, attempt: 21..
0.188154 WARN  Got response: 19, trying again..
0.188935 TRACE Enter SPI mode, attempt: 22..
0.189803 WARN  Got response: 19, trying again..
0.190585 TRACE Enter SPI mode, attempt: 23..
0.191453 WARN  Got response: 19, trying again..
0.192234 TRACE Enter SPI mode, attempt: 24..
0.193102 WARN  Got response: 19, trying again..
0.193883 TRACE Enter SPI mode, attempt: 25..
0.194751 WARN  Got response: 19, trying again..
0.195532 TRACE Enter SPI mode, attempt: 26..
0.196401 WARN  Got response: 19, trying again..
0.197182 TRACE Enter SPI mode, attempt: 27..
0.198050 WARN  Got response: 19, trying again..
0.198831 TRACE Enter SPI mode, attempt: 28..
0.199699 WARN  Got response: 19, trying again..
0.200480 TRACE Enter SPI mode, attempt: 29..
0.201348 WARN  Got response: 19, trying again..
0.202130 TRACE Enter SPI mode, attempt: 30..
0.202998 WARN  Got response: 19, trying again..
0.203779 TRACE Enter SPI mode, attempt: 31..
0.204647 WARN  Got response: 19, trying again..
0.205428 TRACE Enter SPI mode, attempt: 32..
0.206296 WARN  Got response: 19, trying again..
0.207077 TRACE Enter SPI mode, attempt: 33..
0.207946 WARN  Got response: 19, trying again..
0.208727 TRACE Enter SPI mode, attempt: 34..
0.209595 WARN  Got response: 19, trying again..
0.210376 TRACE Enter SPI mode, attempt: 35..
0.211244 WARN  Got response: 19, trying again..
0.212025 TRACE Enter SPI mode, attempt: 36..
0.212893 WARN  Got response: 19, trying again..
0.213675 TRACE Enter SPI mode, attempt: 37..
0.214543 WARN  Got response: 19, trying again..
0.215324 TRACE Enter SPI mode, attempt: 38..
0.216192 WARN  Got response: 19, trying again..
0.216973 TRACE Enter SPI mode, attempt: 39..
0.217841 WARN  Got response: 19, trying again..
0.218622 TRACE Enter SPI mode, attempt: 40..
0.219491 WARN  Got response: 19, trying again..
0.220272 TRACE Enter SPI mode, attempt: 41..
0.221140 WARN  Got response: 19, trying again..
0.221921 TRACE Enter SPI mode, attempt: 42..
0.222789 WARN  Got response: 19, trying again..
0.223570 TRACE Enter SPI mode, attempt: 43..
0.224438 WARN  Got response: 19, trying again..
0.225220 TRACE Enter SPI mode, attempt: 44..
0.226088 WARN  Got response: 19, trying again..
0.226869 TRACE Enter SPI mode, attempt: 45..
0.227737 WARN  Got response: 19, trying again..
0.228518 TRACE Enter SPI mode, attempt: 46..
0.229386 WARN  Got response: 19, trying again..
0.230167 TRACE Enter SPI mode, attempt: 47..
0.231036 WARN  Got response: 19, trying again..
0.231817 TRACE Enter SPI mode, attempt: 48..
0.232685 WARN  Got response: 19, trying again..
0.233466 TRACE Enter SPI mode, attempt: 49..
0.234334 WARN  Got response: 19, trying again..
0.235115 TRACE Enter SPI mode, attempt: 50..
0.235983 WARN  Got response: 19, trying again..
0.236765 TRACE Enter SPI mode, attempt: 51..
0.237633 WARN  Got response: 19, trying again..
0.238414 WARN  unable to open volume0 DeviceError(CardNotFound)

@robamu

robamu commented Mar 21, 2026

Copy link
Copy Markdown
Contributor Author

Yes, this worked for me on real hardware with a dedicated SD peripheral. I was not using the Spi mode. Unfortunately i do not have the hardware to test with spi mode yet. Can you pinpoint where it goes wrong / is the code open-source?

@shilga

shilga commented Mar 21, 2026

Copy link
Copy Markdown
Contributor

I think the it is because you changed the crc7 algorithm. Now it gets the wrong value here and the commands are not accepted by the cart

buf[5] = crc7(&buf[0..5]);

@robamu

robamu commented Mar 21, 2026

Copy link
Copy Markdown
Contributor Author

A shift might be missing. I think the very last bit is 1 and the crc7 is left shifted by 1 but i would have to check the spec again.
I verified the crc7 updates against some spec examples as well

@shilga

shilga commented Mar 21, 2026

Copy link
Copy Markdown
Contributor

I just reverted this one line back to the original (crc << 1) | 1 and my sd cards are recognized again.

shilga added a commit to shilga/embedded-sdmmc-rs that referenced this pull request Mar 21, 2026
@shilga

shilga commented Mar 21, 2026

Copy link
Copy Markdown
Contributor

#237 fixes it for me

@robamu

robamu commented Mar 21, 2026

Copy link
Copy Markdown
Contributor Author

nice. hope this did not take too long to find. I should have looked for usages of the CRC7 function..

@robamu robamu deleted the improve-csd-parsing branch March 21, 2026 19:17
github-merge-queue Bot pushed a commit that referenced this pull request Mar 21, 2026
Fix SPI communication after #222 broke it
@shilga

shilga commented Mar 21, 2026

Copy link
Copy Markdown
Contributor

no worries. It cost me few hours today, but it was pretty clear soon that the problem is the lib itself and not my hardware. The rest was only that I did want to find the problem itself and it helped me understand the lib better.

Maybe we could add some tests to the spi communication so this can't happen again?

@robamu

robamu commented Mar 21, 2026

Copy link
Copy Markdown
Contributor Author

Some unittests most certainly sound good to prevent this in the future. Should be possiible by adding a SPI interface mock

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants