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

Micro SD write speed on RP2040 is too slow #156

Open
axoulc opened this issue Oct 25, 2024 · 3 comments
Open

Micro SD write speed on RP2040 is too slow #156

axoulc opened this issue Oct 25, 2024 · 3 comments

Comments

@axoulc
Copy link

axoulc commented Oct 25, 2024

Hello,

Here is my configuration:

  • MCU : RP2040
  • SPI speed: 16MHz
  • Periodic write size: ~80 bytes

I'm using the embedded-sdmmc-rs library (version 0.5.0 because I can't get SpiDevice to work on thumbv6m-none-eabi architecture, although I've tried with embedded-hal-bus without success).
My program writes one line of a CSV file as quickly as possible and starts again. Each time I open the same file, prepare my bytes, write to the micro SD and close the file. I measured a time of around 54ms per write, which is far too long for my application (I'd like at least 10x faster).

Do you have any advice for my problem or even solutions?

Thanks in advance

@michaelkamprath
Copy link

If you call the VolumeManager::write method for each individual byte, then that is a very slow process. Even if you write a small buffer, the overhead of everything that needs to happen just to lay down the bytes is high. I've written a buffer manager that wraps the VolumeManager for a specific file, and gives me a write like interface that instead of writing the byes to the SD card right away, they get written to a buffer that in turn writes to the SD card when sufficient bytes have been accumulated to make the overhead of the write worth it. Also added a flush method just to force the write if warranted.

BTW, I do have the latest version of SpiDevice working on the RP2040 just fine with the lates embedded-hal. You do need to implement the transaction method of the SpiDevice trait. Don't forget that the chip select pin for a SPI device is active low ... that issue tripped me up for a while.

@axoulc
Copy link
Author

axoulc commented Oct 25, 2024

@michaelkamprath
For the SpiDevice, I was just too lazy to develop this trait.
I'll study your answer. If you can share a snippet of your code for the VolumeManager, I'd love to.
Thanks in advance.
PS: and yes, Chip Select is written as /CS because it's active when low ;)

@michaelkamprath
Copy link

Here is some sample code that I have working on a rp2040: https://github.com/michaelkamprath/rp2040-rust-robot/blob/main/src/robot/file_storage/sd_card_spi_device.rs

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

No branches or pull requests

2 participants