![](templates/subSilver/images/CCSLogo.jpg) |
![CCS C Software and Maintenance Offers](templates/subSilver/images/forumAd6.jpg) |
View previous topic :: View next topic |
Author |
Message |
Hans Wedemeyer
Joined: 15 Sep 2003 Posts: 226
|
SD memory card what is the dirty little secret. |
Posted: Wed Jul 21, 2004 9:39 pm |
|
|
This is a long post, but without the details it may be even more confusing...
I've been using the SD card for a while. My original attempt at reading a card with some code given to me, left me with a working system that could only read a particular 32Meg card, I was convinced I did something wrong and could not find the problem.
I needed to move on and purchased an Atmel SD card library, and ported it to the PIC18 with good results. I was then able to read a lot more SD cards.
Recently I've run into a problem with certain brand name 32 meg card (Delkin, & HP) that I cannot read, and today I got (eBay) a bunch of 16 meg cards that I also cannot read.
These 16 meg cards come formatted with FAT12, and I need FAT16. So I formatted one and it works OK on the PC using a USB SD card reader.
My PIC project cannot read these cards.
So I did something I had considered doing for a while and wrote my own version of a format function for the SD card, on my PIC project hardware.
The results is I can now read and write to the entire card.
Here comes the reason for my post:
The card I inserted was according to the USB reader and WinHex FAT12 .
My hardware formatted it to FAT16, and it is 100% OK to read and write. Using the ICD-U40 debugger the boot sector entries are correct for a 16 meg card. So My code did the trick.
I then plugged that card back into the USB read and looked at my handy work with WinHex, and found the bot sector was still reporting it as FAT12 with correct entries for FAT12...
I inserted it into an iPAQ and used a flash format program, which reported it as FAT12.... ! Put it back in my PIC hardware and it works as FAT16 and the debugger confirms the boot sector reads as FAT16 !
I got 10 cards and have reproduced this effect TWO time... I'm saving the other 8 card for show a few people in the coming days... These are people that would normally call me nuts and so I have to defend the little bit of sanity I still have :-)
So what is the dirty little secret behind this SD card boot sectors. I have confirmed the USB read is NOT using SPI to read/write the card, I am using SPI.
I have no concrete evidence to prove this:
However it looks like the SD card interface has access to a different copies of the FAT. One for the 4 wire hardware and one for SPI interface...
It is the only logical reason I can come up with (pure guess work) as to why the two FATS coexist on the same card and appear to both start at address 0.
This SD card "thing" is not a clear cut as many have indicated....
I wonder why the SD card org. wants $11,000.00 for membership, is there a dirty little secret about the SD card that they hope $11K will prevent the rabble from finding out.... ?
As we all know the MMC morphed into the SD card , the SD card connectors prove the SD card was an after thought. i.e. poor planning when the MMC was born. |
|
![](templates/subSilver/images/spacer.gif) |
Steve H. Guest
|
|
Posted: Wed Jul 21, 2004 10:48 pm |
|
|
Ouch! You have convinced me to stick with CF cards or my own Flash EEPROM dongles!
That is really weird...
Steve H. |
|
![](templates/subSilver/images/spacer.gif) |
lucky
Joined: 12 Sep 2003 Posts: 46 Location: South Coast - England
|
Nasty |
Posted: Thu Jul 22, 2004 2:04 am |
|
|
Wow, that sounds real nasty.
I use CF in my MP3 player project but almost went the MMC/SD route. _________________ Lucky
www.mpic3.com - MPIC3 player project, Forum, Downloads, Online Shop |
|
![](templates/subSilver/images/spacer.gif) |
ckielstra
Joined: 18 Mar 2004 Posts: 3680 Location: The Netherlands
|
|
Posted: Thu Jul 22, 2004 5:45 am |
|
|
Hans,
There are several documents describing the SD-card:
* "SD Memory Card Specifications, part1 physical layer specification"
* "SD Memory Card Specifications, part2 file system specification"
* "SD Memory Card Specifications, Secure Digital Input/Output (SDIO)
Card Specification"
A simplified version of the first and third documents can be found at the Sandisk website http://www.sandisk.com/industrial/manuals.asp and also via links at http://www.sdcard.org/sd_memorycard/index.html.
The second document is way more interesting for your problem and I haven't been able to find this on the internet. The full documents are confidential and I guess the reason for this secrecy is that they want you to pay a substantial amount of money for use of their patents.
Where did you find the information of a $11,000 membership? The information I found starts at an annual $1,500 Membership fee and annual $1,000 license fee (per product?). |
|
![](templates/subSilver/images/spacer.gif) |
ckielstra
Joined: 18 Mar 2004 Posts: 3680 Location: The Netherlands
|
|
Posted: Thu Jul 22, 2004 6:09 am |
|
|
I don't know, but could your problems with some of the cards have something to do with multiple partitions on your flash card?
Because you wrote your own formatting routines you are quiet sure to have created a new Master Boot Record (MBR), but are the USB devices (under Windows?) looking at the MBR or are they looking at an Partition Boot Sector (PBS)?
In the Sandisk SD Card Product manual I found the following which made me wonder: Quote: | Protected Area—The part of the Card that relates to the secured copyright management and has separate DOS partitioning including sectors and blocks. |
I have a question: Can you tell us the value in the FILE_FORMAT field of the CSD register for a working card and for a card that you can't read? This field is rewritable and indicates the file format on the card:
Quote: | 0 = Hard disk-like file system with partition table
1 = DOS FAT (floppy-like) with boot sector only (no partition table)
2 = Universal File Format
3 = Others/Unknown |
|
|
![](templates/subSilver/images/spacer.gif) |
Guest
|
Data Sheet |
Posted: Thu Jul 22, 2004 7:48 am |
|
|
ckielstra wrote: | Hans,
There are several documents describing the SD-card:
* "SD Memory Card Specifications, part1 physical layer specification"
* "SD Memory Card Specifications, part2 file system specification"
* "SD Memory Card Specifications, Secure Digital Input/Output (SDIO)
Card Specification"
A simplified version of the first and third documents can be found at the Sandisk website http://www.sandisk.com/industrial/manuals.asp and also via links at http://www.sdcard.org/sd_memorycard/index.html.
The second document is way more interesting for your problem and I haven't been able to find this on the internet. The full documents are confidential and I guess the reason for this secrecy is that they want you to pay a substantial amount of money for use of their patents.
Where did you find the information of a $11,000 membership? The information I found starts at an annual $1,500 Membership fee and annual $1,000 license fee (per product?). |
Yes I have all these doc's and more. Until a few months agod Snadisk had the SD card spec. sheet on the web site. Now it says to contact Tech. support at Sandisk.
So I did, and I got a message from them to Join the club before they can elevate the question to their engineers. !
So I called the SD Org and talked with them.
They will sell the data sheet to non-members for $1,100.- !
At the same time I ask about membership... $11K per year.
At that time I ended the convesation !
I the meatime I searched the web and found the (I thin is latest) data sheet V1.7 on a Russian site ! |
|
![](templates/subSilver/images/spacer.gif) |
Guest
|
format |
Posted: Thu Jul 22, 2004 9:03 am |
|
|
ckielstra wrote: | I don't know, but could your problems with some of the cards have something to do with multiple partitions on your flash card?
Because you wrote your own formatting routines you are quiet sure to have created a new Master Boot Record (MBR), but are the USB devices (under Windows?) looking at the MBR or are they looking at an Partition Boot Sector (PBS)?
In the Sandisk SD Card Product manual I found the following which made me wonder: Quote: | Protected Area—The part of the Card that relates to the secured copyright management and has separate DOS partitioning including sectors and blocks. |
I have a question: Can you tell us the value in the FILE_FORMAT field of the CSD register for a working card and for a card that you can't read? This field is rewritable and indicates the file format on the card:
Quote: | 0 = Hard disk-like file system with partition table
1 = DOS FAT (floppy-like) with boot sector only (no partition table)
2 = Universal File Format
3 = Others/Unknown |
|
Yes I read that, however the statements much earlier in the doc. state that the SD card is MMC compatible.
When the card gets initialized ( CMD0 and CMD1 using SPI) it ends up as an MMC card and knows nothing about the SD features. That could explain why my code is seeing the "regular" boot sector which I formated and somewhere on the card is another copy holding the original FAT12 boot sector, accessible only throught the SD secure commands, which in MMC mode have no menaing. You may be on to something here. I'll need time to investigate it.
I'll have to rig up some code to read the CSD register.
I'll have to write code to do this, it's not part of the lib. and will post update when (this weekend, hopefully) I have results.
I did check the OCR register to make sure the cards I have will work at 3.3Volts, and everyone I have are good for it.
Thanks for the info. the search goes on... |
|
![](templates/subSilver/images/spacer.gif) |
Hans Wedemeyer
Joined: 15 Sep 2003 Posts: 226
|
Some results |
Posted: Thu Jul 22, 2004 11:06 am |
|
|
Not sure what to make of this yet:
Formatted a 16MB card to FAT16 on the iPAQ and confirmed it "took" by using WinHex on the PC with the UBS reader.
Put the card in my hardware and read 00 at all boot sector locations.
Formatted the boot sector in my hardware to FAT16. Read that same boot sector and it reads correctly.
Using WinHex wrote 00 to every location.
After that I tried to open the card(drive) again using WinHex and WinHex complained it could not read the card....
So that confirms the boot sector has 00 in all locations.
Put the card back in my hardware and it read the FAT16 boot sector correctly !
Wrote the boot sector and FAT again.
The card shows up as a 7 meg card, of half or partition is used. !
With my hardware/software made two directories.
folder1
folder2
Read the card again using WinHex and WinHex was able to read the FAT as FAT16, and WinHex found the two folders. However Explorer reported one folder but name was wrong !
In the iPAQ flash format reported 2 sectors per cluster ! Yet the FAT16 my hardware/software wrote was 1 sector per cluster.
Formatted on the iPAQ using Flash Format to 1 sector per cluster and enabled the Backup FAT.
Put the card back in my hardware and am able to write to the two ORIGINAL folder1 and folder2 !
I think this confirms the iPAQ using Flash Format uses a copy of the boot sector and FAT.
Put the card in the USB reader and made two directories
ABC345
ZXY123
Confirmed Windows File explorer was able to "see" these, and also the iPAQ.
However my hardware only sees the folders it made and still only reports 7 meg...
Initial conclusion there are two partitions that are only seen by the respective hardware that made them.
Winhex can see the folder entries for folder1 and folder2 and they are at 0X15800 which is not the root directory as reported by WinHex , also WinHex reports only one FAT !
Yet I enabled the second FAT in the iPAQ.
So if you want to lose data fast... Write your own FTA in PIC hardware and if you then write something on the PC with a USB ready .... chances are you will blow away your PIC/FAT..... !
Clearly there are two boot sectors and different FAT's .
Getting these to be synchronous seems to be the task at hand.
Perhaps the CSD register holds the clue...
I think this is the biggest mess I have ever seen.... I do think the SD card org. are sitting on a dirty little secret.... and the $11K membership fee is a crude ( and futile) attempt at keeping the secret under lock and key.
I hope I can nail down what is going one and then expose it all to the world...
Shame on the SD Org. for not making this public....
After all we are the customers trying to use this product, why does they think putting hurdles in our way will endear us to this SD card....
I'm also upset at the arrogance of Sandisk... perhaps I should buy some shares and then show up at one of the share holders meetings and voice my opinions to the board of dircetors and other share holders... I expect it will fall on deaf ears...
The only thing stopping me going CF is that horrible socket, it looks like a nightmare to solder. |
|
![](templates/subSilver/images/spacer.gif) |
Douglas Kennedy
Joined: 07 Sep 2003 Posts: 755 Location: Florida
|
FAT12 or FAT16 identification |
Posted: Thu Jul 22, 2004 11:32 am |
|
|
The identification of a FAT16 formatted card or FAT12 is a softee issue. I believe the format FAT12 or FAT16 is assumed by the softees based on the (count of clusters) logical capacity of the card not on the actual software format. If the cluster count is less than 4085 its FAT12,
4086 to 65525 FAT 16 So a small capacity card formated at FAT 16 ( Ex 16 mb) may be asssumed to require FAT12 format if the softee system sees it in a format drive scenario. A drive could be formatted as FAT16 but if the total clusters is less than 4085 the softees will assume FAT12. |
|
![](templates/subSilver/images/spacer.gif) |
Guest
|
Re: FAT12 or FAT16 identification |
Posted: Thu Jul 22, 2004 1:02 pm |
|
|
Douglas Kennedy wrote: | The identification of a FAT16 formatted card or FAT12 is a softee issue. I believe the format FAT12 or FAT16 is assumed by the softees based on the (count of clusters) logical capacity of the card not on the actual software format. If the cluster count is less than 4085 its FAT12,
4086 to 65525 FAT 16 So a small capacity card formated at FAT 16 ( Ex 16 mb) may be asssumed to require FAT12 format if the softee system sees it in a format drive scenario. A drive could be formatted as FAT16 but if the total clusters is less than 4085 the softees will assume FAT12. |
That's true. However with 1 sector per cluster , using the recommended (microsoft) code it gets indentified correctly as FAT16.
Because there are 28800 clusters * 1 sector per cluster (512) = 14,745,600 bytes.
In practice even a drive with 4085 or less could still have a FAT16 format, the code reading the boot sector would have to ignore the <4085 test. However that would violate the MS agreement,
Conclusion. FAT16 on 16MB card is valid.
The previous test I published today clearly demonstrate there are two bootsectors and FAT. I can zero a card and my bootsector remains intact.
One BS seems to be used by the SD card protocol the other is used by the MMC /SPI side of the card. |
|
![](templates/subSilver/images/spacer.gif) |
ckielstra
Joined: 18 Mar 2004 Posts: 3680 Location: The Netherlands
|
|
Posted: Thu Jul 22, 2004 3:18 pm |
|
|
Quote: | Yes I read that, however the statements much earlier in the doc. state that the SD card is MMC compatible.
When the card gets initialized ( CMD0 and CMD1 using SPI) it ends up as an MMC card and knows nothing about the SD features. |
Wait a moment, you are initializing the SD-card with CMD0 and CMD1? I didn't know this was possible! The normal sequence for an SD-card is to use CMD0-ACMD41, I checked it and only in SPI-mode the SD card supports CMD1. So this difference in startup commands is one more difference between your application and the USB-readers.
Then the issue with two bootsectors: I have only a limited set of documentation, but let's assume a certain version of the SD standard allows a card to both react on the MMC and SD card startup sequence. How to handle the situation where an SD card with secured data is inserted in a device with only MMC support? How can you allow the MMC device to write data while preventing the MMC device from destroying secured SD data? One possible (but clumsy) way to solve this would be to implement 2 FAT's. It's all guessing, but from your experiments it's clear there are two FAT's, one accessible from MMC-mode and the other from SD-mode. |
|
![](templates/subSilver/images/spacer.gif) |
Hans Wedemeyer
Joined: 15 Sep 2003 Posts: 226
|
MMC init. |
Posted: Thu Jul 22, 2004 4:13 pm |
|
|
ckielstra wrote: | Quote: | Yes I read that, however the statements much earlier in the doc. state that the SD card is MMC compatible.
When the card gets initialized ( CMD0 and CMD1 using SPI) it ends up as an MMC card and knows nothing about the SD features. |
Wait a moment, you are initializing the SD-card with CMD0 and CMD1? I didn't know this was possible! The normal sequence for an SD-card is to use CMD0-ACMD41, I checked it and only in SPI-mode the SD card supports CMD1. So this difference in startup commands is one more difference between your application and the USB-readers.
Then the issue with two bootsectors: I have only a limited set of documentation, but let's assume a certain version of the SD standard allows a card to both react on the MMC and SD card startup sequence. How to handle the situation where an SD card with secured data is inserted in a device with only MMC support? How can you allow the MMC device to write data while preventing the MMC device from destroying secured SD data? One possible (but clumsy) way to solve this would be to implement 2 FAT's. It's all guessing, but from your experiments it's clear there are two FAT's, one accessible from MMC-mode and the other from SD-mode. |
Best you read the data sheet in more depth. The SD card get initialized to MMC mode after CMD0 with CMD1 it's clearly stated in the documentation. Which is available somewhere on the web.... I found Rev. 1.7 on a Russian site.
NO there is no thin SD card. Where did you get that idea...? Please don't start rumors :-)
The SD card is thicker than the MMC so that is CANNOT be plugged into the MMC socket, however a MMC can be plugged into the SD card socket and will get initialized as MMC.
The SD card is MMC backward compatible, read the spec. it's all in there.
The Spec sheet talks about a secure area. Clearly this area is not available when the card is initialied as MMC, because MMC has zero security.
The data sheet tell's you a 16 meg card has about 14 million bytes avaiable, so "the rest" must be the secure area.
I have not tired to access the secure are4a, I don;t need it, and I'm also no sure if it is possible form the SPI interface, because not all CMD's and ACMD's are avaialble with through the SPI, again it's in the data sheet.
If you need more info about the FAT... you can download the entire Microsoft FAT spec. with code samples from the MS web site. It is free.
Here is the link...
http://www.microsoft.com/whdc/system/platform/firmware/fatgen.mspx |
|
![](templates/subSilver/images/spacer.gif) |
ckielstra
Joined: 18 Mar 2004 Posts: 3680 Location: The Netherlands
|
|
Posted: Thu Jul 22, 2004 4:56 pm |
|
|
Quote: | I the meatime I searched the web and found the (I thin is latest) data sheet V1.7 on a Russian site ! |
The SD manual V1.7 can still be found on the Sandisk site http://www.sandisk.com/download/Product%20Manuals/Product%20ManualSDCardv1.7.pdf
And a few months ago I downloaded V1.9 from the Sandisk site, but these links are now broken and you have to contact Support. According to the revision history the only changes from v1.7 to v1.9 are VDD read/write values. |
|
![](templates/subSilver/images/spacer.gif) |
Nick Guest
|
|
Posted: Thu Jul 22, 2004 5:00 pm |
|
|
if your looking for old files check the web archiver. The way back machine archives can help you get old files, I use that website so much, its almost abuse.
Nick |
|
![](templates/subSilver/images/spacer.gif) |
Jerry I
Joined: 14 Sep 2003 Posts: 96 Location: Toronto, Ontario, Canada
|
|
![](templates/subSilver/images/spacer.gif) |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|