Reply by Miguel Angel July 8, 20092009-07-08
http://www.siwawi.arubi.uni-kl.de/avr_projects/arm_projects/arm_memcards/lpc213x_chanfat_mthomas_20090528.zip

This is a code from Marthin Thomas to interface Chan's FFs to SDHC,
I've tested it, and it works correctly :)

2009/7/8 drproton2003 :
> I've attempted to fix the non-fifo code. I made the fix to the readsector
> function and the card now initializes correctly. However I found a problem
> in the write function as well
>
> static euint8 xmit_datablock (
> hwInterface *iface,
> const euint8 *buff, /* 512 byte data block to be transmitted */
> euint8 token /* Data/Stop token */
> )
> {
> euint8 resp;
> euint16 wc;
>
> if ( wait_ready( iface ) != 0xFF ) {
> return 0;
> }
>
> if_spiSend( iface, token ); /* Xmit data token */
> if ( token != 0xFD ) { /* Is data token */
> wc = 0;
> do { /* Xmit the 512 byte data block to MMC */
> if_spiSend( iface, *buff++);
> wc++;
> } while (wc<512);
>
> if_spiSend( iface, 0xff); /* CRC (Dummy) */
> if_spiSend( iface, 0xff); /* CRC (Dummy) */
> resp = if_spiSend( iface, 0xff); /* Reveive data response */
> if ( (resp & 0x1F) != 0x05 ) /* If not accepted, return with error */
> return 0;
> }
>
> return 1;
> }
>
> I had to add the wc++ line, otherwise bad things would happen. With this in
> place the log files seem to open/write/close okay. However when I plug the
> card into my PC the file appears, but I cannot open it. It shows a legit
> size and I used a hex editor to verify that the contents appear correct.
> What else might be going on?
>
> --- In l..., "Michael Anton" wrote:
>>
>> > -----Original Message-----
>> > From: l...
>> > [mailto:l...]On Behalf
>> > Of drproton2003
>> > Sent: Tuesday, July 07, 2009 11:35 PM
>> > To: l...
>> > Subject: [lpc2000] Re: EFSL and SDHC
>> >
>> >
>> > Well, I found the problem. It looks as though SDHC is only
>> > supported on the MCI, not the SPI. I simply did a search for
>> > SDHC in all the files. The only hit, other than the
>> > initialization routine was in lpc2000_mci.c. From there the
>> > only difference I could see is that when reading/writing a
>> > sector the address is multiplied by 512 for standard cards
>> > and not for SDHC.
>>
>> Not finding SDHC in comments does not mean much. Most of the
>> SDHC support is handled in SD.c, and these routines are usually
>> used by all hardware drivers.
>>
>> The reason that SDHC support didn't work in FIFO mode, is that
>> the main reading functions are not called in that interface,
>> as it requires something very different. Especially if any
>> form of performance is required.
>>
>> Please take a look at some of my comments on the EFSL Sourceforge
>> forums as well, as there are a number of other shortcomings in
>> the library that I found some useful workarounds for. Specifically,
>> watch out for cache performance issues when writing a lot without
>> closing files.
>> >
>> > I did a quick bandaid test. I externed CardType from sd.c to
>> > lpc2000_sd.c. In the if_readBuf I added the following,
>> > likewise in if_writeBuf.
>> >
>> > if(CardType==1||CardType==2||CardType==4)
>> > if_Command(CMDREAD, 512 * address);
>> > if(CardType=)
>> > if_Command(CMDREAD, address);
>> >
>> > With this mod it works with the fifo for both SD and SDHC
>> > cards. By this I mean that I have successfully made files on
>> > both cards, but have no measures of reliability or stability.
>>
>> That is good news. I thought it should not be too difficult. You may
>> want to change it to:
>>
>> if ( !(CardType & 8) )
>> if_Command(CMDREAD, 512 * address);
>> else
>> if_Command(CMDREAD, address);
>>
>> to simplify it slightly.
>>
>> Prior versions were quite reliable after I applied a bunch of patches,
>> and fixed some other bugs that I found through my testing. These
>> MT versions are supposed to have all of those applied. Alas, many
>> new features have been added as well, and as you have found there
>> are obviously a number of bugs remaining.
>>
>> >
>> > As to the problems with the non-fifo routines. Here is the
>> > function that clocks in the sector:
>> >
>> > static euint8 rcvr_datablock (
>> > hwInterface *iface,
>> > euint8 *buff, /* Data buffer to store received data */
>> > euint16 btr /* Byte count (must be even number) */
>> > )
>> > {
>> > euint8 token;
>> > euint16 retry;
>> >
>> > retry = LOOP_CNT_100;
>> > /* should retry 100ms */
>> > do {
>> > token = if_spiSend( iface, 0xff );
>> > retry--;
>> > } while ((token == 0xFF) && retry);
>> >
>> > if(token != 0xFE) {
>> > return 0; /* If not valid data token,
>> > retutn with error */
>> > }
>> >
>> > do { /* Receive the data
>> > block into buffer */
>> > if_spiSend( iface, *buff++ );
>> > if_spiSend( iface, *buff++ );
>> > } while (btr -= 2);
>> > if_spiSend( iface, 0xff); /* Discard CRC */
>> > if_spiSend( iface, 0xff); /* Discard CRC */
>> >
>> > return 1; /* Return with success */
>> > }
>> >
>> > and it calls:
>> >
>> > euint8 if_spiSend(hwInterface *iface, euint8 outgoing)
>> > {
>> > euint8 incoming;
>> >
>> > #if ( HW_ENDPOINT_LPC2000_SPINUM == 0 )
>> > S0SPDR = outgoing;
>> > while( !(S0SPSR & (1< >> > incoming = S0SPDR;
>> > #endif
>> >
>> > #if ( HW_ENDPOINT_LPC2000_SPINUM == 1 )
>> > while( !(SPI_STATUS_REG & (1< >> > SSPDR = outgoing;
>> > while( !(SPI_STATUS_REG & (1< >> > incoming = SSPDR;
>> > #endif
>> >
>> > return(incoming);
>> > }
>> >
>> > Seems to me like if_spiSend( iface, *buff++ ); should be
>> > something like *buff++=if_spiSend( iface, 0xFF);
>>
>> What you propose looks correct when comparing to prior versions.
>> I don't know how MT would have missed this.
>>
>> Mike
>>

--
Miguel Angel Ajo Pelayo
http://www.nbee.es
+34 91 120 1798
+34 636 52 25 69
skype: ajoajoajo

An Engineer's Guide to the LPC2100 Series

Reply by drproton2003 July 8, 20092009-07-08
I've attempted to fix the non-fifo code. I made the fix to the readsector function and the card now initializes correctly. However I found a problem in the write function as well

static euint8 xmit_datablock (
hwInterface *iface,
const euint8 *buff, /* 512 byte data block to be transmitted */
euint8 token /* Data/Stop token */
)
{
euint8 resp;
euint16 wc;

if ( wait_ready( iface ) != 0xFF ) {
return 0;
}

if_spiSend( iface, token ); /* Xmit data token */
if ( token != 0xFD ) { /* Is data token */
wc = 0;
do { /* Xmit the 512 byte data block to MMC */
if_spiSend( iface, *buff++);
wc++;
} while (wc<512);

if_spiSend( iface, 0xff); /* CRC (Dummy) */
if_spiSend( iface, 0xff); /* CRC (Dummy) */
resp = if_spiSend( iface, 0xff); /* Reveive data response */
if ( (resp & 0x1F) != 0x05 ) /* If not accepted, return with error */
return 0;
}

return 1;
}

I had to add the wc++ line, otherwise bad things would happen. With this in place the log files seem to open/write/close okay. However when I plug the card into my PC the file appears, but I cannot open it. It shows a legit size and I used a hex editor to verify that the contents appear correct. What else might be going on?

--- In l..., "Michael Anton" wrote:
>
> > -----Original Message-----
> > From: l...
> > [mailto:l...]On Behalf
> > Of drproton2003
> > Sent: Tuesday, July 07, 2009 11:35 PM
> > To: l...
> > Subject: [lpc2000] Re: EFSL and SDHC
> >
> >
> > Well, I found the problem. It looks as though SDHC is only
> > supported on the MCI, not the SPI. I simply did a search for
> > SDHC in all the files. The only hit, other than the
> > initialization routine was in lpc2000_mci.c. From there the
> > only difference I could see is that when reading/writing a
> > sector the address is multiplied by 512 for standard cards
> > and not for SDHC.
>
> Not finding SDHC in comments does not mean much. Most of the
> SDHC support is handled in SD.c, and these routines are usually
> used by all hardware drivers.
>
> The reason that SDHC support didn't work in FIFO mode, is that
> the main reading functions are not called in that interface,
> as it requires something very different. Especially if any
> form of performance is required.
>
> Please take a look at some of my comments on the EFSL Sourceforge
> forums as well, as there are a number of other shortcomings in
> the library that I found some useful workarounds for. Specifically,
> watch out for cache performance issues when writing a lot without
> closing files.
>
>
> >
> > I did a quick bandaid test. I externed CardType from sd.c to
> > lpc2000_sd.c. In the if_readBuf I added the following,
> > likewise in if_writeBuf.
> >
> > if(CardType==1||CardType==2||CardType==4)
> > if_Command(CMDREAD, 512 * address);
> > if(CardType=)
> > if_Command(CMDREAD, address);
> >
> > With this mod it works with the fifo for both SD and SDHC
> > cards. By this I mean that I have successfully made files on
> > both cards, but have no measures of reliability or stability.
>
> That is good news. I thought it should not be too difficult. You may
> want to change it to:
>
> if ( !(CardType & 8) )
> if_Command(CMDREAD, 512 * address);
> else
> if_Command(CMDREAD, address);
>
> to simplify it slightly.
>
> Prior versions were quite reliable after I applied a bunch of patches,
> and fixed some other bugs that I found through my testing. These
> MT versions are supposed to have all of those applied. Alas, many
> new features have been added as well, and as you have found there
> are obviously a number of bugs remaining.
>
> >
> > As to the problems with the non-fifo routines. Here is the
> > function that clocks in the sector:
> >
> > static euint8 rcvr_datablock (
> > hwInterface *iface,
> > euint8 *buff, /* Data buffer to store received data */
> > euint16 btr /* Byte count (must be even number) */
> > )
> > {
> > euint8 token;
> > euint16 retry;
> >
> > retry = LOOP_CNT_100;
> > /* should retry 100ms */
> > do {
> > token = if_spiSend( iface, 0xff );
> > retry--;
> > } while ((token == 0xFF) && retry);
> >
> > if(token != 0xFE) {
> > return 0; /* If not valid data token,
> > retutn with error */
> > }
> >
> > do { /* Receive the data
> > block into buffer */
> > if_spiSend( iface, *buff++ );
> > if_spiSend( iface, *buff++ );
> > } while (btr -= 2);
> > if_spiSend( iface, 0xff); /* Discard CRC */
> > if_spiSend( iface, 0xff); /* Discard CRC */
> >
> > return 1; /* Return with success */
> > }
> >
> > and it calls:
> >
> > euint8 if_spiSend(hwInterface *iface, euint8 outgoing)
> > {
> > euint8 incoming;
> >
> > #if ( HW_ENDPOINT_LPC2000_SPINUM == 0 )
> > S0SPDR = outgoing;
> > while( !(S0SPSR & (1< > > incoming = S0SPDR;
> > #endif
> >
> > #if ( HW_ENDPOINT_LPC2000_SPINUM == 1 )
> > while( !(SPI_STATUS_REG & (1< > > SSPDR = outgoing;
> > while( !(SPI_STATUS_REG & (1< > > incoming = SSPDR;
> > #endif
> >
> > return(incoming);
> > }
> >
> > Seems to me like if_spiSend( iface, *buff++ ); should be
> > something like *buff++=if_spiSend( iface, 0xFF);
>
> What you propose looks correct when comparing to prior versions.
> I don't know how MT would have missed this.
>
> Mike
>

Reply by Michael Anton July 8, 20092009-07-08
> -----Original Message-----
> From: l...
> [mailto:l...]On Behalf
> Of drproton2003
> Sent: Tuesday, July 07, 2009 11:35 PM
> To: l...
> Subject: [lpc2000] Re: EFSL and SDHC
> Well, I found the problem. It looks as though SDHC is only
> supported on the MCI, not the SPI. I simply did a search for
> SDHC in all the files. The only hit, other than the
> initialization routine was in lpc2000_mci.c. From there the
> only difference I could see is that when reading/writing a
> sector the address is multiplied by 512 for standard cards
> and not for SDHC.

Not finding SDHC in comments does not mean much. Most of the
SDHC support is handled in SD.c, and these routines are usually
used by all hardware drivers.

The reason that SDHC support didn't work in FIFO mode, is that
the main reading functions are not called in that interface,
as it requires something very different. Especially if any
form of performance is required.

Please take a look at some of my comments on the EFSL Sourceforge
forums as well, as there are a number of other shortcomings in
the library that I found some useful workarounds for. Specifically,
watch out for cache performance issues when writing a lot without
closing files.

>
> I did a quick bandaid test. I externed CardType from sd.c to
> lpc2000_sd.c. In the if_readBuf I added the following,
> likewise in if_writeBuf.
>
> if(CardType==1||CardType==2||CardType==4)
> if_Command(CMDREAD, 512 * address);
> if(CardType=)
> if_Command(CMDREAD, address);
>
> With this mod it works with the fifo for both SD and SDHC
> cards. By this I mean that I have successfully made files on
> both cards, but have no measures of reliability or stability.

That is good news. I thought it should not be too difficult. You may
want to change it to:

if ( !(CardType & 8) )
if_Command(CMDREAD, 512 * address);
else
if_Command(CMDREAD, address);

to simplify it slightly.

Prior versions were quite reliable after I applied a bunch of patches,
and fixed some other bugs that I found through my testing. These
MT versions are supposed to have all of those applied. Alas, many
new features have been added as well, and as you have found there
are obviously a number of bugs remaining.

>
> As to the problems with the non-fifo routines. Here is the
> function that clocks in the sector:
>
> static euint8 rcvr_datablock (
> hwInterface *iface,
> euint8 *buff, /* Data buffer to store received data */
> euint16 btr /* Byte count (must be even number) */
> )
> {
> euint8 token;
> euint16 retry;
>
> retry = LOOP_CNT_100;
> /* should retry 100ms */
> do {
> token = if_spiSend( iface, 0xff );
> retry--;
> } while ((token == 0xFF) && retry);
>
> if(token != 0xFE) {
> return 0; /* If not valid data token,
> retutn with error */
> }
>
> do { /* Receive the data
> block into buffer */
> if_spiSend( iface, *buff++ );
> if_spiSend( iface, *buff++ );
> } while (btr -= 2);
> if_spiSend( iface, 0xff); /* Discard CRC */
> if_spiSend( iface, 0xff); /* Discard CRC */
>
> return 1; /* Return with success */
> }
>
> and it calls:
>
> euint8 if_spiSend(hwInterface *iface, euint8 outgoing)
> {
> euint8 incoming;
>
> #if ( HW_ENDPOINT_LPC2000_SPINUM == 0 )
> S0SPDR = outgoing;
> while( !(S0SPSR & (1< > incoming = S0SPDR;
> #endif
>
> #if ( HW_ENDPOINT_LPC2000_SPINUM == 1 )
> while( !(SPI_STATUS_REG & (1< > SSPDR = outgoing;
> while( !(SPI_STATUS_REG & (1< > incoming = SSPDR;
> #endif
>
> return(incoming);
> }
>
> Seems to me like if_spiSend( iface, *buff++ ); should be
> something like *buff++=if_spiSend( iface, 0xFF);

What you propose looks correct when comparing to prior versions.
I don't know how MT would have missed this.

Mike

Reply by drproton2003 July 8, 20092009-07-08
Well, I found the problem. It looks as though SDHC is only supported on the MCI, not the SPI. I simply did a search for SDHC in all the files. The only hit, other than the initialization routine was in lpc2000_mci.c. From there the only difference I could see is that when reading/writing a sector the address is multiplied by 512 for standard cards and not for SDHC.

I did a quick bandaid test. I externed CardType from sd.c to lpc2000_sd.c. In the if_readBuf I added the following, likewise in if_writeBuf.

if(CardType==1||CardType==2||CardType==4)
if_Command(CMDREAD, 512 * address);
if(CardType=)
if_Command(CMDREAD, address);

With this mod it works with the fifo for both SD and SDHC cards. By this I mean that I have successfully made files on both cards, but have no measures of reliability or stability.

As to the problems with the non-fifo routines. Here is the function that clocks in the sector:

static euint8 rcvr_datablock (
hwInterface *iface,
euint8 *buff, /* Data buffer to store received data */
euint16 btr /* Byte count (must be even number) */
)
{
euint8 token;
euint16 retry;

retry = LOOP_CNT_100;
/* should retry 100ms */
do {
token = if_spiSend( iface, 0xff );
retry--;
} while ((token == 0xFF) && retry);

if(token != 0xFE) {
return 0; /* If not valid data token, retutn with error */
}

do { /* Receive the data block into buffer */
if_spiSend( iface, *buff++ );
if_spiSend( iface, *buff++ );
} while (btr -= 2);
if_spiSend( iface, 0xff); /* Discard CRC */
if_spiSend( iface, 0xff); /* Discard CRC */

return 1; /* Return with success */
}

and it calls:

euint8 if_spiSend(hwInterface *iface, euint8 outgoing)
{
euint8 incoming;

#if ( HW_ENDPOINT_LPC2000_SPINUM == 0 )
S0SPDR = outgoing;
while( !(S0SPSR & (1< incoming = S0SPDR;
#endif

#if ( HW_ENDPOINT_LPC2000_SPINUM == 1 )
while( !(SPI_STATUS_REG & (1< SSPDR = outgoing;
while( !(SPI_STATUS_REG & (1< incoming = SSPDR;
#endif

return(incoming);
}

Seems to me like if_spiSend( iface, *buff++ ); should be something like *buff++=if_spiSend( iface, 0xFF);

--- In l..., "Michael Anton" wrote:
>
> > -----Original Message-----
> > From: l...
> > [mailto:l...]On Behalf
> > Of drproton2003
> > Sent: Tuesday, July 07, 2009 10:28 PM
> > To: l...
> > Subject: [lpc2000] Re: EFSL and SDHC
> >
> >
> > Mike,
> >
> > Thanks for the info. Originally I had not intended on using
> > the FIFO code. However I found that the non-fifo functions
> > did not work even for the standard SD cards. On the webpage
> > it says "Does not work in simple SPI mode".
>
> This comment appears to relate to the AVR. There are no significant
> differences in lpc2000_sd.c between version 0.2.9RC4 and 0.2.9RC7.
> Certainly I don't see anything that would break either mode of
> operation. I would expect that even the FIFO enabled code would
> work ok for non-SDHC cards, but, I haven't tried it.
>
> >
> > Do you have a non-fifo version that works with SDHC?
> > I suspect it works, but you will need to try it.
>
> I have not attempted to get it to work with SDHC, but I have been
> meaning to. Eventually I will get at it, and make the SSP FIFO
> code work properly, but no doubt that will be much later than you
> would like.
>
> Do you absolutely need SDHC support. If not, I would suggest trying
> one of the earlier releases from that site, as at least I know
> they work (at least RC4 does).
>
> If you continue to have difficulties, let me know. I may try
> to find some time to look into this further.
>
> One question: how do you have all of this wired up?
>
> Mike
>

Reply by Michael Anton July 8, 20092009-07-08
> -----Original Message-----
> From: l...
> [mailto:l...]On Behalf
> Of drproton2003
> Sent: Tuesday, July 07, 2009 10:28 PM
> To: l...
> Subject: [lpc2000] Re: EFSL and SDHC
> Mike,
>
> Thanks for the info. Originally I had not intended on using
> the FIFO code. However I found that the non-fifo functions
> did not work even for the standard SD cards. On the webpage
> it says "Does not work in simple SPI mode".

This comment appears to relate to the AVR. There are no significant
differences in lpc2000_sd.c between version 0.2.9RC4 and 0.2.9RC7.
Certainly I don't see anything that would break either mode of
operation. I would expect that even the FIFO enabled code would
work ok for non-SDHC cards, but, I haven't tried it.

>
> Do you have a non-fifo version that works with SDHC?
>

I suspect it works, but you will need to try it.

I have not attempted to get it to work with SDHC, but I have been
meaning to. Eventually I will get at it, and make the SSP FIFO
code work properly, but no doubt that will be much later than you
would like.

Do you absolutely need SDHC support. If not, I would suggest trying
one of the earlier releases from that site, as at least I know
they work (at least RC4 does).

If you continue to have difficulties, let me know. I may try
to find some time to look into this further.

One question: how do you have all of this wired up?

Mike
Reply by drproton2003 July 8, 20092009-07-08
Mike,

Thanks for the info. Originally I had not intended on using the FIFO code. However I found that the non-fifo functions did not work even for the standard SD cards. On the webpage it says "Does not work in simple SPI mode".

Do you have a non-fifo version that works with SDHC?

--- In l..., "Michael Anton" wrote:
>
> I am the author of the EFSL SSP FIFO support code, and
> Martin Thomas kindly added this into the build he has on his site.
>
> Currently, the SSP FIFO code does not support SDHC cards. It would
> appear that Martin added support for SDHC after I originated
> the FIFO support, and did not update my code to support SDHC as
> well. I have had this on my todo list for sometime, but I have
> not had a chance to get started on it.
>
> If you turn off the SSP FIFO support, it may work ok.
>
> If you want to fix the FIFO code, it looks like a few simple patches
> to if_command(), if_readBuf() and if_writeBuf() would be required.
> Mostly what is needed is to use a block address rather than a byte
> address for SDHC cards. Look at the corresponding non-FIFO routines
> to see how this is handled.
>
> The FIFO code has been carefully optimized for speed, which is one
> of the reasons that it is so different than the non-FIFO code. As a
> result of this, it can be a bit more problematic to modify, and
> understand.
>
> Good luck,
>
> Mike Anton
>
>
>
> > -----Original Message-----
> > From: l...
> > [mailto:l...]On Behalf
> > Of drproton2003
> > Sent: Tuesday, July 07, 2009 8:24 PM
> > To: l...
> > Subject: [lpc2000] Re: EFSL and SDHC
> >
> >
> > The code I am using (EFSL) does just this. It it just hidden
> > in another function that I did not paste in. In any case the
> > initialization part seems to be working now, but the file
> > system part is not.
> >
> > --- In l..., Sutton Mehaffey wrote:
> > >
> > > I assume you are using CMD55 before ACMD41 and getting a
> > status of 1
> > > before issuing ACMD41. I don't see that in your code. The
> > sequence
> > > needs to be:
> > >
> > > CMD8
> > > CMD55
> > > ACMD41
> > >
> > > Sutton
> > >
> > >
> > >
> > > drproton2003 wrote:
> > > >
> > > >
> > > > I don't seem to be having this problem any more. The only
> > thing I can
> > > > point to is that it didn't like me having a breakpoint in
> > that block
> > > > of code.
> > > >
> > > > That being said, it still doesn't work. efs_init now returns -2
> > > > (failed to initialize file system). One problem is that
> > when I try to
> > > > view the results of a sector read from the debugger it is
> > different
> > > > than what the hex editor on my computer says. The really
> > weird part is
> > > > that this occurs for both the 1GB card that works fine
> > and the 4GB
> > > > SDHC card that doesn't.
> > > >
> > > > I've spent all day working on this now so I think it is
> > time for a break.
> > > >
> > > > --- In l...
> > ,
> > > > Sutton Mehaffey wrote:
> > > > >
> > > > > Are you preceding ACMD41 with a CMD55?
> > > > >
> > > > >
> > > > >
> > > > > drproton2003 wrote:
> > > > > >
> > > > > >
> > > > > > I've got one step further with this. Turns out the sd_Command
> > > > function
> > > > > > was using the wrong CRC for CMD8. The CRC was
> > orignally set to 0x97
> > > > > > and it should be 0x87.
> > > > > >
> > > > > > Now the initialization gets stuck in the next few
> > lines. ACMD41
> > > > always
> > > > > > seems to return 1, so I get stuck in the do loop.
> > > > > >
> > > > > > if ( ocr[2] == 0x01 && ocr[3] == 0xAA ) {
> > > > > > retry = LOOP_CNT_1000; /* should retry 1000ms */
> > > > > > do {
> > > > > > //Wait for leaving idle state (ACMD41 with HCS bit)
> > > > > > resp = sd_Command( iface, ACMD41,((1UL << 30)>>16), 0 );
> > > > > > retry--;
> > > > > > } while ( retry && (resp != 0) );
> > > > > >
> > > > > > if ( retry && sd_Command( iface, CMD58, 0, 0 ) == 0) {
> > > > > > /* Check CCS bit in the OCR */
> > > > > > for ( n = 0; n < 4; n++ ) {
> > > > > > ocr[n] = if_spiSend( iface, 0xff );
> > > > > > }
> > > > > > ty = (ocr[0] & 0x40) ? 12 : 4;
> > > > > > if ( ty == 12 ) DBG((TXT("SDHC HighCap\n")));
> > > > > > if ( ty == 4 ) DBG((TXT("SDHC\n")));
> > > > > > }
> > > > > >
> > > > > > Seeing as how the CRC was wrong it makes me think
> > that this code has
> > > > > > never been tested with SDHC.
> > > > > >
> > > > > > --- In l...
> >
> > > > ,
> > > > > > "drproton2003" wrote:
> > > > > > >
> > > > > > > Hello everyone,
> > > > > > >
> > > > > > > I am attempting to get EFSL to work with SDHC cards. I have
> > > > > > downloaded version 0.2.9 RC7 from this page
> > > > > > >
> > > > > > >
> > > > > >
> > > >
> > http://www.siwawi.arubi.uni-kl.de/avr_projects/arm_projects/ar
> > m_memcards/
> > > >
> > > > rm_memcards/>
> > > >
> > > > > >
> > > >
> > > > rm_memcards/
> > > >
> > > > rm_memcards/>>
> > > > > > >
> > > > > > > After realizing that I needed to use the SSP FIFO
> > mode I had it
> > > > > > working with a 1GB SD card.
> > > > > > >
> > > > > > > Now that I am using a SDHC card I am having some
> > problems. The
> > > > > > problems start in the sd_Init function. Namely, this
> > block of code
> > > > here:
> > > > > > >
> > > > > > > if ( sd_Command( iface, CMD8, 0, 0x01AA) == 1 ) {
> > > > > > > /* SDHC */
> > > > > > > for ( n=0; n<4; n++ ) {
> > > > > > > ocr[n] = if_spiSend( iface, 0xff );
> > > > > > > }
> > > > > > > if ( ocr[2] == 0x01 && ocr[3] == 0xAA )
> > > > > > >
> > > > > > > The card I am using responds to CMD8 with a value
> > of 9, so it fails
> > > > > > this check and goes to the SDSC case. As I understand
> > it if CMD8
> > > > > > responds the card is SDHC, does the response need to
> > be 1? If I
> > > > remove
> > > > > > the == 1 from the first if, ocr[] is filled in with
> > 0xFF, so the next
> > > > > > test fails.
> > > > > > >
> > > > > > > Has anyone used EFSL with SDHC cards? What might be
> > the cause of my
> > > > > > problems? Also where can I find documentation on
> > interfacing with
> > > > SDHC
> > > > > > cards? I've found a lot of docs for standard SD, but
> > not too much for
> > > > > > SDHC.
> > > > > > >
> > > > > >
> > > > > >
> > > > >
> > > > > --
> > > > > Sutton Mehaffey
> > > > > Lookout Portable Security
> > > > > 4040 Royal Dr. #100
> > > > > Kennesaw, GA 30144
> > > > > 800-207-6269, 770-514-7999, 770-514-1285 FAX
> > > > > sutton@
> > > > >
> > > >
> > > >
> > >
> > > --
> > > Sutton Mehaffey
> > > Lookout Portable Security
> > > 4040 Royal Dr. #100
> > > Kennesaw, GA 30144
> > > 800-207-6269, 770-514-7999, 770-514-1285 FAX
> > > sutton@
> > >
> >
> >
> >
> >
> >
> >
> >
Reply by Michael Anton July 8, 20092009-07-08
I am the author of the EFSL SSP FIFO support code, and
Martin Thomas kindly added this into the build he has on his site.

Currently, the SSP FIFO code does not support SDHC cards. It would
appear that Martin added support for SDHC after I originated
the FIFO support, and did not update my code to support SDHC as
well. I have had this on my todo list for sometime, but I have
not had a chance to get started on it.

If you turn off the SSP FIFO support, it may work ok.

If you want to fix the FIFO code, it looks like a few simple patches
to if_command(), if_readBuf() and if_writeBuf() would be required.
Mostly what is needed is to use a block address rather than a byte
address for SDHC cards. Look at the corresponding non-FIFO routines
to see how this is handled.

The FIFO code has been carefully optimized for speed, which is one
of the reasons that it is so different than the non-FIFO code. As a
result of this, it can be a bit more problematic to modify, and
understand.

Good luck,

Mike Anton

> -----Original Message-----
> From: l...
> [mailto:l...]On Behalf
> Of drproton2003
> Sent: Tuesday, July 07, 2009 8:24 PM
> To: l...
> Subject: [lpc2000] Re: EFSL and SDHC
> The code I am using (EFSL) does just this. It it just hidden
> in another function that I did not paste in. In any case the
> initialization part seems to be working now, but the file
> system part is not.
>
> --- In l..., Sutton Mehaffey wrote:
> >
> > I assume you are using CMD55 before ACMD41 and getting a
> status of 1
> > before issuing ACMD41. I don't see that in your code. The
> sequence
> > needs to be:
> >
> > CMD8
> > CMD55
> > ACMD41
> >
> > Sutton
> >
> >
> >
> > drproton2003 wrote:
> > >
> > >
> > > I don't seem to be having this problem any more. The only
> thing I can
> > > point to is that it didn't like me having a breakpoint in
> that block
> > > of code.
> > >
> > > That being said, it still doesn't work. efs_init now returns -2
> > > (failed to initialize file system). One problem is that
> when I try to
> > > view the results of a sector read from the debugger it is
> different
> > > than what the hex editor on my computer says. The really
> weird part is
> > > that this occurs for both the 1GB card that works fine
> and the 4GB
> > > SDHC card that doesn't.
> > >
> > > I've spent all day working on this now so I think it is
> time for a break.
> > >
> > > --- In l...
> ,
> > > Sutton Mehaffey wrote:
> > > >
> > > > Are you preceding ACMD41 with a CMD55?
> > > >
> > > >
> > > >
> > > > drproton2003 wrote:
> > > > >
> > > > >
> > > > > I've got one step further with this. Turns out the sd_Command
> > > function
> > > > > was using the wrong CRC for CMD8. The CRC was
> orignally set to 0x97
> > > > > and it should be 0x87.
> > > > >
> > > > > Now the initialization gets stuck in the next few
> lines. ACMD41
> > > always
> > > > > seems to return 1, so I get stuck in the do loop.
> > > > >
> > > > > if ( ocr[2] == 0x01 && ocr[3] == 0xAA ) {
> > > > > retry = LOOP_CNT_1000; /* should retry 1000ms */
> > > > > do {
> > > > > //Wait for leaving idle state (ACMD41 with HCS bit)
> > > > > resp = sd_Command( iface, ACMD41,((1UL << 30)>>16), 0 );
> > > > > retry--;
> > > > > } while ( retry && (resp != 0) );
> > > > >
> > > > > if ( retry && sd_Command( iface, CMD58, 0, 0 ) == 0) {
> > > > > /* Check CCS bit in the OCR */
> > > > > for ( n = 0; n < 4; n++ ) {
> > > > > ocr[n] = if_spiSend( iface, 0xff );
> > > > > }
> > > > > ty = (ocr[0] & 0x40) ? 12 : 4;
> > > > > if ( ty == 12 ) DBG((TXT("SDHC HighCap\n")));
> > > > > if ( ty == 4 ) DBG((TXT("SDHC\n")));
> > > > > }
> > > > >
> > > > > Seeing as how the CRC was wrong it makes me think
> that this code has
> > > > > never been tested with SDHC.
> > > > >
> > > > > --- In l...
>
> > > ,
> > > > > "drproton2003" wrote:
> > > > > >
> > > > > > Hello everyone,
> > > > > >
> > > > > > I am attempting to get EFSL to work with SDHC cards. I have
> > > > > downloaded version 0.2.9 RC7 from this page
> > > > > >
> > > > > >
> > > > >
> > >
> http://www.siwawi.arubi.uni-kl.de/avr_projects/arm_projects/ar
> m_memcards/
> > >
> > rm_memcards/>
> > >
> > > > >
> > >
> > rm_memcards/
> > >
> > rm_memcards/>>
> > > > > >
> > > > > > After realizing that I needed to use the SSP FIFO
> mode I had it
> > > > > working with a 1GB SD card.
> > > > > >
> > > > > > Now that I am using a SDHC card I am having some
> problems. The
> > > > > problems start in the sd_Init function. Namely, this
> block of code
> > > here:
> > > > > >
> > > > > > if ( sd_Command( iface, CMD8, 0, 0x01AA) == 1 ) {
> > > > > > /* SDHC */
> > > > > > for ( n=0; n<4; n++ ) {
> > > > > > ocr[n] = if_spiSend( iface, 0xff );
> > > > > > }
> > > > > > if ( ocr[2] == 0x01 && ocr[3] == 0xAA )
> > > > > >
> > > > > > The card I am using responds to CMD8 with a value
> of 9, so it fails
> > > > > this check and goes to the SDSC case. As I understand
> it if CMD8
> > > > > responds the card is SDHC, does the response need to
> be 1? If I
> > > remove
> > > > > the == 1 from the first if, ocr[] is filled in with
> 0xFF, so the next
> > > > > test fails.
> > > > > >
> > > > > > Has anyone used EFSL with SDHC cards? What might be
> the cause of my
> > > > > problems? Also where can I find documentation on
> interfacing with
> > > SDHC
> > > > > cards? I've found a lot of docs for standard SD, but
> not too much for
> > > > > SDHC.
> > > > > >
> > > > >
> > > > >
> > > >
> > > > --
> > > > Sutton Mehaffey
> > > > Lookout Portable Security
> > > > 4040 Royal Dr. #100
> > > > Kennesaw, GA 30144
> > > > 800-207-6269, 770-514-7999, 770-514-1285 FAX
> > > > sutton@
> > > >
> > >
> > >
> >
> > --
> > Sutton Mehaffey
> > Lookout Portable Security
> > 4040 Royal Dr. #100
> > Kennesaw, GA 30144
> > 800-207-6269, 770-514-7999, 770-514-1285 FAX
> > sutton@...
> >
>
Reply by drproton2003 July 7, 20092009-07-07
The code I am using (EFSL) does just this. It it just hidden in another function that I did not paste in. In any case the initialization part seems to be working now, but the file system part is not.

--- In l..., Sutton Mehaffey wrote:
>
> I assume you are using CMD55 before ACMD41 and getting a status of 1
> before issuing ACMD41. I don't see that in your code. The sequence
> needs to be:
>
> CMD8
> CMD55
> ACMD41
>
> Sutton
>
> drproton2003 wrote:
> >
> >
> > I don't seem to be having this problem any more. The only thing I can
> > point to is that it didn't like me having a breakpoint in that block
> > of code.
> >
> > That being said, it still doesn't work. efs_init now returns -2
> > (failed to initialize file system). One problem is that when I try to
> > view the results of a sector read from the debugger it is different
> > than what the hex editor on my computer says. The really weird part is
> > that this occurs for both the 1GB card that works fine and the 4GB
> > SDHC card that doesn't.
> >
> > I've spent all day working on this now so I think it is time for a break.
> >
> > --- In l... ,
> > Sutton Mehaffey wrote:
> > >
> > > Are you preceding ACMD41 with a CMD55?
> > >
> > >
> > >
> > > drproton2003 wrote:
> > > >
> > > >
> > > > I've got one step further with this. Turns out the sd_Command
> > function
> > > > was using the wrong CRC for CMD8. The CRC was orignally set to 0x97
> > > > and it should be 0x87.
> > > >
> > > > Now the initialization gets stuck in the next few lines. ACMD41
> > always
> > > > seems to return 1, so I get stuck in the do loop.
> > > >
> > > > if ( ocr[2] == 0x01 && ocr[3] == 0xAA ) {
> > > > retry = LOOP_CNT_1000; /* should retry 1000ms */
> > > > do {
> > > > //Wait for leaving idle state (ACMD41 with HCS bit)
> > > > resp = sd_Command( iface, ACMD41,((1UL << 30)>>16), 0 );
> > > > retry--;
> > > > } while ( retry && (resp != 0) );
> > > >
> > > > if ( retry && sd_Command( iface, CMD58, 0, 0 ) == 0) {
> > > > /* Check CCS bit in the OCR */
> > > > for ( n = 0; n < 4; n++ ) {
> > > > ocr[n] = if_spiSend( iface, 0xff );
> > > > }
> > > > ty = (ocr[0] & 0x40) ? 12 : 4;
> > > > if ( ty == 12 ) DBG((TXT("SDHC HighCap\n")));
> > > > if ( ty == 4 ) DBG((TXT("SDHC\n")));
> > > > }
> > > >
> > > > Seeing as how the CRC was wrong it makes me think that this code has
> > > > never been tested with SDHC.
> > > >
> > > > --- In l...
> > ,
> > > > "drproton2003" wrote:
> > > > >
> > > > > Hello everyone,
> > > > >
> > > > > I am attempting to get EFSL to work with SDHC cards. I have
> > > > downloaded version 0.2.9 RC7 from this page
> > > > >
> > > > >
> > > >
> > http://www.siwawi.arubi.uni-kl.de/avr_projects/arm_projects/arm_memcards/
> >
> >
> > > >
> > > > >
> > > > >
> > > > > After realizing that I needed to use the SSP FIFO mode I had it
> > > > working with a 1GB SD card.
> > > > >
> > > > > Now that I am using a SDHC card I am having some problems. The
> > > > problems start in the sd_Init function. Namely, this block of code
> > here:
> > > > >
> > > > > if ( sd_Command( iface, CMD8, 0, 0x01AA) == 1 ) {
> > > > > /* SDHC */
> > > > > for ( n=0; n<4; n++ ) {
> > > > > ocr[n] = if_spiSend( iface, 0xff );
> > > > > }
> > > > > if ( ocr[2] == 0x01 && ocr[3] == 0xAA )
> > > > >
> > > > > The card I am using responds to CMD8 with a value of 9, so it fails
> > > > this check and goes to the SDSC case. As I understand it if CMD8
> > > > responds the card is SDHC, does the response need to be 1? If I
> > remove
> > > > the == 1 from the first if, ocr[] is filled in with 0xFF, so the next
> > > > test fails.
> > > > >
> > > > > Has anyone used EFSL with SDHC cards? What might be the cause of my
> > > > problems? Also where can I find documentation on interfacing with
> > SDHC
> > > > cards? I've found a lot of docs for standard SD, but not too much for
> > > > SDHC.
> > > > >
> > > >
> > > >
> > >
> > > --
> > > Sutton Mehaffey
> > > Lookout Portable Security
> > > 4040 Royal Dr. #100
> > > Kennesaw, GA 30144
> > > 800-207-6269, 770-514-7999, 770-514-1285 FAX
> > > sutton@
> > >
> >
> > --
> Sutton Mehaffey
> Lookout Portable Security
> 4040 Royal Dr. #100
> Kennesaw, GA 30144
> 800-207-6269, 770-514-7999, 770-514-1285 FAX
> sutton@...
>

Reply by Sutton Mehaffey July 7, 20092009-07-07
I assume you are using CMD55 before ACMD41 and getting a status of 1
before issuing ACMD41. I don't see that in your code. The sequence
needs to be:

CMD8
CMD55
ACMD41

Sutton

drproton2003 wrote:
> I don't seem to be having this problem any more. The only thing I can
> point to is that it didn't like me having a breakpoint in that block
> of code.
>
> That being said, it still doesn't work. efs_init now returns -2
> (failed to initialize file system). One problem is that when I try to
> view the results of a sector read from the debugger it is different
> than what the hex editor on my computer says. The really weird part is
> that this occurs for both the 1GB card that works fine and the 4GB
> SDHC card that doesn't.
>
> I've spent all day working on this now so I think it is time for a break.
>
> --- In l... ,
> Sutton Mehaffey wrote:
> >
> > Are you preceding ACMD41 with a CMD55?
> >
> >
> >
> > drproton2003 wrote:
> > >
> > >
> > > I've got one step further with this. Turns out the sd_Command
> function
> > > was using the wrong CRC for CMD8. The CRC was orignally set to 0x97
> > > and it should be 0x87.
> > >
> > > Now the initialization gets stuck in the next few lines. ACMD41
> always
> > > seems to return 1, so I get stuck in the do loop.
> > >
> > > if ( ocr[2] == 0x01 && ocr[3] == 0xAA ) {
> > > retry = LOOP_CNT_1000; /* should retry 1000ms */
> > > do {
> > > //Wait for leaving idle state (ACMD41 with HCS bit)
> > > resp = sd_Command( iface, ACMD41,((1UL << 30)>>16), 0 );
> > > retry--;
> > > } while ( retry && (resp != 0) );
> > >
> > > if ( retry && sd_Command( iface, CMD58, 0, 0 ) == 0) {
> > > /* Check CCS bit in the OCR */
> > > for ( n = 0; n < 4; n++ ) {
> > > ocr[n] = if_spiSend( iface, 0xff );
> > > }
> > > ty = (ocr[0] & 0x40) ? 12 : 4;
> > > if ( ty == 12 ) DBG((TXT("SDHC HighCap\n")));
> > > if ( ty == 4 ) DBG((TXT("SDHC\n")));
> > > }
> > >
> > > Seeing as how the CRC was wrong it makes me think that this code has
> > > never been tested with SDHC.
> > >
> > > --- In l...
> ,
> > > "drproton2003" wrote:
> > > >
> > > > Hello everyone,
> > > >
> > > > I am attempting to get EFSL to work with SDHC cards. I have
> > > downloaded version 0.2.9 RC7 from this page
> > > >
> > > >
> > >
> http://www.siwawi.arubi.uni-kl.de/avr_projects/arm_projects/arm_memcards/
> > >
> > >
> > > >
> > > > After realizing that I needed to use the SSP FIFO mode I had it
> > > working with a 1GB SD card.
> > > >
> > > > Now that I am using a SDHC card I am having some problems. The
> > > problems start in the sd_Init function. Namely, this block of code
> here:
> > > >
> > > > if ( sd_Command( iface, CMD8, 0, 0x01AA) == 1 ) {
> > > > /* SDHC */
> > > > for ( n=0; n<4; n++ ) {
> > > > ocr[n] = if_spiSend( iface, 0xff );
> > > > }
> > > > if ( ocr[2] == 0x01 && ocr[3] == 0xAA )
> > > >
> > > > The card I am using responds to CMD8 with a value of 9, so it fails
> > > this check and goes to the SDSC case. As I understand it if CMD8
> > > responds the card is SDHC, does the response need to be 1? If I
> remove
> > > the == 1 from the first if, ocr[] is filled in with 0xFF, so the next
> > > test fails.
> > > >
> > > > Has anyone used EFSL with SDHC cards? What might be the cause of my
> > > problems? Also where can I find documentation on interfacing with
> SDHC
> > > cards? I've found a lot of docs for standard SD, but not too much for
> > > SDHC.
> > > >
> > >
> > >
> >
> > --
> > Sutton Mehaffey
> > Lookout Portable Security
> > 4040 Royal Dr. #100
> > Kennesaw, GA 30144
> > 800-207-6269, 770-514-7999, 770-514-1285 FAX
> > 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

Reply by drproton2003 July 7, 20092009-07-07
I don't seem to be having this problem any more. The only thing I can point to is that it didn't like me having a breakpoint in that block of code.

That being said, it still doesn't work. efs_init now returns -2 (failed to initialize file system). One problem is that when I try to view the results of a sector read from the debugger it is different than what the hex editor on my computer says. The really weird part is that this occurs for both the 1GB card that works fine and the 4GB SDHC card that doesn't.

I've spent all day working on this now so I think it is time for a break.
--- In l..., Sutton Mehaffey wrote:
>
> Are you preceding ACMD41 with a CMD55?
>
> drproton2003 wrote:
> >
> >
> > I've got one step further with this. Turns out the sd_Command function
> > was using the wrong CRC for CMD8. The CRC was orignally set to 0x97
> > and it should be 0x87.
> >
> > Now the initialization gets stuck in the next few lines. ACMD41 always
> > seems to return 1, so I get stuck in the do loop.
> >
> > if ( ocr[2] == 0x01 && ocr[3] == 0xAA ) {
> > retry = LOOP_CNT_1000; /* should retry 1000ms */
> > do {
> > //Wait for leaving idle state (ACMD41 with HCS bit)
> > resp = sd_Command( iface, ACMD41,((1UL << 30)>>16), 0 );
> > retry--;
> > } while ( retry && (resp != 0) );
> >
> > if ( retry && sd_Command( iface, CMD58, 0, 0 ) == 0) {
> > /* Check CCS bit in the OCR */
> > for ( n = 0; n < 4; n++ ) {
> > ocr[n] = if_spiSend( iface, 0xff );
> > }
> > ty = (ocr[0] & 0x40) ? 12 : 4;
> > if ( ty == 12 ) DBG((TXT("SDHC HighCap\n")));
> > if ( ty == 4 ) DBG((TXT("SDHC\n")));
> > }
> >
> > Seeing as how the CRC was wrong it makes me think that this code has
> > never been tested with SDHC.
> >
> > --- In l... ,
> > "drproton2003" wrote:
> > >
> > > Hello everyone,
> > >
> > > I am attempting to get EFSL to work with SDHC cards. I have
> > downloaded version 0.2.9 RC7 from this page
> > >
> > >
> > http://www.siwawi.arubi.uni-kl.de/avr_projects/arm_projects/arm_memcards/
> >
> > >
> > > After realizing that I needed to use the SSP FIFO mode I had it
> > working with a 1GB SD card.
> > >
> > > Now that I am using a SDHC card I am having some problems. The
> > problems start in the sd_Init function. Namely, this block of code here:
> > >
> > > if ( sd_Command( iface, CMD8, 0, 0x01AA) == 1 ) {
> > > /* SDHC */
> > > for ( n=0; n<4; n++ ) {
> > > ocr[n] = if_spiSend( iface, 0xff );
> > > }
> > > if ( ocr[2] == 0x01 && ocr[3] == 0xAA )
> > >
> > > The card I am using responds to CMD8 with a value of 9, so it fails
> > this check and goes to the SDSC case. As I understand it if CMD8
> > responds the card is SDHC, does the response need to be 1? If I remove
> > the == 1 from the first if, ocr[] is filled in with 0xFF, so the next
> > test fails.
> > >
> > > Has anyone used EFSL with SDHC cards? What might be the cause of my
> > problems? Also where can I find documentation on interfacing with SDHC
> > cards? I've found a lot of docs for standard SD, but not too much for
> > SDHC.
> > >
> >
> > --
> Sutton Mehaffey
> Lookout Portable Security
> 4040 Royal Dr. #100
> Kennesaw, GA 30144
> 800-207-6269, 770-514-7999, 770-514-1285 FAX
> sutton@...
>