Reply by Sutton Mehaffey July 6, 20122012-07-06
Interesting. Because SanDisk, PNY and other big name cards always works
for me. The off brands seem to not cooperate sometimes.

Even though I'm not using your library, which command is causing the
CRC16 error? I vaguely remember a command where I physically had to
figure out the CRC (based on my parameters) in order for the command to
work properly.

Sutton Mehaffey
Lookout Portable Security
4040 Royal Dr.
Kennesaw, GA 30144
770-514-7999, 800-207-6269
Fax: 770-514-1285
http://www.lookoutportablesecurity.com
s...@lookoutportablesecurity.com
On 7/5/2012 2:09 PM, lawzaz wrote:
>
> I'm back with more progress and lessons learned, but no complete
> solution (yet).
>
> 1. SD card class has nothing to do with SPI data rates. My Class 2
> card is happy humming along at 10MHz, while my Class 6 card barfs at
> anything over 4.
>
> 2. This driver was obviously not tested with SDHC cards. While address
> /= 512, dataLen was not /= 512 and it should have been (in the case of
> SDHC cards).
>
> 3. With the clock set to 4MHz and these changes made, I spoke with my
> first SDHC card! But not all SDHC cards work. While AData and
> MicroCenter cards work fine, SanDisk returns CRC16 errors.
>
> 4. At this point, I'm stuck trying to figure out this pesky CRC16
> error. I believe the algorithm to be correct since the two other
> brands work; however, SanDisk CRC16's return invalid and ignoring the
> error results in a 'NO FILESYSTEM' error. It does seem strange that
> the test is:
>
> if (sd_crc16_data(data+(dataIndex-sd_block_len), sd_block_len) != crc16)
>
> because for SDHC cards, I would have thought that it should be
>
> if (sd_crc16_data(data+(dataIndex-1), sd_block_len) != crc16)
>
> but in this case, all SDHC cards fail.
>
> I'll keep trucking along -- but if anyone has ideas or thoughts about
> why CRC16 might work on some cards and fail with others, please let me
> know.
>
> If it helps, the cards that work are 4.02GB while the cards that fail
> are 3.97GB. It's possible that the cards that work are made by the
> same manufacturer and therefore share an error in CRC, but who knows..
> The card data indicate different manufacturers.
>
> --- In l... ,
> "mjames_doveridge" wrote:
> >
> > >
> > > Thanks again for the eyes and time. Hopefully someone else is
> learning along with me.
> > >
> >
> > Thanks very much - I am watching you thread with interest and, with
> a bit of luck, will help me fix my own SDHC problems, once I can get
> rid of the other nasty bugs in the rest of my app:(
> >
> > Again, many thanks for posting your problems and debugging results
> >
> > Rgds,
> > Martin
> >



An Engineer's Guide to the LPC2100 Series

Reply by mjames_doveridge July 5, 20122012-07-05
--- In l..., "lawzaz" wrote:
>
> I'm back with more progress and lessons learned, but no complete solution (yet).
>
> 1. SD card class has nothing to do with SPI data rates. My Class 2 card is happy humming along at 10MHz, while my Class 6 card barfs at anything over 4.
>

Hmm.. interesting. I have got my controller fired up just about as fast as it can go - the divider is set at 1 since it works with my old cards

I wil try setting my divider to 15 and see if I get any better responses from the big cards.

Rgds,
Martin

Reply by lawzaz July 5, 20122012-07-05
I'm back with more progress and lessons learned, but no complete solution (yet).

1. SD card class has nothing to do with SPI data rates. My Class 2 card is happy humming along at 10MHz, while my Class 6 card barfs at anything over 4.

2. This driver was obviously not tested with SDHC cards. While address /= 512, dataLen was not /= 512 and it should have been (in the case of SDHC cards).

3. With the clock set to 4MHz and these changes made, I spoke with my first SDHC card! But not all SDHC cards work. While AData and MicroCenter cards work fine, SanDisk returns CRC16 errors.

4. At this point, I'm stuck trying to figure out this pesky CRC16 error. I believe the algorithm to be correct since the two other brands work; however, SanDisk CRC16's return invalid and ignoring the error results in a 'NO FILESYSTEM' error. It does seem strange that the test is:

if (sd_crc16_data(data+(dataIndex-sd_block_len), sd_block_len) != crc16)

because for SDHC cards, I would have thought that it should be

if (sd_crc16_data(data+(dataIndex-1), sd_block_len) != crc16)

but in this case, all SDHC cards fail.

I'll keep trucking along -- but if anyone has ideas or thoughts about why CRC16 might work on some cards and fail with others, please let me know.

If it helps, the cards that work are 4.02GB while the cards that fail are 3.97GB. It's possible that the cards that work are made by the same manufacturer and therefore share an error in CRC, but who knows.. The card data indicate different manufacturers.

--- In l..., "mjames_doveridge" wrote:
>
> >
> > Thanks again for the eyes and time. Hopefully someone else is learning along with me.
> >
>
> Thanks very much - I am watching you thread with interest and, with a bit of luck, will help me fix my own SDHC problems, once I can get rid of the other nasty bugs in the rest of my app:(
>
> Again, many thanks for posting your problems and debugging results
>
> Rgds,
> Martin
>

Reply by mjames_doveridge July 3, 20122012-07-03
>
> Thanks again for the eyes and time. Hopefully someone else is learning along with me.
>

Thanks very much - I am watching you thread with interest and, with a bit of luck, will help me fix my own SDHC problems, once I can get rid of the other nasty bugs in the rest of my app:(

Again, many thanks for posting your problems and debugging results

Rgds,
Martin

Reply by Sutton Mehaffey July 2, 20122012-07-02
Here are my comments for card init. This is after CMD0 was successful.

// Determines whether card type is SD-Version 1, SD-Version 2 or HCSD card
// MMC card not supported, for now

// this uses the SD Spec, Version 2.00, Sept. 25, 2006, p. 95

// Initialization procedure (must be done after every RESET - CMD0)
// - issue CMD8 - check to see if card supports this command.
// - this command is only valid in SD Version 2 and HCSD cards.
// - save status of CMD8 for later - 0x05 is invalid command, 0x01 is
accepted.
// - Read_OCR - operating condition register - 4 bytes.
// - status should be 0x01, since card is not initialized yet.
// - check voltage level to be sure card can be used.
// - issue CMD55-ACMD41 combination and wait for status on ACMD41 to be
0x00.
// - status of 0x01 means initialization is not complete yet.
// - all ACMD commands MUST be preceeded by CMD55.
// - ACMD41 is the card initialization command.
// - after card init is OK (status = 0x01), Read_OCR a second time - 4
bytes.
// - the status should be 0x00, since card is initialized.
// - make sure the voltage is still OK.
// - check bit 30 of the OCR.
// - if '1', then HCSD card.
// - if '0' and CMD8 status accepted, then 'SD-Version 2'.
// - if '0' and CMD8 rejected, then 'SD-Version 1".

I use my own library for manipulating files after initialization, so I'm
not sure I'd be any help on the correct sequences for your library
functions. As, I don't have any knowledge on specifically what each of
those functions entails as far as command sequences. Is that driver
code something you wrote, or was it something that you found somewhere
and are editing? I wrote my own init functions and all my other
functions, so I knew exactly what was happening on the card.

Sutton

Sutton Mehaffey
Lookout Portable Security
4040 Royal Dr. #100
Kennesaw, GA 30144
800-207-6269, 770-514-7999, 770-514-1285 FAX
s...@lookoutportablesecurity.com
On 7/2/2012 10:19 PM, lawzaz wrote:
>
> Thank you for looking. I found a few parts of the program that I had
> to change and I'm further along, but still not quite there. To give my
> part back to the community, I'll post what I've changed and what I
> learned.
>
> Change 1:
> MSB/LSB error in the driver code. There is a line
> if (((response[3] & (1<<6)) != 0x00)
> that should be
> if (((response[1] & (1<<6)) != 0x00)
> Now, I can correctly identify SDSC or SDHC. Small victory.
>
> Change 2:
> When I mount the FS and open the directory, the FS mounts but
> f_opendir returns a DISK_ERR. If I repeat the process of doing f_mount
> and then f_opendir, both succeed the second time. I don't know why
> this works, but it does. Not all cards require this loop.
>
> Now, all SDSC cards <= 1GB work. I don't care about 2GB cards with
> their 1024 byte sectors, but SDHC still does not work. f_mount is
> successful, but f_opendir still fails. Specifically, CMD18 fails with
> a bad CRC16. If SDHC, I set address /= 512; . Do I need to do the same
> with dataLen?
>
> Thanks again for the eyes and time. Hopefully someone else is learning
> along with me.
> --- In l... ,
> Sutton Mehaffey wrote:
> >
> > I'm using a regular SD card, in SPI mode on a LPC2148 and can use any
> > card up to 8GB. I haven't tried anything higher, but I assume it would
> > work the same. Your sequence of commands is pretty much what I do.
> > What status are you getting when you issue a CMD8? What is your CMD8
> > command sequence? You state 'set voltage', but I think it's only a
> > command that helps determine whether VER1, VER2 or HC card. At least
> > that's what I have documented. It's been a few years since I messed
> > with it.
> >
> > Sutton
> >
> > Sutton Mehaffey
> > Lookout Portable Security
> > 4040 Royal Dr. #100
> > Kennesaw, GA 30144
> > 800-207-6269, 770-514-7999, 770-514-1285 FAX
> > sutton@...
> >
> >
> > On 7/2/2012 12:21 PM, lawzaz wrote:
> > >
> > > That may be the case. I am using SPI mode.
> > >
> > > My 2GB card has 1024 byte sectors, so I modified the MAX_SS in FatFS
> > > to 1024 and change block size command to no avail. It fails on 2GB
> > > SDSC cards as well as the HC cards. I'm really at a loss here, and
> > > unfortunately 1GB microSD cards are hard to find local.
> > >
> > > --- In l...
> ,
> > > "mjames_doveridge" wrote:
> > > >
> > > >
> > > >
> > > > --- In l...
> ,
> > > "stevec" wrote:
> > > > >
> > > > > I may be recalling incorrectly, but I vaguely remember that high
> > > capacity cards (SDHC) cannot use SPI mode, only the proprietary MMC
> > > nibble mode.
> > > > >
> > > >
> > > > I have my controller in 4-bit mode. It is, of course, quite
> possible
> > > that the OP and I have completely different bugs with the same
> symptoms :(
> > > >
> > > > Rgds,
> > > > Martin
> > > >
> > >
> > >
> >
> >
> >
> >


Reply by lawzaz July 2, 20122012-07-02
Thank you for looking. I found a few parts of the program that I had to change and I'm further along, but still not quite there. To give my part back to the community, I'll post what I've changed and what I learned.

Change 1:
MSB/LSB error in the driver code. There is a line
if (((response[3] & (1<<6)) != 0x00)
that should be
if (((response[1] & (1<<6)) != 0x00)
Now, I can correctly identify SDSC or SDHC. Small victory.

Change 2:
When I mount the FS and open the directory, the FS mounts but f_opendir returns a DISK_ERR. If I repeat the process of doing f_mount and then f_opendir, both succeed the second time. I don't know why this works, but it does. Not all cards require this loop.

Now, all SDSC cards <= 1GB work. I don't care about 2GB cards with their 1024 byte sectors, but SDHC still does not work. f_mount is successful, but f_opendir still fails. Specifically, CMD18 fails with a bad CRC16. If SDHC, I set address /= 512; . Do I need to do the same with dataLen?

Thanks again for the eyes and time. Hopefully someone else is learning along with me.

--- In l..., Sutton Mehaffey wrote:
>
> I'm using a regular SD card, in SPI mode on a LPC2148 and can use any
> card up to 8GB. I haven't tried anything higher, but I assume it would
> work the same. Your sequence of commands is pretty much what I do.
> What status are you getting when you issue a CMD8? What is your CMD8
> command sequence? You state 'set voltage', but I think it's only a
> command that helps determine whether VER1, VER2 or HC card. At least
> that's what I have documented. It's been a few years since I messed
> with it.
>
> Sutton
>
> Sutton Mehaffey
> Lookout Portable Security
> 4040 Royal Dr. #100
> Kennesaw, GA 30144
> 800-207-6269, 770-514-7999, 770-514-1285 FAX
> sutton@...
> On 7/2/2012 12:21 PM, lawzaz wrote:
> >
> > That may be the case. I am using SPI mode.
> >
> > My 2GB card has 1024 byte sectors, so I modified the MAX_SS in FatFS
> > to 1024 and change block size command to no avail. It fails on 2GB
> > SDSC cards as well as the HC cards. I'm really at a loss here, and
> > unfortunately 1GB microSD cards are hard to find local.
> >
> > --- In l... ,
> > "mjames_doveridge" wrote:
> > >
> > >
> > >
> > > --- In l... ,
> > "stevec" wrote:
> > > >
> > > > I may be recalling incorrectly, but I vaguely remember that high
> > capacity cards (SDHC) cannot use SPI mode, only the proprietary MMC
> > nibble mode.
> > > >
> > >
> > > I have my controller in 4-bit mode. It is, of course, quite possible
> > that the OP and I have completely different bugs with the same symptoms :(
> > >
> > > Rgds,
> > > Martin
> > >
> >
> >
>
>

Reply by Sutton Mehaffey July 2, 20122012-07-02
I'm using a regular SD card, in SPI mode on a LPC2148 and can use any
card up to 8GB. I haven't tried anything higher, but I assume it would
work the same. Your sequence of commands is pretty much what I do.
What status are you getting when you issue a CMD8? What is your CMD8
command sequence? You state 'set voltage', but I think it's only a
command that helps determine whether VER1, VER2 or HC card. At least
that's what I have documented. It's been a few years since I messed
with it.

Sutton

Sutton Mehaffey
Lookout Portable Security
4040 Royal Dr. #100
Kennesaw, GA 30144
800-207-6269, 770-514-7999, 770-514-1285 FAX
s...@lookoutportablesecurity.com
On 7/2/2012 12:21 PM, lawzaz wrote:
>
> That may be the case. I am using SPI mode.
>
> My 2GB card has 1024 byte sectors, so I modified the MAX_SS in FatFS
> to 1024 and change block size command to no avail. It fails on 2GB
> SDSC cards as well as the HC cards. I'm really at a loss here, and
> unfortunately 1GB microSD cards are hard to find local.
>
> --- In l... ,
> "mjames_doveridge" wrote:
> >
> >
> >
> > --- In l... ,
> "stevec" wrote:
> > >
> > > I may be recalling incorrectly, but I vaguely remember that high
> capacity cards (SDHC) cannot use SPI mode, only the proprietary MMC
> nibble mode.
> > >
> >
> > I have my controller in 4-bit mode. It is, of course, quite possible
> that the OP and I have completely different bugs with the same symptoms :(
> >
> > Rgds,
> > Martin
> >


Reply by lawzaz July 2, 20122012-07-02
That may be the case. I am using SPI mode.

My 2GB card has 1024 byte sectors, so I modified the MAX_SS in FatFS to 1024 and change block size command to no avail. It fails on 2GB SDSC cards as well as the HC cards. I'm really at a loss here, and unfortunately 1GB microSD cards are hard to find local.

--- In l..., "mjames_doveridge" wrote:
>
> --- In l..., "stevec" wrote:
> >
> > I may be recalling incorrectly, but I vaguely remember that high capacity cards (SDHC) cannot use SPI mode, only the proprietary MMC nibble mode.
> > I have my controller in 4-bit mode. It is, of course, quite possible that the OP and I have completely different bugs with the same symptoms :(
>
> Rgds,
> Martin
>

Reply by mjames_doveridge July 2, 20122012-07-02
--- In l..., "stevec" wrote:
>
> I may be recalling incorrectly, but I vaguely remember that high capacity cards (SDHC) cannot use SPI mode, only the proprietary MMC nibble mode.
>

I have my controller in 4-bit mode. It is, of course, quite possible that the OP and I have completely different bugs with the same symptoms :(

Rgds,
Martin

Reply by cfbsoftware1 July 1, 20122012-07-01
--- In l..., "lawzaz" wrote:
> Does anyone have experience they can share re: SDSC/SDHC over SPI? I'm using SanDisk cards, so they should be compliant with the spec...
>

There was a discussion titled "SD snd SDHC card differences" in the comp.arch.embedded Usenet newsgroup a couple of years ago. If you do not have Usenet access you can view it here:

http://compgroups.net/comp.arch.embedded/sd-snd-sdhc-card-differences/198869

Regards,
Chris Burrows
Astrobe v4.2: Oberon for Cortex-M3 Development System
http://www.astrobe.com