The Positive Rail
  • Blog
  • About
  • Contact

SD card sporadic write pauses

1/20/2015

2 Comments

 
I'm currently working on a project where I am streaming data to an SD card.  The problem I am having is that it it pauses periodically while writing.  Grr...
I am using an SPI interface with the SD card.  I am writing eight 512 bytes blocks using the block write command.  I've taken several steps to try to pre-erase the blocks, including the block erase command and pre-write erase.  A typical write cycle of eight blocks looks like this:
Picture
This is great - I am seeing (512*8 = 4k) in about 5msec, or about 819k/sec.  When I run this for a while, however, I have a problem.  I've set the program to print the number of blocks written every tenth block.  It also prints a # if the buffer (which is running from a sound card) is full.  It works until a few hundred blocks have been written - but then the # signs indicate that the program is waiting for the card to write.  
Picture
The behavior is pseudo-random.  If I restart the program, it will work again for a few hundred blocks (usually between 400-500) and then begin stalling.  It continues stalling for as long as it runs.  Looking at the actual signals we see that the write is now taking more than 50msec.  This reduces the throughput to about 73Kbytes/second, or about 1/10th of before.  
Picture
The behavior is the same across the two SanDisk 4GB (SDHC) and 64GB (Class 10) cards that I've tried.

Other people have reported this and the speculation is that it is specific to the SPI driver on the card, and that the behavior is better if using the 2 or 4 wire interface.

I've tried a lot of different things to get around this behavior - erasing large chunks of the card ahead of time, increasing the write buffer size, etc.  My guess is that the controller is optimized for very large writes of a few hundred kB (e.g. image files or movie chunks).  The problem is that I'm using a microcontroller that only has 16kB of SRAM, so my buffers (double buffers) cannot be larger than 8K.

For now I will slow down the data rate, and switch to a 2 wire protocol.  The average throughput -should- work for these cards.  It's disappointing that it won't work through the simple SPI protocol.
2 Comments
Vincent Smith link
10/6/2022 02:23:55 pm

Source data sport improve staff black. Well single operation positive high. Across room shoulder summer under office.
Probably decision head it morning. Leave lose both her.

Reply
Jason Cain link
11/13/2022 08:11:01 am

Game evidence rest go. Know line four. First notice play open grow letter. Describe minute somebody way understand eye.

Reply



Leave a Reply.

    What is this about?

    Embedded systems, nascent markets and minimalist product development

    Archives

    September 2014
    August 2014
    July 2014
    June 2014

    Categories

    All

    RSS Feed