• AVR Freaks

C_SIZE on SD cards - problems...

Super Member
  • Total Posts : 769
  • Reward points : 0
  • Joined: 2006/12/03 10:20:52
  • Location: UK
  • Status: offline
2010/06/12 05:23:03 (permalink)

C_SIZE on SD cards - problems...

Excuse me for duplicating a post, but I posted on the wrong forum yesterday in error. Admins feel free to delete the other post at *this location*.

My problem is with C_SIZE and therefore determining an SD card's absolute size. I know this is the card size minus security protected areas, but I'm getting about 123 - 127MB for a 2GB card. Here's the original post:

Is my C_SIZE wrong? (0x3AE+1)

I'm asking here as I've searched through the posts pretty extensively and although found useful tips, nothing specific to this problem.

I bought a batch of 5 x 2GB Sandisk cards from aria.co.uk a while back and am writing a proprietary file system as it's commercial and I don't want FAT litigation + overheads etc. So, I've initialised the card, and get as far as reading the CSD and verifying CRC. Here it is:


CRC = 0x9FC5, checked + verified using separate program

So, I'm fairly happy the contents are valid. The problem lies in that if you match it up with the slices from the CSD register definitions, this is what I get:


This should give me the necessary info to calculate card size; Quoting from the physical layer specs:

This parameter is used to compute the user’s data card capacity (not include the security protected
area). The memory capacity of the card is computed from the entries C_SIZE, C_SIZE_MULT and
READ_BL_LEN as follows:

memory capacity = BLOCKNR * BLOCK_LEN





To indicate 2 GByte card, BLOCK_LEN shall be 1024 bytes.
Therefore, the maximal capacity that can be coded is 4096*512*1024 = 2 G bytes.

Example: A 32 Mbyte card with BLOCK_LEN = 512 can be coded by C_SIZE_MULT = 3 and C_SIZE =

So for me then:

943 * 128 = 120704. BLOCKNR = 120704.

BLOCK_LEN = 2^10 = 1024.

120704 * 1024 = 123600896.

123MB??? What's going on?

The card is a standard 2GB sandisk SD card, formatted FAT as read in WinXP, size 1.83GB under properties. I have two of the five I bought doing the same thing. (exact same C_SIZE)

If anyone has any ideas I'd be grateful - I wonder if they might be fakes? They both have the same identical serial number - I hope that's a batch number not a unique identifier...

I have just tried a 4GB card from my camera but it didn't get past the ACMD41 stage; Need further investigation there. I might see what other cards I can find just to check.

Also, I have checked other cards:

Reading C_SIZE from several other cards:

512MB uSD: 3C7 -> 64MB (512Byte Blk / 2^7 mult)
2GB uSD: 3CD -> 127MB (1024Byte Blk / 2^7 mult)
1GB uSD: 3CA -> 15MB (512Byte Blk / 2^5 mult)

mults have had 2 added to exponent i.e. they read 5, 5, 3 in above cards.

The CRCs from the cards check out fine too. What am I doing wrong? Can't be misaligned, surely, as the CRCs would fail; I can see the FF,FE before the CSD is TX'd, and it's FF's after the buffer - I captured 32bytes just to make sure.

Hmm... Have I missed something in the calculations?

I'll try reading from / writing to the last block of a 2GB size card, as it's byte addressed, so I can easily read the last 512bytes for instance, and see if I get an error.

Any help or suggestions would be great, thank you.

2 Replies Related Threads

    Super Member
    • Total Posts : 1714
    • Reward points : 0
    • Joined: 2004/11/16 02:02:02
    • Location: Surrey, UK
    • Status: offline
    RE: C_SIZE on SD cards - problems... 2010/06/13 03:53:47 (permalink)
    How do you extract C_SIZE from your CSD?

    You have 002600325F5A83AEFEFBCFFF928040DF
    With C_SIZE as bits 73:62 of that.

    Let's expand the sequence as binary

    0 0 2 6 0 0 3 2 5 f 5 A 8 3 A E F E F B ...
    0000 0000 0010 0110 0000 0000 0011 0010 0101 1111 0101 1010 1000 0011 1010 1110 1111 1110 1111 1011 ...
    ^^ ^^^^Reserved
    ^^^^ ^^^^TAAC
    ^^^^ ^^^^NSAC
    ^^^^ ^^^^TRAN_SPEED
    ^^^^ ^^^^ ^^^^CCC
    ^^ ^^^^ ^^^^ ^^C_SIZE

    So I make C_SIZE 111010111011 = 0xEBB, not the value you quote.

    I ought to say that I'm away from my main computer so I can't compare this with my SD code. But I think you are two bits out.

    Hope this helps,
    Super Member
    • Total Posts : 769
    • Reward points : 0
    • Joined: 2006/12/03 10:20:52
    • Location: UK
    • Status: offline
    RE: C_SIZE on SD cards - problems... 2010/06/13 09:52:37 (permalink)
    It does help, thanks Mr Danish Smile

    I'd written this out on paper, but only made the C_SIZE 10bits long by mistake, missing the last two off, so read it back from 64 instead of 62... Doh!

    Recalculating then:

    MULT = 2^7(2^9)
    READ_BL_LEN = 1024...

    EBCh * 512d = 1931264

    1931264 * 1024 = 1977614336

    Which sounds a lot more realistic. I take it that (2^31 - 1977614336 = 169869312) is the area at the beginning of the card I'm not supposed to write to? That was basically what I wanted to find out, but the physical layer specs only say "several AUs from the beginning of the card" and then make references to the "security protected area" so I was trying to find that from C_SIZE basically.

    Still - 197MB at the beginning of the card not allowed? Hmm... It is FAT formatted - would that make a difference?
    Jump to:
    © 2019 APG vNext Commercial Version 4.5