Skip to main content
PLEE.2
Associate II
February 13, 2023
Solved

Calculate crc in spc5studio and SPC58ECxxxx MCUs

  • February 13, 2023
  • 1 reply
  • 1555 views

I am using spc5studio and SPC58EC80E1.

i import crc sample from application library.

i set CRC Settings at low level Drivers component RLA

- CRC-32, Polymonial seed 0x4c11db7, reset = 0xFFFFFFFF

and firmware code

​-----------------------------------------------------------------------------------------------------

const CRCContextConfig *crc_ctx_config[] = {

 &crc_context_config_contex_crc32,

};

  (void)crc_lld_start(&CRCD1);

  (void)crc_lld_start_context(&CRCD1, 0, crc_ctx_config[0]);

  if (crc_lld_calc(&CRCD1, 0, startAddress, (uint32_t)length, &calculatedCRC) != CRC_NO_ERROR) {

   osalThreadDelayMilliseconds(100);

  }

  (void)crc_lld_stop_context(&CRCD1, 0);

  (void)crc_lld_stop(&CRCD1);

-----------------------------------------------------------------------------​

The code for the window is as follows.

uint Polynominal = 0x04C11DB7;

uint InitValue = 0xFFFFFFFF;

int i= 0, j = 0;

uint CRC = 0xFFFFFFFF;// InitValue;

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

{

byte ch = c[i];

for (j = 0; j < 8; j++)

{

CRC = (uint)(ch ^ CRC);

if ((CRC & 0x80000000) != 0)

{

CRC = (CRC <<1) ^ Polynominal;

}

else

{

CRC <<= 1;

}

}

}

---------------------------------------------------------------------------------​​

later

​I checked crc value the image of flash, but it is different from the CRC-32 calculation in windows program.

I want to know how to calculate the application library.

Or, I would appreciate it if you could let me know if my code is wrong.

thanks.

regards.

This topic has been closed for replies.
Best answer by Erwan YVIN

Hello ,

Interesting issue ;)

Could you try your software code in SPC58EC ?

Could you check this application SPC560Pxx OS-Less CRC Test Application for Discovery

there is a CRC calculation SW.

Best regards

Erwan

1 reply

Erwan YVIN
Erwan YVINBest answer
ST Employee
February 13, 2023

Hello ,

Interesting issue ;)

Could you try your software code in SPC58EC ?

Could you check this application SPC560Pxx OS-Less CRC Test Application for Discovery

there is a CRC calculation SW.

Best regards

Erwan

PLEE.2
PLEE.2Author
Associate II
February 14, 2023

hello.

thanks for your answer.

i already used SPC58ECxx_RLA CRC Test Application for Discovery.(the same SPC560Pxx OS-less....)

Firmware has already applied the above code to create the CRC.

i should compare the two by making CRC in the window program with the same image.

I'm inquiring because these two crc values are different.

best regards.

Pil

Tesla DeLorean
Guru
February 14, 2023

For left shifting you'd need to get the data into the high order bits, surely?

CRC = ((uint)(ch) << 24) ^ CRC;

CRC are very sensitive to exact bit order, byte ordering, shift direction, etc.

If you've got anything wrong, you'll get different numbers, so pay particular attention to the details.

Tips, Buy me a coffee, or three.. PayPal VenmoUp vote any posts that you find helpful, it shows what's working..