hi,
i want to store low frequency sound clip(basically) / general data through arduino (with atmega168 chip) on sd-card.Probably it would really be very easy to assume sd-card like simple eeprom chip if i does not have any file system like tell the card the address then data to be simply stored there. i want just arduino to read/write that sd-card data and non else. Does anybody have gone through this process ? or anybody suggest me a better way to do same?
I don't think you can do this. You need at least a rudimentary filing system to mark bad formatted blocks and have check sums for data packages. Without this I don't think an SD card would work.
Never done this but if this was my project I would start dissecting the SDfat lib or so. There must be valuable information in it how to read/write low level...
thanks everybody for your attention. can somebody suggest me a link that could describe very basics of these bad sectors like what causes them bad,its prevention plus other troubleshooting. Above all it would really be helpful for me the information about the initializing->reading->writing routines of card. i have searched & still been, on internet but cann't specific information.
4D LABS sold/sells a sd drive set-up I got from sparkfun a couple of years ago. Unlike most sd modules, it uses a serial link to read and write from. It's early firmware version only did raw 512 byte sector reads, writes, and seeking. A later firmware update added standard fat16 file system support, but retained the ability to just use it in raw sector mode.
http://www.saelig.com/STO/ST001.htm
http://www.4dsystems.com.au/prod.php?id=22
Lefty
very basics of these bad sectors
Ultimately a sector is an analog (real world) object with analog behavior. memory chips are silicon in precise configuration (more or less). The fact that we can store digital information (a bit = binary digit) on such an analog object is that there can be created at least 2 distinct states of such an analog object.
Real world object "wear out" and at a certain moment these 2 distinct (digital) states can not be discriminated anymore or become unpredictable in time (or in place or both). This is seen on every level Macroscopic level - the car key that must be moved up/down before it fits
Microscopic level - wear out of digital media - or faulty copies of DNA (telomeres) - and yes bad sectors!
That's in a nutshell the theory behind it. Back to practice. How to detect bad sectors?
Imagine a sector can hold half a kilobyte = 512 bytes = 4096 bits, then in the lower level sector there are quite some more. (wow can I put more data on it then? yes you can but ...) This extra bits contains at least address information and checksums / codes., either on byte level or on block level depending on the device - floppy, harddisk, etc. There can be even more info on a device like manufacturer, serial nr, production batch, date, etc.
The address information contains the id of the sector, its logical and/or physical location so it can be found back, and the checksums are the result of math formulas with as input data-bits.
So a sector looks like: [address info ][ data bytes ][checksum]
The checksums are very important, as when the checksum is wrong there was an error writing or reading the sector.
Example byte checksum
for every byte add an extra bit that show if the number of 1 bits in the byte are even or odd. Very similar to serial communication parity bit. Old IBM memory had 9 bit bytes. If one bit flips it can be detected, so its a 1 bit-error detecting code.
Besides byte level checksums one can define block (sector) level codes that can detect and even correct multibit errors. More info see - Error detection and correction - Wikipedia
These checksums are very vital for modern day computers, Imagine that a every single bit in memory has a chance of a bitflip once in 1.000.000.000.000 seconds (once in ~3000 years), then a 4GB memory has a chance of a biterror once every 250 seconds statistically speaking. Checksums correct this.
Epilogue:
Yes, you can write in raw format to a disk/SD and you will gain four features:
- extra space (max 10 percent I guess)
- extra speed (factor 2 at most I guess)
- extra errors (factor 2 - 10 ?? )
- extra code to compensate for the errors.
Back to your question, how to detect bad sectors? use checksums. Easiest way? use formatted disks.
sofar my 2 cents,
Rob
Well the whole bad sector subject is a strawman/legacy thing and not really applicable to a SD memory chips in my opinion. SD uses flash chips that are semiconductors, not a magnetic media. I don't think there is much likelihood of 'bad sectors' developing over time in the flash chips used in SD modules anyway, unlike magnetic hard-drives? We know they can fail once their guaranteed erase cycles specs have been exceeded and we don't take any great pains to test/check for that.
As I understand it anyway, bad sector testing and flagging in hard-drives is something only run, tested and detected during low level formatting. Once the formatting is done, any future bad sector will just be flagged as failed read/write checksums after so many retries? The file system for fat16/32 can't dynamically detect and flag out new sector errors on the run, at least that is my understanding. But as always I could be wrong. I once was.
We don't load checksums into our AVR's flash memory with our sketches for future error detection, but we could.
Lefty
I don't think there is much likelihood of 'bad sectors' developing over time in the flash chips
Agree, but I don't know if flash as we use them has a lower level with ECC codes built in. Never researched how flash drives work under the hood, but I do know that once and a while my USB stick and SD card fails... there must be something - http://www.youtube.com/watch?v=QnroWnC6seQ
update: how flashdrives work: - How Flash Memory Works | HowStuffWorks
update: source - USB flash drive - Wikipedia
Longevity
Barring physical destruction of the drive, the memory or USB connector of a flash drive will eventually fail. SLC based memory is good for around 100,000 writes; more commonly used MLC for around 10,000. The USB connector can withstand approximately 1,500 connect/disconnect cycles
Well the whole bad sector subject is a strawman/legacy thing and not really applicable to a SD memory chips in my opinion.
No flash memory comes in two types NAND flash and NOR flash. Memory cards are made from NAND flash.
To quote from that page:-
NAND flash is typically permitted to contain a certain number of faults (NOR flash, as is used for a BIOS ROM, is expected to be fault-free). Manufacturers try to maximize the amount of usable storage by shrinking the size of the transistor below the size where they can be made reliably, to the size where further reductions would increase the number of faults faster than it would increase the total storage available.
Also from the same page:-
NAND devices also require bad block management by the device driver software, or by a separate controller chip. SD cards, for example, include controller circuitry to perform bad block management and wear leveling. When a logical block is accessed by high-level software, it is mapped to a physical block by the device driver or controller. A number of blocks on the flash chip may be set aside for storing mapping tables to deal with bad blocks, or the system may simply check each block at power-up to create a bad block map in RAM. The overall memory capacity gradually shrinks as more blocks are marked as bad.
I have used NAND flash for booting set top boxes and can tell you that there are bad sectors in it due to manufacturing faults. Rather than scrap the chip it is much more economic to mask out the bad sectors.
One approach taken by some devices like the ARM pocket oscilloscopes is to get you to format the card on a PC and create a file of exactly the size you need with a known filename. Then the device interacts with the content of that file as if it were a device in itself ignoring the rest of the filesystem.