2015-01-20 05:41 AM
I am getting a very annoying problem where my SD cards are becoming corrupted after recording data through a custom PCB.
I'm using the SDIO driver (fixed for 4GB), that clive has made available in the forum, for interfacing with the SD card. I acquire data through an external ADC and continuously save the data to the card. Until recently this was working well but now when I record data the SD card is becoming corrupt in such a way that even trying to format/save/delete data from the sd card on a PC is impossible. The sd card has become completely useless. I can still see/read the data that was saved but I can't do anything else. using sandisk SDformater tool it returns and error saying the card is write protected, however, I'm using micro sd cards and not the normal ones. This has happened twice now and I have no idea what can be the cause. Has anyone at all come across the same error? The hardware hasn't been changed and the firmware has been adapted to my needs. If this is firmware related then I might have stumbled in a way to damage the SD card. I haven't managed to carry out further tests because I'm afraid of damaging any SD card I use. If anyone has any ideas as to what tests I could make please let me know. Reading through the SD card specifications I can see that the sd card can be internally write protected but I don't see how this could happen unintentionally. #sdio #stm32 #fatfs #sd-card2015-01-20 08:25 AM
With writes you need to watch the SD FIFO completes (after DMA TC), and that the pending writes all complete properly.
You'd want to make sure you're catching any/all errors generated by the SD or FATFS code. Watch also the speed of the SDIO bus with respect to the performance of the cards.2015-01-20 08:43 AM
In addition to clive1's post:
I haven't managed to carry out further tests because I'm afraid of damaging any SD card I use. If anyone has any ideas as to what tests I could make please let me know.Pretty sure you only managed to damage the file system on the SD card, not the card itself. Just re-format it, and it will be fine.
2015-01-22 02:22 AM
Hi Clive,
Thanks for your reply. I have gone through the code to check the points you have mentioned and I can't see anything out of place. By that I mean that errors are being checked for. I will also check for FIFO being sent completely and as for the speed I'm using a 32GB class 10 48MB/s sandisk micro sd card running at 24MHz, so I think that may not be the issue. The strange thing is that this was working fine until I made a small change in the code. This change was only to set a marker on the data being saved, nothing else. I will revert this back and see if it works normally again but I'm waiting the new SD card to arrive. I did find out, through the CSD bits of the sd card, that the card has been permanently write protected and after contacting sandisk I was told that this is a safety feature so that the user doesn't lose the data. They didn't tell me what triggers this. Anyways, thanks for the suggestions and I'll see if I can find the error.2015-01-22 02:28 AM
Hi argentum,
I wish that was the case, however, the problem is worst than that. When I insert the card in the computer I can see the data and read it but I can't do anything else (that includes formatting). As I mentioned, for some reason the card has been set to permanently write protected and if you take a look at the sd card specifications this cannot be undone. I'm quite annoyed because I really want to figure out why this is happening. Sandisk is yet to return to me with more information about this safety feature but I don't think I will get much more information about it.2015-01-22 06:15 AM
Have you tried the HP USB Disk Format Tool ?
It's name suggest USB sticks, but I believe it also works for other media. At least worth a try. I would have tried several Linux tools too, like fdisk and parted. Edit: these tools probably wouldn't know about special Sandisk ''safety features'' ...2015-01-25 03:30 AM
Hi Argentum,
Thanks again for your suggestions. I havejust tried HP USB formater but I also got an error saying it was unable to format the card. I have tried using linux too but still didn't get anywhere. Sandisk still hasn't given me a better explanation other than it is a safety feature and that they will be replacing the cards I have sent them with this problem. I want to find out if the trigger of this issue is either firmware or hardware. The frustrating part is that this has worked well in the past and recently has started doing this. The hardware is exactly the same and the firmware was modified to change a single value of the buffer sent to the SD card to act as a time marker on the data. This shouldn't be the source of this problem but as soon as I receive the sd cards I've ordered then I will change the firmware back to when it was working and see if I still get any errors. If you have more suggestions please let me know .2015-01-25 07:59 AM
If you have more suggestions please let me know .
Not really - I'm out of ideas. Most of this tool assume the device they deal with obeys the specifications. Any deviation or addition is alien to them, and they are uncapable to deal with such cases. Proprietary tools help in such cases, not sure if Sandisk has any (at least for the public). My colleagues and me have made similiar experiences with MMC, CF and CFast devices. Fortunately, my employer can insist on payed support - which is rather difficult for a hobbyist or small company...
2015-01-27 08:30 AM
I have found the source of the problem!!! Somehow my external ADC got damaged and it was shorting the power supply when it was turned on.This was causing the power supply to have a significant voltage drop (up to 400mV) on the rail which I guess has triggered the card's protection. The SD card and the ADC are both on a supply and the MCU has a different power supply. It was only when the ext ADC was running that I would see this issue.
Anyways, it is good to know that if your sd card power supply oscilates whilst data is being written to the card then the internal protection of the sd card (Sandisk) triggers to prevent data loss. This also makes your card useless for anything else after that, except to read the data that was saved. Thanks for your suggestions.