cancel
Showing results for 
Search instead for 
Did you mean: 

SPI CRC initial value

konstantin23
Associate II
Posted on August 22, 2009 at 07:09

SPI CRC initial value

6 REPLIES 6
konstantin23
Associate II
Posted on May 17, 2011 at 13:19

Just starting to use this micro and I don't see a way to change the init values for CRC calculation on SPI.

They are initialized to 0x0000 and the registers are read only. I'd prefer to be able to move the blind spot from 0s.

Am I missing something?

guyvo67
Associate II
Posted on May 17, 2011 at 13:19

Maybe you can take a look at my post:

http://www.st.com/mcu/forums-cat-8752-23.html

There you find a snippet of the SPI initialisation phase. I didn't try it myself though. But maybe a good starting point to let the bells ring and solve your zeros problem.

cheers

Guy

konstantin23
Associate II
Posted on May 17, 2011 at 13:19

Thanks for the response.

That SD card SPI project doesn't appear to use the hardware CRC. There is a software CRC16-CCITT function, but it still uses init value of 0.

I can always calculate CRC in code, but it'd be a shame to not use the HW that already exists and is much faster.

guyvo67
Associate II
Posted on May 17, 2011 at 13:19

Hey,

Yes I saw it too like this:

Quote:

_crc16 = spi_txrx(0xff) << 8;

_crc16 |= spi_txrx(0xff);

calc_crc = crc16(buf, len);

if (_crc16 != calc_crc) {

printf(''%s, crcs differ: %04x vs. %04x, len:%i\n'', __func__, _crc16, calc_crc, len);

return -1;

}

Apparently the 0xFF cmd is used to get hardware CRC value calculated and it's based on a zero init. I don't know what the specs are saying on hardware CRC for SD cards. Maybe it's just not possible to alter the CRC init. Maybe there are some differences between SD and not SD or even SDHC.

I didn't look in any of these specs. The only thing I know is that it's hard sometimes to filter the necessary information out of these specs. A friend of mine ones did the init procedure in assembler and he search quit a lot to get trough it.

Maybe this is something suited for an SD card forum but I did quick googling and found nothing that points in that low level direction. I also know that secure part of SD is quit held hidden and specs are only available by paying a fee.

What is the reason actually that you want the change this anyway ?

Cheers

Guy

[ This message was edited by: guyvo67 on 12-08-2009 18:11 ]

konstantin23
Associate II
Posted on May 17, 2011 at 13:19

Sorry for late response.

The place where the crc is initialized is actually in crc16()

Code:

u16 crc16(const u8 *p, int len)

{

int i;

u16 crc = 0;

for (i=0; i<len; i++)

crc = crc16_ccitt(crc, p[i]);

return crc;

}

Here you can see that the 1st one is initialized to 0. But it doesn't matter anyway because I want to use the hardware CRC calculation.

The application is not with an SD card, but with another part of the product we are working on. We can always have a preset 1st word to ''initialize'' the CRC calculation, but it's really a work around.

The reason I want to change is from 0x0000 is to get rid of the blind spot of all 0s. If init value is 0, the CRC for a message that contains only 0s is still 0. So that means that a non-functioning slave will not cause a CRC error. There are several ways to avoid this, but the simplest one to me is hardware CRC check.

guyvo67
Associate II
Posted on May 17, 2011 at 13:19

Ok I get the picture now thanks.

Indeed CRC calc with init and content all 0s will give OK

cheers

Guy