Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sdcardio: Use CMD25 across multiple writeblocks() calls #5510

Merged
merged 5 commits into from
Oct 26, 2021

Conversation

jepler
Copy link
Member

@jepler jepler commented Oct 25, 2021

This increases write rates (of gifio from #5490) from about 2.4fps to over 5fps by making more efficient use of the SD card protocol.

Because of details of oofatfs, it usually manages 64 writes in a single CMD25, then two writes in a different area of the SD card (presumably, filesystem metadata). I couldn't find where to increase "64" to a higher number. 512*64 = 32768 bytes is the cluster size of the filesystem.

I tried preallocating too, but oddly it significantly lowered the write rate.

Any trailing data is committed when the file is close()d, or when the sync method of the SDCard object is called. You can check that this is happening by looking for the same token on the first & last lines of the file.

Test code (no gifio required):
code-cmd25.zip

Test board: Kaluga (v1.3), 32GB "class 10" micro SD card with "G.SKILL" branding in a https://www.adafruit.com/product/254

Speed in the test program increased from about 260KiB/s to over 725KiB/s.

This increases write rates (of gifio from adafruit#5490) from about 2.4fps to over
5fps by making more efficient use of the SD card protocol.

Because of details of oofatfs, it usually manages 64 writes in a single
CMD25, then two writes in a different area of the SD card (presumably,
filesystem metadata).  I couldn't find where to increase "64" to a higher
number. This may depend on the allocation size of the filesystem.

I tried preallocating too, but oddly it significantly lowered the write
rate.

Any trailing data is committed when the file is close()d, or when
the `sync` method of the SDCard object is called.
Copy link
Member

@tannewt tannewt left a comment

Choose a reason for hiding this comment

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

Looks good overall but has some prints in it still.

shared-module/sdcardio/SDCard.c Outdated Show resolved Hide resolved
Copy link
Member

@tannewt tannewt left a comment

Choose a reason for hiding this comment

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

Thank you!

@dhalbert dhalbert merged commit e868f1b into adafruit:main Oct 26, 2021
This was referenced Mar 25, 2022
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