I am currently using the STM3210B-EVAL Mass Storage example, which allow access of the SD card from a PC, through Mass Storage USB connection. The SD card is accessed through SPI. I'm using a 2GB microSD card, and I can successfully read and write files on it through Windows. So far so good.
However, I measure very poor write performances, something like 80 kB/s (writing a 10MB file takes approx 2 minutes). I measured up to 3MB/s writing performances on the same micro SD card, when used on a card reader, so the issue seems not to be that the card is too slow in itself.
Actually, I think I found out where most of the time is lost, but I fail to see why and how to correct this. Here is how it goes :
For each 512 bytes buffer to write, a write command (CMD24) is sent, followed by the 512 bytes of data. I modified the code and I use a DMA here so there is no wasted time. With a 12MHz clock on the SPI, this take approx 340ns. The SD card then send the "data ok" ack (0x05, or 0xE5 masked), and then sends zeros (MISO line is low) while writing the data. And there is the issue : this takes something like 2 to 4 ms! Then the data line goes up again, indicating the end of the write process, and the next buffer is sent.
There is a little time lost elsewhere, but even if there were not, counting just these 2-4ms for each 512 bytes, I can't expect more than approx 150kB/s of writing speed. This is way too low.
I noticed the example code is really simple, with only a few commands used (CMD17 and 24 for read and write, CMD9, 10 and 13 for infos and status, CMD0 and 1 for startup, and that's it).
I'm not looking for maximum performances, I know the SPI bus will limit the max speed, but what I notice here seems in no way linked to the limitations of the SPI bus, but to the time the SD card takes to write a buffer.
How would you solve this ?