Skip to main content
HarryQiu
Associate
Jul 5, 2021 2:03 AM UTC
Question

CRC peripheral can't get correct data

Hi there,

I currently use STM32L073 for evaluation and found some issue with CRC module.

L073 has a CRC peripheral whose polynomial is programmable. And when I programm the peripheral as below, the checksum returns from the module doesn't match the one from a 3-party calculator -- it has an extra XOR with 0xFF.

The peripheral configuration is as below. In this case, both the 3-party calculator and my software code get a result of 0x5A but the CRC peripheral in the L073 gives a result of 0xA5 (which is 0x5A XOR 0xFF). Same happens for other data input.

CRC->CR = 0x01; // reset CRC module
CRC->CR = 0x10; // 8-bit polynomial
CRC->POL = 0xFE; // set polynomial
CRC->INIT = 0xFF; // set initial value
*(__IO unsigned char *)(CRC_BASE) = 0x5A; // 8-bit write to CRC->DR register
result = CRC->DR; // readout CRC checksum

Could anyone please help me with this?

Thanks a lot.

Regards,

Harry

This topic has been closed for replies.

4 replies

waclawek.jan
Super User
Jul 5, 2021 4:44 AM UTC

What's that 3rd party calculator? If it performs the final xor, well then you have to perform it too.

JW

HarryQiu
HarryQiuAuthor
Associate
Jul 5, 2021 5:14 AM UTC

Hi JW,

Thanks for your reply.

It's here: http://www.zorc.breitbandkatze.de/crc.html

It does have a "final XOR" configuration but unfortunately I put a "0" there. See below:

0693W00000BcmXXQAZ.pngI did some further investigation and seems if the LSB of the polynomial is "0" (in this case 0xFE = 8b11111110), the L073's CRC adds a final XOR with 0xFF to the result.

waclawek.jan
Super User
Jul 5, 2021 5:33 AM UTC

From the CRC chapter in RM:

Polynomial programmability

The polynomial coefficients are fully programmable through the CRC_POL register, and the 

polynomial size can be configured to be 7, 8, 16 or 32 bits by programming the 

POLYSIZE[1:0] bits in the CRC_CR register. Even polynomials are not supported.

JW

HarryQiu
HarryQiuAuthor
Associate
Jul 5, 2021 5:39 AM UTC

Ah I see. Thanks a lot. I missed that "Even..." part.