cancel
Showing results for 
Search instead for 
Did you mean: 

Saving data to SD card

HChau.2
Associate

Hello everyone,

In CubeMX 5.3.0 I have configured FATFS+DMA+SDMMC for a card running STM32F777VI. i've been trying to save some data into a .txt file.

It works fine, but i can't write data to SD card as fast as I want. Requirement is to save 25 bytes every 3ms (which I receive from UART at 330Hz), but it seems doing so affects speed of other UART communications/ stops communication for a moment. What's the maximum write speed I can achieve without affecting other peripheral behavior?

I was playing with clock settings/SDMMC CLK divide factor to figure out if it's low clock setting issue. Attaching system clk config and SDMMC settings,can anyone see a potential problem in clock settings?

0693W000001tTBMQA2.png

0693W000001tTBbQAM.png

2 REPLIES 2
TDK
Guru

SDMMC gives no guarantees on execution speed. The first write typically takes much longer than 3ms, but even subsequent writes may take as long. Writing complete blocks (512 bytes) will be more efficient than writing 25 bytes at a time.

If you have hard timing requirements, you'll need to buffer the data you send to SDMMC and use DMA to transfer it. Using interrupts for UART communication is also an alternative.

If you feel a post has answered your question, please click "Accept as Solution".

Buffer data so you're writing large aligned blocks, calling f_write() with 25 bytes is going to murder performance

Would expect I could write blocks of 8 or 16KB, at 4-5 MBps all day, and not lose any data from the UART

Tips, buy me a coffee, or three.. PayPal Venmo Up vote any posts that you find helpful, it shows what's working..