View previous topic :: View next topic |
Author |
Message |
twesthoff
Joined: 16 Dec 2005 Posts: 6
|
Posted: Wed Jul 13, 2011 2:08 am Post subject: Write Throughput |
|
|
Niclas,
Have you done any testing to determine how fast (bytes per second) it will write a file to the SD card?
For example, how long does it take to write a 10Mbyte file?
I would be interested in your thoughts as to make writing as fast as possible, even if using a lot of RAM.
I have read about a block write mode where up to 32Kbytes can be written at one time. I do not totally understand how this works, but am interested in optimizing the write speed as much as possible.
Writing one byte at a time seems to be slow way to do it.
Tom |
|
Back to top |
|
|
KokkeKat
Joined: 08 May 2011 Posts: 59 Location: Stockholm
|
Posted: Wed Jul 13, 2011 4:09 pm Post subject: |
|
|
Hi Tom
I think that your questions and goal are relevant and interesting, but I haven't done any performance testing. I'm afraid I won't have time to write the code, but it should be reasonably simple to do.
Please notice that the current functionality is doing 512-byte sector writing to the card, so it's not that bad. Each time you call Sdwritebyte, it increments the array pointer, checks if it needs to save to the card (because of sector boundary crossing), stores the byte in the 512-byte array, and increments the file size counter. It is a number of operations, but it isn't byte-by-byte writing.
Anyway, here's what you need to do:
Please see the SD specification document found in the library zip file. Look at 7.2.4 "Data Write" on pages 117-118.
I don't know what is the limitation to how many 512-byte consecutive blocks you can send, but I couldn't find it in the specs when I looked briefly. I think the practical limitation is the number of sectors per cluster, in case you want to use FAT32, at least up to a certain card size. This means your application should be able to adapt to the inserted SD card's formatting and send the data for each cluster in one CMD25 multiple blocks transfer. (Never more than on cluster per transfer!)
This might mean that you will have to experiment to see how many 512-byte blocks your SD cards can actually handle in one transfer. Please be aware that there might be differences in the various manufacturers' interpretation of the SD standard, so what works on one card might not work on another. Try a 32GB and a 16GB SDHC and (if you think it's worth it) a 64GB SDXC.
There might also be SD card timeout considerations due to data collection CPU time, but I don't know what they are. (If you truly want high speed writing, you need to collect and write the data concurrently.)
You need to do something like this:
* Copy Sdwritesector: and split it into 3 parts:
___Sdwritesectorsa: sends CMD25 instead of CMD24 and sets the addressing mode
___Sdwritesectorsb: sends start token, 512-byte data block plus dummy CRC, receives response token, handles response, and waits until not busy
___Sdwritesectorsc: clocks SD, sets !CS, and clocks SD
###Repeat step b for each sector (512-byte block) you want to send
* Copy Sdwritebyte: and modify it so that it operates on a cluster and/or sectors instead of bytes. It has to keep track of the total number of characters your file gets (excluding the final empty bytes and sectors) - otherwise your file will seem to contain garbage at the end.
There might be additional steps for you to take, but this should get you started at least.
Please keep me posted on your progress. It would be nice if we could add this to the library.
Kind regards
Niclas |
|
Back to top |
|
|
twesthoff
Joined: 16 Dec 2005 Posts: 6
|
Posted: Thu Jul 14, 2011 4:17 am Post subject: |
|
|
Niclas,
Thank you for the detailed response. It will be some time before I get the hardware set up and can try this, but I hope to be able to do it.
If you get some time and could test how long it takes to write a 10Mbyte file, just writing a random string over and over for example, I would appreciate you posting your result. (Or anyone else who has the hardware setup.) No modifications, just the code as it is now.
I appreciate your work with the SD card code!
Tom |
|
Back to top |
|
|
KokkeKat
Joined: 08 May 2011 Posts: 59 Location: Stockholm
|
Posted: Thu Jul 14, 2011 1:28 pm Post subject: |
|
|
Hi Tom
Thanks!
I'll do it as soon as I can find the time. (I will be away on work and holiday in the next two weeks but I will post the result here then.)
Kind regards
Niclas |
|
Back to top |
|
|
glena
Joined: 25 Jul 2007 Posts: 284 Location: PA near Philly
|
|
Back to top |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum You cannot attach files in this forum You cannot download files in this forum
|
|