4
\$\begingroup\$

I'm a software developer working on an in-vehicle (WinCE) device that uses an SDIO card for its storage.

We are suffering from (seemingly) random corruptions of the data, seemingly from the FAT table getting corrupted. You may find inaccessible directories, files with "junk" half way through them, and so on. The card does NOT seem to suffer from physical damage (bad sectors) - a chkdsk fixes the FAT in most cases (the data of course is in trouble).

This sounds like a classic case of power loss in the middle of writes, so we've implemented a fair bit to combat that scenario.

We now have electronics to notify us that the master switch has been turned off, and give the application running on the device enough time to shut down cleanly.

Despite all that, we still have the problem. We seem to see corruption, even in the absence of a "dirty" shutdown.

Assuming for a second that the software side is all correct. Is it within the realms of possibility that momentary spikes, brown-outs,or other irregularlities in the power supply could cause what we're seeing? We have filters etc. in place to shut

Is it possible the ESD/electromagnetic interference could cause any of the above? Any other thoughts from an electrical/electronics side?

Much appreciated.

\$\endgroup\$
3
\$\begingroup\$

This is probably a software bug. However, you did say "vehicle", which implies unusually nasty power. If this is a normal car, then the "12V" power is about as bad as such things get electrically. You definitely can NOT just connect the 12V car power directly to your single board computer (or whatever your hardware is) unless it is specifically rated for "automotive power", even if it has a 12V or so power input.

Car power can be nearly 14V in normal operation, and can have 10s of volts of short term spikes. These can confuse or destroy electronics not specifically designed with them in mind.

You didn't say what voltage and current your computer needs, but the easiest solution is to get a "automotive rated" power supply that makes the right DC voltages. There must be such things available off the shelf somewhere.

\$\endgroup\$
  • 3
    \$\begingroup\$ Not only does a vehicle have "nasty power", it also has nasty vibrations. Normally that wouldn't be an issue, but it is possible that if the SDIO card connector isn't 100% good then there could be intermittent connections. If the OP can reproduce the problem on the workbench with a benchtop power supply then dirty power and vibrations can be eliminated as a source of the corruption. \$\endgroup\$ – user3624 Feb 16 '12 at 19:14
3
\$\begingroup\$

Most common flash media include within the storage device a mechanism which dynamically maps logical sector numbers to physical addresses, since software expects to be able to write any particular sector an arbitrary number of times with minimal delay, whereas most flash devices have hardware pages have to be recycled in groups of 256, 1024, or more. When one writes to sector 123, the hardware will identify a blank page, write page's data there along with some tags indicating that its sector 123. If one rewrites sector 123, the hardware will identify an old page, write the page's data there along with some tags. Additionally, the hardware will either assign the new page a sequence number of some sort that's higher than the old one, or else it will void out the tags on the old page. If there the number of blank pages available gets very small, the system will try to find a block on which many of the pages have been superceded, copy all the non-superceded pages from that block to some of the few remaining blank ones, and then erase the old block. Note that such an operation may involve any arbitrary collection of pages, often including pages not involved in any recent or current operation.

The logic to handle all of this in a flash device which has many millions of pages, but probably does not have millions of bytes of RAM, is quite complicated. Arranging the logic so as to be robust if power is lost at any point would make it even more so. It is possible that some companies have managed to design very robust systems for ensuring data integrity, but it's also pretty clear that not all flash media incorporate such systems (not effectively and correctly, anyway). Unfortunately, there's really no nice way for the software that writes to flash media to know what is going to happen 'behind the scenes' in response to a write request. Unless you require the use of media which are known to behave robustly in adverse conditions, the only way to avoid corruption in case of unexpected power loss is not to unexpectedly lose power.

\$\endgroup\$
3
\$\begingroup\$

I second the vote for software bug.

I recently worked through a flash corruption issue, on a WinCE system, as part of a development team. We would sporadically find 2K blocks of flash that were erased. (All bytes 0xFF) For about 6 months we tested everything from ESD, to dirty power to EMI and RFI interference, we bought brand new devices and tracked usage to make sure we weren't exceeding the erase cycle limit and buring out blocks, we went through our (application level) software with a fine toothed comb.

In the end it turned out to be an obscure bug in the very low level flash driver code, which only occurred under periods of heavy CPU load. The driver came from a 3rd party. We informed them of the issue we found, but I don't know if they ever released a patch.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.