Writing to absolute sectors on SD Card

Robert S. Grimes rsg at alum.mit.edu
Wed Nov 19 13:16:14 UTC 2008


Sebastian Huber wrote:
> Chris Johns wrote:
>   
>> Robert S. Grimes wrote:
>>     
>>> Is it possible to write to absolute sectors using the spi-sd-card driver?
>>>       
>> Yes but you are on your own with how this interacts with the cache. I wonder 
>> why the SD card is implemented this way. I would have thought the 
>> rtems_blkdev_generic_* calls such as rtems_blkdev_generic_write was the way to 
>> do this. This removes the need for sd_card_driver_read and 
>> sd_card_driver_write. Maybe Thomas could help here.
>>     
>
> I used the sd_card_driver_* stuff for testing and debugging.  Maybe it
> is better to remove it and provide only the LibBlock interface.  Can I
> just add these rtems_blkdev_generic_* functions to the sd_card_disk_ops
> and only provide a custom initialization function?
>
> [...]
>   
Sebastian,

Welcome back - I hope you enjoyed your vacation!

I'm just chiming in to clarify my usage of your driver.  As it sits 
right now, it works properly, with adequate performance for my 
application.  And more to the point, I no longer need, nor care, to 
write to absolute sectors.  So please don't expend any effort on this on 
my account - you and Chris have already done enough to help!

For your reference, it turns out that bulk of the data I'm writing 
happens to fit quite nicely into SD card blocks, so by writing a block 
at a time, I'm getting about 40 kilobytes per second throughput, while 
my application requires only 5 kilobytes per second.  A factor of 8 is 
enough to keep me feeling comfortable.  However, I did look into 
improving this some more, and I realized I had probably hit the limit of 
my hardware.  The SPI controller IP that Xilinx provides only supports a 
fixed clock, the frequency of which is frozen at configuration time.  My 
experiments have shown that SD cards do seem to require the 
MMC-compatible 400 kHz max clock rate at startup, so that is what I'm 
operating at - this limits data throughput to somewhat less than 50 
kbytes/sec - hence, I don't have much room for improvement!

I did spend an hour modifying the Xilinx IP to support a simple, 
two-rate clock, which allows me to select between 400 kHz and 6.25 MHz.  
Unfortunately, the driver no longer works.  When I set the clock to 400 
kHz at startup, I can indeed initialize the driver and card, and the 
card specific information is successfully read.  However, when I switch 
to the higher rate, things break down badly, and nothing seems to work.  
I have to put this to bed to meet my schedule, but I would be interested 
in working through this if someone else needs it and is willing to help.

FWIW - I still don't know how fast one can actually expect to write to 
an SD card.  As I've said before, SanDisk has published a number that 
leads one to believe only 21 kBytes/second is possible, though I have 
magically doubled that.  Ed Sutter has expressed disbelief in these 
numbers, citing digital cameras - at either of these two rates, their 
write performance would seem improbable!

Thanks again, guys!
-Bob





More information about the users mailing list