Skip to content

sdcard: Compute CRC7 for all SPI commands.#1088

Open
kwagyeman wants to merge 2 commits intomicropython:masterfrom
kwagyeman:kwabena/sdcard_fixes
Open

sdcard: Compute CRC7 for all SPI commands.#1088
kwagyeman wants to merge 2 commits intomicropython:masterfrom
kwagyeman:kwabena/sdcard_fixes

Conversation

@kwagyeman
Copy link

@kwagyeman kwagyeman commented Feb 25, 2026

Some SD cards (e.g., SDXC) permanently enable CRC checking in SPI mode. Sending commands with CRC=0x00 causes them to return ILLEGAL_COMMAND, making initialisation fail. Fixed this by computing a valid CRC7 for every command. Most of my SD cards did not work with the SPI code. After adding CRC support all the cards worked.

Also added a performance test to the test script to benchmark things (using baudrate of 20MHz):

OpenMV 071b46ba24; MicroPython 366b6bd242; OpenMV-AE3 with AE302F80F55D5AE
Type "help()" for more information.
>>> 
10811 bytes read

Single block read/write
11 bytes written
11 bytes read

Write speed test
528 KB/s
Read speed test
263 KB/s

Verifying data read back
Large file Pass
Small file Pass

Tests passed
OpenMV 071b46ba24; MicroPython 366b6bd242; OpenMV-AE3 with AE302F80F55D5AE
Type "help()" for more information.
>>> 

@kwagyeman kwagyeman changed the title Kwabena/sdcard fixes sdcard: Compute CRC7 for all SPI commands. Feb 25, 2026
Some SD cards (e.g. SDXC) have CRC checking permanently enabled in SPI
mode. Sending commands with CRC=0x00 causes them to return ILLEGAL_COMMAND,
making initialisation fail. Fix this by computing a valid CRC7 for every
command.

Signed-off-by: Kwabena W. Agyeman <kwagyeman@live.com>
Writes and reads 1 MB through the FAT filesystem and prints throughput
in KB/s.

Signed-off-by: Kwabena W. Agyeman <kwagyeman@live.com>
@kwagyeman kwagyeman force-pushed the kwabena/sdcard_fixes branch from d1cb87a to 95f72a7 Compare February 25, 2026 22:25
@kwagyeman
Copy link
Author

@dpgeorge - This fix is needed to make the SD card work on the AE3 for the battery shield: https://openmv.io/collections/openmv-ae3-accessories/products/openmv-ae3-battery-shield?variant=42433436385374

@dpgeorge
Copy link
Member

See #765, which does this and other improvements. I gave a lot of feedback on that PR and was waiting for it to be addressed, but it looks like that might never happen...

@kwagyeman
Copy link
Author

kwagyeman commented Feb 26, 2026

Oh... yeah, way to many changes in one commit in that PR. I tried to make sure this one just fixes what was causing problems. Nothing else to make it easy to review.

If that PR is in limbo, then would appreciate this being considered instead. The only change that needed to be done was to add CRC7 support.

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.

2 participants