0
\$\begingroup\$

I use Elm Chan's FAT32 library with custom initialisation code for SD managemnt with STM32. I have a bunch of 512Mb-2Gb SD cards that I wanna utilize in hardware. I noticed strange behavior with some of the cards.
According to Elm's code we should issue CMD8 command to check the card's type: 1.0/1.1 or 2.0+

512Mb cards give me

CMD0 OK
sdc_cmd: CMD8
Spi::assert
R: 0xFF
R: 0x5

Which is illegal command + idle - OK

1Gb/2Gb cards give me

CMD0 OK
sdc_cmd: CMD8
Spi::assert
get_response:
R: 0xFF
R: 0x1
CMD8 OK
SDHC detected
SD v2

after standart initiation I issue

sdc_cmd: CMD16
Spi::assert
get_response: expecting 0x1
R: 0xFF
R: 0x1
Block size was set to 512
SD init OK
Spi::highspeed
disk_read: Drive=0, sector=0,
Sdc::read_block, Address=0, BlockSize=1
sdc_cmd: CMD17
Spi::assert
get_response: expecting 0x0
R: 0xFF
R: 0x1

So it does not respond to CMD17 as I expected. In Windows all 2Gb cards works OK and detected as SD, not SDHC.

The question:

1) Why 2Gb card behaves like v2.0? 2) What to do in this case? Where I made mistake in the init process?

The code is here SDC_Error Sdc::initialize(void)

\$\endgroup\$
1
\$\begingroup\$

1) Why 2Gb card behaves like v2.0?

Almost all 2 GB cards are newer than the 2.0 SD card spec, and thus support the newer commands. But they still run in SD mode - the 32 bit address is measured in bytes and not in 512 byte blocks.

Only SDHC cards >= 4GB use 512 byte block addresses.

2) What to do in this case?

Set the block size to 512 bytes and use the card as any other SD card.

Where I made mistake in the init process?

You should use the elaborate SD card initialisation that is shipped with FATFS instead of trying to roll your own.

\$\endgroup\$
1
  • \$\begingroup\$ Thanks, I just tried to study the internal processes. If you want to know how something works - hack it :) \$\endgroup\$ – pugnator Feb 1 '17 at 8:26

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.