I am working on a data logger that requires measurements to be taken during narrow time windows. I have been storing the measurement data on SD cards, however, the write times are very inconsistent, usually a few ms for 1kB but occasionally over 100ms which blocks the timing critical measurements.

I am using an STM32L4 microcontroller, FreeRTOS, and SDIO configured with DMA. I had hoped that this would allow long writes to yield to more timing critical tasks however STM32 SDIO implementation does not seem to like being interrupted.

What other mass storage options are viable that have consistent write times?

  • 4
    \$\begingroup\$ I would look into the buffering scheme first. You also do not say what capacity. MB? GB? How often is occasionally? Every few minutes? Or a couple of times per second? \$\endgroup\$
    – DKNguyen
    Nov 19, 2021 at 17:06
  • \$\begingroup\$ Any reason you can't thread your IO so that you decouple the write time from everything else? \$\endgroup\$ Nov 19, 2021 at 17:07
  • \$\begingroup\$ Most likely SD card wear leveling algorithm that causes this. Try different SD cards, maybe ones with rated for the use you need. Can you try USB storage? \$\endgroup\$
    – Justme
    Nov 19, 2021 at 17:23
  • \$\begingroup\$ @Justme that. Also, any SD cards timings will typically get worse over time. \$\endgroup\$ Nov 19, 2021 at 17:30
  • \$\begingroup\$ @DKNguyen It would be required to store at least a few gigabytes, we are collecting about 100 MB a day. Also always writing 1024 bytes at a time, the large delays are quite infrequent. Over 20ms roughly once ever 2-3 minutes and over 100ms every 4 hours. It's not consistent enough to be predictable though that's just the average. \$\endgroup\$
    – Liamm36
    Nov 22, 2021 at 9:43

1 Answer 1


There is a very wide range of performance and quality of SD cards.

"a SanDisk microSD card engineer reportedly stated that as many as one-third of all SanDisk microSD cards were counterfeit. "

You have a choice to create a FIFO buffer and/or get a better SD card to meet expectations.



Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.