SDHC capacity read bug?

Go To Last Post
2 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I have problem with AVR32 UC3B SDHC read capacity.

function sd_mmc_spi_get_capacity

 

Atmel studio 7. sd_mmc_spi.c

 

  if (card_type == SD_CARD_2_SDHC) // SDHC Card

  {
    c_size = ((csd[7] & 0x3F) << 16) | (csd[8] << 8) | csd[9];
    ++c_size;
    capacity = (uint64_t)c_size << 19;
    capacity_mult = (c_size >> 13) & 0x01FF;
    sd_mmc_spi_last_block_address = (capacity >> 9) + (capacity_mult << 23) - 1;
  } else ......

 

 

I have ADATA 8GB SDHC Class 4 card.

CSD hex is : 400e00325b5900003add7f800a4000a9

 

So Device size(c_size)  is 0x003add [Decimal: 15069]

 

calculated value of capacity is 15069 << 19 = 7900495872

capacity_mult  is 15069 >> 13 = 1

sd_mmc_spi_last_block_address is  15.430.656 + 8.388.608 - 1

result is 12+ GB (with 8GB SDHC card)

 

I think there is problem with  (capacity_mult << 23)

 

Wikipedia says:

SD card Versions 2 and 3:

Capacity is calculated thus:

Capacity=(C_SIZE+1) × 524288

 

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Have you tried reformatting the SD card?  When I was playing around with the RasPi last year, I learned that improper formatting techniques could alter the usable capacity of SC cards.

 

Try formatting with the SD Card Association formatter

 

 

 

edit: typo

Greg Muth

Portland, OR, US

Atmel Studio 7 (Version: 7.0.1652) on Windows 10

Xplained/Pro/Mini Boards mostly