Go Down

Topic: 2 SD cards in parallel (Read 5804 times) previous topic - next topic

robtillaart


Is it possible to write to 2 SD card simultaneously?  So using the same SS pin for both? Same type cards, fresh formatted, ...

I strongly expect there will be conflicts with the (sector) administration or so.
Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

frank26080115

are you looking for redundancy? why do you need 2 cards in parallel with the slave select going to both at once? just want two copies of the same data really fast?

i would never design this way, too many things can go wrong

does formatting erase all the bits? if not, then you are obviously asking for trouble when reading the card

having two cards in parallel means two pins driving the same signal, even the slightest differences in signal timing will cause a conflict

I suggest simply having two SS pins and performing the same operation twice
Freelance engineer, consultant, contractor. Graduated from UW in 2013.

robtillaart

Quote
just want two copies of the same data really fast?

That was the basic idea, no intention to build a RAID 5 storage

Quote
does formatting erase all the bits?

It should clean up all relevant bits,

Quote
having two cards in parallel means two pins driving the same signal, even the slightest differences in signal timing will cause a conflict

yes at some time you would need to read a directory or a FAT etc and that's asking for interference ==> trouble.

Quote
I suggest simply having two SS pins and performing the same operation twice

That is my original design but I just wondered if it could be done in parallel, would free some CPU cycles and footprint.
Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

fat16lib

SD cards can't be run in parallel.  They are very complex, more complex than the Arduino.

When you send a command to a card it goes busy by pulling MISO high until it is ready to send status.  If you had two cards enabled they would interfere with each other.

There are many other reasons this won't work.

You could write a driver that mirrored blocks during write but this is the easy part of the problem.  The cards are bound to get out of sync due to crashes or unexpected power downs.

You would need a program to resolve inconsistencies in file systems.  This is a hard problem.

frank26080115

Quote
It should clean up all relevant bits,


All relevant bits? If it's not literally all bits, then you're going to have problems.

Quote
yes at some time you would need to read a directory or a FAT etc and that's asking for interference ==> trouble.


That's not what I meant, I even if both cards tried to send 0x55, you might still get timing differences on the picosecond scale.

If you are desperate for speed, try a multi-processor system, where one processor is dedicated to writing to two cards

Then again, if you need speed, SD cards are not the right solution in the first place.
Freelance engineer, consultant, contractor. Graduated from UW in 2013.

robtillaart

Quote
All relevant bits? If it's not literally all bits, then you're going to have problems.

A fast format only cleans the FAT table but not the filedata on disk, but that should be enough. that is what I meant

Quote
That's not what I meant, I even if both cards tried to send 0x55, you might still get timing differences on the picosecond scale.

thanks for explaining, I'll stick with the original and proven "write twice" strategy.
Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

frank26080115


A fast format only cleans the FAT table but not the filedata on disk, but that should be enough. that is what I meant


Ah, but that is not enough. Imagine you read one card and it outputs a bit 1, while the other card reads a bit 0. What happens on the MISO pin? One will be driven high while the other is driven low. That's like short circuiting the positive terminal of a battery with the negative terminal, you'll end up getting a surge of current between the two pins, quite possibly causing damage.
Freelance engineer, consultant, contractor. Graduated from UW in 2013.

fat16lib

Forget it.  Cards don't just start sending data when you read.  A card holds MISO high until it is ready and then sends a start of block token followed by data.

The idea of parallel cards won't work!

An SD card is not a simple passive device!!  They do things when they want to.

johnwasser

You should give it a try.  Just remember to leave MISO unconnected from one of the two cards so they don't conflict on reads.
Send Bitcoin tips to: 1L3CTDoTgrXNA5WyF77uWqt4gUdye9mezN
Send Litecoin tips to : LVtpaq6JgJAZwvnVq3ftVeHafWkcpmuR1e

frank26080115


You should give it a try.  Just remember to leave MISO unconnected from one of the two cards so they don't conflict on reads.


All the code I've used to access SD cards has a little bit that requires the card to be ready before performing any write action, without MISO, this is impossible to detect. If you add delays, then you pretty much forfeit the advantage of having the two cards in parallel, which is speed. Also, no reading means no writing unless you are writing in 512 byte blocks only, due to the way flash memory works (erase by blocks, so you need to read in what was there before if you only write a partial block)
Freelance engineer, consultant, contractor. Graduated from UW in 2013.

johnwasser



You should give it a try.  Just remember to leave MISO unconnected from one of the two cards so they don't conflict on reads.


All the code I've used to access SD cards has a little bit that requires the card to be ready before performing any write action, without MISO, this is impossible to detect. If you add delays, then you pretty much forfeit the advantage of having the two cards in parallel, which is speed. Also, no reading means no writing unless you are writing in 512 byte blocks only, due to the way flash memory works (erase by blocks, so you need to read in what was there before if you only write a partial block)


I said "leave MISO unconnected from ONE of the two cards".  If it's going to work at all it will work by having the two cards sufficiently similar that the timing that works for the one that is connected to MISO will also work for the one that is NOT connected to MISO.  I'm not saying that it WILL work, only that there is little reason not to try.
Send Bitcoin tips to: 1L3CTDoTgrXNA5WyF77uWqt4gUdye9mezN
Send Litecoin tips to : LVtpaq6JgJAZwvnVq3ftVeHafWkcpmuR1e

frank26080115

#11
Sep 14, 2011, 02:29 am Last Edit: Sep 14, 2011, 02:53 pm by frank26080115 Reason: 1



You should give it a try.  Just remember to leave MISO unconnected from one of the two cards so they don't conflict on reads.


All the code I've used to access SD cards has a little bit that requires the card to be ready before performing any write action, without MISO, this is impossible to detect. If you add delays, then you pretty much forfeit the advantage of having the two cards in parallel, which is speed. Also, no reading means no writing unless you are writing in 512 byte blocks only, due to the way flash memory works (erase by blocks, so you need to read in what was there before if you only write a partial block)


I said "leave MISO unconnected from ONE of the two cards".  If it's going to work at all it will work by having the two cards sufficiently similar that the timing that works for the one that is connected to MISO will also work for the one that is NOT connected to MISO.  I'm not saying that it WILL work, only that there is little reason not to try.


oops sorry, must have read "or" instead
Freelance engineer, consultant, contractor. Graduated from UW in 2013.

fat16lib

This will never work! 

Two identical cards will not have the same timing because no two cards are identical.  Flash has bad spots that are remapped.

The delays happen due to the flash controller in the cards doing wear leveling, flash erase of large blocks, remap of bad spots, and other operations. 

The timing of two cards will never allow parallel operations because no two cards behave the same.



johnwasser


This will never work! 


Would it not be possible to produce a circuit that detects when both cards are ready before signaling ready?

My understanding is that the SD card holds the MISO/DO line high while it's busy after a command.  It seems to me that it would not be that hard to detect this signal (and differentiate it from data on the MISO/DO line) so that the MISO/DO line could be held high if either SD card was busy.  Would that not allow the command to successfully complete on both cards?
Send Bitcoin tips to: 1L3CTDoTgrXNA5WyF77uWqt4gUdye9mezN
Send Litecoin tips to : LVtpaq6JgJAZwvnVq3ftVeHafWkcpmuR1e

fat16lib

I suggest you read the SD protocol spec.  Your ideas are not even close to possible.

Good luck detecting the difference between data, commands, and status.

How do you handle command status?   Both cards send status after a command.  Which status do you send on the SPI bus to the Arduino?

SD cards rarely fail.  Most lost data is due to software bugs, unexpected reboots, or power down during a write.

Parallel cards won't help much.

You could write your precious data to two cards.  SdFat supports multiple cards on the SPI bus.  You could have a file open on each card and write your data to both files.  It is likely one card will survive a reboot or power down.

You would need to use a Mega since each card requires a 512 byte cache.  Only very small apps can support two cards on a 328.

Go Up